Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit b4b54f5

Browse files
committed
Force bounds on the Constructor cursor
1 parent 309f1c3 commit b4b54f5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Base.rte/Devices/Tools/Constructor/Constructor.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function Create(self)
124124
self.toAutoBuild = false;
125125
self.operatedByAI = false;
126126
self.cursorMoveSpeed = 2;
127+
self.maxCursorDist = Vector(FrameMan.PlayerScreenWidth * 0.5 - 6, FrameMan.PlayerScreenHeight * 0.5 - 6);
127128

128129
-- autobuild for standard units
129130
self.autoBuildList = {
@@ -426,8 +427,6 @@ function Update(self)
426427
end
427428

428429
if self.cursor then
429-
430-
actor.ViewPoint = self.cursor;
431430

432431
local cursorMovement = Vector();
433432
local mouseControlled = ctrl:IsMouseControlled();
@@ -472,6 +471,14 @@ function Update(self)
472471
PrimitiveMan:DrawLinePrimitive(screen, self.cursor + Vector(4, 0), self.cursor + Vector(-4, 0), displayColorYellow);
473472
end
474473
PrimitiveMan:DrawBoxPrimitive(screen, map, map + Vector(self.blockSize - 1, self.blockSize - 1), displayColorYellow);
474+
475+
local dist = SceneMan:ShortestDistance(actor.ViewPoint, self.cursor, SceneMan.SceneWrapsX);
476+
if math.abs(dist.X) > self.maxCursorDist.X then
477+
self.cursor.X = actor.ViewPoint.X + self.maxCursorDist.X * (dist.X < 0 and -1 or 1);
478+
end
479+
if math.abs(dist.Y) > self.maxCursorDist.Y then
480+
self.cursor.Y = actor.ViewPoint.Y + self.maxCursorDist.Y * (dist.Y < 0 and -1 or 1);
481+
end
475482

476483
if ctrl:IsState(Controller.PIE_MENU_ACTIVE) or ctrl:IsState(Controller.ACTOR_NEXT_PREP) or ctrl:IsState(Controller.ACTOR_PREV_PREP) then
477484
self.cursor = nil;

0 commit comments

Comments
 (0)