Skip to content

Commit

Permalink
Improved grid alignment of pregame building previews (#2772)
Browse files Browse the repository at this point in the history
* Fixed an issue with non-square buildings being slightly offset with the pregame build queue

*Added an x/z offset based on the absolute difference in height/width to non-square buildings
*Added a few readability tweaks to a few functions

Test Steps
*Ensure pregame build queue behaves in expected manner
*Ensure incorrect offset for non-square buildings is no longer present (examples: Arm Air Lab/Arm Vehicle Bay)

* Fixed an issue with non-square buildings being slightly offset with the pregame build queue

*Added an x/z offset based on the absolute difference in height/width to non-square buildings
*Added a few readability tweaks to a few functions

Test Steps
*Ensure pregame build queue behaves in expected manner
*Ensure incorrect offset for non-square buildings is no longer present (examples: Arm Air Lab/Arm Vehicle Bay)

* Removed some of the readability tweaks to keep the script lightweight

* Removed the offset values - wasn't needed, the Spring API handles this with an optional parameter.

* Making it so the arrow correctly follows with mouse movement instead of being offset.

---------

Co-authored-by: Kiirar <[email protected]>
  • Loading branch information
kiirar and Kiirar authored Mar 26, 2024
1 parent 22a74e5 commit f40a24f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions luaui/Widgets/gui_easyFacing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ local function drawOrientation()

local _, coords = spTraceScreenRay(mx, my, true, true)
if not coords then return end
local centerX, centerY, centerZ = spPos2BuildPos( unitDefID, coords[1], coords[2], coords[3] )


local facing = spGetBuildFacing()
local centerX, centerY, centerZ = spPos2BuildPos( unitDefID, coords[1], coords[2], coords[3], facing )
local transSpace = unitZsize[unitDefID] * 4 --should be ysize but its not there?!?
local transX, transZ
local facing = spGetBuildFacing()
if facing == 0 then
transX = 0
transZ = transSpace
Expand Down
10 changes: 5 additions & 5 deletions luaui/Widgets/gui_pregame_build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ local function DrawBuilding(buildData, borderColor, drawRanges)

gl.DepthTest(false)
gl.Color(borderColor)

gl.Shape(GL.LINE_LOOP, { { v = { bx - bw, by, bz - bh } },
{ v = { bx + bw, by, bz - bh } },
{ v = { bx + bw, by, bz + bh } },
Expand Down Expand Up @@ -303,13 +303,12 @@ function widget:MousePress(x, y, button)
if not pos then
return
end

local bx, by, bz = Spring.Pos2BuildPos(selBuildQueueDefID, pos[1], pos[2], pos[3])
local buildFacing = Spring.GetBuildFacing()
local bx, by, bz = Spring.Pos2BuildPos(selBuildQueueDefID, pos[1], pos[2], pos[3], buildFacing)
local buildData = { selBuildQueueDefID, bx, by, bz, buildFacing }
local cx, cy, cz = Spring.GetTeamStartPosition(myTeamID) -- Returns -100, -100, -100 when none chosen
local _, _, meta, shift = Spring.GetModKeyState()

if (meta or not shift) and cx ~= -100 then
local cbx, cby, cbz = Spring.Pos2BuildPos(startDefID, cx, cy, cz)

Expand All @@ -319,6 +318,7 @@ function widget:MousePress(x, y, button)
end

if Spring.TestBuildOrder(selBuildQueueDefID, bx, by, bz, buildFacing) ~= 0 then

if meta then
table.insert(buildQueue, 1, buildData)

Expand Down Expand Up @@ -412,8 +412,8 @@ function widget:DrawWorld()
local x, y, _ = Spring.GetMouseState()
local _, pos = Spring.TraceScreenRay(x, y, true, false, false, isUnderwater(selBuildQueueDefID))
if pos then
local bx, by, bz = Spring.Pos2BuildPos(selBuildQueueDefID, pos[1], pos[2], pos[3])
local buildFacing = Spring.GetBuildFacing()
local bx, by, bz = Spring.Pos2BuildPos(selBuildQueueDefID, pos[1], pos[2], pos[3], buildFacing)
selBuildData = { selBuildQueueDefID, bx, by, bz, buildFacing }
end
end
Expand Down

0 comments on commit f40a24f

Please sign in to comment.