Support spritesheets instead of individual frames for event object pics
This commit is contained in:
parent
5e42b07bff
commit
23efdc2bea
5 changed files with 53 additions and 8 deletions
|
@ -1653,6 +1653,7 @@ QList<DraggablePixmapItem *> *Editor::getObjects() {
|
|||
void Editor::redrawObject(DraggablePixmapItem *item) {
|
||||
if (item) {
|
||||
item->setPixmap(item->event->pixmap);
|
||||
item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
|
||||
if (selected_events && selected_events->contains(item)) {
|
||||
QImage image = item->pixmap().toImage();
|
||||
QPainter painter(&image);
|
||||
|
|
7
editor.h
7
editor.h
|
@ -174,10 +174,8 @@ public:
|
|||
int last_x;
|
||||
int last_y;
|
||||
void updatePosition() {
|
||||
int x = event->x() * 16;
|
||||
int y = event->y() * 16;
|
||||
x -= pixmap().width() / 32 * 16;
|
||||
y -= pixmap().height() - 16;
|
||||
int x = event->getPixelX();
|
||||
int y = event->getPixelY();
|
||||
setX(x);
|
||||
setY(y);
|
||||
setZValue(event->y());
|
||||
|
@ -193,6 +191,7 @@ public:
|
|||
objects.append(event);
|
||||
event->pixmap = QPixmap();
|
||||
editor->project->loadEventPixmaps(objects);
|
||||
this->updatePosition();
|
||||
editor->redrawObject(this);
|
||||
emit spriteChanged(event->pixmap);
|
||||
}
|
||||
|
|
22
event.cpp
22
event.cpp
|
@ -12,6 +12,8 @@ QString EventType::HealLocation = "event_heal_location";
|
|||
|
||||
Event::Event()
|
||||
{
|
||||
this->spriteWidth = 16;
|
||||
this->spriteHeight = 16;
|
||||
}
|
||||
|
||||
Event* Event::createNewEvent(QString event_type, QString map_name)
|
||||
|
@ -126,6 +128,16 @@ Event* Event::createNewSecretBaseEvent()
|
|||
return event;
|
||||
}
|
||||
|
||||
int Event::getPixelX()
|
||||
{
|
||||
return (this->x() * 16) - qMax(0, (this->spriteWidth - 16) / 2);
|
||||
}
|
||||
|
||||
int Event::getPixelY()
|
||||
{
|
||||
return (this->y() * 16) - qMax(0, this->spriteHeight - 16);
|
||||
}
|
||||
|
||||
QString Event::buildObjectEventMacro(int item_index)
|
||||
{
|
||||
int radius_x = this->getInt("radius_x");
|
||||
|
@ -236,3 +248,13 @@ QString Event::buildSecretBaseEventMacro()
|
|||
text += "\n";
|
||||
return text;
|
||||
}
|
||||
|
||||
void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight)
|
||||
{
|
||||
// Set first palette color fully transparent.
|
||||
QImage img = spritesheet.copy(0, 0, spriteWidth, spriteHeight);
|
||||
img.setColor(0, qRgba(0, 0, 0, 0));
|
||||
pixmap = QPixmap::fromImage(img);
|
||||
this->spriteWidth = spriteWidth;
|
||||
this->spriteHeight = spriteHeight;
|
||||
}
|
||||
|
|
5
event.h
5
event.h
|
@ -71,9 +71,14 @@ public:
|
|||
QString buildSignEventMacro();
|
||||
QString buildHiddenItemEventMacro();
|
||||
QString buildSecretBaseEventMacro();
|
||||
void setPixmapFromSpritesheet(QImage, int, int);
|
||||
int getPixelX();
|
||||
int getPixelY();
|
||||
|
||||
QMap<QString, QString> values;
|
||||
QPixmap pixmap;
|
||||
int spriteWidth;
|
||||
int spriteHeight;
|
||||
};
|
||||
|
||||
#endif // EVENT_H
|
||||
|
|
26
project.cpp
26
project.cpp
|
@ -1292,6 +1292,9 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
|
|||
if (!object->pixmap.isNull()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
object->spriteWidth = 16;
|
||||
object->spriteHeight = 16;
|
||||
QString event_type = object->get("event_type");
|
||||
if (event_type == EventType::Object) {
|
||||
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(0, 0, 16, 16);
|
||||
|
@ -1309,16 +1312,31 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
|
|||
int sprite_id = constants.value(object->get("sprite"));
|
||||
|
||||
QString info_label = pointers.value(sprite_id).replace("&", "");
|
||||
QString pic_label = readCArray(info_text, info_label).value(14);
|
||||
QStringList gfx_info = readCArray(info_text, info_label);
|
||||
QString pic_label = gfx_info.value(14);
|
||||
QString dimensions_label = gfx_info.value(11);
|
||||
QString subsprites_label = gfx_info.value(12);
|
||||
QString gfx_label = readCArray(pic_text, pic_label).value(0);
|
||||
gfx_label = gfx_label.section(QRegExp("[\\(\\)]"), 1, 1);
|
||||
QString path = readCIncbin(assets_text, gfx_label);
|
||||
|
||||
if (!path.isNull()) {
|
||||
path = fixGraphicPath(path);
|
||||
QPixmap pixmap(root + "/" + path);
|
||||
if (!pixmap.isNull()) {
|
||||
object->pixmap = pixmap;
|
||||
QImage spritesheet(root + "/" + path);
|
||||
if (!spritesheet.isNull()) {
|
||||
// Infer the sprite dimensions from the OAM labels.
|
||||
int spriteWidth = spritesheet.width();
|
||||
int spriteHeight = spritesheet.height();
|
||||
QRegularExpression re("\\S+_(\\d+)x(\\d+)");
|
||||
QRegularExpressionMatch dimensionMatch = re.match(dimensions_label);
|
||||
if (dimensionMatch.hasMatch()) {
|
||||
QRegularExpressionMatch oamTablesMatch = re.match(subsprites_label);
|
||||
if (oamTablesMatch.hasMatch()) {
|
||||
spriteWidth = dimensionMatch.captured(1).toInt();
|
||||
spriteHeight = dimensionMatch.captured(2).toInt();
|
||||
}
|
||||
}
|
||||
object->setPixmapFromSpritesheet(spritesheet, spriteWidth, spriteHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue