]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/anim/keyframe.qc
Fix FL_WEAPON flag overlapping FL_JUMPRELEASED. This unintentional change was introdu...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / keyframe.qc
index d83a2cbd4927e80ef69748beb2aa4eea01e3cc67..12c0c9acadecd7e26c9922157ee50188e0fbc4af 100644 (file)
-#ifndef ANIM_KEYFRAME_H
-#define ANIM_KEYFRAME_H
-#include "animation.qc"
-CLASS(Keyframe, Animation)
-       METHOD(Keyframe, addEasing, entity(entity, float, float, float(float, float, float, float)));
-       METHOD(Keyframe, addAnim, void(entity, entity));
-       METHOD(Keyframe, calcValue, float(entity, float, float, float, float));
-       ATTRIB(Keyframe, currentChild, entity, NULL)
-       ATTRIB(Keyframe, firstChild, entity, NULL)
-       ATTRIB(Keyframe, lastChild, entity, NULL)
-ENDCLASS(Keyframe)
-entity makeHostedKeyframe(entity, void(entity, float), float, float, float);
-entity makeKeyframe(entity, void(entity, float), float, float, float);
-float getNewChildStart(entity);
-float getNewChildDuration(entity, float);
-float getNewChildValue(entity);
-#endif
-
-#ifdef IMPLEMENTATION
-entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
-{
-       entity me;
-       me = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
-       anim.addAnim(anim, me);
-       return me;
-}
-
-entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
-{
-       entity me;
-       me = NEW(Keyframe);
-       me.configureAnimation(me, obj, objSetter, time, animDuration, animStart, animEnd);
-       return me;
-}
-
-entity Keyframe_addEasing(entity me, float animDurationTime, float animEnd, float(float, float, float, float) func)
-{
-       entity other;
-       other = makeEasing(me.object, me.setter, func, getNewChildStart(me), getNewChildDuration(me, animDurationTime), getNewChildValue(me), animEnd);
-       me.addAnim(me, other);
-       return other;
-}
-
-float getNewChildStart(entity me)
-{
-       if (me.lastChild)
-               return (me.lastChild.startTime + me.lastChild.duration);
-       else
-               return 0;
-}
-
-float getNewChildDuration(entity me, float durationTime)
-{
-       float dura, maxDura;
-       maxDura = me.duration;
-       if (me.lastChild) maxDura = maxDura - (me.lastChild.startTime + me.lastChild.duration);
-       dura = durationTime;
-       if (0 >= dura || dura > maxDura) dura = maxDura;
-       return dura;
-}
-
-float getNewChildValue(entity me)
-{
-       if (me.lastChild)
-               return (me.lastChild.startValue + me.lastChild.delta);
-       else
-               return me.startValue;
-}
-
-void Keyframe_addAnim(entity me, entity other)
-{
-       if(other.parent)
-               error("Can't add already added anim!");
-
-       if(other.isFinished(other))
-               error("Can't add finished anim!");
-
-       other.parent = me;
-
-       entity l;
-       l = me.lastChild;
-
-       if(l)
-               l.nextSibling = other;
-       else
+#include "keyframe.qh"
+
+#include "../menu.qh"
+#include "easing.qh"
+
+#include "../item/container.qh"
+
+.entity parent;
+
+       entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
+       {
+               entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
+               anim.addAnim(anim, this);
+               return this;
+       }
+
+       entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
+       {
+               entity this = NEW(Keyframe);
+               this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd);
+               return this;
+       }
+
+       METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func))
+       {
+               entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd);
+               this.addAnim(this, other);
+               return other;
+       }
+
+       float getNewChildStart(entity this)
        {
-               me.currentChild = other;
-               me.firstChild = other;
+               if (this.lastChild) return this.lastChild.startTime + this.lastChild.duration;
+               else return 0;
        }
 
-       other.prevSibling = l;
-       other.nextSibling = NULL;
-       me.lastChild = other;
-}
+       float getNewChildDuration(entity this, float durationTime)
+       {
+               float maxDura = this.duration;
+               if (this.lastChild) maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration);
+               float dura = durationTime;
+               if (0 >= dura || dura > maxDura) dura = maxDura;
+               return dura;
+       }
 
-float Keyframe_calcValue(entity me, float tickTime, float animDuration, float animStartValue, float animDelta)
-{
-       if (me.currentChild)
-               if (me.currentChild.isFinished(me.currentChild))
-                       me.currentChild = me.currentChild.nextSibling;
+       float getNewChildValue(entity this)
+       {
+               if (this.lastChild) return this.lastChild.startValue + this.lastChild.delta;
+               else return this.startValue;
+       }
 
-       if (me.currentChild)
+       METHOD(Keyframe, addAnim, void(entity this, entity other))
        {
-               me.currentChild.tick(me.currentChild, tickTime);
-               return me.currentChild.value;
+               if (other.parent) error("Can't add already added anim!");
+
+               if (other.isFinished(other)) error("Can't add finished anim!");
+
+               other.parent = this;
+
+               entity l = this.lastChild;
+
+               if (l)
+               {
+                       l.nextSibling = other;
+               }
+               else
+               {
+                       this.currentChild = other;
+                       this.firstChild = other;
+               }
+
+               other.prevSibling = l;
+               other.nextSibling = NULL;
+               this.lastChild = other;
        }
 
-       return animStartValue + animDelta;
-}
-#endif
+       METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
+       {
+               if (this.currentChild)
+                       if (this.currentChild.isFinished(this.currentChild)) this.currentChild = this.currentChild.nextSibling;
+
+               if (this.currentChild)
+               {
+                       this.currentChild.tick(this.currentChild, tickTime);
+                       return this.currentChild.value;
+               }
+
+               return animStartValue + animDelta;
+       }