| 1 | #include "MapObj/RouletteSwitch.h" |
| 2 | |
| 3 | #include <basis/seadTypes.h> |
| 4 | |
| 5 | #include "Library/LiveActor/ActorClippingFunction.h" |
| 6 | #include "Library/LiveActor/ActorInitFunction.h" |
| 7 | #include "Library/LiveActor/ActorInitInfo.h" |
| 8 | #include "Library/LiveActor/ActorInitUtil.h" |
| 9 | #include "Library/Nerve/NerveSetupUtil.h" |
| 10 | #include "Library/Placement/PlacementFunction.h" |
| 11 | #include "Library/Placement/PlacementInfo.h" |
| 12 | #include "Library/Stage/StageSwitchUtil.h" |
| 13 | |
| 14 | #include "MapObj/HipDropSwitch.h" |
| 15 | #include "MapObj/TrampleSwitch.h" |
| 16 | |
| 17 | namespace { |
| 18 | NERVE_IMPL(RouletteSwitch, Wait); |
| 19 | |
| 20 | NERVES_MAKE_STRUCT(RouletteSwitch, Wait); |
| 21 | } // namespace |
| 22 | |
| 23 | RouletteSwitch::RouletteSwitch(const char* name) : al::LiveActor(name) {} |
| 24 | |
| 25 | void RouletteSwitch::init(const al::ActorInitInfo& actorInitInfo) { |
| 26 | al::initActorSceneInfo(actor: this, info: actorInitInfo); |
| 27 | al::initActorPoseTRSV(actor: this); |
| 28 | al::initActorSRT(actor: this, info: actorInitInfo); |
| 29 | al::initActorClipping(actor: this, initInfo: actorInitInfo); |
| 30 | al::initExecutorUpdate(actor: this, info: actorInitInfo, "地形オブジェ[Movement]" ); |
| 31 | al::initStageSwitch(this, actorInitInfo); |
| 32 | al::initNerve(actor: this, nerve: &NrvRouletteSwitch.Wait, maxStates: 0); |
| 33 | al::initGroupClipping(actor: this, initInfo: actorInitInfo); |
| 34 | |
| 35 | for (s32 i = 0; i < mButtons.capacity(); i++) { |
| 36 | sead::FixedSafeString<0x80>* string = new sead::FixedSafeString<0x80>(); |
| 37 | string->format(formatStr: "Button%d" , i + 1); |
| 38 | al::PlacementInfo placementInfo; |
| 39 | if (!al::tryGetLinksInfo(linkPlacementInfo: &placementInfo, initInfo: actorInitInfo, linkName: string->cstr())) |
| 40 | break; |
| 41 | |
| 42 | TrampleSwitch* trampleSwitch = new TrampleSwitch(string->cstr()); |
| 43 | al::ActorInitInfo switchInitInfo; |
| 44 | switchInitInfo.initViewIdHost(&placementInfo, actorInitInfo); |
| 45 | trampleSwitch->init(info: switchInitInfo); |
| 46 | |
| 47 | mButtons.pushBack(ptr: trampleSwitch); |
| 48 | } |
| 49 | |
| 50 | al::PlacementInfo placementInfo; |
| 51 | if (!al::tryGetLinksInfo(linkPlacementInfo: &placementInfo, initInfo: actorInitInfo, linkName: "ButtonReset" )) { |
| 52 | makeActorDead(); |
| 53 | return; |
| 54 | } |
| 55 | mResetButton = new HipDropSwitch("リセットボタン" ); |
| 56 | al::ActorInitInfo switchInitInfo; |
| 57 | switchInitInfo.initViewIdHost(&placementInfo, actorInitInfo); |
| 58 | mResetButton->init(switchInitInfo); |
| 59 | mIsPressReset = mResetButton->isOnWait(); |
| 60 | makeActorAlive(); |
| 61 | } |
| 62 | |
| 63 | void RouletteSwitch::control() { |
| 64 | if (!mIsPressReset && mResetButton->isOnWait()) { |
| 65 | for (s32 i = 0; i < mButtons.size(); i++) |
| 66 | mButtons[i]->offSwitch(); |
| 67 | mIsPressReset = mResetButton->isOnWait(); |
| 68 | return; |
| 69 | } |
| 70 | bool isAnySwitchOn = false; |
| 71 | for (s32 i = 0; i < mButtons.size(); i++) { |
| 72 | sead::FixedSafeString<0x100> string; |
| 73 | string.format(formatStr: "SwitchButton%dOn" , i + 1); |
| 74 | if (!mButtons[i]->isOn()) { |
| 75 | al::offStageSwitch(user: this, linkName: string.cstr()); |
| 76 | } else { |
| 77 | al::onStageSwitch(user: this, linkName: string.cstr()); |
| 78 | isAnySwitchOn = true; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (isAnySwitchOn && mResetButton->isOnWait()) |
| 83 | mResetButton->reset(); |
| 84 | mIsPressReset = mResetButton->isOnWait(); |
| 85 | } |
| 86 | |
| 87 | void RouletteSwitch::exeWait() {} |
| 88 | |