Add option to show an outline around the currently-hovered map tile

This commit is contained in:
Marcus Huderle 2019-01-09 09:35:34 -06:00
parent 543743bcd0
commit 61b919566a
13 changed files with 120 additions and 32 deletions

View file

@ -2588,8 +2588,9 @@
</property>
<addaction name="actionZoom_In"/>
<addaction name="actionZoom_Out"/>
<addaction name="actionBetter_Cursors"/>
<addaction name="actionCursor_Tile_Outline"/>
<addaction name="actionPlayer_View_Rectangle"/>
<addaction name="actionBetter_Cursors"/>
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
@ -2820,6 +2821,17 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show the player's view rectangle on the map based on the cursor's position.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</action>
<action name="actionCursor_Tile_Outline">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Cursor Tile Outline</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View file

@ -33,6 +33,8 @@ public:
this->mapSortOrder = MapSortOrder::Group;
this->prettyCursors = true;
this->collisionOpacity = 50;
this->showPlayerView = false;
this->showCursorTile = true;
}
void setRecentProject(QString project);
void setRecentMap(QString map);
@ -40,12 +42,16 @@ public:
void setPrettyCursors(bool enabled);
void setGeometry(QByteArray, QByteArray, QByteArray, QByteArray, QByteArray);
void setCollisionOpacity(int opacity);
void setShowPlayerView(bool enabled);
void setShowCursorTile(bool enabled);
QString getRecentProject();
QString getRecentMap();
MapSortOrder getMapSortOrder();
bool getPrettyCursors();
QMap<QString, QByteArray> getGeometry();
int getCollisionOpacity();
bool getShowPlayerView();
bool getShowCursorTile();
protected:
QString getConfigFilepath();
void parseConfigKeyValue(QString key, QString value);
@ -64,6 +70,8 @@ private:
QByteArray eventsSlpitterState;
QByteArray mainSplitterState;
int collisionOpacity;
bool showPlayerView;
bool showCursorTile;
};
extern PorymapConfig porymapConfig;

View file

@ -20,7 +20,7 @@
#include "collisionpixmapitem.h"
#include "mappixmapitem.h"
#include "settings.h"
#include "playerviewrect.h"
#include "movablerect.h"
class DraggablePixmapItem;
class MetatilesPixmapItem;
@ -95,7 +95,8 @@ public:
QGraphicsItemGroup *events_group = nullptr;
QList<QGraphicsPixmapItem*> borderItems;
QList<QGraphicsLineItem*> gridLines;
PlayerViewRect *playerViewRect = nullptr;
MovableRect *playerViewRect = nullptr;
MovableRect *cursorMapTileRect = nullptr;
QGraphicsScene *scene_metatiles = nullptr;
QGraphicsScene *scene_current_metatile_selection = nullptr;

View file

@ -75,6 +75,7 @@ private slots:
void on_actionZoom_Out_triggered();
void on_actionBetter_Cursors_triggered();
void on_actionPlayer_View_Rectangle_triggered();
void on_actionCursor_Tile_Outline_triggered();
void on_actionPencil_triggered();
void on_actionPointer_triggered();
void on_actionFlood_Fill_triggered();

View file

@ -11,6 +11,7 @@ public:
bool betterCursors;
QCursor mapCursor;
bool playerViewRectEnabled;
bool cursorTileRectEnabled;
};
#endif // SETTINGS_H

View file

@ -1,13 +1,14 @@
#ifndef PLAYERVIEWRECT_H
#define PLAYERVIEWRECT_H
#ifndef MOVABLERECT_H
#define MOVABLERECT_H
#include <QGraphicsItem>
#include <QPainter>
#include <QRgb>
class PlayerViewRect : public QGraphicsItem
class MovableRect : public QGraphicsItem
{
public:
PlayerViewRect(bool *enabled);
MovableRect(bool *enabled, int width, int height, QRgb color);
QRectF boundingRect() const override
{
qreal penWidth = 4;
@ -20,16 +21,18 @@ public:
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(this->color);
painter->drawRect(-2, -2, this->width + 3, this->height + 3);
painter->setPen(QColor(0, 0, 0));
painter->drawRect(-3, -3, width + 5, height + 5);
painter->drawRect(-1, -1, width + 1, height + 1);
painter->drawRect(-3, -3, this->width + 5, this->height + 5);
painter->drawRect(-1, -1, this->width + 1, this->height + 1);
}
void updateLocation(int x, int y);
bool *enabled;
private:
int width;
int height;
QRgb color;
};
#endif // PLAYERVIEWRECT_H
#endif // MOVABLERECT_H

View file

@ -40,12 +40,12 @@ SOURCES += src/core/block.cpp \
src/ui/mapsceneeventfilter.cpp \
src/ui/metatilelayersitem.cpp \
src/ui/metatileselector.cpp \
src/ui/movablerect.cpp \
src/ui/movementpermissionsselector.cpp \
src/ui/neweventtoolbutton.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 \
@ -87,12 +87,12 @@ HEADERS += include/core/block.h \
include/ui/mapsceneeventfilter.h \
include/ui/metatilelayersitem.h \
include/ui/metatileselector.h \
include/ui/movablerect.h \
include/ui/movementpermissionsselector.h \
include/ui/neweventtoolbutton.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 \

View file

@ -136,6 +136,18 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
logWarn(QString("Invalid config value for collision_opacity: '%1'. Must be an integer.").arg(value));
this->collisionOpacity = 50;
}
} else if (key == "show_player_view") {
bool ok;
this->showPlayerView = value.toInt(&ok);
if (!ok) {
logWarn(QString("Invalid config value for show_player_view: '%1'. Must be 0 or 1.").arg(value));
}
} else if (key == "show_cursor_tile") {
bool ok;
this->showCursorTile = value.toInt(&ok);
if (!ok) {
logWarn(QString("Invalid config value for show_cursor_tile: '%1'. Must be 0 or 1.").arg(value));
}
} else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
}
@ -153,6 +165,8 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("events_splitter_state", stringFromByteArray(this->eventsSlpitterState));
map.insert("main_splitter_state", stringFromByteArray(this->mainSplitterState));
map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity));
map.insert("show_player_view", this->showPlayerView ? "1" : "0");
map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0");
return map;
}
@ -208,6 +222,16 @@ void PorymapConfig::setCollisionOpacity(int opacity) {
// don't auto-save here because this can be called very frequently.
}
void PorymapConfig::setShowPlayerView(bool enabled) {
this->showPlayerView = enabled;
this->save();
}
void PorymapConfig::setShowCursorTile(bool enabled) {
this->showCursorTile = enabled;
this->save();
}
QString PorymapConfig::getRecentProject() {
return this->recentProject;
}
@ -240,6 +264,14 @@ int PorymapConfig::getCollisionOpacity() {
return this->collisionOpacity;
}
bool PorymapConfig::getShowPlayerView() {
return this->showPlayerView;
}
bool PorymapConfig::getShowCursorTile() {
return this->showCursorTile;
}
const QMap<BaseGameVersion, QString> baseGameVersionMap = {
{BaseGameVersion::pokeruby, "pokeruby"},
{BaseGameVersion::pokeemerald, "pokeemerald"},

View file

@ -17,7 +17,8 @@ Editor::Editor(Ui::MainWindow* ui)
this->ui = ui;
this->selected_events = new QList<DraggablePixmapItem*>;
this->settings = new Settings();
this->playerViewRect = new PlayerViewRect(&this->settings->playerViewRectEnabled);
this->playerViewRect = new MovableRect(&this->settings->playerViewRectEnabled, 30 * 8, 20 * 8, qRgb(255, 255, 255));
this->cursorMapTileRect = new MovableRect(&this->settings->cursorTileRectEnabled, 16, 16, qRgb(255, 255, 255));
}
void Editor::saveProject() {
@ -354,6 +355,7 @@ void Editor::onSelectedMetatilesChanged() {
void Editor::onHoveredMapMetatileChanged(int x, int y) {
this->playerViewRect->updateLocation(x, y);
this->cursorMapTileRect->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;
@ -367,6 +369,7 @@ void Editor::onHoveredMapMetatileChanged(int x, int y) {
void Editor::onHoveredMapMetatileCleared() {
this->playerViewRect->setVisible(false);
this->cursorMapTileRect->setVisible(false);
if (map_item->paintingEnabled) {
this->ui->statusBar->clearMessage();
}
@ -374,6 +377,7 @@ void Editor::onHoveredMapMetatileCleared() {
void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
this->playerViewRect->updateLocation(x, y);
this->cursorMapTileRect->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;
@ -388,6 +392,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
void Editor::onHoveredMapMovementPermissionCleared() {
this->playerViewRect->setVisible(false);
this->cursorMapTileRect->setVisible(false);
if (map_item->paintingEnabled) {
this->ui->statusBar->clearMessage();
}
@ -445,6 +450,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
int x = static_cast<int>(pos.x()) / 16;
int y = static_cast<int>(pos.y()) / 16;
this->playerViewRect->updateLocation(x, y);
this->cursorMapTileRect->updateLocation(x, y);
if (map_edit_mode == "paint") {
if (event->buttons() & Qt::RightButton) {
item->updateMetatileSelection(event);
@ -487,6 +493,7 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
int x = static_cast<int>(pos.x()) / 16;
int y = static_cast<int>(pos.y()) / 16;
this->playerViewRect->updateLocation(x, y);
this->cursorMapTileRect->updateLocation(x, y);
if (map_edit_mode == "paint") {
if (event->buttons() & Qt::RightButton) {
item->updateMovementPermissionSelection(event);
@ -527,6 +534,8 @@ void Editor::displayMap() {
if (map_item && scene) {
scene->removeItem(map_item);
delete map_item;
scene->removeItem(this->playerViewRect);
scene->removeItem(this->cursorMapTileRect);
}
displayMetatileSelector();
@ -539,8 +548,11 @@ void Editor::displayMap() {
displayMapConnections();
displayMapBorder();
displayMapGrid();
this->playerViewRect->setZValue(1000);
this->cursorMapTileRect->setZValue(1001);
scene->addItem(this->playerViewRect);
scene->addItem(this->cursorMapTileRect);
if (map_item) {
map_item->setVisible(false);
@ -1071,6 +1083,7 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
int x = static_cast<int>(mouse->pos().x() + this->pos().x()) / 16;
int y = static_cast<int>(mouse->pos().y() + this->pos().y()) / 16;
this->editor->playerViewRect->updateLocation(x, y);
this->editor->cursorMapTileRect->updateLocation(x, y);
if (x != last_x || y != last_y) {
if (editor->selected_events->contains(this)) {
for (DraggablePixmapItem *item : *editor->selected_events) {

View file

@ -205,6 +205,10 @@ void MainWindow::on_lineEdit_filterBox_textChanged(const QString &arg1)
void MainWindow::loadUserSettings() {
ui->actionBetter_Cursors->setChecked(porymapConfig.getPrettyCursors());
this->editor->settings->betterCursors = porymapConfig.getPrettyCursors();
ui->actionPlayer_View_Rectangle->setChecked(porymapConfig.getShowPlayerView());
this->editor->settings->playerViewRectEnabled = porymapConfig.getShowPlayerView();
ui->actionCursor_Tile_Outline->setChecked(porymapConfig.getShowCursorTile());
this->editor->settings->cursorTileRectEnabled = porymapConfig.getShowCursorTile();
mapSortOrder = porymapConfig.getMapSortOrder();
ui->horizontalSlider_CollisionTransparency->blockSignals(true);
this->editor->collisionOpacity = static_cast<qreal>(porymapConfig.getCollisionOpacity()) / 100;
@ -972,7 +976,16 @@ void MainWindow::on_actionBetter_Cursors_triggered() {
void MainWindow::on_actionPlayer_View_Rectangle_triggered()
{
this->editor->settings->playerViewRectEnabled = ui->actionPlayer_View_Rectangle->isChecked();
bool enabled = ui->actionPlayer_View_Rectangle->isChecked();
porymapConfig.setShowPlayerView(enabled);
this->editor->settings->playerViewRectEnabled = enabled;
}
void MainWindow::on_actionCursor_Tile_Outline_triggered()
{
bool enabled = ui->actionCursor_Tile_Outline->isChecked();
porymapConfig.setShowCursorTile(enabled);
this->editor->settings->cursorTileRectEnabled = enabled;
}
void MainWindow::on_actionPencil_triggered()

View file

@ -5,4 +5,5 @@ Settings::Settings()
this->smartPathsEnabled = false;
this->betterCursors = true;
this->playerViewRectEnabled = false;
this->cursorTileRectEnabled = true;
}

17
src/ui/movablerect.cpp Normal file
View file

@ -0,0 +1,17 @@
#include "movablerect.h"
MovableRect::MovableRect(bool *enabled, int width, int height, QRgb color)
{
this->enabled = enabled;
this->width = width;
this->height = height;
this->color = color;
this->setVisible(*enabled);
}
void MovableRect::updateLocation(int x, int y)
{
this->setX((x * 16) - this->width / 2 + 8);
this->setY((y * 16) - this->height / 2 + 8);
this->setVisible(*this->enabled);
}

View file

@ -1,14 +0,0 @@
#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);
}