]>
Commit | Line | Data |
---|---|---|
9ad526c0 | 1 | using System; |
74c15570 BB |
2 | using System.Collections.Generic; |
3 | using System.Linq; | |
4 | using System.Text; | |
bca44639 BB |
5 | using Microsoft.Xna.Framework; |
6 | using Microsoft.Xna.Framework.Graphics; | |
74c15570 BB |
7 | |
8 | namespace SuperPolarity | |
9 | { | |
10 | class Widget | |
11 | { | |
bca44639 | 12 | public List<Widget> Children; |
74c15570 BB |
13 | public Dictionary<string, List<Action<float>>> Listeners; |
14 | ||
bca44639 BB |
15 | public Vector2 Position; |
16 | public SuperPolarity Game; | |
17 | ||
18 | protected bool Active; | |
19 | ||
20 | public Widget(SuperPolarity game, Vector2 position) | |
21 | { | |
22 | Game = game; | |
23 | Position = position; | |
24 | Active = false; | |
25 | Children = new List<Widget>(); | |
26 | Listeners = new Dictionary<string, List<Action<float>>>(); | |
27 | } | |
28 | ||
29 | public void Activate() | |
30 | { | |
31 | Active = true; | |
32 | } | |
33 | ||
34 | public void Deactivate() | |
35 | { | |
36 | Active = false; | |
37 | } | |
38 | ||
74c15570 BB |
39 | public virtual void AppendChild(Widget widget) |
40 | { | |
41 | Children.Add(widget); | |
42 | } | |
43 | ||
44 | public virtual void Bind(string eventName, Action<float> eventListener) | |
45 | { | |
46 | List<Action<float>> newListenerList; | |
47 | List<Action<float>> listenerList; | |
48 | bool foundListeners; | |
49 | ||
50 | if (!Listeners.ContainsKey(eventName)) | |
51 | { | |
52 | newListenerList = new List<Action<float>>(); | |
53 | Listeners.Add(eventName, newListenerList); | |
54 | } | |
55 | ||
56 | foundListeners = Listeners.TryGetValue(eventName, out listenerList); | |
57 | ||
58 | listenerList.Add(eventListener); | |
59 | } | |
60 | ||
61 | public virtual void Unbind(string eventName, Action<float> eventListener) | |
62 | { | |
63 | // NOT YET IMPLEMENTED; | |
64 | } | |
65 | ||
66 | public virtual void Dispatch(string eventName, float value) | |
67 | { | |
68 | List<Action<float>> listenerList; | |
69 | bool foundListeners; | |
70 | ||
71 | foundListeners = Listeners.TryGetValue(eventName, out listenerList); | |
72 | ||
73 | if (!foundListeners) | |
74 | { | |
75 | return; | |
76 | } | |
77 | ||
78 | foreach (Action<float> method in listenerList) | |
79 | { | |
80 | method(value); | |
81 | } | |
82 | } | |
bca44639 BB |
83 | |
84 | public virtual void Update(GameTime gameTime) | |
85 | { | |
86 | } | |
87 | ||
88 | public virtual void Draw(SpriteBatch spriteBatch) | |
89 | { | |
90 | } | |
74c15570 BB |
91 | } |
92 | } |