Remove straight paths checkbox and refactor
This commit is contained in:
parent
de2246e2fd
commit
2fd3df9734
10 changed files with 19 additions and 66 deletions
|
@ -626,22 +626,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="checkBox_straightPaths">
|
|
||||||
<property name="layoutDirection">
|
|
||||||
<enum>Qt::LeftToRight</enum>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true"/>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Straight Paths</string>
|
|
||||||
</property>
|
|
||||||
<property name="tristate">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox_ToggleGrid">
|
<widget class="QCheckBox" name="checkBox_ToggleGrid">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
|
|
|
@ -100,8 +100,6 @@ public:
|
||||||
Q_INVOKABLE bool getBorderVisibility();
|
Q_INVOKABLE bool getBorderVisibility();
|
||||||
Q_INVOKABLE void setSmartPathsEnabled(bool visible);
|
Q_INVOKABLE void setSmartPathsEnabled(bool visible);
|
||||||
Q_INVOKABLE bool getSmartPathsEnabled();
|
Q_INVOKABLE bool getSmartPathsEnabled();
|
||||||
Q_INVOKABLE void setStraightPathsEnabled(bool visible);
|
|
||||||
Q_INVOKABLE bool getStraightPathsEnabled();
|
|
||||||
Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = "");
|
Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = "");
|
||||||
Q_INVOKABLE void setTimeout(QJSValue callback, int milliseconds);
|
Q_INVOKABLE void setTimeout(QJSValue callback, int milliseconds);
|
||||||
void invokeCallback(QJSValue callback);
|
void invokeCallback(QJSValue callback);
|
||||||
|
@ -203,7 +201,6 @@ private slots:
|
||||||
void on_comboBox_SecondaryTileset_currentTextChanged(const QString &arg1);
|
void on_comboBox_SecondaryTileset_currentTextChanged(const QString &arg1);
|
||||||
void on_pushButton_ChangeDimensions_clicked();
|
void on_pushButton_ChangeDimensions_clicked();
|
||||||
void on_checkBox_smartPaths_stateChanged(int selected);
|
void on_checkBox_smartPaths_stateChanged(int selected);
|
||||||
void on_checkBox_straightPaths_stateChanged(int selected);
|
|
||||||
void on_checkBox_Visibility_clicked(bool checked);
|
void on_checkBox_Visibility_clicked(bool checked);
|
||||||
void on_checkBox_ToggleBorder_stateChanged(int arg1);
|
void on_checkBox_ToggleBorder_stateChanged(int arg1);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ class Settings
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings();
|
||||||
bool smartPathsEnabled;
|
bool smartPathsEnabled;
|
||||||
bool straightPathsEnabled;
|
|
||||||
bool betterCursors;
|
bool betterCursors;
|
||||||
QCursor mapCursor;
|
QCursor mapCursor;
|
||||||
bool playerViewRectEnabled;
|
bool playerViewRectEnabled;
|
||||||
|
|
|
@ -50,13 +50,12 @@ public:
|
||||||
void stopAnchor();
|
void stopAnchor();
|
||||||
void initRightClickSelectionAnchor(int coordX, int coordY);
|
void initRightClickSelectionAnchor(int coordX, int coordY);
|
||||||
void stopRightClickSelectionAnchor();
|
void stopRightClickSelectionAnchor();
|
||||||
void setSmartPathMode();
|
void setSmartPathMode(bool enable);
|
||||||
bool getSmartPathMode() { return this->smartPathMode; }
|
bool getSmartPathMode() { return this->smartPathMode; }
|
||||||
void setStraightPathMode();
|
void setStraightPathMode(bool enable);
|
||||||
bool getStraightPathMode() { return this->straightPathMode; }
|
bool getStraightPathMode() { return this->straightPathMode; }
|
||||||
void setSingleTileMode();
|
void setSingleTileMode();
|
||||||
void stopSingleTileMode();
|
void stopSingleTileMode();
|
||||||
void setNormalPathMode();
|
|
||||||
void updateLocation(int x, int y);
|
void updateLocation(int x, int y);
|
||||||
void updateSelectionSize(int width, int height);
|
void updateSelectionSize(int width, int height);
|
||||||
void setVisibility(bool visible);
|
void setVisibility(bool visible);
|
||||||
|
@ -76,7 +75,6 @@ private:
|
||||||
int selectionHeight;
|
int selectionHeight;
|
||||||
QRgb color;
|
QRgb color;
|
||||||
bool smartPathInEffect();
|
bool smartPathInEffect();
|
||||||
bool straightPathInEffect();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1009,7 +1009,8 @@ void Editor::onMapEndPaint(QGraphicsSceneMouseEvent *, MapPixmapItem *item) {
|
||||||
this->cursorMapTileRect->stopAnchor();
|
this->cursorMapTileRect->stopAnchor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setSmartPathCursorMode(QGraphicsSceneMouseEvent *event) {
|
void Editor::setSmartPathCursorMode(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
||||||
if (settings->smartPathsEnabled) {
|
if (settings->smartPathsEnabled) {
|
||||||
if (!shiftPressed) {
|
if (!shiftPressed) {
|
||||||
|
@ -1055,13 +1056,13 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
||||||
item->floodFill(event);
|
item->floodFill(event);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
this->setSmartPathCursorMode(event);
|
||||||
this->setStraightPathCursorMode(event);
|
this->setStraightPathCursorMode(event);
|
||||||
if (this->cursorMapTileRect->getStraightPathMode()) {
|
if (this->cursorMapTileRect->getStraightPathMode()) {
|
||||||
item->lockNondominantAxis(event);
|
item->lockNondominantAxis(event);
|
||||||
x = item->adjustCoord(x, MapPixmapItem::Axis::X);
|
x = item->adjustCoord(x, MapPixmapItem::Axis::X);
|
||||||
y = item->adjustCoord(y, MapPixmapItem::Axis::Y);
|
y = item->adjustCoord(y, MapPixmapItem::Axis::Y);
|
||||||
}
|
}
|
||||||
this->setSmartPathCursorMode(event);
|
|
||||||
item->paint(event);
|
item->paint(event);
|
||||||
}
|
}
|
||||||
} else if (map_edit_mode == "select") {
|
} else if (map_edit_mode == "select") {
|
||||||
|
|
|
@ -2492,18 +2492,12 @@ void MainWindow::on_checkBox_smartPaths_stateChanged(int selected)
|
||||||
bool enabled = selected == Qt::Checked;
|
bool enabled = selected == Qt::Checked;
|
||||||
editor->settings->smartPathsEnabled = enabled;
|
editor->settings->smartPathsEnabled = enabled;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
editor->cursorMapTileRect->setSmartPathMode();
|
editor->cursorMapTileRect->setSmartPathMode(true);
|
||||||
} else {
|
} 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)
|
void MainWindow::on_checkBox_ToggleBorder_stateChanged(int selected)
|
||||||
{
|
{
|
||||||
bool visible = selected != 0;
|
bool visible = selected != 0;
|
||||||
|
|
|
@ -476,14 +476,6 @@ bool MainWindow::getSmartPathsEnabled() {
|
||||||
return this->ui->checkBox_smartPaths->isChecked();
|
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) {
|
void MainWindow::registerAction(QString functionName, QString actionName, QString shortcut) {
|
||||||
if (!this->ui || !this->ui->menuTools)
|
if (!this->ui || !this->ui->menuTools)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
this->smartPathsEnabled = false;
|
this->smartPathsEnabled = false;
|
||||||
this->straightPathsEnabled = false;
|
|
||||||
this->betterCursors = true;
|
this->betterCursors = true;
|
||||||
this->playerViewRectEnabled = false;
|
this->playerViewRectEnabled = false;
|
||||||
this->cursorTileRectEnabled = true;
|
this->cursorTileRectEnabled = true;
|
||||||
|
|
|
@ -58,14 +58,14 @@ void CursorTileRect::updateSelectionSize(int width, int height)
|
||||||
this->update();
|
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()
|
void CursorTileRect::setSingleTileMode()
|
||||||
|
@ -78,22 +78,11 @@ void CursorTileRect::stopSingleTileMode()
|
||||||
this->singleTileMode = false;
|
this->singleTileMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CursorTileRect::setNormalPathMode()
|
|
||||||
{
|
|
||||||
this->smartPathMode = false;
|
|
||||||
this->straightPathMode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CursorTileRect::smartPathInEffect()
|
bool CursorTileRect::smartPathInEffect()
|
||||||
{
|
{
|
||||||
return !this->rightClickSelectionAnchored && this->smartPathMode && this->selectionHeight == 3 && this->selectionWidth == 3;
|
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)
|
void CursorTileRect::updateLocation(int coordX, int coordY)
|
||||||
{
|
{
|
||||||
if (!this->singleTileMode) {
|
if (!this->singleTileMode) {
|
||||||
|
|
|
@ -15,8 +15,7 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
int y = static_cast<int>(pos.y()) / 16;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
|
|
||||||
// Set straight paths on/off and snap to the dominant axis when on
|
// Set straight paths on/off and snap to the dominant axis when on
|
||||||
bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier;
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
if (this->settings->straightPathsEnabled || straightPathsEnabled) {
|
|
||||||
this->lockNondominantAxis(event);
|
this->lockNondominantAxis(event);
|
||||||
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
|
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
|
||||||
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
|
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
|
||||||
|
@ -55,8 +54,7 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
|
||||||
int y = static_cast<int>(pos.y()) / 16;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
|
|
||||||
// Set straight paths on/off and snap to the dominant axis when on
|
// Set straight paths on/off and snap to the dominant axis when on
|
||||||
bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier;
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
if (this->settings->straightPathsEnabled || straightPathsEnabled) {
|
|
||||||
this->lockNondominantAxis(event);
|
this->lockNondominantAxis(event);
|
||||||
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
|
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
|
||||||
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
|
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 xDiff = x - this->straight_path_initial_x;
|
||||||
int yDiff = y - this->straight_path_initial_y;
|
int yDiff = y - this->straight_path_initial_y;
|
||||||
if ((xDiff || yDiff) && event->type() != QEvent::GraphicsSceneMouseRelease) {
|
if ((xDiff || yDiff) && event->type() != QEvent::GraphicsSceneMouseRelease) {
|
||||||
if (abs(xDiff) < abs(yDiff))
|
if (abs(xDiff) < abs(yDiff)) {
|
||||||
this->lockedAxis = MapPixmapItem::Axis::X;
|
this->lockedAxis = MapPixmapItem::Axis::X;
|
||||||
else
|
} else {
|
||||||
this->lockedAxis = MapPixmapItem::Axis::Y;
|
this->lockedAxis = MapPixmapItem::Axis::Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust the cooresponding coordinate when it is locked
|
// Adjust the cooresponding coordinate when it is locked
|
||||||
int MapPixmapItem::adjustCoord(int coord, MapPixmapItem::Axis axis) {
|
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;
|
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;
|
coord = this->straight_path_initial_y;
|
||||||
|
}
|
||||||
return coord;
|
return coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue