Skip to content

Commit 099e601

Browse files
committed
Add configurable padding around the multi-cube area
This should help with the (smooth) camera keeping up with the multiple cubes are moving.
1 parent faa18c8 commit 099e601

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

locale/en/locale.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ label-top-right=Top/Right:
4040
label-type=Type:
4141
label-until-build=Follow until build
4242
label-zoom=Zoom:
43+
label-cube-padding=Cube padding:
4344
label-transitionperiod=Transition period:
4445
label-cityblock-size=Block size:
4546
label-cityblock-offset=Offset:
@@ -92,6 +93,7 @@ tracker-cityblock-blockScale=How many city blocks to zoom out, centered on the c
9293
tracker-cityblock-blockScale-value=A zoom of 3 will capture the current block and all of the neighbors. <enter> to set.
9394
tracker-cityblock-player=Use player coordinates to select the current city block.
9495
tracker-cube-not-available=This tracker is not available because Ultracube mod is not loaded.
96+
tracker-cube-padding=Padding (in tiles) applied around the cube area when multiple cubes are present.
9597

9698
[controls]
9799
tlbe-main-window-toggle=Open/Close camera settings

scripts/gui.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,17 @@ function GUI.onTextChanged(event)
635635
selectedTracker.maxPos.x = value
636636
Tracker.areaUpdateCenterAndSize(selectedTracker)
637637

638+
GUI.updateTrackerConfig(playerSettings.gui.trackerInfo, selectedTracker)
639+
GUI.updateTrackerInfo(playerSettings.gui.trackerInfo, selectedTracker)
640+
end
641+
elseif event.element.name == "tlbe-tracker-cube-padding" and event.element.text ~= nil then
642+
local value = tonumber(event.element.text)
643+
if value ~= nil then
644+
if value < 0 then
645+
value = 0
646+
end
647+
selectedTracker.cubePadding = value
648+
638649
GUI.updateTrackerConfig(playerSettings.gui.trackerInfo, selectedTracker)
639650
GUI.updateTrackerInfo(playerSettings.gui.trackerInfo, selectedTracker)
640651
end
@@ -1594,6 +1605,20 @@ function GUI.createTrackerConfigAndInfo(trackerInfo, tracker)
15941605
tooltip = { "tooltip.tracker-until-build" },
15951606
state = tracker.untilBuild
15961607
}
1608+
elseif tracker.type == "cube" then
1609+
trackerInfo.add {
1610+
type = "label",
1611+
caption = { "gui.label-cube-padding" },
1612+
tooltip = { "tooltip.tracker-cube-padding" },
1613+
style = "bold_label"
1614+
}
1615+
trackerInfo.add {
1616+
type = "textfield",
1617+
name = "tlbe-tracker-cube-padding",
1618+
style = "tlbe_config_half_width_textfield",
1619+
numeric = true,
1620+
allow_negative = false
1621+
}
15971622
elseif tracker.type == "cityblock" then
15981623
trackerInfo.add {
15991624
type = "label",
@@ -1762,6 +1787,8 @@ function GUI.updateTrackerConfig(trackerInfo, tracker)
17621787
blFlow["tlbe-tracker-left"].style = style
17631788
elseif tracker.type == "player" then
17641789
trackerInfo["tracker-untilbuild"].state = tracker.untilBuild
1790+
elseif tracker.type == "cube" then
1791+
trackerInfo["tlbe-tracker-cube-padding"].text = string.format("%d", tracker.cubePadding)
17651792
elseif tracker.type == "cityblock" then
17661793
local cityBlock = tracker.cityBlock
17671794
if cityBlock == nil then

scripts/tracker.lua

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ local Tracker = {}
1313
--- @field userCanEnable boolean When true, the user can enabled/disable the tracker, otherwise the tracker is controlled by TLBE
1414
--- @field moveToNextTracker boolean|nil Disables the tracker after the cameras are processed (end of game tick)
1515
--- @field changeId integer Incremented on each position/size change of the tracker
16+
--- @field cubePadding number Padding (in tiles) applied around the cube area when multiple cubes are present
1617
--- @field centerPos MapPosition.0|nil Center position of the tracker area (Calculated from minPos and maxPos)
1718
--- @field size MapPosition.0|nil Size of the tracker area (Calculated from minPos and maxPos)
1819
--- @field minPos MapPosition.0 Bottom/Left of tracker area
@@ -61,9 +62,10 @@ function Tracker.newTracker(player, trackerType, trackerList)
6162
smooth = true,
6263
untilBuild = false,
6364
changeId = 0,
65+
cubePadding = 0,
6466
-- Set some sensible defaults but will be most likely overwritten by the tracker specific implementations
6567
minPos = { x = -5, y = -5 },
66-
maxPos = { x = 5, y = 5 }
68+
maxPos = { x = 5, y = 5 },
6769
}
6870

6971
-- Add tracker specific details
@@ -178,23 +180,23 @@ function Tracker.tick(tracker, player)
178180
local size
179181

180182
if minPos ~= nil and maxPos ~= nil then
181-
local sizeX = maxPos.x - minPos.x
182-
local sizeY = maxPos.y - minPos.y
183+
local baseSizeX = maxPos.x - minPos.x
184+
local baseSizeY = maxPos.y - minPos.y
183185

184-
if sizeX == 0 then
185-
sizeX = 1
186+
if baseSizeX == 0 then
187+
baseSizeX = 1
186188
end
187-
if sizeY == 0 then
188-
sizeY = 1
189+
if baseSizeY == 0 then
190+
baseSizeY = 1
189191
end
190192

191193
size = {
192-
x = sizeX,
193-
y = sizeY
194+
x = baseSizeX + 2 * tracker.cubePadding,
195+
y = baseSizeY + 2 * tracker.cubePadding
194196
}
195197
centerPos = {
196-
x = minPos.x + size.x / 2,
197-
y = minPos.y + size.y / 2
198+
x = minPos.x + baseSizeX / 2,
199+
y = minPos.y + baseSizeY / 2
198200
}
199201
elseif info.position ~= nil then
200202
centerPos = {

0 commit comments

Comments
 (0)