mirror of
https://github.com/huderlem/porymap.git
synced 2026-03-21 17:45:44 -05:00
Add API callback to intercept species icon loading
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
This commit is contained in:
parent
f0c8e21781
commit
6d52fda252
|
|
@ -361,6 +361,8 @@ private:
|
|||
QString findSpeciesIconPath(const QStringList &names) const;
|
||||
QPixmap getEventPixmap(const QString &gfxName, int frame, bool hFlip);
|
||||
|
||||
QPixmap loadSpeciesIcon(const QString &species);
|
||||
|
||||
int maxObjectEvents;
|
||||
int maxMapDataSize;
|
||||
QSize defaultMapSize;
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ public:
|
|||
static void cb_MapViewTabChanged(int oldTab, int newTab);
|
||||
static void cb_BorderVisibilityToggled(bool visible);
|
||||
static QImage cb_EventSpriteLoading(const QString &gfxName, const QString &direction);
|
||||
static QImage cb_SpeciesIconLoading(const QString &species);
|
||||
|
||||
static bool tryErrorJS(QJSValue js);
|
||||
static QJSValue fromBlock(Block block);
|
||||
|
|
@ -153,6 +154,7 @@ public:
|
|||
static void cb_MapViewTabChanged(int, int) {};
|
||||
static void cb_BorderVisibilityToggled(bool) {};
|
||||
static QImage cb_EventSpriteLoading(const QString &, const QString &) {return QImage();}
|
||||
static QImage cb_SpeciesIconLoading(const QString &) {return QImage();}
|
||||
};
|
||||
|
||||
#endif // QT_QML_LIB
|
||||
|
|
|
|||
|
|
@ -3382,26 +3382,34 @@ QString Project::findSpeciesIconPath(const QStringList &names) const {
|
|||
QPixmap Project::getSpeciesIcon(const QString &species) {
|
||||
QPixmap pixmap;
|
||||
if (!QPixmapCache::find(species, &pixmap)) {
|
||||
// Prefer path from config. If not present, use the path parsed from project files
|
||||
QString path = Project::getExistingFilepath(projectConfig.pokemonIconPaths.value(species));
|
||||
if (path.isEmpty()) {
|
||||
path = getDefaultSpeciesIconPath(species);
|
||||
}
|
||||
|
||||
QImage img(path);
|
||||
if (img.isNull()) {
|
||||
// No icon for this species, use placeholder
|
||||
static const QPixmap placeholder = QPixmap(QStringLiteral(":images/pokemon_icon_placeholder.png"));
|
||||
pixmap = placeholder;
|
||||
} else {
|
||||
img.setColor(0, qRgba(0, 0, 0, 0));
|
||||
pixmap = QPixmap::fromImage(img).copy(0, 0, 32, 32);
|
||||
QPixmapCache::insert(species, pixmap);
|
||||
}
|
||||
pixmap = loadSpeciesIcon(species);
|
||||
QPixmapCache::insert(species, pixmap);
|
||||
}
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QPixmap Project::loadSpeciesIcon(const QString &species) {
|
||||
// Users may intercept the sprite loading with a scripting callback.
|
||||
QImage scriptImage = Scripting::cb_SpeciesIconLoading(species);
|
||||
if (!scriptImage.isNull()) return QPixmap::fromImage(scriptImage);
|
||||
|
||||
// Prefer path from config. If not present, use the path parsed from project files
|
||||
QString path = Project::getExistingFilepath(projectConfig.pokemonIconPaths.value(species));
|
||||
if (path.isEmpty()) {
|
||||
path = getDefaultSpeciesIconPath(species);
|
||||
}
|
||||
|
||||
QImage img(path);
|
||||
if (img.isNull()) {
|
||||
// No icon for this species, use placeholder
|
||||
static const QPixmap placeholder = QPixmap(QStringLiteral(":images/pokemon_icon_placeholder.png"));
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
img.setColor(0, qRgba(0, 0, 0, 0));
|
||||
return QPixmap::fromImage(img).copy(0, 0, 32, 32);
|
||||
}
|
||||
|
||||
int Project::getMapDataSize(int width, int height) const {
|
||||
return (width + this->mapSizeAddition.width())
|
||||
* (height + this->mapSizeAddition.height());
|
||||
|
|
|
|||
|
|
@ -402,6 +402,15 @@ QImage Scripting::cb_EventSpriteLoading(const QString &gfxName, const QString &d
|
|||
return toImage(instance->invokeCallback(QStringLiteral("onEventSpriteLoading"), args));
|
||||
}
|
||||
|
||||
QImage Scripting::cb_SpeciesIconLoading(const QString &species) {
|
||||
if (!instance) return QImage();
|
||||
|
||||
QJSValueList args {
|
||||
species,
|
||||
};
|
||||
return toImage(instance->invokeCallback(QStringLiteral("onSpeciesIconLoading"), args));
|
||||
}
|
||||
|
||||
QJSValue Scripting::fromBlock(Block block) {
|
||||
QJSValue obj = instance->engine->newObject();
|
||||
obj.setProperty("metatileId", block.metatileId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user