Remove straight paths checkbox and refactor

This commit is contained in:
BigBahss
2020-08-25 16:32:40 -04:00
committed by garak
parent de2246e2fd
commit 2fd3df9734
10 changed files with 19 additions and 66 deletions

View File

@@ -1009,7 +1009,8 @@ void Editor::onMapEndPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *item) {
this->cursorMapTileRect->stopAnchor();
}
void Editor::setSmartPathCursorMode(QGraphicsSceneMouseEvent *event) {
void Editor::setSmartPathCursorMode(QGraphicsSceneMouseEvent *event)
{
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
if (settings->smartPathsEnabled) {
if (!shiftPressed) {
@@ -1055,13 +1056,13 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
item->floodFill(event);
}
} else {
this->setSmartPathCursorMode(event);
this->setStraightPathCursorMode(event);
if (this->cursorMapTileRect->getStraightPathMode()) {
item->lockNondominantAxis(event);
x = item->adjustCoord(x, MapPixmapItem::Axis::X);
y = item->adjustCoord(y, MapPixmapItem::Axis::Y);
}
this->setSmartPathCursorMode(event);
item->paint(event);
}
} else if (map_edit_mode == "select") {

View File

@@ -2492,18 +2492,12 @@ void MainWindow::on_checkBox_smartPaths_stateChanged(int selected)
bool enabled = selected == Qt::Checked;
editor->settings->smartPathsEnabled = enabled;
if (enabled) {
editor->cursorMapTileRect->setSmartPathMode();
editor->cursorMapTileRect->setSmartPathMode(true);
} else {
editor->cursorMapTileRect->setNormalPathMode();
editor->cursorMapTileRect->setSmartPathMode(false);
}
}
void MainWindow::on_checkBox_straightPaths_stateChanged(int selected)
{
bool enabled = selected == Qt::Checked;
editor->settings->straightPathsEnabled = enabled;
}
void MainWindow::on_checkBox_ToggleBorder_stateChanged(int selected)
{
bool visible = selected != 0;

View File

@@ -476,14 +476,6 @@ bool MainWindow::getSmartPathsEnabled() {
return this->ui->checkBox_smartPaths->isChecked();
}
void MainWindow::setStraightPathsEnabled(bool visible) {
this->ui->checkBox_straightPaths->setChecked(visible);
}
bool MainWindow::getStraightPathsEnabled() {
return this->ui->checkBox_straightPaths->isChecked();
}
void MainWindow::registerAction(QString functionName, QString actionName, QString shortcut) {
if (!this->ui || !this->ui->menuTools)
return;

View File

@@ -3,7 +3,6 @@
Settings::Settings()
{
this->smartPathsEnabled = false;
this->straightPathsEnabled = false;
this->betterCursors = true;
this->playerViewRectEnabled = false;
this->cursorTileRectEnabled = true;

View File

@@ -58,14 +58,14 @@ void CursorTileRect::updateSelectionSize(int width, int height)
this->update();
}
void CursorTileRect::setSmartPathMode()
void CursorTileRect::setSmartPathMode(bool enable)
{
this->smartPathMode = true;
this->smartPathMode = enable;
}
void CursorTileRect::setStraightPathMode()
void CursorTileRect::setStraightPathMode(bool enable)
{
this->straightPathMode = true;
this->straightPathMode = enable;
}
void CursorTileRect::setSingleTileMode()
@@ -78,22 +78,11 @@ void CursorTileRect::stopSingleTileMode()
this->singleTileMode = false;
}
void CursorTileRect::setNormalPathMode()
{
this->smartPathMode = false;
this->straightPathMode = false;
}
bool CursorTileRect::smartPathInEffect()
{
return !this->rightClickSelectionAnchored && this->smartPathMode && this->selectionHeight == 3 && this->selectionWidth == 3;
}
bool CursorTileRect::straightPathInEffect()
{
return !this->rightClickSelectionAnchored && this->straightPathMode;
}
void CursorTileRect::updateLocation(int coordX, int coordY)
{
if (!this->singleTileMode) {

View File

@@ -15,8 +15,7 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
int y = static_cast<int>(pos.y()) / 16;
// Set straight paths on/off and snap to the dominant axis when on
bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier;
if (this->settings->straightPathsEnabled || straightPathsEnabled) {
if (event->modifiers() & Qt::ControlModifier) {
this->lockNondominantAxis(event);
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
@@ -55,8 +54,7 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
int y = static_cast<int>(pos.y()) / 16;
// Set straight paths on/off and snap to the dominant axis when on
bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier;
if (this->settings->straightPathsEnabled || straightPathsEnabled) {
if (event->modifiers() & Qt::ControlModifier) {
this->lockNondominantAxis(event);
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
@@ -302,19 +300,21 @@ void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) {
int xDiff = x - this->straight_path_initial_x;
int yDiff = y - this->straight_path_initial_y;
if ((xDiff || yDiff) && event->type() != QEvent::GraphicsSceneMouseRelease) {
if (abs(xDiff) < abs(yDiff))
if (abs(xDiff) < abs(yDiff)) {
this->lockedAxis = MapPixmapItem::Axis::X;
else
} else {
this->lockedAxis = MapPixmapItem::Axis::Y;
}
}
}
// Adjust the cooresponding coordinate when it is locked
int MapPixmapItem::adjustCoord(int coord, MapPixmapItem::Axis axis) {
if (axis == MapPixmapItem::Axis::X && this->lockedAxis == MapPixmapItem::Axis::X)
if (axis == MapPixmapItem::Axis::X && this->lockedAxis == MapPixmapItem::Axis::X) {
coord = this->straight_path_initial_x;
else if (axis == MapPixmapItem::Axis::Y && this->lockedAxis == MapPixmapItem::Axis::Y)
} else if (axis == MapPixmapItem::Axis::Y && this->lockedAxis == MapPixmapItem::Axis::Y) {
coord = this->straight_path_initial_y;
}
return coord;
}