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