commit
6f3c5c25dd
11 changed files with 594 additions and 411 deletions
|
@ -11,6 +11,9 @@ class Blockdata : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Blockdata(QObject *parent = 0);
|
explicit Blockdata(QObject *parent = 0);
|
||||||
|
~Blockdata() {
|
||||||
|
if (blocks) delete blocks;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<Block> *blocks = NULL;
|
QList<Block> *blocks = NULL;
|
||||||
|
|
347
editor.cpp
347
editor.cpp
|
@ -31,6 +31,7 @@ void Editor::undo() {
|
||||||
if (current_view) {
|
if (current_view) {
|
||||||
map->undo();
|
map->undo();
|
||||||
map_item->draw();
|
map_item->draw();
|
||||||
|
collision_item->draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ void Editor::redo() {
|
||||||
if (current_view) {
|
if (current_view) {
|
||||||
map->redo();
|
map->redo();
|
||||||
map_item->draw();
|
map_item->draw();
|
||||||
|
collision_item->draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,13 +326,21 @@ void Editor::setMap(QString map_name) {
|
||||||
}
|
}
|
||||||
if (project) {
|
if (project) {
|
||||||
map = project->loadMap(map_name);
|
map = project->loadMap(map_name);
|
||||||
|
connect(map, &Map::paintTileChanged, [=](Map *map) {
|
||||||
|
lastSelectedMetatilesFromMap = false;
|
||||||
|
redrawCurrentMetatilesSelection();
|
||||||
|
});
|
||||||
selected_events->clear();
|
selected_events->clear();
|
||||||
|
updateCurrentMetatilesSelection();
|
||||||
displayMap();
|
displayMap();
|
||||||
updateSelectedEvents();
|
updateSelectedEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
||||||
|
if (event->buttons() & Qt::RightButton) {
|
||||||
|
item->updateMetatileSelection(event);
|
||||||
|
} else {
|
||||||
if (map_edit_mode == "paint") {
|
if (map_edit_mode == "paint") {
|
||||||
item->paint(event);
|
item->paint(event);
|
||||||
} else if (map_edit_mode == "fill") {
|
} else if (map_edit_mode == "fill") {
|
||||||
|
@ -341,7 +351,11 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
||||||
item->select(event);
|
item->select(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
|
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
|
||||||
|
if (event->buttons() & Qt::RightButton) {
|
||||||
|
item->updateMovementPermissionSelection(event);
|
||||||
|
} else {
|
||||||
if (map_edit_mode == "paint") {
|
if (map_edit_mode == "paint") {
|
||||||
item->paint(event);
|
item->paint(event);
|
||||||
} else if (map_edit_mode == "fill") {
|
} else if (map_edit_mode == "fill") {
|
||||||
|
@ -352,6 +366,16 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
|
||||||
item->select(event);
|
item->select(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::updateCurrentMetatilesSelection() {
|
||||||
|
if (lastSelectedMetatilesFromMap) {
|
||||||
|
// Remember the copied metatiles from the previously-opened map
|
||||||
|
map->selected_metatiles_width = this->copiedMetatileSelectionWidth;
|
||||||
|
map->selected_metatiles_height = this->copiedMetatileSelectionHeight;
|
||||||
|
*map->selected_metatiles = *this->copiedMetatileSelection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::displayMap() {
|
void Editor::displayMap() {
|
||||||
if (!scene)
|
if (!scene)
|
||||||
|
@ -361,7 +385,7 @@ void Editor::displayMap() {
|
||||||
scene->removeItem(map_item);
|
scene->removeItem(map_item);
|
||||||
delete map_item;
|
delete map_item;
|
||||||
}
|
}
|
||||||
map_item = new MapPixmapItem(map);
|
map_item = new MapPixmapItem(map, this);
|
||||||
connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
|
connect(map_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,MapPixmapItem*)),
|
||||||
this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
this, SLOT(mouseEvent_map(QGraphicsSceneMouseEvent*,MapPixmapItem*)));
|
||||||
|
|
||||||
|
@ -372,7 +396,7 @@ void Editor::displayMap() {
|
||||||
scene->removeItem(collision_item);
|
scene->removeItem(collision_item);
|
||||||
delete collision_item;
|
delete collision_item;
|
||||||
}
|
}
|
||||||
collision_item = new CollisionPixmapItem(map);
|
collision_item = new CollisionPixmapItem(map, this);
|
||||||
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
|
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
|
||||||
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
||||||
|
|
||||||
|
@ -390,8 +414,8 @@ void Editor::displayMap() {
|
||||||
|
|
||||||
displayMetatiles();
|
displayMetatiles();
|
||||||
displayBorderMetatiles();
|
displayBorderMetatiles();
|
||||||
|
displayCurrentMetatilesSelection();
|
||||||
displayCollisionMetatiles();
|
displayCollisionMetatiles();
|
||||||
displayElevationMetatiles();
|
|
||||||
displayMapEvents();
|
displayMapEvents();
|
||||||
displayMapConnections();
|
displayMapConnections();
|
||||||
displayMapBorder();
|
displayMapBorder();
|
||||||
|
@ -434,6 +458,25 @@ void Editor::displayBorderMetatiles() {
|
||||||
connect(selected_border_metatiles_item, SIGNAL(borderMetatilesChanged()), this, SLOT(onBorderMetatilesChanged()));
|
connect(selected_border_metatiles_item, SIGNAL(borderMetatilesChanged()), this, SLOT(onBorderMetatilesChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::displayCurrentMetatilesSelection() {
|
||||||
|
if (scene_current_metatile_selection_item && scene_current_metatile_selection_item->scene()) {
|
||||||
|
scene_current_metatile_selection_item->scene()->removeItem(scene_current_metatile_selection_item);
|
||||||
|
delete scene_current_metatile_selection_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
scene_current_metatile_selection = new QGraphicsScene;
|
||||||
|
scene_current_metatile_selection_item = new CurrentSelectedMetatilesPixmapItem(map);
|
||||||
|
scene_current_metatile_selection_item->draw();
|
||||||
|
scene_current_metatile_selection->addItem(scene_current_metatile_selection_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::redrawCurrentMetatilesSelection() {
|
||||||
|
if (scene_current_metatile_selection_item) {
|
||||||
|
scene_current_metatile_selection_item->draw();
|
||||||
|
emit currentMetatilesSelectionChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::displayCollisionMetatiles() {
|
void Editor::displayCollisionMetatiles() {
|
||||||
if (collision_metatiles_item && collision_metatiles_item->scene()) {
|
if (collision_metatiles_item && collision_metatiles_item->scene()) {
|
||||||
collision_metatiles_item->scene()->removeItem(collision_metatiles_item);
|
collision_metatiles_item->scene()->removeItem(collision_metatiles_item);
|
||||||
|
@ -441,23 +484,11 @@ void Editor::displayCollisionMetatiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
scene_collision_metatiles = new QGraphicsScene;
|
scene_collision_metatiles = new QGraphicsScene;
|
||||||
collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
|
collision_metatiles_item = new MovementPermissionsPixmapItem(map);
|
||||||
collision_metatiles_item->draw();
|
collision_metatiles_item->draw();
|
||||||
scene_collision_metatiles->addItem(collision_metatiles_item);
|
scene_collision_metatiles->addItem(collision_metatiles_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::displayElevationMetatiles() {
|
|
||||||
if (elevation_metatiles_item && elevation_metatiles_item->scene()) {
|
|
||||||
elevation_metatiles_item->scene()->removeItem(elevation_metatiles_item);
|
|
||||||
delete elevation_metatiles_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
scene_elevation_metatiles = new QGraphicsScene;
|
|
||||||
elevation_metatiles_item = new ElevationMetatilesPixmapItem(map);
|
|
||||||
elevation_metatiles_item->draw();
|
|
||||||
scene_elevation_metatiles->addItem(elevation_metatiles_item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Editor::displayMapEvents() {
|
void Editor::displayMapEvents() {
|
||||||
if (events_group) {
|
if (events_group) {
|
||||||
for (QGraphicsItem *child : events_group->childItems()) {
|
for (QGraphicsItem *child : events_group->childItems()) {
|
||||||
|
@ -863,35 +894,28 @@ void MetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
int y = ((int)pos.y()) / 16;
|
int y = ((int)pos.y()) / 16;
|
||||||
map->paint_metatile_initial_x = x;
|
map->paint_metatile_initial_x = x;
|
||||||
map->paint_metatile_initial_y = y;
|
map->paint_metatile_initial_y = y;
|
||||||
updateSelection(event->pos(), event->button());
|
updateSelection(event->pos());
|
||||||
}
|
}
|
||||||
void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatilesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
updateCurHoveredMetatile(event->pos());
|
updateCurHoveredMetatile(event->pos());
|
||||||
Qt::MouseButton button = event->button();
|
updateSelection(event->pos());
|
||||||
if (button == Qt::MouseButton::NoButton) {
|
|
||||||
Qt::MouseButtons heldButtons = event->buttons();
|
|
||||||
if (heldButtons & Qt::RightButton) {
|
|
||||||
button = Qt::RightButton;
|
|
||||||
} else if (heldButtons & Qt::LeftButton) {
|
|
||||||
button = Qt::LeftButton;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateSelection(event->pos(), button);
|
|
||||||
}
|
}
|
||||||
void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void MetatilesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
updateSelection(event->pos(), event->button());
|
updateSelection(event->pos());
|
||||||
}
|
}
|
||||||
void MetatilesPixmapItem::updateSelection(QPointF pos, Qt::MouseButton button) {
|
void MetatilesPixmapItem::updateSelection(QPointF pos) {
|
||||||
int x = ((int)pos.x()) / 16;
|
int x = ((int)pos.x()) / 16;
|
||||||
int y = ((int)pos.y()) / 16;
|
int y = ((int)pos.y()) / 16;
|
||||||
int width = pixmap().width() / 16;
|
int width = pixmap().width() / 16;
|
||||||
int height = pixmap().height() / 16;
|
int height = pixmap().height() / 16;
|
||||||
if ((x >= 0 && x < width) && (y >=0 && y < height)) {
|
if ((x >= 0 && x < width) && (y >=0 && y < height)) {
|
||||||
int baseTileX = x < map->paint_metatile_initial_x ? x : map->paint_metatile_initial_x;
|
int x1 = x < map->paint_metatile_initial_x ? x : map->paint_metatile_initial_x;
|
||||||
int baseTileY = y < map->paint_metatile_initial_y ? y : map->paint_metatile_initial_y;
|
int y1 = y < map->paint_metatile_initial_y ? y : map->paint_metatile_initial_y;
|
||||||
map->paint_tile_index = baseTileY * 8 + baseTileX;
|
map->paint_tile_index = y1 * 8 + x1;
|
||||||
map->paint_tile_width = abs(map->paint_metatile_initial_x - x) + 1;
|
map->paint_tile_width = abs(map->paint_metatile_initial_x - x) + 1;
|
||||||
map->paint_tile_height = abs(map->paint_metatile_initial_y - y) + 1;
|
map->paint_tile_height = abs(map->paint_metatile_initial_y - y) + 1;
|
||||||
|
map->setSelectedMetatilesFromTilePicker();
|
||||||
|
|
||||||
emit map->paintTileChanged(map);
|
emit map->paintTileChanged(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -901,10 +925,10 @@ void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
int x = ((int)pos.x()) / 16;
|
int x = ((int)pos.x()) / 16;
|
||||||
int y = ((int)pos.y()) / 16;
|
int y = ((int)pos.y()) / 16;
|
||||||
|
|
||||||
for (int i = 0; i < map->paint_tile_width && (i + x) < 2; i++) {
|
for (int i = 0; i < map->selected_metatiles_width && (i + x) < 2; i++) {
|
||||||
for (int j = 0; j < map->paint_tile_height && (j + y) < 2; j++) {
|
for (int j = 0; j < map->selected_metatiles_height && (j + y) < 2; j++) {
|
||||||
int blockIndex = (j + y) * 2 + (i + x);
|
int blockIndex = (j + y) * 2 + (i + x);
|
||||||
int tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8));
|
int tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i);
|
||||||
(*map->layout->border->blocks)[blockIndex].tile = tile;
|
(*map->layout->border->blocks)[blockIndex].tile = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -933,15 +957,40 @@ void BorderMetatilesPixmapItem::draw() {
|
||||||
setPixmap(QPixmap::fromImage(image));
|
setPixmap(QPixmap::fromImage(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CurrentSelectedMetatilesPixmapItem::draw() {
|
||||||
|
int width = map->selected_metatiles_width * 16;
|
||||||
|
int height = map->selected_metatiles_height * 16;
|
||||||
|
QImage image(width, height, QImage::Format_RGBA8888);
|
||||||
|
QPainter painter(&image);
|
||||||
|
|
||||||
|
for (int i = 0; i < map->selected_metatiles_width; i++)
|
||||||
|
for (int j = 0; j < map->selected_metatiles_height; j++)
|
||||||
|
{
|
||||||
|
int x = i * 16;
|
||||||
|
int y = j * 16;
|
||||||
|
int index = j * map->selected_metatiles_width + i;
|
||||||
|
QImage metatile_image = Metatile::getMetatileImage(map->selected_metatiles->at(index), map->layout->tileset_primary, map->layout->tileset_secondary);
|
||||||
|
QPoint metatile_origin = QPoint(x, y);
|
||||||
|
painter.drawImage(metatile_origin, metatile_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.end();
|
||||||
|
setPixmap(QPixmap::fromImage(image));
|
||||||
|
}
|
||||||
|
|
||||||
void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int x = ((int)pos.x()) / 16;
|
int x = ((int)pos.x()) / 32;
|
||||||
int y = ((int)pos.y()) / 16;
|
int y = ((int)pos.y()) / 32;
|
||||||
int width = pixmap().width() / 16;
|
int width = pixmap().width() / 32;
|
||||||
int height = pixmap().height() / 16;
|
int height = pixmap().height() / 32;
|
||||||
if ((x >= 0 && x < width) && (y >=0 && y < height)) {
|
|
||||||
pick(y * width + x);
|
// Snap to a valid position inside the selection area.
|
||||||
}
|
if (x < 0) x = 0;
|
||||||
|
if (x >= width) x = width - 1;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
if (y >= height) y = height - 1;
|
||||||
|
pick(x, y);
|
||||||
}
|
}
|
||||||
void MovementPermissionsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
|
void MovementPermissionsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
|
||||||
updateCurHoveredMetatile(event->pos());
|
updateCurHoveredMetatile(event->pos());
|
||||||
|
@ -951,17 +1000,18 @@ void MovementPermissionsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent*
|
||||||
mousePressEvent(event);
|
mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
void MovementPermissionsPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
||||||
int x = ((int)pos.x()) / 16;
|
int x = ((int)pos.x()) / 32;
|
||||||
int y = ((int)pos.y()) / 16;
|
int y = ((int)pos.y()) / 32;
|
||||||
int width = pixmap().width() / 16;
|
int width = pixmap().width() / 32;
|
||||||
int height = pixmap().height() / 16;
|
int height = pixmap().height() / 32;
|
||||||
if (x < 0 || x >= width || y < 0 || y >= height) {
|
|
||||||
map->clearHoveredCollisionTile();
|
// Snap to a valid position inside the selection area.
|
||||||
} else {
|
if (x < 0) x = 0;
|
||||||
int collision = y * width + x;
|
if (x >= width) x = width - 1;
|
||||||
map->hoveredCollisionTileChanged(collision);
|
if (y < 0) y = 0;
|
||||||
}
|
if (y >= height) y = height - 1;
|
||||||
|
map->hoveredMovementPermissionTileChanged(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConnectionPixmapItem::getMinOffset() {
|
int ConnectionPixmapItem::getMinOffset() {
|
||||||
|
@ -1020,34 +1070,23 @@ void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) {
|
||||||
emit connectionItemDoubleClicked(this);
|
emit connectionItemDoubleClicked(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
|
||||||
int x = ((int)pos.x()) / 16;
|
|
||||||
int y = ((int)pos.y()) / 16;
|
|
||||||
int width = pixmap().width() / 16;
|
|
||||||
int height = pixmap().height() / 16;
|
|
||||||
if (x < 0 || x >= width || y < 0 || y >= height) {
|
|
||||||
map->clearHoveredElevationTile();
|
|
||||||
} else {
|
|
||||||
int elevation = y * width + x;
|
|
||||||
map->hoveredElevationTileChanged(elevation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
if (map) {
|
if (map) {
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
map->commit();
|
||||||
|
} else {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int x = (int)(pos.x()) / 16;
|
int x = (int)(pos.x()) / 16;
|
||||||
int y = (int)(pos.y()) / 16;
|
int y = (int)(pos.y()) / 16;
|
||||||
|
|
||||||
if (map->smart_paths_enabled && map->paint_tile_width == 3 && map->paint_tile_height == 3) {
|
// Paint onto the map.
|
||||||
|
if (map->smart_paths_enabled && map->selected_metatiles_width == 3 && map->selected_metatiles_height == 3) {
|
||||||
paintSmartPath(x, y);
|
paintSmartPath(x, y);
|
||||||
} else {
|
} else {
|
||||||
paintNormal(x, y);
|
paintNormal(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
|
||||||
map->commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1057,18 +1096,18 @@ void MapPixmapItem::paintNormal(int x, int y) {
|
||||||
// This allows painting via dragging the mouse to tile the painted region.
|
// This allows painting via dragging the mouse to tile the painted region.
|
||||||
int xDiff = x - map->paint_tile_initial_x;
|
int xDiff = x - map->paint_tile_initial_x;
|
||||||
int yDiff = y - map->paint_tile_initial_y;
|
int yDiff = y - map->paint_tile_initial_y;
|
||||||
if (xDiff < 0 && xDiff % map->paint_tile_width != 0) xDiff -= map->paint_tile_width;
|
if (xDiff < 0 && xDiff % map->selected_metatiles_width != 0) xDiff -= map->selected_metatiles_width;
|
||||||
if (yDiff < 0 && yDiff % map->paint_tile_height != 0) yDiff -= map->paint_tile_height;
|
if (yDiff < 0 && yDiff % map->selected_metatiles_height != 0) yDiff -= map->selected_metatiles_height;
|
||||||
|
|
||||||
x = map->paint_tile_initial_x + (xDiff / map->paint_tile_width) * map->paint_tile_width;
|
x = map->paint_tile_initial_x + (xDiff / map->selected_metatiles_width) * map->selected_metatiles_width;
|
||||||
y = map->paint_tile_initial_y + (yDiff / map->paint_tile_height) * map->paint_tile_height;
|
y = map->paint_tile_initial_y + (yDiff / map->selected_metatiles_height) * map->selected_metatiles_height;
|
||||||
for (int i = 0; i < map->paint_tile_width && i + x < map->getWidth(); i++)
|
for (int i = 0; i < map->selected_metatiles_width && i + x < map->getWidth(); i++)
|
||||||
for (int j = 0; j < map->paint_tile_height && j + y < map->getHeight(); j++) {
|
for (int j = 0; j < map->selected_metatiles_height && j + y < map->getHeight(); j++) {
|
||||||
int actualX = i + x;
|
int actualX = i + x;
|
||||||
int actualY = j + y;
|
int actualY = j + y;
|
||||||
Block *block = map->getBlock(actualX, actualY);
|
Block *block = map->getBlock(actualX, actualY);
|
||||||
if (block) {
|
if (block) {
|
||||||
block->tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8));
|
block->tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i);
|
||||||
map->_setBlock(actualX, actualY, *block);
|
map->_setBlock(actualX, actualY, *block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1078,34 +1117,32 @@ void MapPixmapItem::paintNormal(int x, int y) {
|
||||||
// Each entry is for one possibility from the marching squares value for a tile.
|
// Each entry is for one possibility from the marching squares value for a tile.
|
||||||
// (Marching Squares: https://en.wikipedia.org/wiki/Marching_squares)
|
// (Marching Squares: https://en.wikipedia.org/wiki/Marching_squares)
|
||||||
QList<int> MapPixmapItem::smartPathTable = QList<int>({
|
QList<int> MapPixmapItem::smartPathTable = QList<int>({
|
||||||
8 + 1, // 0000
|
4, // 0000
|
||||||
8 + 1, // 0001
|
4, // 0001
|
||||||
8 + 1, // 0010
|
4, // 0010
|
||||||
16 + 0, // 0011
|
6, // 0011
|
||||||
8 + 1, // 0100
|
4, // 0100
|
||||||
8 + 1, // 0101
|
4, // 0101
|
||||||
0 + 0, // 0110
|
0, // 0110
|
||||||
8 + 0, // 0111
|
3, // 0111
|
||||||
8 + 1, // 1000
|
4, // 1000
|
||||||
16 + 2, // 1001
|
8, // 1001
|
||||||
8 + 1, // 1010
|
4, // 1010
|
||||||
16 + 1, // 1011
|
7, // 1011
|
||||||
0 + 2, // 1100
|
2, // 1100
|
||||||
8 + 2, // 1101
|
5, // 1101
|
||||||
0 + 1, // 1110
|
1, // 1110
|
||||||
8 + 1, // 1111
|
4, // 1111
|
||||||
});
|
});
|
||||||
|
|
||||||
#define IS_SMART_PATH_TILE(block) ((map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 3) \
|
#define IS_SMART_PATH_TILE(block) (map->selected_metatiles->contains(block->tile))
|
||||||
|| (map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index + 8 && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 11) \
|
|
||||||
|| (map->getDisplayedBlockIndex(block->tile) >= map->paint_tile_index + 16 && map->getDisplayedBlockIndex(block->tile) < map->paint_tile_index + 19))
|
|
||||||
|
|
||||||
void MapPixmapItem::paintSmartPath(int x, int y) {
|
void MapPixmapItem::paintSmartPath(int x, int y) {
|
||||||
// Smart path should never be enabled without a 3x3 block selection.
|
// Smart path should never be enabled without a 3x3 block selection.
|
||||||
if (map->paint_tile_width != 3 || map->paint_tile_height != 3) return;
|
if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return;
|
||||||
|
|
||||||
// Shift to the middle tile of the smart path selection.
|
// Shift to the middle tile of the smart path selection.
|
||||||
int openTile = map->paint_tile_index + 8 + 1;
|
int openTile = map->selected_metatiles->at(4);
|
||||||
|
|
||||||
// Fill the region with the open tile.
|
// Fill the region with the open tile.
|
||||||
for (int i = -1; i <= 1; i++)
|
for (int i = -1; i <= 1; i++)
|
||||||
|
@ -1117,7 +1154,7 @@ void MapPixmapItem::paintSmartPath(int x, int y) {
|
||||||
int actualY = j + y;
|
int actualY = j + y;
|
||||||
Block *block = map->getBlock(actualX, actualY);
|
Block *block = map->getBlock(actualX, actualY);
|
||||||
if (block) {
|
if (block) {
|
||||||
block->tile = map->getSelectedBlockIndex(openTile);
|
block->tile = openTile;
|
||||||
map->_setBlock(actualX, actualY, *block);
|
map->_setBlock(actualX, actualY, *block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1157,28 +1194,79 @@ void MapPixmapItem::paintSmartPath(int x, int y) {
|
||||||
if (left && IS_SMART_PATH_TILE(left))
|
if (left && IS_SMART_PATH_TILE(left))
|
||||||
id += 8;
|
id += 8;
|
||||||
|
|
||||||
block->tile = map->getSelectedBlockIndex(map->paint_tile_index + smartPathTable[id]);
|
block->tile = map->selected_metatiles->at(smartPathTable[id]);
|
||||||
map->_setBlock(actualX, actualY, *block);
|
map->_setBlock(actualX, actualY, *block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
||||||
|
QPointF pos = event->pos();
|
||||||
|
int x = (int)(pos.x()) / 16;
|
||||||
|
int y = (int)(pos.y()) / 16;
|
||||||
|
|
||||||
|
// Snap point to within map bounds.
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (x >= map->getWidth()) x = map->getWidth() - 1;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
if (y >= map->getHeight()) y = map->getHeight() - 1;
|
||||||
|
|
||||||
|
// Update/apply copied metatiles.
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||||
|
selection_origin = QPoint(x, y);
|
||||||
|
selection.clear();
|
||||||
|
selection.append(QPoint(x, y));
|
||||||
|
editor->copiedMetatileSelectionWidth = 1;
|
||||||
|
editor->copiedMetatileSelectionHeight = 1;
|
||||||
|
} else if (event->type() == QEvent::GraphicsSceneMouseMove) {
|
||||||
|
QPoint pos = QPoint(x, y);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
editor->copiedMetatileSelectionWidth = x2 - x1 + 1;
|
||||||
|
editor->copiedMetatileSelectionHeight = y2 - y1 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor->copiedMetatileSelection->clear();
|
||||||
|
for (QPoint point : selection) {
|
||||||
|
editor->copiedMetatileSelection->append(map->getBlock(point.x(), point.y())->tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
editor->lastSelectedMetatilesFromMap = true;
|
||||||
|
map->selected_metatiles_width = editor->copiedMetatileSelectionWidth;
|
||||||
|
map->selected_metatiles_height = editor->copiedMetatileSelectionHeight;
|
||||||
|
*map->selected_metatiles = *editor->copiedMetatileSelection;
|
||||||
|
|
||||||
|
editor->redrawCurrentMetatilesSelection();
|
||||||
|
}
|
||||||
|
|
||||||
void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||||
if (map) {
|
if (map) {
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
map->commit();
|
||||||
|
} else {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int x = (int)(pos.x()) / 16;
|
int x = (int)(pos.x()) / 16;
|
||||||
int y = (int)(pos.y()) / 16;
|
int y = (int)(pos.y()) / 16;
|
||||||
Block *block = map->getBlock(x, y);
|
Block *block = map->getBlock(x, y);
|
||||||
int tile = map->getSelectedBlockIndex(map->paint_tile_index);
|
int tile = map->selected_metatiles->first();
|
||||||
if (block && block->tile != tile) {
|
if (block && block->tile != tile) {
|
||||||
if (map->smart_paths_enabled && map->paint_tile_width == 3 && map->paint_tile_height == 3)
|
if (map->smart_paths_enabled && map->selected_metatiles_width == 3 && map->selected_metatiles_height == 3)
|
||||||
this->_floodFillSmartPath(x, y);
|
this->_floodFillSmartPath(x, y);
|
||||||
else
|
else
|
||||||
this->_floodFill(x, y);
|
this->_floodFill(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
|
||||||
map->commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1198,11 +1286,11 @@ void MapPixmapItem::_floodFill(int initialX, int initialY) {
|
||||||
|
|
||||||
int xDiff = x - initialX;
|
int xDiff = x - initialX;
|
||||||
int yDiff = y - initialY;
|
int yDiff = y - initialY;
|
||||||
int i = xDiff % map->paint_tile_width;
|
int i = xDiff % map->selected_metatiles_width;
|
||||||
int j = yDiff % map->paint_tile_height;
|
int j = yDiff % map->selected_metatiles_height;
|
||||||
if (i < 0) i = map->paint_tile_width + i;
|
if (i < 0) i = map->selected_metatiles_width + i;
|
||||||
if (j < 0) j = map->paint_tile_height + j;
|
if (j < 0) j = map->selected_metatiles_height + j;
|
||||||
int tile = map->getSelectedBlockIndex(map->paint_tile_index + i + (j * 8));
|
int tile = map->selected_metatiles->at(j * map->selected_metatiles_width + i);
|
||||||
uint old_tile = block->tile;
|
uint old_tile = block->tile;
|
||||||
if (old_tile == tile) {
|
if (old_tile == tile) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1227,10 +1315,10 @@ void MapPixmapItem::_floodFill(int initialX, int initialY) {
|
||||||
|
|
||||||
void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
|
void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
|
||||||
// Smart path should never be enabled without a 3x3 block selection.
|
// Smart path should never be enabled without a 3x3 block selection.
|
||||||
if (map->paint_tile_width != 3 || map->paint_tile_height != 3) return;
|
if (map->selected_metatiles_width != 3 || map->selected_metatiles_height != 3) return;
|
||||||
|
|
||||||
// Shift to the middle tile of the smart path selection.
|
// Shift to the middle tile of the smart path selection.
|
||||||
int openTile = map->paint_tile_index + 8 + 1;
|
int openTile = map->selected_metatiles->at(4);
|
||||||
|
|
||||||
// Flood fill the region with the open tile.
|
// Flood fill the region with the open tile.
|
||||||
QList<QPoint> todo;
|
QList<QPoint> todo;
|
||||||
|
@ -1245,13 +1333,12 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tile = map->getSelectedBlockIndex(openTile);
|
|
||||||
uint old_tile = block->tile;
|
uint old_tile = block->tile;
|
||||||
if (old_tile == tile) {
|
if (old_tile == openTile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
block->tile = tile;
|
block->tile = openTile;
|
||||||
map->_setBlock(x, y, *block);
|
map->_setBlock(x, y, *block);
|
||||||
if ((block = map->getBlock(x + 1, y)) && block->tile == old_tile) {
|
if ((block = map->getBlock(x + 1, y)) && block->tile == old_tile) {
|
||||||
todo.append(QPoint(x + 1, y));
|
todo.append(QPoint(x + 1, y));
|
||||||
|
@ -1301,7 +1388,7 @@ void MapPixmapItem::_floodFillSmartPath(int initialX, int initialY) {
|
||||||
if (left && IS_SMART_PATH_TILE(left))
|
if (left && IS_SMART_PATH_TILE(left))
|
||||||
id += 8;
|
id += 8;
|
||||||
|
|
||||||
block->tile = map->getSelectedBlockIndex(map->paint_tile_index + smartPathTable[id]);
|
block->tile = map->selected_metatiles->at(smartPathTable[id]);
|
||||||
map->_setBlock(x, y, *block);
|
map->_setBlock(x, y, *block);
|
||||||
|
|
||||||
// Visit neighbors if they are smart-path tiles, and don't revisit any.
|
// Visit neighbors if they are smart-path tiles, and don't revisit any.
|
||||||
|
@ -1333,12 +1420,12 @@ void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||||
map->paint_tile_index = map->getDisplayedBlockIndex(block->tile);
|
map->paint_tile_index = map->getDisplayedBlockIndex(block->tile);
|
||||||
map->paint_tile_width = 1;
|
map->paint_tile_width = 1;
|
||||||
map->paint_tile_height = 1;
|
map->paint_tile_height = 1;
|
||||||
|
map->setSelectedMetatilesFromTilePicker();
|
||||||
|
|
||||||
emit map->paintTileChanged(map);
|
emit map->paintTileChanged(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
|
||||||
|
|
||||||
void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::select(QGraphicsSceneMouseEvent *event) {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int x = (int)(pos.x()) / 16;
|
int x = (int)(pos.x()) / 16;
|
||||||
|
@ -1384,8 +1471,14 @@ void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
|
||||||
if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
|
if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
|
||||||
map->clearHoveredTile();
|
map->clearHoveredTile();
|
||||||
} else {
|
} else {
|
||||||
|
if (editor->current_view == editor->map_item) {
|
||||||
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
|
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
|
||||||
map->hoveredTileChanged(x, y, tile);
|
map->hoveredTileChanged(x, y, tile);
|
||||||
|
} else if (editor->current_view == editor->collision_item) {
|
||||||
|
int collision = map->layout->blockdata->blocks->at(blockIndex).collision;
|
||||||
|
int elevation = map->layout->blockdata->blocks->at(blockIndex).elevation;
|
||||||
|
map->hoveredMovementPermissionTileChanged(collision, elevation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1479,6 +1572,24 @@ void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event) {
|
||||||
|
QPointF pos = event->pos();
|
||||||
|
int x = (int)(pos.x()) / 16;
|
||||||
|
int y = (int)(pos.y()) / 16;
|
||||||
|
|
||||||
|
// Snap point to within map bounds.
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (x >= map->getWidth()) x = map->getWidth() - 1;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
if (y >= map->getHeight()) y = map->getHeight() - 1;
|
||||||
|
|
||||||
|
int collision = map->getBlock(x, y)->collision;
|
||||||
|
int elevation = map->getBlock(x, y)->elevation;
|
||||||
|
map->paint_collision = collision;
|
||||||
|
map->paint_elevation = elevation;
|
||||||
|
editor->collision_metatiles_item->draw();
|
||||||
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
active = true;
|
active = true;
|
||||||
last_x = (mouse->pos().x() + this->pos().x()) / 16;
|
last_x = (mouse->pos().x() + this->pos().x()) / 16;
|
||||||
|
|
85
editor.h
85
editor.h
|
@ -17,8 +17,10 @@ class CollisionPixmapItem;
|
||||||
class ConnectionPixmapItem;
|
class ConnectionPixmapItem;
|
||||||
class MetatilesPixmapItem;
|
class MetatilesPixmapItem;
|
||||||
class BorderMetatilesPixmapItem;
|
class BorderMetatilesPixmapItem;
|
||||||
class CollisionMetatilesPixmapItem;
|
class CurrentSelectedMetatilesPixmapItem;
|
||||||
class ElevationMetatilesPixmapItem;
|
class MovementPermissionsPixmapItem;
|
||||||
|
|
||||||
|
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
||||||
|
|
||||||
class Editor : public QObject
|
class Editor : public QObject
|
||||||
{
|
{
|
||||||
|
@ -35,9 +37,12 @@ public:
|
||||||
void undo();
|
void undo();
|
||||||
void redo();
|
void redo();
|
||||||
void setMap(QString map_name);
|
void setMap(QString map_name);
|
||||||
|
void updateCurrentMetatilesSelection();
|
||||||
void displayMap();
|
void displayMap();
|
||||||
void displayMetatiles();
|
void displayMetatiles();
|
||||||
void displayBorderMetatiles();
|
void displayBorderMetatiles();
|
||||||
|
void displayCurrentMetatilesSelection();
|
||||||
|
void redrawCurrentMetatilesSelection();
|
||||||
void displayCollisionMetatiles();
|
void displayCollisionMetatiles();
|
||||||
void displayElevationMetatiles();
|
void displayElevationMetatiles();
|
||||||
void displayMapEvents();
|
void displayMapEvents();
|
||||||
|
@ -84,17 +89,24 @@ public:
|
||||||
QList<QGraphicsLineItem*> gridLines;
|
QList<QGraphicsLineItem*> gridLines;
|
||||||
|
|
||||||
QGraphicsScene *scene_metatiles = NULL;
|
QGraphicsScene *scene_metatiles = NULL;
|
||||||
|
QGraphicsScene *scene_current_metatile_selection = NULL;
|
||||||
QGraphicsScene *scene_selected_border_metatiles = NULL;
|
QGraphicsScene *scene_selected_border_metatiles = NULL;
|
||||||
QGraphicsScene *scene_collision_metatiles = NULL;
|
QGraphicsScene *scene_collision_metatiles = NULL;
|
||||||
QGraphicsScene *scene_elevation_metatiles = NULL;
|
QGraphicsScene *scene_elevation_metatiles = NULL;
|
||||||
MetatilesPixmapItem *metatiles_item = NULL;
|
MetatilesPixmapItem *metatiles_item = NULL;
|
||||||
|
|
||||||
BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL;
|
BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL;
|
||||||
CollisionMetatilesPixmapItem *collision_metatiles_item = NULL;
|
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = NULL;
|
||||||
ElevationMetatilesPixmapItem *elevation_metatiles_item = NULL;
|
MovementPermissionsPixmapItem *collision_metatiles_item = NULL;
|
||||||
|
|
||||||
QList<DraggablePixmapItem*> *events = NULL;
|
QList<DraggablePixmapItem*> *events = NULL;
|
||||||
QList<DraggablePixmapItem*> *selected_events = NULL;
|
QList<DraggablePixmapItem*> *selected_events = NULL;
|
||||||
|
|
||||||
|
bool lastSelectedMetatilesFromMap = false;
|
||||||
|
int copiedMetatileSelectionWidth = 0;
|
||||||
|
int copiedMetatileSelectionHeight = 0;
|
||||||
|
QList<int> *copiedMetatileSelection = new QList<int>;
|
||||||
|
|
||||||
QString map_edit_mode;
|
QString map_edit_mode;
|
||||||
|
|
||||||
void objectsView_onMousePress(QMouseEvent *event);
|
void objectsView_onMousePress(QMouseEvent *event);
|
||||||
|
@ -139,6 +151,7 @@ signals:
|
||||||
void loadMapRequested(QString, QString);
|
void loadMapRequested(QString, QString);
|
||||||
void tilesetChanged(QString);
|
void tilesetChanged(QString);
|
||||||
void warpEventDoubleClicked(QString mapName, QString warpNum);
|
void warpEventDoubleClicked(QString mapName, QString warpNum);
|
||||||
|
void currentMetatilesSelectionChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -241,8 +254,10 @@ public:
|
||||||
MapPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
MapPixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {
|
||||||
}
|
}
|
||||||
Map *map = NULL;
|
Map *map = NULL;
|
||||||
MapPixmapItem(Map *map_) {
|
Editor *editor = NULL;
|
||||||
|
MapPixmapItem(Map *map_, Editor *editor_) {
|
||||||
map = map_;
|
map = map_;
|
||||||
|
editor = editor_;
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
bool active;
|
bool active;
|
||||||
|
@ -256,6 +271,7 @@ public:
|
||||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||||
virtual void select(QGraphicsSceneMouseEvent*);
|
virtual void select(QGraphicsSceneMouseEvent*);
|
||||||
virtual void draw(bool ignoreCache = false);
|
virtual void draw(bool ignoreCache = false);
|
||||||
|
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCurHoveredTile(QPointF pos);
|
void updateCurHoveredTile(QPointF pos);
|
||||||
|
@ -279,8 +295,9 @@ class CollisionPixmapItem : public MapPixmapItem {
|
||||||
public:
|
public:
|
||||||
CollisionPixmapItem(QPixmap pixmap): MapPixmapItem(pixmap) {
|
CollisionPixmapItem(QPixmap pixmap): MapPixmapItem(pixmap) {
|
||||||
}
|
}
|
||||||
CollisionPixmapItem(Map *map_): MapPixmapItem(map_) {
|
CollisionPixmapItem(Map *map_, Editor *editor_): MapPixmapItem(map_, editor_) {
|
||||||
}
|
}
|
||||||
|
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||||
|
@ -349,7 +366,7 @@ public:
|
||||||
Map* map = NULL;
|
Map* map = NULL;
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
private:
|
private:
|
||||||
void updateSelection(QPointF pos, Qt::MouseButton button);
|
void updateSelection(QPointF pos);
|
||||||
protected:
|
protected:
|
||||||
virtual void updateCurHoveredMetatile(QPointF pos);
|
virtual void updateCurHoveredMetatile(QPointF pos);
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -377,34 +394,34 @@ protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CurrentSelectedMetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CurrentSelectedMetatilesPixmapItem(Map *map_) {
|
||||||
|
map = map_;
|
||||||
|
}
|
||||||
|
Map* map = NULL;
|
||||||
|
virtual void draw();
|
||||||
|
};
|
||||||
|
|
||||||
class MovementPermissionsPixmapItem : public MetatilesPixmapItem {
|
class MovementPermissionsPixmapItem : public MetatilesPixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) {}
|
MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
|
||||||
virtual void pick(uint collision) {
|
|
||||||
map->paint_collision = collision;
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
};
|
|
||||||
|
|
||||||
class CollisionMetatilesPixmapItem : public MovementPermissionsPixmapItem {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
CollisionMetatilesPixmapItem(Map *map_): MovementPermissionsPixmapItem(map_) {
|
|
||||||
connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
|
connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
|
||||||
}
|
}
|
||||||
virtual void pick(uint collision) {
|
virtual void pick(uint collision, uint elevation) {
|
||||||
map->paint_collision = collision;
|
map->paint_collision = collision;
|
||||||
|
map->paint_elevation = elevation;
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
virtual void draw() {
|
virtual void draw() {
|
||||||
setPixmap(map->renderCollisionMetatiles());
|
setPixmap(map->renderCollisionMetatiles());
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
virtual void updateCurHoveredMetatile(QPointF pos);
|
virtual void updateCurHoveredMetatile(QPointF pos);
|
||||||
private slots:
|
private slots:
|
||||||
void paintCollisionChanged(Map *map) {
|
void paintCollisionChanged(Map *map) {
|
||||||
|
@ -412,26 +429,4 @@ private slots:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ElevationMetatilesPixmapItem : public MovementPermissionsPixmapItem {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ElevationMetatilesPixmapItem(Map *map_): MovementPermissionsPixmapItem(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());
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
virtual void updateCurHoveredMetatile(QPointF pos);
|
|
||||||
private slots:
|
|
||||||
void paintCollisionChanged(Map *map) {
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // EDITOR_H
|
#endif // EDITOR_H
|
||||||
|
|
|
@ -38,6 +38,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
|
connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
|
||||||
connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
|
connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
|
||||||
connect(editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
|
connect(editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
|
||||||
|
connect(editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
|
||||||
|
|
||||||
on_toolButton_Paint_clicked();
|
on_toolButton_Paint_clicked();
|
||||||
|
|
||||||
|
@ -188,13 +189,12 @@ void MainWindow::redrawMapScene()
|
||||||
ui->graphicsView_BorderMetatile->setScene(editor->scene_selected_border_metatiles);
|
ui->graphicsView_BorderMetatile->setScene(editor->scene_selected_border_metatiles);
|
||||||
ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width() + 2, editor->selected_border_metatiles_item->pixmap().height() + 2);
|
ui->graphicsView_BorderMetatile->setFixedSize(editor->selected_border_metatiles_item->pixmap().width() + 2, editor->selected_border_metatiles_item->pixmap().height() + 2);
|
||||||
|
|
||||||
|
ui->graphicsView_currentMetatileSelection->setScene(editor->scene_current_metatile_selection);
|
||||||
|
ui->graphicsView_currentMetatileSelection->setFixedSize(editor->scene_current_metatile_selection_item->pixmap().width() + 2, editor->scene_current_metatile_selection_item->pixmap().height() + 2);
|
||||||
|
|
||||||
ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles);
|
ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles);
|
||||||
//ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect());
|
//ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect());
|
||||||
ui->graphicsView_Collision->setFixedSize(editor->collision_metatiles_item->pixmap().width() + 2, editor->collision_metatiles_item->pixmap().height() + 2);
|
ui->graphicsView_Collision->setFixedSize(editor->collision_metatiles_item->pixmap().width() + 2, editor->collision_metatiles_item->pixmap().height() + 2);
|
||||||
|
|
||||||
ui->graphicsView_Elevation->setScene(editor->scene_elevation_metatiles);
|
|
||||||
//ui->graphicsView_Elevation->setSceneRect(editor->scene_elevation_metatiles->sceneRect());
|
|
||||||
ui->graphicsView_Elevation->setFixedSize(editor->elevation_metatiles_item->pixmap().width() + 2, editor->elevation_metatiles_item->pixmap().height() + 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openWarpMap(QString map_name, QString warp_num) {
|
void MainWindow::openWarpMap(QString map_name, QString warp_num) {
|
||||||
|
@ -485,6 +485,12 @@ void MainWindow::onTilesetChanged(QString mapName)
|
||||||
setMap(mapName);
|
setMap(mapName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::currentMetatilesSelectionChanged()
|
||||||
|
{
|
||||||
|
ui->graphicsView_currentMetatileSelection->setFixedSize(editor->scene_current_metatile_selection_item->pixmap().width() + 2, editor->scene_current_metatile_selection_item->pixmap().height() + 2);
|
||||||
|
ui->graphicsView_currentMetatileSelection->setSceneRect(0, 0, editor->scene_current_metatile_selection_item->pixmap().width(), editor->scene_current_metatile_selection_item->pixmap().height());
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
QVariant data = index.data(Qt::UserRole);
|
QVariant data = index.data(Qt::UserRole);
|
||||||
|
|
|
@ -74,6 +74,7 @@ private slots:
|
||||||
void onOpenMapListContextMenu(const QPoint &point);
|
void onOpenMapListContextMenu(const QPoint &point);
|
||||||
void onAddNewMapToGroupClick(QAction* triggeredAction);
|
void onAddNewMapToGroupClick(QAction* triggeredAction);
|
||||||
void onTilesetChanged(QString);
|
void onTilesetChanged(QString);
|
||||||
|
void currentMetatilesSelectionChanged();
|
||||||
|
|
||||||
void on_action_Export_Map_Image_triggered();
|
void on_action_Export_Map_Image_triggered();
|
||||||
|
|
||||||
|
|
294
mainwindow.ui
294
mainwindow.ui
|
@ -171,7 +171,7 @@
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p>Pencil</p><p>Click and drag to draw on the map.</p></body></html></string>
|
<string><html><head/><body><p>Editor</p><p><span style=" font-weight:600;">Click</span> and drag to draw on the map.</p><p><span style=" font-weight:600;">Right-click</span> and drag to select tiles.</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Paint</string>
|
<string>Paint</string>
|
||||||
|
@ -334,7 +334,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>436</width>
|
<width>429</width>
|
||||||
<height>620</height>
|
<height>620</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -476,7 +476,7 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Blocks</string>
|
<string>Metatiles</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
|
@ -647,6 +647,143 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
|
<widget class="QFrame" name="frame_currentMetatileSelection">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>92</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>92</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_10">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Selection</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QScrollArea" name="scrollArea_6">
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaWidgetContents_6">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>315</width>
|
||||||
|
<height>86</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_16">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGraphicsView" name="graphicsView_currentMetatileSelection">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="verticalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="interactive">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_17">
|
||||||
|
<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>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
<widget class="QScrollArea" name="scrollArea_2">
|
<widget class="QScrollArea" name="scrollArea_2">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
@ -677,8 +814,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>358</width>
|
<width>365</width>
|
||||||
<height>497</height>
|
<height>405</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -775,7 +912,7 @@
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@ -783,97 +920,78 @@
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Collision</string>
|
<string>Collision</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<widget class="Line" name="line">
|
<layout class="QGridLayout" name="gridLayout_CollisionSelection">
|
||||||
<property name="geometry">
|
<property name="sizeConstraint">
|
||||||
<rect>
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
<x>20</x>
|
|
||||||
<y>60</y>
|
|
||||||
<width>111</width>
|
|
||||||
<height>20</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QGraphicsView" name="graphicsView_Collision">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>64</width>
|
||||||
|
<height>512</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<spacer name="horizontalSpacer_18">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="sizeHint" stdset="0">
|
||||||
<widget class="QFrame" name="frame">
|
<size>
|
||||||
<property name="geometry">
|
<width>40</width>
|
||||||
<rect>
|
<height>20</height>
|
||||||
<x>0</x>
|
</size>
|
||||||
<y>80</y>
|
|
||||||
<width>151</width>
|
|
||||||
<height>101</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
</spacer>
|
||||||
<enum>QFrame::StyledPanel</enum>
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<spacer name="horizontalSpacer_19">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShadow">
|
<property name="sizeHint" stdset="0">
|
||||||
<enum>QFrame::Raised</enum>
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QLabel" name="label_2">
|
</spacer>
|
||||||
<property name="geometry">
|
</item>
|
||||||
<rect>
|
<item row="1" column="1">
|
||||||
<x>10</x>
|
<spacer name="verticalSpacer_6">
|
||||||
<y>10</y>
|
<property name="orientation">
|
||||||
<width>47</width>
|
<enum>Qt::Vertical</enum>
|
||||||
<height>13</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="sizeHint" stdset="0">
|
||||||
<string>Elevation</string>
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</spacer>
|
||||||
<widget class="QGraphicsView" name="graphicsView_Elevation">
|
</item>
|
||||||
<property name="geometry">
|
</layout>
|
||||||
<rect>
|
|
||||||
<x>10</x>
|
|
||||||
<y>30</y>
|
|
||||||
<width>131</width>
|
|
||||||
<height>61</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
<widget class="QFrame" name="frame_2">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>151</width>
|
|
||||||
<height>61</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::StyledPanel</enum>
|
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Raised</enum>
|
|
||||||
</property>
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>10</x>
|
|
||||||
<y>10</y>
|
|
||||||
<width>47</width>
|
|
||||||
<height>13</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Collision</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QGraphicsView" name="graphicsView_Collision">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>40</x>
|
|
||||||
<y>30</y>
|
|
||||||
<width>66</width>
|
|
||||||
<height>18</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
163
map.cpp
163
map.cpp
|
@ -12,6 +12,10 @@ Map::Map(QObject *parent) : QObject(parent)
|
||||||
paint_tile_index = 1;
|
paint_tile_index = 1;
|
||||||
paint_collision = 0;
|
paint_collision = 0;
|
||||||
paint_elevation = 3;
|
paint_elevation = 3;
|
||||||
|
selected_metatiles_width = 1;
|
||||||
|
selected_metatiles_height = 1;
|
||||||
|
selected_metatiles = new QList<int>;
|
||||||
|
selected_metatiles->append(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::setName(QString mapName) {
|
void Map::setName(QString mapName) {
|
||||||
|
@ -77,46 +81,14 @@ int Map::getDisplayedBlockIndex(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage Map::getCollisionMetatileImage(Block block) {
|
QImage Map::getCollisionMetatileImage(Block block) {
|
||||||
return getCollisionMetatileImage(block.collision);
|
return getCollisionMetatileImage(block.collision, block.elevation);
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage Map::getCollisionMetatileImage(int collision) {
|
QImage Map::getCollisionMetatileImage(int collision, int elevation) {
|
||||||
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
int x = collision * 16;
|
||||||
QColor color;
|
int y = elevation * 16;
|
||||||
if (collision == 0) {
|
QPixmap collisionImage = QPixmap(":/images/collisions.png").copy(x, y, 16, 16);
|
||||||
color.setGreen(0xff);
|
return collisionImage.toImage();
|
||||||
} else if (collision == 1) {
|
|
||||||
color.setRed(0xff);
|
|
||||||
} else if (collision == 2) {
|
|
||||||
color.setBlue(0xff);
|
|
||||||
} else if (collision == 3) {
|
|
||||||
// black
|
|
||||||
}
|
|
||||||
metatile_image.fill(color);
|
|
||||||
return metatile_image;
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage Map::getElevationMetatileImage(Block block) {
|
|
||||||
return getElevationMetatileImage(block.elevation);
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage Map::getElevationMetatileImage(int elevation) {
|
|
||||||
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
|
||||||
QColor color;
|
|
||||||
if (elevation < 15) {
|
|
||||||
uint saturation = (elevation + 1) * 16 + 15;
|
|
||||||
color.setGreen(saturation);
|
|
||||||
color.setRed(saturation);
|
|
||||||
color.setBlue(saturation);
|
|
||||||
} else {
|
|
||||||
color.setGreen(0xd0);
|
|
||||||
color.setBlue(0xd0);
|
|
||||||
color.setRed(0);
|
|
||||||
}
|
|
||||||
metatile_image.fill(color);
|
|
||||||
//QPainter painter(&metatile_image);
|
|
||||||
//painter.end();
|
|
||||||
return metatile_image;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::blockChanged(int i, Blockdata *cache) {
|
bool Map::blockChanged(int i, Blockdata *cache) {
|
||||||
|
@ -199,40 +171,15 @@ QPixmap Map::renderCollision(bool ignoreCache) {
|
||||||
Block block = layout->blockdata->blocks->value(i);
|
Block block = layout->blockdata->blocks->value(i);
|
||||||
QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
||||||
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
||||||
QImage elevation_metatile_image = getElevationMetatileImage(block);
|
|
||||||
int map_y = width_ ? i / width_ : 0;
|
int map_y = width_ ? i / width_ : 0;
|
||||||
int map_x = width_ ? i % width_ : 0;
|
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);
|
||||||
|
|
||||||
painter.save();
|
painter.save();
|
||||||
if (block.elevation == 15) {
|
painter.setOpacity(0.55);
|
||||||
painter.setOpacity(0.5);
|
|
||||||
} else if (block.elevation == 0) {
|
|
||||||
painter.setOpacity(0);
|
|
||||||
} else {
|
|
||||||
painter.setOpacity(1);//(block.elevation / 16.0) * 0.8);
|
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Overlay);
|
|
||||||
}
|
|
||||||
painter.drawImage(metatile_origin, elevation_metatile_image);
|
|
||||||
painter.restore();
|
|
||||||
|
|
||||||
painter.save();
|
|
||||||
if (block.collision == 0) {
|
|
||||||
painter.setOpacity(0.1);
|
|
||||||
} else {
|
|
||||||
painter.setOpacity(0.4);
|
|
||||||
}
|
|
||||||
painter.drawImage(metatile_origin, collision_metatile_image);
|
painter.drawImage(metatile_origin, collision_metatile_image);
|
||||||
painter.restore();
|
painter.restore();
|
||||||
|
|
||||||
painter.save();
|
|
||||||
painter.setOpacity(0.6);
|
|
||||||
painter.setPen(QColor(255, 255, 255, 192));
|
|
||||||
painter.setFont(QFont("Helvetica", 8));
|
|
||||||
painter.drawText(QPoint(metatile_origin.x(), metatile_origin.y() + 8), QString("%1").arg(block.elevation));
|
|
||||||
painter.restore();
|
|
||||||
}
|
}
|
||||||
painter.end();
|
painter.end();
|
||||||
cacheCollision();
|
cacheCollision();
|
||||||
|
@ -349,54 +296,35 @@ QPixmap Map::renderConnection(Connection connection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderCollisionMetatiles() {
|
QPixmap Map::renderCollisionMetatiles() {
|
||||||
int length_ = 4;
|
int width_ = 2;
|
||||||
int height_ = 1;
|
int height_ = 16;
|
||||||
int width_ = length_ / height_;
|
QImage image(width_ * 32, height_ * 32, 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 < width_; i++) {
|
||||||
int y = i / width_;
|
for (int j = 0; j < height_; j++) {
|
||||||
int x = i % width_;
|
QPoint origin(i * 32, j * 32);
|
||||||
QPoint origin(x * 16, y * 16);
|
QImage metatile_image = getCollisionMetatileImage(i, j).scaled(32, 32);
|
||||||
QImage metatile_image = getCollisionMetatileImage(i);
|
|
||||||
painter.drawImage(origin, metatile_image);
|
painter.drawImage(origin, metatile_image);
|
||||||
}
|
}
|
||||||
drawSelection(paint_collision, width_, 1, 1, &painter);
|
}
|
||||||
|
drawSelection(paint_collision + paint_elevation * width_, width_, 1, 1, &painter, 32);
|
||||||
painter.end();
|
painter.end();
|
||||||
return QPixmap::fromImage(image);
|
return QPixmap::fromImage(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderElevationMetatiles() {
|
void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth) {
|
||||||
int length_ = 16;
|
|
||||||
int height_ = 2;
|
|
||||||
int width_ = length_ / height_;
|
|
||||||
QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
|
||||||
QPainter painter(&image);
|
|
||||||
for (int i = 0; i < length_; i++) {
|
|
||||||
int y = i / width_;
|
|
||||||
int x = i % width_;
|
|
||||||
QPoint origin(x * 16, y * 16);
|
|
||||||
QImage metatile_image = getElevationMetatileImage(i);
|
|
||||||
painter.drawImage(origin, metatile_image);
|
|
||||||
}
|
|
||||||
drawSelection(paint_elevation, width_, 1, 1, &painter);
|
|
||||||
painter.end();
|
|
||||||
return QPixmap::fromImage(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter) {
|
|
||||||
int x = i % w;
|
int x = i % w;
|
||||||
int y = i / w;
|
int y = i / w;
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QColor penColor = QColor(0xff, 0xff, 0xff);
|
QColor penColor = QColor(0xff, 0xff, 0xff);
|
||||||
painter->setPen(penColor);
|
painter->setPen(penColor);
|
||||||
int rectWidth = selectionWidth * 16;
|
int rectWidth = selectionWidth * gridWidth;
|
||||||
int rectHeight = selectionHeight * 16;
|
int rectHeight = selectionHeight * gridWidth;
|
||||||
painter->drawRect(x * 16, y * 16, rectWidth - 1, rectHeight -1);
|
painter->drawRect(x * gridWidth, y * gridWidth, rectWidth - 1, rectHeight -1);
|
||||||
painter->setPen(QColor(0, 0, 0));
|
painter->setPen(QColor(0, 0, 0));
|
||||||
painter->drawRect(x * 16 - 1, y * 16 - 1, rectWidth + 1, rectHeight + 1);
|
painter->drawRect(x * gridWidth - 1, y * gridWidth - 1, rectWidth + 1, rectHeight + 1);
|
||||||
painter->drawRect(x * 16 + 1, y * 16 + 1, rectWidth - 3, rectHeight - 3);
|
painter->drawRect(x * gridWidth + 1, y * gridWidth + 1, rectWidth - 3, rectHeight - 3);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +351,7 @@ QPixmap Map::renderMetatiles() {
|
||||||
painter.drawImage(metatile_origin, metatile_image);
|
painter.drawImage(metatile_origin, metatile_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawSelection(paint_tile_index, width_, paint_tile_width, paint_tile_height, &painter);
|
drawSelection(paint_tile_index, width_, paint_tile_width, paint_tile_height, &painter, 16);
|
||||||
|
|
||||||
painter.end();
|
painter.end();
|
||||||
return QPixmap::fromImage(image);
|
return QPixmap::fromImage(image);
|
||||||
|
@ -680,7 +608,7 @@ bool Map::hasUnsavedChanges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::hoveredTileChanged(int x, int y, int block) {
|
void Map::hoveredTileChanged(int x, int y, int block) {
|
||||||
emit statusBarMessage(QString("X: %1, Y: %2, Block: 0x%3")
|
emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3")
|
||||||
.arg(x)
|
.arg(x)
|
||||||
.arg(y)
|
.arg(y)
|
||||||
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
|
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
|
||||||
|
@ -692,7 +620,7 @@ void Map::clearHoveredTile() {
|
||||||
|
|
||||||
void Map::hoveredMetatileChanged(int blockIndex) {
|
void Map::hoveredMetatileChanged(int blockIndex) {
|
||||||
int tile = getSelectedBlockIndex(blockIndex);
|
int tile = getSelectedBlockIndex(blockIndex);
|
||||||
emit statusBarMessage(QString("Block: 0x%1")
|
emit statusBarMessage(QString("Metatile: 0x%1")
|
||||||
.arg(QString("%1").arg(tile, 3, 16, QChar('0')).toUpper()));
|
.arg(QString("%1").arg(tile, 3, 16, QChar('0')).toUpper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,18 +628,35 @@ void Map::clearHoveredMetatile() {
|
||||||
emit statusBarMessage(QString(""));
|
emit statusBarMessage(QString(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::hoveredCollisionTileChanged(int collision) {
|
void Map::hoveredMovementPermissionTileChanged(int collision, int elevation) {
|
||||||
emit statusBarMessage(QString("Collision: %1").arg(collision));
|
QString message;
|
||||||
|
if (collision == 0 && elevation == 0) {
|
||||||
|
message = "Collision: Transition between elevations";
|
||||||
|
} else if (collision == 0 && elevation == 15) {
|
||||||
|
message = "Collision: Multi-Level (Bridge)";
|
||||||
|
} else if (collision == 0 && elevation == 1) {
|
||||||
|
message = "Collision: Surf";
|
||||||
|
} else if (collision == 0) {
|
||||||
|
message = QString("Collision: Passable, Elevation: %1").arg(elevation);
|
||||||
|
} else {
|
||||||
|
message = QString("Collision: Impassable, Elevation: %1").arg(elevation);
|
||||||
|
}
|
||||||
|
emit statusBarMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::clearHoveredCollisionTile() {
|
void Map::clearHoveredMovementPermissionTile() {
|
||||||
emit statusBarMessage(QString(""));
|
emit statusBarMessage(QString(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::hoveredElevationTileChanged(int elevation) {
|
void Map::setSelectedMetatilesFromTilePicker() {
|
||||||
emit statusBarMessage(QString("Elevation: %1").arg(elevation));
|
this->selected_metatiles_width = this->paint_tile_width;
|
||||||
|
this->selected_metatiles_height = this->paint_tile_height;
|
||||||
|
this->selected_metatiles->clear();
|
||||||
|
for (int j = 0; j < this->paint_tile_height; j++) {
|
||||||
|
for (int i = 0; i < this->paint_tile_width; i++) {
|
||||||
|
int metatile = this->getSelectedBlockIndex(this->paint_tile_index + i + (j * 8));
|
||||||
|
this->selected_metatiles->append(metatile);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::clearHoveredElevationTile() {
|
|
||||||
emit statusBarMessage(QString(""));
|
|
||||||
}
|
|
||||||
|
|
19
map.h
19
map.h
|
@ -155,13 +155,10 @@ public:
|
||||||
QImage collision_image;
|
QImage collision_image;
|
||||||
QPixmap collision_pixmap;
|
QPixmap collision_pixmap;
|
||||||
QImage getCollisionMetatileImage(Block);
|
QImage getCollisionMetatileImage(Block);
|
||||||
QImage getElevationMetatileImage(Block);
|
QImage getCollisionMetatileImage(int, int);
|
||||||
QImage getCollisionMetatileImage(int);
|
|
||||||
QImage getElevationMetatileImage(int);
|
|
||||||
|
|
||||||
QPixmap renderCollisionMetatiles();
|
QPixmap renderCollisionMetatiles();
|
||||||
QPixmap renderElevationMetatiles();
|
|
||||||
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter);
|
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth);
|
||||||
|
|
||||||
bool blockChanged(int, Blockdata*);
|
bool blockChanged(int, Blockdata*);
|
||||||
void cacheBlockdata();
|
void cacheBlockdata();
|
||||||
|
@ -177,6 +174,9 @@ public:
|
||||||
int paint_tile_height = 1;
|
int paint_tile_height = 1;
|
||||||
int paint_tile_initial_x;
|
int paint_tile_initial_x;
|
||||||
int paint_tile_initial_y;
|
int paint_tile_initial_y;
|
||||||
|
int selected_metatiles_width;
|
||||||
|
int selected_metatiles_height;
|
||||||
|
QList<int> *selected_metatiles = NULL;
|
||||||
int paint_collision;
|
int paint_collision;
|
||||||
int paint_elevation;
|
int paint_elevation;
|
||||||
|
|
||||||
|
@ -214,10 +214,9 @@ public:
|
||||||
void clearHoveredTile();
|
void clearHoveredTile();
|
||||||
void hoveredMetatileChanged(int block);
|
void hoveredMetatileChanged(int block);
|
||||||
void clearHoveredMetatile();
|
void clearHoveredMetatile();
|
||||||
void hoveredCollisionTileChanged(int collision);
|
void hoveredMovementPermissionTileChanged(int collision, int elevation);
|
||||||
void clearHoveredCollisionTile();
|
void clearHoveredMovementPermissionTile();
|
||||||
void hoveredElevationTileChanged(int elevation);
|
void setSelectedMetatilesFromTilePicker();
|
||||||
void clearHoveredElevationTile();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void paintTileChanged(Map *map);
|
void paintTileChanged(Map *map);
|
||||||
|
|
|
@ -15,5 +15,6 @@
|
||||||
<file>icons/add.ico</file>
|
<file>icons/add.ico</file>
|
||||||
<file>icons/delete.ico</file>
|
<file>icons/delete.ico</file>
|
||||||
<file>icons/viewsprites.ico</file>
|
<file>icons/viewsprites.ico</file>
|
||||||
|
<file>images/collisions.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
BIN
resources/images/collisions.png
Normal file
BIN
resources/images/collisions.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
|
@ -110,7 +110,11 @@ QList<QList<QRgb>> Metatile::getBlockPalettes(Tileset *primaryTileset, Tileset *
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
palettes.append(primaryTileset->palettes->at(i));
|
palettes.append(primaryTileset->palettes->at(i));
|
||||||
}
|
}
|
||||||
for (int i = 6; i < 12; i++) {
|
|
||||||
|
// TODO: Find a reliable way to detect Ruby vs. Emerald
|
||||||
|
// Ruby's secondary tilesets only use palettes 6-11, whereas
|
||||||
|
// Emerald uses 6-12.
|
||||||
|
for (int i = 6; i < 13; i++) {
|
||||||
palettes.append(secondaryTileset->palettes->at(i));
|
palettes.append(secondaryTileset->palettes->at(i));
|
||||||
}
|
}
|
||||||
return palettes;
|
return palettes;
|
||||||
|
|
Loading…
Reference in a new issue