Merge pull request #574 from GriffinRichards/vert-spritesheet
Support vertical spritesheets for overworld graphics
This commit is contained in:
commit
dc290652e0
3 changed files with 34 additions and 18 deletions
|
@ -42,6 +42,13 @@ public:
|
||||||
virtual void visitSign(SignEvent *) = 0;
|
virtual void visitSign(SignEvent *) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct EventGraphics
|
||||||
|
{
|
||||||
|
QImage spritesheet;
|
||||||
|
int spriteWidth;
|
||||||
|
int spriteHeight;
|
||||||
|
bool inanimate;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -258,7 +265,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setFrameFromMovement(QString movement);
|
void setFrameFromMovement(QString movement);
|
||||||
void setPixmapFromSpritesheet(QImage, int, int, bool);
|
void setPixmapFromSpritesheet(EventGraphics * gfx);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -18,14 +18,6 @@
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
|
|
||||||
struct EventGraphics
|
|
||||||
{
|
|
||||||
QImage spritesheet;
|
|
||||||
int spriteWidth;
|
|
||||||
int spriteHeight;
|
|
||||||
bool inanimate;
|
|
||||||
};
|
|
||||||
|
|
||||||
// The displayed name of the special map value used by warps with multiple potential destinations
|
// The displayed name of the special map value used by warps with multiple potential destinations
|
||||||
static QString DYNAMIC_MAP_NAME = "Dynamic";
|
static QString DYNAMIC_MAP_NAME = "Dynamic";
|
||||||
|
|
||||||
|
|
|
@ -288,22 +288,39 @@ void ObjectEvent::loadPixmap(Project *project) {
|
||||||
this->usingSprite = false;
|
this->usingSprite = false;
|
||||||
} else {
|
} else {
|
||||||
this->setFrameFromMovement(project->facingDirections.value(this->movement));
|
this->setFrameFromMovement(project->facingDirections.value(this->movement));
|
||||||
this->setPixmapFromSpritesheet(eventGfx->spritesheet, eventGfx->spriteWidth, eventGfx->spriteHeight, eventGfx->inanimate);
|
this->setPixmapFromSpritesheet(eventGfx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectEvent::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight, bool inanimate)
|
void ObjectEvent::setPixmapFromSpritesheet(EventGraphics * gfx)
|
||||||
{
|
{
|
||||||
int frame = inanimate ? 0 : this->frame;
|
QImage img;
|
||||||
QImage img = spritesheet.copy(frame * spriteWidth % spritesheet.width(), 0, spriteWidth, spriteHeight);
|
if (gfx->inanimate) {
|
||||||
if (this->hFlip && !inanimate) {
|
img = gfx->spritesheet.copy(0, 0, gfx->spriteWidth, gfx->spriteHeight);
|
||||||
img = img.transformed(QTransform().scale(-1, 1));
|
} else {
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
|
// Get frame's position in spritesheet.
|
||||||
|
// Assume horizontal layout. If position would exceed sheet width, try vertical layout.
|
||||||
|
if ((this->frame + 1) * gfx->spriteWidth <= gfx->spritesheet.width()) {
|
||||||
|
x = this->frame * gfx->spriteWidth;
|
||||||
|
} else if ((this->frame + 1) * gfx->spriteHeight <= gfx->spritesheet.height()) {
|
||||||
|
y = this->frame * gfx->spriteHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
img = gfx->spritesheet.copy(x, y, gfx->spriteWidth, gfx->spriteHeight);
|
||||||
|
|
||||||
|
// Right-facing sprite is just the left-facing sprite mirrored
|
||||||
|
if (this->hFlip) {
|
||||||
|
img = img.transformed(QTransform().scale(-1, 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Set first palette color fully transparent.
|
// Set first palette color fully transparent.
|
||||||
img.setColor(0, qRgba(0, 0, 0, 0));
|
img.setColor(0, qRgba(0, 0, 0, 0));
|
||||||
pixmap = QPixmap::fromImage(img);
|
pixmap = QPixmap::fromImage(img);
|
||||||
this->spriteWidth = spriteWidth;
|
this->spriteWidth = gfx->spriteWidth;
|
||||||
this->spriteHeight = spriteHeight;
|
this->spriteHeight = gfx->spriteHeight;
|
||||||
this->usingSprite = true;
|
this->usingSprite = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,7 +452,7 @@ void CloneObjectEvent::loadPixmap(Project *project) {
|
||||||
this->usingSprite = false;
|
this->usingSprite = false;
|
||||||
} else {
|
} else {
|
||||||
this->setFrameFromMovement(project->facingDirections.value(this->movement));
|
this->setFrameFromMovement(project->facingDirections.value(this->movement));
|
||||||
this->setPixmapFromSpritesheet(eventGfx->spritesheet, eventGfx->spriteWidth, eventGfx->spriteHeight, eventGfx->inanimate);
|
this->setPixmapFromSpritesheet(eventGfx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue