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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Aug 12 15:05:05 2017 UTC (2 years, 2 months ago) by william
File size: 3324 byte(s)
commit scripts for skyui 5.1
1 scriptname SKI_SettingsManager extends SKI_QuestBase
2
3 ; CONSTANTS ---------------------------------------------------------------------------------------
4
5 string property MENU_ROOT = "_global.skyui.util.ConfigManager" autoReadonly
6
7 string property INVENTORY_MENU = "InventoryMenu" autoReadonly
8 string property MAGIC_MENU = "MagicMenu" autoReadonly
9 string property CONTAINER_MENU = "ContainerMenu" autoReadonly
10 string property BARTER_MENU = "BarterMenu" autoReadonly
11 string property GIFT_MENU = "GiftMenu" autoReadonly
12 string property CRAFTING_MENU = "Crafting Menu" autoReadonly
13
14
15 ; PRIVATE VARIABLES -------------------------------------------------------------------------------
16
17 int _overrideCount = 0
18 string[] _overrideKeys
19 string[] _overrideValues
20
21 string _currentMenu
22
23
24 ; INITIALIZATION ----------------------------------------------------------------------------------
25
26 event OnInit()
27 _overrideKeys = new string[128]
28 _overrideValues = new string[128]
29
30 int i = 0
31 while (i<128)
32 _overrideKeys[i] = ""
33 _overrideValues[i] = ""
34 i += 1
35 endWhile
36
37 OnGameReload()
38 endEvent
39
40 ; @implements SKI_QuestBase
41 event OnGameReload()
42 RegisterForMenu(INVENTORY_MENU)
43 RegisterForMenu(MAGIC_MENU)
44 RegisterForMenu(CONTAINER_MENU)
45 RegisterForMenu(BARTER_MENU)
46 RegisterForMenu(GIFT_MENU)
47 RegisterForMenu(CRAFTING_MENU)
48 RegisterForModEvent("SKICO_setConfigOverride", "OnSetConfigOverride")
49 endEvent
50
51
52 ; EVENTS ------------------------------------------------------------------------------------------
53
54 event OnMenuOpen(string a_menuName)
55 GotoState("LOCKED")
56 ; Check if it's still open
57 if (UI.IsMenuOpen(a_menuName))
58 _currentMenu = a_menuName
59 UI.InvokeStringA(a_menuName, MENU_ROOT + ".setExternalOverrideKeys", _overrideKeys)
60 UI.InvokeStringA(a_menuName, MENU_ROOT + ".setExternalOverrideValues", _overrideValues)
61 endIf
62 GotoState("")
63 endEvent
64
65 event OnSetConfigOverride(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
66 string overrideKey = a_strArg
67 string overrideValue = UI.GetString(_currentMenu, MENU_ROOT + ".out_overrides." + overrideKey)
68
69 SetOverride(overrideKey, overrideValue)
70 endEvent
71
72 ; ----------------------------------------------
73 state LOCKED
74
75 event OnMenuOpen(string a_menuName)
76 endEvent
77
78 endState
79
80
81 ; FUNCTIONS ---------------------------------------------------------------------------------------
82
83 ; @interface
84 bool function SetOverride(string a_key, string a_value)
85 if (a_key == "")
86 return false
87 endIf
88
89 ; Existing override?
90 int index = _overrideKeys.Find(a_key)
91 if (index != -1)
92 _overrideValues[index] = a_value
93
94 return true
95
96 ; New override
97 else
98 if (_overrideCount >= 128)
99 return false
100 endIf
101
102 index = NextFreeIndex()
103 if (index == -1)
104 return false
105 endIf
106
107 _overrideKeys[index] = a_key
108 _overrideValues[index] = a_value
109 _overrideCount += 1
110
111 return true
112 endIf
113
114 endFunction
115
116 ; @interface
117 bool function ClearOverride(string a_key)
118 if (a_key == "")
119 return false
120 endIf
121
122 int index = _overrideKeys.Find(a_key)
123 if (index == -1)
124 return false
125 endIf
126
127 _overrideKeys[index] = ""
128 _overrideValues[index] = ""
129 _overrideCount -= 1
130
131 return true
132 endFunction
133
134 int function NextFreeIndex()
135 int i = 0
136
137 while (i < _overrideKeys.length)
138 if (_overrideKeys[i] == "")
139 return i
140 endIf
141 i += 1
142 endWhile
143
144 return -1
145 endFunction

  ViewVC Help
Powered by ViewVC 1.1.22