This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 525
/
GlobalSettings.lua
284 lines (249 loc) · 9.41 KB
/
GlobalSettings.lua
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
-- all the Global Settings
--- Load courses at startup?
---@class LoadCoursesAtStartupSetting : BooleanSetting
LoadCoursesAtStartupSetting = CpObject(BooleanSetting)
function LoadCoursesAtStartupSetting:init()
BooleanSetting.init(self, 'loadCoursesAtStartup', 'COURSEPLAY_LOAD_COURSES_AT_STARTUP',
'COURSEPLAY_LOAD_COURSES_AT_STARTUP_TOOLTIP', nil)
end
---@class AutoFieldScanSetting : BooleanSetting
AutoFieldScanSetting = CpObject(BooleanSetting)
function AutoFieldScanSetting:init()
BooleanSetting.init(self, 'autoFieldScan', 'COURSEPLAY_AUTO_FIELD_SCAN',
'COURSEPLAY_YES_NO_FIELDSCAN', nil)
-- set default while we are transitioning from the the old setting to this new one
self:set(true)
end
---@class ClickToSwitchSetting : BooleanSetting
ClickToSwitchSetting = CpObject(BooleanSetting)
function ClickToSwitchSetting:init()
BooleanSetting.init(self, 'clickToSwitch', 'COURSEPLAY_CLICK_TO_SWITCH',
'COURSEPLAY_YES_NO_CLICK_TO_SWITCH', nil)
-- set default while we are transitioning from the the old setting to this new one
self:set(true)
end
---@class WorkerWagesSetting : SettingList
WorkerWagesSetting = CpObject(SettingList)
function WorkerWagesSetting:init()
SettingList.init(self, 'workerWages', 'COURSEPLAY_WORKER_WAGES', 'COURSEPLAY_WORKER_WAGES_TOOLTIP', nil,
{0, 50, 100, 250, 500, 1000},
{'0%', '50%', '100%', '250%', '500%', '1000%'}
)
self:set(0)
end
---@class EnableOpenHudWithMouseGlobalSetting : BooleanSetting
EnableOpenHudWithMouseGlobalSetting = CpObject(BooleanSetting)
function EnableOpenHudWithMouseGlobalSetting:init()
BooleanSetting.init(self, 'enableOpenHudWithMouseGlobal', 'COURSEPLAY_ENABLE_OPEN_HUD_WITH_MOUSE_GLOBAL',
'COURSEPLAY_YES_NO_ENABLE_OPEN_HUD_WITH_MOUSE_GLOBAL', nil)
-- set default while we are transitioning from the the old setting to this new one
self:set(true)
end
---@class EnableOpenHudWithMouseVehicleSetting : BooleanSetting
EnableOpenHudWithMouseVehicleSetting = CpObject(BooleanSetting)
function EnableOpenHudWithMouseVehicleSetting:init()
BooleanSetting.init(self, 'enableOpenHudWithMouseVehicle', 'COURSEPLAY_ENABLE_OPEN_HUD_WITH_MOUSE_VEHICLE',
'COURSEPLAY_YES_NO_ENABLE_OPEN_HUD_WITH_MOUSE_VEHICLE', nil)
-- set default while we are transitioning from the the old setting to this new one
self:set(true)
end
---@class ShowMiniHudSetting : BooleanSetting
ShowMiniHudSetting = CpObject(BooleanSetting)
function ShowMiniHudSetting:init()
BooleanSetting.init(self, 'showMiniHud', 'COURSEPLAY_SHOW_MINI_HUD',
'COURSEPLAY_YES_NO_SHOW_MINI_HUD', nil)
-- set default while we are transitioning from the the old setting to this new one
self:set(false)
end
---@class ShowActionEventTextsSetting : BooleanSetting
ShowActionEventTextsSetting = CpObject(BooleanSetting)
function ShowActionEventTextsSetting:init()
BooleanSetting.init(self, 'showActionEventsTexts', 'COURSEPLAY_SHOW_ACTION_EVENTS_TEXTS',
'COURSEPLAY_SHOW_ACTION_EVENTS_TEXTS_TOOLTIP', nil)
-- set default while we are transitioning from the the old setting to this new one
self:set(true)
end
---On setting change, make sure the current entered vehicle gets updated.
function ShowActionEventTextsSetting:onChange()
if g_currentMission then
local vehicle = g_currentMission.controlledVehicle
if vehicle ~= nil then
ActionEventsLoader.updateAllActionEvents(vehicle)
end
end
end
---@class AutoRepairSetting : SettingList
AutoRepairSetting = CpObject(SettingList)
AutoRepairSetting.OFF = 0
function AutoRepairSetting:init()
SettingList.init(self, 'autoRepair', 'COURSEPLAY_AUTOREPAIR', 'COURSEPLAY_AUTOREPAIR_TOOLTIP', nil,
{AutoRepairSetting.OFF, 25, 70, 99},
{'COURSEPLAY_AUTOREPAIR_OFF', '< 25%', '< 70%', 'COURSEPLAY_AUTOREPAIR_ALWAYS'}
)
self:set(0)
end
function AutoRepairSetting:isAutoRepairActive()
return self:get() ~= AutoRepairSetting.OFF
end
function AutoRepairSetting:onUpdateTick(dt, isActive, isActiveForInput, isSelected)
local rootVehicle = self:getRootVehicle()
local isOwned = rootVehicle.propertyState ~= Vehicle.PROPERTY_STATE_MISSION
if courseplay:isAIDriverActive(rootVehicle) and isOwned then
if courseplay.globalSettings.autoRepair:isAutoRepairActive() then
local repairStatus = (1 - self:getWearTotalAmount())*100
if repairStatus < courseplay.globalSettings.autoRepair:get() then
self:repairVehicle()
end
end
end
end
Wearable.onUpdateTick = Utils.appendedFunction(Wearable.onUpdateTick, AutoRepairSetting.onUpdateTick)
---@class ShowMapHotspotSetting : SettingList
ShowMapHotspotSetting = CpObject(SettingList)
ShowMapHotspotSetting.DEACTIVATED = 0
ShowMapHotspotSetting.NAME_ONLY = 1
ShowMapHotspotSetting.NAME_AND_COURSE = 2
function ShowMapHotspotSetting:init()
SettingList.init(self, 'showMapHotspot', 'COURSEPLAY_INGAMEMAP_ICONS_SHOWTEXT', 'COURSEPLAY_INGAMEMAP_ICONS_SHOWTEXT', nil,
{
ShowMapHotspotSetting.DEACTIVATED,
ShowMapHotspotSetting.NAME_ONLY,
ShowMapHotspotSetting.NAME_AND_COURSE
},
{
'COURSEPLAY_DEACTIVATED',
'COURSEPLAY_NAME_ONLY',
'COURSEPLAY_NAME_AND_COURSE'
}
)
self:set(ShowMapHotspotSetting.NAME_ONLY)
end
---If the setting changes force update all mapHotSpot texts
function ShowMapHotspotSetting:onChange()
self:updateHotSpotTexts()
end
function ShowMapHotspotSetting:updateHotSpotTexts()
if CpManager.activeCoursePlayers then
for _,vehicle in pairs(CpManager.activeCoursePlayers) do
if vehicle.spec_aiVehicle.mapAIHotspot then
vehicle.spec_aiVehicle.mapAIHotspot:setText(self:getMapHotspotText(vehicle))
end
end
end
end
function ShowMapHotspotSetting:getMapHotspotText(vehicle)
local text = ''
if self:is(ShowMapHotspotSetting.NAME_ONLY) then
text = string.format("%s%s\n",text,nameNum(vehicle, true))
elseif self:is(ShowMapHotspotSetting.NAME_AND_COURSE) then
text = string.format("%s%s\n%s",text,nameNum(vehicle, true),vehicle.cp.currentCourseName or courseplay:loc('COURSEPLAY_TEMP_COURSE'))
end
return text
end
--- This Setting handles all debug channels.
--- For each debug channel is a code short cut created,
--- for example: DebugChannelsSetting.DBG_MODE_3.
--- This is defined in the debug config xml file.
--- For backwards compatibility are all
--- courseplay.debugChannels[ix] or courseplay["DBG_MODE_3"] calls still valid.
---@class DebugChannelsSetting : Setting
DebugChannelsSetting = CpObject(Setting)
function DebugChannelsSetting:init()
Setting.init(self,"debugChannels")
self.xmlFilePath = Utils.getFilename('config/DebugChannels.xml', courseplay.path)
self:load(self.xmlFilePath)
self.DEFAULT_EVENT = self:registerIntEvent(self.setFromNetwork)
end
function DebugChannelsSetting:load(xmlFilePath)
local xmlFile = loadXMLFile('debugChannels', xmlFilePath)
local baseKey = "DebugChannels"
self.channels = {}
self.numChannels = 0
self.toolTips = {}
if xmlFile and hasXMLProperty(xmlFile, baseKey) then
print("Loading debug channel setup!")
local i = 0
while true do
local key = string.format("%s.%s(%d)",baseKey,"DebugChannel",i)
if not hasXMLProperty(xmlFile, key) then
break
end
local text = getXMLString(xmlFile, key.."#text")
local name = getXMLString(xmlFile, key.."#name")
local active = getXMLBool(xmlFile, key.."#active")
i = i + 1
self[name] = i
courseplay[name] = i --- Old code
self.toolTips[i] = text
--- Evaluate pre debug setups from the DevSetup xml file.
--- Also make sure active ~= nil.
active = Utils.getNoNil(active or
CpManager.preDebugSetup.nameToChannel[name] or
CpManager.preDebugSetup.idToChannel[i]
,false)
self.channels[i] = active
if active then
print(string.format("Debug channel id: %s, name: %s is activated.",tostring(i),tostring(name)))
end
end
self.numChannels = i
delete(xmlFile)
else
print("Couldn't load debug channel setup!")
end
courseplay.debugChannels = self.channels --- Old code
end
function DebugChannelsSetting:onWriteStream(streamID)
streamWriteUInt8(streamID,self.numChannels)
for ix,value in ipairs(self.channels) do
streamWriteBool(streamID,value)
end
end
function DebugChannelsSetting:onReadStream(streamID)
self.numChannels = streamReadUInt8(streamID)
for i= 1, self.numChannels do
self.channels[i] = streamReadBool(streamID)
end
end
function DebugChannelsSetting:toggleChannel(ix,noEventSend)
self:set(ix,not self.channels[ix],noEventSend)
end
function DebugChannelsSetting:set(ix,value,noEventSend)
self.channels[ix] = value
if noEventSend == nil or noEventSend == false then
self:sendEvent(ix)
end
self:onChange()
end
function DebugChannelsSetting:get()
return self.channels
end
function DebugChannelsSetting:getNumberOfChannels()
return self.numChannels
end
function DebugChannelsSetting:getToolTips()
return self.toolTips
end
function DebugChannelsSetting:sendEvent(ix)
self:raiseEvent(self.DEFAULT_EVENT,ix)
end
function DebugChannelsSetting:setFromNetwork(ix)
self:toggleChannel(ix,true)
end
function DebugChannelsSetting:isActive(ix)
return self.channels[ix]
end
function SettingsContainer.createGlobalSettings()
local container = SettingsContainer("globalSettings")
container:addSetting(DebugChannelsSetting)
container:addSetting(LoadCoursesAtStartupSetting)
container:addSetting(AutoFieldScanSetting)
container:addSetting(WorkerWagesSetting)
container:addSetting(ClickToSwitchSetting)
container:addSetting(ShowMiniHudSetting)
container:addSetting(EnableOpenHudWithMouseGlobalSetting)
container:addSetting(AutoRepairSetting)
container:addSetting(ShowMapHotspotSetting)
container:addSetting(ShowActionEventTextsSetting)
return container
end