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

@@ -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);
}