-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathParkVehicleSettingsGui.lua
More file actions
66 lines (54 loc) · 2.74 KB
/
Copy pathParkVehicleSettingsGui.lua
File metadata and controls
66 lines (54 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--- Injects a "Park Vehicle" section (own header + "Auto-unpark vehicles" checkbox)
--- into the native General Settings tab of the pause menu. Clones an existing
--- section-title element and the "Is Train Tabbable" checkbox row (same kind of
--- on/off vehicle-tabbing toggle), and rebinds the checkbox's click callback to
--- our own persisted setting instead of the native g_settingsModel.
ParkVehicleSettingsGui = {}
function ParkVehicleSettingsGui.install()
InGameMenuSettingsFrame.onFrameOpen = Utils.appendedFunction(InGameMenuSettingsFrame.onFrameOpen, ParkVehicleSettingsGui.onFrameOpen)
end
function ParkVehicleSettingsGui.onFrameOpen(settingsFrame)
if settingsFrame.parkVehicleCheckbox ~= nil then
ParkVehicleSettingsGui.refreshCheckbox(settingsFrame.parkVehicleCheckbox)
return
end
local templateBox = settingsFrame.checkIsTrainTabbableBox
local layout = templateBox ~= nil and templateBox.parent or nil
if layout == nil then
return
end
-- Section header: clone any existing "General Settings" section title
-- (e.g. "Sound", "Camera") instead of appending into someone else's group.
for _, element in ipairs(layout.elements) do
if element.name == "sectionHeader" then
local header = element:clone(layout)
header:setText(g_i18n:getText("PARKVEHICLE_SETTINGS_SECTION"))
break
end
end
local clonedBox = templateBox:clone(layout)
local checkbox = clonedBox.elements[1]
local title = clonedBox.elements[2]
local tooltip = checkbox.elements[1]
title:setText(g_i18n:getText("PARKVEHICLE_AUTOUNPARK_SETTING"))
tooltip:setText(g_i18n:getText("PARKVEHICLE_AUTOUNPARK_SETTING_TOOLTIP"))
checkbox.target = ParkVehicleSettingsGui
checkbox:setCallback("onClickCallback", "onClickAutoUnpark")
ParkVehicleSettingsGui.refreshCheckbox(checkbox)
layout:invalidateLayout()
settingsFrame.parkVehicleCheckboxBox = clonedBox
settingsFrame.parkVehicleCheckbox = checkbox
end
--- Sets the checkbox's visual state directly instead of going through
--- setIsChecked/setState: those skip the left/right highlight update
--- (updateSelection) whenever the new state already equals the state the
--- checkbox inherited from its clone source, which left the row visually
--- stuck on the wrong side despite the underlying value being correct.
function ParkVehicleSettingsGui.refreshCheckbox(checkbox)
checkbox.state = g_parkVehicleSystem.autoUnparkEnabled and BinaryOptionElement.STATE_RIGHT or BinaryOptionElement.STATE_LEFT
checkbox.skipAnimation = true
checkbox:updateSelection()
end
function ParkVehicleSettingsGui:onClickAutoUnpark(state, element)
g_parkVehicleSystem:setAutoUnparkEnabled(element:getIsChecked())
end