Implement straight paths for map tiles and smart paths
This commit is contained in:
parent
6a9088c4ea
commit
5da761ea94
8 changed files with 89 additions and 7 deletions
|
@ -181,6 +181,7 @@ private slots:
|
||||||
void onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
void onMapStartPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
void onMapEndPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
void onMapEndPaint(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
void setSmartPathCursorMode(QGraphicsSceneMouseEvent *event);
|
void setSmartPathCursorMode(QGraphicsSceneMouseEvent *event);
|
||||||
|
void setStraightPathCursorMode(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
||||||
void onConnectionMoved(MapConnection*);
|
void onConnectionMoved(MapConnection*);
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Settings
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings();
|
||||||
bool smartPathsEnabled;
|
bool smartPathsEnabled;
|
||||||
|
bool straightPathsEnabled;
|
||||||
bool betterCursors;
|
bool betterCursors;
|
||||||
QCursor mapCursor;
|
QCursor mapCursor;
|
||||||
bool playerViewRectEnabled;
|
bool playerViewRectEnabled;
|
||||||
|
|
|
@ -52,6 +52,8 @@ public:
|
||||||
void stopRightClickSelectionAnchor();
|
void stopRightClickSelectionAnchor();
|
||||||
void setSmartPathMode();
|
void setSmartPathMode();
|
||||||
bool getSmartPathMode() { return this->smartPathMode; }
|
bool getSmartPathMode() { return this->smartPathMode; }
|
||||||
|
void setStraightPathMode();
|
||||||
|
bool getStraightPathMode() { return this->straightPathMode; }
|
||||||
void setSingleTileMode();
|
void setSingleTileMode();
|
||||||
void stopSingleTileMode();
|
void stopSingleTileMode();
|
||||||
void setNormalPathMode();
|
void setNormalPathMode();
|
||||||
|
@ -66,6 +68,7 @@ private:
|
||||||
bool anchored;
|
bool anchored;
|
||||||
bool rightClickSelectionAnchored;
|
bool rightClickSelectionAnchored;
|
||||||
bool smartPathMode;
|
bool smartPathMode;
|
||||||
|
bool straightPathMode;
|
||||||
bool singleTileMode;
|
bool singleTileMode;
|
||||||
int anchorCoordX;
|
int anchorCoordX;
|
||||||
int anchorCoordY;
|
int anchorCoordY;
|
||||||
|
@ -73,6 +76,7 @@ private:
|
||||||
int selectionHeight;
|
int selectionHeight;
|
||||||
QRgb color;
|
QRgb color;
|
||||||
bool smartPathInEffect();
|
bool smartPathInEffect();
|
||||||
|
bool straightPathInEffect();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ public:
|
||||||
this->metatileSelector = metatileSelector;
|
this->metatileSelector = metatileSelector;
|
||||||
this->settings = settings;
|
this->settings = settings;
|
||||||
this->paintingMode = PaintMode::Metatiles;
|
this->paintingMode = PaintMode::Metatiles;
|
||||||
|
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
MapPixmapItem::PaintMode paintingMode;
|
MapPixmapItem::PaintMode paintingMode;
|
||||||
|
@ -34,6 +35,13 @@ public:
|
||||||
bool right_click;
|
bool right_click;
|
||||||
int paint_tile_initial_x;
|
int paint_tile_initial_x;
|
||||||
int paint_tile_initial_y;
|
int paint_tile_initial_y;
|
||||||
|
bool straightPathMode;
|
||||||
|
enum Axis {
|
||||||
|
None = 0,
|
||||||
|
X,
|
||||||
|
Y
|
||||||
|
};
|
||||||
|
MapPixmapItem::Axis lockedAxis;
|
||||||
QPoint selection_origin;
|
QPoint selection_origin;
|
||||||
QList<QPoint> selection;
|
QList<QPoint> selection;
|
||||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||||
|
@ -64,6 +72,8 @@ public:
|
||||||
virtual void draw(bool ignoreCache = false);
|
virtual void draw(bool ignoreCache = false);
|
||||||
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
|
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
|
||||||
void paintNormal(int x, int y, bool fromScriptCall = false);
|
void paintNormal(int x, int y, bool fromScriptCall = false);
|
||||||
|
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
|
||||||
|
int adjustCoord(int coord, MapPixmapItem::Axis axis);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintSmartPath(int x, int y, bool fromScriptCall = false);
|
void paintSmartPath(int x, int y, bool fromScriptCall = false);
|
||||||
|
|
|
@ -938,7 +938,7 @@ void Editor::onHoveredMapMovementPermissionCleared() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation){
|
QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation) {
|
||||||
QString message;
|
QString message;
|
||||||
if (collision == 0 && elevation == 0) {
|
if (collision == 0 && elevation == 0) {
|
||||||
message = "Collision: Transition between elevations";
|
message = "Collision: Transition between elevations";
|
||||||
|
@ -1009,24 +1009,31 @@ 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) {
|
||||||
this->cursorMapTileRect->setSmartPathMode();
|
this->cursorMapTileRect->setSmartPathMode(true);
|
||||||
} else {
|
} else {
|
||||||
this->cursorMapTileRect->setNormalPathMode();
|
this->cursorMapTileRect->setSmartPathMode(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (shiftPressed) {
|
if (shiftPressed) {
|
||||||
this->cursorMapTileRect->setSmartPathMode();
|
this->cursorMapTileRect->setSmartPathMode(true);
|
||||||
} else {
|
} else {
|
||||||
this->cursorMapTileRect->setNormalPathMode();
|
this->cursorMapTileRect->setSmartPathMode(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::setStraightPathCursorMode(QGraphicsSceneMouseEvent *event) {
|
||||||
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
|
this->cursorMapTileRect->setStraightPathMode(true);
|
||||||
|
} else {
|
||||||
|
this->cursorMapTileRect->setStraightPathMode(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
|
||||||
// TODO: add event tab object painting tool buttons stuff here
|
// TODO: add event tab object painting tool buttons stuff here
|
||||||
if (item->paintingMode == MapPixmapItem::PaintMode::Disabled) {
|
if (item->paintingMode == MapPixmapItem::PaintMode::Disabled) {
|
||||||
|
@ -1048,6 +1055,12 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
||||||
item->floodFill(event);
|
item->floodFill(event);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
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);
|
this->setSmartPathCursorMode(event);
|
||||||
item->paint(event);
|
item->paint(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
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;
|
||||||
|
|
|
@ -9,6 +9,7 @@ CursorTileRect::CursorTileRect(bool *enabled, QRgb color)
|
||||||
this->width = 16;
|
this->width = 16;
|
||||||
this->height = 16;
|
this->height = 16;
|
||||||
this->smartPathMode = false;
|
this->smartPathMode = false;
|
||||||
|
this->straightPathMode = false;
|
||||||
this->singleTileMode = false;
|
this->singleTileMode = false;
|
||||||
this->anchored = false;
|
this->anchored = false;
|
||||||
this->rightClickSelectionAnchored = false;
|
this->rightClickSelectionAnchored = false;
|
||||||
|
@ -62,6 +63,11 @@ void CursorTileRect::setSmartPathMode()
|
||||||
this->smartPathMode = true;
|
this->smartPathMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CursorTileRect::setStraightPathMode()
|
||||||
|
{
|
||||||
|
this->straightPathMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
void CursorTileRect::setSingleTileMode()
|
void CursorTileRect::setSingleTileMode()
|
||||||
{
|
{
|
||||||
this->singleTileMode = true;
|
this->singleTileMode = true;
|
||||||
|
@ -75,6 +81,7 @@ void CursorTileRect::stopSingleTileMode()
|
||||||
void CursorTileRect::setNormalPathMode()
|
void CursorTileRect::setNormalPathMode()
|
||||||
{
|
{
|
||||||
this->smartPathMode = false;
|
this->smartPathMode = false;
|
||||||
|
this->straightPathMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CursorTileRect::smartPathInEffect()
|
bool CursorTileRect::smartPathInEffect()
|
||||||
|
@ -82,6 +89,11 @@ 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) {
|
||||||
|
|
|
@ -14,6 +14,19 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
int x = static_cast<int>(pos.x()) / 16;
|
int x = static_cast<int>(pos.x()) / 16;
|
||||||
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
|
||||||
|
bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier;
|
||||||
|
if (this->settings->straightPathsEnabled || straightPathsEnabled) {
|
||||||
|
this->straightPathMode = true;
|
||||||
|
} else {
|
||||||
|
this->straightPathMode = false;
|
||||||
|
}
|
||||||
|
if (this->straightPathMode) {
|
||||||
|
this->lockNondominantAxis(event);
|
||||||
|
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
|
||||||
|
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
|
||||||
|
}
|
||||||
|
|
||||||
// Paint onto the map.
|
// Paint onto the map.
|
||||||
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
|
||||||
QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions();
|
QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions();
|
||||||
|
@ -259,6 +272,32 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) {
|
||||||
|
// Return if an axis is already locked
|
||||||
|
if (this->lockedAxis != MapPixmapItem::Axis::None) return;
|
||||||
|
|
||||||
|
QPointF pos = event->pos();
|
||||||
|
int xDiff = (static_cast<int>(pos.x()) / 16) - this->paint_tile_initial_x;
|
||||||
|
int yDiff = (static_cast<int>(pos.y()) / 16) - this->paint_tile_initial_y;
|
||||||
|
|
||||||
|
// Only lock an axis when the current pos != initial and not after the mouse gets released
|
||||||
|
if ((xDiff || yDiff) && event->type() != QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
if (abs(xDiff) < abs(yDiff))
|
||||||
|
this->lockedAxis = MapPixmapItem::Axis::X;
|
||||||
|
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)
|
||||||
|
coord = this->paint_tile_initial_x;
|
||||||
|
else if (axis == MapPixmapItem::Axis::Y && this->lockedAxis == MapPixmapItem::Axis::Y)
|
||||||
|
coord = this->paint_tile_initial_y;
|
||||||
|
return coord;
|
||||||
|
}
|
||||||
|
|
||||||
void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int x = static_cast<int>(pos.x()) / 16;
|
int x = static_cast<int>(pos.x()) / 16;
|
||||||
|
@ -711,6 +750,7 @@ void MapPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void MapPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||||
emit endPaint(event, this);
|
emit endPaint(event, this);
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue