1#include "Layout/GaugeAir.h"
2
3#include "Library/Layout/LayoutActionFunction.h"
4#include "Library/Layout/LayoutInitInfo.h"
5#include "Library/Math/MathUtil.h"
6#include "Library/Nerve/NerveSetupUtil.h"
7#include "Library/Nerve/NerveUtil.h"
8
9namespace {
10NERVE_IMPL(GaugeAir, Appear);
11NERVE_IMPL(GaugeAir, Wait);
12NERVE_IMPL(GaugeAir, End);
13NERVE_IMPL(GaugeAir, FastEnd);
14
15NERVES_MAKE_NOSTRUCT(GaugeAir, Appear, FastEnd);
16NERVES_MAKE_STRUCT(GaugeAir, Wait, End);
17} // namespace
18
19GaugeAir::GaugeAir(const char* name, const al::LayoutInitInfo& info) : al::LayoutActor(name) {
20 al::initLayoutActor(this, info, "GaugeAir", nullptr);
21 initNerve(&Appear, 0);
22 kill();
23}
24
25bool GaugeAir::isWait() const {
26 return isAlive() && al::isNerve(user: this, nerve: &NrvGaugeAir.Wait);
27}
28
29void GaugeAir::start() {
30 appear();
31 mIsActive = false;
32 exeWait();
33 al::setNerve(user: this, nerve: &Appear);
34}
35
36void GaugeAir::updateStateAnim() {
37 if (mIsActive && mRate >= 1.0f) {
38 if (!al::isActionPlaying(layout: this, actionName: "Max", paneName: "State"))
39 al::startAction(layout: this, actionName: "Max", paneName: "State");
40 return;
41 }
42
43 if (al::isNearZeroOrLess(value: mRate)) {
44 if (!al::isActionPlaying(layout: this, actionName: "Empty", paneName: "State"))
45 al::startAction(layout: this, actionName: "Empty", paneName: "State");
46 return;
47 }
48
49 if (!al::isActionPlaying(layout: this, actionName: "Normal", paneName: "State"))
50 al::startAction(layout: this, actionName: "Normal", paneName: "State");
51}
52
53void GaugeAir::endMax() {
54 if (!isWait())
55 return;
56 al::startFreezeAction(layout: this, actionName: "Decrease", frame: 0.0f, paneName: "Gauge");
57 updateStateAnim();
58 al::setNerve(user: this, nerve: &NrvGaugeAir.End);
59}
60
61void GaugeAir::fastEnd() {
62 if (isAlive() && !al::isNerve(user: this, nerve: &FastEnd))
63 al::setNerve(user: this, nerve: &FastEnd);
64}
65
66void GaugeAir::setRate(f32 rate) {
67 mRate = rate;
68 if (rate < 0.99f)
69 mIsActive = true;
70}
71
72void GaugeAir::exeAppear() {
73 if (al::isFirstStep(user: this))
74 al::startAction(layout: this, actionName: "Appear", paneName: nullptr);
75 if (al::isActionEnd(layout: this, paneName: nullptr))
76 return al::setNerve(user: this, nerve: &NrvGaugeAir.Wait);
77}
78
79void GaugeAir::exeWait() {
80 al::startFreezeAction(layout: this, actionName: "Decrease",
81 frame: al::getActionFrameMax(layout: this, actionName: "Decrease", paneName: "Gauge") * (1.0f - mRate),
82 paneName: "Gauge");
83 updateStateAnim();
84}
85
86void GaugeAir::exeEnd() {
87 if (al::isLessStep(user: this, step: 30))
88 return;
89
90 if (al::isStep(user: this, step: 30))
91 al::startAction(layout: this, actionName: "End", paneName: nullptr);
92
93 if (al::isActionEnd(layout: this, paneName: nullptr))
94 kill();
95}
96
97void GaugeAir::exeFastEnd() {
98 if (al::isFirstStep(user: this))
99 al::startAction(layout: this, actionName: "End", paneName: nullptr);
100
101 if (al::isActionEnd(layout: this, paneName: nullptr))
102 kill();
103}
104