Fix collision straight paths and general improvement
This commit is contained in:
parent
b8bbfe60e8
commit
27c9fec0b4
3 changed files with 34 additions and 16 deletions
|
@ -25,6 +25,7 @@ public:
|
||||||
this->settings = settings;
|
this->settings = settings;
|
||||||
this->paintingMode = PaintMode::Metatiles;
|
this->paintingMode = PaintMode::Metatiles;
|
||||||
this->lockedAxis = MapPixmapItem::Axis::None;
|
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||||
|
this->prevStraightPathState = false;
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
}
|
}
|
||||||
MapPixmapItem::PaintMode paintingMode;
|
MapPixmapItem::PaintMode paintingMode;
|
||||||
|
@ -36,6 +37,9 @@ public:
|
||||||
int paint_tile_initial_x;
|
int paint_tile_initial_x;
|
||||||
int paint_tile_initial_y;
|
int paint_tile_initial_y;
|
||||||
bool straightPathMode;
|
bool straightPathMode;
|
||||||
|
bool prevStraightPathState;
|
||||||
|
int straight_path_initial_x;
|
||||||
|
int straight_path_initial_y;
|
||||||
enum Axis {
|
enum Axis {
|
||||||
None = 0,
|
None = 0,
|
||||||
X,
|
X,
|
||||||
|
|
|
@ -9,23 +9,27 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
setCursor(this->settings->mapCursor);
|
setCursor(this->settings->mapCursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||||
emit this->hoveredMapMovementPermissionCleared();
|
emit this->hoveredMapMovementPermissionCleared();
|
||||||
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles){
|
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles){
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
void CollisionPixmapItem::mousePressEvent(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;
|
||||||
int y = static_cast<int>(pos.y()) / 16;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
this->paint_tile_initial_x = x;
|
this->paint_tile_initial_x = this->straight_path_initial_x = x;
|
||||||
this->paint_tile_initial_y = y;
|
this->paint_tile_initial_y = this->straight_path_initial_y = y;
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
this->lockedAxis = CollisionPixmapItem::Axis::None;
|
this->lockedAxis = CollisionPixmapItem::Axis::None;
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
|
@ -49,16 +53,13 @@ void CollisionPixmapItem::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->straightPathMode = true;
|
|
||||||
} else {
|
|
||||||
this->straightPathMode = false;
|
|
||||||
}
|
|
||||||
if (this->straightPathMode) {
|
|
||||||
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);
|
||||||
|
} else {
|
||||||
|
this->prevStraightPathState = false;
|
||||||
|
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block *block = map->getBlock(x, y);
|
Block *block = map->getBlock(x, y);
|
||||||
|
|
|
@ -20,6 +20,8 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
this->straightPathMode = true;
|
this->straightPathMode = true;
|
||||||
} else {
|
} else {
|
||||||
this->straightPathMode = false;
|
this->straightPathMode = false;
|
||||||
|
this->prevStraightPathState = false;
|
||||||
|
this->lockedAxis = MapPixmapItem::Axis::None;
|
||||||
}
|
}
|
||||||
if (this->straightPathMode) {
|
if (this->straightPathMode) {
|
||||||
this->lockNondominantAxis(event);
|
this->lockNondominantAxis(event);
|
||||||
|
@ -290,10 +292,21 @@ void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) {
|
||||||
if (this->lockedAxis != MapPixmapItem::Axis::None) return;
|
if (this->lockedAxis != MapPixmapItem::Axis::None) return;
|
||||||
|
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int xDiff = (static_cast<int>(pos.x()) / 16) - this->paint_tile_initial_x;
|
int x = static_cast<int>(pos.x()) / 16;
|
||||||
int yDiff = (static_cast<int>(pos.y()) / 16) - this->paint_tile_initial_y;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
|
if (event->modifiers() & Qt::ControlModifier) {
|
||||||
|
if (!this->prevStraightPathState) {
|
||||||
|
this->prevStraightPathState = true;
|
||||||
|
this->straight_path_initial_x = x;
|
||||||
|
this->straight_path_initial_y = y;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this->prevStraightPathState = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Only lock an axis when the current pos != initial and not after the mouse gets released
|
// Only lock an axis when the current pos != initial and not after the mouse gets released
|
||||||
|
int xDiff = x - this->straight_path_initial_x;
|
||||||
|
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;
|
||||||
|
@ -305,9 +318,9 @@ void MapPixmapItem::lockNondominantAxis(QGraphicsSceneMouseEvent *event) {
|
||||||
// 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->paint_tile_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->paint_tile_initial_y;
|
coord = this->straight_path_initial_y;
|
||||||
return coord;
|
return coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,8 +764,8 @@ void MapPixmapItem::mousePressEvent(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;
|
||||||
int y = static_cast<int>(pos.y()) / 16;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
this->paint_tile_initial_x = x;
|
this->paint_tile_initial_x = this->straight_path_initial_x = x;
|
||||||
this->paint_tile_initial_y = y;
|
this->paint_tile_initial_y = this->straight_path_initial_y = y;
|
||||||
emit startPaint(event, this);
|
emit startPaint(event, this);
|
||||||
emit mouseEvent(event, this);
|
emit mouseEvent(event, this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue