summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/koopatlas/starcoin.cpp168
-rw-r--r--src/koopatlas/starcoin.h26
2 files changed, 182 insertions, 12 deletions
diff --git a/src/koopatlas/starcoin.cpp b/src/koopatlas/starcoin.cpp
index 7b7db51..3b8372e 100644
--- a/src/koopatlas/starcoin.cpp
+++ b/src/koopatlas/starcoin.cpp
@@ -11,11 +11,19 @@ dWMStarCoin_c *dWMStarCoin_c::build() {
return c;
}
-dWMStarCoin_c::dWMStarCoin_c() {
+dWMStarCoin_c::dWMStarCoin_c() : state(this) {
layoutLoaded = false;
visible = false;
+ state.setState(&StateID_Hidden);
}
+CREATE_STATE(dWMStarCoin_c, Hidden);
+CREATE_STATE(dWMStarCoin_c, ShowWait);
+CREATE_STATE(dWMStarCoin_c, ShowSectionWait);
+CREATE_STATE(dWMStarCoin_c, Wait);
+CREATE_STATE(dWMStarCoin_c, HideSectionWait);
+CREATE_STATE(dWMStarCoin_c, HideWait);
+
int dWMStarCoin_c::onCreate() {
if (!layoutLoaded) {
@@ -100,24 +108,17 @@ int dWMStarCoin_c::onDelete() {
void dWMStarCoin_c::show() {
- visible = true;
- layout.enableNonLoopAnim(SHOW_ALL);
+ if (state.getCurrentState() == &StateID_Hidden)
+ state.setState(&StateID_ShowWait);
}
int dWMStarCoin_c::onExecute() {
+ state.execute();
+
if (visible) {
layout.execAnimations();
layout.update();
-
- int nowPressed = Remocon_GetPressed(GetActiveRemocon());
-
- if (!layout.isAnyAnimOn()) {
- if (nowPressed & WPAD_B) {
- MapSoundPlayer(SoundRelatedClass, SE_SYS_DIALOGUE_OUT_AUTO, 1);
- layout.enableNonLoopAnim(1);
- }
- }
}
return true;
@@ -130,3 +131,146 @@ int dWMStarCoin_c::onDraw() {
return true;
}
+
+void dWMStarCoin_c::showLeftArrow() {
+ if (!isLeftArrowVisible) {
+ isLeftArrowVisible = true;
+ layout.enableNonLoopAnim(SHOW_LEFT_ARROW);
+ }
+}
+
+void dWMStarCoin_c::showRightArrow() {
+ if (!isRightArrowVisible) {
+ isRightArrowVisible = true;
+ layout.enableNonLoopAnim(SHOW_RIGHT_ARROW);
+ }
+}
+
+void dWMStarCoin_c::hideLeftArrow() {
+ if (isLeftArrowVisible) {
+ isLeftArrowVisible = false;
+ layout.enableNonLoopAnim(HIDE_LEFT_ARROW);
+ }
+}
+
+void dWMStarCoin_c::hideRightArrow() {
+ if (isRightArrowVisible) {
+ isRightArrowVisible = false;
+ layout.enableNonLoopAnim(HIDE_RIGHT_ARROW);
+ }
+}
+
+void dWMStarCoin_c::setLeftArrowVisible(bool value) {
+ if (value)
+ showLeftArrow();
+ else
+ hideLeftArrow();
+}
+
+void dWMStarCoin_c::setRightArrowVisible(bool value) {
+ if (value)
+ showRightArrow();
+ else
+ hideRightArrow();
+}
+
+
+bool dWMStarCoin_c::canScrollLeft() const {
+ return (currentSection > 0);
+}
+bool dWMStarCoin_c::canScrollRight() const {
+ // TODO
+ return false;
+}
+
+void dWMStarCoin_c::loadInfo() {
+ // TODO
+}
+
+void dWMStarCoin_c::loadSectionInfo() {
+ // TODO
+}
+
+
+void dWMStarCoin_c::beginState_Hidden() { }
+void dWMStarCoin_c::executeState_Hidden() { }
+void dWMStarCoin_c::endState_Hidden() { }
+
+void dWMStarCoin_c::beginState_ShowWait() {
+ visible = true;
+ loadInfo();
+ layout.enableNonLoopAnim(SHOW_ALL);
+}
+void dWMStarCoin_c::executeState_ShowWait() {
+ if (!layout.isAnimOn(SHOW_ALL))
+ state.setState(&StateID_ShowSectionWait);
+}
+void dWMStarCoin_c::endState_ShowWait() { }
+
+void dWMStarCoin_c::beginState_ShowSectionWait() {
+ loadSectionInfo();
+ layout.enableNonLoopAnim(SHOW_SECTION);
+
+ if (canScrollLeft())
+ showLeftArrow();
+ if (canScrollRight())
+ showRightArrow();
+}
+void dWMStarCoin_c::executeState_ShowSectionWait() {
+ if (!layout.isAnimOn(SHOW_SECTION))
+ state.setState(&StateID_Wait);
+}
+void dWMStarCoin_c::endState_ShowSectionWait() { }
+
+void dWMStarCoin_c::beginState_Wait() { }
+void dWMStarCoin_c::executeState_Wait() {
+ int nowPressed = Remocon_GetPressed(GetActiveRemocon());
+
+ if (nowPressed & WPAD_ONE) {
+ MapSoundPlayer(SoundRelatedClass, SE_SYS_DIALOGUE_OUT_AUTO, 1);
+ willExit = true;
+ state.setState(&StateID_HideSectionWait);
+ } else if ((nowPressed & WPAD_LEFT) && canScrollLeft()) {
+ currentSection--;
+ willExit = false;
+ state.setState(&StateID_HideSectionWait);
+ } else if ((nowPressed & WPAD_RIGHT) && canScrollRight()) {
+ currentSection++;
+ willExit = false;
+ state.setState(&StateID_HideSectionWait);
+ }
+}
+void dWMStarCoin_c::endState_Wait() { }
+
+void dWMStarCoin_c::beginState_HideSectionWait() {
+ layout.enableNonLoopAnim(HIDE_SECTION);
+ if (willExit) {
+ hideLeftArrow();
+ hideRightArrow();
+ } else {
+ setLeftArrowVisible(canScrollLeft());
+ setRightArrowVisible(canScrollRight());
+ }
+}
+void dWMStarCoin_c::executeState_HideSectionWait() {
+ if (!layout.isAnimOn(HIDE_SECTION)) {
+ if (willExit)
+ state.setState(&StateID_HideWait);
+ else
+ state.setState(&StateID_ShowSectionWait);
+ }
+}
+void dWMStarCoin_c::endState_HideSectionWait() { }
+
+void dWMStarCoin_c::beginState_HideWait() {
+ layout.enableNonLoopAnim(SHOW_ALL);
+ layout.grpHandlers[SHOW_ALL].frameCtrl.flags = 3; // NO_LOOP | REVERSE
+}
+void dWMStarCoin_c::executeState_HideWait() {
+ if (!layout.isAnimOn(SHOW_ALL))
+ state.setState(&StateID_Wait);
+}
+void dWMStarCoin_c::endState_HideWait() {
+ visible = false;
+}
+
diff --git a/src/koopatlas/starcoin.h b/src/koopatlas/starcoin.h
index c4e9cbf..3d931e8 100644
--- a/src/koopatlas/starcoin.h
+++ b/src/koopatlas/starcoin.h
@@ -37,6 +37,23 @@ class dWMStarCoin_c : public dActor_c {
SHINE_COUNT = 5,
};
+ int currentSection;
+
+ bool isLeftArrowVisible, isRightArrowVisible;
+ bool willExit;
+
+ bool canScrollLeft() const;
+ bool canScrollRight() const;
+ void loadInfo();
+ void loadSectionInfo();
+
+ void showLeftArrow();
+ void showRightArrow();
+ void hideLeftArrow();
+ void hideRightArrow();
+ void setLeftArrowVisible(bool value);
+ void setRightArrowVisible(bool value);
+
nw4r::lyt::Picture
*Shine[COLUMN_COUNT][SHINE_COUNT],
*CoinOutline[COLUMN_COUNT][ROW_COUNT][3],
@@ -49,6 +66,15 @@ class dWMStarCoin_c : public dActor_c {
*EarnedCoinCount, *EarnedCoinMax,
*BtnWorldSelText, *BtnBackText;
+ dStateWrapper_c<dWMStarCoin_c> state;
+
+ USING_STATES(dWMStarCoin_c);
+ DECLARE_STATE(Hidden);
+ DECLARE_STATE(ShowWait);
+ DECLARE_STATE(ShowSectionWait);
+ DECLARE_STATE(Wait);
+ DECLARE_STATE(HideSectionWait);
+ DECLARE_STATE(HideWait);
};
#endif