lots of changes
|
@ -1,4 +1,5 @@
|
||||||
#include "blockdata.h"
|
#include "blockdata.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
Blockdata::Blockdata(QObject *parent) : QObject(parent)
|
Blockdata::Blockdata(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -37,3 +38,18 @@ Blockdata* Blockdata::copy() {
|
||||||
blockdata->copyFrom(this);
|
blockdata->copyFrom(this);
|
||||||
return blockdata;
|
return blockdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Blockdata::equals(Blockdata *other) {
|
||||||
|
if (!other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (blocks->length() != other->blocks->length()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < blocks->length(); i++) {
|
||||||
|
if (blocks->value(i) != other->blocks->value(i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -13,12 +13,13 @@ public:
|
||||||
explicit Blockdata(QObject *parent = 0);
|
explicit Blockdata(QObject *parent = 0);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<Block> *blocks;
|
QList<Block> *blocks = NULL;
|
||||||
void addBlock(uint16_t);
|
void addBlock(uint16_t);
|
||||||
void addBlock(Block);
|
void addBlock(Block);
|
||||||
QByteArray serialize();
|
QByteArray serialize();
|
||||||
void copyFrom(Blockdata*);
|
void copyFrom(Blockdata*);
|
||||||
Blockdata* copy();
|
Blockdata* copy();
|
||||||
|
bool equals(Blockdata *);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
422
editor.cpp
|
@ -1,8 +1,10 @@
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
Editor::Editor()
|
Editor::Editor()
|
||||||
{
|
{
|
||||||
|
selected_events = new QList<DraggablePixmapItem*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::saveProject() {
|
void Editor::saveProject() {
|
||||||
|
@ -31,53 +33,111 @@ void Editor::redo() {
|
||||||
|
|
||||||
void Editor::setEditingMap() {
|
void Editor::setEditingMap() {
|
||||||
current_view = map_item;
|
current_view = map_item;
|
||||||
map_item->draw();
|
if (map_item) {
|
||||||
map_item->setVisible(true);
|
map_item->draw();
|
||||||
map_item->setEnabled(true);
|
map_item->setVisible(true);
|
||||||
collision_item->setVisible(false);
|
map_item->setEnabled(true);
|
||||||
objects_group->setVisible(false);
|
}
|
||||||
|
if (collision_item) {
|
||||||
|
collision_item->setVisible(false);
|
||||||
|
}
|
||||||
|
if (objects_group) {
|
||||||
|
objects_group->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setEditingCollision() {
|
void Editor::setEditingCollision() {
|
||||||
current_view = collision_item;
|
current_view = collision_item;
|
||||||
collision_item->draw();
|
if (collision_item) {
|
||||||
collision_item->setVisible(true);
|
collision_item->draw();
|
||||||
map_item->setVisible(false);
|
collision_item->setVisible(true);
|
||||||
objects_group->setVisible(false);
|
}
|
||||||
|
if (map_item) {
|
||||||
|
map_item->setVisible(false);
|
||||||
|
}
|
||||||
|
if (objects_group) {
|
||||||
|
objects_group->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setEditingObjects() {
|
void Editor::setEditingObjects() {
|
||||||
objects_group->setVisible(true);
|
current_view = map_item;
|
||||||
map_item->setVisible(true);
|
if (objects_group) {
|
||||||
map_item->setEnabled(false);
|
objects_group->setVisible(true);
|
||||||
collision_item->setVisible(false);
|
}
|
||||||
|
if (map_item) {
|
||||||
|
map_item->setVisible(true);
|
||||||
|
map_item->setEnabled(false);
|
||||||
|
}
|
||||||
|
if (collision_item) {
|
||||||
|
collision_item->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setMap(QString map_name) {
|
void Editor::setMap(QString map_name) {
|
||||||
if (map_name.isNull()) {
|
if (map_name.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
map = project->getMap(map_name);
|
if (project) {
|
||||||
displayMap();
|
map = project->loadMap(map_name);
|
||||||
|
displayMap();
|
||||||
|
selected_events->clear();
|
||||||
|
updateSelectedObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
||||||
|
if (map_edit_mode == "paint") {
|
||||||
|
item->paint(event);
|
||||||
|
} else if (map_edit_mode == "fill") {
|
||||||
|
item->floodFill(event);
|
||||||
|
} else if (map_edit_mode == "pick") {
|
||||||
|
item->pick(event);
|
||||||
|
} else if (map_edit_mode == "select") {
|
||||||
|
item->select(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
|
||||||
|
if (map_edit_mode == "paint") {
|
||||||
|
item->paint(event);
|
||||||
|
} else if (map_edit_mode == "fill") {
|
||||||
|
item->floodFill(event);
|
||||||
|
} else if (map_edit_mode == "pick") {
|
||||||
|
item->pick(event);
|
||||||
|
} else if (map_edit_mode == "select") {
|
||||||
|
item->select(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::displayMap() {
|
void Editor::displayMap() {
|
||||||
scene = new QGraphicsScene;
|
scene = new QGraphicsScene;
|
||||||
|
|
||||||
map_item = new MapPixmapItem(map);
|
map_item = new MapPixmapItem(map);
|
||||||
|
connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
|
||||||
|
this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
||||||
|
|
||||||
map_item->draw();
|
map_item->draw();
|
||||||
scene->addItem(map_item);
|
scene->addItem(map_item);
|
||||||
|
|
||||||
collision_item = new CollisionPixmapItem(map);
|
collision_item = new CollisionPixmapItem(map);
|
||||||
|
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
|
||||||
|
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
||||||
|
|
||||||
collision_item->draw();
|
collision_item->draw();
|
||||||
scene->addItem(collision_item);
|
scene->addItem(collision_item);
|
||||||
|
|
||||||
objects_group = new QGraphicsItemGroup;
|
objects_group = new EventGroup;
|
||||||
scene->addItem(objects_group);
|
scene->addItem(objects_group);
|
||||||
|
|
||||||
map_item->setVisible(false);
|
if (map_item) {
|
||||||
collision_item->setVisible(false);
|
map_item->setVisible(false);
|
||||||
objects_group->setVisible(false);
|
}
|
||||||
|
if (collision_item) {
|
||||||
|
collision_item->setVisible(false);
|
||||||
|
}
|
||||||
|
if (objects_group) {
|
||||||
|
objects_group->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
int tw = 16;
|
int tw = 16;
|
||||||
int th = 16;
|
int th = 16;
|
||||||
|
@ -122,13 +182,22 @@ void Editor::displayMapObjects() {
|
||||||
objects_group->removeFromGroup(child);
|
objects_group->removeFromGroup(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
project->loadObjectPixmaps(map->object_events);
|
QList<Event *> events = map->getAllEvents();
|
||||||
for (int i = 0; i < map->object_events.length(); i++) {
|
project->loadObjectPixmaps(events);
|
||||||
ObjectEvent *object_event = map->object_events.value(i);
|
for (Event *event : events) {
|
||||||
DraggablePixmapItem *object = new DraggablePixmapItem(object_event);
|
addMapObject(event);
|
||||||
objects_group->addToGroup(object);
|
|
||||||
}
|
}
|
||||||
objects_group->setFiltersChildEvents(false);
|
//objects_group->setFiltersChildEvents(false);
|
||||||
|
objects_group->setHandlesChildEvents(false);
|
||||||
|
|
||||||
|
emit objectsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
DraggablePixmapItem *Editor::addMapObject(Event *event) {
|
||||||
|
DraggablePixmapItem *object = new DraggablePixmapItem(event);
|
||||||
|
object->editor = this;
|
||||||
|
objects_group->addToGroup(object);
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::displayMapConnections() {
|
void Editor::displayMapConnections() {
|
||||||
|
@ -139,7 +208,7 @@ void Editor::displayMapConnections() {
|
||||||
Map *connected_map = project->getMap(connection->map_name);
|
Map *connected_map = project->getMap(connection->map_name);
|
||||||
QPixmap pixmap = connected_map->renderConnection(*connection);
|
QPixmap pixmap = connected_map->renderConnection(*connection);
|
||||||
int offset = connection->offset.toInt(nullptr, 0);
|
int offset = connection->offset.toInt(nullptr, 0);
|
||||||
int x, y;
|
int x = 0, y = 0;
|
||||||
if (connection->direction == "up") {
|
if (connection->direction == "up") {
|
||||||
x = offset * 16;
|
x = offset * 16;
|
||||||
y = -pixmap.height();
|
y = -pixmap.height();
|
||||||
|
@ -154,6 +223,7 @@ void Editor::displayMapConnections() {
|
||||||
y = offset * 16;
|
y = offset * 16;
|
||||||
}
|
}
|
||||||
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
||||||
|
item->setZValue(-1);
|
||||||
item->setX(x);
|
item->setX(x);
|
||||||
item->setY(y);
|
item->setY(y);
|
||||||
scene->addItem(item);
|
scene->addItem(item);
|
||||||
|
@ -167,11 +237,14 @@ void Editor::displayMapBorder() {
|
||||||
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
||||||
item->setX(x * 16);
|
item->setX(x * 16);
|
||||||
item->setY(y * 16);
|
item->setY(y * 16);
|
||||||
item->setZValue(-1);
|
item->setZValue(-2);
|
||||||
scene->addItem(item);
|
scene->addItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
void MetatilesPixmapItem::draw() {
|
void MetatilesPixmapItem::draw() {
|
||||||
setPixmap(map->renderMetatiles());
|
setPixmap(map->renderMetatiles());
|
||||||
|
@ -179,7 +252,7 @@ void MetatilesPixmapItem::draw() {
|
||||||
|
|
||||||
void MetatilesPixmapItem::pick(uint tile) {
|
void MetatilesPixmapItem::pick(uint tile) {
|
||||||
map->paint_tile = tile;
|
map->paint_tile = tile;
|
||||||
draw();
|
emit map->paintTileChanged(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
@ -193,6 +266,9 @@ void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
pick(y * width + x);
|
pick(y * width + x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
mousePressEvent(event);
|
||||||
|
}
|
||||||
void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
mousePressEvent(event);
|
mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +282,10 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
Block *block = map->getBlock(x, y);
|
Block *block = map->getBlock(x, y);
|
||||||
if (block) {
|
if (block) {
|
||||||
block->tile = map->paint_tile;
|
block->tile = map->paint_tile;
|
||||||
map->setBlock(x, y, *block);
|
map->_setBlock(x, y, *block);
|
||||||
|
}
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
map->commit();
|
||||||
}
|
}
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
@ -222,45 +301,95 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapPixmapItem::draw() {
|
void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||||
setPixmap(map->render());
|
QPointF pos = event->pos();
|
||||||
}
|
int x = (int)(pos.x()) / 16;
|
||||||
|
int y = (int)(pos.y()) / 16;
|
||||||
void MapPixmapItem::undo() {
|
Block *block = map->getBlock(x, y);
|
||||||
map->undo();
|
if (block) {
|
||||||
draw();
|
map->paint_tile = block->tile;
|
||||||
}
|
emit map->paintTileChanged(map);
|
||||||
|
|
||||||
void MapPixmapItem::redo() {
|
|
||||||
map->redo();
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
|
||||||
active = true;
|
|
||||||
if (event->button() == Qt::RightButton) {
|
|
||||||
right_click = true;
|
|
||||||
floodFill(event);
|
|
||||||
} else {
|
|
||||||
right_click = false;
|
|
||||||
paint(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|
||||||
if (active) {
|
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
||||||
if (right_click) {
|
|
||||||
floodFill(event);
|
void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
||||||
} else {
|
QPointF pos = event->pos();
|
||||||
paint(event);
|
int x = (int)(pos.x()) / 16;
|
||||||
|
int y = (int)(pos.y()) / 16;
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||||
|
selection_origin = QPoint(x, y);
|
||||||
|
selection.clear();
|
||||||
|
} else if (event->type() == QEvent::GraphicsSceneMouseMove) {
|
||||||
|
if (event->buttons() & Qt::LeftButton) {
|
||||||
|
selection.clear();
|
||||||
|
selection.append(QPoint(x, y));
|
||||||
|
}
|
||||||
|
} else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
if (!selection.isEmpty()) {
|
||||||
|
QPoint pos = selection.last();
|
||||||
|
int x1 = selection_origin.x();
|
||||||
|
int y1 = selection_origin.y();
|
||||||
|
int x2 = pos.x();
|
||||||
|
int y2 = pos.y();
|
||||||
|
if (x1 > x2) SWAP(x1, x2);
|
||||||
|
if (y1 > y2) SWAP(y1, y2);
|
||||||
|
selection.clear();
|
||||||
|
for (int y = y1; y <= y2; y++) {
|
||||||
|
for (int x = x1; x <= x2; x++) {
|
||||||
|
selection.append(QPoint(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << QString("selected (%1, %2) -> (%3, %4)").arg(x1).arg(y1).arg(x2).arg(y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapPixmapItem::draw() {
|
||||||
|
if (map) {
|
||||||
|
setPixmap(map->render());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapPixmapItem::undo() {
|
||||||
|
if (map) {
|
||||||
|
map->undo();
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapPixmapItem::redo() {
|
||||||
|
if (map) {
|
||||||
|
map->redo();
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
emit mouseEvent(event, this);
|
||||||
|
}
|
||||||
|
void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
emit mouseEvent(event, this);
|
||||||
|
}
|
||||||
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
active = false;
|
emit mouseEvent(event, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
emit mouseEvent(event, this);
|
||||||
|
}
|
||||||
|
void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
emit mouseEvent(event, this);
|
||||||
|
}
|
||||||
|
void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionPixmapItem::draw() {
|
void CollisionPixmapItem::draw() {
|
||||||
setPixmap(map->renderCollision());
|
if (map) {
|
||||||
|
setPixmap(map->renderCollision());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
|
@ -276,7 +405,10 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
if (map->paint_elevation >= 0) {
|
if (map->paint_elevation >= 0) {
|
||||||
block->elevation = map->paint_elevation;
|
block->elevation = map->paint_elevation;
|
||||||
}
|
}
|
||||||
map->setBlock(x, y, *block);
|
map->_setBlock(x, y, *block);
|
||||||
|
}
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
map->commit();
|
||||||
}
|
}
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
@ -300,25 +432,177 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||||
|
QPointF pos = event->pos();
|
||||||
|
int x = (int)(pos.x()) / 16;
|
||||||
|
int y = (int)(pos.y()) / 16;
|
||||||
|
Block *block = map->getBlock(x, y);
|
||||||
|
if (block) {
|
||||||
|
map->paint_collision = block->collision;
|
||||||
|
map->paint_elevation = block->elevation;
|
||||||
|
emit map->paintCollisionChanged(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
active = true;
|
active = true;
|
||||||
last_x = mouse->pos().x() / 16;
|
clicking = true;
|
||||||
last_y = mouse->pos().y() / 16;
|
last_x = (mouse->pos().x() + this->pos().x()) / 16;
|
||||||
qDebug() << event->x_ + ", " + event->y_;
|
last_y = (mouse->pos().y() + this->pos().y()) / 16;
|
||||||
|
//qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("y"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DraggablePixmapItem::move(int x, int y) {
|
||||||
|
event->setX(event->x() + x);
|
||||||
|
event->setY(event->y() + y);
|
||||||
|
updatePosition();
|
||||||
|
emitPositionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
if (active) {
|
if (active) {
|
||||||
int x = mouse->pos().x() / 16;
|
int x = (mouse->pos().x() + this->pos().x()) / 16;
|
||||||
int y = mouse->pos().y() / 16;
|
int y = (mouse->pos().y() + this->pos().y()) / 16;
|
||||||
if (x != last_x || y != last_y) {
|
if (x != last_x || y != last_y) {
|
||||||
event->setX(event->x() + x - last_x);
|
clicking = false;
|
||||||
event->setY(event->y() + y - last_y);
|
if (editor->selected_events->contains(this)) {
|
||||||
update();
|
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||||
|
item->move(x - last_x, y - last_y);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
move(x - last_x, y - last_y);
|
||||||
|
}
|
||||||
|
last_x = x;
|
||||||
|
last_y = y;
|
||||||
|
//qDebug() << QString("(%1, %2)").arg(event->get("x")).arg(event->get("x"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
|
if (clicking) {
|
||||||
|
this->editor->selectMapObject(this, mouse->modifiers() & Qt::ControlModifier);
|
||||||
|
this->editor->updateSelectedObjects();
|
||||||
|
}
|
||||||
active = false;
|
active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<DraggablePixmapItem *> *Editor::getObjects() {
|
||||||
|
QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
|
||||||
|
for (Event *event : map->getAllEvents()) {
|
||||||
|
for (QGraphicsItem *child : objects_group->childItems()) {
|
||||||
|
DraggablePixmapItem *item = (DraggablePixmapItem *)child;
|
||||||
|
if (item->event == event) {
|
||||||
|
list->append(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::redrawObject(DraggablePixmapItem *item) {
|
||||||
|
if (item) {
|
||||||
|
item->setPixmap(item->event->pixmap);
|
||||||
|
if (selected_events && selected_events->contains(item)) {
|
||||||
|
QImage image = item->pixmap().toImage();
|
||||||
|
QPainter painter(&image);
|
||||||
|
painter.setPen(QColor(250, 100, 25));
|
||||||
|
painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
|
||||||
|
painter.end();
|
||||||
|
item->setPixmap(QPixmap::fromImage(image));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::updateSelectedObjects() {
|
||||||
|
for (DraggablePixmapItem *item : *(getObjects())) {
|
||||||
|
redrawObject(item);
|
||||||
|
}
|
||||||
|
emit selectedObjectsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::selectMapObject(DraggablePixmapItem *object) {
|
||||||
|
selectMapObject(object, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::selectMapObject(DraggablePixmapItem *object, bool toggle) {
|
||||||
|
if (selected_events && object) {
|
||||||
|
if (selected_events->contains(object)) {
|
||||||
|
if (toggle) {
|
||||||
|
selected_events->removeOne(object);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!toggle) {
|
||||||
|
selected_events->clear();
|
||||||
|
}
|
||||||
|
selected_events->append(object);
|
||||||
|
}
|
||||||
|
updateSelectedObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DraggablePixmapItem* Editor::addNewEvent() {
|
||||||
|
return addNewEvent("object");
|
||||||
|
}
|
||||||
|
|
||||||
|
DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
|
||||||
|
if (project && map) {
|
||||||
|
Event *event = new Event;
|
||||||
|
event->put("map_name", map->name);
|
||||||
|
event->put("event_type", event_type);
|
||||||
|
map->addEvent(event);
|
||||||
|
project->loadObjectPixmaps(map->getAllEvents());
|
||||||
|
DraggablePixmapItem *object = addMapObject(event);
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::deleteEvent(Event *event) {
|
||||||
|
Map *map = project->getMap(event->get("map_name"));
|
||||||
|
if (map) {
|
||||||
|
map->removeEvent(event);
|
||||||
|
}
|
||||||
|
//selected_events->removeAll(event);
|
||||||
|
//updateSelectedObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// dunno how to detect bubbling. QMouseEvent::isAccepted seems to always be true
|
||||||
|
// check if selected_events changed instead. this has the side effect of deselecting
|
||||||
|
// when you click on a selected event, since selected_events doesn't change.
|
||||||
|
|
||||||
|
QList<DraggablePixmapItem *> selected_events_test;
|
||||||
|
bool clicking = false;
|
||||||
|
|
||||||
|
void Editor::objectsView_onMousePress(QMouseEvent *event) {
|
||||||
|
clicking = true;
|
||||||
|
selected_events_test = *selected_events;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::objectsView_onMouseMove(QMouseEvent *event) {
|
||||||
|
clicking = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::objectsView_onMouseRelease(QMouseEvent *event) {
|
||||||
|
if (clicking) {
|
||||||
|
if (selected_events_test.length()) {
|
||||||
|
if (selected_events_test.length() == selected_events->length()) {
|
||||||
|
bool deselect = true;
|
||||||
|
for (int i = 0; i < selected_events_test.length(); i++) {
|
||||||
|
if (selected_events_test.at(i) != selected_events->at(i)) {
|
||||||
|
deselect = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (deselect) {
|
||||||
|
selected_events->clear();
|
||||||
|
updateSelectedObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clicking = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
375
editor.h
|
@ -4,123 +4,27 @@
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsItemGroup>
|
#include <QGraphicsItemGroup>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QGraphicsItemAnimation>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
|
||||||
|
class DraggablePixmapItem;
|
||||||
|
class MapPixmapItem;
|
||||||
|
class CollisionPixmapItem;
|
||||||
|
class MetatilesPixmapItem;
|
||||||
|
class CollisionMetatilesPixmapItem;
|
||||||
|
class ElevationMetatilesPixmapItem;
|
||||||
|
|
||||||
class DraggablePixmapItem : public QGraphicsPixmapItem {
|
class Editor : public QObject
|
||||||
public:
|
|
||||||
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
|
||||||
}
|
|
||||||
Event *event;
|
|
||||||
DraggablePixmapItem(Event *event_) : QGraphicsPixmapItem(event_->pixmap) {
|
|
||||||
event = event_;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
bool active;
|
|
||||||
bool right_click;
|
|
||||||
int last_x;
|
|
||||||
int last_y;
|
|
||||||
void update() {
|
|
||||||
int x = event->x() * 16;
|
|
||||||
int y = event->y() * 16;
|
|
||||||
x -= pixmap().width() / 32 * 16;
|
|
||||||
y -= pixmap().height() - 16;
|
|
||||||
setX(x);
|
|
||||||
setY(y);
|
|
||||||
setZValue(event->y());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
};
|
|
||||||
|
|
||||||
class MapPixmapItem : public QGraphicsPixmapItem {
|
|
||||||
public:
|
|
||||||
MapPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
|
||||||
}
|
|
||||||
Map *map;
|
|
||||||
MapPixmapItem(Map *map_) {
|
|
||||||
map = map_;
|
|
||||||
}
|
|
||||||
bool active;
|
|
||||||
bool right_click;
|
|
||||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
|
||||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
|
||||||
virtual void undo();
|
|
||||||
virtual void redo();
|
|
||||||
virtual void draw();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
};
|
|
||||||
|
|
||||||
class CollisionPixmapItem : public MapPixmapItem {
|
|
||||||
public:
|
|
||||||
CollisionPixmapItem(QPixmap pixmap): MapPixmapItem(pixmap) {
|
|
||||||
}
|
|
||||||
CollisionPixmapItem(Map *map_): MapPixmapItem(map_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
|
||||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
|
||||||
virtual void draw();
|
|
||||||
};
|
|
||||||
|
|
||||||
class MetatilesPixmapItem : public QGraphicsPixmapItem {
|
|
||||||
public:
|
|
||||||
MetatilesPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
|
||||||
}
|
|
||||||
MetatilesPixmapItem(Map *map_) {
|
|
||||||
map = map_;
|
|
||||||
}
|
|
||||||
Map* map;
|
|
||||||
virtual void pick(uint);
|
|
||||||
virtual void draw();
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
};
|
|
||||||
|
|
||||||
class CollisionMetatilesPixmapItem : public MetatilesPixmapItem {
|
|
||||||
public:
|
|
||||||
CollisionMetatilesPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
|
|
||||||
}
|
|
||||||
virtual void pick(uint collision) {
|
|
||||||
map->paint_collision = collision;
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
virtual void draw() {
|
|
||||||
setPixmap(map->renderCollisionMetatiles());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class ElevationMetatilesPixmapItem : public MetatilesPixmapItem {
|
|
||||||
public:
|
|
||||||
ElevationMetatilesPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
|
|
||||||
}
|
|
||||||
virtual void pick(uint elevation) {
|
|
||||||
map->paint_elevation = elevation;
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
virtual void draw() {
|
|
||||||
setPixmap(map->renderElevationMetatiles());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Editor
|
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Editor();
|
Editor();
|
||||||
public:
|
public:
|
||||||
Project *project;
|
QObject *parent = NULL;
|
||||||
Map *map;
|
Project *project = NULL;
|
||||||
|
Map *map = NULL;
|
||||||
void saveProject();
|
void saveProject();
|
||||||
void save();
|
void save();
|
||||||
void undo();
|
void undo();
|
||||||
|
@ -138,18 +42,249 @@ public:
|
||||||
void setEditingCollision();
|
void setEditingCollision();
|
||||||
void setEditingObjects();
|
void setEditingObjects();
|
||||||
|
|
||||||
QGraphicsScene *scene;
|
DraggablePixmapItem *addMapObject(Event *event);
|
||||||
QGraphicsPixmapItem *current_view;
|
void selectMapObject(DraggablePixmapItem *object);
|
||||||
MapPixmapItem *map_item;
|
void selectMapObject(DraggablePixmapItem *object, bool toggle);
|
||||||
CollisionPixmapItem *collision_item;
|
DraggablePixmapItem *addNewEvent();
|
||||||
QGraphicsItemGroup *objects_group;
|
DraggablePixmapItem *addNewEvent(QString event_type);
|
||||||
|
void deleteEvent(Event *);
|
||||||
|
void updateSelectedObjects();
|
||||||
|
void redrawObject(DraggablePixmapItem *item);
|
||||||
|
QList<DraggablePixmapItem *> *getObjects();
|
||||||
|
|
||||||
QGraphicsScene *scene_metatiles;
|
QGraphicsScene *scene = NULL;
|
||||||
QGraphicsScene *scene_collision_metatiles;
|
QGraphicsPixmapItem *current_view = NULL;
|
||||||
QGraphicsScene *scene_elevation_metatiles;
|
MapPixmapItem *map_item = NULL;
|
||||||
MetatilesPixmapItem *metatiles_item;
|
CollisionPixmapItem *collision_item = NULL;
|
||||||
CollisionMetatilesPixmapItem *collision_metatiles_item;
|
QGraphicsItemGroup *objects_group = NULL;
|
||||||
ElevationMetatilesPixmapItem *elevation_metatiles_item;
|
|
||||||
|
QGraphicsScene *scene_metatiles = NULL;
|
||||||
|
QGraphicsScene *scene_collision_metatiles = NULL;
|
||||||
|
QGraphicsScene *scene_elevation_metatiles = NULL;
|
||||||
|
MetatilesPixmapItem *metatiles_item = NULL;
|
||||||
|
CollisionMetatilesPixmapItem *collision_metatiles_item = NULL;
|
||||||
|
ElevationMetatilesPixmapItem *elevation_metatiles_item = NULL;
|
||||||
|
|
||||||
|
QList<DraggablePixmapItem*> *events = NULL;
|
||||||
|
QList<DraggablePixmapItem*> *selected_events = NULL;
|
||||||
|
|
||||||
|
QString map_edit_mode;
|
||||||
|
|
||||||
|
void objectsView_onMousePress(QMouseEvent *event);
|
||||||
|
void objectsView_onMouseMove(QMouseEvent *event);
|
||||||
|
void objectsView_onMouseRelease(QMouseEvent *event);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
|
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void objectsChanged();
|
||||||
|
void selectedObjectsChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
||||||
|
}
|
||||||
|
Editor *editor = NULL;
|
||||||
|
Event *event = NULL;
|
||||||
|
QGraphicsItemAnimation *pos_anim = NULL;
|
||||||
|
DraggablePixmapItem(Event *event_) : QGraphicsPixmapItem(event_->pixmap) {
|
||||||
|
event = event_;
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
bool active;
|
||||||
|
bool right_click;
|
||||||
|
bool clicking;
|
||||||
|
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;
|
||||||
|
setX(x);
|
||||||
|
setY(y);
|
||||||
|
setZValue(event->y());
|
||||||
|
}
|
||||||
|
void move(int x, int y);
|
||||||
|
void emitPositionChanged() {
|
||||||
|
emit xChanged(event->x());
|
||||||
|
emit yChanged(event->y());
|
||||||
|
emit elevationChanged(event->elevation());
|
||||||
|
}
|
||||||
|
void updatePixmap() {
|
||||||
|
QList<Event*> objects;
|
||||||
|
objects.append(event);
|
||||||
|
event->pixmap = QPixmap();
|
||||||
|
editor->project->loadObjectPixmaps(objects);
|
||||||
|
editor->redrawObject(this);
|
||||||
|
emit spriteChanged(event->pixmap);
|
||||||
|
}
|
||||||
|
void bind(QComboBox *combo, QString key) {
|
||||||
|
connect(combo, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
||||||
|
this, [this, key](QString value){
|
||||||
|
this->event->put(key, value);
|
||||||
|
});
|
||||||
|
connect(this, &DraggablePixmapItem::onPropertyChanged,
|
||||||
|
this, [combo, key](QString key2, QString value){
|
||||||
|
if (key2 == key) {
|
||||||
|
combo->addItem(value);
|
||||||
|
combo->setCurrentText(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void positionChanged(Event *event);
|
||||||
|
void xChanged(int);
|
||||||
|
void yChanged(int);
|
||||||
|
void elevationChanged(int);
|
||||||
|
void spriteChanged(QPixmap pixmap);
|
||||||
|
void onPropertyChanged(QString key, QString value);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void set_x(const QString &text) {
|
||||||
|
event->put("x", text);
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
void set_y(const QString &text) {
|
||||||
|
event->put("y", text);
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
void set_elevation(const QString &text) {
|
||||||
|
event->put("elevation", text);
|
||||||
|
updatePosition();
|
||||||
|
}
|
||||||
|
void set_sprite(const QString &text) {
|
||||||
|
event->put("sprite", text);
|
||||||
|
updatePixmap();
|
||||||
|
}
|
||||||
|
void set_script(const QString &text) {
|
||||||
|
event->put("script_label", text);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
};
|
||||||
|
|
||||||
|
class EventGroup : public QGraphicsItemGroup {
|
||||||
|
};
|
||||||
|
|
||||||
|
class MapPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MapPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
||||||
|
}
|
||||||
|
Map *map = NULL;
|
||||||
|
MapPixmapItem(Map *map_) {
|
||||||
|
map = map_;
|
||||||
|
}
|
||||||
|
bool active;
|
||||||
|
bool right_click;
|
||||||
|
QPoint selection_origin;
|
||||||
|
QList<QPoint> selection;
|
||||||
|
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void select(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
virtual void draw();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void mouseEvent(QGraphicsSceneMouseEvent *, MapPixmapItem *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
};
|
||||||
|
|
||||||
|
class CollisionPixmapItem : public MapPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CollisionPixmapItem(QPixmap pixmap): MapPixmapItem(pixmap) {
|
||||||
|
}
|
||||||
|
CollisionPixmapItem(Map *map_): MapPixmapItem(map_) {
|
||||||
|
}
|
||||||
|
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void draw();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
};
|
||||||
|
|
||||||
|
class MetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MetatilesPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
||||||
|
}
|
||||||
|
MetatilesPixmapItem(Map *map_) {
|
||||||
|
map = map_;
|
||||||
|
connect(map, SIGNAL(paintTileChanged(Map*)), this, SLOT(paintTileChanged(Map *)));
|
||||||
|
}
|
||||||
|
Map* map = NULL;
|
||||||
|
virtual void pick(uint);
|
||||||
|
virtual void draw();
|
||||||
|
private slots:
|
||||||
|
void paintTileChanged(Map *map);
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
};
|
||||||
|
|
||||||
|
class CollisionMetatilesPixmapItem : public MetatilesPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CollisionMetatilesPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
|
||||||
|
connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
|
||||||
|
}
|
||||||
|
virtual void pick(uint collision) {
|
||||||
|
map->paint_collision = collision;
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
virtual void draw() {
|
||||||
|
setPixmap(map->renderCollisionMetatiles());
|
||||||
|
}
|
||||||
|
private slots:
|
||||||
|
void paintCollisionChanged(Map *map) {
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ElevationMetatilesPixmapItem : public MetatilesPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ElevationMetatilesPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
|
||||||
|
connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
|
||||||
|
}
|
||||||
|
virtual void pick(uint elevation) {
|
||||||
|
map->paint_elevation = elevation;
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
virtual void draw() {
|
||||||
|
setPixmap(map->renderElevationMetatiles());
|
||||||
|
}
|
||||||
|
private slots:
|
||||||
|
void paintCollisionChanged(Map *map) {
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // EDITOR_H
|
#endif // EDITOR_H
|
||||||
|
|
47
event.cpp
|
@ -2,51 +2,4 @@
|
||||||
|
|
||||||
Event::Event()
|
Event::Event()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectEvent::ObjectEvent()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Warp::Warp()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
CoordEvent::CoordEvent()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BGEvent::BGEvent()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Sign::Sign()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Sign::Sign(const BGEvent &bg)
|
|
||||||
{
|
|
||||||
x_ = bg.x_;
|
|
||||||
y_ = bg.y_;
|
|
||||||
elevation_ = bg.elevation_;
|
|
||||||
type = bg.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
HiddenItem::HiddenItem()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
HiddenItem::HiddenItem(const BGEvent &bg)
|
|
||||||
{
|
|
||||||
x_ = bg.x_;
|
|
||||||
y_ = bg.y_;
|
|
||||||
elevation_ = bg.elevation_;
|
|
||||||
type = bg.type;
|
|
||||||
}
|
}
|
||||||
|
|
96
event.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
class Event
|
class Event
|
||||||
{
|
{
|
||||||
|
@ -11,90 +12,39 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int x() {
|
int x() {
|
||||||
return x_.toInt(nullptr, 0);
|
return getInt("x");
|
||||||
}
|
}
|
||||||
int y() {
|
int y() {
|
||||||
return y_.toInt(nullptr, 0);
|
return getInt("y");
|
||||||
}
|
}
|
||||||
int elevation() {
|
int elevation() {
|
||||||
return elevation_.toInt(nullptr, 0);
|
return getInt("elevation");
|
||||||
}
|
}
|
||||||
void setX(int x) {
|
void setX(int x) {
|
||||||
x_ = QString("%1").arg(x);
|
put("x", x);
|
||||||
}
|
}
|
||||||
void setY(int y) {
|
void setY(int y) {
|
||||||
y_ = QString("%1").arg(y);
|
put("y", y);
|
||||||
|
}
|
||||||
|
QString get(QString key) {
|
||||||
|
return values.value(key);
|
||||||
|
}
|
||||||
|
int getInt(QString key) {
|
||||||
|
return values.value(key).toInt(nullptr, 0);
|
||||||
|
}
|
||||||
|
void put(QString key, int value) {
|
||||||
|
put(key, QString("%1").arg(value));
|
||||||
|
}
|
||||||
|
void put(QString key, QString value) {
|
||||||
|
values.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString x_;
|
bool is_hidden_item() {
|
||||||
QString y_;
|
return getInt("type") >= 5;
|
||||||
QString elevation_;
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> values;
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ObjectEvent : public Event {
|
|
||||||
public:
|
|
||||||
ObjectEvent();
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString sprite;
|
|
||||||
QString replacement; // ????
|
|
||||||
QString behavior;
|
|
||||||
QString radius_x;
|
|
||||||
QString radius_y;
|
|
||||||
QString property;
|
|
||||||
QString sight_radius;
|
|
||||||
QString script_label;
|
|
||||||
QString event_flag;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Warp : public Event {
|
|
||||||
public:
|
|
||||||
Warp();
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString destination_warp;
|
|
||||||
QString destination_map;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CoordEvent : public Event {
|
|
||||||
public:
|
|
||||||
CoordEvent();
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString unknown1;
|
|
||||||
QString unknown2;
|
|
||||||
QString unknown3;
|
|
||||||
QString unknown4;
|
|
||||||
QString script_label;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BGEvent : public Event {
|
|
||||||
public:
|
|
||||||
BGEvent();
|
|
||||||
public:
|
|
||||||
bool is_item() {
|
|
||||||
return type.toInt(nullptr, 0) >= 5;
|
|
||||||
}
|
|
||||||
QString type;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Sign : public BGEvent {
|
|
||||||
public:
|
|
||||||
Sign();
|
|
||||||
Sign(const BGEvent&);
|
|
||||||
public:
|
|
||||||
QString script_label;
|
|
||||||
};
|
|
||||||
|
|
||||||
class HiddenItem : public BGEvent {
|
|
||||||
public:
|
|
||||||
HiddenItem();
|
|
||||||
HiddenItem(const BGEvent&);
|
|
||||||
public:
|
|
||||||
QString item;
|
|
||||||
QString unknown5;
|
|
||||||
QString unknown6;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EVENT_H
|
#endif // EVENT_H
|
||||||
|
|
22
graphicsview.cpp
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#include "graphicsview.h"
|
||||||
|
|
||||||
|
void GraphicsView::mousePressEvent(QMouseEvent *event) {
|
||||||
|
QGraphicsView::mousePressEvent(event);
|
||||||
|
if (editor) {
|
||||||
|
editor->objectsView_onMousePress(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsView::mouseMoveEvent(QMouseEvent *event) {
|
||||||
|
QGraphicsView::mouseMoveEvent(event);
|
||||||
|
if (editor) {
|
||||||
|
editor->objectsView_onMouseMove(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsView::mouseReleaseEvent(QMouseEvent *event) {
|
||||||
|
QGraphicsView::mouseReleaseEvent(event);
|
||||||
|
if (editor) {
|
||||||
|
editor->objectsView_onMouseRelease(event);
|
||||||
|
}
|
||||||
|
}
|
38
graphicsview.h
Executable file
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef GRAPHICSVIEW_H
|
||||||
|
#define GRAPHICSVIEW_H
|
||||||
|
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
#include "editor.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
class GraphicsView_Object : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void onMousePress(QMouseEvent *event);
|
||||||
|
void onMouseMove(QMouseEvent *event);
|
||||||
|
void onMouseRelease(QMouseEvent *event);
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
class GraphicsView : public QGraphicsView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GraphicsView() : QGraphicsView() {}
|
||||||
|
GraphicsView(QWidget *parent) : QGraphicsView(parent) {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// GraphicsView_Object object;
|
||||||
|
Editor *editor = NULL;
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
|
//Q_DECLARE_METATYPE(GraphicsView)
|
||||||
|
|
||||||
|
#endif // GRAPHICSVIEW_H
|
365
mainwindow.cpp
|
@ -1,12 +1,20 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
#include "editor.h"
|
||||||
|
#include "objectpropertiesframe.h"
|
||||||
|
#include "ui_objectpropertiesframe.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QSpacerItem>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QScrollBar>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
|
@ -15,16 +23,23 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
QCoreApplication::setOrganizationName("pret");
|
QCoreApplication::setOrganizationName("pret");
|
||||||
QCoreApplication::setApplicationName("pretmap");
|
QCoreApplication::setApplicationName("pretmap");
|
||||||
|
|
||||||
editor = new Editor;
|
|
||||||
|
|
||||||
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
|
||||||
|
|
||||||
|
editor = new Editor;
|
||||||
|
connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
|
||||||
|
connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
|
||||||
|
|
||||||
|
on_toolButton_Paint_clicked();
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString key = "recent_projects";
|
QString key = "recent_projects";
|
||||||
if (settings.contains(key)) {
|
if (settings.contains(key)) {
|
||||||
QString default_dir = settings.value(key).toStringList().last();
|
QString default_dir = settings.value(key).toStringList().last();
|
||||||
openProject(default_dir);
|
if (!default_dir.isNull()) {
|
||||||
|
qDebug() << QString("default_dir: '%1'").arg(default_dir);
|
||||||
|
openProject(default_dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,35 +49,53 @@ MainWindow::~MainWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openProject(QString dir) {
|
void MainWindow::openProject(QString dir) {
|
||||||
bool already_open = (editor->project != NULL) && (editor->project->root == dir);
|
if (dir.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool already_open = (
|
||||||
|
(editor != NULL && editor != nullptr)
|
||||||
|
&& (editor->project != NULL && editor->project != nullptr)
|
||||||
|
&& (editor->project->root == dir)
|
||||||
|
);
|
||||||
if (!already_open) {
|
if (!already_open) {
|
||||||
editor->project = new Project;
|
editor->project = new Project;
|
||||||
editor->project->root = dir;
|
editor->project->root = dir;
|
||||||
|
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
||||||
populateMapList();
|
populateMapList();
|
||||||
setMap(getDefaultMap());
|
setMap(getDefaultMap());
|
||||||
} else {
|
} else {
|
||||||
|
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
||||||
populateMapList();
|
populateMapList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::getDefaultMap() {
|
QString MainWindow::getDefaultMap() {
|
||||||
QSettings settings;
|
if (editor && editor->project) {
|
||||||
QString key = "project:" + editor->project->root;
|
QList<QStringList*> *names = editor->project->groupedMapNames;
|
||||||
if (settings.contains(key)) {
|
if (names) {
|
||||||
QMap<QString, QVariant> qmap = settings.value(key).toMap();
|
QSettings settings;
|
||||||
if (qmap.contains("recent_map")) {
|
QString key = "project:" + editor->project->root;
|
||||||
QString map_name = qmap.value("recent_map").toString();
|
if (settings.contains(key)) {
|
||||||
return map_name;
|
QMap<QString, QVariant> qmap = settings.value(key).toMap();
|
||||||
|
if (qmap.contains("recent_map")) {
|
||||||
|
QString map_name = qmap.value("recent_map").toString();
|
||||||
|
for (int i = 0; i < names->length(); i++) {
|
||||||
|
if (names->value(i)->contains(map_name)) {
|
||||||
|
return map_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Failing that, just get the first map in the list.
|
||||||
|
for (int i = 0; i < names->length(); i++) {
|
||||||
|
QStringList *list = names->value(i);
|
||||||
|
if (list->length()) {
|
||||||
|
return list->value(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Failing that, just get the first map in the list.
|
return QString();
|
||||||
for (int i = 0; i < editor->project->groupedMapNames->length(); i++) {
|
|
||||||
QStringList *list = editor->project->groupedMapNames->value(i);
|
|
||||||
if (list->length()) {
|
|
||||||
return list->value(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::getExistingDirectory(QString dir) {
|
QString MainWindow::getExistingDirectory(QString dir) {
|
||||||
|
@ -92,6 +125,7 @@ void MainWindow::on_action_Open_Project_triggered()
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setMap(QString map_name) {
|
void MainWindow::setMap(QString map_name) {
|
||||||
|
qDebug() << QString("setMap(%1)").arg(map_name);
|
||||||
if (map_name.isNull()) {
|
if (map_name.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -114,6 +148,7 @@ void MainWindow::setMap(QString map_name) {
|
||||||
ui->graphicsView_Objects_Map->setScene(editor->scene);
|
ui->graphicsView_Objects_Map->setScene(editor->scene);
|
||||||
ui->graphicsView_Objects_Map->setSceneRect(editor->scene->sceneRect());
|
ui->graphicsView_Objects_Map->setSceneRect(editor->scene->sceneRect());
|
||||||
ui->graphicsView_Objects_Map->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2);
|
ui->graphicsView_Objects_Map->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2);
|
||||||
|
ui->graphicsView_Objects_Map->editor = editor;
|
||||||
|
|
||||||
ui->graphicsView_Metatiles->setScene(editor->scene_metatiles);
|
ui->graphicsView_Metatiles->setScene(editor->scene_metatiles);
|
||||||
//ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect());
|
//ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect());
|
||||||
|
@ -129,6 +164,10 @@ void MainWindow::setMap(QString map_name) {
|
||||||
|
|
||||||
displayMapProperties();
|
displayMapProperties();
|
||||||
|
|
||||||
|
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
|
||||||
|
|
||||||
|
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
||||||
|
|
||||||
setRecentMap(map_name);
|
setRecentMap(map_name);
|
||||||
updateMapList();
|
updateMapList();
|
||||||
}
|
}
|
||||||
|
@ -145,11 +184,22 @@ void MainWindow::setRecentMap(QString map_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::displayMapProperties() {
|
void MainWindow::displayMapProperties() {
|
||||||
|
ui->comboBox_Song->clear();
|
||||||
|
ui->comboBox_Location->clear();
|
||||||
|
ui->comboBox_Visibility->clear();
|
||||||
|
ui->comboBox_Weather->clear();
|
||||||
|
ui->comboBox_Type->clear();
|
||||||
|
ui->comboBox_BattleScene->clear();
|
||||||
|
ui->checkBox_ShowLocation->setChecked(false);
|
||||||
|
if (!editor || !editor->map || !editor->project) {
|
||||||
|
ui->frame_3->setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ui->frame_3->setEnabled(true);
|
||||||
Map *map = editor->map;
|
Map *map = editor->map;
|
||||||
Project *project = editor->project;
|
Project *project = editor->project;
|
||||||
|
|
||||||
QStringList songs = project->getSongNames();
|
QStringList songs = project->getSongNames();
|
||||||
ui->comboBox_Song->clear();
|
|
||||||
ui->comboBox_Song->addItems(songs);
|
ui->comboBox_Song->addItems(songs);
|
||||||
QString song = map->song;
|
QString song = map->song;
|
||||||
if (!songs.contains(song)) {
|
if (!songs.contains(song)) {
|
||||||
|
@ -157,23 +207,18 @@ void MainWindow::displayMapProperties() {
|
||||||
}
|
}
|
||||||
ui->comboBox_Song->setCurrentText(song);
|
ui->comboBox_Song->setCurrentText(song);
|
||||||
|
|
||||||
ui->comboBox_Location->clear();
|
|
||||||
ui->comboBox_Location->addItems(project->getLocations());
|
ui->comboBox_Location->addItems(project->getLocations());
|
||||||
ui->comboBox_Location->setCurrentText(map->location);
|
ui->comboBox_Location->setCurrentText(map->location);
|
||||||
|
|
||||||
ui->comboBox_Visibility->clear();
|
|
||||||
ui->comboBox_Visibility->addItems(project->getVisibilities());
|
ui->comboBox_Visibility->addItems(project->getVisibilities());
|
||||||
ui->comboBox_Visibility->setCurrentText(map->visibility);
|
ui->comboBox_Visibility->setCurrentText(map->visibility);
|
||||||
|
|
||||||
ui->comboBox_Weather->clear();
|
|
||||||
ui->comboBox_Weather->addItems(project->getWeathers());
|
ui->comboBox_Weather->addItems(project->getWeathers());
|
||||||
ui->comboBox_Weather->setCurrentText(map->weather);
|
ui->comboBox_Weather->setCurrentText(map->weather);
|
||||||
|
|
||||||
ui->comboBox_Type->clear();
|
|
||||||
ui->comboBox_Type->addItems(project->getMapTypes());
|
ui->comboBox_Type->addItems(project->getMapTypes());
|
||||||
ui->comboBox_Type->setCurrentText(map->type);
|
ui->comboBox_Type->setCurrentText(map->type);
|
||||||
|
|
||||||
ui->comboBox_BattleScene->clear();
|
|
||||||
ui->comboBox_BattleScene->addItems(project->getBattleScenes());
|
ui->comboBox_BattleScene->addItems(project->getBattleScenes());
|
||||||
ui->comboBox_BattleScene->setCurrentText(map->battle_scene);
|
ui->comboBox_BattleScene->setCurrentText(map->battle_scene);
|
||||||
|
|
||||||
|
@ -182,40 +227,54 @@ void MainWindow::displayMapProperties() {
|
||||||
|
|
||||||
void MainWindow::on_comboBox_Song_activated(const QString &song)
|
void MainWindow::on_comboBox_Song_activated(const QString &song)
|
||||||
{
|
{
|
||||||
editor->map->song = song;
|
if (editor && editor->map) {
|
||||||
|
editor->map->song = song;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_comboBox_Location_activated(const QString &location)
|
void MainWindow::on_comboBox_Location_activated(const QString &location)
|
||||||
{
|
{
|
||||||
editor->map->location = location;
|
if (editor && editor->map) {
|
||||||
|
editor->map->location = location;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_comboBox_Visibility_activated(const QString &visibility)
|
void MainWindow::on_comboBox_Visibility_activated(const QString &visibility)
|
||||||
{
|
{
|
||||||
editor->map->visibility = visibility;
|
if (editor && editor->map) {
|
||||||
|
editor->map->visibility = visibility;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_comboBox_Weather_activated(const QString &weather)
|
void MainWindow::on_comboBox_Weather_activated(const QString &weather)
|
||||||
{
|
{
|
||||||
editor->map->weather = weather;
|
if (editor && editor->map) {
|
||||||
|
editor->map->weather = weather;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_comboBox_Type_activated(const QString &type)
|
void MainWindow::on_comboBox_Type_activated(const QString &type)
|
||||||
{
|
{
|
||||||
editor->map->type = type;
|
if (editor && editor->map) {
|
||||||
|
editor->map->type = type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_comboBox_BattleScene_activated(const QString &battle_scene)
|
void MainWindow::on_comboBox_BattleScene_activated(const QString &battle_scene)
|
||||||
{
|
{
|
||||||
editor->map->battle_scene = battle_scene;
|
if (editor && editor->map) {
|
||||||
|
editor->map->battle_scene = battle_scene;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
|
void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
|
||||||
{
|
{
|
||||||
if (checked) {
|
if (editor && editor->map) {
|
||||||
editor->map->show_location = "TRUE";
|
if (checked) {
|
||||||
} else {
|
editor->map->show_location = "TRUE";
|
||||||
editor->map->show_location = "FALSE";
|
} else {
|
||||||
|
editor->map->show_location = "FALSE";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +340,7 @@ void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||||
if (!data.isNull()) {
|
if (!data.isNull()) {
|
||||||
setMap(data.toString());
|
setMap(data.toString());
|
||||||
}
|
}
|
||||||
updateMapList();
|
//updateMapList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::markAllEdited(QAbstractItemModel *model) {
|
void MainWindow::markAllEdited(QAbstractItemModel *model) {
|
||||||
|
@ -307,7 +366,8 @@ void MainWindow::markEdited(QModelIndex index) {
|
||||||
if (editor->project->map_cache->contains(map_name)) {
|
if (editor->project->map_cache->contains(map_name)) {
|
||||||
// Just mark anything that's been opened for now.
|
// Just mark anything that's been opened for now.
|
||||||
// TODO if (project->getMap()->saved)
|
// TODO if (project->getMap()->saved)
|
||||||
ui->mapList->setExpanded(index, true);
|
//ui->mapList->setExpanded(index, true);
|
||||||
|
ui->mapList->setExpanded(index, editor->project->map_cache->value(map_name)->hasUnsavedChanges());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,6 +394,7 @@ void MainWindow::redo() {
|
||||||
|
|
||||||
void MainWindow::on_action_Save_triggered() {
|
void MainWindow::on_action_Save_triggered() {
|
||||||
editor->save();
|
editor->save();
|
||||||
|
updateMapList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_tabWidget_2_currentChanged(int index)
|
void MainWindow::on_tabWidget_2_currentChanged(int index)
|
||||||
|
@ -368,3 +429,231 @@ void MainWindow::on_actionRedo_triggered()
|
||||||
{
|
{
|
||||||
redo();
|
redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolButton_newObject_clicked()
|
||||||
|
{
|
||||||
|
if (editor) {
|
||||||
|
DraggablePixmapItem *object = editor->addNewEvent();
|
||||||
|
if (object) {
|
||||||
|
//if (editor->selected_events->length()) {
|
||||||
|
editor->selectMapObject(object, true);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
updateSelectedObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should probably just pass layout and let the editor work it out
|
||||||
|
void MainWindow::updateSelectedObjects() {
|
||||||
|
|
||||||
|
QList<DraggablePixmapItem *> *all_events = editor->getObjects();
|
||||||
|
QList<DraggablePixmapItem *> *events = all_events;
|
||||||
|
|
||||||
|
if (editor->selected_events && editor->selected_events->length()) {
|
||||||
|
events = editor->selected_events;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, int> map_obj_gfx_constants = editor->project->getMapObjGfxConstants();
|
||||||
|
|
||||||
|
QList<ObjectPropertiesFrame *> frames;
|
||||||
|
|
||||||
|
for (DraggablePixmapItem *item : *events) {
|
||||||
|
ObjectPropertiesFrame *frame = new ObjectPropertiesFrame;
|
||||||
|
// frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
|
|
||||||
|
QSpinBox *x = frame->ui->spinBox_x;
|
||||||
|
QSpinBox *y = frame->ui->spinBox_y;
|
||||||
|
QSpinBox *z = frame->ui->spinBox_z;
|
||||||
|
|
||||||
|
x->setValue(item->event->x());
|
||||||
|
connect(x, SIGNAL(valueChanged(QString)), item, SLOT(set_x(QString)));
|
||||||
|
connect(item, SIGNAL(xChanged(int)), x, SLOT(setValue(int)));
|
||||||
|
|
||||||
|
y->setValue(item->event->y());
|
||||||
|
connect(y, SIGNAL(valueChanged(QString)), item, SLOT(set_y(QString)));
|
||||||
|
connect(item, SIGNAL(yChanged(int)), y, SLOT(setValue(int)));
|
||||||
|
|
||||||
|
z->setValue(item->event->elevation());
|
||||||
|
connect(z, SIGNAL(valueChanged(QString)), item, SLOT(set_elevation(QString)));
|
||||||
|
connect(item, SIGNAL(elevationChanged(int)), z, SLOT(setValue(int)));
|
||||||
|
|
||||||
|
QFont font;
|
||||||
|
font.setCapitalization(QFont::Capitalize);
|
||||||
|
frame->ui->label_name->setFont(font);
|
||||||
|
QString event_type = item->event->get("event_type");
|
||||||
|
QString map_name = item->event->get("map_name");
|
||||||
|
frame->ui->label_name->setText(
|
||||||
|
QString("%1 %2 %3")
|
||||||
|
.arg(map_name)
|
||||||
|
.arg(event_type)
|
||||||
|
.arg(editor->project->getMap(map_name)->events.value(event_type).indexOf(item->event) + 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
frame->ui->label_spritePixmap->setPixmap(item->event->pixmap);
|
||||||
|
connect(item, SIGNAL(spriteChanged(QPixmap)), frame->ui->label_spritePixmap, SLOT(setPixmap(QPixmap)));
|
||||||
|
|
||||||
|
frame->ui->sprite->setVisible(false);
|
||||||
|
|
||||||
|
QMap<QString, QString> field_labels;
|
||||||
|
field_labels["script_label"] = "Script";
|
||||||
|
field_labels["event_flag"] = "Event Flag";
|
||||||
|
field_labels["replacement"] = "Replacement";
|
||||||
|
field_labels["property"] = "Property";
|
||||||
|
field_labels["sight_radius"] = "Sight Radius";
|
||||||
|
field_labels["destination_warp"] = "Destination Warp";
|
||||||
|
field_labels["destination_map"] = "Destination Map";
|
||||||
|
field_labels["coord_unknown1"] = "Unknown 1";
|
||||||
|
field_labels["coord_unknown2"] = "Unknown 2";
|
||||||
|
field_labels["type"] = "Type";
|
||||||
|
field_labels["item"] = "Item";
|
||||||
|
field_labels["item_unknown5"] = "Unknown 5";
|
||||||
|
field_labels["item_unknown6"] = "Unknown 6";
|
||||||
|
|
||||||
|
QStringList fields;
|
||||||
|
|
||||||
|
if (event_type == "object") {
|
||||||
|
|
||||||
|
frame->ui->sprite->setVisible(true);
|
||||||
|
frame->ui->comboBox_sprite->addItems(map_obj_gfx_constants.keys());
|
||||||
|
frame->ui->comboBox_sprite->setCurrentText(item->event->get("sprite"));
|
||||||
|
connect(frame->ui->comboBox_sprite, SIGNAL(activated(QString)), item, SLOT(set_sprite(QString)));
|
||||||
|
|
||||||
|
/*
|
||||||
|
frame->ui->script->setVisible(true);
|
||||||
|
frame->ui->comboBox_script->addItem(item->event->get("script_label"));
|
||||||
|
frame->ui->comboBox_script->setCurrentText(item->event->get("script_label"));
|
||||||
|
//item->bind(frame->ui->comboBox_script, "script_label");
|
||||||
|
connect(frame->ui->comboBox_script, SIGNAL(activated(QString)), item, SLOT(set_script(QString)));
|
||||||
|
//connect(frame->ui->comboBox_script, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated), item, [item](QString script_label){ item->event->put("script_label", script_label); });
|
||||||
|
//connect(item, SIGNAL(scriptChanged(QString)), frame->ui->comboBox_script, SLOT(setValue(QString)));
|
||||||
|
*/
|
||||||
|
|
||||||
|
fields << "script_label";
|
||||||
|
fields << "event_flag";
|
||||||
|
fields << "replacement";
|
||||||
|
fields << "property";
|
||||||
|
fields << "sight_radius";
|
||||||
|
}
|
||||||
|
else if (event_type == "warp") {
|
||||||
|
fields << "destination_warp";
|
||||||
|
fields << "destination_map";
|
||||||
|
}
|
||||||
|
else if (event_type == "trap") {
|
||||||
|
fields << "script_label";
|
||||||
|
fields << "coord_unknown1";
|
||||||
|
fields << "coord_unknown2";
|
||||||
|
}
|
||||||
|
else if (event_type == "sign") {
|
||||||
|
fields << "type";
|
||||||
|
fields << "script_label";
|
||||||
|
}
|
||||||
|
else if (event_type == "hidden item") {
|
||||||
|
fields << "type";
|
||||||
|
fields << "item";
|
||||||
|
fields << "item_unknown5";
|
||||||
|
fields << "item_unknown6";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (QString key : fields) {
|
||||||
|
QWidget *widget = new QWidget(frame);
|
||||||
|
QFormLayout *fl = new QFormLayout(widget);
|
||||||
|
fl->setContentsMargins(9, 0, 9, 0);
|
||||||
|
QComboBox *combo = new QComboBox(widget);
|
||||||
|
combo->setEditable(true);
|
||||||
|
|
||||||
|
QString value = item->event->get(key);
|
||||||
|
if (key == "destination_map") {
|
||||||
|
if (!editor->project->mapNames->contains(value)) {
|
||||||
|
combo->addItem(value);
|
||||||
|
}
|
||||||
|
combo->addItems(*editor->project->mapNames);
|
||||||
|
} else {
|
||||||
|
combo->addItem(value);
|
||||||
|
}
|
||||||
|
combo->setCurrentText(value);
|
||||||
|
|
||||||
|
fl->addRow(new QLabel(field_labels[key], widget), combo);
|
||||||
|
widget->setLayout(fl);
|
||||||
|
frame->layout()->addWidget(widget);
|
||||||
|
|
||||||
|
item->bind(combo, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
frames.append(frame);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//int scroll = ui->scrollArea_4->verticalScrollBar()->value();
|
||||||
|
|
||||||
|
QWidget *target = ui->scrollAreaWidgetContents;
|
||||||
|
|
||||||
|
if (target->children().length()) {
|
||||||
|
qDeleteAll(target->children());
|
||||||
|
}
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout(target);
|
||||||
|
target->setLayout(layout);
|
||||||
|
ui->scrollArea_4->setWidgetResizable(true);
|
||||||
|
ui->scrollArea_4->setWidget(target);
|
||||||
|
|
||||||
|
for (ObjectPropertiesFrame *frame : frames) {
|
||||||
|
layout->addWidget(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
layout->addStretch(1);
|
||||||
|
|
||||||
|
// doesn't work
|
||||||
|
//QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||||
|
//ui->scrollArea_4->ensureVisible(0, scroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolButton_deleteObject_clicked()
|
||||||
|
{
|
||||||
|
if (editor && editor->selected_events) {
|
||||||
|
if (editor->selected_events->length()) {
|
||||||
|
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||||
|
editor->deleteEvent(item->event);
|
||||||
|
if (editor->scene->items().contains(item)) {
|
||||||
|
editor->scene->removeItem(item);
|
||||||
|
}
|
||||||
|
editor->selected_events->removeOne(item);
|
||||||
|
}
|
||||||
|
updateSelectedObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolButton_Paint_clicked()
|
||||||
|
{
|
||||||
|
editor->map_edit_mode = "paint";
|
||||||
|
checkToolButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolButton_Select_clicked()
|
||||||
|
{
|
||||||
|
editor->map_edit_mode = "select";
|
||||||
|
checkToolButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolButton_Fill_clicked()
|
||||||
|
{
|
||||||
|
editor->map_edit_mode = "fill";
|
||||||
|
checkToolButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolButton_Dropper_clicked()
|
||||||
|
{
|
||||||
|
editor->map_edit_mode = "pick";
|
||||||
|
checkToolButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::checkToolButtons() {
|
||||||
|
ui->toolButton_Paint->setChecked(editor->map_edit_mode == "paint");
|
||||||
|
ui->toolButton_Select->setChecked(editor->map_edit_mode == "select");
|
||||||
|
ui->toolButton_Fill->setChecked(editor->map_edit_mode == "fill");
|
||||||
|
ui->toolButton_Dropper->setChecked(editor->map_edit_mode == "pick");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onMapChanged(Map *map) {
|
||||||
|
updateMapList();
|
||||||
|
}
|
||||||
|
|
19
mainwindow.h
|
@ -32,6 +32,8 @@ private slots:
|
||||||
void undo();
|
void undo();
|
||||||
void redo();
|
void redo();
|
||||||
|
|
||||||
|
void onMapChanged(Map *map);
|
||||||
|
|
||||||
void on_action_Save_triggered();
|
void on_action_Save_triggered();
|
||||||
void on_tabWidget_2_currentChanged(int index);
|
void on_tabWidget_2_currentChanged(int index);
|
||||||
void on_action_Exit_triggered();
|
void on_action_Exit_triggered();
|
||||||
|
@ -49,9 +51,23 @@ private slots:
|
||||||
|
|
||||||
void on_actionRedo_triggered();
|
void on_actionRedo_triggered();
|
||||||
|
|
||||||
|
void on_toolButton_newObject_clicked();
|
||||||
|
|
||||||
|
void on_toolButton_deleteObject_clicked();
|
||||||
|
|
||||||
|
void updateSelectedObjects();
|
||||||
|
|
||||||
|
void on_toolButton_Paint_clicked();
|
||||||
|
|
||||||
|
void on_toolButton_Select_clicked();
|
||||||
|
|
||||||
|
void on_toolButton_Fill_clicked();
|
||||||
|
|
||||||
|
void on_toolButton_Dropper_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
Editor *editor;
|
Editor *editor = NULL;
|
||||||
void setMap(QString);
|
void setMap(QString);
|
||||||
void populateMapList();
|
void populateMapList();
|
||||||
QString getExistingDirectory(QString);
|
QString getExistingDirectory(QString);
|
||||||
|
@ -64,6 +80,7 @@ private:
|
||||||
void updateMapList();
|
void updateMapList();
|
||||||
|
|
||||||
void displayMapProperties();
|
void displayMapProperties();
|
||||||
|
void checkToolButtons();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
1041
mainwindow.ui
221
map.cpp
|
@ -3,9 +3,11 @@
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
Map::Map(QObject *parent) : QObject(parent)
|
Map::Map(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
blockdata = new Blockdata;
|
||||||
cached_blockdata = new Blockdata;
|
cached_blockdata = new Blockdata;
|
||||||
cached_collision = new Blockdata;
|
cached_collision = new Blockdata;
|
||||||
cached_border = new Blockdata;
|
cached_border = new Blockdata;
|
||||||
|
@ -22,8 +24,8 @@ int Map::getHeight() {
|
||||||
return height.toInt(nullptr, 0);
|
return height.toInt(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tileset* Map::getBlockTileset(uint metatile_index) {
|
Tileset* Map::getBlockTileset(int metatile_index) {
|
||||||
uint primary_size = 0x200;//tileset_primary->metatiles->length();
|
int primary_size = 0x200;//tileset_primary->metatiles->length();
|
||||||
if (metatile_index < primary_size) {
|
if (metatile_index < primary_size) {
|
||||||
return tileset_primary;
|
return tileset_primary;
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,23 +33,43 @@ Tileset* Map::getBlockTileset(uint metatile_index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage Map::getMetatileTile(uint tile) {
|
QList<QList<QRgb>> Map::getBlockPalettes(int metatile_index) {
|
||||||
uint primary_size = 0x200;//tileset_primary->metatiles->length();
|
QList<QList<QRgb>> palettes;
|
||||||
if (tile < primary_size) {
|
for (int i = 0; i < 6; i++) {
|
||||||
return tileset_primary->tiles->value(tile);
|
palettes.append(tileset_primary->palettes->at(i));
|
||||||
|
}
|
||||||
|
for (int i = 6; i < tileset_secondary->palettes->length(); i++) {
|
||||||
|
palettes.append(tileset_secondary->palettes->at(i));
|
||||||
|
}
|
||||||
|
return palettes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Map::getBlockIndex(int index) {
|
||||||
|
int primary_size = 0x200;
|
||||||
|
if (index < primary_size) {
|
||||||
|
return index;
|
||||||
} else {
|
} else {
|
||||||
return tileset_secondary->tiles->value(tile - primary_size);
|
return index - primary_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Metatile* Map::getMetatile(uint index) {
|
QImage Map::getMetatileTile(int tile) {
|
||||||
uint primary_size = 0x200;//tileset_primary->metatiles->length();
|
Tileset *tileset = getBlockTileset(tile);
|
||||||
if (index < primary_size) {
|
int local_index = getBlockIndex(tile);
|
||||||
return tileset_primary->metatiles->value(index);
|
if (!tileset || !tileset->tiles) {
|
||||||
} else {
|
return QImage();
|
||||||
//qDebug() << QString("secondary tileset: %1").arg(index - primary_size, 0, 16);
|
|
||||||
return tileset_secondary->metatiles->value(index - primary_size);
|
|
||||||
}
|
}
|
||||||
|
return tileset->tiles->value(local_index, QImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
Metatile* Map::getMetatile(int index) {
|
||||||
|
Tileset *tileset = getBlockTileset(index);
|
||||||
|
int local_index = getBlockIndex(index);
|
||||||
|
if (!tileset || !tileset->metatiles) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
Metatile *metatile = tileset->metatiles->value(local_index, NULL);
|
||||||
|
return metatile;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage Map::getCollisionMetatileImage(Block block) {
|
QImage Map::getCollisionMetatileImage(Block block) {
|
||||||
|
@ -93,28 +115,38 @@ QImage Map::getElevationMetatileImage(int elevation) {
|
||||||
return metatile_image;
|
return metatile_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage Map::getMetatileImage(uint tile) {
|
QImage Map::getMetatileImage(int tile) {
|
||||||
|
|
||||||
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
||||||
|
|
||||||
Metatile* metatile = getMetatile(tile);
|
Metatile* metatile = getMetatile(tile);
|
||||||
if (metatile == NULL) {
|
if (!metatile || !metatile->tiles) {
|
||||||
metatile_image.fill(0xffffffff);
|
metatile_image.fill(0xffffffff);
|
||||||
return metatile_image;
|
return metatile_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tileset* blockTileset = getBlockTileset(tile);
|
Tileset* blockTileset = getBlockTileset(tile);
|
||||||
|
if (!blockTileset) {
|
||||||
|
metatile_image.fill(0xffffffff);
|
||||||
|
return metatile_image;
|
||||||
|
}
|
||||||
|
QList<QList<QRgb>> palettes = getBlockPalettes(tile);
|
||||||
|
|
||||||
|
QPainter metatile_painter(&metatile_image);
|
||||||
for (int layer = 0; layer < 2; layer++)
|
for (int layer = 0; layer < 2; layer++)
|
||||||
for (int y = 0; y < 2; y++)
|
for (int y = 0; y < 2; y++)
|
||||||
for (int x = 0; x < 2; x++) {
|
for (int x = 0; x < 2; x++) {
|
||||||
//qDebug() << QString("x=%1 y=%2 layer=%3").arg(x).arg(y).arg(layer);
|
Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
|
||||||
Tile tile = metatile->tiles->value((y * 2) + x + (layer * 4));
|
QImage tile_image = getMetatileTile(tile_.tile);
|
||||||
QImage tile_image = getMetatileTile(tile.tile);
|
//if (tile_image.isNull()) {
|
||||||
QList<QRgb> palette = blockTileset->palettes->value(tile.palette);
|
// continue;
|
||||||
for (int j = 0; j < palette.length(); j++) {
|
//}
|
||||||
tile_image.setColor(j, palette.value(j));
|
//if (blockTileset->palettes) {
|
||||||
}
|
QList<QRgb> palette = palettes.value(tile_.palette);
|
||||||
|
for (int j = 0; j < palette.length(); j++) {
|
||||||
|
tile_image.setColor(j, palette.value(j));
|
||||||
|
}
|
||||||
|
//}
|
||||||
//QVector<QRgb> vector = palette.toVector();
|
//QVector<QRgb> vector = palette.toVector();
|
||||||
//tile_image.setColorTable(vector);
|
//tile_image.setColorTable(vector);
|
||||||
if (layer > 0) {
|
if (layer > 0) {
|
||||||
|
@ -122,43 +154,66 @@ QImage Map::getMetatileImage(uint tile) {
|
||||||
color.setAlpha(0);
|
color.setAlpha(0);
|
||||||
tile_image.setColor(15, color.rgba());
|
tile_image.setColor(15, color.rgba());
|
||||||
}
|
}
|
||||||
QPainter metatile_painter(&metatile_image);
|
|
||||||
QPoint origin = QPoint(x*8, y*8);
|
QPoint origin = QPoint(x*8, y*8);
|
||||||
metatile_painter.drawImage(origin, tile_image.mirrored(tile.xflip == 1, tile.yflip == 1));
|
metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
|
||||||
metatile_painter.end();
|
|
||||||
}
|
}
|
||||||
|
metatile_painter.end();
|
||||||
|
|
||||||
return metatile_image;
|
return metatile_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::blockChanged(int i, Blockdata *cache) {
|
bool Map::blockChanged(int i, Blockdata *cache) {
|
||||||
|
if (cache == NULL || cache == nullptr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (blockdata == NULL || blockdata == nullptr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (cache->blocks == NULL || cache->blocks == nullptr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (blockdata->blocks == NULL || blockdata->blocks == nullptr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (cache->blocks->length() <= i) {
|
if (cache->blocks->length() <= i) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (blockdata->blocks->length() <= i) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return blockdata->blocks->value(i) != cache->blocks->value(i);
|
return blockdata->blocks->value(i) != cache->blocks->value(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::cacheBorder() {
|
void Map::cacheBorder() {
|
||||||
|
if (cached_border) delete cached_border;
|
||||||
cached_border = new Blockdata;
|
cached_border = new Blockdata;
|
||||||
for (int i = 0; i < border->blocks->length(); i++) {
|
if (border && border->blocks) {
|
||||||
Block block = border->blocks->value(i);
|
for (int i = 0; i < border->blocks->length(); i++) {
|
||||||
cached_border->blocks->append(block);
|
Block block = border->blocks->value(i);
|
||||||
|
cached_border->blocks->append(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::cacheBlockdata() {
|
void Map::cacheBlockdata() {
|
||||||
|
if (cached_blockdata) delete cached_blockdata;
|
||||||
cached_blockdata = new Blockdata;
|
cached_blockdata = new Blockdata;
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
if (blockdata && blockdata->blocks) {
|
||||||
Block block = blockdata->blocks->value(i);
|
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
||||||
cached_blockdata->blocks->append(block);
|
Block block = blockdata->blocks->value(i);
|
||||||
|
cached_blockdata->blocks->append(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::cacheCollision() {
|
void Map::cacheCollision() {
|
||||||
|
if (cached_collision) delete cached_collision;
|
||||||
cached_collision = new Blockdata;
|
cached_collision = new Blockdata;
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
if (blockdata && blockdata->blocks) {
|
||||||
Block block = blockdata->blocks->value(i);
|
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
||||||
cached_collision->blocks->append(block);
|
Block block = blockdata->blocks->value(i);
|
||||||
|
cached_collision->blocks->append(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,9 +229,13 @@ QPixmap Map::renderCollision() {
|
||||||
collision_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
collision_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
}
|
}
|
||||||
|
if (!(blockdata && blockdata->blocks && width_ && height_)) {
|
||||||
|
collision_pixmap = collision_pixmap.fromImage(collision_image);
|
||||||
|
return collision_pixmap;
|
||||||
|
}
|
||||||
QPainter painter(&collision_image);
|
QPainter painter(&collision_image);
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
||||||
if (!blockChanged(i, cached_collision)) {
|
if (cached_collision && !blockChanged(i, cached_collision)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
|
@ -184,8 +243,8 @@ QPixmap Map::renderCollision() {
|
||||||
QImage metatile_image = getMetatileImage(block.tile);
|
QImage metatile_image = getMetatileImage(block.tile);
|
||||||
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
||||||
QImage elevation_metatile_image = getElevationMetatileImage(block);
|
QImage elevation_metatile_image = getElevationMetatileImage(block);
|
||||||
int map_y = i / width_;
|
int map_y = width_ ? i / width_ : 0;
|
||||||
int map_x = i % width_;
|
int map_x = width_ ? i % width_ : 0;
|
||||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||||
painter.setOpacity(1);
|
painter.setOpacity(1);
|
||||||
painter.drawImage(metatile_origin, metatile_image);
|
painter.drawImage(metatile_origin, metatile_image);
|
||||||
|
@ -238,6 +297,11 @@ QPixmap Map::render() {
|
||||||
image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
}
|
}
|
||||||
|
if (!(blockdata && blockdata->blocks && width_ && height_)) {
|
||||||
|
pixmap = pixmap.fromImage(image);
|
||||||
|
return pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
QPainter painter(&image);
|
QPainter painter(&image);
|
||||||
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
for (int i = 0; i < blockdata->blocks->length(); i++) {
|
||||||
if (!blockChanged(i, cached_blockdata)) {
|
if (!blockChanged(i, cached_blockdata)) {
|
||||||
|
@ -246,8 +310,8 @@ QPixmap Map::render() {
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
Block block = blockdata->blocks->value(i);
|
Block block = blockdata->blocks->value(i);
|
||||||
QImage metatile_image = getMetatileImage(block.tile);
|
QImage metatile_image = getMetatileImage(block.tile);
|
||||||
int map_y = i / width_;
|
int map_y = width_ ? i / width_ : 0;
|
||||||
int map_x = i % width_;
|
int map_x = width_ ? i % width_ : 0;
|
||||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||||
painter.drawImage(metatile_origin, metatile_image);
|
painter.drawImage(metatile_origin, metatile_image);
|
||||||
}
|
}
|
||||||
|
@ -267,6 +331,10 @@ QPixmap Map::renderBorder() {
|
||||||
border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
border_image = QImage(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
}
|
}
|
||||||
|
if (!(border && border->blocks)) {
|
||||||
|
border_pixmap = border_pixmap.fromImage(border_image);
|
||||||
|
return border_pixmap;
|
||||||
|
}
|
||||||
QPainter painter(&border_image);
|
QPainter painter(&border_image);
|
||||||
for (int i = 0; i < border->blocks->length(); i++) {
|
for (int i = 0; i < border->blocks->length(); i++) {
|
||||||
if (!blockChanged(i, cached_border)) {
|
if (!blockChanged(i, cached_border)) {
|
||||||
|
@ -371,6 +439,9 @@ void Map::drawSelection(int i, int w, QPainter *painter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderMetatiles() {
|
QPixmap Map::renderMetatiles() {
|
||||||
|
if (!tileset_primary || !tileset_primary->metatiles || !tileset_secondary || !tileset_secondary->metatiles) {
|
||||||
|
return QPixmap();
|
||||||
|
}
|
||||||
int primary_length = tileset_primary->metatiles->length();
|
int primary_length = tileset_primary->metatiles->length();
|
||||||
int length_ = primary_length + tileset_secondary->metatiles->length();
|
int length_ = primary_length + tileset_secondary->metatiles->length();
|
||||||
int width_ = 8;
|
int width_ = 8;
|
||||||
|
@ -378,7 +449,7 @@ QPixmap Map::renderMetatiles() {
|
||||||
QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||||
QPainter painter(&image);
|
QPainter painter(&image);
|
||||||
for (int i = 0; i < length_; i++) {
|
for (int i = 0; i < length_; i++) {
|
||||||
uint tile = i;
|
int tile = i;
|
||||||
if (i >= primary_length) {
|
if (i >= primary_length) {
|
||||||
tile += 0x200 - primary_length;
|
tile += 0x200 - primary_length;
|
||||||
}
|
}
|
||||||
|
@ -396,17 +467,21 @@ QPixmap Map::renderMetatiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Block* Map::getBlock(int x, int y) {
|
Block* Map::getBlock(int x, int y) {
|
||||||
if (x >= 0 && x < getWidth())
|
if (blockdata && blockdata->blocks) {
|
||||||
if (y >= 0 && y < getHeight()) {
|
if (x >= 0 && x < getWidth())
|
||||||
int i = y * getWidth() + x;
|
if (y >= 0 && y < getHeight()) {
|
||||||
return new Block(blockdata->blocks->value(i));
|
int i = y * getWidth() + x;
|
||||||
|
return new Block(blockdata->blocks->value(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::_setBlock(int x, int y, Block block) {
|
void Map::_setBlock(int x, int y, Block block) {
|
||||||
int i = y * getWidth() + x;
|
int i = y * getWidth() + x;
|
||||||
blockdata->blocks->replace(i, block);
|
if (blockdata && blockdata->blocks) {
|
||||||
|
blockdata->blocks->replace(i, block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::_floodFill(int x, int y, uint tile) {
|
void Map::_floodFill(int x, int y, uint tile) {
|
||||||
|
@ -542,22 +617,33 @@ void Map::_floodFillCollisionElevation(int x, int y, uint collision, uint elevat
|
||||||
|
|
||||||
|
|
||||||
void Map::undo() {
|
void Map::undo() {
|
||||||
Blockdata *commit = history.pop();
|
if (blockdata) {
|
||||||
if (commit != NULL) {
|
Blockdata *commit = history.pop();
|
||||||
blockdata->copyFrom(commit);
|
if (commit != NULL) {
|
||||||
|
blockdata->copyFrom(commit);
|
||||||
|
emit mapChanged(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::redo() {
|
void Map::redo() {
|
||||||
Blockdata *commit = history.next();
|
if (blockdata) {
|
||||||
if (commit != NULL) {
|
Blockdata *commit = history.next();
|
||||||
blockdata->copyFrom(commit);
|
if (commit != NULL) {
|
||||||
|
blockdata->copyFrom(commit);
|
||||||
|
emit mapChanged(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::commit() {
|
void Map::commit() {
|
||||||
Blockdata* commit = blockdata->copy();
|
if (blockdata) {
|
||||||
history.push(commit);
|
if (!blockdata->equals(history.history.at(history.head))) {
|
||||||
|
Blockdata* commit = blockdata->copy();
|
||||||
|
history.push(commit);
|
||||||
|
emit mapChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::setBlock(int x, int y, Block block) {
|
void Map::setBlock(int x, int y, Block block) {
|
||||||
|
@ -598,3 +684,30 @@ void Map::floodFillCollisionElevation(int x, int y, uint collision, uint elevati
|
||||||
commit();
|
commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Event *> Map::getAllEvents() {
|
||||||
|
QList<Event*> all;
|
||||||
|
for (QList<Event*> list : events.values()) {
|
||||||
|
all += list;
|
||||||
|
}
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Event *> Map::getEventsByType(QString type)
|
||||||
|
{
|
||||||
|
return events.value(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::removeEvent(Event *event) {
|
||||||
|
for (QString key : events.keys()) {
|
||||||
|
events[key].removeAll(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::addEvent(Event *event) {
|
||||||
|
events[event->get("event_type")].append(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Map::hasUnsavedChanges() {
|
||||||
|
return !history.isSaved();
|
||||||
|
}
|
||||||
|
|
54
map.h
|
@ -14,10 +14,11 @@ template <typename T>
|
||||||
class History {
|
class History {
|
||||||
public:
|
public:
|
||||||
QList<T> history;
|
QList<T> history;
|
||||||
int head;
|
int head = -1;
|
||||||
|
int saved = -1;
|
||||||
|
|
||||||
History() {
|
History() {
|
||||||
head = -1;
|
|
||||||
}
|
}
|
||||||
T pop() {
|
T pop() {
|
||||||
if (head > 0) {
|
if (head > 0) {
|
||||||
|
@ -35,9 +36,18 @@ public:
|
||||||
while (head + 1 < history.length()) {
|
while (head + 1 < history.length()) {
|
||||||
history.removeLast();
|
history.removeLast();
|
||||||
}
|
}
|
||||||
|
if (saved > head) {
|
||||||
|
saved = -1;
|
||||||
|
}
|
||||||
history.append(commit);
|
history.append(commit);
|
||||||
head++;
|
head++;
|
||||||
}
|
}
|
||||||
|
void save() {
|
||||||
|
saved = head;
|
||||||
|
}
|
||||||
|
bool isSaved() {
|
||||||
|
return saved == head;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Connection {
|
class Connection {
|
||||||
|
@ -79,18 +89,19 @@ public:
|
||||||
QString tileset_primary_label;
|
QString tileset_primary_label;
|
||||||
QString tileset_secondary_label;
|
QString tileset_secondary_label;
|
||||||
|
|
||||||
Tileset *tileset_primary;
|
Tileset *tileset_primary = NULL;
|
||||||
Tileset *tileset_secondary;
|
Tileset *tileset_secondary = NULL;
|
||||||
|
|
||||||
Blockdata* blockdata;
|
Blockdata* blockdata = NULL;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int getWidth();
|
int getWidth();
|
||||||
int getHeight();
|
int getHeight();
|
||||||
Tileset* getBlockTileset(uint);
|
Tileset* getBlockTileset(int);
|
||||||
Metatile* getMetatile(uint);
|
int getBlockIndex(int index);
|
||||||
QImage getMetatileImage(uint);
|
Metatile* getMetatile(int);
|
||||||
QImage getMetatileTile(uint);
|
QImage getMetatileImage(int);
|
||||||
|
QImage getMetatileTile(int);
|
||||||
QPixmap render();
|
QPixmap render();
|
||||||
QPixmap renderMetatiles();
|
QPixmap renderMetatiles();
|
||||||
|
|
||||||
|
@ -107,9 +118,9 @@ public:
|
||||||
void drawSelection(int i, int w, QPainter *painter);
|
void drawSelection(int i, int w, QPainter *painter);
|
||||||
|
|
||||||
bool blockChanged(int, Blockdata*);
|
bool blockChanged(int, Blockdata*);
|
||||||
Blockdata* cached_blockdata;
|
Blockdata* cached_blockdata = NULL;
|
||||||
void cacheBlockdata();
|
void cacheBlockdata();
|
||||||
Blockdata* cached_collision;
|
Blockdata* cached_collision = NULL;
|
||||||
void cacheCollision();
|
void cacheCollision();
|
||||||
QImage image;
|
QImage image;
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
|
@ -141,23 +152,30 @@ public:
|
||||||
QString coord_events_label;
|
QString coord_events_label;
|
||||||
QString bg_events_label;
|
QString bg_events_label;
|
||||||
|
|
||||||
QList<ObjectEvent*> object_events;
|
QList<Event*> getAllEvents();
|
||||||
QList<Warp*> warps;
|
QList<Event*> getEventsByType(QString type);
|
||||||
QList<CoordEvent*> coord_events;
|
void removeEvent(Event *event);
|
||||||
QList<Sign*> signs;
|
void addEvent(Event *event);
|
||||||
QList<HiddenItem*> hidden_items;
|
QMap<QString, QList<Event*>> events;
|
||||||
|
|
||||||
QList<Connection*> connections;
|
QList<Connection*> connections;
|
||||||
QPixmap renderConnection(Connection);
|
QPixmap renderConnection(Connection);
|
||||||
|
|
||||||
QImage border_image;
|
QImage border_image;
|
||||||
QPixmap border_pixmap;
|
QPixmap border_pixmap;
|
||||||
Blockdata *border;
|
Blockdata *border = NULL;
|
||||||
Blockdata *cached_border;
|
Blockdata *cached_border = NULL;
|
||||||
QPixmap renderBorder();
|
QPixmap renderBorder();
|
||||||
void cacheBorder();
|
void cacheBorder();
|
||||||
|
|
||||||
|
bool hasUnsavedChanges();
|
||||||
|
|
||||||
|
QList<QList<QRgb> > getBlockPalettes(int metatile_index);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void paintTileChanged(Map *map);
|
||||||
|
void paintCollisionChanged(Map *map);
|
||||||
|
void mapChanged(Map *map);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Metatile
|
||||||
public:
|
public:
|
||||||
Metatile();
|
Metatile();
|
||||||
public:
|
public:
|
||||||
QList<Tile> *tiles;
|
QList<Tile> *tiles = NULL;
|
||||||
int attr;
|
int attr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
14
objectpropertiesframe.cpp
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "objectpropertiesframe.h"
|
||||||
|
#include "ui_objectpropertiesframe.h"
|
||||||
|
|
||||||
|
ObjectPropertiesFrame::ObjectPropertiesFrame(QWidget *parent) :
|
||||||
|
QFrame(parent),
|
||||||
|
ui(new Ui::ObjectPropertiesFrame)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectPropertiesFrame::~ObjectPropertiesFrame()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
22
objectpropertiesframe.h
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef OBJECTPROPERTIESFRAME_H
|
||||||
|
#define OBJECTPROPERTIESFRAME_H
|
||||||
|
|
||||||
|
#include <QFrame>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ObjectPropertiesFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ObjectPropertiesFrame : public QFrame
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ObjectPropertiesFrame(QWidget *parent = 0);
|
||||||
|
~ObjectPropertiesFrame();
|
||||||
|
|
||||||
|
public:
|
||||||
|
Ui::ObjectPropertiesFrame *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OBJECTPROPERTIESFRAME_H
|
250
objectpropertiesframe.ui
Executable file
|
@ -0,0 +1,250 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ObjectPropertiesFrame</class>
|
||||||
|
<widget class="QFrame" name="ObjectPropertiesFrame">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>284</width>
|
||||||
|
<height>146</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>284</width>
|
||||||
|
<height>90</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Frame</string>
|
||||||
|
</property>
|
||||||
|
<property name="layoutDirection">
|
||||||
|
<enum>Qt::LeftToRight</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::Box</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_spritePixmap">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>64</width>
|
||||||
|
<height>64</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::Box</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Sunken</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="scaledContents">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
<property name="indent">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_name">
|
||||||
|
<property name="text">
|
||||||
|
<string>Object 1</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="x">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_x">
|
||||||
|
<property name="text">
|
||||||
|
<string>X</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinBox_x">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>-32768</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>32767</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="y">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_y">
|
||||||
|
<property name="text">
|
||||||
|
<string>Y</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinBox_y">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>-32768</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>32767</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="z">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Z</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinBox_z">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>15</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="sprite" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<layout class="QFormLayout" name="formLayout_sprite">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>9</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_sprite">
|
||||||
|
<property name="text">
|
||||||
|
<string>Sprite</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>comboBox_sprite</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="comboBox_sprite">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="currentText">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="maxVisibleItems">
|
||||||
|
<number>25</number>
|
||||||
|
</property>
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>spinBox_x</tabstop>
|
||||||
|
<tabstop>spinBox_y</tabstop>
|
||||||
|
<tabstop>spinBox_z</tabstop>
|
||||||
|
<tabstop>comboBox_sprite</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
11
pretmap.pro
|
@ -23,7 +23,9 @@ SOURCES += main.cpp\
|
||||||
metatile.cpp \
|
metatile.cpp \
|
||||||
tile.cpp \
|
tile.cpp \
|
||||||
event.cpp \
|
event.cpp \
|
||||||
editor.cpp
|
editor.cpp \
|
||||||
|
objectpropertiesframe.cpp \
|
||||||
|
graphicsview.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
project.h \
|
project.h \
|
||||||
|
@ -35,9 +37,12 @@ HEADERS += mainwindow.h \
|
||||||
metatile.h \
|
metatile.h \
|
||||||
tile.h \
|
tile.h \
|
||||||
event.h \
|
event.h \
|
||||||
editor.h
|
editor.h \
|
||||||
|
objectpropertiesframe.h \
|
||||||
|
graphicsview.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui
|
FORMS += mainwindow.ui \
|
||||||
|
objectpropertiesframe.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources/images.qrc
|
resources/images.qrc
|
||||||
|
|
424
project.cpp
|
@ -15,12 +15,17 @@ Project::Project()
|
||||||
{
|
{
|
||||||
groupNames = new QStringList;
|
groupNames = new QStringList;
|
||||||
groupedMapNames = new QList<QStringList*>;
|
groupedMapNames = new QList<QStringList*>;
|
||||||
|
mapNames = new QStringList;
|
||||||
map_cache = new QMap<QString, Map*>;
|
map_cache = new QMap<QString, Map*>;
|
||||||
tileset_cache = new QMap<QString, Tileset*>;
|
tileset_cache = new QMap<QString, Tileset*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::getProjectTitle() {
|
QString Project::getProjectTitle() {
|
||||||
return root.section('/', -1);
|
if (!root.isNull()) {
|
||||||
|
return root.section('/', -1);
|
||||||
|
} else {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map* Project::loadMap(QString map_name) {
|
Map* Project::loadMap(QString map_name) {
|
||||||
|
@ -35,6 +40,7 @@ Map* Project::loadMap(QString map_name) {
|
||||||
readMapEvents(map);
|
readMapEvents(map);
|
||||||
loadMapConnections(map);
|
loadMapConnections(map);
|
||||||
map->commit();
|
map->commit();
|
||||||
|
map->history.save();
|
||||||
|
|
||||||
map_cache->insert(map_name, map);
|
map_cache->insert(map_name, map);
|
||||||
return map;
|
return map;
|
||||||
|
@ -43,9 +49,9 @@ Map* Project::loadMap(QString map_name) {
|
||||||
void Project::loadMapConnections(Map *map) {
|
void Project::loadMapConnections(Map *map) {
|
||||||
map->connections.clear();
|
map->connections.clear();
|
||||||
if (!map->connections_label.isNull()) {
|
if (!map->connections_label.isNull()) {
|
||||||
QString path = root + QString("/data/maps/%1/connections.s").arg(map->name);
|
QString path = root + QString("/data/maps/%1/connections.inc").arg(map->name);
|
||||||
QString text = readTextFile(path);
|
QString text = readTextFile(path);
|
||||||
if (text != NULL) {
|
if (!text.isNull()) {
|
||||||
QList<QStringList> *commands = parse(text);
|
QList<QStringList> *commands = parse(text);
|
||||||
QStringList *list = getLabelValues(commands, map->connections_label);
|
QStringList *list = getLabelValues(commands, map->connections_label);
|
||||||
|
|
||||||
|
@ -114,7 +120,10 @@ void Project::readMapHeader(Map* map) {
|
||||||
QString label = map->name;
|
QString label = map->name;
|
||||||
Asm *parser = new Asm;
|
Asm *parser = new Asm;
|
||||||
|
|
||||||
QString header_text = readTextFile(root + "/data/maps/" + label + "/header.s");
|
QString header_text = readTextFile(root + "/data/maps/" + label + "/header.inc");
|
||||||
|
if (header_text.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QStringList *header = getLabelValues(parser->parse(header_text), label);
|
QStringList *header = getLabelValues(parser->parse(header_text), label);
|
||||||
map->attributes_label = header->value(0);
|
map->attributes_label = header->value(0);
|
||||||
map->events_label = header->value(1);
|
map->events_label = header->value(1);
|
||||||
|
@ -133,7 +142,7 @@ void Project::readMapHeader(Map* map) {
|
||||||
|
|
||||||
void Project::saveMapHeader(Map *map) {
|
void Project::saveMapHeader(Map *map) {
|
||||||
QString label = map->name;
|
QString label = map->name;
|
||||||
QString header_path = root + "/data/maps/" + label + "/header.s";
|
QString header_path = root + "/data/maps/" + label + "/header.inc";
|
||||||
QString text = "";
|
QString text = "";
|
||||||
text += QString("%1::\n").arg(label);
|
text += QString("%1::\n").arg(label);
|
||||||
text += QString("\t.4byte %1\n").arg(map->attributes_label);
|
text += QString("\t.4byte %1\n").arg(map->attributes_label);
|
||||||
|
@ -155,7 +164,10 @@ void Project::saveMapHeader(Map *map) {
|
||||||
void Project::readMapAttributes(Map* map) {
|
void Project::readMapAttributes(Map* map) {
|
||||||
Asm *parser = new Asm;
|
Asm *parser = new Asm;
|
||||||
|
|
||||||
QString assets_text = readTextFile(root + "/data/maps/_assets.s");
|
QString assets_text = readTextFile(root + "/data/maps/_assets.inc");
|
||||||
|
if (assets_text.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QStringList *attributes = getLabelValues(parser->parse(assets_text), map->attributes_label);
|
QStringList *attributes = getLabelValues(parser->parse(assets_text), map->attributes_label);
|
||||||
map->width = attributes->value(0);
|
map->width = attributes->value(0);
|
||||||
map->height = attributes->value(1);
|
map->height = attributes->value(1);
|
||||||
|
@ -173,7 +185,7 @@ void Project::getTilesets(Map* map) {
|
||||||
Tileset* Project::loadTileset(QString label) {
|
Tileset* Project::loadTileset(QString label) {
|
||||||
Asm *parser = new Asm;
|
Asm *parser = new Asm;
|
||||||
|
|
||||||
QString headers_text = readTextFile(root + "/data/tilesets/headers.s");
|
QString headers_text = readTextFile(root + "/data/tilesets/headers.inc");
|
||||||
QStringList *values = getLabelValues(parser->parse(headers_text), label);
|
QStringList *values = getLabelValues(parser->parse(headers_text), label);
|
||||||
Tileset *tileset = new Tileset;
|
Tileset *tileset = new Tileset;
|
||||||
tileset->name = label;
|
tileset->name = label;
|
||||||
|
@ -193,7 +205,7 @@ Tileset* Project::loadTileset(QString label) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::getBlockdataPath(Map* map) {
|
QString Project::getBlockdataPath(Map* map) {
|
||||||
QString text = readTextFile(root + "/data/maps/_assets.s");
|
QString text = readTextFile(root + "/data/maps/_assets.inc");
|
||||||
QStringList *values = getLabelValues(parse(text), map->blockdata_label);
|
QStringList *values = getLabelValues(parse(text), map->blockdata_label);
|
||||||
QString path;
|
QString path;
|
||||||
if (!values->isEmpty()) {
|
if (!values->isEmpty()) {
|
||||||
|
@ -205,7 +217,7 @@ QString Project::getBlockdataPath(Map* map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::getMapBorderPath(Map *map) {
|
QString Project::getMapBorderPath(Map *map) {
|
||||||
QString text = readTextFile(root + "/data/maps/_assets.s");
|
QString text = readTextFile(root + "/data/maps/_assets.inc");
|
||||||
QStringList *values = getLabelValues(parse(text), map->border_label);
|
QStringList *values = getLabelValues(parse(text), map->border_label);
|
||||||
QString path;
|
QString path;
|
||||||
if (!values->isEmpty()) {
|
if (!values->isEmpty()) {
|
||||||
|
@ -229,6 +241,7 @@ void Project::loadMapBorder(Map *map) {
|
||||||
void Project::saveBlockdata(Map* map) {
|
void Project::saveBlockdata(Map* map) {
|
||||||
QString path = getBlockdataPath(map);
|
QString path = getBlockdataPath(map);
|
||||||
writeBlockdata(path, map->blockdata);
|
writeBlockdata(path, map->blockdata);
|
||||||
|
map->history.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::writeBlockdata(QString path, Blockdata *blockdata) {
|
void Project::writeBlockdata(QString path, Blockdata *blockdata) {
|
||||||
|
@ -251,14 +264,18 @@ void Project::saveAllMaps() {
|
||||||
void Project::saveMap(Map *map) {
|
void Project::saveMap(Map *map) {
|
||||||
saveBlockdata(map);
|
saveBlockdata(map);
|
||||||
saveMapHeader(map);
|
saveMapHeader(map);
|
||||||
|
saveMapEvents(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::loadTilesetAssets(Tileset* tileset) {
|
void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
Asm* parser = new Asm;
|
Asm* parser = new Asm;
|
||||||
QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
|
QString category = (tileset->is_secondary == "TRUE") ? "secondary" : "primary";
|
||||||
|
if (tileset->name.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QString dir_path = root + "/data/tilesets/" + category + "/" + tileset->name.replace("gTileset_", "").toLower();
|
QString dir_path = root + "/data/tilesets/" + category + "/" + tileset->name.replace("gTileset_", "").toLower();
|
||||||
|
|
||||||
QString graphics_text = readTextFile(root + "/data/tilesets/graphics.s");
|
QString graphics_text = readTextFile(root + "/data/tilesets/graphics.inc");
|
||||||
QList<QStringList> *graphics = parser->parse(graphics_text);
|
QList<QStringList> *graphics = parser->parse(graphics_text);
|
||||||
QStringList *tiles_values = getLabelValues(graphics, tileset->tiles_label);
|
QStringList *tiles_values = getLabelValues(graphics, tileset->tiles_label);
|
||||||
QStringList *palettes_values = getLabelValues(graphics, tileset->palettes_label);
|
QStringList *palettes_values = getLabelValues(graphics, tileset->palettes_label);
|
||||||
|
@ -288,7 +305,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
|
|
||||||
QString metatiles_path;
|
QString metatiles_path;
|
||||||
QString metatile_attrs_path;
|
QString metatile_attrs_path;
|
||||||
QString metatiles_text = readTextFile(root + "/data/tilesets/metatiles.s");
|
QString metatiles_text = readTextFile(root + "/data/tilesets/metatiles.inc");
|
||||||
QList<QStringList> *metatiles_macros = parser->parse(metatiles_text);
|
QList<QStringList> *metatiles_macros = parser->parse(metatiles_text);
|
||||||
QStringList *metatiles_values = getLabelValues(metatiles_macros, tileset->metatiles_label);
|
QStringList *metatiles_values = getLabelValues(metatiles_macros, tileset->metatiles_label);
|
||||||
if (!metatiles_values->isEmpty()) {
|
if (!metatiles_values->isEmpty()) {
|
||||||
|
@ -328,7 +345,7 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
QList<Metatile*> *metatiles = new QList<Metatile*>;
|
QList<Metatile*> *metatiles = new QList<Metatile*>;
|
||||||
for (int i = 0; i < num_metatiles; i++) {
|
for (int i = 0; i < num_metatiles; i++) {
|
||||||
Metatile *metatile = new Metatile;
|
Metatile *metatile = new Metatile;
|
||||||
int index = i * 16;
|
int index = i * (2 * 4 * num_layers);
|
||||||
for (int j = 0; j < 4 * num_layers; j++) {
|
for (int j = 0; j < 4 * num_layers; j++) {
|
||||||
uint16_t word = data[index++] & 0xff;
|
uint16_t word = data[index++] & 0xff;
|
||||||
word += (data[index++] & 0xff) << 8;
|
word += (data[index++] & 0xff) << 8;
|
||||||
|
@ -342,6 +359,9 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
metatiles->append(metatile);
|
metatiles->append(metatile);
|
||||||
}
|
}
|
||||||
tileset->metatiles = metatiles;
|
tileset->metatiles = metatiles;
|
||||||
|
} else {
|
||||||
|
tileset->metatiles = new QList<Metatile*>;
|
||||||
|
qDebug() << QString("Could not open '%1'").arg(metatiles_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile attrs_file(metatile_attrs_path);
|
QFile attrs_file(metatile_attrs_path);
|
||||||
|
@ -354,6 +374,8 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
word += (data[i*2 + 1] & 0xff) << 8;
|
word += (data[i*2 + 1] & 0xff) << 8;
|
||||||
tileset->metatiles->value(i)->attr = word;
|
tileset->metatiles->value(i)->attr = word;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << QString("Could not open '%1'").arg(metatile_attrs_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// palettes
|
// palettes
|
||||||
|
@ -377,6 +399,11 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
QRgb color = qRgb(red * 8, green * 8, blue * 8);
|
QRgb color = qRgb(red * 8, green * 8, blue * 8);
|
||||||
palette.prepend(color);
|
palette.prepend(color);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (int j = 0; j < 16; j++) {
|
||||||
|
palette.append(qRgb(j * 16, j * 16, j * 16));
|
||||||
|
}
|
||||||
|
qDebug() << QString("Could not open '%1'").arg(path);
|
||||||
}
|
}
|
||||||
//qDebug() << path;
|
//qDebug() << path;
|
||||||
palettes->append(palette);
|
palettes->append(palette);
|
||||||
|
@ -420,7 +447,8 @@ QString Project::readTextFile(QString path) {
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
//QMessageBox::information(0, "Error", QString("Could not open '%1': ").arg(path) + file.errorString());
|
//QMessageBox::information(0, "Error", QString("Could not open '%1': ").arg(path) + file.errorString());
|
||||||
return NULL;
|
qDebug() << QString("Could not open '%1': ").arg(path) + file.errorString();
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
QString text = "";
|
QString text = "";
|
||||||
|
@ -434,12 +462,14 @@ void Project::saveTextFile(QString path, QString text) {
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
file.write(text.toUtf8());
|
file.write(text.toUtf8());
|
||||||
|
} else {
|
||||||
|
qDebug() << QString("Could not open '%1' for writing: ").arg(path) + file.errorString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readMapGroups() {
|
void Project::readMapGroups() {
|
||||||
QString text = readTextFile(root + "/data/maps/_groups.s");
|
QString text = readTextFile(root + "/data/maps/_groups.inc");
|
||||||
if (text == NULL) {
|
if (text.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Asm *parser = new Asm;
|
Asm *parser = new Asm;
|
||||||
|
@ -466,12 +496,13 @@ void Project::readMapGroups() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStringList*> *maps = new QList<QStringList*>;
|
QList<QStringList*> *groupedMaps = new QList<QStringList*>;
|
||||||
for (int i = 0; i < groups->length(); i++) {
|
for (int i = 0; i < groups->length(); i++) {
|
||||||
QStringList *list = new QStringList;
|
QStringList *list = new QStringList;
|
||||||
maps->append(list);
|
groupedMaps->append(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList *maps = new QStringList;
|
||||||
int group = -1;
|
int group = -1;
|
||||||
for (int i = 0; i < commands->length(); i++) {
|
for (int i = 0; i < commands->length(); i++) {
|
||||||
QStringList params = commands->value(i);
|
QStringList params = commands->value(i);
|
||||||
|
@ -481,15 +512,17 @@ void Project::readMapGroups() {
|
||||||
} else if (macro == ".4byte") {
|
} else if (macro == ".4byte") {
|
||||||
if (group != -1) {
|
if (group != -1) {
|
||||||
for (int j = 1; j < params.length(); j++) {
|
for (int j = 1; j < params.length(); j++) {
|
||||||
QStringList *list = maps->value(group);
|
QStringList *list = groupedMaps->value(group);
|
||||||
list->append(params.value(j));
|
list->append(params.value(j));
|
||||||
|
maps->append(params.value(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
groupNames = groups;
|
groupNames = groups;
|
||||||
groupedMapNames = maps;
|
groupedMapNames = groupedMaps;
|
||||||
|
mapNames = maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStringList>* Project::parse(QString text) {
|
QList<QStringList>* Project::parse(QString text) {
|
||||||
|
@ -544,8 +577,8 @@ QStringList Project::getBattleScenes() {
|
||||||
|
|
||||||
QStringList Project::getSongNames() {
|
QStringList Project::getSongNames() {
|
||||||
QStringList names;
|
QStringList names;
|
||||||
QString text = readTextFile(root + "/constants/songs.s");
|
QString text = readTextFile(root + "/constants/songs.inc");
|
||||||
if (text != NULL) {
|
if (!text.isNull()) {
|
||||||
QList<QStringList> *commands = parse(text);
|
QList<QStringList> *commands = parse(text);
|
||||||
for (int i = 0; i < commands->length(); i++) {
|
for (int i = 0; i < commands->length(); i++) {
|
||||||
QStringList params = commands->value(i);
|
QStringList params = commands->value(i);
|
||||||
|
@ -560,8 +593,8 @@ QStringList Project::getSongNames() {
|
||||||
|
|
||||||
QString Project::getSongName(int value) {
|
QString Project::getSongName(int value) {
|
||||||
QStringList names;
|
QStringList names;
|
||||||
QString text = readTextFile(root + "/constants/songs.s");
|
QString text = readTextFile(root + "/constants/songs.inc");
|
||||||
if (text != NULL) {
|
if (!text.isNull()) {
|
||||||
QList<QStringList> *commands = parse(text);
|
QList<QStringList> *commands = parse(text);
|
||||||
for (int i = 0; i < commands->length(); i++) {
|
for (int i = 0; i < commands->length(); i++) {
|
||||||
QStringList params = commands->value(i);
|
QStringList params = commands->value(i);
|
||||||
|
@ -578,8 +611,8 @@ QString Project::getSongName(int value) {
|
||||||
|
|
||||||
QMap<QString, int> Project::getMapObjGfxConstants() {
|
QMap<QString, int> Project::getMapObjGfxConstants() {
|
||||||
QMap<QString, int> constants;
|
QMap<QString, int> constants;
|
||||||
QString text = readTextFile(root + "/constants/map_object_constants.s");
|
QString text = readTextFile(root + "/constants/map_object_constants.inc");
|
||||||
if (text != NULL) {
|
if (!text.isNull()) {
|
||||||
QList<QStringList> *commands = parse(text);
|
QList<QStringList> *commands = parse(text);
|
||||||
for (int i = 0; i < commands->length(); i++) {
|
for (int i = 0; i < commands->length(); i++) {
|
||||||
QStringList params = commands->value(i);
|
QStringList params = commands->value(i);
|
||||||
|
@ -602,9 +635,9 @@ QString Project::fixGraphicPath(QString path) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::loadObjectPixmaps(QList<ObjectEvent*> objects) {
|
void Project::loadObjectPixmaps(QList<Event*> objects) {
|
||||||
bool needs_update = false;
|
bool needs_update = false;
|
||||||
for (ObjectEvent *object : objects) {
|
for (Event *object : objects) {
|
||||||
if (object->pixmap.isNull()) {
|
if (object->pixmap.isNull()) {
|
||||||
needs_update = true;
|
needs_update = true;
|
||||||
break;
|
break;
|
||||||
|
@ -616,62 +649,152 @@ void Project::loadObjectPixmaps(QList<ObjectEvent*> objects) {
|
||||||
|
|
||||||
QMap<QString, int> constants = getMapObjGfxConstants();
|
QMap<QString, int> constants = getMapObjGfxConstants();
|
||||||
|
|
||||||
QString pointers_path = root + "/data/graphics/field_objects/map_object_graphics_info_pointers.s";
|
QString pointers_text = readTextFile(root + "/include/data/field_map_obj/map_object_graphics_info_pointers.h");
|
||||||
QString pointers_text = readTextFile(pointers_path);
|
QString info_text = readTextFile(root + "/include/data/field_map_obj/map_object_graphics_info.h");
|
||||||
if (pointers_text == NULL) {
|
QString pic_text = readTextFile(root + "/include/data/field_map_obj/map_object_pic_tables.h");
|
||||||
return;
|
QString assets_text = readTextFile(root + "/src/field_map_obj.c");
|
||||||
}
|
|
||||||
QString info_path = root + "/data/graphics/field_objects/map_object_graphics_info.s";
|
|
||||||
QString info_text = readTextFile(info_path);
|
|
||||||
if (info_text == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString pic_path = root + "/data/graphics/field_objects/map_object_pic_tables.s";
|
|
||||||
QString pic_text = readTextFile(pic_path);
|
|
||||||
if (pic_text == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString assets_path = root + "/data/graphics/field_objects/map_object_graphics.s";
|
|
||||||
QString assets_text = readTextFile(assets_path);
|
|
||||||
if (assets_text == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList *pointers = getLabelValues(parse(pointers_text), "gMapObjectGraphicsInfoPointers");
|
QStringList pointers = readCArray(pointers_text, "gMapObjectGraphicsInfoPointers");
|
||||||
QList<QStringList> *info_commands = parse(info_text);
|
|
||||||
QList<QStringList> *asset_commands = parse(assets_text);
|
|
||||||
QList<QStringList> *pic_commands = parse(pic_text);
|
|
||||||
|
|
||||||
for (ObjectEvent *object : objects) {
|
for (Event *object : objects) {
|
||||||
if (!object->pixmap.isNull()) {
|
if (!object->pixmap.isNull()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int id = constants.value(object->sprite);
|
QString event_type = object->get("event_type");
|
||||||
QString info_label = pointers->value(id);
|
if (event_type == "object") {
|
||||||
QStringList *info = getLabelValues(info_commands, info_label);
|
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(0, 0, 16, 16);
|
||||||
QString pic_label = info->value(12);
|
} else if (event_type == "warp") {
|
||||||
|
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(16, 0, 16, 16);
|
||||||
|
} else if (event_type == "trap") {
|
||||||
|
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(32, 0, 16, 16);
|
||||||
|
} else if (event_type == "sign" || event_type == "hidden item") {
|
||||||
|
object->pixmap = QPixmap(":/images/Entities_16x16.png").copy(48, 0, 16, 16);
|
||||||
|
}
|
||||||
|
|
||||||
QList<QStringList> *pic = getLabelMacros(pic_commands, pic_label);
|
if (event_type == "object") {
|
||||||
for (int i = 0; i < pic->length(); i++) {
|
|
||||||
QStringList command = pic->value(i);
|
int sprite_id = constants.value(object->get("sprite"));
|
||||||
QString macro = command.value(0);
|
|
||||||
if (macro == "obj_frame_tiles") {
|
QString info_label = pointers.value(sprite_id).replace("&", "");
|
||||||
QString label = command.value(1);
|
QString pic_label = readCArray(info_text, info_label).value(14);
|
||||||
QStringList *incbins = getLabelValues(asset_commands, label);
|
QString gfx_label = readCArray(pic_text, pic_label).value(0);
|
||||||
QString path = incbins->value(0).section('"', 1, 1);
|
gfx_label = gfx_label.section(QRegExp("[\\(\\)]"), 1, 1);
|
||||||
|
QString path = readCIncbin(assets_text, gfx_label);
|
||||||
|
|
||||||
|
if (!path.isNull()) {
|
||||||
path = fixGraphicPath(path);
|
path = fixGraphicPath(path);
|
||||||
QPixmap pixmap(root + "/" + path);
|
QPixmap pixmap(root + "/" + path);
|
||||||
object->pixmap = pixmap;
|
if (!pixmap.isNull()) {
|
||||||
break;
|
object->pixmap = pixmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::saveMapEvents(Map *map) {
|
||||||
|
QString path = root + QString("/data/maps/events/%1.inc").arg(map->name);
|
||||||
|
QString text = "";
|
||||||
|
|
||||||
|
text += QString("%1::\n").arg(map->object_events_label);
|
||||||
|
for (int i = 0; i < map->events["object"].length(); i++) {
|
||||||
|
Event *object_event = map->events["object"].value(i);
|
||||||
|
int radius_x = object_event->getInt("radius_x");
|
||||||
|
int radius_y = object_event->getInt("radius_y");
|
||||||
|
QString radius = QString("%1").arg((radius_x & 0xf) + ((radius_y & 0xf) << 4));
|
||||||
|
uint16_t x = object_event->getInt("x");
|
||||||
|
uint16_t y = object_event->getInt("y");
|
||||||
|
|
||||||
|
text += QString("\tobject_event %1").arg(i + 1);
|
||||||
|
text += QString(", %1").arg(object_event->get("sprite"));
|
||||||
|
text += QString(", %1").arg(object_event->get("replacement"));
|
||||||
|
text += QString(", %1").arg(x & 0xff);
|
||||||
|
text += QString(", %1").arg((x >> 8) & 0xff);
|
||||||
|
text += QString(", %1").arg(y & 0xff);
|
||||||
|
text += QString(", %1").arg((y >> 8) & 0xff);
|
||||||
|
text += QString(", %1").arg(object_event->get("elevation"));
|
||||||
|
text += QString(", %1").arg(object_event->get("behavior"));
|
||||||
|
text += QString(", %1").arg(radius);
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", %1").arg(object_event->get("property"));
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", %1").arg(object_event->get("sight_radius"));
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", %1").arg(object_event->get("script_label"));
|
||||||
|
text += QString(", %1").arg(object_event->get("event_flag"));
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", 0");
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
|
text += "\n";
|
||||||
|
|
||||||
|
text += QString("%1::\n").arg(map->warps_label);
|
||||||
|
for (Event *warp : map->events["warp"]) {
|
||||||
|
text += QString("\twarp_def %1").arg(warp->get("x"));
|
||||||
|
text += QString(", %1").arg(warp->get("y"));
|
||||||
|
text += QString(", %1").arg(warp->get("elevation"));
|
||||||
|
text += QString(", %1").arg(warp->get("destination_warp"));
|
||||||
|
text += QString(", %1").arg(warp->get("destination_map"));
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
|
text += "\n";
|
||||||
|
|
||||||
|
text += QString("%1::\n").arg(map->coord_events_label);
|
||||||
|
for (Event *coords : map->events["trap"]) {
|
||||||
|
text += QString("\tcoord_event %1").arg(coords->get("x"));
|
||||||
|
text += QString(", %1").arg(coords->get("y"));
|
||||||
|
text += QString(", %1").arg(coords->get("elevation"));
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", %1").arg(coords->get("coord_unknown1"));
|
||||||
|
text += QString(", %1").arg(coords->get("coord_unknown2"));
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", %1").arg(coords->get("script_label"));
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
|
text += "\n";
|
||||||
|
|
||||||
|
text += QString("%1::\n").arg(map->bg_events_label);
|
||||||
|
for (Event *sign : map->events["sign"]) {
|
||||||
|
text += QString("\tbg_event %1").arg(sign->get("x"));
|
||||||
|
text += QString(", %1").arg(sign->get("y"));
|
||||||
|
text += QString(", %1").arg(sign->get("elevation"));
|
||||||
|
text += QString(", %1").arg(sign->get("type"));
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", %1").arg(sign->get("script_label"));
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
|
for (Event *item : map->events["hidden item"]) {
|
||||||
|
text += QString("\tbg_event %1").arg(item->get("x"));
|
||||||
|
text += QString(", %1").arg(item->get("y"));
|
||||||
|
text += QString(", %1").arg(item->get("elevation"));
|
||||||
|
text += QString(", %1").arg(item->get("type"));
|
||||||
|
text += QString(", 0");
|
||||||
|
text += QString(", %1").arg(item->get("item"));
|
||||||
|
text += QString(", %1").arg(item->get("item_unknown5"));
|
||||||
|
text += QString(", %1").arg(item->get("item_unknown6"));
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
|
text += "\n";
|
||||||
|
|
||||||
|
text += QString("%1::\n").arg(map->events_label);
|
||||||
|
text += QString("\tmap_events %1, %2, %3, %4\n")
|
||||||
|
.arg(map->object_events_label)
|
||||||
|
.arg(map->warps_label)
|
||||||
|
.arg(map->coord_events_label)
|
||||||
|
.arg(map->bg_events_label);
|
||||||
|
|
||||||
|
saveTextFile(path, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::readMapEvents(Map *map) {
|
void Project::readMapEvents(Map *map) {
|
||||||
// lazy
|
// lazy
|
||||||
QString path = root + QString("/data/maps/events/%1.s").arg(map->name);
|
QString path = root + QString("/data/maps/events/%1.inc").arg(map->name);
|
||||||
QString text = readTextFile(path);
|
QString text = readTextFile(path);
|
||||||
|
if (text.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList *labels = getLabelValues(parse(text), map->events_label);
|
QStringList *labels = getLabelValues(parse(text), map->events_label);
|
||||||
map->object_events_label = labels->value(0);
|
map->object_events_label = labels->value(0);
|
||||||
|
@ -680,10 +803,11 @@ void Project::readMapEvents(Map *map) {
|
||||||
map->bg_events_label = labels->value(3);
|
map->bg_events_label = labels->value(3);
|
||||||
|
|
||||||
QList<QStringList> *object_events = getLabelMacros(parse(text), map->object_events_label);
|
QList<QStringList> *object_events = getLabelMacros(parse(text), map->object_events_label);
|
||||||
map->object_events.clear();
|
map->events["object"].clear();
|
||||||
for (QStringList command : *object_events) {
|
for (QStringList command : *object_events) {
|
||||||
if (command.value(0) == "object_event") {
|
if (command.value(0) == "object_event") {
|
||||||
ObjectEvent *object = new ObjectEvent;
|
Event *object = new Event;
|
||||||
|
object->put("map_name", map->name);
|
||||||
// This macro is not fixed as of writing, but it should take fewer args.
|
// This macro is not fixed as of writing, but it should take fewer args.
|
||||||
bool old_macro = false;
|
bool old_macro = false;
|
||||||
if (command.length() >= 20) {
|
if (command.length() >= 20) {
|
||||||
|
@ -692,96 +816,156 @@ void Project::readMapEvents(Map *map) {
|
||||||
command.removeAt(15);
|
command.removeAt(15);
|
||||||
command.removeAt(13);
|
command.removeAt(13);
|
||||||
command.removeAt(11);
|
command.removeAt(11);
|
||||||
command.removeAt(7);
|
|
||||||
command.removeAt(5);
|
|
||||||
command.removeAt(1); // id. not 0, but is just the index in the list of objects
|
command.removeAt(1); // id. not 0, but is just the index in the list of objects
|
||||||
old_macro = true;
|
old_macro = true;
|
||||||
}
|
}
|
||||||
int i = 1;
|
int i = 1;
|
||||||
object->sprite = command.value(i++);
|
object->put("sprite", command.value(i++));
|
||||||
object->replacement = command.value(i++);
|
object->put("replacement", command.value(i++));
|
||||||
object->x_ = command.value(i++);
|
int16_t x = command.value(i++).toInt(nullptr, 0) | (command.value(i++).toInt(nullptr, 0) << 8);
|
||||||
object->y_ = command.value(i++);
|
int16_t y = command.value(i++).toInt(nullptr, 0) | (command.value(i++).toInt(nullptr, 0) << 8);
|
||||||
object->elevation_ = command.value(i++);
|
object->put("x", x);
|
||||||
object->behavior = command.value(i++);
|
object->put("y", y);
|
||||||
|
object->put("elevation", command.value(i++));
|
||||||
|
object->put("behavior", command.value(i++));
|
||||||
if (old_macro) {
|
if (old_macro) {
|
||||||
int radius = command.value(i++).toInt(nullptr, 0);
|
int radius = command.value(i++).toInt(nullptr, 0);
|
||||||
object->radius_x = QString("%1").arg(radius & 0xf);
|
object->put("radius_x", radius & 0xf);
|
||||||
object->radius_y = QString("%1").arg((radius >> 4) & 0xf);
|
object->put("radius_y", (radius >> 4) & 0xf);
|
||||||
} else {
|
} else {
|
||||||
object->radius_x = command.value(i++);
|
object->put("radius_x", command.value(i++));
|
||||||
object->radius_y = command.value(i++);
|
object->put("radius_y", command.value(i++));
|
||||||
}
|
}
|
||||||
object->property = command.value(i++);
|
object->put("property", command.value(i++));
|
||||||
object->sight_radius = command.value(i++);
|
object->put("sight_radius", command.value(i++));
|
||||||
object->script_label = command.value(i++);
|
object->put("script_label", command.value(i++));
|
||||||
object->event_flag = command.value(i++);
|
object->put("event_flag", command.value(i++));
|
||||||
|
|
||||||
map->object_events.append(object);
|
object->put("event_type", "object");
|
||||||
|
map->events["object"].append(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStringList> *warps = getLabelMacros(parse(text), map->warps_label);
|
QList<QStringList> *warps = getLabelMacros(parse(text), map->warps_label);
|
||||||
map->warps.clear();
|
map->events["warp"].clear();
|
||||||
for (QStringList command : *warps) {
|
for (QStringList command : *warps) {
|
||||||
if (command.value(0) == "warp_def") {
|
if (command.value(0) == "warp_def") {
|
||||||
Warp *warp = new Warp;
|
Event *warp = new Event;
|
||||||
|
warp->put("map_name", map->name);
|
||||||
int i = 1;
|
int i = 1;
|
||||||
warp->x_ = command.value(i++);
|
warp->put("x", command.value(i++));
|
||||||
warp->y_ = command.value(i++);
|
warp->put("y", command.value(i++));
|
||||||
warp->elevation_ = command.value(i++);
|
warp->put("elevation", command.value(i++));
|
||||||
warp->destination_warp = command.value(i++);
|
warp->put("destination_warp", command.value(i++));
|
||||||
warp->destination_map = command.value(i++);
|
warp->put("destination_map", command.value(i++));
|
||||||
map->warps.append(warp);
|
|
||||||
|
warp->put("event_type", "warp");
|
||||||
|
map->events["warp"].append(warp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStringList> *coords = getLabelMacros(parse(text), map->coord_events_label);
|
QList<QStringList> *coords = getLabelMacros(parse(text), map->coord_events_label);
|
||||||
map->coord_events.clear();
|
map->events["trap"].clear();
|
||||||
for (QStringList command : *coords) {
|
for (QStringList command : *coords) {
|
||||||
if (command.value(0) == "coord_event") {
|
if (command.value(0) == "coord_event") {
|
||||||
CoordEvent *coord = new CoordEvent;
|
Event *coord = new Event;
|
||||||
|
coord->put("map_name", map->name);
|
||||||
bool old_macro = false;
|
bool old_macro = false;
|
||||||
if (command.length() >= 9) {
|
if (command.length() >= 9) {
|
||||||
command.removeAt(7);
|
command.removeAt(7);
|
||||||
command.removeAt(6);
|
|
||||||
command.removeAt(4);
|
command.removeAt(4);
|
||||||
old_macro = true;
|
old_macro = true;
|
||||||
}
|
}
|
||||||
int i = 1;
|
int i = 1;
|
||||||
coord->x_ = command.value(i++);
|
coord->put("x", command.value(i++));
|
||||||
coord->y_ = command.value(i++);
|
coord->put("y", command.value(i++));
|
||||||
coord->elevation_ = command.value(i++);
|
coord->put("elevation", command.value(i++));
|
||||||
coord->unknown1 = command.value(i++);
|
coord->put("coord_unknown1", command.value(i++));
|
||||||
coord->script_label = command.value(i++);
|
coord->put("coord_unknown2", command.value(i++));
|
||||||
map->coord_events.append(coord);
|
coord->put("script_label", command.value(i++));
|
||||||
|
//coord_unknown3
|
||||||
|
//coord_unknown4
|
||||||
|
|
||||||
|
coord->put("event_type", "trap");
|
||||||
|
map->events["trap"].append(coord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QStringList> *bgs = getLabelMacros(parse(text), map->warps_label);
|
QList<QStringList> *bgs = getLabelMacros(parse(text), map->bg_events_label);
|
||||||
map->hidden_items.clear();
|
map->events["hidden item"].clear();
|
||||||
map->signs.clear();
|
map->events["sign"].clear();
|
||||||
for (QStringList command : *bgs) {
|
for (QStringList command : *bgs) {
|
||||||
if (command.value(0) == "bg_event") {
|
if (command.value(0) == "bg_event") {
|
||||||
BGEvent *bg = new BGEvent;
|
Event *bg = new Event;
|
||||||
|
bg->put("map_name", map->name);
|
||||||
int i = 1;
|
int i = 1;
|
||||||
bg->x_ = command.value(i++);
|
bg->put("x", command.value(i++));
|
||||||
bg->y_ = command.value(i++);
|
bg->put("y", command.value(i++));
|
||||||
bg->elevation_ = command.value(i++);
|
bg->put("elevation", command.value(i++));
|
||||||
bg->type = command.value(i++);
|
bg->put("type", command.value(i++));
|
||||||
i++;
|
i++;
|
||||||
if (bg->is_item()) {
|
if (bg->is_hidden_item()) {
|
||||||
HiddenItem *item = new HiddenItem(*bg);
|
bg->put("item", command.value(i++));
|
||||||
item->item = command.value(i++);
|
bg->put("item_unknown5", command.value(i++));
|
||||||
item->unknown5 = command.value(i++);
|
bg->put("item_unknown6", command.value(i++));
|
||||||
item->unknown6 = command.value(i++);
|
|
||||||
map->hidden_items.append(item);
|
bg->put("event_type", "hidden item");
|
||||||
|
map->events["hidden item"].append(bg);
|
||||||
} else {
|
} else {
|
||||||
Sign *sign = new Sign(*bg);
|
bg->put("script_label", command.value(i++));
|
||||||
sign->script_label = command.value(i++);
|
//sign_unknown7
|
||||||
map->signs.append(sign);
|
|
||||||
|
bg->put("event_type", "sign");
|
||||||
|
map->events["sign"].append(bg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList Project::readCArray(QString text, QString label) {
|
||||||
|
QStringList list;
|
||||||
|
|
||||||
|
if (label.isNull()) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRegExp *re = new QRegExp(QString("\\b%1\\b\\s*\\[?\\s*\\]?\\s*=\\s*\\{([^\\}]*)\\}").arg(label));
|
||||||
|
int pos = re->indexIn(text);
|
||||||
|
if (pos != -1) {
|
||||||
|
QString body = re->cap(1);
|
||||||
|
body = body.replace(QRegExp("\\s*"), "");
|
||||||
|
list = body.split(',');
|
||||||
|
/*
|
||||||
|
QRegExp *inner = new QRegExp("&?\\b([A-Za-z0-9_\\(\\)]*)\\b,");
|
||||||
|
int pos = 0;
|
||||||
|
while ((pos = inner->indexIn(body, pos)) != -1) {
|
||||||
|
list << inner->cap(1);
|
||||||
|
pos += inner->matchedLength();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Project::readCIncbin(QString text, QString label) {
|
||||||
|
QString path;
|
||||||
|
|
||||||
|
if (label.isNull()) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRegExp *re = new QRegExp(QString(
|
||||||
|
"\\b%1\\b"
|
||||||
|
"\\s*\\[?\\s*\\]?\\s*=\\s*"
|
||||||
|
"INCBIN_[US][0-9][0-9]?"
|
||||||
|
"\\(\"([^\"]*)\"\\)").arg(label));
|
||||||
|
|
||||||
|
int pos = re->indexIn(text);
|
||||||
|
if (pos != -1) {
|
||||||
|
path = re->cap(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
14
project.h
|
@ -12,14 +12,15 @@ class Project
|
||||||
public:
|
public:
|
||||||
Project();
|
Project();
|
||||||
QString root;
|
QString root;
|
||||||
QStringList *groupNames;
|
QStringList *groupNames = NULL;
|
||||||
QList<QStringList*> *groupedMapNames;
|
QList<QStringList*> *groupedMapNames = NULL;
|
||||||
|
QStringList *mapNames = NULL;
|
||||||
|
|
||||||
QMap<QString, Map*> *map_cache;
|
QMap<QString, Map*> *map_cache;
|
||||||
Map* loadMap(QString);
|
Map* loadMap(QString);
|
||||||
Map* getMap(QString);
|
Map* getMap(QString);
|
||||||
|
|
||||||
QMap<QString, Tileset*> *tileset_cache;
|
QMap<QString, Tileset*> *tileset_cache = NULL;
|
||||||
Tileset* loadTileset(QString);
|
Tileset* loadTileset(QString);
|
||||||
Tileset* getTileset(QString);
|
Tileset* getTileset(QString);
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ public:
|
||||||
QStringList getMapTypes();
|
QStringList getMapTypes();
|
||||||
QStringList getBattleScenes();
|
QStringList getBattleScenes();
|
||||||
|
|
||||||
void loadObjectPixmaps(QList<ObjectEvent*> objects);
|
void loadObjectPixmaps(QList<Event*> objects);
|
||||||
QMap<QString, int> getMapObjGfxConstants();
|
QMap<QString, int> getMapObjGfxConstants();
|
||||||
QString fixGraphicPath(QString path);
|
QString fixGraphicPath(QString path);
|
||||||
|
|
||||||
|
@ -64,6 +65,11 @@ public:
|
||||||
|
|
||||||
void loadMapBorder(Map *map);
|
void loadMapBorder(Map *map);
|
||||||
QString getMapBorderPath(Map *map);
|
QString getMapBorderPath(Map *map);
|
||||||
|
|
||||||
|
void saveMapEvents(Map *map);
|
||||||
|
|
||||||
|
QStringList readCArray(QString text, QString label);
|
||||||
|
QString readCIncbin(QString text, QString label);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROJECT_H
|
#endif // PROJECT_H
|
||||||
|
|
BIN
resources/icons/add.ico
Executable file
After Width: | Height: | Size: 5.3 KiB |
BIN
resources/icons/cursor.ico
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/icons/delete.ico
Executable file
After Width: | Height: | Size: 5.3 KiB |
BIN
resources/icons/fill_color.ico
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/icons/pencil.ico
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/icons/pipette.ico
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/icons/viewsprites.ico
Executable file
After Width: | Height: | Size: 5.3 KiB |
|
@ -7,5 +7,13 @@
|
||||||
<file>icons/folder_map.ico</file>
|
<file>icons/folder_map.ico</file>
|
||||||
<file>icons/image.ico</file>
|
<file>icons/image.ico</file>
|
||||||
<file>icons/map.ico</file>
|
<file>icons/map.ico</file>
|
||||||
|
<file>icons/cursor.ico</file>
|
||||||
|
<file>icons/fill_color.ico</file>
|
||||||
|
<file>icons/pencil.ico</file>
|
||||||
|
<file>icons/pipette.ico</file>
|
||||||
|
<file>images/Entities_16x16.png</file>
|
||||||
|
<file>icons/add.ico</file>
|
||||||
|
<file>icons/delete.ico</file>
|
||||||
|
<file>icons/viewsprites.ico</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
BIN
resources/images/Entities_16x16.png
Executable file
After Width: | Height: | Size: 274 B |
|
@ -19,9 +19,9 @@ public:
|
||||||
QString callback_label;
|
QString callback_label;
|
||||||
QString metatile_attrs_label;
|
QString metatile_attrs_label;
|
||||||
|
|
||||||
QList<QImage> *tiles;
|
QList<QImage> *tiles = NULL;
|
||||||
QList<Metatile*> *metatiles;
|
QList<Metatile*> *metatiles = NULL;
|
||||||
QList<QList<QRgb>> *palettes;
|
QList<QList<QRgb>> *palettes = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TILESET_H
|
#endif // TILESET_H
|
||||||
|
|