/[skyui_scripts]/branch/skyui_510/Source/ski_configmanager.psc
ViewVC logotype

Contents of /branch/skyui_510/Source/ski_configmanager.psc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Aug 12 15:05:05 2017 UTC (2 years, 3 months ago) by william
File size: 9156 byte(s)
commit scripts for skyui 5.1
1 scriptname SKI_ConfigManager extends SKI_QuestBase hidden
2
3 ; SCRIPT VERSION ----------------------------------------------------------------------------------
4 ;
5 ; History
6 ;
7 ; 1: - Initial version
8 ;
9 ; 2: - Added lock for API functions
10 ;
11 ; 3: - Removed lock again until I have time to test it properly
12 ;
13 ; 4: - Added redundancy for registration process
14
15 int function GetVersion()
16 return 4
17 endFunction
18
19
20 ; CONSTANTS ---------------------------------------------------------------------------------------
21
22 string property JOURNAL_MENU = "Journal Menu" autoReadonly
23 string property MENU_ROOT = "_root.ConfigPanelFader.configPanel" autoReadonly
24
25
26 ; PRIVATE VARIABLES -------------------------------------------------------------------------------
27
28 ; -- Version 1 --
29
30 SKI_ConfigBase[] _modConfigs
31 string[] _modNames
32 int _curConfigID = 0
33 int _configCount = 0
34
35 SKI_ConfigBase _activeConfig
36
37 ; -- Version 2 --
38
39 ; keep those for now
40 bool _lockInit = false
41 bool _locked = false
42
43 ; -- Version 4 --
44
45 bool _cleanupFlag = false
46 int _addCounter = 0
47 int _updateCounter = 0
48
49
50 ; INITIALIZATION ----------------------------------------------------------------------------------
51
52 event OnInit()
53 _modConfigs = new SKI_ConfigBase[128]
54 _modNames = new string[128]
55
56 OnGameReload()
57 endEvent
58
59 ; @implements SKI_QuestBase
60 event OnGameReload()
61 RegisterForModEvent("SKICP_modSelected", "OnModSelect")
62 RegisterForModEvent("SKICP_pageSelected", "OnPageSelect")
63 RegisterForModEvent("SKICP_optionHighlighted", "OnOptionHighlight")
64 RegisterForModEvent("SKICP_optionSelected", "OnOptionSelect")
65 RegisterForModEvent("SKICP_optionDefaulted", "OnOptionDefault")
66 RegisterForModEvent("SKICP_keymapChanged", "OnKeymapChange")
67 RegisterForModEvent("SKICP_sliderSelected", "OnSliderSelect")
68 RegisterForModEvent("SKICP_sliderAccepted", "OnSliderAccept")
69 RegisterForModEvent("SKICP_menuSelected", "OnMenuSelect")
70 RegisterForModEvent("SKICP_menuAccepted", "OnMenuAccept")
71 RegisterForModEvent("SKICP_colorSelected", "OnColorSelect")
72 RegisterForModEvent("SKICP_colorAccepted", "OnColorAccept")
73 RegisterForModEvent("SKICP_dialogCanceled", "OnDialogCancel")
74
75 RegisterForMenu(JOURNAL_MENU)
76
77 ; no longer used but better safe than sorry
78 _lockInit = true
79
80 _cleanupFlag = true
81
82 CleanUp()
83 SendModEvent("SKICP_configManagerReady")
84
85 _updateCounter = 0
86 RegisterForSingleUpdate(5)
87 endEvent
88
89
90 ; EVENTS ------------------------------------------------------------------------------------------
91
92 event OnUpdate()
93
94 if (_cleanupFlag)
95 CleanUp()
96 endIf
97
98 if (_addCounter > 0)
99 Debug.Notification("MCM: Registered " + _addCounter + " new menu(s).")
100 _addCounter = 0
101 endIf
102
103 SendModEvent("SKICP_configManagerReady")
104
105 if (_updateCounter < 6)
106 _updateCounter += 1
107 RegisterForSingleUpdate(5)
108 else
109 RegisterForSingleUpdate(30)
110 endIf
111 endEvent
112
113 event OnMenuOpen(string a_menuName)
114 GotoState("BUSY")
115 _activeConfig = none
116 UI.InvokeStringA(JOURNAL_MENU, MENU_ROOT + ".setModNames", _modNames);
117 endEvent
118
119 event OnMenuClose(string a_menuName)
120 GotoState("")
121 if (_activeConfig)
122 _activeConfig.CloseConfig()
123 endIf
124
125 _activeConfig = none
126 endEvent
127
128 event OnModSelect(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
129 int configIndex = a_numArg as int
130 if (configIndex > -1)
131
132 ; We can clean the buffers of the previous menu now
133 if (_activeConfig)
134 _activeConfig.CloseConfig()
135 endIf
136
137 _activeConfig = _modConfigs[configIndex]
138 _activeConfig.OpenConfig()
139 endIf
140 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
141 endEvent
142
143 event OnPageSelect(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
144 string page = a_strArg
145 int index = a_numArg as int
146 _activeConfig.SetPage(page, index)
147 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
148 endEvent
149
150 event OnOptionHighlight(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
151 int optionIndex = a_numArg as int
152 _activeConfig.HighlightOption(optionIndex)
153 endEvent
154
155 event OnOptionSelect(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
156 int optionIndex = a_numArg as int
157 _activeConfig.SelectOption(optionIndex)
158 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
159 endEvent
160
161 event OnOptionDefault(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
162 int optionIndex = a_numArg as int
163 _activeConfig.ResetOption(optionIndex)
164 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
165 endEvent
166
167 event OnKeymapChange(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
168 int optionIndex = a_numArg as int
169 int keyCode = UI.GetInt(JOURNAL_MENU, MENU_ROOT + ".selectedKeyCode")
170
171 ; First test vanilla controls
172 string conflictControl = Input.GetMappedControl(keyCode)
173 string conflictName = ""
174
175 ; Then test mod controls
176 int i = 0
177 while (conflictControl == "" && i < _modConfigs.length)
178 if (_modConfigs[i] != none)
179 conflictControl = _modConfigs[i].GetCustomControl(keyCode)
180 if (conflictControl != "")
181 conflictName = _modNames[i]
182 endIf
183 endIf
184
185 i += 1
186 endWhile
187
188 _activeConfig.RemapKey(optionIndex, keyCode, conflictControl, conflictName)
189 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
190 endEvent
191
192 event OnSliderSelect(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
193 int optionIndex = a_numArg as int
194 _activeConfig.RequestSliderDialogData(optionIndex)
195 endEvent
196
197 event OnSliderAccept(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
198 float value = a_numArg
199 _activeConfig.SetSliderValue(value)
200 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
201 endEvent
202
203 event OnMenuSelect(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
204 int optionIndex = a_numArg as int
205 _activeConfig.RequestMenuDialogData(optionIndex)
206 endEvent
207
208 event OnMenuAccept(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
209 int value = a_numArg as int
210 _activeConfig.SetMenuIndex(value)
211 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
212 endEvent
213
214 event OnColorSelect(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
215 int optionIndex = a_numArg as int
216 _activeConfig.RequestColorDialogData(optionIndex)
217 endEvent
218
219 event OnColorAccept(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
220 int color = a_numArg as int
221 _activeConfig.SetColorValue(color)
222 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
223 endEvent
224
225 event OnDialogCancel(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
226 UI.InvokeBool(JOURNAL_MENU, MENU_ROOT + ".unlock", true)
227 endEvent
228
229
230 ; FUNCTIONS ---------------------------------------------------------------------------------------
231
232 ; @interface
233 int function RegisterMod(SKI_ConfigBase a_menu, string a_modName)
234 GotoState("BUSY")
235 ;Log("Registering config menu: " + a_menu + "(" + a_modName + ")")
236
237 if (_configCount >= 128)
238 GotoState("")
239 return -1
240 endIf
241
242 ; Already registered?
243 int i = 0
244 while (i < _modConfigs.length)
245 if (_modConfigs[i] == a_menu)
246 GotoState("")
247 return i
248 endIf
249
250 i += 1
251 endWhile
252
253 ; New registration
254 int configID = NextID()
255
256 if (configID == -1)
257 GotoState("")
258 return -1
259 endIf
260
261 _modConfigs[configID] = a_menu
262 _modNames[configID] = a_modName
263
264 _configCount += 1
265
266 ; Track mods added in the current cycle so we don't have to display one message per mod
267 _addCounter += 1
268
269 GotoState("")
270
271 return configID
272 endFunction
273
274 ; @interface
275 int function UnregisterMod(SKI_ConfigBase a_menu)
276 GotoState("BUSY")
277 ;Log("Unregistering config menu: " + a_menu)
278
279 int i = 0
280 while (i < _modConfigs.length)
281 if (_modConfigs[i] == a_menu)
282 _modConfigs[i] = none
283 _modNames[i] = ""
284 _configCount -= 1
285
286 GotoState("")
287 return i
288 endIf
289
290 i += 1
291 endWhile
292
293 GotoState("")
294 return -1
295 endFunction
296
297 ; @interface
298 function ForceReset()
299 Log("Forcing config manager reset...")
300 SendModEvent("SKICP_configManagerReset")
301
302 GotoState("BUSY")
303
304 int i = 0
305 while (i < _modConfigs.length)
306 _modConfigs[i] = none
307 _modNames[i] = ""
308 i += 1
309 endWhile
310
311 _curConfigID = 0
312 _configCount = 0
313
314 GotoState("")
315
316 SendModEvent("SKICP_configManagerReady")
317 endFunction
318
319 function CleanUp()
320 GotoState("BUSY")
321
322 _cleanupFlag = false
323
324 _configCount = 0
325 int i = 0
326 while (i < _modConfigs.length)
327 if (_modConfigs[i] == none || _modConfigs[i].GetFormID() == 0)
328 _modConfigs[i] = none
329 _modNames[i] = ""
330 else
331 _configCount += 1
332 endIf
333
334 i += 1
335 endWhile
336
337 GotoState("")
338 endFunction
339
340 int function NextID()
341 int startIdx = _curConfigID
342
343 while (_modConfigs[_curConfigID] != none)
344 _curConfigID += 1
345 if (_curConfigID >= 128)
346 _curConfigID = 0
347 endIf
348 if (_curConfigID == startIdx)
349 return -1 ; Just to be sure.
350 endIf
351 endWhile
352
353 return _curConfigID
354 endFunction
355
356 function Log(string a_msg)
357 ;Debug.Trace(self + ": " + a_msg)
358 endFunction
359
360
361 ; STATES ---------------------------------------------------------------------------------------
362
363 state BUSY
364 int function RegisterMod(SKI_ConfigBase a_menu, string a_modName)
365 return -2
366 endFunction
367
368 int function UnregisterMod(SKI_ConfigBase a_menu)
369 return -2
370 endFunction
371
372 function ForceReset()
373 endFunction
374
375 function CleanUp()
376 endFunction
377 endState

  ViewVC Help
Powered by ViewVC 1.1.22