Update collision/elevation selection
This commit is contained in:
parent
de9bfaa9bb
commit
21af92b856
8 changed files with 186 additions and 312 deletions
117
editor.cpp
117
editor.cpp
|
@ -353,14 +353,18 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
}
|
||||
}
|
||||
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);
|
||||
if (event->buttons() & Qt::RightButton) {
|
||||
item->updateMovementPermissionSelection(event);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -412,7 +416,6 @@ void Editor::displayMap() {
|
|||
displayBorderMetatiles();
|
||||
displayCurrentMetatilesSelection();
|
||||
displayCollisionMetatiles();
|
||||
displayElevationMetatiles();
|
||||
displayMapEvents();
|
||||
displayMapConnections();
|
||||
displayMapBorder();
|
||||
|
@ -481,23 +484,11 @@ void Editor::displayCollisionMetatiles() {
|
|||
}
|
||||
|
||||
scene_collision_metatiles = new QGraphicsScene;
|
||||
collision_metatiles_item = new CollisionMetatilesPixmapItem(map);
|
||||
collision_metatiles_item = new MovementPermissionsPixmapItem(map);
|
||||
collision_metatiles_item->draw();
|
||||
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() {
|
||||
if (events_group) {
|
||||
for (QGraphicsItem *child : events_group->childItems()) {
|
||||
|
@ -989,13 +980,17 @@ void CurrentSelectedMetatilesPixmapItem::draw() {
|
|||
|
||||
void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
||||
QPointF pos = event->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)) {
|
||||
pick(y * width + x);
|
||||
}
|
||||
int x = ((int)pos.x()) / 32;
|
||||
int y = ((int)pos.y()) / 32;
|
||||
int width = pixmap().width() / 32;
|
||||
int height = pixmap().height() / 32;
|
||||
|
||||
// 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) {
|
||||
updateCurHoveredMetatile(event->pos());
|
||||
|
@ -1005,17 +1000,18 @@ void MovementPermissionsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent*
|
|||
mousePressEvent(event);
|
||||
}
|
||||
|
||||
void CollisionMetatilesPixmapItem::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->clearHoveredCollisionTile();
|
||||
} else {
|
||||
int collision = y * width + x;
|
||||
map->hoveredCollisionTileChanged(collision);
|
||||
}
|
||||
void MovementPermissionsPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
||||
int x = ((int)pos.x()) / 32;
|
||||
int y = ((int)pos.y()) / 32;
|
||||
int width = pixmap().width() / 32;
|
||||
int height = pixmap().height() / 32;
|
||||
|
||||
// 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;
|
||||
map->hoveredMovementPermissionTileChanged(x, y);
|
||||
}
|
||||
|
||||
int ConnectionPixmapItem::getMinOffset() {
|
||||
|
@ -1074,19 +1070,6 @@ void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) {
|
|||
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) {
|
||||
if (map) {
|
||||
QPointF pos = event->pos();
|
||||
|
@ -1487,8 +1470,14 @@ void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
|
|||
if (x < 0 || x >= map->getWidth() || y < 0 || y >= map->getHeight()) {
|
||||
map->clearHoveredTile();
|
||||
} else {
|
||||
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
|
||||
map->hoveredTileChanged(x, y, tile);
|
||||
if (editor->current_view == editor->map_item) {
|
||||
int tile = map->layout->blockdata->blocks->at(blockIndex).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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1582,6 +1571,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) {
|
||||
active = true;
|
||||
last_x = (mouse->pos().x() + this->pos().x()) / 16;
|
||||
|
|
51
editor.h
51
editor.h
|
@ -18,8 +18,7 @@ class ConnectionPixmapItem;
|
|||
class MetatilesPixmapItem;
|
||||
class BorderMetatilesPixmapItem;
|
||||
class CurrentSelectedMetatilesPixmapItem;
|
||||
class CollisionMetatilesPixmapItem;
|
||||
class ElevationMetatilesPixmapItem;
|
||||
class MovementPermissionsPixmapItem;
|
||||
|
||||
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
||||
|
||||
|
@ -98,8 +97,7 @@ public:
|
|||
|
||||
BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL;
|
||||
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = NULL;
|
||||
CollisionMetatilesPixmapItem *collision_metatiles_item = NULL;
|
||||
ElevationMetatilesPixmapItem *elevation_metatiles_item = NULL;
|
||||
MovementPermissionsPixmapItem *collision_metatiles_item = NULL;
|
||||
|
||||
QList<DraggablePixmapItem*> *events = NULL;
|
||||
QList<DraggablePixmapItem*> *selected_events = NULL;
|
||||
|
@ -299,6 +297,7 @@ public:
|
|||
}
|
||||
CollisionPixmapItem(Map *map_, Editor *editor_): MapPixmapItem(map_, editor_) {
|
||||
}
|
||||
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event);
|
||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||
|
@ -408,31 +407,21 @@ public:
|
|||
class MovementPermissionsPixmapItem : public MetatilesPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
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_) {
|
||||
MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(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_elevation = elevation;
|
||||
draw();
|
||||
}
|
||||
virtual void draw() {
|
||||
setPixmap(map->renderCollisionMetatiles());
|
||||
}
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
virtual void updateCurHoveredMetatile(QPointF pos);
|
||||
private slots:
|
||||
void paintCollisionChanged(Map *map) {
|
||||
|
@ -440,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
|
||||
|
|
|
@ -38,7 +38,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
|
||||
connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
|
||||
connect(editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
|
||||
connect(editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged()));
|
||||
|
||||
on_toolButton_Paint_clicked();
|
||||
|
||||
|
@ -195,10 +194,6 @@ void MainWindow::redrawMapScene()
|
|||
ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles);
|
||||
//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_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) {
|
||||
|
|
157
mainwindow.ui
157
mainwindow.ui
|
@ -466,7 +466,7 @@
|
|||
</size>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_blocks">
|
||||
<property name="sizePolicy">
|
||||
|
@ -912,7 +912,7 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@ -920,97 +920,78 @@
|
|||
<attribute name="title">
|
||||
<string>Collision</string>
|
||||
</attribute>
|
||||
<widget class="Line" name="line">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>60</y>
|
||||
<width>111</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
<layout class="QGridLayout" name="gridLayout_CollisionSelection">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>80</y>
|
||||
<width>151</width>
|
||||
<height>101</height>
|
||||
</rect>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>47</width>
|
||||
<height>13</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Elevation</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGraphicsView" name="graphicsView_Elevation">
|
||||
<property name="geometry">
|
||||
<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>
|
||||
<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">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer_19">
|
||||
<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 row="1" column="1">
|
||||
<spacer name="verticalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
152
map.cpp
152
map.cpp
|
@ -81,46 +81,14 @@ int Map::getDisplayedBlockIndex(int index) {
|
|||
}
|
||||
|
||||
QImage Map::getCollisionMetatileImage(Block block) {
|
||||
return getCollisionMetatileImage(block.collision);
|
||||
return getCollisionMetatileImage(block.collision, block.elevation);
|
||||
}
|
||||
|
||||
QImage Map::getCollisionMetatileImage(int collision) {
|
||||
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
||||
QColor color;
|
||||
if (collision == 0) {
|
||||
color.setGreen(0xff);
|
||||
} 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;
|
||||
QImage Map::getCollisionMetatileImage(int collision, int elevation) {
|
||||
int x = collision * 16;
|
||||
int y = elevation * 16;
|
||||
QPixmap collisionImage = QPixmap(":/images/collisions.png").copy(x, y, 16, 16);
|
||||
return collisionImage.toImage();
|
||||
}
|
||||
|
||||
bool Map::blockChanged(int i, Blockdata *cache) {
|
||||
|
@ -203,40 +171,15 @@ QPixmap Map::renderCollision(bool ignoreCache) {
|
|||
Block block = layout->blockdata->blocks->value(i);
|
||||
QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
||||
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
||||
QImage elevation_metatile_image = getElevationMetatileImage(block);
|
||||
int map_y = width_ ? i / width_ : 0;
|
||||
int map_x = width_ ? i % width_ : 0;
|
||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||
painter.setOpacity(1);
|
||||
painter.drawImage(metatile_origin, metatile_image);
|
||||
|
||||
painter.save();
|
||||
if (block.elevation == 15) {
|
||||
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.setOpacity(0.55);
|
||||
painter.drawImage(metatile_origin, collision_metatile_image);
|
||||
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();
|
||||
cacheCollision();
|
||||
|
@ -353,54 +296,35 @@ QPixmap Map::renderConnection(Connection connection) {
|
|||
}
|
||||
|
||||
QPixmap Map::renderCollisionMetatiles() {
|
||||
int length_ = 4;
|
||||
int height_ = 1;
|
||||
int width_ = length_ / height_;
|
||||
QImage image(width_ * 16, height_ * 16, QImage::Format_RGBA8888);
|
||||
int width_ = 2;
|
||||
int height_ = 16;
|
||||
QImage image(width_ * 32, height_ * 32, 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 = getCollisionMetatileImage(i);
|
||||
painter.drawImage(origin, metatile_image);
|
||||
for (int i = 0; i < width_; i++) {
|
||||
for (int j = 0; j < height_; j++) {
|
||||
QPoint origin(i * 32, j * 32);
|
||||
QImage metatile_image = getCollisionMetatileImage(i, j).scaled(32, 32);
|
||||
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();
|
||||
return QPixmap::fromImage(image);
|
||||
}
|
||||
|
||||
QPixmap Map::renderElevationMetatiles() {
|
||||
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) {
|
||||
void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth) {
|
||||
int x = i % w;
|
||||
int y = i / w;
|
||||
painter->save();
|
||||
|
||||
QColor penColor = QColor(0xff, 0xff, 0xff);
|
||||
painter->setPen(penColor);
|
||||
int rectWidth = selectionWidth * 16;
|
||||
int rectHeight = selectionHeight * 16;
|
||||
painter->drawRect(x * 16, y * 16, rectWidth - 1, rectHeight -1);
|
||||
int rectWidth = selectionWidth * gridWidth;
|
||||
int rectHeight = selectionHeight * gridWidth;
|
||||
painter->drawRect(x * gridWidth, y * gridWidth, rectWidth - 1, rectHeight -1);
|
||||
painter->setPen(QColor(0, 0, 0));
|
||||
painter->drawRect(x * 16 - 1, y * 16 - 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 + 1, rectHeight + 1);
|
||||
painter->drawRect(x * gridWidth + 1, y * gridWidth + 1, rectWidth - 3, rectHeight - 3);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
@ -427,7 +351,7 @@ QPixmap Map::renderMetatiles() {
|
|||
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();
|
||||
return QPixmap::fromImage(image);
|
||||
|
@ -684,7 +608,7 @@ bool Map::hasUnsavedChanges() {
|
|||
}
|
||||
|
||||
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(y)
|
||||
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
|
||||
|
@ -704,19 +628,23 @@ void Map::clearHoveredMetatile() {
|
|||
emit statusBarMessage(QString(""));
|
||||
}
|
||||
|
||||
void Map::hoveredCollisionTileChanged(int collision) {
|
||||
emit statusBarMessage(QString("Collision: %1").arg(collision));
|
||||
void Map::hoveredMovementPermissionTileChanged(int collision, int elevation) {
|
||||
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() {
|
||||
emit statusBarMessage(QString(""));
|
||||
}
|
||||
|
||||
void Map::hoveredElevationTileChanged(int elevation) {
|
||||
emit statusBarMessage(QString("Elevation: %1").arg(elevation));
|
||||
}
|
||||
|
||||
void Map::clearHoveredElevationTile() {
|
||||
void Map::clearHoveredMovementPermissionTile() {
|
||||
emit statusBarMessage(QString(""));
|
||||
}
|
||||
|
||||
|
|
15
map.h
15
map.h
|
@ -155,13 +155,10 @@ public:
|
|||
QImage collision_image;
|
||||
QPixmap collision_pixmap;
|
||||
QImage getCollisionMetatileImage(Block);
|
||||
QImage getElevationMetatileImage(Block);
|
||||
QImage getCollisionMetatileImage(int);
|
||||
QImage getElevationMetatileImage(int);
|
||||
|
||||
QImage getCollisionMetatileImage(int, int);
|
||||
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*);
|
||||
void cacheBlockdata();
|
||||
|
@ -217,10 +214,8 @@ public:
|
|||
void clearHoveredTile();
|
||||
void hoveredMetatileChanged(int block);
|
||||
void clearHoveredMetatile();
|
||||
void hoveredCollisionTileChanged(int collision);
|
||||
void clearHoveredCollisionTile();
|
||||
void hoveredElevationTileChanged(int elevation);
|
||||
void clearHoveredElevationTile();
|
||||
void hoveredMovementPermissionTileChanged(int collision, int elevation);
|
||||
void clearHoveredMovementPermissionTile();
|
||||
void setSelectedMetatilesFromTilePicker();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -15,5 +15,6 @@
|
|||
<file>icons/add.ico</file>
|
||||
<file>icons/delete.ico</file>
|
||||
<file>icons/viewsprites.ico</file>
|
||||
<file>images/collisions.png</file>
|
||||
</qresource>
|
||||
</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 |
Loading…
Reference in a new issue