/
Mr.Stalin
/
FOnline-Engine
Обзор
Документация
Войти
/
Mr.Stalin
/
FOnline-Engine
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Scripting/AngelScript/CoreScripts/Tween.fos
231 строка
4 KB
cvet
Enhance Panel class with scroll functionality and smooth animations
22 мар 2026, 18:31
22 мар 2026, 18:31
66d7bf1
Код
Авторство
О чём код?
namespace Tween { enum EasingType { Linear, InQuad, OutQuad, InOutQuad, OutCubic, } class Tween { void Init(int beginX, int beginY, int endX, int endY, int pixelsPerSecond) { x1 = beginX; y1 = beginY; x2 = endX; y2 = endY; x3 = beginX; y3 = beginY; end = false; pps = pixelsPerSecond; } void UpdatePos(int newX, int newY) { x2 = newX; y2 = newY; x3 = newX; y3 = newY; } void Move(bool toEnd) { if (end == toEnd) { return; } x3 = CurX; y3 = CurY; end = toEnd; startTick = Game.FrameTime; } void ForceMove(bool toEnd) { end = toEnd; x3 = (end ? x2 : x1); y3 = (end ? y2 : y1); } int get_CurX() { return x3 + Percent * ((end ? x2 : x1) - x3) / 100; } int get_CurY() { return y3 + Percent * ((end ? y2 : y1) - y3) / 100; } int get_Dist() { return Math::RoundToInt(math::sqrt(Math::Pow2((end ? x2 : x1) - x3) + Math::Pow2((end ? y2 : y1) - y3))); } int get_Percent() { int dist = Dist; return dist > 0 ? Math::Min((Game.FrameTime - startTick).milliseconds * pps / 1000 * 100 / Dist, 100) : 100; } private bool end; private int x1; private int y1; private int x2; private int y2; private int x3; private int y3; private int pps; private nanotime startTick; }; class ValueTween { void Reset(int value) { _From = value; _To = value; _Current = value; _DurationMs = 0; _Easing = EasingType::OutCubic; _Active = false; _StartTick = nanotime(); } void MoveTo(int fromValue, int toValue, int durationMs, EasingType easing = EasingType::OutCubic) { _From = fromValue; _To = toValue; _Current = fromValue; _DurationMs = Math::Max(durationMs, 0); _Easing = easing; _StartTick = Game.FrameTime; _Active = (_From != _To && _DurationMs > 0); if (!_Active) { _Current = _To; } } void SnapTo(int value) { Reset(value); } int Update() { if (!_Active) { return _Current; } float t = Math::ClampF(float((Game.FrameTime - _StartTick).milliseconds) / float(_DurationMs), 0.0f, 1.0f); _Current = Math::Lerp(_From, _To, _ApplyEasing(t)); if (t >= 1.0f || _Current == _To) { _Current = _To; _Active = false; } return _Current; } bool get_Active() { return _Active; } int get_Current() { return _Current; } int get_Target() { return _To; } private float _ApplyEasing(float t) { switch (_Easing) { case EasingType::InQuad: return InQuad(t); case EasingType::OutQuad: return OutQuad(t); case EasingType::InOutQuad: return InOutQuad(t); case EasingType::OutCubic: return OutCubic(t); case EasingType::Linear: default: return Linear(t); } } private int _From; private int _To; private int _Current; private int _DurationMs; private EasingType _Easing; private bool _Active; private nanotime _StartTick; }; float Linear(float t) { return Math::ClampF(t, 0.0f, 1.0f); } float InQuad(float t) { t = Linear(t); return t * t; } float OutQuad(float t) { t = Linear(t); float inv = 1.0f - t; return 1.0f - inv * inv; } float InOutQuad(float t) { t = Linear(t); if (t < 0.5f) { return 2.0f * t * t; } float inv = -2.0f * t + 2.0f; return 1.0f - inv * inv / 2.0f; } float OutCubic(float t) { t = Linear(t); float inv = 1.0f - t; return 1.0f - inv * inv * inv; } }