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) {
|
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
|
||||||
if (map_edit_mode == "paint") {
|
if (event->buttons() & Qt::RightButton) {
|
||||||
item->paint(event);
|
item->updateMovementPermissionSelection(event);
|
||||||
} else if (map_edit_mode == "fill") {
|
} else {
|
||||||
item->floodFill(event);
|
if (map_edit_mode == "paint") {
|
||||||
} else if (map_edit_mode == "pick") {
|
item->paint(event);
|
||||||
item->pick(event);
|
} else if (map_edit_mode == "fill") {
|
||||||
} else if (map_edit_mode == "select") {
|
item->floodFill(event);
|
||||||
item->select(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();
|
displayBorderMetatiles();
|
||||||
displayCurrentMetatilesSelection();
|
displayCurrentMetatilesSelection();
|
||||||
displayCollisionMetatiles();
|
displayCollisionMetatiles();
|
||||||
displayElevationMetatiles();
|
|
||||||
displayMapEvents();
|
displayMapEvents();
|
||||||
displayMapConnections();
|
displayMapConnections();
|
||||||
displayMapBorder();
|
displayMapBorder();
|
||||||
|
@ -481,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()) {
|
||||||
|
@ -989,13 +980,17 @@ void CurrentSelectedMetatilesPixmapItem::draw() {
|
||||||
|
|
||||||
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());
|
||||||
|
@ -1005,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() {
|
||||||
|
@ -1074,19 +1070,6 @@ 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) {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
|
@ -1487,8 +1470,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 {
|
||||||
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
|
if (editor->current_view == editor->map_item) {
|
||||||
map->hoveredTileChanged(x, y, tile);
|
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) {
|
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;
|
||||||
|
|
51
editor.h
51
editor.h
|
@ -18,8 +18,7 @@ class ConnectionPixmapItem;
|
||||||
class MetatilesPixmapItem;
|
class MetatilesPixmapItem;
|
||||||
class BorderMetatilesPixmapItem;
|
class BorderMetatilesPixmapItem;
|
||||||
class CurrentSelectedMetatilesPixmapItem;
|
class CurrentSelectedMetatilesPixmapItem;
|
||||||
class CollisionMetatilesPixmapItem;
|
class MovementPermissionsPixmapItem;
|
||||||
class ElevationMetatilesPixmapItem;
|
|
||||||
|
|
||||||
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
#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;
|
BorderMetatilesPixmapItem *selected_border_metatiles_item = NULL;
|
||||||
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = NULL;
|
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = NULL;
|
||||||
CollisionMetatilesPixmapItem *collision_metatiles_item = NULL;
|
MovementPermissionsPixmapItem *collision_metatiles_item = NULL;
|
||||||
ElevationMetatilesPixmapItem *elevation_metatiles_item = NULL;
|
|
||||||
|
|
||||||
QList<DraggablePixmapItem*> *events = NULL;
|
QList<DraggablePixmapItem*> *events = NULL;
|
||||||
QList<DraggablePixmapItem*> *selected_events = NULL;
|
QList<DraggablePixmapItem*> *selected_events = NULL;
|
||||||
|
@ -299,6 +297,7 @@ public:
|
||||||
}
|
}
|
||||||
CollisionPixmapItem(Map *map_, Editor *editor_): MapPixmapItem(map_, editor_) {
|
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*);
|
||||||
|
@ -408,31 +407,21 @@ public:
|
||||||
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) {
|
||||||
|
@ -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
|
#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(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();
|
||||||
|
|
||||||
|
@ -195,10 +194,6 @@ void MainWindow::redrawMapScene()
|
||||||
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) {
|
||||||
|
|
157
mainwindow.ui
157
mainwindow.ui
|
@ -466,7 +466,7 @@
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_blocks">
|
<widget class="QWidget" name="tab_blocks">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -912,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>
|
||||||
|
@ -920,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="orientation">
|
<property name="leftMargin">
|
||||||
<enum>Qt::Horizontal</enum>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="topMargin">
|
||||||
<widget class="QFrame" name="frame">
|
<number>0</number>
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>80</y>
|
|
||||||
<width>151</width>
|
|
||||||
<height>101</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<property name="rightMargin">
|
||||||
<enum>QFrame::StyledPanel</enum>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShadow">
|
<property name="bottomMargin">
|
||||||
<enum>QFrame::Raised</enum>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QLabel" name="label_2">
|
<item row="0" column="1">
|
||||||
<property name="geometry">
|
<widget class="QGraphicsView" name="graphicsView_Collision">
|
||||||
<rect>
|
<property name="sizePolicy">
|
||||||
<x>10</x>
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<y>10</y>
|
<horstretch>0</horstretch>
|
||||||
<width>47</width>
|
<verstretch>0</verstretch>
|
||||||
<height>13</height>
|
</sizepolicy>
|
||||||
</rect>
|
</property>
|
||||||
</property>
|
<property name="minimumSize">
|
||||||
<property name="text">
|
<size>
|
||||||
<string>Elevation</string>
|
<width>64</width>
|
||||||
</property>
|
<height>512</height>
|
||||||
</widget>
|
</size>
|
||||||
<widget class="QGraphicsView" name="graphicsView_Elevation">
|
</property>
|
||||||
<property name="geometry">
|
</widget>
|
||||||
<rect>
|
</item>
|
||||||
<x>10</x>
|
<item row="0" column="0">
|
||||||
<y>30</y>
|
<spacer name="horizontalSpacer_18">
|
||||||
<width>131</width>
|
<property name="orientation">
|
||||||
<height>61</height>
|
<enum>Qt::Horizontal</enum>
|
||||||
</rect>
|
</property>
|
||||||
</property>
|
<property name="sizeHint" stdset="0">
|
||||||
</widget>
|
<size>
|
||||||
</widget>
|
<width>40</width>
|
||||||
<widget class="QFrame" name="frame_2">
|
<height>20</height>
|
||||||
<property name="geometry">
|
</size>
|
||||||
<rect>
|
</property>
|
||||||
<x>0</x>
|
</spacer>
|
||||||
<y>0</y>
|
</item>
|
||||||
<width>151</width>
|
<item row="0" column="2">
|
||||||
<height>61</height>
|
<spacer name="horizontalSpacer_19">
|
||||||
</rect>
|
<property name="orientation">
|
||||||
</property>
|
<enum>Qt::Horizontal</enum>
|
||||||
<property name="frameShape">
|
</property>
|
||||||
<enum>QFrame::StyledPanel</enum>
|
<property name="sizeHint" stdset="0">
|
||||||
</property>
|
<size>
|
||||||
<property name="frameShadow">
|
<width>40</width>
|
||||||
<enum>QFrame::Raised</enum>
|
<height>20</height>
|
||||||
</property>
|
</size>
|
||||||
<widget class="QLabel" name="label">
|
</property>
|
||||||
<property name="geometry">
|
</spacer>
|
||||||
<rect>
|
</item>
|
||||||
<x>10</x>
|
<item row="1" column="1">
|
||||||
<y>10</y>
|
<spacer name="verticalSpacer_6">
|
||||||
<width>47</width>
|
<property name="orientation">
|
||||||
<height>13</height>
|
<enum>Qt::Vertical</enum>
|
||||||
</rect>
|
</property>
|
||||||
</property>
|
<property name="sizeHint" stdset="0">
|
||||||
<property name="text">
|
<size>
|
||||||
<string>Collision</string>
|
<width>20</width>
|
||||||
</property>
|
<height>40</height>
|
||||||
</widget>
|
</size>
|
||||||
<widget class="QGraphicsView" name="graphicsView_Collision">
|
</property>
|
||||||
<property name="geometry">
|
</spacer>
|
||||||
<rect>
|
</item>
|
||||||
<x>40</x>
|
</layout>
|
||||||
<y>30</y>
|
|
||||||
<width>66</width>
|
|
||||||
<height>18</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
152
map.cpp
152
map.cpp
|
@ -81,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) {
|
||||||
|
@ -203,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();
|
||||||
|
@ -353,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,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);
|
||||||
|
@ -684,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()));
|
||||||
|
@ -704,19 +628,23 @@ 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(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Map::hoveredElevationTileChanged(int elevation) {
|
|
||||||
emit statusBarMessage(QString("Elevation: %1").arg(elevation));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Map::clearHoveredElevationTile() {
|
|
||||||
emit statusBarMessage(QString(""));
|
emit statusBarMessage(QString(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
map.h
15
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();
|
||||||
|
@ -217,10 +214,8 @@ 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 clearHoveredElevationTile();
|
|
||||||
void setSelectedMetatilesFromTilePicker();
|
void setSelectedMetatilesFromTilePicker();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -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 |
Loading…
Reference in a new issue