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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations) (download)
Sat Aug 12 15:05:05 2017 UTC (2 years, 6 months ago) by william
File size: 4607 byte(s)
commit scripts for skyui 5.1
1 william 3 scriptname SKI_WidgetManager extends SKI_QuestBase
2    
3     ; CONSTANTS ---------------------------------------------------------------------------------------
4    
5     string property HUD_MENU = "HUD Menu" autoReadOnly
6    
7    
8     ; PRIVATE VARIABLES -------------------------------------------------------------------------------
9    
10     SKI_WidgetBase[] _widgets
11     string[] _widgetSources
12     int _curWidgetID = 0
13     int _widgetCount = 0
14    
15    
16     ; INITIALIZATION ----------------------------------------------------------------------------------
17    
18     event OnInit()
19     _widgets = new SKI_WidgetBase[128]
20     _widgetSources = new string[128]
21    
22     ; Wait until all widgets have registered their callbacks
23     Utility.Wait(0.5)
24    
25     OnGameReload()
26     endEvent
27    
28     event OnGameReload()
29     RegisterForModEvent("SKIWF_widgetLoaded", "OnWidgetLoad")
30     RegisterForModEvent("SKIWF_widgetError", "OnWidgetError")
31    
32     CleanUp()
33    
34     ; Init now, or delay until hudmenu has been loaded
35     if (UI.IsMenuOpen(HUD_MENU))
36     InitWidgetLoader()
37     else
38     RegisterForMenu(HUD_MENU)
39     endIf
40     endEvent
41    
42     event OnMenuOpen(string a_menuName)
43     if (a_menuName == HUD_MENU)
44     UnregisterForMenu(HUD_MENU)
45     InitWidgetLoader()
46     endIf
47     endEvent
48    
49     function CleanUp()
50     _widgetCount = 0
51     int i = 0
52    
53     while (i < _widgets.length)
54     if (_widgets[i] == none || _widgets[i].GetFormID() == 0)
55     ; Widget no longer exists
56     _widgets[i] = none
57     _widgetSources[i] = ""
58     else
59     _widgetCount += 1
60     endIf
61     i += 1
62     endWhile
63     endFunction
64    
65     function InitWidgetLoader()
66     Debug.Trace("InitWidgetLoader()")
67    
68     int releaseIdx = UI.GetInt(HUD_MENU, "_global.WidgetLoader.SKYUI_RELEASE_IDX")
69    
70     ; Not injected yet
71     if (releaseIdx == 0)
72    
73     ; Interface/
74     string rootPath = ""
75    
76     string[] args = new string[2]
77     args[0] = "widgetLoaderContainer"
78     args[1] = "-1000"
79    
80     ; Create empty container clip
81     UI.InvokeStringA(HUD_MENU, "_root.createEmptyMovieClip", args)
82    
83     ; Try to load from Interface/exported/hudmenu.gfx
84     UI.InvokeString(HUD_MENU, "_root.widgetLoaderContainer.loadMovie", "skyui/widgetloader.swf")
85     Utility.Wait(0.5)
86     releaseIdx = UI.GetInt(HUD_MENU, "_global.WidgetLoader.SKYUI_RELEASE_IDX")
87    
88     ; If failed, try to load from Interface/hudmenu.swf
89     if (releaseIdx == 0)
90     ; Interface/exported
91     rootPath = "exported/"
92     UI.InvokeString(HUD_MENU, "_root.widgetLoaderContainer.loadMovie", "exported/skyui/widgetloader.swf")
93     Utility.Wait(0.5)
94     releaseIdx = UI.GetInt(HUD_MENU, "_global.WidgetLoader.SKYUI_RELEASE_IDX")
95     endIf
96    
97     ; Injection failed
98     if (releaseIdx == 0)
99     Debug.Trace("InitWidgetLoader(): load failed")
100     return
101     endIf
102    
103     UI.InvokeString(HUD_MENU, "_root.widgetLoaderContainer.widgetLoader.setRootPath", rootPath)
104     endIf
105    
106     ; Load already registered widgets
107     UI.InvokeStringA(HUD_MENU, "_root.widgetLoaderContainer.widgetLoader.loadWidgets", _widgetSources)
108    
109     SendModEvent("SKIWF_widgetManagerReady")
110     endFunction
111    
112    
113     ; EVENTS ------------------------------------------------------------------------------------------
114    
115     event OnWidgetLoad(string a_eventName, string a_strArg, float a_numArg, form a_sender)
116     int widgetID = a_strArg as int
117     SKI_WidgetBase client = _widgets[widgetID]
118    
119     if (client != none)
120     client.OnWidgetLoad()
121     endIf
122     endEvent
123    
124     event OnWidgetError(string a_eventName, string a_strArg, float a_numArg, form a_sender)
125     int widgetID = a_numArg as int
126     string errorType = a_strArg
127    
128     Debug.Trace("WidgetError: " + (_widgets[widgetID] as string) + ": " + errorType)
129     endEvent
130    
131    
132     ; FUNCTIONS ---------------------------------------------------------------------------------------
133    
134     int function RequestWidgetID(SKI_WidgetBase a_client)
135     if (_widgetCount >= 128)
136     return -1
137     endIf
138    
139     int widgetID = NextWidgetID()
140     _widgets[widgetID] = a_client
141     _widgetCount += 1
142    
143     return widgetID
144     endFunction
145    
146     int function NextWidgetID()
147     int startIdx = _curWidgetID
148    
149     while (_widgets[_curWidgetID] != none)
150     _curWidgetID += 1
151     if (_curWidgetID >= 128)
152     _curWidgetID = 0
153     endIf
154     if (_curWidgetID == startIdx)
155     return -1 ; Should never happen because we have widgetCount. Just to be sure.
156     endIf
157     endWhile
158    
159     return _curWidgetID
160     endFunction
161    
162     function CreateWidget(int a_widgetID, string a_widgetSource)
163     _widgetSources[a_widgetID] = a_widgetSource
164     string[] args = new string[2]
165     args[0] = a_widgetID as string
166     args[1] = a_widgetSource
167     UI.InvokeStringA(HUD_MENU, "_root.widgetLoaderContainer.widgetLoader.loadWidget", args);
168     endFunction
169    
170     SKI_WidgetBase[] function GetWidgets()
171     ; Return a copy
172     SKI_WidgetBase[] widgetsCopy = new SKI_WidgetBase[128]
173     int i = 0
174    
175     while (i < _widgets.length)
176     widgetsCopy[i] = _widgets[i]
177     i += 1
178     endWhile
179    
180     return widgetsCopy
181     endFunction

  ViewVC Help
Powered by ViewVC 1.1.22