]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animhost.c
Merge branch 'master' into terencehill/menu_tooltips_2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / animhost.c
1 #ifdef INTERFACE
2 CLASS(AnimHost) EXTENDS(Object)
3         METHOD(AnimHost, addAnim, void(entity, entity))
4         METHOD(AnimHost, removeAnim, void(entity, entity))
5         METHOD(AnimHost, removeAllAnim, void(entity))
6         METHOD(AnimHost, removeObjAnim, void(entity, entity))
7         METHOD(AnimHost, stopAllAnim, void(entity))
8         METHOD(AnimHost, stopObjAnim, void(entity, entity))
9         METHOD(AnimHost, resumeAllAnim, void(entity))
10         METHOD(AnimHost, resumeObjAnim, void(entity, entity))
11         METHOD(AnimHost, finishAllAnim, void(entity))
12         METHOD(AnimHost, finishObjAnim, void(entity, entity))
13         METHOD(AnimHost, tickAll, void(entity))
14         ATTRIB(AnimHost, firstChild, entity, NULL)
15         ATTRIB(AnimHost, lastChild, entity, NULL)
16 ENDCLASS(AnimHost)
17 .entity nextSibling;
18 .entity prevSibling;
19 #endif
20
21 #ifdef IMPLEMENTATION
22 void AnimHost_addAnim(entity me, entity other)
23 {
24         if(other.parent)
25                 error("Can't add already added anim!");
26
27         if(other.isFinished(other))
28                 error("Can't add finished anim!");
29
30         other.parent = me;
31
32         entity f, l;
33         f = me.firstChild;
34         l = me.lastChild;
35
36         if(l)
37                 l.nextSibling = other;
38         else
39                 me.firstChild = other;
40
41         other.prevSibling = l;
42         other.nextSibling = NULL;
43         me.lastChild = other;
44 }
45
46 void AnimHost_removeAnim(entity me, entity other)
47 {
48         if(other.parent != me)
49                 error("Can't remove from wrong AnimHost!");
50
51         other.parent = NULL;
52
53         entity n, p, f, l;
54         f = me.firstChild;
55         l = me.lastChild;
56         n = other.nextSibling;
57         p = other.prevSibling;
58
59         if(p)
60                 p.nextSibling = n;
61         else
62                 me.firstChild = n;
63
64         if(n)
65                 n.prevSibling = p;
66         else
67                 me.lastChild = p;
68         remove(other);
69 }
70
71 void AnimHost_removeAllAnim(entity me)
72 {
73         entity e, tmp;
74         for(e = me.firstChild; e; e = e.nextSibling)
75         {
76                 tmp = e;
77                 e = tmp.prevSibling;
78                 me.removeAnim(me, tmp);
79         }
80 }
81
82 void AnimHost_removeObjAnim(entity me, entity obj)
83 {
84         entity e, tmp;
85         for(e = me.firstChild; e; e = e.nextSibling)
86         {
87                 if (e.object == obj)
88                 {
89                         tmp = e;
90                         e = tmp.prevSibling;
91                         me.removeAnim(me, tmp);
92                 }
93         }
94 }
95
96 void AnimHost_stopAllAnim(entity me)
97 {
98         entity e;
99         for(e = me.firstChild; e; e = e.nextSibling)
100         {
101                 e.stopAnim(e);
102         }
103 }
104
105 void AnimHost_stopObjAnim(entity me, entity obj)
106 {
107         entity e;
108         for(e = me.firstChild; e; e = e.nextSibling)
109         {
110                 if (e.object == obj)
111                 {
112                         e.stopAnim(e);
113                 }
114         }
115 }
116
117 void AnimHost_resumeAllAnim(entity me)
118 {
119         entity e;
120         for(e = me.firstChild; e; e = e.nextSibling)
121         {
122                 e.resumeAnim(e);
123         }
124 }
125
126 void AnimHost_resumeObjAnim(entity me, entity obj)
127 {
128         entity e;
129         for(e = me.firstChild; e; e = e.nextSibling)
130         {
131                 if (e.object == obj)
132                 {
133                         e.resumeAnim(e);
134                 }
135         }
136 }
137
138 void AnimHost_finishAllAnim(entity me)
139 {
140         entity e, tmp;
141         for(e = me.firstChild; e; e = e.nextSibling)
142         {
143                 tmp = e;
144                 e = tmp.prevSibling;
145                 tmp.finishAnim(tmp);
146         }
147 }
148
149 void AnimHost_finishObjAnim(entity me, entity obj)
150 {
151         entity e, tmp;
152         for(e = me.firstChild; e; e = e.nextSibling)
153         {
154                 if (e.object == obj)
155                 {
156                         tmp = e;
157                         e = tmp.prevSibling;
158                         tmp.finishAnim(tmp);
159                 }
160         }
161 }
162
163 void AnimHost_tickAll(entity me)
164 {
165         entity e, tmp;
166         for(e = me.firstChild; e; e = e.nextSibling)
167         {
168                 e.tick(e, time);
169                 if (e.isFinished(e))
170                 {
171                         tmp = e;
172                         e = tmp.prevSibling;
173                         me.removeAnim(me, tmp);
174                 }
175         }
176 }
177 #endif