Add player view rectangle option
This commit is contained in:
parent
3f88072981
commit
4d088766a0
13 changed files with 115 additions and 11 deletions
|
@ -2589,6 +2589,7 @@
|
||||||
<addaction name="actionZoom_In"/>
|
<addaction name="actionZoom_In"/>
|
||||||
<addaction name="actionZoom_Out"/>
|
<addaction name="actionZoom_Out"/>
|
||||||
<addaction name="actionBetter_Cursors"/>
|
<addaction name="actionBetter_Cursors"/>
|
||||||
|
<addaction name="actionPlayer_View_Rectangle"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuTools">
|
<widget class="QMenu" name="menuTools">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -2808,6 +2809,17 @@
|
||||||
<string>About Porymap...</string>
|
<string>About Porymap...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionPlayer_View_Rectangle">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Player View Rectangle</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><html><head/><body><p>Show the player's view rectangle on the map based on the cursor's position.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "collisionpixmapitem.h"
|
#include "collisionpixmapitem.h"
|
||||||
#include "mappixmapitem.h"
|
#include "mappixmapitem.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "playerviewrect.h"
|
||||||
|
|
||||||
class DraggablePixmapItem;
|
class DraggablePixmapItem;
|
||||||
class MetatilesPixmapItem;
|
class MetatilesPixmapItem;
|
||||||
|
@ -94,6 +95,7 @@ public:
|
||||||
QGraphicsItemGroup *events_group = nullptr;
|
QGraphicsItemGroup *events_group = nullptr;
|
||||||
QList<QGraphicsPixmapItem*> borderItems;
|
QList<QGraphicsPixmapItem*> borderItems;
|
||||||
QList<QGraphicsLineItem*> gridLines;
|
QList<QGraphicsLineItem*> gridLines;
|
||||||
|
PlayerViewRect *playerViewRect = nullptr;
|
||||||
|
|
||||||
QGraphicsScene *scene_metatiles = nullptr;
|
QGraphicsScene *scene_metatiles = nullptr;
|
||||||
QGraphicsScene *scene_current_metatile_selection = nullptr;
|
QGraphicsScene *scene_current_metatile_selection = nullptr;
|
||||||
|
|
|
@ -74,6 +74,7 @@ private slots:
|
||||||
void on_actionZoom_In_triggered();
|
void on_actionZoom_In_triggered();
|
||||||
void on_actionZoom_Out_triggered();
|
void on_actionZoom_Out_triggered();
|
||||||
void on_actionBetter_Cursors_triggered();
|
void on_actionBetter_Cursors_triggered();
|
||||||
|
void on_actionPlayer_View_Rectangle_triggered();
|
||||||
void on_actionPencil_triggered();
|
void on_actionPencil_triggered();
|
||||||
void on_actionPointer_triggered();
|
void on_actionPointer_triggered();
|
||||||
void on_actionFlood_Fill_triggered();
|
void on_actionFlood_Fill_triggered();
|
||||||
|
|
|
@ -10,6 +10,7 @@ public:
|
||||||
bool smartPathsEnabled;
|
bool smartPathsEnabled;
|
||||||
bool betterCursors;
|
bool betterCursors;
|
||||||
QCursor mapCursor;
|
QCursor mapCursor;
|
||||||
|
bool playerViewRectEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
|
|
@ -13,8 +13,10 @@ public:
|
||||||
this->map = map_;
|
this->map = map_;
|
||||||
this->metatileSelector = metatileSelector;
|
this->metatileSelector = metatileSelector;
|
||||||
this->settings = settings;
|
this->settings = settings;
|
||||||
|
this->paintingEnabled = true;
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
|
bool paintingEnabled;
|
||||||
Map *map;
|
Map *map;
|
||||||
MetatileSelector *metatileSelector;
|
MetatileSelector *metatileSelector;
|
||||||
Settings *settings;
|
Settings *settings;
|
||||||
|
|
35
include/ui/playerviewrect.h
Normal file
35
include/ui/playerviewrect.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef PLAYERVIEWRECT_H
|
||||||
|
#define PLAYERVIEWRECT_H
|
||||||
|
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
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
|
|
@ -45,6 +45,7 @@ SOURCES += src/core/block.cpp \
|
||||||
src/ui/noscrollcombobox.cpp \
|
src/ui/noscrollcombobox.cpp \
|
||||||
src/ui/noscrollspinbox.cpp \
|
src/ui/noscrollspinbox.cpp \
|
||||||
src/ui/paletteeditor.cpp \
|
src/ui/paletteeditor.cpp \
|
||||||
|
src/ui/playerviewrect.cpp \
|
||||||
src/ui/selectablepixmapitem.cpp \
|
src/ui/selectablepixmapitem.cpp \
|
||||||
src/ui/tileseteditor.cpp \
|
src/ui/tileseteditor.cpp \
|
||||||
src/ui/tileseteditormetatileselector.cpp \
|
src/ui/tileseteditormetatileselector.cpp \
|
||||||
|
@ -91,6 +92,7 @@ HEADERS += include/core/block.h \
|
||||||
include/ui/noscrollcombobox.h \
|
include/ui/noscrollcombobox.h \
|
||||||
include/ui/noscrollspinbox.h \
|
include/ui/noscrollspinbox.h \
|
||||||
include/ui/paletteeditor.h \
|
include/ui/paletteeditor.h \
|
||||||
|
include/ui/playerviewrect.h \
|
||||||
include/ui/selectablepixmapitem.h \
|
include/ui/selectablepixmapitem.h \
|
||||||
include/ui/tileseteditor.h \
|
include/ui/tileseteditor.h \
|
||||||
include/ui/tileseteditormetatileselector.h \
|
include/ui/tileseteditormetatileselector.h \
|
||||||
|
|
|
@ -17,6 +17,7 @@ Editor::Editor(Ui::MainWindow* ui)
|
||||||
this->ui = ui;
|
this->ui = ui;
|
||||||
this->selected_events = new QList<DraggablePixmapItem*>;
|
this->selected_events = new QList<DraggablePixmapItem*>;
|
||||||
this->settings = new Settings();
|
this->settings = new Settings();
|
||||||
|
this->playerViewRect = new PlayerViewRect(&this->settings->playerViewRectEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::saveProject() {
|
void Editor::saveProject() {
|
||||||
|
@ -59,10 +60,10 @@ void Editor::closeProject() {
|
||||||
void Editor::setEditingMap() {
|
void Editor::setEditingMap() {
|
||||||
current_view = map_item;
|
current_view = map_item;
|
||||||
if (map_item) {
|
if (map_item) {
|
||||||
|
map_item->paintingEnabled = true;
|
||||||
displayMapConnections();
|
displayMapConnections();
|
||||||
map_item->draw();
|
map_item->draw();
|
||||||
map_item->setVisible(true);
|
map_item->setVisible(true);
|
||||||
map_item->setEnabled(true);
|
|
||||||
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
|
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
|
||||||
}
|
}
|
||||||
if (collision_item) {
|
if (collision_item) {
|
||||||
|
@ -84,6 +85,7 @@ void Editor::setEditingCollision() {
|
||||||
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
|
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
|
||||||
}
|
}
|
||||||
if (map_item) {
|
if (map_item) {
|
||||||
|
map_item->paintingEnabled = true;
|
||||||
map_item->setVisible(false);
|
map_item->setVisible(false);
|
||||||
}
|
}
|
||||||
if (events_group) {
|
if (events_group) {
|
||||||
|
@ -99,8 +101,8 @@ void Editor::setEditingObjects() {
|
||||||
events_group->setVisible(true);
|
events_group->setVisible(true);
|
||||||
}
|
}
|
||||||
if (map_item) {
|
if (map_item) {
|
||||||
|
map_item->paintingEnabled = false;
|
||||||
map_item->setVisible(true);
|
map_item->setVisible(true);
|
||||||
map_item->setEnabled(false);
|
|
||||||
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
|
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
|
||||||
}
|
}
|
||||||
if (collision_item) {
|
if (collision_item) {
|
||||||
|
@ -113,9 +115,9 @@ void Editor::setEditingObjects() {
|
||||||
void Editor::setEditingConnections() {
|
void Editor::setEditingConnections() {
|
||||||
current_view = map_item;
|
current_view = map_item;
|
||||||
if (map_item) {
|
if (map_item) {
|
||||||
|
map_item->paintingEnabled = false;
|
||||||
map_item->draw();
|
map_item->draw();
|
||||||
map_item->setVisible(true);
|
map_item->setVisible(true);
|
||||||
map_item->setEnabled(false);
|
|
||||||
populateConnectionMapPickers();
|
populateConnectionMapPickers();
|
||||||
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
||||||
setConnectionsVisibility(false);
|
setConnectionsVisibility(false);
|
||||||
|
@ -351,7 +353,8 @@ void Editor::onSelectedMetatilesChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::onHoveredMapMetatileChanged(int x, int y) {
|
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 blockIndex = y * map->getWidth() + x;
|
||||||
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
|
int tile = map->layout->blockdata->blocks->at(blockIndex).tile;
|
||||||
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Metatile: 0x%3, Scale = %4x")
|
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() {
|
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) {
|
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;
|
int blockIndex = y * map->getWidth() + x;
|
||||||
uint16_t collision = map->layout->blockdata->blocks->at(blockIndex).collision;
|
uint16_t collision = map->layout->blockdata->blocks->at(blockIndex).collision;
|
||||||
uint16_t elevation = map->layout->blockdata->blocks->at(blockIndex).elevation;
|
uint16_t elevation = map->layout->blockdata->blocks->at(blockIndex).elevation;
|
||||||
|
@ -380,7 +387,10 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::onHoveredMapMovementPermissionCleared() {
|
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){
|
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) {
|
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
||||||
|
if (!item->paintingEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF pos = event->pos();
|
||||||
|
int x = static_cast<int>(pos.x()) / 16;
|
||||||
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
|
this->playerViewRect->updateLocation(x, y);
|
||||||
if (map_edit_mode == "paint") {
|
if (map_edit_mode == "paint") {
|
||||||
if (event->buttons() & Qt::RightButton) {
|
if (event->buttons() & Qt::RightButton) {
|
||||||
item->updateMetatileSelection(event);
|
item->updateMetatileSelection(event);
|
||||||
|
@ -461,6 +479,14 @@ 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 (!item->paintingEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF pos = event->pos();
|
||||||
|
int x = static_cast<int>(pos.x()) / 16;
|
||||||
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
|
this->playerViewRect->updateLocation(x, y);
|
||||||
if (map_edit_mode == "paint") {
|
if (map_edit_mode == "paint") {
|
||||||
if (event->buttons() & Qt::RightButton) {
|
if (event->buttons() & Qt::RightButton) {
|
||||||
item->updateMovementPermissionSelection(event);
|
item->updateMovementPermissionSelection(event);
|
||||||
|
@ -513,6 +539,8 @@ void Editor::displayMap() {
|
||||||
displayMapConnections();
|
displayMapConnections();
|
||||||
displayMapBorder();
|
displayMapBorder();
|
||||||
displayMapGrid();
|
displayMapGrid();
|
||||||
|
this->playerViewRect->setZValue(1000);
|
||||||
|
scene->addItem(this->playerViewRect);
|
||||||
|
|
||||||
if (map_item) {
|
if (map_item) {
|
||||||
map_item->setVisible(false);
|
map_item->setVisible(false);
|
||||||
|
@ -1042,6 +1070,7 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
if (active) {
|
if (active) {
|
||||||
int x = static_cast<int>(mouse->pos().x() + this->pos().x()) / 16;
|
int x = static_cast<int>(mouse->pos().x() + this->pos().x()) / 16;
|
||||||
int y = static_cast<int>(mouse->pos().y() + this->pos().y()) / 16;
|
int y = static_cast<int>(mouse->pos().y() + this->pos().y()) / 16;
|
||||||
|
this->editor->playerViewRect->updateLocation(x, y);
|
||||||
if (x != last_x || y != last_y) {
|
if (x != last_x || y != last_y) {
|
||||||
if (editor->selected_events->contains(this)) {
|
if (editor->selected_events->contains(this)) {
|
||||||
for (DraggablePixmapItem *item : *editor->selected_events) {
|
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||||
|
|
|
@ -970,6 +970,11 @@ void MainWindow::on_actionBetter_Cursors_triggered() {
|
||||||
this->editor->settings->betterCursors = ui->actionBetter_Cursors->isChecked();
|
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()
|
void MainWindow::on_actionPencil_triggered()
|
||||||
{
|
{
|
||||||
on_toolButton_Paint_clicked();
|
on_toolButton_Paint_clicked();
|
||||||
|
|
|
@ -4,4 +4,5 @@ Settings::Settings()
|
||||||
{
|
{
|
||||||
this->smartPathsEnabled = false;
|
this->smartPathsEnabled = false;
|
||||||
this->betterCursors = true;
|
this->betterCursors = true;
|
||||||
|
this->playerViewRectEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,13 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
int x = static_cast<int>(event->pos().x()) / 16;
|
int x = static_cast<int>(event->pos().x()) / 16;
|
||||||
int y = static_cast<int>(event->pos().y()) / 16;
|
int y = static_cast<int>(event->pos().y()) / 16;
|
||||||
emit this->hoveredMapMovementPermissionChanged(x, y);
|
emit this->hoveredMapMovementPermissionChanged(x, y);
|
||||||
if (this->settings->betterCursors){
|
if (this->settings->betterCursors && this->paintingEnabled) {
|
||||||
setCursor(this->settings->mapCursor);
|
setCursor(this->settings->mapCursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||||
emit this->hoveredMapMovementPermissionCleared();
|
emit this->hoveredMapMovementPermissionCleared();
|
||||||
if (this->settings->betterCursors){
|
if (this->settings->betterCursors && this->paintingEnabled){
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -499,13 +499,13 @@ void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
int x = static_cast<int>(event->pos().x()) / 16;
|
int x = static_cast<int>(event->pos().x()) / 16;
|
||||||
int y = static_cast<int>(event->pos().y()) / 16;
|
int y = static_cast<int>(event->pos().y()) / 16;
|
||||||
emit this->hoveredMapMetatileChanged(x, y);
|
emit this->hoveredMapMetatileChanged(x, y);
|
||||||
if (this->settings->betterCursors){
|
if (this->settings->betterCursors && this->paintingEnabled) {
|
||||||
setCursor(this->settings->mapCursor);
|
setCursor(this->settings->mapCursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||||
emit this->hoveredMapMetatileCleared();
|
emit this->hoveredMapMetatileCleared();
|
||||||
if (this->settings->betterCursors){
|
if (this->settings->betterCursors && this->paintingEnabled) {
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
src/ui/playerviewrect.cpp
Normal file
14
src/ui/playerviewrect.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in a new issue