persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
UISequenceAnimation.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
11
12#include <concepts>
13#include <etl/vector.h>
14#include <memory>
15#include <type_traits>
16
17class UIAnimator;
18
23{
24 public:
25 static constexpr std::size_t MAX_STEPS = 8;
26 static constexpr std::size_t MAX_ANIMATIONS_PER_STEP = 4;
27 using Group = etl::vector<std::shared_ptr<UIAnimation>, MAX_ANIMATIONS_PER_STEP>;
28
29 void appendGroup(std::shared_ptr<UIAnimation> anim)
30 {
31 if (steps.full())
32 {
33 return;
34 }
35
36 Group group;
37 group.push_back(std::move(anim));
38 steps.push_back(std::move(group));
39 }
40
41 void joinGroup(std::shared_ptr<UIAnimation> anim)
42 {
43 if (steps.empty())
44 {
45 appendGroup(std::move(anim));
46 return;
47 }
48
49 if (!steps.back().full())
50 {
51 steps.back().push_back(std::move(anim));
52 }
53 }
54
55 void reverse() override
56 {
57 // Not reversing whole sequences; individual property steps handle reverse.
58 }
59
60 void reset() override
61 {
63 currentStep = 0;
64 for (auto& group : steps)
65 {
66 for (auto& anim : group)
67 {
68 if (anim)
69 {
70 anim->reset();
71 }
72 }
73 }
74 }
75
76 protected:
77 bool onUpdate(ae::q20_12_t dt) override
78 {
79 if (currentStep >= static_cast<int>(steps.size()))
80 {
81 return true;
82 }
83
84 Group& group = steps[currentStep];
85 bool allDone = true;
86 for (auto& anim : group)
87 {
88 if (anim && !anim->tick(dt))
89 {
90 allDone = false;
91 }
92 }
93 if (allDone)
94 {
96 }
97
98 return currentStep >= static_cast<int>(steps.size());
99 }
100
101 private:
102 etl::vector<Group, MAX_STEPS> steps;
103 int currentStep = 0;
104};
105
110{
111 public:
112 explicit UISequenceBuilder(UIAnimator* animOwner = nullptr)
113 : seq(std::make_shared<UISequenceAnimation>()), owner(animOwner)
114 {
115 }
116
117 template <typename Builder>
118 requires(!std::convertible_to<Builder, std::shared_ptr<UIAnimation>>)
120 {
121 seq->appendGroup(std::forward<Builder>(b).build());
122 return *this;
123 }
124
125 template <typename Builder>
126 requires(!std::convertible_to<Builder, std::shared_ptr<UIAnimation>>)
128 {
129 seq->joinGroup(std::forward<Builder>(b).build());
130 return *this;
131 }
132
133 UISequenceBuilder& append(std::shared_ptr<UIAnimation> anim)
134 {
135 seq->appendGroup(std::move(anim));
136 return *this;
137 }
138
139 UISequenceBuilder& join(std::shared_ptr<UIAnimation> anim)
140 {
141 seq->joinGroup(std::move(anim));
142 return *this;
143 }
144
145 UISequenceBuilder& repeat(UIRepeatMode mode, int count = -1)
146 {
147 seq->setRepeat(mode, count);
148 return *this;
149 }
150
151 std::shared_ptr<UIAnimation> build()
152 {
153 return seq;
154 }
155
157
158 private:
159 std::shared_ptr<UISequenceAnimation> seq;
161};
Weak handle used by callers to cancel/pause/query a running UI animation.
Base class for one UI animation step (property, delay, callback, sequence).
UIRepeatMode
How an animation behaves after reaching its end.
Non-owning control handle for a UIAnimation managed by UIAnimator.
virtual void reset()
Resets runtime state so the animation can play again (used by Loop).
UIAnimation(const UIAnimation &)=delete
Owns and ticks active UI animations. Safe against cancel-during-tick.
Plays groups of animations: each step waits until all in the group finish.
void appendGroup(std::shared_ptr< UIAnimation > anim)
etl::vector< std::shared_ptr< UIAnimation >, MAX_ANIMATIONS_PER_STEP > Group
void reset() override
Resets runtime state so the animation can play again (used by Loop).
static constexpr std::size_t MAX_STEPS
bool onUpdate(ae::q20_12_t dt) override
Per-frame update.
static constexpr std::size_t MAX_ANIMATIONS_PER_STEP
etl::vector< Group, MAX_STEPS > steps
void joinGroup(std::shared_ptr< UIAnimation > anim)
UISequenceBuilder(UIAnimator *animOwner=nullptr)
std::shared_ptr< UISequenceAnimation > seq
UISequenceBuilder & join(std::shared_ptr< UIAnimation > anim)
UISequenceBuilder & append(std::shared_ptr< UIAnimation > anim)
std::shared_ptr< UIAnimation > build()
UISequenceBuilder & append(Builder &&b)
UISequenceBuilder & repeat(UIRepeatMode mode, int count=-1)
UIAnimationHandle start()
UISequenceBuilder & join(Builder &&b)