diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
index 1e8f7dac..675eb420 100644
--- a/forms/mainwindow.ui
+++ b/forms/mainwindow.ui
@@ -2589,6 +2589,7 @@
+
diff --git a/include/editor.h b/include/editor.h
index 82a3ca9b..8b7e15ac 100644
--- a/include/editor.h
+++ b/include/editor.h
@@ -20,6 +20,7 @@
#include "collisionpixmapitem.h"
#include "mappixmapitem.h"
#include "settings.h"
+#include "playerviewrect.h"
class DraggablePixmapItem;
class MetatilesPixmapItem;
@@ -94,6 +95,7 @@ public:
QGraphicsItemGroup *events_group = nullptr;
QList borderItems;
QList gridLines;
+ PlayerViewRect *playerViewRect = nullptr;
QGraphicsScene *scene_metatiles = nullptr;
QGraphicsScene *scene_current_metatile_selection = nullptr;
diff --git a/include/mainwindow.h b/include/mainwindow.h
index b751f29d..e03b3741 100644
--- a/include/mainwindow.h
+++ b/include/mainwindow.h
@@ -74,6 +74,7 @@ private slots:
void on_actionZoom_In_triggered();
void on_actionZoom_Out_triggered();
void on_actionBetter_Cursors_triggered();
+ void on_actionPlayer_View_Rectangle_triggered();
void on_actionPencil_triggered();
void on_actionPointer_triggered();
void on_actionFlood_Fill_triggered();
diff --git a/include/settings.h b/include/settings.h
index 91699542..d9c1c095 100644
--- a/include/settings.h
+++ b/include/settings.h
@@ -10,6 +10,7 @@ public:
bool smartPathsEnabled;
bool betterCursors;
QCursor mapCursor;
+ bool playerViewRectEnabled;
};
#endif // SETTINGS_H
diff --git a/include/ui/mappixmapitem.h b/include/ui/mappixmapitem.h
index 1f9aaf8a..4ab66b21 100644
--- a/include/ui/mappixmapitem.h
+++ b/include/ui/mappixmapitem.h
@@ -13,8 +13,10 @@ public:
this->map = map_;
this->metatileSelector = metatileSelector;
this->settings = settings;
+ this->paintingEnabled = true;
setAcceptHoverEvents(true);
}
+ bool paintingEnabled;
Map *map;
MetatileSelector *metatileSelector;
Settings *settings;
diff --git a/include/ui/playerviewrect.h b/include/ui/playerviewrect.h
new file mode 100644
index 00000000..955ab692
--- /dev/null
+++ b/include/ui/playerviewrect.h
@@ -0,0 +1,35 @@
+#ifndef PLAYERVIEWRECT_H
+#define PLAYERVIEWRECT_H
+
+#include
+#include
+
+class PlayerViewRect : public QGraphicsItem
+{
+public:
+ PlayerViewRect(bool *enabled);
+ QRectF boundingRect() const override
+ {
+ qreal penWidth = 4;
+ return QRectF(-penWidth,
+ -penWidth,
+ 30 * 8 + penWidth * 2,
+ 20 * 8 + penWidth * 2);
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget) override
+ {
+ int width = 30 * 8;
+ int height = 20 * 8;
+ painter->setPen(QColor(0xff, 0xff, 0xff));
+ painter->drawRect(-2, -2, width + 3, height + 3);
+ painter->setPen(QColor(0, 0, 0));
+ painter->drawRect(-3, -3, width + 5, height + 5);
+ painter->drawRect(-1, -1, width + 1, height + 1);
+ }
+ void updateLocation(int x, int y);
+ bool *enabled;
+};
+
+#endif // PLAYERVIEWRECT_H
diff --git a/porymap.pro b/porymap.pro
index 6bee230d..e83bde72 100644
--- a/porymap.pro
+++ b/porymap.pro
@@ -45,6 +45,7 @@ SOURCES += src/core/block.cpp \
src/ui/noscrollcombobox.cpp \
src/ui/noscrollspinbox.cpp \
src/ui/paletteeditor.cpp \
+ src/ui/playerviewrect.cpp \
src/ui/selectablepixmapitem.cpp \
src/ui/tileseteditor.cpp \
src/ui/tileseteditormetatileselector.cpp \
@@ -91,6 +92,7 @@ HEADERS += include/core/block.h \
include/ui/noscrollcombobox.h \
include/ui/noscrollspinbox.h \
include/ui/paletteeditor.h \
+ include/ui/playerviewrect.h \
include/ui/selectablepixmapitem.h \
include/ui/tileseteditor.h \
include/ui/tileseteditormetatileselector.h \
diff --git a/src/editor.cpp b/src/editor.cpp
index 1f8dbc82..3c65b558 100644
--- a/src/editor.cpp
+++ b/src/editor.cpp
@@ -17,6 +17,7 @@ Editor::Editor(Ui::MainWindow* ui)
this->ui = ui;
this->selected_events = new QList;
this->settings = new Settings();
+ this->playerViewRect = new PlayerViewRect(&this->settings->playerViewRectEnabled);
}
void Editor::saveProject() {
@@ -59,10 +60,10 @@ void Editor::closeProject() {
void Editor::setEditingMap() {
current_view = map_item;
if (map_item) {
+ map_item->paintingEnabled = true;
displayMapConnections();
map_item->draw();
map_item->setVisible(true);
- map_item->setEnabled(true);
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
}
if (collision_item) {
@@ -84,6 +85,7 @@ void Editor::setEditingCollision() {
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
}
if (map_item) {
+ map_item->paintingEnabled = true;
map_item->setVisible(false);
}
if (events_group) {
@@ -99,8 +101,8 @@ void Editor::setEditingObjects() {
events_group->setVisible(true);
}
if (map_item) {
+ map_item->paintingEnabled = false;
map_item->setVisible(true);
- map_item->setEnabled(false);
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
}
if (collision_item) {
@@ -113,9 +115,9 @@ void Editor::setEditingObjects() {
void Editor::setEditingConnections() {
current_view = map_item;
if (map_item) {
+ map_item->paintingEnabled = false;
map_item->draw();
map_item->setVisible(true);
- map_item->setEnabled(false);
populateConnectionMapPickers();
ui->label_NumConnections->setText(QString::number(map->connections.length()));
setConnectionsVisibility(false);
@@ -351,7 +353,8 @@ void Editor::onSelectedMetatilesChanged() {
}
void Editor::onHoveredMapMetatileChanged(int x, int y) {
- if (x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) {
+ this->playerViewRect->updateLocation(x, y);
+ if (map_item->paintingEnabled && x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) {
int blockIndex = y * map->getWidth() + x;
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Metatile: 0x%3, Scale = %4x")
@@ -363,11 +366,15 @@ void Editor::onHoveredMapMetatileChanged(int x, int y) {
}
void Editor::onHoveredMapMetatileCleared() {
- this->ui->statusBar->clearMessage();
+ this->playerViewRect->setVisible(false);
+ if (map_item->paintingEnabled) {
+ this->ui->statusBar->clearMessage();
+ }
}
void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
- if (x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) {
+ this->playerViewRect->updateLocation(x, y);
+ if (map_item->paintingEnabled && x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) {
int blockIndex = y * map->getWidth() + x;
uint16_t collision = map->layout->blockdata->blocks->at(blockIndex).collision;
uint16_t elevation = map->layout->blockdata->blocks->at(blockIndex).elevation;
@@ -380,7 +387,10 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
}
void Editor::onHoveredMapMovementPermissionCleared() {
- this->ui->statusBar->clearMessage();
+ this->playerViewRect->setVisible(false);
+ if (map_item->paintingEnabled) {
+ this->ui->statusBar->clearMessage();
+ }
}
QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation){
@@ -427,6 +437,14 @@ bool Editor::setMap(QString map_name) {
}
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
+ if (!item->paintingEnabled) {
+ return;
+ }
+
+ QPointF pos = event->pos();
+ int x = static_cast(pos.x()) / 16;
+ int y = static_cast(pos.y()) / 16;
+ this->playerViewRect->updateLocation(x, y);
if (map_edit_mode == "paint") {
if (event->buttons() & Qt::RightButton) {
item->updateMetatileSelection(event);
@@ -461,6 +479,14 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
}
}
void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) {
+ if (!item->paintingEnabled) {
+ return;
+ }
+
+ QPointF pos = event->pos();
+ int x = static_cast(pos.x()) / 16;
+ int y = static_cast(pos.y()) / 16;
+ this->playerViewRect->updateLocation(x, y);
if (map_edit_mode == "paint") {
if (event->buttons() & Qt::RightButton) {
item->updateMovementPermissionSelection(event);
@@ -513,6 +539,8 @@ void Editor::displayMap() {
displayMapConnections();
displayMapBorder();
displayMapGrid();
+ this->playerViewRect->setZValue(1000);
+ scene->addItem(this->playerViewRect);
if (map_item) {
map_item->setVisible(false);
@@ -1042,6 +1070,7 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
if (active) {
int x = static_cast(mouse->pos().x() + this->pos().x()) / 16;
int y = static_cast(mouse->pos().y() + this->pos().y()) / 16;
+ this->editor->playerViewRect->updateLocation(x, y);
if (x != last_x || y != last_y) {
if (editor->selected_events->contains(this)) {
for (DraggablePixmapItem *item : *editor->selected_events) {
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index cd630a54..4e5fb0ff 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -970,6 +970,11 @@ void MainWindow::on_actionBetter_Cursors_triggered() {
this->editor->settings->betterCursors = ui->actionBetter_Cursors->isChecked();
}
+void MainWindow::on_actionPlayer_View_Rectangle_triggered()
+{
+ this->editor->settings->playerViewRectEnabled = ui->actionPlayer_View_Rectangle->isChecked();
+}
+
void MainWindow::on_actionPencil_triggered()
{
on_toolButton_Paint_clicked();
diff --git a/src/settings.cpp b/src/settings.cpp
index 37786a81..235d1371 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -4,4 +4,5 @@ Settings::Settings()
{
this->smartPathsEnabled = false;
this->betterCursors = true;
+ this->playerViewRectEnabled = false;
}
diff --git a/src/ui/collisionpixmapitem.cpp b/src/ui/collisionpixmapitem.cpp
index 723fe0da..3d7079d9 100644
--- a/src/ui/collisionpixmapitem.cpp
+++ b/src/ui/collisionpixmapitem.cpp
@@ -4,13 +4,13 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
int x = static_cast(event->pos().x()) / 16;
int y = static_cast(event->pos().y()) / 16;
emit this->hoveredMapMovementPermissionChanged(x, y);
- if (this->settings->betterCursors){
+ if (this->settings->betterCursors && this->paintingEnabled) {
setCursor(this->settings->mapCursor);
}
}
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
emit this->hoveredMapMovementPermissionCleared();
- if (this->settings->betterCursors){
+ if (this->settings->betterCursors && this->paintingEnabled){
unsetCursor();
}
}
diff --git a/src/ui/mappixmapitem.cpp b/src/ui/mappixmapitem.cpp
index 9bbf254a..0c7571bf 100644
--- a/src/ui/mappixmapitem.cpp
+++ b/src/ui/mappixmapitem.cpp
@@ -499,13 +499,13 @@ void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
int x = static_cast(event->pos().x()) / 16;
int y = static_cast(event->pos().y()) / 16;
emit this->hoveredMapMetatileChanged(x, y);
- if (this->settings->betterCursors){
+ if (this->settings->betterCursors && this->paintingEnabled) {
setCursor(this->settings->mapCursor);
}
}
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
emit this->hoveredMapMetatileCleared();
- if (this->settings->betterCursors){
+ if (this->settings->betterCursors && this->paintingEnabled) {
unsetCursor();
}
}
diff --git a/src/ui/playerviewrect.cpp b/src/ui/playerviewrect.cpp
new file mode 100644
index 00000000..9757517c
--- /dev/null
+++ b/src/ui/playerviewrect.cpp
@@ -0,0 +1,14 @@
+#include "playerviewrect.h"
+
+PlayerViewRect::PlayerViewRect(bool *enabled)
+{
+ this->enabled = enabled;
+ this->setVisible(*enabled);
+}
+
+void PlayerViewRect::updateLocation(int x, int y)
+{
+ this->setX((x * 16) - (14 * 8));
+ this->setY((y * 16) - (9 * 8));
+ this->setVisible(*this->enabled);
+}