]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animhost.qc
Sort menu classes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / animhost.qc
1 #include "../menu.qh"
2
3 #ifndef ANIM_ANIMHOST_H
4 #define ANIM_ANIMHOST_H
5 CLASS(AnimHost, Object)
6         METHOD(AnimHost, addAnim, void(entity, entity))
7         METHOD(AnimHost, removeAnim, void(entity, entity))
8         METHOD(AnimHost, removeAllAnim, void(entity))
9         METHOD(AnimHost, removeObjAnim, void(entity, entity))
10         METHOD(AnimHost, stopAllAnim, void(entity))
11         METHOD(AnimHost, stopObjAnim, void(entity, entity))
12         METHOD(AnimHost, resumeAllAnim, void(entity))
13         METHOD(AnimHost, resumeObjAnim, void(entity, entity))
14         METHOD(AnimHost, finishAllAnim, void(entity))
15         METHOD(AnimHost, finishObjAnim, void(entity, entity))
16         METHOD(AnimHost, tickAll, void(entity))
17         ATTRIB(AnimHost, firstChild, entity, NULL)
18         ATTRIB(AnimHost, lastChild, entity, NULL)
19 ENDCLASS(AnimHost)
20 .entity nextSibling;
21 .entity prevSibling;
22 #endif
23
24 #ifdef IMPLEMENTATION
25 void AnimHost_addAnim(entity me, entity other)
26 {
27         if(other.parent)
28                 error("Can't add already added anim!");
29
30         if(other.isFinished(other))
31                 error("Can't add finished anim!");
32
33         other.parent = me;
34
35         entity l;
36         l = me.lastChild;
37
38         if(l)
39                 l.nextSibling = other;
40         else
41                 me.firstChild = other;
42
43         other.prevSibling = l;
44         other.nextSibling = NULL;
45         me.lastChild = other;
46 }
47
48 void AnimHost_removeAnim(entity me, entity other)
49 {
50         if(other.parent != me)
51                 error("Can't remove from wrong AnimHost!");
52
53         other.parent = NULL;
54
55         entity n, p;
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