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

Annotation of /branch/skyui_510/Source/ski_configbase.psc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations) (download)
Sat Aug 12 15:05:05 2017 UTC (2 years ago) by william
File size: 30924 byte(s)
commit scripts for skyui 5.1
1 william 3 scriptname SKI_ConfigBase extends SKI_QuestBase
2    
3     ; CONSTANTS ---------------------------------------------------------------------------------------
4    
5     string property JOURNAL_MENU = "Journal Menu" autoReadonly
6     string property MENU_ROOT = "_root.ConfigPanelFader.configPanel" autoReadonly
7    
8     int property STATE_DEFAULT = 0 autoReadonly
9     int property STATE_RESET = 1 autoReadonly
10     int property STATE_SLIDER = 2 autoReadonly
11     int property STATE_MENU = 3 autoReadonly
12     int property STATE_COLOR = 4 autoReadonly
13    
14     int property OPTION_TYPE_EMPTY = 0x00 autoReadonly
15     int property OPTION_TYPE_HEADER = 0x01 autoReadonly
16     int property OPTION_TYPE_TEXT = 0x02 autoReadonly
17     int property OPTION_TYPE_TOGGLE = 0x03 autoReadonly
18     int property OPTION_TYPE_SLIDER = 0x04 autoReadonly
19     int property OPTION_TYPE_MENU = 0x05 autoReadonly
20     int property OPTION_TYPE_COLOR = 0x06 autoReadonly
21     int property OPTION_TYPE_KEYMAP = 0x07 autoReadonly
22    
23     int property OPTION_FLAG_NONE = 0x00 autoReadonly
24     int property OPTION_FLAG_DISABLED = 0x01 autoReadonly
25     int property OPTION_FLAG_HIDDEN = 0x02 autoReadonly
26     int property OPTION_FLAG_WITH_UNMAP = 0x04 autoReadonly
27    
28     int property LEFT_TO_RIGHT = 1 autoReadonly
29     int property TOP_TO_BOTTOM = 2 autoReadonly
30    
31    
32     ; PRIVATE VARIABLES -------------------------------------------------------------------------------
33    
34     SKI_ConfigManager _configManager
35     bool _initialized = false
36     int _configID = -1
37     string _currentPage = ""
38     int _currentPageNum = 0 ; 0 for "", real pages start at 1
39    
40     ; Keep track of what we're doing at the moment for stupidity checks
41     int _state = 0
42    
43     int _cursorPosition = 0
44     int _cursorFillMode = 1 ;LEFT_TO_RIGHT
45    
46     ; Local buffers
47     int[] _optionFlagsBuf ; byte 1 type, byte 2 flags
48     string[] _textBuf
49     string[] _strValueBuf
50     float[] _numValueBuf
51    
52     float[] _sliderParams
53     int[] _menuParams
54     int[] _colorParams
55    
56     int _activeOption = -1
57    
58     string _infoText
59    
60     bool _messageResult = false
61     bool _waitForMessage = false
62    
63     string[] _stateOptionMap
64    
65    
66     ; PROPERTIES --------------------------------------------------------------------------------------
67    
68     string property ModName auto
69    
70     string[] property Pages auto
71    
72     string property CurrentPage
73     string function get()
74     return _currentPage
75     endFunction
76     endProperty
77    
78    
79     ; INITIALIZATION ----------------------------------------------------------------------------------
80    
81     event OnInit()
82     OnGameReload()
83     endEvent
84    
85     ; @implements SKI_QuestBase
86     event OnGameReload()
87     if (!_initialized)
88     _initialized = true
89    
90     ; Buffer alloc/free on config open/close
91     ;_optionFlagsBuf = new int[128]
92     ;_textBuf = new string[128]
93     ;_strValueBuf = new string[128]
94     ;_numValueBuf = new float[128]
95    
96     ; 0 startValue
97     ; 1 defaultValue
98     ; 2 minValue
99     ; 3 maxValue
100     ; 4 interval
101     _sliderParams = new float[5]
102    
103     ; 0 startIndex
104     ; 1 defaultIndex
105     _menuParams = new int[2]
106    
107     ; 0 currentColor
108     ; 1 defaultColor
109     _colorParams = new int[2]
110    
111     OnConfigInit()
112    
113     ;Debug.Trace(self + " INITIALIZED")
114     endIf
115    
116     RegisterForModEvent("SKICP_configManagerReady", "OnConfigManagerReady")
117     RegisterForModEvent("SKICP_configManagerReset", "OnConfigManagerReset")
118    
119     CheckVersion()
120     endEvent
121    
122    
123     ; EVENTS ------------------------------------------------------------------------------------------
124    
125     ; @interface
126     event OnConfigInit()
127     {Called when this config menu is initialized}
128     endEvent
129    
130     ; @interface
131     event OnConfigRegister()
132     {Called when this config menu registered at the control panel}
133     endEvent
134    
135     ; @interface
136     event OnConfigOpen()
137     {Called when this config menu is opened}
138     endEvent
139    
140     ; @interface
141     event OnConfigClose()
142     {Called when this config menu is closed}
143     endEvent
144    
145     ; @interface(SKI_QuestBase)
146     event OnVersionUpdate(int a_version)
147     {Called when a version update of this script has been detected}
148     endEvent
149    
150     ; @interface
151     event OnPageReset(string a_page)
152     {Called when a new page is selected, including the initial empty page}
153     endEvent
154    
155     ; @interface
156     event OnOptionHighlight(int a_option)
157     {Called when highlighting an option}
158     endEvent
159    
160     ; @interface
161     event OnOptionSelect(int a_option)
162     {Called when a non-interactive option has been selected}
163     endEvent
164    
165     ; @interface
166     event OnOptionDefault(int a_option)
167     {Called when resetting an option to its default value}
168     endEvent
169    
170     ; @interface
171     event OnOptionSliderOpen(int a_option)
172     {Called when a slider option has been selected}
173     endEvent
174    
175     ; @interface
176     event OnOptionSliderAccept(int a_option, float a_value)
177     {Called when a new slider value has been accepted}
178     endEvent
179    
180     ; @interface
181     event OnOptionMenuOpen(int a_option)
182     {Called when a menu option has been selected}
183     endEvent
184    
185     ; @interface
186     event OnOptionMenuAccept(int a_option, int a_index)
187     {Called when a menu entry has been accepted}
188     endEvent
189    
190     ; @interface
191     event OnOptionColorOpen(int a_option)
192     {Called when a color option has been selected}
193     endEvent
194    
195     ; @interface
196     event OnOptionColorAccept(int a_option, int a_color)
197     {Called when a new color has been accepted}
198     endEvent
199    
200     ; @interface
201     event OnOptionKeyMapChange(int a_option, int a_keyCode, string a_conflictControl, string a_conflictName)
202     {Called when a key has been remapped}
203     endEvent
204    
205     ; @interface
206     event OnHighlightST()
207     {Called when highlighting a state option}
208     endEvent
209    
210     ; @interface
211     event OnSelectST()
212     {Called when a non-interactive state option has been selected}
213     endEvent
214    
215     ; @interface
216     event OnDefaultST()
217     {Called when resetting a state option to its default value}
218     endEvent
219    
220     ; @interface
221     event OnSliderOpenST()
222     {Called when a slider state option has been selected}
223     endEvent
224    
225     ; @interface
226     event OnSliderAcceptST(float a_value)
227     {Called when a new slider state value has been accepted}
228     endEvent
229    
230     ; @interface
231     event OnMenuOpenST()
232     {Called when a menu state option has been selected}
233     endEvent
234    
235     ; @interface
236     event OnMenuAcceptST(int a_index)
237     {Called when a menu entry has been accepted for this state option}
238     endEvent
239    
240     ; @interface
241     event OnColorOpenST()
242     {Called when a color state option has been selected}
243     endEvent
244    
245     ; @interface
246     event OnColorAcceptST(int a_color)
247     {Called when a new color has been accepted for this state option}
248     endEvent
249    
250     ; @interface
251     event OnKeyMapChangeST(int a_keyCode, string a_conflictControl, string a_conflictName)
252     {Called when a key has been remapped for this state option}
253     endEvent
254    
255     event OnConfigManagerReset(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
256     _configManager = none
257     endEvent
258    
259     event OnConfigManagerReady(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
260     SKI_ConfigManager newManager = a_sender as SKI_ConfigManager
261     ; Already registered?
262     if (_configManager == newManager || newManager == none)
263     return
264     endIf
265    
266     _configID = newManager.RegisterMod(self, ModName)
267    
268     ; Success
269     if (_configID >= 0)
270     _configManager = newManager
271     OnConfigRegister()
272     ;Debug.Trace(self + ": Registered " + ModName + " at MCM.")
273     endIf
274     endEvent
275    
276     event OnMessageDialogClose(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
277     _messageResult = a_numArg as bool
278     _waitForMessage = false
279     endEvent
280    
281    
282     ; FUNCTIONS ---------------------------------------------------------------------------------------
283    
284     ; @interface(SKI_QuestBase)
285     int function GetVersion()
286     {Returns version of this script}
287     return 1
288     endFunction
289    
290     ; @interface
291     string function GetCustomControl(int a_keyCode)
292     {Returns the name of a custom control mapped to given keyCode, or "" if the key is not in use by this config}
293     return ""
294     endFunction
295    
296     ; @interface
297     function ForcePageReset()
298     {Forces a full reset of the current page}
299     UI.Invoke(JOURNAL_MENU, MENU_ROOT + ".forcePageReset")
300     endFunction
301    
302     ; @interface
303     function SetTitleText(string a_text)
304     UI.InvokeString(JOURNAL_MENU, MENU_ROOT + ".setTitleText", a_text)
305     endFunction
306    
307     ; @interface
308     function SetInfoText(string a_text)
309     _infoText = a_text
310     endFunction
311    
312     ; @interface
313     function SetCursorPosition(int a_position)
314     if (a_position < 128)
315     _cursorPosition = a_position
316     endIf
317     endFunction
318    
319     ; @interface
320     function SetCursorFillMode(int a_fillMode)
321     if (a_fillMode == LEFT_TO_RIGHT || a_fillMode == TOP_TO_BOTTOM)
322     _cursorFillMode = a_fillMode
323     endIf
324     endFunction
325    
326     ; @interface
327     int function AddEmptyOption()
328     return AddOption(OPTION_TYPE_EMPTY, none, none, 0, 0)
329     endFunction
330    
331     ; @interface
332     int function AddHeaderOption(string a_text, int a_flags = 0)
333     return AddOption(OPTION_TYPE_HEADER, a_text, none, 0, a_flags)
334     endFunction
335    
336     ; @interface
337     int function AddTextOption(string a_text, string a_value, int a_flags = 0)
338     return AddOption(OPTION_TYPE_TEXT, a_text, a_value, 0, a_flags)
339     endFunction
340    
341     ; @interface
342     int function AddToggleOption(string a_text, bool a_checked, int a_flags = 0)
343     return AddOption(OPTION_TYPE_TOGGLE, a_text, none, a_checked as int, a_flags)
344     endfunction
345    
346     ; @interface
347     int function AddSliderOption(string a_text, float a_value, string a_formatString = "{0}", int a_flags = 0)
348     return AddOption(OPTION_TYPE_SLIDER, a_text, a_formatString, a_value, a_flags)
349     endFunction
350    
351     ; @interface
352     int function AddMenuOption(string a_text, string a_value, int a_flags = 0)
353     return AddOption(OPTION_TYPE_MENU, a_text, a_value, 0, a_flags)
354     endFunction
355    
356     ; @interface
357     int function AddColorOption(string a_text, int a_color, int a_flags = 0)
358     return AddOption(OPTION_TYPE_COLOR, a_text, none, a_color, a_flags)
359     endFunction
360    
361     ; @interface
362     int function AddKeyMapOption(string a_text, int a_keyCode, int a_flags = 0)
363     return AddOption(OPTION_TYPE_KEYMAP, a_text, none, a_keyCode, a_flags)
364     endFunction
365    
366     ; @since 4
367     int function AddInputOption(string a_text, string a_value, int a_flags = 0)
368     {Adds a text input option}
369     Guard()
370     endFunction
371     ; @since 4
372     function SetInputOptionValue(int a_option, string a_value, bool a_noUpdate = false)
373     {Sets the value(s) of an existing option}
374     Guard()
375     endFunction
376     ; @since 4
377     function SetInputDialogStartText(string a_text)
378     {Sets text input dialog parameter(s)}
379     Guard()
380     endFunction
381    
382     ; @interface
383     function AddTextOptionST(string a_stateName, string a_text, string a_value, int a_flags = 0)
384     AddOptionST(a_stateName, OPTION_TYPE_TEXT, a_text, a_value, 0, a_flags)
385     endFunction
386    
387     ; @interface
388     function AddToggleOptionST(string a_stateName, string a_text, bool a_checked, int a_flags = 0)
389     AddOptionST(a_stateName, OPTION_TYPE_TOGGLE, a_text, none, a_checked as int, a_flags)
390     endfunction
391    
392     ; @interface
393     function AddSliderOptionST(string a_stateName, string a_text, float a_value, string a_formatString = "{0}", int a_flags = 0)
394     AddOptionST(a_stateName, OPTION_TYPE_SLIDER, a_text, a_formatString, a_value, a_flags)
395     endFunction
396    
397     ; @interface
398     function AddMenuOptionST(string a_stateName, string a_text, string a_value, int a_flags = 0)
399     AddOptionST(a_stateName, OPTION_TYPE_MENU, a_text, a_value, 0, a_flags)
400     endFunction
401    
402     ; @interface
403     function AddColorOptionST(string a_stateName, string a_text, int a_color, int a_flags = 0)
404     AddOptionST(a_stateName, OPTION_TYPE_COLOR, a_text, none, a_color, a_flags)
405     endFunction
406    
407     ; @interface
408     function AddKeyMapOptionST(string a_stateName, string a_text, int a_keyCode, int a_flags = 0)
409     AddOptionST(a_stateName, OPTION_TYPE_KEYMAP, a_text, none, a_keyCode, a_flags)
410     endFunction
411    
412     ; @interface
413     function LoadCustomContent(string a_source, float a_x = 0.0, float a_y = 0.0)
414     float[] params = new float[2]
415     params[0] = a_x
416     params[1] = a_y
417     UI.InvokeFloatA(JOURNAL_MENU, MENU_ROOT + ".setCustomContentParams", params)
418     UI.InvokeString(JOURNAL_MENU, MENU_ROOT + ".loadCustomContent", a_source)
419     endFunction
420    
421     ; @interface
422     function UnloadCustomContent()
423     UI.Invoke(JOURNAL_MENU, MENU_ROOT + ".unloadCustomContent")
424     endFunction
425    
426     ; @interface
427     function SetOptionFlags(int a_option, int a_flags, bool a_noUpdate = false)
428     if (_state == STATE_RESET)
429     Error("Cannot set option flags while in OnPageReset(). Pass flags to AddOption instead")
430     return
431     endIf
432    
433     int index = a_option % 0x100
434    
435     ; Update flags buffer
436     int oldFlags = _optionFlagsBuf[index] as int
437     oldFlags %= 0x100 ; Clear upper bytes, keep type
438     oldFlags += a_flags * 0x100 ; Set new flags
439    
440     ; Update display
441     int[] params = new int[2]
442     params[0] = index
443     params[1] = a_flags
444     UI.InvokeIntA(JOURNAL_MENU, MENU_ROOT + ".setOptionFlags", params)
445    
446     if (!a_noUpdate)
447     UI.Invoke(JOURNAL_MENU, MENU_ROOT + ".invalidateOptionData")
448     endIf
449     endFunction
450    
451     ; @interface
452     function SetTextOptionValue(int a_option, string a_value, bool a_noUpdate = false)
453     int index = a_option % 0x100
454     int type = _optionFlagsBuf[index] % 0x100
455    
456     if (type != OPTION_TYPE_TEXT)
457     int pageIdx = ((a_option / 0x100) as int) - 1
458     if (pageIdx != -1)
459     Error("Option type mismatch. Expected text option, page \"" + Pages[pageIdx] + "\", index " + index)
460     else
461     Error("Option type mismatch. Expected text option, page \"\", index " + index)
462     endIf
463     return
464     endIf
465    
466     SetOptionStrValue(index, a_value, a_noUpdate)
467     endFunction
468    
469     ; @interface
470     function SetToggleOptionValue(int a_option, bool a_checked, bool a_noUpdate = false)
471     int index = a_option % 0x100
472     int type = _optionFlagsBuf[index] % 0x100
473    
474     if (type != OPTION_TYPE_TOGGLE)
475     int pageIdx = ((a_option / 0x100) as int) - 1
476     if (pageIdx != -1)
477     Error("Option type mismatch. Expected toggle option, page \"" + Pages[pageIdx] + "\", index " + index)
478     else
479     Error("Option type mismatch. Expected toggle option, page \"\", index " + index)
480     endIf
481     return
482     endIf
483    
484     SetOptionNumValue(index, a_checked as int, a_noUpdate)
485     endfunction
486    
487     ; @interface
488     function SetSliderOptionValue(int a_option, float a_value, string a_formatString = "{0}", bool a_noUpdate = false)
489     int index = a_option % 0x100
490     int type = _optionFlagsBuf[index] % 0x100
491    
492     if (type != OPTION_TYPE_SLIDER)
493     int pageIdx = ((a_option / 0x100) as int) - 1
494     if (pageIdx != -1)
495     Error("Option type mismatch. Expected slider option, page \"" + Pages[pageIdx] + "\", index " + index)
496     else
497     Error("Option type mismatch. Expected slider option, page \"\", index " + index)
498     endIf
499     return
500     endIf
501    
502     SetOptionValues(index, a_formatString, a_value, a_noUpdate)
503     endFunction
504    
505     ; @interface
506     function SetMenuOptionValue(int a_option, string a_value, bool a_noUpdate = false)
507     int index = a_option % 0x100
508     int type = _optionFlagsBuf[index] % 0x100
509    
510     if (type != OPTION_TYPE_MENU)
511     int pageIdx = ((a_option / 0x100) as int) - 1
512     if (pageIdx != -1)
513     Error("Option type mismatch. Expected menu option, page \"" + Pages[pageIdx] + "\", index " + index)
514     else
515     Error("Option type mismatch. Expected menu option, page \"\", index " + index)
516     endIf
517     return
518     endIf
519    
520     SetOptionStrValue(index, a_value, a_noUpdate)
521     endFunction
522    
523     ; @interface
524     function SetColorOptionValue(int a_option, int a_color, bool a_noUpdate = false)
525     int index = a_option % 0x100
526     int type = _optionFlagsBuf[index] % 0x100
527    
528     if (type != OPTION_TYPE_COLOR)
529     int pageIdx = ((a_option / 0x100) as int) - 1
530     if (pageIdx != -1)
531     Error("Option type mismatch. Expected color option, page \"" + Pages[pageIdx] + "\", index " + index)
532     else
533     Error("Option type mismatch. Expected color option, page \"\", index " + index)
534     endIf
535     return
536     endIf
537    
538     SetOptionNumValue(index, a_color, a_noUpdate)
539     endFunction
540    
541     ; @interface
542     function SetKeyMapOptionValue(int a_option, int a_keyCode, bool a_noUpdate = false)
543     int index = a_option % 0x100
544     int type = _optionFlagsBuf[index] % 0x100
545    
546     if (type != OPTION_TYPE_KEYMAP)
547     int pageIdx = ((a_option / 0x100) as int) - 1
548     if (pageIdx != -1)
549     Error("Option type mismatch. Expected keymap option, page \"" + Pages[pageIdx] + "\", index " + index)
550     else
551     Error("Option type mismatch. Expected keymap option, page \"\", index " + index)
552     endIf
553     return
554     endIf
555    
556     SetOptionNumValue(index, a_keyCode, a_noUpdate)
557     endFunction
558    
559     ; @interface
560     function SetOptionFlagsST(int a_flags, bool a_noUpdate = false, string a_stateName = "")
561     if (_state == STATE_RESET)
562     Error("Cannot set option flags while in OnPageReset(). Pass flags to AddOption instead")
563     return
564     endIf
565    
566     int index = GetStateOptionIndex(a_stateName)
567     if (index < 0)
568     Error("Cannot use SetOptionFlagsST outside a valid option state")
569     return
570     endIf
571    
572     SetOptionFlags(index, a_flags, a_noUpdate)
573     endFunction
574    
575     ; @interface
576     function SetTextOptionValueST(string a_value, bool a_noUpdate = false, string a_stateName = "")
577     int index = GetStateOptionIndex(a_stateName)
578     if (index < 0)
579     Error("Cannot use SetTextOptionValueST outside a valid option state")
580     return
581     endIf
582    
583     SetTextOptionValue(index, a_value, a_noUpdate)
584     endFunction
585    
586     ; @interface
587     function SetToggleOptionValueST(bool a_checked, bool a_noUpdate = false, string a_stateName = "")
588     int index = GetStateOptionIndex(a_stateName)
589     if (index < 0)
590     Error("Cannot use SetToggleOptionValueST outside a valid option state")
591     return
592     endIf
593    
594     SetToggleOptionValue(index, a_checked, a_noUpdate)
595     endFunction
596    
597     ; @interface
598     function SetSliderOptionValueST(float a_value, string a_formatString = "{0}", bool a_noUpdate = false, string a_stateName = "")
599     int index = GetStateOptionIndex(a_stateName)
600     if (index < 0)
601     Error("Cannot use SetSliderOptionValueST outside a valid option state")
602     return
603     endIf
604    
605     SetSliderOptionValue(index, a_value, a_formatString, a_noUpdate)
606     endFunction
607    
608     ; @interface
609     function SetMenuOptionValueST(string a_value, bool a_noUpdate = false, string a_stateName = "")
610     int index = GetStateOptionIndex(a_stateName)
611     if (index < 0)
612     Error("Cannot use SetMenuOptionValueST outside a valid option state")
613     return
614     endIf
615    
616     SetMenuOptionValue(index, a_value, a_noUpdate)
617     endFunction
618    
619     ; @interface
620     function SetColorOptionValueST(int a_color, bool a_noUpdate = false, string a_stateName = "")
621     int index = GetStateOptionIndex(a_stateName)
622     if (index < 0)
623     Error("Cannot use SetColorOptionValueST outside a valid option state")
624     return
625     endIf
626    
627     SetColorOptionValue(index, a_color, a_noUpdate)
628     endFunction
629    
630     ; @interface
631     function SetKeyMapOptionValueST(int a_keyCode, bool a_noUpdate = false, string a_stateName = "")
632     int index = GetStateOptionIndex(a_stateName)
633     if (index < 0)
634     Error("Cannot use SetKeyMapOptionValueST outside a valid option state")
635     return
636     endIf
637    
638     SetKeyMapOptionValue(index, a_keyCode, a_noUpdate)
639     endFunction
640    
641     ; @interface
642     function SetSliderDialogStartValue(float a_value)
643     if (_state != STATE_SLIDER)
644     Error("Cannot set slider dialog params while outside OnOptionSliderOpen()")
645     return
646     endIf
647    
648     _sliderParams[0] = a_value
649     endFunction
650    
651     ; @interface
652     function SetSliderDialogDefaultValue(float a_value)
653     if (_state != STATE_SLIDER)
654     Error("Cannot set slider dialog params while outside OnOptionSliderOpen()")
655     return
656     endIf
657    
658     _sliderParams[1] = a_value
659     endFunction
660    
661     ; @interface
662     function SetSliderDialogRange(float a_minValue, float a_maxValue)
663     if (_state != STATE_SLIDER)
664     Error("Cannot set slider dialog params while outside OnOptionSliderOpen()")
665     return
666     endIf
667    
668     _sliderParams[2] = a_minValue
669     _sliderParams[3] = a_maxValue
670     endFunction
671    
672     ; @interface
673     function SetSliderDialogInterval(float a_value)
674     if (_state != STATE_SLIDER)
675     Error("Cannot set slider dialog params while outside OnOptionSliderOpen()")
676     return
677     endIf
678    
679     _sliderParams[4] = a_value
680     endFunction
681    
682     ; @interface
683     function SetMenuDialogStartIndex(int a_value)
684     if (_state != STATE_MENU)
685     Error("Cannot set menu dialog params while outside OnOptionMenuOpen()")
686     return
687     endIf
688    
689     _menuParams[0] = a_value
690     endFunction
691    
692     ; @interface
693     function SetMenuDialogDefaultIndex(int a_value)
694     if (_state != STATE_MENU)
695     Error("Cannot set menu dialog params while outside OnOptionMenuOpen()")
696     return
697     endIf
698    
699     _menuParams[1] = a_value
700     endFunction
701    
702     ; @interface
703     function SetMenuDialogOptions(string[] a_options)
704     if (_state != STATE_MENU)
705     Error("Cannot set menu dialog params while outside OnOptionMenuOpen()")
706     return
707     endIf
708    
709     UI.InvokeStringA(JOURNAL_MENU, MENU_ROOT + ".setMenuDialogOptions", a_options)
710     endFunction
711    
712     ; @interface
713     function SetColorDialogStartColor(int a_color)
714     if (_state != STATE_COLOR)
715     Error("Cannot set color dialog params while outside OnOptionColorOpen()")
716     return
717     endIf
718    
719     _colorParams[0] = a_color
720     endFunction
721    
722     ; @interface
723     function SetColorDialogDefaultColor(int a_color)
724     if (_state != STATE_COLOR)
725     Error("Cannot set color dialog params while outside OnOptionColorOpen()")
726     return
727     endIf
728    
729     _colorParams[1] = a_color
730     endFunction
731    
732     ; @interface
733     bool function ShowMessage(string a_message, bool a_withCancel = true, string a_acceptLabel = "$Accept", string a_cancelLabel = "$Cancel")
734     if (_waitForMessage)
735     Error("Called ShowMessage() while another message was already open")
736     return false
737     endIf
738    
739     _waitForMessage = true
740     _messageResult = false
741    
742     string[] params = new string[3]
743     params[0] = a_message
744     params[1] = a_acceptLabel
745     if (a_withCancel)
746     params[2] = a_cancelLabel
747     else
748     params[2] = ""
749     endIf
750    
751     RegisterForModEvent("SKICP_messageDialogClosed", "OnMessageDialogClose")
752     UI.InvokeStringA(JOURNAL_MENU, MENU_ROOT + ".showMessageDialog", params)
753    
754     ; Wait for result
755     while (_waitForMessage)
756     Utility.WaitMenuMode(0.1)
757     endWhile
758    
759     UnregisterForModEvent("SKICP_messageDialogClosed")
760    
761     return _messageResult
762     endFunction
763    
764     function Error(string a_msg)
765     ;Debug.Trace(self + " ERROR: " + a_msg)
766     endFunction
767    
768     function OpenConfig()
769     ; Alloc
770     _optionFlagsBuf = new int[128]
771     _textBuf = new string[128]
772     _strValueBuf = new string[128]
773     _numValueBuf = new float[128]
774     _stateOptionMap = new string[128]
775    
776     SetPage("", -1)
777    
778     OnConfigOpen()
779    
780     UI.InvokeStringA(JOURNAL_MENU, MENU_ROOT + ".setPageNames", Pages)
781     endFunction
782    
783     function CloseConfig()
784     OnConfigClose()
785     ClearOptionBuffers()
786     _waitForMessage = false
787    
788     ; Free
789     _optionFlagsBuf = new int[1]
790     _textBuf = new string[1]
791     _strValueBuf = new string[1]
792     _numValueBuf = new float[1]
793     _stateOptionMap = new string[1]
794     endFunction
795    
796     function SetPage(string a_page, int a_index)
797     _currentPage = a_page
798     _currentPageNum = 1+a_index
799    
800     ; Set default title, can be overridden in OnPageReset
801     if (a_page != "")
802     SetTitleText(a_page)
803     else
804     SetTitleText(ModName)
805     endIf
806    
807     ClearOptionBuffers()
808     _state = STATE_RESET
809     OnPageReset(a_page)
810     _state = STATE_DEFAULT
811     WriteOptionBuffers()
812     endFunction
813    
814     int function AddOption(int a_optionType, string a_text, string a_strValue, float a_numValue, int a_flags)
815     if (_state != STATE_RESET)
816     Error("Cannot add option " + a_text + " outside of OnPageReset()")
817     return -1
818     endIf
819    
820     int pos = _cursorPosition
821     if (pos == -1)
822     return -1 ; invalid
823     endIf
824    
825     _optionFlagsBuf[pos] = a_optionType + a_flags * 0x100
826     _textBuf[pos] = a_text
827     _strValueBuf[pos] = a_strValue
828     _numValueBuf[pos] = a_numValue
829    
830     ; Just use numerical value of fill mode
831     _cursorPosition += _cursorFillMode
832     if (_cursorPosition >= 128)
833     _cursorPosition = -1
834     endIf
835    
836     ; byte 1 - position
837     ; byte 2 - page
838     return pos + _currentPageNum * 0x100
839     endFunction
840    
841     function AddOptionST(string a_stateName, int a_optionType, string a_text, string a_strValue, float a_numValue, int a_flags)
842     if (_stateOptionMap.find(a_stateName) != -1)
843     Error("State option name " + a_stateName + " is already in use")
844     return
845     endIf
846    
847     int index = AddOption(a_optionType, a_text, a_strValue, a_numValue, a_flags) % 0x100
848     if (index < 0)
849     return
850     endIf
851    
852     if (_stateOptionMap[index] != "")
853     Error("State option index " + index + " already in use")
854     return
855     endIf
856    
857     _stateOptionMap[index] = a_stateName
858     endFunction
859    
860     int function GetStateOptionIndex(string a_stateName)
861     if (a_stateName == "")
862     a_stateName = GetState()
863     endIf
864    
865     if (a_stateName == "")
866     return -1
867     endIf
868    
869     return _stateOptionMap.find(a_stateName)
870     endFunction
871    
872     function WriteOptionBuffers()
873     string menu = JOURNAL_MENU
874     string root = MENU_ROOT
875     int t = OPTION_TYPE_EMPTY
876     int i = 0
877     int optionCount = 0;
878    
879     ; Tell UI where to cut off the buffer
880     i = 0
881     while (i < 128)
882     if (_optionFlagsBuf[i] != t)
883     optionCount = i + 1
884     endif
885     i += 1
886     endWhile
887    
888     UI.InvokeIntA(menu, root + ".setOptionFlagsBuffer", _optionFlagsBuf)
889     UI.InvokeStringA(menu, root + ".setOptionTextBuffer", _textBuf)
890     UI.InvokeStringA(menu, root + ".setOptionStrValueBuffer", _strValueBuf)
891     UI.InvokeFloatA(menu, root + ".setOptionNumValueBuffer", _numValueBuf)
892     UI.InvokeInt(menu, root + ".flushOptionBuffers", optionCount)
893     endFunction
894    
895     function ClearOptionBuffers()
896     int t = OPTION_TYPE_EMPTY
897     int i = 0
898     while (i < 128)
899     _optionFlagsBuf[i] = t
900     _textBuf[i] = ""
901     _strValueBuf[i] = ""
902     _numValueBuf[i] = 0
903    
904     ; Also clear state map as it's tied to the buffers
905     _stateOptionMap[i] = ""
906     i += 1
907     endWhile
908    
909     _cursorPosition = 0
910     _cursorFillMode = LEFT_TO_RIGHT
911     endFunction
912    
913     function SetOptionStrValue(int a_index, string a_strValue, bool a_noUpdate)
914     if (_state == STATE_RESET)
915     Error("Cannot modify option data while in OnPageReset()")
916     return
917     endIf
918    
919     string menu = JOURNAL_MENU
920     string root = MENU_ROOT
921    
922     UI.SetInt(menu, root + ".optionCursorIndex", a_index)
923     UI.SetString(menu, root + ".optionCursor.strValue", a_strValue)
924     if (!a_noUpdate)
925     UI.Invoke(menu, root + ".invalidateOptionData")
926     endIf
927     endFunction
928    
929     function SetOptionNumValue(int a_index, float a_numValue, bool a_noUpdate)
930     if (_state == STATE_RESET)
931     Error("Cannot modify option data while in OnPageReset()")
932     return
933     endIf
934    
935     string menu = JOURNAL_MENU
936     string root = MENU_ROOT
937    
938     UI.SetInt(menu, root + ".optionCursorIndex", a_index)
939     UI.SetFloat(menu, root + ".optionCursor.numValue", a_numValue)
940     if (!a_noUpdate)
941     UI.Invoke(menu, root + ".invalidateOptionData")
942     endIf
943     endFunction
944    
945     function SetOptionValues(int a_index, string a_strValue, float a_numValue, bool a_noUpdate)
946     if (_state == STATE_RESET)
947     Error("Cannot modify option data while in OnPageReset()")
948     return
949     endIf
950    
951     string menu = JOURNAL_MENU
952     string root = MENU_ROOT
953    
954     UI.SetInt(menu, root + ".optionCursorIndex", a_index)
955     UI.SetString(menu, root + ".optionCursor.strValue", a_strValue)
956     UI.SetFloat(menu, root + ".optionCursor.numValue", a_numValue)
957     if (!a_noUpdate)
958     UI.Invoke(menu, root + ".invalidateOptionData")
959     endIf
960     endFunction
961    
962     function RequestSliderDialogData(int a_index)
963     _activeOption = a_index + _currentPageNum * 0x100
964    
965     ; Defaults
966     _sliderParams[0] = 0
967     _sliderParams[1] = 0
968     _sliderParams[2] = 0
969     _sliderParams[3] = 1
970     _sliderParams[4] = 1
971    
972     _state = STATE_SLIDER
973    
974     string optionState = _stateOptionMap[a_index]
975     if (optionState != "")
976     string oldState = GetState()
977     gotoState(optionState)
978     OnSliderOpenST()
979     gotoState(oldState)
980     else
981     OnOptionSliderOpen(_activeOption)
982     endIf
983    
984     _state = STATE_DEFAULT
985    
986     UI.InvokeFloatA(JOURNAL_MENU, MENU_ROOT + ".setSliderDialogParams", _sliderParams)
987     endFunction
988    
989     function RequestMenuDialogData(int a_index)
990     _activeOption = a_index + _currentPageNum * 0x100
991    
992     ; Defaults
993     _menuParams[0] = -1
994     _menuParams[1] = -1
995    
996     _state = STATE_MENU
997    
998     string optionState = _stateOptionMap[a_index]
999     if (optionState != "")
1000     string oldState = GetState()
1001     gotoState(optionState)
1002     OnMenuOpenST()
1003     gotoState(oldState)
1004     else
1005     OnOptionMenuOpen(_activeOption)
1006     endIf
1007    
1008     _state = STATE_DEFAULT
1009    
1010     UI.InvokeIntA(JOURNAL_MENU, MENU_ROOT + ".setMenuDialogParams", _menuParams)
1011     endFunction
1012    
1013     function RequestColorDialogData(int a_index)
1014     _activeOption = a_index + _currentPageNum * 0x100
1015    
1016     ; Defaults
1017     _colorParams[0] = -1
1018     _colorParams[1] = -1
1019    
1020     _state = STATE_COLOR
1021    
1022     string optionState = _stateOptionMap[a_index]
1023     if (optionState != "")
1024     string oldState = GetState()
1025     gotoState(optionState)
1026     OnColorOpenST()
1027     gotoState(oldState)
1028     else
1029     OnOptionColorOpen(_activeOption)
1030     endIf
1031    
1032     _state = STATE_DEFAULT
1033    
1034     UI.InvokeIntA(JOURNAL_MENU, MENU_ROOT + ".setColorDialogParams", _colorParams)
1035     endFunction
1036    
1037     function SetSliderValue(float a_value)
1038     string optionState = _stateOptionMap[_activeOption % 0x100]
1039     if (optionState != "")
1040     string oldState = GetState()
1041     gotoState(optionState)
1042     OnSliderAcceptST(a_value)
1043     gotoState(oldState)
1044     else
1045     OnOptionSliderAccept(_activeOption, a_value)
1046     endIf
1047     _activeOption = -1
1048     endFunction
1049    
1050     function SetMenuIndex(int a_index)
1051     string optionState = _stateOptionMap[_activeOption % 0x100]
1052     if (optionState != "")
1053     string oldState = GetState()
1054     gotoState(optionState)
1055     OnMenuAcceptST(a_index)
1056     gotoState(oldState)
1057     else
1058     OnOptionMenuAccept(_activeOption, a_index)
1059     endIf
1060     _activeOption = -1
1061     endFunction
1062    
1063     function SetColorValue(int a_color)
1064     string optionState = _stateOptionMap[_activeOption % 0x100]
1065     if (optionState != "")
1066     string oldState = GetState()
1067     gotoState(optionState)
1068     OnColorAcceptST(a_color)
1069     gotoState(oldState)
1070     else
1071     OnOptionColorAccept(_activeOption, a_color)
1072     endIf
1073     _activeOption = -1
1074     endFunction
1075    
1076     function SelectOption(int a_index)
1077     string optionState = _stateOptionMap[a_index]
1078     if (optionState != "")
1079     string oldState = GetState()
1080     gotoState(optionState)
1081     OnSelectST()
1082     gotoState(oldState)
1083     else
1084     int option = a_index + _currentPageNum * 0x100
1085     OnOptionSelect(option)
1086     endIf
1087     endFunction
1088    
1089     function ResetOption(int a_index)
1090     string optionState = _stateOptionMap[a_index]
1091     if (optionState != "")
1092     string oldState = GetState()
1093     gotoState(optionState)
1094     OnDefaultST()
1095     gotoState(oldState)
1096     else
1097     int option = a_index + _currentPageNum * 0x100
1098     OnOptionDefault(option)
1099     endIf
1100     endFunction
1101    
1102     function HighlightOption(int a_index)
1103     _infoText = ""
1104    
1105     if (a_index != -1)
1106     string optionState = _stateOptionMap[a_index]
1107     if (optionState != "")
1108     string oldState = GetState()
1109     gotoState(optionState)
1110     OnHighlightST()
1111     gotoState(oldState)
1112     else
1113     int option = a_index + _currentPageNum * 0x100
1114     OnOptionHighlight(option)
1115     endIf
1116     endIf
1117    
1118     UI.InvokeString(JOURNAL_MENU, MENU_ROOT + ".setInfoText", _infoText)
1119     endFunction
1120    
1121     function RemapKey(int a_index, int a_keyCode, string a_conflictControl, string a_conflictName)
1122     string optionState = _stateOptionMap[a_index]
1123     if (optionState != "")
1124     string oldState = GetState()
1125     gotoState(optionState)
1126     OnKeyMapChangeST(a_keyCode, a_conflictControl, a_conflictName)
1127     gotoState(oldState)
1128     else
1129     int option = a_index + _currentPageNum * 0x100
1130     OnOptionKeyMapChange(option, a_keyCode, a_conflictControl, a_conflictName)
1131     endIf
1132     endFunction

  ViewVC Help
Powered by ViewVC 1.1.22