fix blueprint rotation bug
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -936,7 +937,17 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
for (BlueprintBuilding& bb : m_blueprintMode->buildings)
|
||||
{
|
||||
bb.offset = QPoint(-bb.offset.y(), bb.offset.x());
|
||||
const BuildingDef* def = findBuildingDef(bb.type);
|
||||
if (!def) { continue; }
|
||||
const ParsedSurfaceMask mask = parseSurfaceMask(def->surfaceMask, bb.rotation);
|
||||
int minX = INT_MAX, minY = INT_MAX;
|
||||
for (const QPoint& cell : mask.bodyCells)
|
||||
{
|
||||
const QPoint abs = bb.offset + cell;
|
||||
minX = std::min(minX, -abs.y());
|
||||
minY = std::min(minY, abs.x());
|
||||
}
|
||||
bb.offset = QPoint(minX, minY);
|
||||
bb.rotation = rotateClockwise(bb.rotation);
|
||||
}
|
||||
}
|
||||
@@ -951,7 +962,17 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
for (BlueprintBuilding& bb : m_blueprintMode->buildings)
|
||||
{
|
||||
bb.offset = QPoint(bb.offset.y(), -bb.offset.x());
|
||||
const BuildingDef* def = findBuildingDef(bb.type);
|
||||
if (!def) { continue; }
|
||||
const ParsedSurfaceMask mask = parseSurfaceMask(def->surfaceMask, bb.rotation);
|
||||
int minX = INT_MAX, minY = INT_MAX;
|
||||
for (const QPoint& cell : mask.bodyCells)
|
||||
{
|
||||
const QPoint abs = bb.offset + cell;
|
||||
minX = std::min(minX, abs.y());
|
||||
minY = std::min(minY, -abs.x());
|
||||
}
|
||||
bb.offset = QPoint(minX, minY);
|
||||
bb.rotation = rotateCounterClockwise(bb.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user