#include "UI.h" #include "UIScene_InGameHostOptionsMenu.h" #include "..\..\MultiPlayerLocalPlayer.h" #include "..\..\ClientConnection.h" #include "..\..\MultiPlayerLevel.h" int m_iGamemodeTitleSetting[3]= { IDS_SURVIVAL, IDS_CREATIVE, IDS_ADVENTURE }; int m_iDifficultyTitleSetting[4]= { IDS_DIFFICULTY_TITLE_PEACEFUL, IDS_DIFFICULTY_TITLE_EASY, IDS_DIFFICULTY_TITLE_NORMAL, IDS_DIFFICULTY_TITLE_HARD }; UIScene_InGameHostOptionsMenu::UIScene_InGameHostOptionsMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) { // Setup all the Iggy references we need for this scene initialiseMovie(); Init(); } void UIScene_InGameHostOptionsMenu::Init() { m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_FIRE_SPREADS), eControl_FireSpreads, app.GetGameHostOption(eGameHostOption_FireSpreads) != 0); m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_TNT_EXPLODES), eControl_TNT, app.GetGameHostOption(eGameHostOption_TNT) != 0); if (app.GetGameHostOption(eGameHostOption_CheatsEnabled)) { m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_MOB_LOOT), eControl_DoMobLoot, app.GetGameHostOption(eGameHostOption_DoMobLoot)); m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_TILE_DROPS), eControl_DoTileDrops, app.GetGameHostOption(eGameHostOption_DoTileDrops)); m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_NATURAL_REGEN), eControl_NaturalRegeneration, app.GetGameHostOption(eGameHostOption_NaturalRegeneration)); m_hostOptionsList.AddNewButton(L"Set Day", eControl_TimeSetDay); m_hostOptionsList.AddNewButton(L"Set Night", eControl_TimeSetNight); int m_CurrentDifficulty = app.GetGameSettings(m_iPad, eGameSetting_Difficulty); WCHAR TempString[256]; swprintf_s(TempString, 256, L"%ls: %ls", app.GetString(IDS_SLIDER_DIFFICULTY), app.GetString(m_iDifficultyTitleSetting[app.GetGameSettings(m_iPad, eGameSetting_Difficulty)])); m_hostOptionsList.AddNewSlider(TempString, eControl_Difficulty, 0, 3, app.GetGameSettings(m_iPad, eGameSetting_Difficulty)); swprintf_s(TempString, 256, L"Game Mode: %ls", app.GetString(m_iGamemodeTitleSetting[0])); m_hostOptionsList.AddNewSlider(TempString, eControl_GameType, 0, 2, 0); m_hostOptionsList.AddNewButton(L"Set World Spawn Point", eControl_PlayerPermissions); auto* pMinecraft = Minecraft::GetInstance(); if (pMinecraft->getLevel(0)) { m_hostOptionsList.AddNewLabel(L""); m_hostOptionsList.AddNewLabel(L"Weather"); int weatherState = pMinecraft->getLevel(0)->getWeatherState(); std::wstring weatherString = L""; // TODO: Confirm if these names are correct if (weatherState == 1) weatherString = L"Rain"; else if (weatherState == 2) weatherString = L"Thunder"; else weatherString = L"Clear"; m_hostOptionsList.AddNewSlider(weatherString, eControl_Weather, 0, 2, 0); } m_hostOptionsList.AddNewCheckbox(L"Weather Cycle", eControl_ShowCoordinates, 0); } m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_MOB_GRIEFING), eControl_MobGriefing, app.GetGameHostOption(eGameHostOption_MobGriefing)); m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_KEEP_INVENTORY), eControl_KeepInventory, app.GetGameHostOption(eGameHostOption_KeepInventory)); m_hostOptionsList.AddNewCheckbox(app.GetString(IDS_MOB_SPAWNING), eControl_DoMobSpawning, app.GetGameHostOption(eGameHostOption_DoMobSpawning)); auto* localPlayer = g_NetworkManager.GetLocalPlayerByUserIndex(m_iPad); if (!localPlayer) { app.DebugPrintf(" Error: couldn't retrieve network player %d\n", localPlayer->GetOnlineName()); return; } unsigned int privs = app.GetPlayerPrivileges(localPlayer->GetSmallId()); const bool canTeleport = app.GetGameHostOption(eGameHostOption_CheatsEnabled) && Player::getPlayerGamePrivilege(privs, Player::ePlayerGamePrivilege_CanTeleport) && g_NetworkManager.GetPlayerCount() > 1; if (canTeleport) { m_hostOptionsList.AddNewButton(app.GetString(IDS_TELEPORT_TO_PLAYER), eControl_TeleportToPlayer); m_hostOptionsList.AddNewButton(app.GetString(IDS_TELEPORT_TO_ME), eControl_TeleportToMe); } } wstring UIScene_InGameHostOptionsMenu::getMoviePath() { if(app.GetLocalPlayerCount() > 1) return L"InGameHostOptionsSplit"; else return L"InGameHostOptions"; } void UIScene_InGameHostOptionsMenu::updateTooltips() { ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); } void UIScene_InGameHostOptionsMenu::handleReload() { UIScene::handleReload(); /* // If cheats are disabled, remove checkboxes if (!app.GetGameHostOption(eGameHostOption_CheatsEnabled)) { removeControl(&m_checkboxMobGriefing, true); removeControl(&m_checkboxKeepInventory, true); removeControl(&m_checkboxDoMobSpawning, true); removeControl(&m_checkboxDoDaylightCycle, true); } */ INetworkPlayer *localPlayer = g_NetworkManager.GetLocalPlayerByUserIndex( m_iPad ); if (!localPlayer) return; unsigned int privs = app.GetPlayerPrivileges(localPlayer->GetSmallId()); const bool canTeleport = app.GetGameHostOption(eGameHostOption_CheatsEnabled) && Player::getPlayerGamePrivilege(privs, Player::ePlayerGamePrivilege_CanTeleport) && g_NetworkManager.GetPlayerCount() > 1; if(!canTeleport) { //removeControl(&m_buttonTeleportToPlayer, true); //removeControl(&m_buttonTeleportToMe, true); } } void UIScene_InGameHostOptionsMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) { ui.AnimateKeyPress(iPad, key, repeat, pressed, released); switch(key) { case ACTION_MENU_CANCEL: if(pressed) { /* unsigned int hostOptions = app.GetGameHostOption(eGameHostOption_All); app.SetGameHostOption(hostOptions, eGameHostOption_FireSpreads, m_checkboxFireSpreads.IsChecked()); app.SetGameHostOption(hostOptions, eGameHostOption_TNT, m_checkboxTNT.IsChecked()); app.SetGameHostOption(hostOptions, eGameHostOption_DoMobLoot, m_checkboxDoMobLoot.IsChecked()); app.SetGameHostOption(hostOptions, eGameHostOption_DoTileDrops, m_checkboxDoTileDrops.IsChecked()); app.SetGameHostOption(hostOptions, eGameHostOption_NaturalRegeneration, m_checkboxNaturalRegeneration.IsChecked()); // If cheats are enabled, set cheat values if (app.GetGameHostOption(eGameHostOption_CheatsEnabled)) { app.SetGameHostOption(hostOptions, eGameHostOption_MobGriefing, m_checkboxMobGriefing.IsChecked()); app.SetGameHostOption(hostOptions, eGameHostOption_KeepInventory, m_checkboxKeepInventory.IsChecked()); app.SetGameHostOption(hostOptions, eGameHostOption_DoMobSpawning, m_checkboxDoMobSpawning.IsChecked()); app.SetGameHostOption(hostOptions, eGameHostOption_DoDaylightCycle, m_checkboxDoDaylightCycle.IsChecked()); } // Send update settings packet to server if(hostOptions != app.GetGameHostOption(eGameHostOption_All) ) { Minecraft *pMinecraft = Minecraft::GetInstance(); shared_ptr player = pMinecraft->localplayers[m_iPad]; if(player->connection) player->connection->send(std::make_shared(ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS, hostOptions)); } */ navigateBack(); handled = true; } break; case ACTION_MENU_OK: #ifdef __ORBIS__ case ACTION_MENU_TOUCHPAD_PRESS: #endif sendInputToMovie(key, repeat, pressed, released); break; case ACTION_MENU_UP: case ACTION_MENU_DOWN: sendInputToMovie(key, repeat, pressed, released); break; } } void UIScene_InGameHostOptionsMenu::handlePress(F64 controlId, F64 childId) { auto *initData = new TeleportMenuInitData(); initData->iPad = m_iPad; initData->teleportToPlayer = false; if( static_cast(controlId) == eControl_TeleportToPlayer ) initData->teleportToPlayer = true; ui.NavigateToScene(m_iPad,eUIScene_TeleportMenu,(void*)initData); }