]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animation.qc
Merge branch 'master' into Mirio/balance
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / animation.qc
1 #include "animation.qh"
2
3 #include "../menu.qh"
4
5         METHOD(Animation, configureAnimation, void(entity this, entity obj, void(entity, float) objSetter, float animStartTime, float animDuration, float animStartValue, float animEndValue))
6         {
7                 this.setObjectSetter(this, obj, objSetter);
8                 this.setTimeStartDuration(this, animStartTime, animDuration);
9                 this.setValueStartEnd(this, animStartValue, animEndValue);
10         }
11
12         METHOD(Animation, update, void(entity this, float animDuration, float animStartValue, float animEndValue))
13         {
14                 this.setTimeStartDuration(this, time, animDuration);
15                 this.setValueStartEnd(this, animStartValue, animEndValue);
16         }
17
18         METHOD(Animation, setTimeStartEnd, void(entity this, float s, float e))
19         {
20                 this.startTime = s;
21                 this.duration = e - s;
22         }
23
24         METHOD(Animation, setTimeStartDuration, void(entity this, float s, float d))
25         {
26                 this.startTime = s;
27                 this.duration = d;
28         }
29
30         METHOD(Animation, setValueStartEnd, void(entity this, float s, float e))
31         {
32                 this.startValue = s;
33                 this.delta = e - s;
34         }
35
36         METHOD(Animation, setValueStartDelta, void(entity this, float s, float d))
37         {
38                 this.startValue = s;
39                 this.delta = d;
40         }
41
42         METHOD(Animation, setObjectSetter, void(entity this, entity o, void(entity, float) s))
43         {
44                 this.object = o;
45                 this.setter = s;
46         }
47
48         METHOD(Animation, tick, void(entity this, float tickTime))
49         {
50                 if (this.isStopped(this) || this.isFinished(this) || (tickTime < this.startTime)) return;
51
52                 if (tickTime >= (this.startTime + this.duration)) this.finishAnim(this);
53                 else this.value = this.calcValue(this, (tickTime - this.startTime), this.duration, this.startValue, this.delta);
54
55                 this.setter(this.object, this.value);
56         }
57
58         METHOD(Animation, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
59         {
60                 return animStartValue;
61         }
62
63         METHOD(Animation, isStopped, bool(entity this))
64         {
65                 return this.stopped;
66         }
67
68         METHOD(Animation, stopAnim, void(entity this))
69         {
70                 this.stopped = true;
71         }
72
73         METHOD(Animation, resumeAnim, void(entity this))
74         {
75                 this.stopped = false;
76         }
77
78         METHOD(Animation, isFinished, bool(entity this))
79         {
80                 return this.finished;
81         }
82
83         METHOD(Animation, finishAnim, void(entity this))
84         {
85                 this.value = this.delta + this.startValue;
86                 this.finished = true;
87                 this.setter(this.object, this.value);
88         }