Add player view rectangle option

This commit is contained in:
Marcus Huderle
2019-01-08 18:04:48 -06:00
parent 3f88072981
commit 4d088766a0
13 changed files with 115 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ 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);
}
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<int>(pos.x()) / 16;
int y = static_cast<int>(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<int>(pos.x()) / 16;
int y = static_cast<int>(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<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);
if (x != last_x || y != last_y) {
if (editor->selected_events->contains(this)) {
for (DraggablePixmapItem *item : *editor->selected_events) {

View File

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

View File

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

View File

@@ -4,13 +4,13 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
int x = static_cast<int>(event->pos().x()) / 16;
int y = static_cast<int>(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();
}
}

View File

@@ -499,13 +499,13 @@ void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
int x = static_cast<int>(event->pos().x()) / 16;
int y = static_cast<int>(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();
}
}

14
src/ui/playerviewrect.cpp Normal file
View 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);
}