SuperMarioOdysseyOnline/source/states/StageSceneStateServerConfig.cpp

381 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"
#include "basis/seadNew.h"
#include "game/Layouts/CommonVerticalList.h"
#include "game/SaveData/SaveDataAccessFunction.h"
2022-06-16 21:33:18 +00:00
#include "server/Client.hpp"
#include "al/util.hpp"
#include "al/util/NerveUtil.h"
#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"
2022-08-07 21:42:56 +00:00
#include "server/gamemode/GameModeConfigMenuFactory.hpp"
2022-06-16 21:33:18 +00:00
#include "server/gamemode/GameModeFactory.hpp"
2022-08-07 21:42:56 +00:00
#include "server/gamemode/GameModeManager.hpp"
#include "server/hns/HideAndSeekMode.hpp"
2022-06-16 21:33:18 +00:00
// WIP work on RollPartsData, not exactly working out atm
const char16_t* testValues[] = {u"Test 1", u"Test 2", u"Test 3", u"Test 4", u"Test 5",
u"Test 6", u"Test 7", u"Test 8", u"Test 9"};
2022-06-16 21:33:18 +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;
mGameDataHolder = dataHolder;
mMsgSystem = initInfo.getMessageSystem();
mInput = new InputSeparator(mHost, true);
// page 0 menu
mMainOptions = new SimpleLayoutMenu("ServerConfigMenu", "OptionSelect", initInfo, 0, false);
mMainOptionsList = new CommonVerticalList(mMainOptions, initInfo, true);
al::setPaneString(mMainOptions, "TxtOption", u"Server Configuration", 0);
mMainOptionsList->unkInt1 = 1;
mMainOptionsList->initDataNoResetSelected(5);
2022-06-16 21:33:18 +00:00
sead::SafeArray<sead::WFixedSafeString<0x200>, 5>* mainMenuOptions =
new sead::SafeArray<sead::WFixedSafeString<0x200>, 5>();
2022-06-16 21:33:18 +00:00
mainMenuOptions->mBuffer[ServerConfigOption::GAMEMODECONFIG].copy(u"Gamemode Config");
mainMenuOptions->mBuffer[ServerConfigOption::GAMEMODESWITCH].copy(u"Change Gamemode");
mainMenuOptions->mBuffer[ServerConfigOption::RECONNECT].copy(u"Reconnect to Server");
mainMenuOptions->mBuffer[ServerConfigOption::SETIP].copy(u"Change Server IP");
mainMenuOptions->mBuffer[ServerConfigOption::SETPORT].copy(u"Change Server Port");
2022-06-16 21:33:18 +00:00
mMainOptionsList->addStringData(mainMenuOptions->mBuffer, "TxtContent");
// WIP work on RollPartsData, not exactly working out atm
// RollPartsData* testArr = new RollPartsData[2]();
// for (int i = 0; i < 2; i++) {
// RollPartsData* part = &testArr[i];
// part->mRollMsgCount = 3;
// part->mRollMsgList = testValues;
// part->unkInt1 = 0;
// part->mUnkBool = i == 0;
// }
//mMainOptionsList->startLoopActionAll("Loop", "Loop");
// mMainOptionsList->setRollPartsData(testArr);
2022-06-16 21:33:18 +00:00
// gamemode select menu
mModeSelect = new SimpleLayoutMenu("GamemodeSelectMenu", "OptionSelect", initInfo, 0, false);
mModeSelectList = new CommonVerticalList(mModeSelect, initInfo, true);
al::setPaneString(mModeSelect, "TxtOption", u"Gamemode Selection", 0);
const int modeCount = GameModeFactory::getModeCount();
mModeSelectList->initDataNoResetSelected(modeCount);
sead::SafeArray<sead::WFixedSafeString<0x200>, modeCount>* modeSelectOptions =
new sead::SafeArray<sead::WFixedSafeString<0x200>, modeCount>();
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];
const char* name = factory.getMenuName(mode);
entry.mMenu = factory.getCreator(name)(name);
entry.mLayout = new SimpleLayoutMenu("GameModeConfigMenu", "OptionSelect", initInfo, 0, false);
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
2022-08-07 21:42:56 +00:00
entry.mList->initDataNoResetSelected(entry.mMenu->getMenuSize());
2022-06-16 21:33:18 +00:00
2022-08-07 21:42:56 +00:00
entry.mList->addStringData(entry.mMenu->getStringData(), "TxtContent");
2022-06-16 21:33:18 +00:00
}
2022-08-07 21:42:56 +00:00
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);
}
void StageSceneStateServerConfig::appear(void) {
mCurrentMenu->startAppear("Appear");
al::NerveStateBase::appear();
}
void StageSceneStateServerConfig::kill(void) {
mCurrentMenu->startEnd("End");
al::NerveStateBase::kill();
}
al::MessageSystem* StageSceneStateServerConfig::getMessageSystem(void) const {
return mMsgSystem;
}
void StageSceneStateServerConfig::exeMainMenu() {
if (al::isFirstStep(this)) {
mInput->reset();
mCurrentList->activate();
mCurrentList->appearCursor();
mIsDecideConfig = false;
}
mInput->update();
mCurrentList->update();
if (mInput->isTriggerUiUp()) {
mCurrentList->up(); }
if (mInput->isTriggerUiDown()) {
mCurrentList->down();
}
if (rs::isTriggerUiCancel(mHost)) {
kill();
}
if (rs::isTriggerUiDecide(mHost)) {
al::startHitReaction(mCurrentMenu, "決定", 0);
mCurrentList->endCursor();
mCurrentList->decide();
mIsDecideConfig = true;
}
if (mIsDecideConfig && mCurrentList->isDecideEnd()) {
switch (mCurrentList->mCurSelected) {
case ServerConfigOption::GAMEMODECONFIG: {
al::setNerve(this, &nrvStageSceneStateServerConfigGamemodeConfig);
break;
}
case ServerConfigOption::GAMEMODESWITCH: {
al::setNerve(this, &nrvStageSceneStateServerConfigGamemodeSelect);
break;
}
case ServerConfigOption::RECONNECT: {
al::setNerve(this, &nrvStageSceneStateServerConfigRestartServer);
break;
}
case ServerConfigOption::SETIP: {
al::setNerve(this, &nrvStageSceneStateServerConfigOpenKeyboardIP);
break;
}
case ServerConfigOption::SETPORT: {
al::setNerve(this, &nrvStageSceneStateServerConfigOpenKeyboardPort);
2022-06-16 21:33:18 +00:00
break;
}
default:
kill();
break;
}
}
}
void StageSceneStateServerConfig::exeOpenKeyboardIP() {
if (al::isFirstStep(this)) {
mCurrentList->deactivate();
Client::getKeyboard()->setHeaderText(u"Set a Server IP Below.");
Client::getKeyboard()->setSubText(u"");
bool isSave = Client::openKeyboardIP(); // anything that happens after this will be ran after the keyboard closes
al::startHitReaction(mCurrentMenu, "リセット", 0);
if(isSave)
al::setNerve(this, &nrvStageSceneStateServerConfigSaveData);
else
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
}
}
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);
if(isSave)
al::setNerve(this, &nrvStageSceneStateServerConfigSaveData);
else
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
2022-06-16 21:33:18 +00:00
}
}
void StageSceneStateServerConfig::exeRestartServer() {
if (al::isFirstStep(this)) {
mCurrentList->deactivate();
Client::showConnect();
Client::restartConnection();
2022-06-16 21:33:18 +00:00
}
if (Client::isSocketActive()) {
Client::hideConnect();
2022-06-16 21:33:18 +00:00
al::startHitReaction(mCurrentMenu, "リセット", 0);
2022-06-16 21:33:18 +00:00
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
} else {
al::setNerve(this, &nrvStageSceneStateServerConfigConnectError);
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()];
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()) {
2022-08-07 21:42:56 +00:00
if (mGamemodeConfigMenu->mMenu->updateMenu(mCurrentList->mCurSelected)) {
2022-06-16 21:33:18 +00:00
endSubMenu();
}
}
}
void StageSceneStateServerConfig::exeGamemodeSelect() {
if (al::isFirstStep(this)) {
2022-06-16 21:33:18 +00:00
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::exeConnectError() {
if (al::isFirstStep(this)) {
Client::showConnectError(u"Failed to Reconnect!");
}
if (al::isGreaterEqualStep(this, 60)) { // close after 1 second
Client::hideConnect();
al::startHitReaction(mCurrentMenu, "リセット", 0);
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
}
}
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();
mInput->reset();
mCurrentList->activate();
mCurrentList->appearCursor();
mCurrentMenu->startAppear("Appear");
mIsDecideConfig = false;
}
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)) {
al::startHitReaction(mCurrentMenu, "決定", 0);
mCurrentList->endCursor();
mCurrentList->decide();
mIsDecideConfig = true;
}
}
2022-06-16 21:33:18 +00:00
namespace {
NERVE_IMPL(StageSceneStateServerConfig, MainMenu)
NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardIP)
NERVE_IMPL(StageSceneStateServerConfig, OpenKeyboardPort)
2022-06-16 21:33:18 +00:00
NERVE_IMPL(StageSceneStateServerConfig, RestartServer)
NERVE_IMPL(StageSceneStateServerConfig, GamemodeConfig)
NERVE_IMPL(StageSceneStateServerConfig, GamemodeSelect)
NERVE_IMPL(StageSceneStateServerConfig, SaveData)
NERVE_IMPL(StageSceneStateServerConfig, ConnectError)
2022-06-16 21:33:18 +00:00
}