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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Aug 12 15:05:05 2017 UTC (23 months ago) by william
File size: 7472 byte(s)
commit scripts for skyui 5.1
1 scriptname SKI_WidgetBase extends SKI_QuestBase
2
3 ; CONSTANTS ---------------------------------------------------------------------------------------
4
5 string property HUD_MENU = "HUD Menu" autoReadOnly
6
7
8 ; PRIVATE VARIABLES -------------------------------------------------------------------------------
9
10 SKI_WidgetManager _widgetManager
11
12 bool _initialized = false
13 bool _ready = false
14 int _widgetID = -1
15 string _widgetRoot = ""
16 string[] _modes
17 string _hAnchor = "left"
18 string _vAnchor = "top"
19 float _x = 0.0
20 float _y = 0.0
21 float _alpha = 100.0
22
23
24 ; PROPERTIES --------------------------------------------------------------------------------------
25
26 bool property RequireExtend = true auto
27 {Require extending the widget type instead of using it directly.}
28
29 ; @interface
30 string property WidgetName = "I-forgot-to-set-the-widget name" auto
31 {Name of the widget. Used to identify it in the user interface.}
32
33 ; @interface
34 int property WidgetID
35 {Unique ID of the widget. ReadOnly}
36 int function get()
37 return _widgetID
38 endFunction
39 endProperty
40
41 ; @interface
42 bool property Ready
43 {True once the widget has registered. ReadOnly}
44 bool function get()
45 return _initialized
46 endFunction
47 endProperty
48
49 ; @interface
50 string property WidgetRoot
51 {Path to the root of the widget from _root of HudMenu. ReadOnly}
52 string function get()
53 return _widgetRoot
54 endFunction
55 endProperty
56
57 string[] property Modes
58 {HUDModes in which the widget is visible, see readme for available modes}
59 string[] function get()
60 return _modes
61 endFunction
62
63 function set(string[] a_val)
64 _modes = a_val
65 if (Ready)
66 UpdateWidgetModes()
67 endIf
68 endFunction
69 endProperty
70
71 ; @interface
72 string property HAnchor
73 {Horizontal anchor point of the widget ["left", "center", "right"]. Default: "left"}
74 string function get()
75 return _hAnchor
76 endFunction
77
78 function set(string a_val)
79 _hAnchor = a_val
80 if (Ready)
81 UpdateWidgetHAnchor()
82 endIf
83 endFunction
84 endProperty
85
86 ; @interface
87 string property VAnchor
88 {Vertical anchor point of the widget ["top", "center", "bottom"]. Default: "top"}
89 string function get()
90 return _vAnchor
91 endFunction
92
93 function set(string a_val)
94 _vAnchor = a_val
95 if (Ready)
96 UpdateWidgetVAnchor()
97 endIf
98 endFunction
99 endProperty
100
101 ; @interface
102 float property X
103 {Horizontal position of the widget in pixels at a resolution of 1280x720 [0.0, 1280.0]. Default: 0.0}
104 float function get()
105 return _x
106 endFunction
107
108 function set(float a_val)
109 _x = a_val
110 if (Ready)
111 UpdateWidgetPositionX()
112 endIf
113 endFunction
114 endProperty
115
116 ; @interface
117 float property Y
118 {Vertical position of the widget in pixels at a resolution of 1280x720 [0.0, 720.0]. Default: 0.0}
119 float function get()
120 return _y
121 endFunction
122
123 function set(float a_val)
124 _y = a_val
125 if (Ready)
126 UpdateWidgetPositionY()
127 endIf
128 endFunction
129 endProperty
130
131 ; @interface
132 float property Alpha
133 {Opacity of the widget [0.0, 100.0]. Default: 0.0}
134 float function get()
135 return _alpha
136 endFunction
137
138 function set(float a_val)
139 _alpha = a_val
140 if (Ready)
141 UpdateWidgetAlpha()
142 endIf
143 endFunction
144 endProperty
145
146
147 ; INITIALIZATION ----------------------------------------------------------------------------------
148
149 event OnInit()
150 OnGameReload()
151 endEvent
152
153 ; @implements SKI_QuestBase
154 event OnGameReload()
155 _ready = false
156 RegisterForModEvent("SKIWF_widgetManagerReady", "OnWidgetManagerReady")
157
158 if (!IsExtending() && RequireExtend)
159 Debug.MessageBox("WARNING!\n" + self as string + " must extend a base script type.")
160 endIf
161
162 if (!_initialized)
163 _initialized = true
164
165 ; Default Modes if not set via property
166 if (!_modes)
167 _modes = new string[6]
168 _modes[0] = "All"
169 _modes[1] = "StealthMode"
170 _modes[2] = "Favor"
171 _modes[3] = "Swimming"
172 _modes[4] = "HorseMode"
173 _modes[5] = "WarHorseMode"
174 endIf
175
176 OnWidgetInit()
177
178 Debug.Trace(self + " INITIALIZED")
179 endIf
180
181 CheckVersion()
182 endEvent
183
184 event OnWidgetManagerReady(string a_eventName, string a_strArg, float a_numArg, Form a_sender)
185 SKI_WidgetManager newManager = a_sender as SKI_WidgetManager
186
187 ; Already registered?
188 if (_widgetManager == newManager)
189 return
190 endIf
191
192 _widgetManager = newManager
193
194 _widgetID = _widgetManager.RequestWidgetID(self)
195 if (_widgetID != -1)
196 _widgetRoot = "_root.WidgetContainer." + _widgetID + ".widget"
197 _widgetManager.CreateWidget(_widgetID, GetWidgetSource())
198 else
199 Debug.Trace("WidgetWarning: " + self as string + ": could not be loaded, too many widgets. Max is 128")
200 endIf
201 endEvent
202
203
204 ; EVENTS ------------------------------------------------------------------------------------------
205
206 ; @interface
207 event OnWidgetInit()
208 {Handles any custom widget initialization}
209 endEvent
210
211 ; Executed after each game reload by widget manager.
212 event OnWidgetLoad()
213 _ready = true
214
215 OnWidgetReset()
216
217 ; Before that the widget was still hidden.
218 ; Now that everything is done, set modes to show it eventually.
219 UpdateWidgetModes()
220 endEvent
221
222 event OnWidgetReset()
223 ; Reset base properties except modes to prevent widget from being drawn too early.
224 UpdateWidgetClientInfo()
225 UpdateWidgetHAnchor()
226 UpdateWidgetVAnchor()
227 UpdateWidgetPositionX()
228 UpdateWidgetPositionY()
229 UpdateWidgetAlpha()
230 endEvent
231
232
233 ; FUNCTIONS ---------------------------------------------------------------------------------------
234
235 ; @interface
236 string function GetWidgetSource()
237 return ""
238 endFunction
239
240 ; @interface
241 string function GetWidgetType()
242 ; Must be the same as scriptname
243 return ""
244 endFunction
245
246 ; @interface
247 float[] function GetDimensions()
248 {Return the dimensions of the widget (width,height).}
249 float[] dim = new float[2]
250 dim[0] = 0
251 dim[1] = 0
252 return dim
253 endFunction
254
255 ; @interface
256 function TweenToX(float a_x, float a_duration)
257 {Moves the widget to a new x position over time}
258 TweenTo(a_x, _y, a_duration)
259 endFunction
260
261 ; @interface
262 function TweenToY(float a_y, float a_duration)
263 {Moves the widget to a new y position over time}
264 TweenTo(_x, a_y, a_duration)
265 endFunction
266
267 ; @interface
268 function TweenTo(float a_x, float a_y, float a_duration)
269 {Moves the widget to a new x, y position over time}
270 float[] args = new float[3]
271 args[0] = a_x
272 args[1] = a_y
273 args[2] = a_duration
274 UI.InvokeFloatA(HUD_MENU, _widgetRoot + ".tweenTo", args)
275 endFunction
276
277 ; @interface
278 function FadeTo(float a_alpha, float a_duration)
279 {Fades the widget to a new alpha over time}
280 float[] args = new float[2]
281 args[0] = a_alpha
282 args[1] = a_duration
283 UI.InvokeFloatA(HUD_MENU, _widgetRoot + ".fadeTo", args)
284 endFunction
285
286 bool function IsExtending()
287 string s = self as string
288 string sn = GetWidgetType() + " "
289 s = StringUtil.Substring(s, 1, StringUtil.GetLength(sn))
290 if (s == sn)
291 return false
292 endIf
293 return true
294 endFunction
295
296 function UpdateWidgetClientInfo()
297 UI.InvokeString(HUD_MENU, _widgetRoot + ".setClientInfo", self as string)
298 endFunction
299
300 function UpdateWidgetAlpha()
301 UI.InvokeFloat(HUD_MENU, _widgetRoot + ".setAlpha", Alpha)
302 endFunction
303
304 function UpdateWidgetHAnchor()
305 UI.InvokeString(HUD_MENU, _widgetRoot + ".setHAnchor", HAnchor)
306 endFunction
307
308 function UpdateWidgetVAnchor()
309 UI.InvokeString(HUD_MENU, _widgetRoot + ".setVAnchor", VAnchor)
310 endFunction
311
312 function UpdateWidgetPositionX()
313 UI.InvokeFloat(HUD_MENU, _widgetRoot + ".setPositionX", X)
314 endFunction
315
316 function UpdateWidgetPositionY()
317 UI.InvokeFloat(HUD_MENU, _widgetRoot + ".setPositionY", Y)
318 endFunction
319
320 function UpdateWidgetModes()
321 UI.InvokeStringA(HUD_MENU, _widgetRoot + ".setModes", Modes)
322 endFunction

  ViewVC Help
Powered by ViewVC 1.1.22