diff --git a/Runtime/GuiSys/CMakeLists.txt b/Runtime/GuiSys/CMakeLists.txt index 917e1ff06..447b439e9 100644 --- a/Runtime/GuiSys/CMakeLists.txt +++ b/Runtime/GuiSys/CMakeLists.txt @@ -76,8 +76,6 @@ set(GUISYS_SOURCES CFontImageDef.hpp ITweakGui.hpp CStringTable.cpp - CStringTable.hpp - CSaveUI.cpp - CSaveUI.hpp) + CStringTable.hpp) runtime_add_list(GuiSys GUISYS_SOURCES) diff --git a/Runtime/GuiSys/CSaveUI.cpp b/Runtime/GuiSys/CSaveUI.cpp deleted file mode 100644 index 8c76f9575..000000000 --- a/Runtime/GuiSys/CSaveUI.cpp +++ /dev/null @@ -1,381 +0,0 @@ -#include "CSaveUI.hpp" -#include "CSimplePool.hpp" -#include "GameGlobalObjects.hpp" -#include "CMemoryCardSys.hpp" -#include "GuiSys/CGuiFrame.hpp" -#include "GuiSys/CGuiTableGroup.hpp" -#include "GuiSys/CGuiTextPane.hpp" -#include "MP1/MP1.hpp" - -namespace urde -{ - -CSaveUI::SBannerInfo::SMemoryCardSlotInfo::SMemoryCardSlotInfo(CMemoryCardSys::EMemoryCardPort parentIdx, - const std::string& name) -: x0_cardPort(parentIdx), x14_name(name) -{} - -CSaveUI::SBannerInfo::SBannerInfo(CMemoryCardSys::EMemoryCardPort cardPort, ResId saveBanner, - ResId saveIcon0, ResId saveIcon1, bool flag) -: x0_cardPort(cardPort), x4_saveBanner(saveBanner), - x8_saveIcon0(saveIcon0), xc_saveIcon1(saveIcon1), x19d_flag(flag) -{ - x100_mcSlotInfos.reserve(2); - x100_mcSlotInfos.emplace_back(0, SMemoryCardSlotInfo(x0_cardPort, "MetroidPrime A")); - x100_mcSlotInfos.emplace_back(0, SMemoryCardSlotInfo(x0_cardPort, "MetroidPrime B")); -} - -void CSaveUI::SBannerInfo::FinishedLoading() -{ - x10_state = EState::TwentyFive; - x14_error = EError::Zero; - FinishedLoading2(); -} - -void CSaveUI::SBannerInfo::FinishedLoading2() -{ - auto result = CMemoryCardSys::CardProbe(x0_cardPort); - switch (result.x0_error) - { - case CMemoryCardSys::ECardResult::CARD_RESULT_READY: - if (result.x8_sectorSize != 0x2000) - { - x10_state = EState::Twelve; - x14_error = EError::Seven; - return; - } - x10_state = EState::Five; - MountCard(); - break; - case CMemoryCardSys::ECardResult::CARD_RESULT_BUSY: - break; - case CMemoryCardSys::ECardResult::CARD_RESULT_WRONGDEVICE: - x10_state = EState::Twelve; - x14_error = EError::Four; - break; - default: - NoCardFound(); - break; - } -} - -void CSaveUI::SBannerInfo::NoCardFound() -{ - x10_state = EState::Two; - static_cast(g_Main)->SetCardInserted(false); -} - -void CSaveUI::SBannerInfo::MountCard() -{ - x10_state = EState::TwentySix; - x14_error = EError::Zero; - CMemoryCardSys::ECardResult result = CMemoryCardSys::MountCard(x0_cardPort); - if (result != CMemoryCardSys::ECardResult::CARD_RESULT_READY) - MountCardFailed(result); -} - -void CSaveUI::SBannerInfo::MountCardFailed(CMemoryCardSys::ECardResult result) -{ - switch (result) - { - case CMemoryCardSys::ECardResult::CARD_RESULT_READY: - x10_state = EState::Six; - CheckCard(); - break; - case CMemoryCardSys::ECardResult::CARD_RESULT_BROKEN: - x10_state = EState::Six; - x14_error = EError::One; - CheckCard(); - break; - default: - HandleCardError(result, EState::Thirteen); - break; - } -} - -void CSaveUI::SBannerInfo::CheckCard() -{ - CMemoryCardSys::ECardResult result = CMemoryCardSys::CheckCard(x0_cardPort); - if (result != CMemoryCardSys::ECardResult::CARD_RESULT_READY) - CheckCardFailed(result); -} - -void CSaveUI::SBannerInfo::CheckCardFailed(CMemoryCardSys::ECardResult result) -{ - switch (result) - { - case CMemoryCardSys::ECardResult::CARD_RESULT_READY: - x10_state = EState::Seven; - if (!GetCardFreeBytes()) - return; - if (CMemoryCardSys::GetSerialNo(x0_cardPort, x28_cardSerial) == - CMemoryCardSys::ECardResult::CARD_RESULT_READY) - return; - NoCardFound(); - break; - case CMemoryCardSys::ECardResult::CARD_RESULT_BROKEN: - x10_state = EState::Fourteen; - x14_error = EError::One; - break; - default: - HandleCardError(result, EState::Fourteen); - } -} - -bool CSaveUI::SBannerInfo::GetCardFreeBytes() -{ - CMemoryCardSys::ECardResult result = CMemoryCardSys::GetNumFreeBytes(x0_cardPort, - x18_cardFreeBytes, - x1c_cardFreeFiles); - if (result == CMemoryCardSys::ECardResult::CARD_RESULT_READY) - return true; - NoCardFound(); - return false; -} - -void CSaveUI::SBannerInfo::HandleCardError(CMemoryCardSys::ECardResult result, EState state) -{ - switch (result) - { - case CMemoryCardSys::ECardResult::CARD_RESULT_WRONGDEVICE: - x10_state = state; - x14_error = EError::Four; - break; - case CMemoryCardSys::ECardResult::CARD_RESULT_NOCARD: - NoCardFound(); - break; - case CMemoryCardSys::ECardResult::CARD_RESULT_IOERROR: - x10_state = state; - x14_error = EError::Three; - case CMemoryCardSys::ECardResult::CARD_RESULT_ENCODING: - x10_state = state; - x14_error = EError::Two; - break; - default: break; - } -} - -void CSaveUI::SBannerInfo::Update() -{ - auto result = CMemoryCardSys::CardProbe(x0_cardPort); - - if (result.x0_error == CMemoryCardSys::ECardResult::CARD_RESULT_NOCARD) - { - if (x10_state != EState::Two) - NoCardFound(); - static_cast(g_Main)->SetCardInserted(false); - return; - } - - switch (x10_state) - { - case EState::TwentySix: - case EState::TwentySeven: - case EState::TwentyEight: - case EState::TwentyNine: - case EState::Thirty: - case EState::ThirtyOne: - case EState::ThirtyTwo: - case EState::ThirtyThree: - case EState::ThirtyFour: - case EState::ThirtyFive: - case EState::ThirtySix: - case EState::ThirtySeven: - default: break; - } -} - -std::unique_ptr CSaveUI::ConstructBannerInfo(bool flag) -{ - return std::make_unique(CMemoryCardSys::EMemoryCardPort::SlotA, - g_ResFactory->GetResourceIdByName("TXTR_SaveBanner")->id, - g_ResFactory->GetResourceIdByName("TXTR_SaveIcon0")->id, - g_ResFactory->GetResourceIdByName("TXTR_SaveIcon1")->id, flag); -} - -CIOWin::EMessageReturn CSaveUI::Update(float dt) -{ - -} - -bool CSaveUI::PumpLoad() -{ - if (x50_loadedFrame) - return true; - if (!x14_txtrSaveBanner.IsLoaded()) - return false; - if (!x20_txtrSaveIcon0.IsLoaded()) - return false; - if (!x2c_txtrSaveIcon1.IsLoaded()) - return false; - if (!x38_strgMemoryCard.IsLoaded()) - return false; - for (TLockedToken& savw : x70_saveWorlds) - if (!savw.IsLoaded()) - return false; - if (!x44_frmeGenericMenu.IsLoaded()) - return false; - - x50_loadedFrame = x44_frmeGenericMenu.GetObj(); - x54_textpane_message = static_cast(x50_loadedFrame->FindWidget("textpane_message")); - x58_tablegroup_choices = static_cast(x50_loadedFrame->FindWidget("tablegroup_choices")); - x5c_textpane_choice0 = static_cast(x50_loadedFrame->FindWidget("textpane_choice0")); - x60_textpane_choice1 = static_cast(x50_loadedFrame->FindWidget("textpane_choice1")); - x64_textpane_choice2 = static_cast(x50_loadedFrame->FindWidget("textpane_choice2")); - x68_textpane_choice3 = static_cast(x50_loadedFrame->FindWidget("textpane_choice3")); - - x58_tablegroup_choices->SetMenuAdvanceCallback( - std::bind(&CSaveUI::DoAdvance, this, std::placeholders::_1)); - x58_tablegroup_choices->SetMenuSelectionChangeCallback( - std::bind(&CSaveUI::DoSelectionChange, this, std::placeholders::_1)); - - if (x0_instIdx == 1) - x6c_bannerInfo->FinishedLoading(); - - x10_uiType = SelectUIType(); - FinishedLoading(); - return true; -} - -using EState = CSaveUI::SBannerInfo::EState; - -static bool InRange1(EState v) -{ - return v >= EState::TwentySix && v <= EState::ThirtySeven; -} - -static bool InRange2(EState v) -{ - if (v < EState::TwentyFive) - return false; - if (v == EState::TwentySeven) - return false; - if (v == EState::TwentyNine) - return false; - return true; -} - -CSaveUI::UIType CSaveUI::SelectUIType() const -{ - if (x6c_bannerInfo->x10_state == SBannerInfo::EState::Two) - return UIType::Three; - - switch (x10_uiType) - { - case UIType::Thirteen: - case UIType::Fourteen: - case UIType::Fifteen: - return x10_uiType; - default: break; - } - - if (InRange1(x6c_bannerInfo->x10_state)) - { - if (!InRange2(x6c_bannerInfo->x10_state)) - return UIType::Two; - return UIType::One; - } - - if (x6c_bannerInfo->x10_state == SBannerInfo::EState::One) - { - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::Six) - return UIType::Twelve; - return UIType::Sixteen; - } - - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::One) - return UIType::Four; - - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::Two) - return UIType::Five; - - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::Four) - return UIType::Seven; - - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::Five) - { - if (x6c_bannerInfo->x10_state == SBannerInfo::EState::Fourteen) - return UIType::Eight; - return UIType::Nine; - } - - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::Seven) - return UIType::Ten; - - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::Nine) - return UIType::Eleven; - - if (x6c_bannerInfo->x14_error == SBannerInfo::EError::Three) - return UIType::Six; - - return UIType::Zero; -} - -void CSaveUI::FinishedLoading() -{ - -} - -void CSaveUI::Draw() const -{ - -} - -void CSaveUI::DoAdvance(CGuiTableGroup* caller) -{ - -} - -void CSaveUI::DoSelectionChange(CGuiTableGroup* caller) -{ - -} - -void CSaveUI::ProcessUserInput(const CFinalInput& input) -{ - -} - -void CSaveUI::StartGame(int idx) -{ - -} - -void CSaveUI::EraseGame(int idx) -{ - -} - -void* CSaveUI::GetGameData(int idx) const -{ - return nullptr; -} - -CSaveUI::CSaveUI(u32 instIdx, u32 a, u32 b) -: x0_instIdx(instIdx), x8_a(a), xc_b(b) -{ - x14_txtrSaveBanner = g_SimplePool->GetObj("TXTR_SaveBanner"); - x20_txtrSaveIcon0 = g_SimplePool->GetObj("TXTR_SaveIcon0"); - x2c_txtrSaveIcon1 = g_SimplePool->GetObj("TXTR_SaveIcon1"); - x38_strgMemoryCard = g_SimplePool->GetObj("STRG_MemoryCard"); - x44_frmeGenericMenu = g_SimplePool->GetObj("FRME_GenericMenu"); - - x6c_bannerInfo = ConstructBannerInfo(x0_instIdx / 32); - - if (instIdx == 1) - { - x84_navConfirmSfx = 1432; - x88_navMoveSfx = 1436; - x8c_navBackSfx = 1431; - } - x93_secondaryInst = instIdx; - - x70_saveWorlds.reserve(g_MemoryCardSys->GetMemoryWorlds().size()); - for (const std::pair& wld : g_MemoryCardSys->GetMemoryWorlds()) - { - x70_saveWorlds.push_back( - g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), wld.second.GetSaveWorldAssetId()})); - } -} - -} diff --git a/Runtime/GuiSys/CSaveUI.hpp b/Runtime/GuiSys/CSaveUI.hpp deleted file mode 100644 index 02a1d881c..000000000 --- a/Runtime/GuiSys/CSaveUI.hpp +++ /dev/null @@ -1,187 +0,0 @@ -#ifndef __URDE_CSAVEUI_HPP__ -#define __URDE_CSAVEUI_HPP__ - -#include "RetroTypes.hpp" -#include "CToken.hpp" -#include "CIOWin.hpp" -#include "CMemoryCardSys.hpp" - -namespace urde -{ -class CTexture; -class CStringTable; -class CGuiFrame; -class CSaveWorld; -class CFinalInput; -class CGuiTextPane; -class CGuiTableGroup; - -struct CSaveUI -{ - enum class UIType - { - Zero, - One, - Two, - Three, - Four, - Five, - Six, - Seven, - Eight, - Nine, - Ten, - Eleven, - Twelve, - Thirteen, - Fourteen, - Fifteen, - Sixteen - }; - - bool IsDrawConditional() - { - switch (x10_uiType) - { - case UIType::Sixteen: - case UIType::Zero: - case UIType::One: - case UIType::Two: - return false; - default: - return true; - } - } - - struct SBannerInfo - { - struct SMemoryCardSlotInfo - { - CMemoryCardSys::EMemoryCardPort x0_cardPort; - u32 x4_ = -1; - std::string x14_name; - std::vector x24_; - std::vector x34_; - SMemoryCardSlotInfo(CMemoryCardSys::EMemoryCardPort cardPort, const std::string& name); - }; - - enum class EState - { - Zero, - One = 1, - Two = 2, - Five = 5, - Six = 6, - Seven = 7, - Twelve = 12, - Thirteen = 13, - Fourteen = 14, - TwentyFive = 26, - TwentySix = 26, - TwentySeven = 27, - TwentyEight = 28, - TwentyNine = 29, - Thirty = 30, - ThirtyOne = 31, - ThirtyTwo = 32, - ThirtyThree = 33, - ThirtyFour = 34, - ThirtyFive = 35, - ThirtySix = 36, - ThirtySeven = 37 - }; - - enum class EError - { - Zero, - One, - Two, - Three, - Four, - Five, - Six, - Seven, - Eight, - Nine - }; - - CMemoryCardSys::EMemoryCardPort x0_cardPort; - ResId x4_saveBanner; - ResId x8_saveIcon0; - ResId xc_saveIcon1; - EState x10_state = EState::Zero; - EError x14_error = EError::Zero; - s32 x18_cardFreeBytes = 0; - s32 x1c_cardFreeFiles = 0; - u32 x20_ = 0; - u32 x24_ = 0; - u64 x28_cardSerial = 0; - u8 x30_[174]; - std::unique_ptr xe4_[3]; - std::vector> x100_mcSlotInfos; - u32 x194_ = -1; - u32 x198_ = 0; - bool x19c_ = false; - bool x19d_flag; - - SBannerInfo(CMemoryCardSys::EMemoryCardPort cardPort, ResId saveBanner, - ResId saveIcon0, ResId saveIcon1, bool flag); - void FinishedLoading(); - void FinishedLoading2(); - void NoCardFound(); - void MountCard(); - void MountCardFailed(CMemoryCardSys::ECardResult result); - void CheckCard(); - void CheckCardFailed(CMemoryCardSys::ECardResult result); - bool GetCardFreeBytes(); - void HandleCardError(CMemoryCardSys::ECardResult result, EState state); - void Update(); - }; - - u32 x0_instIdx; - u32 x8_a; - u32 xc_b; - UIType x10_uiType = UIType::Zero; - TLockedToken x14_txtrSaveBanner; - TLockedToken x20_txtrSaveIcon0; - TLockedToken x2c_txtrSaveIcon1; - TLockedToken x38_strgMemoryCard; - TLockedToken x44_frmeGenericMenu; - CGuiFrame* x50_loadedFrame = nullptr; - CGuiTextPane* x54_textpane_message; - CGuiTableGroup* x58_tablegroup_choices; - CGuiTextPane* x5c_textpane_choice0; - CGuiTextPane* x60_textpane_choice1; - CGuiTextPane* x64_textpane_choice2; - CGuiTextPane* x68_textpane_choice3; - std::unique_ptr x6c_bannerInfo; - std::vector> x70_saveWorlds; - u32 x80_ = 0; - u32 x84_navConfirmSfx = 1460; - u32 x88_navMoveSfx = 1461; - u32 x8c_navBackSfx = 1459; - bool x90_ = false; - bool x91_ = false; - bool x92_ = false; - bool x93_secondaryInst; - - static std::unique_ptr ConstructBannerInfo(bool flag); - CIOWin::EMessageReturn Update(float dt); - bool PumpLoad(); - UIType SelectUIType() const; - void FinishedLoading(); - void Draw() const; - - void DoAdvance(CGuiTableGroup* caller); - void DoSelectionChange(CGuiTableGroup* caller); - - void ProcessUserInput(const CFinalInput& input); - void StartGame(int idx); - void EraseGame(int idx); - void* GetGameData(int idx) const; - CSaveUI(u32 inst, u32 a, u32 b); -}; - -} - -#endif // __URDE_CSAVEUI_HPP__ diff --git a/Runtime/MP1/CFrontEndUI.cpp b/Runtime/MP1/CFrontEndUI.cpp index 3bbffc325..bb8935df6 100644 --- a/Runtime/MP1/CFrontEndUI.cpp +++ b/Runtime/MP1/CFrontEndUI.cpp @@ -8,7 +8,7 @@ #include "CSlideShow.hpp" #include "Audio/CSfxManager.hpp" #include "Graphics/CMoviePlayer.hpp" -#include "GuiSys/CSaveUI.hpp" +#include "CSaveUI.hpp" #include "GuiSys/CGuiTextPane.hpp" #include "GuiSys/CGuiFrame.hpp" #include "GuiSys/CStringTable.hpp" diff --git a/Runtime/MP1/CFrontEndUI.hpp b/Runtime/MP1/CFrontEndUI.hpp index 8930903d6..be8b79f37 100644 --- a/Runtime/MP1/CFrontEndUI.hpp +++ b/Runtime/MP1/CFrontEndUI.hpp @@ -25,7 +25,6 @@ class CAudioGroupSet; class CSaveWorld; class CStringTable; class CGuiFrame; -class CSaveUI; class CGuiTextPane; class CGuiWidget; class CGuiTableGroup; @@ -34,6 +33,7 @@ class CGuiModel; namespace MP1 { class CNESEmulator; +class CSaveUI; class CFrontEndUI : public CIOWin { diff --git a/Runtime/MP1/CMakeLists.txt b/Runtime/MP1/CMakeLists.txt index 1174c2396..ab46ee27a 100644 --- a/Runtime/MP1/CMakeLists.txt +++ b/Runtime/MP1/CMakeLists.txt @@ -16,6 +16,8 @@ set(MP1_SOURCES CBeetle.hpp CBeetle.cpp CWarWasp.hpp CWarWasp.cpp CSpacePirate.hpp CSpacePirate.cpp + CSaveUI.hpp CSaveUI.cpp + CMemoryCardDriver.hpp CMemoryCardDriver.cpp MP1.hpp MP1.cpp) runtime_add_list(MP1 MP1_SOURCES) diff --git a/Runtime/MP1/CMemoryCardDriver.cpp b/Runtime/MP1/CMemoryCardDriver.cpp new file mode 100644 index 000000000..5d99526b7 --- /dev/null +++ b/Runtime/MP1/CMemoryCardDriver.cpp @@ -0,0 +1,185 @@ +#include "CMemoryCardDriver.hpp" +#include "MP1.hpp" + +namespace urde +{ +namespace MP1 +{ + +CMemoryCardDriver::SMemoryCardSlotInfo::SMemoryCardSlotInfo(CMemoryCardSys::EMemoryCardPort parentIdx, + const std::string& name) +: x0_cardPort(parentIdx), x14_name(name) +{} + +CMemoryCardDriver::CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, ResId saveBanner, + ResId saveIcon0, ResId saveIcon1, bool flag) +: x0_cardPort(cardPort), x4_saveBanner(saveBanner), + x8_saveIcon0(saveIcon0), xc_saveIcon1(saveIcon1), x19d_flag(flag) +{ + x100_mcSlotInfos.reserve(2); + x100_mcSlotInfos.emplace_back(0, SMemoryCardSlotInfo(x0_cardPort, "MetroidPrime A")); + x100_mcSlotInfos.emplace_back(0, SMemoryCardSlotInfo(x0_cardPort, "MetroidPrime B")); +} + +void CMemoryCardDriver::FinishedLoading() +{ + x10_state = EState::TwentyFive; + x14_error = EError::Zero; + FinishedLoading2(); +} + +void CMemoryCardDriver::FinishedLoading2() +{ + auto result = CMemoryCardSys::CardProbe(x0_cardPort); + switch (result.x0_error) + { + case CMemoryCardSys::ECardResult::CARD_RESULT_READY: + if (result.x8_sectorSize != 0x2000) + { + x10_state = EState::Twelve; + x14_error = EError::Seven; + return; + } + x10_state = EState::Five; + MountCard(); + break; + case CMemoryCardSys::ECardResult::CARD_RESULT_BUSY: + break; + case CMemoryCardSys::ECardResult::CARD_RESULT_WRONGDEVICE: + x10_state = EState::Twelve; + x14_error = EError::Four; + break; + default: + NoCardFound(); + break; + } +} + +void CMemoryCardDriver::NoCardFound() +{ + x10_state = EState::Two; + static_cast(g_Main)->SetCardInserted(false); +} + +void CMemoryCardDriver::MountCard() +{ + x10_state = EState::TwentySix; + x14_error = EError::Zero; + CMemoryCardSys::ECardResult result = CMemoryCardSys::MountCard(x0_cardPort); + if (result != CMemoryCardSys::ECardResult::CARD_RESULT_READY) + MountCardFailed(result); +} + +void CMemoryCardDriver::MountCardFailed(CMemoryCardSys::ECardResult result) +{ + switch (result) + { + case CMemoryCardSys::ECardResult::CARD_RESULT_READY: + x10_state = EState::Six; + CheckCard(); + break; + case CMemoryCardSys::ECardResult::CARD_RESULT_BROKEN: + x10_state = EState::Six; + x14_error = EError::One; + CheckCard(); + break; + default: + HandleCardError(result, EState::Thirteen); + break; + } +} + +void CMemoryCardDriver::CheckCard() +{ + CMemoryCardSys::ECardResult result = CMemoryCardSys::CheckCard(x0_cardPort); + if (result != CMemoryCardSys::ECardResult::CARD_RESULT_READY) + CheckCardFailed(result); +} + +void CMemoryCardDriver::CheckCardFailed(CMemoryCardSys::ECardResult result) +{ + switch (result) + { + case CMemoryCardSys::ECardResult::CARD_RESULT_READY: + x10_state = EState::Seven; + if (!GetCardFreeBytes()) + return; + if (CMemoryCardSys::GetSerialNo(x0_cardPort, x28_cardSerial) == + CMemoryCardSys::ECardResult::CARD_RESULT_READY) + return; + NoCardFound(); + break; + case CMemoryCardSys::ECardResult::CARD_RESULT_BROKEN: + x10_state = EState::Fourteen; + x14_error = EError::One; + break; + default: + HandleCardError(result, EState::Fourteen); + } +} + +bool CMemoryCardDriver::GetCardFreeBytes() +{ + CMemoryCardSys::ECardResult result = CMemoryCardSys::GetNumFreeBytes(x0_cardPort, + x18_cardFreeBytes, + x1c_cardFreeFiles); + if (result == CMemoryCardSys::ECardResult::CARD_RESULT_READY) + return true; + NoCardFound(); + return false; +} + +void CMemoryCardDriver::HandleCardError(CMemoryCardSys::ECardResult result, EState state) +{ + switch (result) + { + case CMemoryCardSys::ECardResult::CARD_RESULT_WRONGDEVICE: + x10_state = state; + x14_error = EError::Four; + break; + case CMemoryCardSys::ECardResult::CARD_RESULT_NOCARD: + NoCardFound(); + break; + case CMemoryCardSys::ECardResult::CARD_RESULT_IOERROR: + x10_state = state; + x14_error = EError::Three; + case CMemoryCardSys::ECardResult::CARD_RESULT_ENCODING: + x10_state = state; + x14_error = EError::Two; + break; + default: break; + } +} + +void CMemoryCardDriver::Update() +{ + auto result = CMemoryCardSys::CardProbe(x0_cardPort); + + if (result.x0_error == CMemoryCardSys::ECardResult::CARD_RESULT_NOCARD) + { + if (x10_state != EState::Two) + NoCardFound(); + static_cast(g_Main)->SetCardInserted(false); + return; + } + + switch (x10_state) + { + case EState::TwentySix: + case EState::TwentySeven: + case EState::TwentyEight: + case EState::TwentyNine: + case EState::Thirty: + case EState::ThirtyOne: + case EState::ThirtyTwo: + case EState::ThirtyThree: + case EState::ThirtyFour: + case EState::ThirtyFive: + case EState::ThirtySix: + case EState::ThirtySeven: + default: break; + } +} + +} +} diff --git a/Runtime/MP1/CMemoryCardDriver.hpp b/Runtime/MP1/CMemoryCardDriver.hpp new file mode 100644 index 000000000..7bca56235 --- /dev/null +++ b/Runtime/MP1/CMemoryCardDriver.hpp @@ -0,0 +1,103 @@ +#ifndef __URDE_CMEMORYCARDDRIVER_HPP__ +#define __URDE_CMEMORYCARDDRIVER_HPP__ + +#include "CMemoryCardSys.hpp" + +namespace urde +{ +namespace MP1 +{ + +class CMemoryCardDriver +{ + friend class CSaveUI; +public: + enum class EState + { + Zero, + One = 1, + Two = 2, + Five = 5, + Six = 6, + Seven = 7, + Twelve = 12, + Thirteen = 13, + Fourteen = 14, + TwentyFive = 26, + TwentySix = 26, + TwentySeven = 27, + TwentyEight = 28, + TwentyNine = 29, + Thirty = 30, + ThirtyOne = 31, + ThirtyTwo = 32, + ThirtyThree = 33, + ThirtyFour = 34, + ThirtyFive = 35, + ThirtySix = 36, + ThirtySeven = 37 + }; + + enum class EError + { + Zero, + One, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine + }; + +private: + struct SMemoryCardSlotInfo + { + CMemoryCardSys::EMemoryCardPort x0_cardPort; + u32 x4_ = -1; + std::string x14_name; + std::vector x24_; + std::vector x34_; + SMemoryCardSlotInfo(CMemoryCardSys::EMemoryCardPort cardPort, const std::string& name); + }; + + CMemoryCardSys::EMemoryCardPort x0_cardPort; + ResId x4_saveBanner; + ResId x8_saveIcon0; + ResId xc_saveIcon1; + EState x10_state = EState::Zero; + EError x14_error = EError::Zero; + s32 x18_cardFreeBytes = 0; + s32 x1c_cardFreeFiles = 0; + u32 x20_ = 0; + u32 x24_ = 0; + u64 x28_cardSerial = 0; + u8 x30_[174]; + std::unique_ptr xe4_[3]; + std::vector> x100_mcSlotInfos; + u32 x194_ = -1; + u32 x198_ = 0; + bool x19c_ = false; + bool x19d_flag; + +public: + CMemoryCardDriver(CMemoryCardSys::EMemoryCardPort cardPort, ResId saveBanner, + ResId saveIcon0, ResId saveIcon1, bool flag); + void FinishedLoading(); + void FinishedLoading2(); + void NoCardFound(); + void MountCard(); + void MountCardFailed(CMemoryCardSys::ECardResult result); + void CheckCard(); + void CheckCardFailed(CMemoryCardSys::ECardResult result); + bool GetCardFreeBytes(); + void HandleCardError(CMemoryCardSys::ECardResult result, EState state); + void Update(); +}; + +} +} + +#endif // __URDE_CMEMORYCARDDRIVER_HPP__ diff --git a/Runtime/MP1/CSaveUI.cpp b/Runtime/MP1/CSaveUI.cpp new file mode 100644 index 000000000..3f012615c --- /dev/null +++ b/Runtime/MP1/CSaveUI.cpp @@ -0,0 +1,208 @@ +#include "CSaveUI.hpp" +#include "CSimplePool.hpp" +#include "GameGlobalObjects.hpp" +#include "CMemoryCardSys.hpp" +#include "GuiSys/CGuiFrame.hpp" +#include "GuiSys/CGuiTableGroup.hpp" +#include "GuiSys/CGuiTextPane.hpp" + +namespace urde +{ +namespace MP1 +{ + +using EState = CMemoryCardDriver::EState; + +CIOWin::EMessageReturn CSaveUI::Update(float dt) +{ + +} + +bool CSaveUI::PumpLoad() +{ + if (x50_loadedFrame) + return true; + if (!x14_txtrSaveBanner.IsLoaded()) + return false; + if (!x20_txtrSaveIcon0.IsLoaded()) + return false; + if (!x2c_txtrSaveIcon1.IsLoaded()) + return false; + if (!x38_strgMemoryCard.IsLoaded()) + return false; + for (TLockedToken& savw : x70_saveWorlds) + if (!savw.IsLoaded()) + return false; + if (!x44_frmeGenericMenu.IsLoaded()) + return false; + + x50_loadedFrame = x44_frmeGenericMenu.GetObj(); + x54_textpane_message = static_cast(x50_loadedFrame->FindWidget("textpane_message")); + x58_tablegroup_choices = static_cast(x50_loadedFrame->FindWidget("tablegroup_choices")); + x5c_textpane_choice0 = static_cast(x50_loadedFrame->FindWidget("textpane_choice0")); + x60_textpane_choice1 = static_cast(x50_loadedFrame->FindWidget("textpane_choice1")); + x64_textpane_choice2 = static_cast(x50_loadedFrame->FindWidget("textpane_choice2")); + x68_textpane_choice3 = static_cast(x50_loadedFrame->FindWidget("textpane_choice3")); + + x58_tablegroup_choices->SetMenuAdvanceCallback( + std::bind(&CSaveUI::DoAdvance, this, std::placeholders::_1)); + x58_tablegroup_choices->SetMenuSelectionChangeCallback( + std::bind(&CSaveUI::DoSelectionChange, this, std::placeholders::_1)); + + if (x0_instIdx == 1) + x6c_cardDriver->FinishedLoading(); + + x10_uiType = SelectUIType(); + FinishedLoading(); + return true; +} + +static bool InRange1(EState v) +{ + return v >= EState::TwentySix && v <= EState::ThirtySeven; +} + +static bool InRange2(EState v) +{ + if (v < EState::TwentyFive) + return false; + if (v == EState::TwentySeven) + return false; + if (v == EState::TwentyNine) + return false; + return true; +} + +CSaveUI::UIType CSaveUI::SelectUIType() const +{ + if (x6c_cardDriver->x10_state == EState::Two) + return UIType::Three; + + switch (x10_uiType) + { + case UIType::Thirteen: + case UIType::Fourteen: + case UIType::Fifteen: + return x10_uiType; + default: break; + } + + if (InRange1(x6c_cardDriver->x10_state)) + { + if (!InRange2(x6c_cardDriver->x10_state)) + return UIType::Two; + return UIType::One; + } + + if (x6c_cardDriver->x10_state == EState::One) + { + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Six) + return UIType::Twelve; + return UIType::Sixteen; + } + + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::One) + return UIType::Four; + + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Two) + return UIType::Five; + + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Four) + return UIType::Seven; + + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Five) + { + if (x6c_cardDriver->x10_state == EState::Fourteen) + return UIType::Eight; + return UIType::Nine; + } + + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Seven) + return UIType::Ten; + + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Nine) + return UIType::Eleven; + + if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::Three) + return UIType::Six; + + return UIType::Zero; +} + +void CSaveUI::FinishedLoading() +{ + +} + +void CSaveUI::Draw() const +{ + +} + +void CSaveUI::DoAdvance(CGuiTableGroup* caller) +{ + +} + +void CSaveUI::DoSelectionChange(CGuiTableGroup* caller) +{ + +} + +void CSaveUI::ProcessUserInput(const CFinalInput& input) +{ + +} + +void CSaveUI::StartGame(int idx) +{ + +} + +void CSaveUI::EraseGame(int idx) +{ + +} + +void* CSaveUI::GetGameData(int idx) const +{ + return nullptr; +} + +CSaveUI::CSaveUI(u32 instIdx, u32 a, u32 b) +: x0_instIdx(instIdx), x8_a(a), xc_b(b) +{ + x14_txtrSaveBanner = g_SimplePool->GetObj("TXTR_SaveBanner"); + x20_txtrSaveIcon0 = g_SimplePool->GetObj("TXTR_SaveIcon0"); + x2c_txtrSaveIcon1 = g_SimplePool->GetObj("TXTR_SaveIcon1"); + x38_strgMemoryCard = g_SimplePool->GetObj("STRG_MemoryCard"); + x44_frmeGenericMenu = g_SimplePool->GetObj("FRME_GenericMenu"); + + x6c_cardDriver = ConstructCardDriver(x0_instIdx / 32); + + if (instIdx == 1) + { + x84_navConfirmSfx = 1432; + x88_navMoveSfx = 1436; + x8c_navBackSfx = 1431; + } + x93_secondaryInst = instIdx; + + x70_saveWorlds.reserve(g_MemoryCardSys->GetMemoryWorlds().size()); + for (const std::pair& wld : g_MemoryCardSys->GetMemoryWorlds()) + { + x70_saveWorlds.push_back( + g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), wld.second.GetSaveWorldAssetId()})); + } +} + +std::unique_ptr CSaveUI::ConstructCardDriver(bool flag) +{ + return std::make_unique(CMemoryCardSys::EMemoryCardPort::SlotA, + g_ResFactory->GetResourceIdByName("TXTR_SaveBanner")->id, + g_ResFactory->GetResourceIdByName("TXTR_SaveIcon0")->id, + g_ResFactory->GetResourceIdByName("TXTR_SaveIcon1")->id, flag); +} + +} +} diff --git a/Runtime/MP1/CSaveUI.hpp b/Runtime/MP1/CSaveUI.hpp new file mode 100644 index 000000000..c8719d766 --- /dev/null +++ b/Runtime/MP1/CSaveUI.hpp @@ -0,0 +1,106 @@ +#ifndef __URDE_CSAVEUI_HPP__ +#define __URDE_CSAVEUI_HPP__ + +#include "RetroTypes.hpp" +#include "CToken.hpp" +#include "CIOWin.hpp" +#include "CMemoryCardDriver.hpp" + +namespace urde +{ +class CTexture; +class CStringTable; +class CGuiFrame; +class CSaveWorld; +class CFinalInput; +class CGuiTextPane; +class CGuiTableGroup; + +namespace MP1 +{ + +struct CSaveUI +{ + enum class UIType + { + Zero, + One, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine, + Ten, + Eleven, + Twelve, + Thirteen, + Fourteen, + Fifteen, + Sixteen + }; + + bool IsDrawConditional() + { + switch (x10_uiType) + { + case UIType::Sixteen: + case UIType::Zero: + case UIType::One: + case UIType::Two: + return false; + default: + return true; + } + } + + u32 x0_instIdx; + u32 x8_a; + u32 xc_b; + UIType x10_uiType = UIType::Zero; + TLockedToken x14_txtrSaveBanner; + TLockedToken x20_txtrSaveIcon0; + TLockedToken x2c_txtrSaveIcon1; + TLockedToken x38_strgMemoryCard; + TLockedToken x44_frmeGenericMenu; + CGuiFrame* x50_loadedFrame = nullptr; + CGuiTextPane* x54_textpane_message; + CGuiTableGroup* x58_tablegroup_choices; + CGuiTextPane* x5c_textpane_choice0; + CGuiTextPane* x60_textpane_choice1; + CGuiTextPane* x64_textpane_choice2; + CGuiTextPane* x68_textpane_choice3; + std::unique_ptr x6c_cardDriver; + std::vector> x70_saveWorlds; + u32 x80_ = 0; + u32 x84_navConfirmSfx = 1460; + u32 x88_navMoveSfx = 1461; + u32 x8c_navBackSfx = 1459; + bool x90_ = false; + bool x91_ = false; + bool x92_ = false; + bool x93_secondaryInst; + + static std::unique_ptr ConstructCardDriver(bool flag); + CIOWin::EMessageReturn Update(float dt); + bool PumpLoad(); + UIType SelectUIType() const; + void FinishedLoading(); + void Draw() const; + + void DoAdvance(CGuiTableGroup* caller); + void DoSelectionChange(CGuiTableGroup* caller); + + void ProcessUserInput(const CFinalInput& input); + void StartGame(int idx); + void EraseGame(int idx); + void* GetGameData(int idx) const; + CSaveUI(u32 inst, u32 a, u32 b); +}; + +} +} + +#endif // __URDE_CSAVEUI_HPP__ diff --git a/Runtime/World/CScriptSwitch.cpp b/Runtime/World/CScriptSwitch.cpp index 03606ff30..3b387d978 100644 --- a/Runtime/World/CScriptSwitch.cpp +++ b/Runtime/World/CScriptSwitch.cpp @@ -9,7 +9,7 @@ CScriptSwitch::CScriptSwitch(TUniqueId uid, const std::string& name, const CEnti { } -void CScriptSwitch::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) +void CScriptSwitch::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr) { if (GetActive()) { diff --git a/Runtime/World/CScriptSwitch.hpp b/Runtime/World/CScriptSwitch.hpp index b7bcc6b1d..81c04ca31 100644 --- a/Runtime/World/CScriptSwitch.hpp +++ b/Runtime/World/CScriptSwitch.hpp @@ -7,8 +7,8 @@ namespace urde { class CScriptSwitch : public CEntity { - bool x34_; - bool x35_; + bool x34_opened; + bool x35_closeOnOpened; public: CScriptSwitch(TUniqueId, const std::string&, const CEntityInfo&, bool, bool, bool); diff --git a/Runtime/World/CScriptTimer.cpp b/Runtime/World/CScriptTimer.cpp index 3ed8499d8..62719733f 100644 --- a/Runtime/World/CScriptTimer.cpp +++ b/Runtime/World/CScriptTimer.cpp @@ -16,7 +16,7 @@ CScriptTimer::CScriptTimer(TUniqueId uid, const std::string& name, const CEntity { } -void CScriptTimer::Think(float, CStateManager&) +void CScriptTimer::Think(float dt, CStateManager& mgr) { if (GetActive() && IsTiming()) ApplyTime(dt, mgr); diff --git a/Runtime/World/CScriptTimer.hpp b/Runtime/World/CScriptTimer.hpp index 4c5684eb6..e914f6eb9 100644 --- a/Runtime/World/CScriptTimer.hpp +++ b/Runtime/World/CScriptTimer.hpp @@ -8,19 +8,19 @@ namespace urde class CScriptTimer : public CEntity { - float x34_; - float x38_; - float x3c_; - bool x40_; - bool x41_; - bool x42_; + float x34_time; + float x38_startTime; + float x3c_maxRandDelay; + bool x40_loop; + bool x41_autoStart; + bool x42_isTiming; public: CScriptTimer(TUniqueId, const std::string& name, const CEntityInfo& info, float, float, bool, bool, bool); void Think(float, CStateManager &); void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr); - bool IsTiming(); + bool IsTiming() const; void StartTiming(bool); void Reset(CStateManager&); void ApplyTime(float, CStateManager&);