]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animhost.c
stop old slider animation before starting a new one
[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, stopAllAnim, void(entity))
6         METHOD(AnimHost, stopObjAnim, void(entity, entity))
7         METHOD(AnimHost, finishAllAnim, void(entity))
8         METHOD(AnimHost, finishObjAnim, void(entity, entity))
9         METHOD(AnimHost, tickAll, void(entity))
10         ATTRIB(AnimHost, firstChild, entity, NULL)
11         ATTRIB(AnimHost, lastChild, entity, NULL)
12 ENDCLASS(AnimHost)
13 .entity nextSibling;
14 .entity prevSibling;
15 #endif
16
17 #ifdef IMPLEMENTATION
18 void addAnimAnimHost(entity me, entity other)
19 {
20         if(other.parent)
21                 error("Can't add already added anim!");
22
23         if(other.isFinished(other))
24                 error("Can't add finished anim!");
25
26         other.parent = me;
27
28         entity f, l;
29         f = me.firstChild;
30         l = me.lastChild;
31
32         if(l)
33                 l.nextSibling = other;
34         else
35                 me.firstChild = other;
36
37         other.prevSibling = l;
38         other.nextSibling = NULL;
39         me.lastChild = other;
40 }
41
42 void removeAnimAnimHost(entity me, entity other)
43 {
44         if(other.parent != me)
45                 error("Can't remove from wrong AnimHost!");
46
47         other.parent = NULL;
48
49         entity n, p, f, l;
50         f = me.firstChild;
51         l = me.lastChild;
52         n = other.nextSibling;
53         p = other.prevSibling;
54
55         if(p)
56                 p.nextSibling = n;
57         else
58                 me.firstChild = n;
59
60         if(n)
61                 n.prevSibling = p;
62         else
63                 me.lastChild = p;
64 }
65
66 void stopAllAnimAnimHost(entity me)
67 {
68         entity e;
69         for(e = me.firstChild; e; e = e.nextSibling)
70         {
71                 e.stopAnim(e);
72         }
73 }
74
75 void stopObjAnimAnimHost(entity me, entity obj)
76 {
77         entity e;
78         for(e = me.firstChild; e; e = e.nextSibling)
79         {
80                 if (e.object == obj)
81                 {
82                         e.stopAnim(e);
83                 }
84         }
85 }
86
87 void finishAllAnimAnimHost(entity me)
88 {
89         entity e, tmp;
90         for(e = me.firstChild; e; e = e.nextSibling)
91         {
92                 tmp = e;
93                 e = tmp.prevSibling;
94                 me.removeAnim(me, tmp);
95                 tmp.finishAnim(tmp);
96         }
97 }
98
99 void finishObjAnimAnimHost(entity me, entity obj)
100 {
101         entity e, tmp;
102         for(e = me.firstChild; e; e = e.nextSibling)
103         {
104                 if (e.object == obj)
105                 {
106                         tmp = e;
107                         e = tmp.prevSibling;
108                         me.removeAnim(me, tmp);
109                         tmp.finishAnim(tmp);
110                 }
111         }
112 }
113
114 void tickAllAnimHost(entity me)
115 {
116         entity e, tmp;
117         for(e = me.firstChild; e; e = e.nextSibling)
118         {
119                 e.tick(e, time);
120         }
121         for(e = me.firstChild; e; e = e.nextSibling)
122         {
123                 if (e.isFinished(e))
124                 {
125                         tmp = e;
126                         e = tmp.prevSibling;
127                         me.removeAnim(me, tmp);
128                         remove(tmp);
129                 }
130         }
131 }
132 #endif