#include "stdafx.h" #include "UI.h" #include "UIScene_CreateBattleMenu.h" #include "..\..\MinecraftServer.h" #include "..\..\Minecraft.h" #include "..\..\Options.h" #include "..\..\TexturePackRepository.h" #include "..\..\TexturePack.h" #include "..\..\..\Minecraft.World\LevelSettings.h" #include "..\..\..\Minecraft.World\StringHelpers.h" #include "..\..\..\Minecraft.World\BiomeSource.h" #include "..\..\..\Minecraft.World\IntCache.h" #include "..\..\..\Minecraft.World\LevelType.h" #include "..\..\DLCTexturePack.h" #ifdef __PSVITA__ #include "PSVita\Network\SQRNetworkManager_AdHoc_Vita.h" #endif #ifdef _WINDOWS64 #include #include "Xbox\Resource.h" #endif #define GAME_CREATE_ONLINE_TIMER_ID 0 #define GAME_CREATE_ONLINE_TIMER_TIME 100 int UIScene_CreateBattleMenu::m_iDifficultyTitleSettingA[] = { IDS_DIFFICULTY_PEACEFUL, IDS_DIFFICULTY_EASY, IDS_DIFFICULTY_NORMAL, IDS_DIFFICULTY_HARD }; UIScene_CreateBattleMenu::UIScene_CreateBattleMenu(int iPad, void* initData, UILayer* parentLayer) : IUIScene_StartGame(iPad, parentLayer) { // Setup Iggy UI initialiseMovie(); m_iPad = iPad; m_bIgnoreInput = false; // ---- Menu Title ---- m_labelMenuTitle.init(L"Battle"); // ---- Multiplayer permissions ---- m_bMultiplayerAllowed = ProfileManager.IsSignedInLive(m_iPad) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); bool bGameSetting_Online = (app.GetGameSettings(m_iPad, eGameSetting_Online) != 0); m_MoreOptionsParams.bOnlineSettingChangedBySystem = false; // ---- Central Spawn Checkbox ---- m_checkboxCentralSpawn.init(L"Central Spawn", eControl_CentralSpawn, TRUE); // ---- Online Game Checkbox ---- bool bOnlineGame = FALSE; if (m_bMultiplayerAllowed) { bOnlineGame = bGameSetting_Online ? TRUE : FALSE; m_MoreOptionsParams.bOnlineGame = bOnlineGame; if (bOnlineGame) { m_MoreOptionsParams.bInviteOnly = (app.GetGameSettings(m_iPad, eGameSetting_InviteOnly) != 0) ? TRUE : FALSE; m_MoreOptionsParams.bAllowFriendsOfFriends = (app.GetGameSettings(m_iPad, eGameSetting_FriendsOfFriends) != 0) ? TRUE : FALSE; } else { m_MoreOptionsParams.bInviteOnly = FALSE; m_MoreOptionsParams.bAllowFriendsOfFriends = FALSE; } } else { m_MoreOptionsParams.bOnlineGame = FALSE; m_MoreOptionsParams.bInviteOnly = FALSE; m_MoreOptionsParams.bAllowFriendsOfFriends = FALSE; if (bGameSetting_Online) m_MoreOptionsParams.bOnlineSettingChangedBySystem = true; } m_checkboxOnline.SetEnable(true); if (ProfileManager.IsSignedInLive(m_iPad) == false) m_checkboxOnline.SetEnable(false); if (m_MoreOptionsParams.bOnlineSettingChangedBySystem) { m_checkboxOnline.SetEnable(false); bOnlineGame = false; } m_checkboxOnline.init(L"Online Game", eControl_OnlineGame, bOnlineGame); // ---- Public Game Checkbox ---- m_checkboxPublicGame.init(L"Public Game", eControl_PublicGame, TRUE); // ---- Allow Friends Of Friends Checkbox ---- m_checkboxFriendsOfFriends.init(L"Allow Friends of Friends", eControl_FriendsOfFriends, TRUE); // ---- Invite Only Checkbox ---- m_checkboxInviteOnly.init(L"Invite Only", eControl_InviteOnly, FALSE); // ---- Select Maps Button ---- m_buttonSelectMaps.init(L"Select Maps", eControl_SelectMaps); // ---- Round Length Slider ---- WCHAR tempString[128]; swprintf(tempString, 128, L"Round Length: Normal"); m_sliderRoundLength.init(tempString, eControl_RoundLength, 0, 2, 1); // ---- Create Casual Button ---- m_buttonCreateWorld.init(L"Create Casual", eControl_CreateCasual); // ---- Timer ---- addTimer(GAME_CREATE_ONLINE_TIMER_ID, GAME_CREATE_ONLINE_TIMER_TIME); // ---- Telemetry ---- TelemetryManager->RecordMenuShown(m_iPad, eUIScene_CreateWorldMenu, 0); } UIScene_CreateBattleMenu::~UIScene_CreateBattleMenu() { } void UIScene_CreateBattleMenu::updateTooltips() { ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); } void UIScene_CreateBattleMenu::updateComponents() { m_parentLayer->showComponent(m_iPad,eUIComponent_Panorama,true); m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,false); } wstring UIScene_CreateBattleMenu::getMoviePath() { return L"CreateWorldMenu"; } UIControl* UIScene_CreateBattleMenu::GetMainPanel() { return &m_controlMainPanel; } void UIScene_CreateBattleMenu::handleDestroy() { #ifdef __PSVITA__ app.DebugPrintf("missing InputManager.DestroyKeyboard on Vita !!!!!!\n"); #endif // shut down the keyboard if it is displayed #if ( defined __PS3__ || defined __ORBIS__ || defined _DURANGO) InputManager.DestroyKeyboard(); #endif } void UIScene_CreateBattleMenu::tick() { UIScene::tick(); if(m_iSetTexturePackDescription >= 0 ) { UpdateTexturePackDescription( m_iSetTexturePackDescription ); m_iSetTexturePackDescription = -1; } if(m_bShowTexturePackDescription) { slideLeft(); m_texturePackDescDisplayed = true; m_bShowTexturePackDescription = false; } #ifdef __ORBIS__ // check the status of the PSPlus common dialog switch (sceNpCommerceDialogUpdateStatus()) { case SCE_COMMON_DIALOG_STATUS_FINISHED: { SceNpCommerceDialogResult Result; sceNpCommerceDialogGetResult(&Result); sceNpCommerceDialogTerminate(); if(Result.authorized) { ProfileManager.PsPlusUpdate(ProfileManager.GetPrimaryPad(), &Result); // they just became a PSPlus member checkStateAndStartGame(); } else { // continue offline? UINT uiIDA[1]; uiIDA[0]=IDS_PRO_NOTONLINE_DECLINE; // Give the player a warning about the texture pack missing ui.RequestAlertMessage(IDS_PLAY_OFFLINE,IDS_NO_PLAYSTATIONPLUS, uiIDA, 1, ProfileManager.GetPrimaryPad(),&UIScene_CreateBattleMenu::ContinueOffline,dynamic_cast(this)); } } break; default: break; } #endif } #ifdef __ORBIS__ int UIScene_CreateBattleMenu::ContinueOffline(void *pParam,int iPad,C4JStorage::EMessageResult result) { UIScene_CreateBattleMenu* pClass = (UIScene_CreateBattleMenu*)pParam; // results switched for this dialog if(result==C4JStorage::EMessage_ResultAccept) { pClass->m_MoreOptionsParams.bOnlineGame=false; pClass->checkStateAndStartGame(); } return 0; } #endif #ifdef _WINDOWS64 void UIScene_CreateBattleMenu::getDirectEditInputs(vector &inputs) { inputs.push_back(&m_editWorldName); } void UIScene_CreateBattleMenu::onDirectEditFinished(UIControl_TextInput *input, UIControl_TextInput::EDirectEditResult result) { m_worldName = input->getEditBuffer(); m_buttonCreateWorld.setEnable(!m_worldName.empty()); } #endif void UIScene_CreateBattleMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) { if(m_bIgnoreInput) return; #ifdef _WINDOWS64 if (isDirectEditBlocking()) { handled = true; return; } #endif ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released); switch(key) { case ACTION_MENU_CANCEL: if(pressed) { navigateBack(); handled = true; } break; case ACTION_MENU_OK: #ifdef __ORBIS__ case ACTION_MENU_TOUCHPAD_PRESS: #endif // 4J-JEV: Inform user why their game must be offline. #if defined _XBOX_ONE if ( pressed && controlHasFocus(m_checkboxOnline.getId()) && !m_checkboxOnline.IsEnabled() ) { UINT uiIDA[1] = { IDS_CONFIRM_OK }; ui.RequestErrorMessage(IDS_PRO_NOTONLINE_TITLE, IDS_PRO_XBOXLIVE_NOTIFICATION, uiIDA, 1, iPad); } #endif case ACTION_MENU_UP: case ACTION_MENU_DOWN: case ACTION_MENU_LEFT: case ACTION_MENU_RIGHT: case ACTION_MENU_OTHER_STICK_UP: case ACTION_MENU_OTHER_STICK_DOWN: sendInputToMovie(key, repeat, pressed, released); bool bOnlineGame = m_checkboxOnline.IsChecked(); if (m_MoreOptionsParams.bOnlineGame != bOnlineGame) { m_MoreOptionsParams.bOnlineGame = bOnlineGame; if (!m_MoreOptionsParams.bOnlineGame) { m_MoreOptionsParams.bInviteOnly = false; m_MoreOptionsParams.bAllowFriendsOfFriends = false; } } handled = true; break; } } void UIScene_CreateBattleMenu::handlePress(F64 controlId, F64 childId) { if(m_bIgnoreInput) return; #ifdef _WINDOWS64 if (isDirectEditBlocking()) return; #endif //CD - Added for audio ui.PlayUISFX(eSFX_Press); switch((int)controlId) { case eControl_EditWorldName: { m_bIgnoreInput=true; #ifdef _WINDOWS64 if (!g_KBMInput.IsKBMActive()) { UIKeyboardInitData kbData; kbData.title = L"Host Mini Game"; kbData.defaultText = m_editWorldName.getLabel(); kbData.maxChars = 25; kbData.callback = &UIScene_CreateBattleMenu::KeyboardCompleteWorldNameCallback; kbData.lpParam = this; ui.NavigateToScene(m_iPad, eUIScene_Keyboard, &kbData); } else { m_bIgnoreInput = false; m_editWorldName.beginDirectEdit(25); } #else InputManager.RequestKeyboard(app.GetString(IDS_CREATE_NEW_WORLD),m_editWorldName.getLabel(),(DWORD)0,25,&UIScene_CreateBattleMenu::KeyboardCompleteWorldNameCallback,this,C_4JInput::EKeyboardMode_Default); #endif } break; case eControl_GameModeToggle: switch(m_iGameModeId) { case 0: // Creative m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_CREATIVE)); m_iGameModeId = GameType::CREATIVE->getId(); m_bGameModeCreative = true; break; case 1: // Adventure m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_ADVENTURE)); m_iGameModeId = GameType::ADVENTURE->getId(); m_bGameModeCreative = false; break; case 2: // Survival m_buttonGamemode.setLabel(app.GetString(IDS_GAMEMODE_SURVIVAL)); m_iGameModeId = GameType::SURVIVAL->getId(); m_bGameModeCreative = false; }; break; case eControl_MoreOptions: ui.NavigateToScene(m_iPad, eUIScene_LaunchMoreOptionsMenu, &m_MoreOptionsParams); break; case eControl_TexturePackList: { UpdateCurrentTexturePack((int)childId); } break; case eControl_NewWorld: { #ifdef _DURANGO if(m_MoreOptionsParams.bOnlineGame) { m_bIgnoreInput = true; ProfileManager.CheckMultiplayerPrivileges(m_iPad, true, &checkPrivilegeCallback, this); } else #endif { StartSharedLaunchFlow(); } break; } } } #ifdef _DURANGO void UIScene_CreateBattleMenu::checkPrivilegeCallback(LPVOID lpParam, bool hasPrivilege, int iPad) { UIScene_CreateBattleMenu* pClass = (UIScene_CreateBattleMenu*)lpParam; if(hasPrivilege) { pClass->StartSharedLaunchFlow(); } else { pClass->m_bIgnoreInput = false; } } #endif void UIScene_CreateBattleMenu::StartSharedLaunchFlow() { // Stubbed, as Create Battle Menu does not need it. app.DebugPrintf("StartSharedLaunchFlow disabled\n"); } void UIScene_CreateBattleMenu::handleSliderMove(F64 sliderId, F64 currentValue) { WCHAR TempString[256]; int value = (int)currentValue; switch((int)sliderId) { case eControl_Difficulty: m_sliderDifficulty.handleSliderMove(value); app.SetGameSettings(m_iPad,eGameSetting_Difficulty,value); swprintf( (WCHAR *)TempString, 256, L"%ls: %ls", app.GetString( IDS_SLIDER_DIFFICULTY ),app.GetString(m_iDifficultyTitleSettingA[value])); m_sliderDifficulty.setLabel(TempString); break; } } void UIScene_CreateBattleMenu::handleTimerComplete(int id) { #ifdef __PSVITA__ // we cannot rebuild touch boxes in an iggy callback because it requires further iggy calls if(m_bRebuildTouchBoxes) { GetMainPanel()->UpdateControl(); ui.TouchBoxRebuild(this); m_bRebuildTouchBoxes = false; } #endif switch(id) { case GAME_CREATE_ONLINE_TIMER_ID: { bool bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); if(bMultiplayerAllowed != m_bMultiplayerAllowed) { if( bMultiplayerAllowed ) { bool bGameSetting_Online=(app.GetGameSettings(m_iPad,eGameSetting_Online)!=0); m_MoreOptionsParams.bOnlineGame = bGameSetting_Online?TRUE:FALSE; if(bGameSetting_Online) { m_MoreOptionsParams.bInviteOnly = (app.GetGameSettings(m_iPad,eGameSetting_InviteOnly)!=0)?TRUE:FALSE; m_MoreOptionsParams.bAllowFriendsOfFriends = (app.GetGameSettings(m_iPad,eGameSetting_FriendsOfFriends)!=0)?TRUE:FALSE; } else { m_MoreOptionsParams.bInviteOnly = FALSE; m_MoreOptionsParams.bAllowFriendsOfFriends = FALSE; } } else { m_MoreOptionsParams.bOnlineGame = FALSE; m_MoreOptionsParams.bInviteOnly = FALSE; m_MoreOptionsParams.bAllowFriendsOfFriends = FALSE; } m_checkboxOnline.SetEnable(bMultiplayerAllowed); m_checkboxOnline.setChecked(m_MoreOptionsParams.bOnlineGame); m_bMultiplayerAllowed = bMultiplayerAllowed; } } break; // 4J-PB - Only Xbox will not have trial DLC patched into the game #ifdef _XBOX case CHECKFORAVAILABLETEXTUREPACKS_TIMER_ID: { // also check for any new texture packs info being available // for each item in the mem list, check it's in the data list CXuiCtrl4JList::LIST_ITEM_INFO ListInfo; // for each iConfig, check if the data is available, and add it to the List, then remove it from the viConfig for(int i=0;i 0 && pbData) { DWORD dwImageBytes=0; PBYTE pbImageData=NULL; app.GetFileFromTPD(eTPDFileType_Icon,pbData,dwBytes,&pbImageData,&dwImageBytes ); ListInfo.fEnabled = TRUE; ListInfo.iData = m_iConfigA[i]; HRESULT hr=XuiCreateTextureBrushFromMemory(pbImageData,dwImageBytes,&ListInfo.hXuiBrush); app.DebugPrintf("Adding texturepack %d from TPD\n",m_iConfigA[i]); m_pTexturePacksList->AddData(ListInfo); m_iConfigA[i]=-1; } } } } break; #endif }; } void UIScene_CreateBattleMenu::handleGainFocus(bool navBack) { if(navBack) { m_checkboxOnline.setChecked(m_MoreOptionsParams.bOnlineGame); } } int UIScene_CreateBattleMenu::KeyboardCompleteWorldNameCallback(LPVOID lpParam,bool bRes) { UIScene_CreateBattleMenu *pClass=(UIScene_CreateBattleMenu *)lpParam; pClass->m_bIgnoreInput=false; // 4J HEG - No reason to set value if keyboard was cancelled if (bRes) { uint16_t pchText[128]; ZeroMemory(pchText, 128 * sizeof(uint16_t) ); #ifdef _WINDOWS64 Win64_GetKeyboardText(pchText, 128); #else InputManager.GetText(pchText); #endif if(pchText[0]!=0) { pClass->m_editWorldName.setLabel((wchar_t *)pchText); pClass->m_worldName = (wchar_t *)pchText; } pClass->m_buttonCreateWorld.setEnable( !pClass->m_worldName.empty() ); } return 0; } void UIScene_CreateBattleMenu::checkStateAndStartGame() { app.DebugPrintf("checkStateAndStartGame disabled\n"); } // Stubbed out, CreateBattleMenu repurposing soon? void UIScene_CreateBattleMenu::CreateGame(UIScene_CreateBattleMenu* pClass, DWORD dwLocalUsersMask) { app.DebugPrintf("CreateGame disabled\n"); } int UIScene_CreateBattleMenu::ConfirmCreateReturned(void* pParam, int iPad, C4JStorage::EMessageResult result) { app.DebugPrintf("ConfirmCreateReturned disabled\n"); return 0; } #ifdef __ORBIS__ int UIScene_CreateBattleMenu::MustSignInReturnedPSN(void *pParam,int iPad,C4JStorage::EMessageResult result) { UIScene_CreateBattleMenu* pClass = (UIScene_CreateBattleMenu *)pParam; pClass->m_bIgnoreInput = false; if(result==C4JStorage::EMessage_ResultAccept) { SQRNetworkManager_Orbis::AttemptPSNSignIn(&UIScene_CreateBattleMenu::StartGame_SignInReturned, pClass, false, iPad); } return 0; } // int UIScene_CreateBattleMenu::PSPlusReturned(void *pParam,int iPad,C4JStorage::EMessageResult result) // { // int32_t iResult; // UIScene_CreateBattleMenu *pClass = (UIScene_CreateBattleMenu *)pParam; // // // continue offline, or upsell PS Plus? // if(result==C4JStorage::EMessage_ResultDecline) // { // // upsell psplus // int32_t iResult=sceNpCommerceDialogInitialize(); // // SceNpCommerceDialogParam param; // sceNpCommerceDialogParamInitialize(¶m); // param.mode=SCE_NP_COMMERCE_DIALOG_MODE_PLUS; // param.features = SCE_NP_PLUS_FEATURE_REALTIME_MULTIPLAY; // param.userId = ProfileManager.getUserID(pClass->m_iPad); // // iResult=sceNpCommerceDialogOpen(¶m); // } // else if(result==C4JStorage::EMessage_ResultAccept) // { // // continue offline // pClass->m_MoreOptionsParams.bOnlineGame=false; // pClass->checkStateAndStartGame(); // } // // pClass->m_bIgnoreInput=false; // return 0; // } #endif void UIScene_CreateBattleMenu::handleTouchBoxRebuild() { m_bRebuildTouchBoxes = true; }