draw sprites based on movement type
This commit is contained in:
parent
d7287ce54b
commit
0a0eaba788
6 changed files with 65 additions and 5 deletions
|
@ -74,18 +74,21 @@ public:
|
||||||
QJsonObject buildSignEventJSON();
|
QJsonObject buildSignEventJSON();
|
||||||
QJsonObject buildHiddenItemEventJSON();
|
QJsonObject buildHiddenItemEventJSON();
|
||||||
QJsonObject buildSecretBaseEventJSON();
|
QJsonObject buildSecretBaseEventJSON();
|
||||||
void setPixmapFromSpritesheet(QImage, int, int);
|
void setPixmapFromSpritesheet(QImage, int, int, int, bool);
|
||||||
int getPixelX();
|
int getPixelX();
|
||||||
int getPixelY();
|
int getPixelY();
|
||||||
QMap<QString, bool> getExpectedFields();
|
QMap<QString, bool> getExpectedFields();
|
||||||
void readCustomValues(QJsonObject values);
|
void readCustomValues(QJsonObject values);
|
||||||
void addCustomValuesTo(QJsonObject *obj);
|
void addCustomValuesTo(QJsonObject *obj);
|
||||||
|
void setFrameFromMovement(QString);
|
||||||
|
|
||||||
QMap<QString, QString> values;
|
QMap<QString, QString> values;
|
||||||
QMap<QString, QString> customValues;
|
QMap<QString, QString> customValues;
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
int spriteWidth;
|
int spriteWidth;
|
||||||
int spriteHeight;
|
int spriteHeight;
|
||||||
|
int frame = 0;
|
||||||
|
bool hFlip = false;
|
||||||
bool usingSprite;
|
bool usingSprite;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
QStringList *bgEventFacingDirections = nullptr;
|
QStringList *bgEventFacingDirections = nullptr;
|
||||||
QMap<QString, int> metatileBehaviorMap;
|
QMap<QString, int> metatileBehaviorMap;
|
||||||
QMap<int, QString> metatileBehaviorMapInverse;
|
QMap<int, QString> metatileBehaviorMapInverse;
|
||||||
|
QMap<QString, QString> facingDirections;
|
||||||
|
|
||||||
QMap<QString, Map*> *map_cache;
|
QMap<QString, Map*> *map_cache;
|
||||||
Map* loadMap(QString);
|
Map* loadMap(QString);
|
||||||
|
@ -106,6 +107,7 @@ public:
|
||||||
void readFlagNames();
|
void readFlagNames();
|
||||||
void readVarNames();
|
void readVarNames();
|
||||||
void readMovementTypes();
|
void readMovementTypes();
|
||||||
|
void readInitialFacingDirections();
|
||||||
void readMapTypes();
|
void readMapTypes();
|
||||||
void readMapBattleScenes();
|
void readMapBattleScenes();
|
||||||
void readWeatherNames();
|
void readWeatherNames();
|
||||||
|
@ -126,6 +128,7 @@ public:
|
||||||
QStringList readCArray(QString text, QString label);
|
QStringList readCArray(QString text, QString label);
|
||||||
QString readCIncbin(QString text, QString label);
|
QString readCIncbin(QString text, QString label);
|
||||||
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
QMap<QString, int> readCDefines(QString text, QStringList prefixes);
|
||||||
|
QMap<QString, QString> readNamedIndexCArray(QString text, QString label);
|
||||||
|
|
||||||
static int getNumTilesPrimary();
|
static int getNumTilesPrimary();
|
||||||
static int getNumTilesTotal();
|
static int getNumTilesTotal();
|
||||||
|
|
|
@ -342,13 +342,35 @@ QJsonObject Event::buildSecretBaseEventJSON()
|
||||||
return secretBaseObj;
|
return secretBaseObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight)
|
void Event::setPixmapFromSpritesheet(QImage spritesheet, int spriteWidth, int spriteHeight, int frame, bool hFlip)
|
||||||
{
|
{
|
||||||
// Set first palette color fully transparent.
|
// Set first palette color fully transparent.
|
||||||
QImage img = spritesheet.copy(0, 0, spriteWidth, spriteHeight);
|
QImage img = spritesheet.copy(frame * spriteWidth % spritesheet.width(), 0, spriteWidth, spriteHeight);
|
||||||
|
if (hFlip) {
|
||||||
|
img = img.transformed(QTransform().scale(-1, 1));
|
||||||
|
}
|
||||||
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 = spriteWidth;
|
||||||
this->spriteHeight = spriteHeight;
|
this->spriteHeight = spriteHeight;
|
||||||
this->usingSprite = true;
|
this->usingSprite = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Event::setFrameFromMovement(QString facingDir) {
|
||||||
|
// defaults
|
||||||
|
this->frame = 0;
|
||||||
|
this->hFlip = false;
|
||||||
|
if (facingDir == "DIR_NORTH") {
|
||||||
|
this->frame = 1;
|
||||||
|
this->hFlip = false;
|
||||||
|
} else if (facingDir == "DIR_SOUTH") {
|
||||||
|
this->frame = 0;
|
||||||
|
this->hFlip = false;
|
||||||
|
} else if (facingDir == "DIR_WEST") {
|
||||||
|
this->frame = 2;
|
||||||
|
this->hFlip = false;
|
||||||
|
} else if (facingDir == "DIR_EAST") {
|
||||||
|
this->frame = 2;
|
||||||
|
this->hFlip = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -761,6 +761,8 @@ void Editor::displayMapEvents() {
|
||||||
|
|
||||||
DraggablePixmapItem *Editor::addMapEvent(Event *event) {
|
DraggablePixmapItem *Editor::addMapEvent(Event *event) {
|
||||||
DraggablePixmapItem *object = new DraggablePixmapItem(event, this);
|
DraggablePixmapItem *object = new DraggablePixmapItem(event, this);
|
||||||
|
event->setFrameFromMovement(project->facingDirections.value(event->get("movement_type")));
|
||||||
|
object->updatePixmap();
|
||||||
if (!event->usingSprite) {
|
if (!event->usingSprite) {
|
||||||
object->setOpacity(0.7);
|
object->setOpacity(0.7);
|
||||||
}
|
}
|
||||||
|
@ -1202,7 +1204,7 @@ QList<DraggablePixmapItem *> *Editor::getObjects() {
|
||||||
|
|
||||||
void Editor::redrawObject(DraggablePixmapItem *item) {
|
void Editor::redrawObject(DraggablePixmapItem *item) {
|
||||||
if (item) {
|
if (item) {
|
||||||
item->setPixmap(item->event->pixmap);
|
item->setPixmap(item->event->pixmap.copy(item->event->frame * item->event->spriteWidth % item->event->pixmap.width(), 0, item->event->spriteWidth, item->event->spriteHeight));
|
||||||
item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
|
item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
|
||||||
if (selected_events && selected_events->contains(item)) {
|
if (selected_events && selected_events->contains(item)) {
|
||||||
QImage image = item->pixmap().toImage();
|
QImage image = item->pixmap().toImage();
|
||||||
|
|
|
@ -600,6 +600,7 @@ void MainWindow::loadDataStructures() {
|
||||||
project->readFlagNames();
|
project->readFlagNames();
|
||||||
project->readVarNames();
|
project->readVarNames();
|
||||||
project->readMovementTypes();
|
project->readMovementTypes();
|
||||||
|
project->readInitialFacingDirections();
|
||||||
project->readMapTypes();
|
project->readMapTypes();
|
||||||
project->readMapBattleScenes();
|
project->readMapBattleScenes();
|
||||||
project->readWeatherNames();
|
project->readWeatherNames();
|
||||||
|
@ -1452,6 +1453,11 @@ void MainWindow::updateSelectedObjects() {
|
||||||
if (!editor->project->movementTypes->contains(value)) {
|
if (!editor->project->movementTypes->contains(value)) {
|
||||||
combo->addItem(value);
|
combo->addItem(value);
|
||||||
}
|
}
|
||||||
|
connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
|
||||||
|
this, [this, item, frame](QString value){
|
||||||
|
item->event->setFrameFromMovement(editor->project->facingDirections.value(value));
|
||||||
|
item->updatePixmap();
|
||||||
|
});
|
||||||
combo->addItems(*editor->project->movementTypes);
|
combo->addItems(*editor->project->movementTypes);
|
||||||
combo->setToolTip("The object's natural movement behavior when the player is not interacting with it.");
|
combo->setToolTip("The object's natural movement behavior when the player is not interacting with it.");
|
||||||
} else if (key == "weather") {
|
} else if (key == "weather") {
|
||||||
|
|
|
@ -1535,6 +1535,11 @@ void Project::readMovementTypes() {
|
||||||
readCDefinesSorted(filepath, prefixes, movementTypes);
|
readCDefinesSorted(filepath, prefixes, movementTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::readInitialFacingDirections() {
|
||||||
|
QString text = readTextFile(root + "/src/event_object_movement.c");
|
||||||
|
facingDirections = readNamedIndexCArray(text, "gInitialMovementTypeFacingDirections");
|
||||||
|
}
|
||||||
|
|
||||||
void Project::readMapTypes() {
|
void Project::readMapTypes() {
|
||||||
QString filepath = root + "/include/constants/map_types.h";
|
QString filepath = root + "/include/constants/map_types.h";
|
||||||
QStringList prefixes = (QStringList() << "MAP_TYPE_");
|
QStringList prefixes = (QStringList() << "MAP_TYPE_");
|
||||||
|
@ -1708,7 +1713,7 @@ void Project::loadEventPixmaps(QList<Event*> objects) {
|
||||||
spriteHeight = dimensionMatch.captured(2).toInt();
|
spriteHeight = dimensionMatch.captured(2).toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
object->setPixmapFromSpritesheet(spritesheet, spriteWidth, spriteHeight);
|
object->setPixmapFromSpritesheet(spritesheet, spriteWidth, spriteHeight, object->frame, object->hFlip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1760,6 +1765,25 @@ QStringList Project::readCArray(QString text, QString label) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> Project::readNamedIndexCArray(QString text, QString label) {
|
||||||
|
QMap<QString, QString> map;
|
||||||
|
|
||||||
|
QRegularExpression re_text(QString("\\b%1\\b\\s*\\[?\\s*\\]?\\s*=\\s*\\{([^\\}]*)\\}").arg(label));
|
||||||
|
text = re_text.match(text).captured(1).replace(QRegularExpression("\\s*"), "");
|
||||||
|
|
||||||
|
QRegularExpression re("\\[(?<index>[A-Za-z1-9_]*)\\]=(?<value>[A-Za-z1-9_]*)");
|
||||||
|
QRegularExpressionMatchIterator iter = re.globalMatch(text);
|
||||||
|
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = iter.next();
|
||||||
|
QString key = match.captured("index");
|
||||||
|
QString value = match.captured("value");
|
||||||
|
map.insert(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
QString Project::readCIncbin(QString text, QString label) {
|
QString Project::readCIncbin(QString text, QString label) {
|
||||||
QString path;
|
QString path;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue