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