SuperMarioOdysseyOnline/source/states/StageSceneStateServerConfig.cpp

377 lines
12 KiB
C++
Raw Normal View History

2022-06-16 21:33:18 +00:00
#include "game/StageScene/StageSceneStateServerConfig.hpp"
#include <cstdlib>
#include <cstring>
2022-06-16 21:33:18 +00:00
#include <math.h>
#include "al/string/StringTmp.h"
2024-06-14 12:18:18 +00:00
#include "al/util.hpp"
#include "basis/seadNew.h"
#include "game/SaveData/SaveDataAccessFunction.h"
2022-06-16 21:33:18 +00:00
#include "server/Client.hpp"
#include "container/seadPtrArray.h"
#include "container/seadSafeArray.h"
#include "logger.hpp"
#include "prim/seadSafeString.h"
#include "prim/seadStringUtil.h"
#include "rs/util/InputUtil.h"
#include "server/gamemode/GameModeBase.hpp"
#include "server/gamemode/GameModeFactory.hpp"
2022-08-07 21:42:56 +00:00
#include "server/gamemode/GameModeManager.hpp"
2024-06-14 09:21:27 +00:00
StageSceneStateServerConfig::StageSceneStateServerConfig(
const char* name,
al::Scene* scene,
const al::LayoutInitInfo& initInfo,
FooterParts* footerParts,
GameDataHolder* dataHolder,
bool
) : al::HostStateBase<al::Scene>(name, scene) {
mFooterParts = footerParts;
2022-06-16 21:33:18 +00:00
mGameDataHolder = dataHolder;
mMsgSystem = initInfo.getMessageSystem();
mInput = new InputSeparator(mHost, true);
// page 0 menu
2024-06-14 09:21:27 +00:00
mMainOptions = new SimpleLayoutMenu("ServerConfigMenu", "OptionSelect", initInfo, 0, false);
2022-06-16 21:33:18 +00:00
mMainOptionsList = new CommonVerticalList(mMainOptions, initInfo, true);
al::setPaneString(mMainOptions, "TxtOption", u"SMOO Mod Menu", 0);
2022-06-16 21:33:18 +00:00
mMainOptionsList->unkInt1 = 1;
mMainOptionsList->initDataNoResetSelected(mMainMenuOptionsCount);
2022-06-16 21:33:18 +00:00
mMainMenuOptions = new sead::SafeArray<sead::WFixedSafeString<0x200>, mMainMenuOptionsCount>();
mMainMenuOptions->mBuffer[ServerConfigOption::GAMEMODECONFIG].copy(u"Gamemode Config");
mMainMenuOptions->mBuffer[ServerConfigOption::GAMEMODESWITCH].copy(u"Change Gamemode");
mMainMenuOptions->mBuffer[ServerConfigOption::SETIP].copy(u"Change Server (needs restart)");
mMainMenuOptions->mBuffer[ServerConfigOption::SETPORT].copy(u"Change Port (needs restart)");
mMainMenuOptions->mBuffer[ServerConfigOption::HIDESERVER].copy(u"Hide Server in Debug (OFF)"); // TBD
2022-06-16 21:33:18 +00:00
mMainOptionsList->addStringData(getMainMenuOptions(), "TxtContent");
2022-06-16 21:33:18 +00:00
// gamemode select menu
2024-06-14 09:21:27 +00:00
mModeSelect = new SimpleLayoutMenu("GamemodeSelectMenu", "OptionSelect", initInfo, 0, false);
2022-06-16 21:33:18 +00:00
mModeSelectList = new CommonVerticalList(mModeSelect, initInfo, true);
al::setPaneString(mModeSelect, "TxtOption", u"Gamemode Selection", 0);
const int modeCount = GameModeFactory::getModeCount();
mModeSelectList->initDataNoResetSelected(modeCount);
2024-06-14 12:18:18 +00:00
auto* modeSelectOptions = new sead::SafeArray<sead::WFixedSafeString<0x200>, modeCount>();
2022-06-16 21:33:18 +00:00
for (size_t i = 0; i < modeCount; i++) {
const char* modeName = GameModeFactory::getModeName(i);
modeSelectOptions->mBuffer[i].convertFromMultiByteString(modeName, strlen(modeName));
}
mModeSelectList->addStringData(modeSelectOptions->mBuffer, "TxtContent");
// gamemode config menu
2022-08-07 21:42:56 +00:00
GameModeConfigMenuFactory factory("GameModeConfigFactory");
for (int mode = 0; mode < factory.getMenuCount(); mode++) {
GameModeEntry& entry = mGamemodeConfigMenus[mode];
2024-06-14 09:21:27 +00:00
const char* name = factory.getMenuName(mode);
entry.mMenu = factory.getCreator(name)(name);
2022-08-07 21:42:56 +00:00
entry.mLayout = new SimpleLayoutMenu("GameModeConfigMenu", "OptionSelect", initInfo, 0, false);
2024-06-14 09:21:27 +00:00
entry.mList = new CommonVerticalList(entry.mLayout, initInfo, true);
2022-06-16 21:33:18 +00:00
2022-08-07 21:42:56 +00:00
al::setPaneString(entry.mLayout, "TxtOption", u"Gamemode Configuration", 0);
2022-06-16 21:33:18 +00:00
}
mCurrentList = mMainOptionsList;
mCurrentMenu = mMainOptions;
}
void StageSceneStateServerConfig::init() {
2022-06-16 21:33:18 +00:00
initNerve(&nrvStageSceneStateServerConfigMainMenu, 0);
#if EMU
char ryujinx[0x10] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
nn::account::Uid user;
nn::account::GetLastOpenedUser(&user);
if (memcmp(user.data, ryujinx, 0x10) == 0) {
Client::showUIMessage(u"Error: Ryujinx default profile detected.\nYou have to create a new user profile!");
}
#endif
2022-06-16 21:33:18 +00:00
}
void StageSceneStateServerConfig::appear(void) {
mCurrentMenu->startAppear("Appear");
al::NerveStateBase::appear();
}
void StageSceneStateServerConfig::kill(void) {
mCurrentMenu->startEnd("End");
al::NerveStateBase::kill();
if (Client::hasServerChanged()) {
#if EMU
Client::showUIMessage(u"You changed the server and have to restart the emulator now.");
#else
Client::showUIMessage(u"You changed the server and have to restart the game now.");
#endif
}
2022-06-16 21:33:18 +00:00
}
al::MessageSystem* StageSceneStateServerConfig::getMessageSystem(void) const {
return mMsgSystem;
}
void StageSceneStateServerConfig::exeMainMenu() {
if (al::isFirstStep(this)) {
activateInput();
2022-06-16 21:33:18 +00:00
}
mInput->update();
mCurrentList->update();
if (mInput->isTriggerUiUp()) {
2024-06-14 09:21:27 +00:00
mCurrentList->up();
}
2022-06-16 21:33:18 +00:00
if (mInput->isTriggerUiDown()) {
mCurrentList->down();
}
if (rs::isTriggerUiCancel(mHost)) {
kill();
}
if (rs::isTriggerUiDecide(mHost)) {
deactivateInput();
2022-06-16 21:33:18 +00:00
}
if (mIsDecideConfig && mCurrentList->isDecideEnd()) {
switch (mCurrentList->mCurSelected) {
2024-06-14 09:21:27 +00:00
case ServerConfigOption::GAMEMODECONFIG: {
al::setNerve(this, &nrvStageSceneStateServerConfigGamemodeConfig);
break;
}
case ServerConfigOption::GAMEMODESWITCH: {
al::setNerve(this, &nrvStageSceneStateServerConfigGamemodeSelect);
break;
}
case ServerConfigOption::SETIP: {
al::setNerve(this, &nrvStageSceneStateServerConfigOpenKeyboardIP);
break;
}
case ServerConfigOption::SETPORT: {
al::setNerve(this, &nrvStageSceneStateServerConfigOpenKeyboardPort);
break;
}
case ServerConfigOption::HIDESERVER: {
al::setNerve(this, &nrvStageSceneStateServerConfigHideServer);
break;
}
2024-06-14 12:18:18 +00:00
default: {
2024-06-14 09:21:27 +00:00
kill();
break;
2024-06-14 12:18:18 +00:00
}
2022-06-16 21:33:18 +00:00
}
}
}
void StageSceneStateServerConfig::exeOpenKeyboardIP() {
if (al::isFirstStep(this)) {
mCurrentList->deactivate();
Client::getKeyboard()->setHeaderText(u"Set a server address below.");
Client::getKeyboard()->setSubText(u"");
bool isSave = Client::openKeyboardIP(); // anything that happens after this will be ran after the keyboard closes
2024-06-14 09:21:27 +00:00
al::startHitReaction(mCurrentMenu, "リセット", 0);
2024-06-14 12:18:18 +00:00
if (isSave) {
al::setNerve(this, &nrvStageSceneStateServerConfigSaveData);
2024-06-14 12:18:18 +00:00
} else {
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
2024-06-14 12:18:18 +00:00
}
}
}
void StageSceneStateServerConfig::exeOpenKeyboardPort() {
2022-06-16 21:33:18 +00:00
if (al::isFirstStep(this)) {
mCurrentList->deactivate();
Client::getKeyboard()->setHeaderText(u"Set a server port below.");
Client::getKeyboard()->setSubText(u"");
bool isSave = Client::openKeyboardPort(); // anything that happens after this will be ran after the keyboard closes
al::startHitReaction(mCurrentMenu, "リセット", 0);
2024-06-14 09:21:27 +00:00
2024-06-14 12:18:18 +00:00
if (isSave) {
al::setNerve(this, &nrvStageSceneStateServerConfigSaveData);
2024-06-14 12:18:18 +00:00
} else {
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
2024-06-14 12:18:18 +00:00
}
2022-06-16 21:33:18 +00:00
}
}
void StageSceneStateServerConfig::exeHideServer() {
if (al::isFirstStep(this)) {
Client::toggleServerHidden();
mMainOptionsList->initDataNoResetSelected(mMainMenuOptionsCount);
mMainOptionsList->addStringData(getMainMenuOptions(), "TxtContent");
mMainOptionsList->updateParts();
al::setNerve(this, &nrvStageSceneStateServerConfigSaveData);
}
}
2022-06-16 21:33:18 +00:00
void StageSceneStateServerConfig::exeGamemodeConfig() {
if (al::isFirstStep(this)) {
2022-08-07 21:42:56 +00:00
mGamemodeConfigMenu = &mGamemodeConfigMenus[GameModeManager::instance()->getGameMode()];
mGamemodeConfigMenu->mList->initDataNoResetSelected(mGamemodeConfigMenu->mMenu->getMenuSize());
mGamemodeConfigMenu->mList->addStringData(mGamemodeConfigMenu->mMenu->getStringData(), "TxtContent");
2022-08-07 21:42:56 +00:00
mCurrentList = mGamemodeConfigMenu->mList;
mCurrentMenu = mGamemodeConfigMenu->mLayout;
2022-06-16 21:33:18 +00:00
subMenuStart();
}
subMenuUpdate();
2022-06-16 21:33:18 +00:00
if (mIsDecideConfig && mCurrentList->isDecideEnd()) {
GameModeConfigMenu::UpdateAction action = mGamemodeConfigMenu->mMenu->updateMenu(mCurrentList->mCurSelected);
switch (action) {
2024-06-14 12:18:18 +00:00
case GameModeConfigMenu::UpdateAction::CLOSE: {
endSubMenu();
break;
2024-06-14 12:18:18 +00:00
}
case GameModeConfigMenu::UpdateAction::REFRESH: {
subMenuRefresh();
break;
2024-06-14 12:18:18 +00:00
}
case GameModeConfigMenu::UpdateAction::NOOP: {
activateInput();
break;
2024-06-14 12:18:18 +00:00
}
2022-06-16 21:33:18 +00:00
}
}
}
void StageSceneStateServerConfig::exeGamemodeSelect() {
if (al::isFirstStep(this)) {
mCurrentList = mModeSelectList;
mCurrentMenu = mModeSelect;
subMenuStart();
}
subMenuUpdate();
if (mIsDecideConfig && mCurrentList->isDecideEnd()) {
Logger::log("Setting Server Mode to: %d\n", mCurrentList->mCurSelected);
2022-08-07 21:42:56 +00:00
GameModeManager::instance()->setMode(static_cast<GameMode>(mCurrentList->mCurSelected));
2022-06-16 21:33:18 +00:00
endSubMenu();
}
}
void StageSceneStateServerConfig::exeSaveData() {
if (al::isFirstStep(this)) {
SaveDataAccessFunction::startSaveDataWrite(mGameDataHolder);
}
if (SaveDataAccessFunction::updateSaveDataAccess(mGameDataHolder, false)) {
al::startHitReaction(mCurrentMenu, "リセット", 0);
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
}
}
2022-06-16 21:33:18 +00:00
void StageSceneStateServerConfig::endSubMenu() {
mCurrentList->deactivate();
mCurrentMenu->kill();
mCurrentList = mMainOptionsList;
mCurrentMenu = mMainOptions;
mCurrentMenu->startAppear("Appear");
al::startHitReaction(mCurrentMenu, "リセット", 0);
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
}
void StageSceneStateServerConfig::subMenuStart() {
mCurrentList->deactivate();
mCurrentMenu->kill();
activateInput();
2022-06-16 21:33:18 +00:00
mCurrentMenu->startAppear("Appear");
}
void StageSceneStateServerConfig::subMenuUpdate() {
mInput->update();
mCurrentList->update();
if (mInput->isTriggerUiUp()) {
mCurrentList->up();
}
if (mInput->isTriggerUiDown()) {
mCurrentList->down();
}
if (rs::isTriggerUiCancel(mHost)) {
endSubMenu();
}
if (rs::isTriggerUiDecide(mHost)) {
deactivateInput();
2022-06-16 21:33:18 +00:00
}
}
void StageSceneStateServerConfig::subMenuRefresh() {
mGamemodeConfigMenu = &mGamemodeConfigMenus[GameModeManager::instance()->getGameMode()];
mGamemodeConfigMenu->mList->initDataNoResetSelected(mGamemodeConfigMenu->mMenu->getMenuSize());
mGamemodeConfigMenu->mList->addStringData(mGamemodeConfigMenu->mMenu->getStringData(), "TxtContent");
mGamemodeConfigMenu->mList->updateParts();
activateInput();
}
2024-06-14 09:21:27 +00:00
const sead::WFixedSafeString<0x200>* StageSceneStateServerConfig::getMainMenuOptions() {
mMainMenuOptions->mBuffer[ServerConfigOption::HIDESERVER].copy(
Client::isServerHidden()
? u"Hide Server in Debug (ON) "
: u"Hide Server in Debug (OFF)"
);
return mMainMenuOptions->mBuffer;
}
void StageSceneStateServerConfig::activateInput() {
mInput->reset();
mCurrentList->activate();
mCurrentList->appearCursor();
mIsDecideConfig = false;
}
void StageSceneStateServerConfig::deactivateInput() {
al::startHitReaction(mCurrentMenu, "決定", 0);
mCurrentList->endCursor();
mCurrentList->decide();
mIsDecideConfig = true;
}
2022-06-16 21:33:18 +00:00
namespace {
2024-06-14 09:21:27 +00:00
NERVE_IMPL(StageSceneStateServerConfig, MainMenu)
NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardIP)
NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardPort)
NERVE_IMPL(StageSceneStateServerConfig, HideServer)
NERVE_IMPL(StageSceneStateServerConfig, GamemodeConfig)
NERVE_IMPL(StageSceneStateServerConfig, GamemodeSelect)
NERVE_IMPL(StageSceneStateServerConfig, SaveData)
2023-07-07 21:30:10 +00:00
}