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

Contents of /branch/skyui_510/Source/ski_main.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: 9860 byte(s)
commit scripts for skyui 5.1
1 scriptname SKI_Main extends SKI_QuestBase
2
3 ; CONSTANTS ---------------------------------------------------------------------------------------
4
5 string property HUD_MENU = "HUD Menu" autoReadOnly
6 string property INVENTORY_MENU = "InventoryMenu" autoReadonly
7 string property MAGIC_MENU = "MagicMenu" autoReadonly
8 string property CONTAINER_MENU = "ContainerMenu" autoReadonly
9 string property BARTER_MENU = "BarterMenu" autoReadonly
10 string property GIFT_MENU = "GiftMenu" autoReadonly
11 string property JOURNAL_MENU = "Journal Menu" autoReadonly
12 string property MAP_MENU = "MapMenu" autoReadonly
13 string property FAVORITES_MENU = "FavoritesMenu" autoReadonly
14 string property CRAFTING_MENU = "Crafting Menu" autoReadonly
15
16 int property ERR_SKSE_MISSING = 1 autoReadonly
17 int property ERR_SKSE_VERSION_RT = 2 autoReadonly
18 int property ERR_SKSE_VERSION_SCPT = 3 autoReadonly
19 int property ERR_INI_PAPYRUS = 4 autoReadonly
20 int property ERR_SWF_INVALID = 5 autoReadonly
21 int property ERR_SWF_VERSION = 6 autoReadonly
22 int property ERR_SKSE_BROKEN = 7 autoReadonly
23
24
25 ; PRIVATE VARIABLES -------------------------------------------------------------------------------
26
27 bool _inventoryMenuCheckEnabled = true
28 bool _magicMenuCheckEnabled = true
29 bool _barterMenuCheckEnabled = true
30 bool _containerMenuCheckEnabled = true
31 bool _giftMenuCheckEnabled = true
32 bool _mapMenuCheckEnabled = true
33 bool _favoritesMenuCheckEnabled = true
34 bool _craftingMenuCheckEnabled = true
35
36
37 ; PROPERTIES --------------------------------------------------------------------------------------
38
39 int property MinSKSERelease = 44 autoReadonly
40 string property MinSKSEVersion = "1.6.16" autoReadonly
41
42 int property ReqSWFRelease = 17 autoReadonly
43 string property ReqSWFVersion = "5.0" autoReadonly
44
45 bool property ErrorDetected = false auto
46
47
48 bool property InventoryMenuCheckEnabled
49 bool function get()
50 return _inventoryMenuCheckEnabled
51 endFunction
52
53 function set(bool a_val)
54 _inventoryMenuCheckEnabled = a_val
55 if (a_val)
56 RegisterForMenu(INVENTORY_MENU)
57 else
58 UnregisterForMenu(INVENTORY_MENU)
59 endIf
60 endFunction
61 endProperty
62
63 bool property MagicMenuCheckEnabled
64 bool function get()
65 return _magicMenuCheckEnabled
66 endFunction
67
68 function set(bool a_val)
69 _magicMenuCheckEnabled = a_val
70 if (a_val)
71 RegisterForMenu(MAGIC_MENU)
72 else
73 UnregisterForMenu(MAGIC_MENU)
74 endIf
75 endFunction
76 endProperty
77
78 bool property BarterMenuCheckEnabled
79 bool function get()
80 return _barterMenuCheckEnabled
81 endFunction
82
83 function set(bool a_val)
84 _barterMenuCheckEnabled = a_val
85 if (a_val)
86 RegisterForMenu(BARTER_MENU)
87 else
88 UnregisterForMenu(BARTER_MENU)
89 endIf
90 endFunction
91 endProperty
92
93 bool property ContainerMenuCheckEnabled
94 bool function get()
95 return _containerMenuCheckEnabled
96 endFunction
97
98 function set(bool a_val)
99 _containerMenuCheckEnabled = a_val
100 if (a_val)
101 RegisterForMenu(CONTAINER_MENU)
102 else
103 UnregisterForMenu(CONTAINER_MENU)
104 endIf
105 endFunction
106 endProperty
107
108 bool property GiftMenuCheckEnabled
109 bool function get()
110 return _giftMenuCheckEnabled
111 endFunction
112
113 function set(bool a_val)
114 _giftMenuCheckEnabled = a_val
115 if (a_val)
116 RegisterForMenu(GIFT_MENU)
117 else
118 UnregisterForMenu(GIFT_MENU)
119 endIf
120 endFunction
121 endProperty
122
123 bool property MapMenuCheckEnabled
124 bool function get()
125 return _mapMenuCheckEnabled
126 endFunction
127
128 function set(bool a_val)
129 _mapMenuCheckEnabled = a_val
130 if (a_val)
131 RegisterForMenu(MAP_MENU)
132 else
133 UnregisterForMenu(MAP_MENU)
134 endIf
135 endFunction
136 endProperty
137
138 bool property FavoritesMenuCheckEnabled
139 bool function get()
140 return _favoritesMenuCheckEnabled
141 endFunction
142
143 function set(bool a_val)
144 _favoritesMenuCheckEnabled = a_val
145 if (a_val)
146 RegisterForMenu(FAVORITES_MENU)
147 else
148 UnregisterForMenu(FAVORITES_MENU)
149 endIf
150 endFunction
151 endProperty
152
153 bool property CraftingMenuCheckEnabled
154 bool function get()
155 return _craftingMenuCheckEnabled
156 endFunction
157
158 function set(bool a_val)
159 _craftingMenuCheckEnabled = a_val
160 if (a_val)
161 RegisterForMenu(CRAFTING_MENU)
162 else
163 UnregisterForMenu(CRAFTING_MENU)
164 endIf
165 endFunction
166 endProperty
167
168
169 ; INITIALIZATION ----------------------------------------------------------------------------------
170
171 event OnInit()
172 OnGameReload()
173 endEvent
174
175 ; @implements SKI_QuestBase
176 event OnGameReload()
177 ErrorDetected = false
178
179 if (SKSE.GetVersionRelease() == 0)
180 Error(ERR_SKSE_MISSING, "The Skyrim Script Extender (SKSE) is not running.\nSkyUI will not work correctly!\n\n" \
181 + "This message may also appear if a new Skyrim Patch has been released. In this case, wait until SKSE has been updated, then install the new version.")
182 return
183
184 elseIf (GetType() == 0)
185 Error(ERR_SKSE_BROKEN, "The SKSE scripts have been overwritten or are not properly loaded.\nReinstalling SKSE might fix this.")
186 return
187
188 elseIf (SKSE.GetVersionRelease() < MinSKSERelease)
189 Error(ERR_SKSE_VERSION_RT, "SKSE is outdated.\nSkyUI will not work correctly!\n" \
190 + "Required version: " + MinSKSEVersion + " or newer\n" \
191 + "Detected version: " + SKSE.GetVersion() + "." + SKSE.GetVersionMinor() + "." + SKSE.GetVersionBeta())
192 return
193
194 elseIf (SKSE.GetScriptVersionRelease() < MinSKSERelease)
195 Error(ERR_SKSE_VERSION_SCPT, "SKSE scripts are outdated.\nYou probably forgot to install/update them with the rest of SKSE.\nSkyUI will not work correctly!")
196 return
197 endIf
198
199 if (Utility.GetINIInt("iMinMemoryPageSize:Papyrus") <= 0 || Utility.GetINIInt("iMaxMemoryPageSize:Papyrus") <= 0 || Utility.GetINIInt("iMaxAllocatedMemoryBytes:Papyrus") <= 0)
200 Error(ERR_INI_PAPYRUS, "Your Papyrus INI settings are invalid. Please fix this, otherwise SkyUI will stop working at some point.")
201 return
202 endIf
203
204 ; Check menus, when they're opened
205 if (InventoryMenuCheckEnabled)
206 RegisterForMenu(INVENTORY_MENU)
207 endIf
208
209 if (MagicMenuCheckEnabled)
210 RegisterForMenu(MAGIC_MENU)
211 endIf
212
213 if (ContainerMenuCheckEnabled)
214 RegisterForMenu(CONTAINER_MENU)
215 endIf
216
217 if (BarterMenuCheckEnabled)
218 RegisterForMenu(BARTER_MENU)
219 endIf
220
221 if (GiftMenuCheckEnabled)
222 RegisterForMenu(GIFT_MENU)
223 endIf
224
225 if (MapMenuCheckEnabled)
226 RegisterForMenu(MAP_MENU)
227 endIf
228
229 if (FavoritesMenuCheckEnabled)
230 RegisterForMenu(FAVORITES_MENU)
231 endIf
232
233 if (CraftingMenuCheckEnabled)
234 RegisterForMenu(CRAFTING_MENU)
235 endIf
236
237 RegisterForMenu(JOURNAL_MENU)
238 endEvent
239
240
241 ; EVENTS ------------------------------------------------------------------------------------------
242
243 event OnMenuOpen(string a_menuName)
244 if (a_menuName == INVENTORY_MENU)
245 if (CheckMenuVersion("inventorymenu.swf", a_menuName, "_global.InventoryMenu") && \
246 CheckItemMenuComponents(a_menuName))
247 ; Only unregister if all checks have been performed (regardless of check result)
248 UnregisterForMenu(a_menuName)
249 endIf
250
251 elseIf (a_menuName == MAGIC_MENU)
252 if (CheckMenuVersion("magicmenu.swf", a_menuName, "_global.MagicMenu") && \
253 CheckItemMenuComponents(a_menuName))
254 UnregisterForMenu(a_menuName)
255 endIf
256
257 elseIf (a_menuName == CONTAINER_MENU)
258 if (CheckMenuVersion("containermenu.swf", a_menuName, "_global.ContainerMenu") && \
259 CheckItemMenuComponents(a_menuName))
260 UnregisterForMenu(a_menuName)
261 endIf
262
263 elseIf (a_menuName == BARTER_MENU)
264 if (CheckMenuVersion("bartermenu.swf", a_menuName, "_global.BarterMenu") && \
265 CheckItemMenuComponents(a_menuName))
266 UnregisterForMenu(a_menuName)
267 endIf
268
269 elseIf (a_menuName == GIFT_MENU)
270 if (CheckMenuVersion("giftmenu.swf", a_menuName, "_global.GiftMenu") && \
271 CheckItemMenuComponents(a_menuName))
272 UnregisterForMenu(a_menuName)
273 endIf
274
275 elseIf (a_menuName == JOURNAL_MENU)
276 if (CheckMenuVersion("quest_journal.swf", a_menuName, "_global.Quest_Journal") && \
277 CheckMenuVersion("skyui/configpanel.swf", a_menuName, "_global.ConfigPanel"))
278 UnregisterForMenu(a_menuName)
279 endIf
280
281 elseIf (a_menuName == MAP_MENU)
282 if (CheckMenuVersion("map.swf", a_menuName, "_global.Map.MapMenu"))
283 UnregisterForMenu(a_menuName)
284 endIf
285
286 elseIf (a_menuName == FAVORITES_MENU)
287 if (CheckMenuVersion("favoritesmenu.swf", a_menuName, "_global.FavoritesMenu"))
288 UnregisterForMenu(a_menuName)
289 endIf
290
291 elseIf (a_menuName == CRAFTING_MENU)
292 if (CheckMenuVersion("craftingmenu.swf", a_menuName, "_global.CraftingMenu"))
293 UnregisterForMenu(a_menuName)
294 endIf
295 endIf
296 endEvent
297
298
299 ; FUNCTIONS ---------------------------------------------------------------------------------------
300
301 function Error(int a_errId, string a_msg)
302 Debug.MessageBox("SKYUI ERROR CODE " + a_errId + "\n\n" + a_msg + "\n\nFor more help, visit the SkyUI download site.")
303 ErrorDetected = true
304 endFunction
305
306 bool function CheckMenuVersion(string a_swfName, string a_menu, string a_class)
307 ; Returns false if the menu is closed before UI.Get* receive their value
308
309 int releaseIdx = UI.GetInt(a_menu, a_class + ".SKYUI_RELEASE_IDX")
310 string version = UI.GetString(a_menu, a_class + ".SKYUI_VERSION_STRING")
311
312 if (!UI.IsMenuOpen(a_menu))
313 return false
314 endIf
315
316 if (releaseIdx == 0)
317 Error(ERR_SWF_INVALID, "Incompatible menu file (" + a_swfName + ").\nPlease make sure you installed everything correctly and no other mod has overwritten this file.\n" \
318 + "If you were using an older SkyUI version, un-install it and re-install the latest version.")
319
320 elseIf (releaseIdx != ReqSWFRelease)
321 Error(ERR_SWF_VERSION, "Menu file version mismatch for " + a_swfName + ".\n" \
322 + "Required version: " + ReqSWFVersion + "\n" \
323 + "Detected version: " + version)
324
325 endIf
326
327 return true
328 endFunction
329
330 bool function CheckItemMenuComponents(string a_menu)
331 ; Returns false if the menu is closed before all checks have finished
332
333 return CheckMenuVersion("skyui/itemcard.swf", a_menu, "_global.ItemCard") && \
334 CheckMenuVersion("skyui/bottombar.swf", a_menu, "_global.BottomBar") && \
335 CheckMenuVersion("skyui/inventorylists.swf", a_menu, "_global.InventoryLists")
336 endFunction

  ViewVC Help
Powered by ViewVC 1.1.22