-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[texi] change: QListWidget to QListView and a list model
add: ability to open key, erf, and zip containers update: rollnw
- Loading branch information
Showing
10 changed files
with
168 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Build | ||
build/ | ||
build-debug/ | ||
build-doc/ | ||
vcpkg/ | ||
vcpkg_installed/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule rollnw
updated
23 files
+16 −16 | external/zlib-1.3.1/CMakeLists.txt | |
+3 −0 | lib/nw/formats/Image.cpp | |
+4 −0 | lib/nw/formats/Image.hpp | |
+2 −2 | lib/nw/script/Ast.cpp | |
+1 −1 | lib/nw/script/Ast.hpp | |
+5 −21 | lib/nw/script/AstConstEvaluator.hpp | |
+3 −2 | lib/nw/script/AstHinter.hpp | |
+3 −2 | lib/nw/script/AstLocator.hpp | |
+19 −27 | lib/nw/script/AstResolver.hpp | |
+2 −0 | lib/nw/script/Context.cpp | |
+7 −1 | lib/nw/script/Context.hpp | |
+82 −39 | lib/nw/script/Nss.cpp | |
+10 −5 | lib/nw/script/Nss.hpp | |
+15 −2 | lib/nw/script/NssParser.cpp | |
+1 −1 | lib/nw/script/NssParser.hpp | |
+1 −0 | rollnw-py/opaque_types.cpp | |
+2 −0 | rollnw-py/opaque_types.hpp | |
+29 −37 | rollnw-py/wrapper_script.cpp | |
+1 −1 | setup.py | |
+4 −0 | tests/legacy_image.cpp | |
+77 −5 | tests/script_nss.cpp | |
+5 −0 | tests/test_data/user/development/test_inc_stack.nss | |
+3 −0 | tests/test_data/user/development/test_inc_stack_2.nss |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "texuregallerymodel.h" | ||
|
||
#include "nw/formats/Image.hpp" | ||
#include "nw/log.hpp" | ||
#include "nw/resources/Directory.hpp" | ||
#include "nw/resources/Erf.hpp" | ||
#include "nw/resources/Key.hpp" | ||
#include "nw/resources/Zip.hpp" | ||
#include "nw/util/platform.hpp" | ||
|
||
#include <QIcon> | ||
#include <QImage> | ||
|
||
inline std::unique_ptr<nw::Container> load_container(const std::filesystem::path& p) | ||
{ | ||
auto ext = nw::path_to_string(p.extension()); | ||
|
||
if (std::filesystem::is_directory(p)) { | ||
return std::make_unique<nw::Directory>(p); | ||
} else if (nw::string::icmp(ext, ".hak")) { | ||
return std::make_unique<nw::Erf>(p); | ||
} else if (nw::string::icmp(ext, ".erf")) { | ||
return std::make_unique<nw::Erf>(p); | ||
} else if (nw::string::icmp(ext, ".zip")) { | ||
return std::make_unique<nw::Zip>(p); | ||
} else if (nw::string::icmp(ext, ".key")) { | ||
return std::make_unique<nw::Key>(p); | ||
} | ||
return nullptr; | ||
} | ||
|
||
TexureGalleryModel::TexureGalleryModel(const QString& path, QObject* parent) | ||
: QAbstractListModel(parent) | ||
{ | ||
container_ = load_container(path.toStdString()); | ||
|
||
auto cb = [this](const nw::Resource& resource) { | ||
if (resource.type == nw::ResourceType::plt) { | ||
return; | ||
} | ||
if (nw::ResourceType::check_category(nw::ResourceType::texture, resource.type)) { | ||
labels_.push_back(resource); | ||
} | ||
}; | ||
|
||
container_->visit(cb); | ||
std::sort(std::begin(labels_), std::end(labels_)); | ||
} | ||
|
||
QVariant TexureGalleryModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
{ | ||
return {}; | ||
} | ||
|
||
int TexureGalleryModel::rowCount(const QModelIndex& parent) const | ||
{ | ||
return labels_.size(); | ||
} | ||
|
||
int TexureGalleryModel::columnCount(const QModelIndex& parent) const | ||
{ | ||
return 1; | ||
} | ||
|
||
QVariant TexureGalleryModel::data(const QModelIndex& index, int role) const | ||
{ | ||
if (!index.isValid()) | ||
return QVariant(); | ||
|
||
if (role == Qt::DecorationRole) { | ||
auto it = cache_.find(labels_[index.row()]); | ||
if (it != std::end(cache_)) { | ||
return it->second; | ||
} else { | ||
nw::Image img{container_->demand(labels_[index.row()])}; | ||
if (!img.valid()) { | ||
QVariant(); | ||
} | ||
|
||
QImage qi(img.data(), img.width(), img.height(), | ||
img.channels() == 4 ? QImage::Format_RGBA8888 : QImage::Format_RGB888); | ||
if (qi.height() > 128 || qi.width() > 128) { | ||
qi = qi.scaled(128, 128, Qt::KeepAspectRatio); | ||
} | ||
if (img.is_bio_dds()) { | ||
qi.mirror(); | ||
} | ||
auto it2 = cache_.emplace(labels_[index.row()], QPixmap::fromImage(qi)); | ||
return it2.first->second; | ||
} | ||
} else if (role == Qt::SizeHintRole) { | ||
return QSize(128, 150); | ||
} else if (role == Qt::DisplayRole) { | ||
return QString::fromStdString(labels_[index.row()].filename()); | ||
} else if (role == Qt::TextAlignmentRole) { | ||
return (Qt::AlignBottom | Qt::AlignHCenter).toInt(); | ||
} else if (role == Qt::ToolTipRole) { | ||
auto it = cache_.find(labels_[index.row()]); | ||
if (it == std::end(cache_)) { | ||
return {}; | ||
} | ||
return QString::fromStdString(fmt::format("{}x{}", it->second.width(), it->second.height())); | ||
} | ||
return QVariant(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef TEXUREGALLERYMODEL_H | ||
#define TEXUREGALLERYMODEL_H | ||
|
||
#include "nw/resources/Container.hpp" | ||
|
||
#include "absl/container/flat_hash_map.h" | ||
|
||
#include <QAbstractListModel> | ||
#include <QPixmap> | ||
|
||
#include <string> | ||
|
||
class TexureGalleryModel : public QAbstractListModel { | ||
Q_OBJECT | ||
|
||
public: | ||
explicit TexureGalleryModel(const QString& path, QObject* parent = nullptr); | ||
|
||
// Header: | ||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | ||
|
||
// Basic functionality: | ||
int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||
|
||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
|
||
private: | ||
std::unique_ptr<nw::Container> container_; | ||
std::vector<nw::Resource> labels_; | ||
mutable absl::flat_hash_map<nw::Resource, QPixmap> cache_; | ||
}; | ||
|
||
#endif // TEXUREGALLERYMODEL_H |