the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 400 lines 10 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h" 4#include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.entity.h" 5#include "MultiPlayerLocalPlayer.h" 6#include "..\..\Minecraft.h" 7#include "UIScene_AnvilMenu.h" 8 9UIScene_AnvilMenu::UIScene_AnvilMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer) 10{ 11 // Setup all the Iggy references we need for this scene 12 initialiseMovie(); 13 14 m_showingCross = false; 15 m_textInputAnvil.init(m_itemName,eControl_TextInput); 16 17 m_labelAnvil.init( app.GetString(IDS_REPAIR_AND_NAME) ); 18 19 AnvilScreenInput *initData = (AnvilScreenInput *)_initData; 20 m_inventory = initData->inventory; 21 22 Minecraft *pMinecraft = Minecraft::GetInstance(); 23 if( pMinecraft->localgameModes[iPad] != NULL ) 24 { 25 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[iPad]; 26 m_previousTutorialState = gameMode->getTutorial()->getCurrentState(); 27 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Anvil_Menu, this); 28 } 29 30 m_repairMenu = new AnvilMenu( initData->inventory, initData->level, initData->x, initData->y, initData->z, pMinecraft->localplayers[iPad] ); 31 m_repairMenu->addSlotListener(this); 32 33 Initialize( iPad, m_repairMenu, true, AnvilMenu::INV_SLOT_START, eSectionAnvilUsing, eSectionAnvilMax ); 34 35 m_slotListItem1.addSlots(AnvilMenu::INPUT_SLOT, 1); 36 m_slotListItem2.addSlots(AnvilMenu::ADDITIONAL_SLOT, 1); 37 m_slotListResult.addSlots(AnvilMenu::RESULT_SLOT, 1); 38 39 bool expensive = false; 40 wstring m_costString = L""; 41 42 if(m_repairMenu->cost > 0) 43 { 44 if(m_repairMenu->cost >= 40 && !pMinecraft->localplayers[iPad]->abilities.instabuild) 45 { 46 m_costString = app.GetString(IDS_REPAIR_EXPENSIVE); 47 expensive = true; 48 } 49 else if(!m_repairMenu->getSlot(AnvilMenu::RESULT_SLOT)->hasItem()) 50 { 51 // Do nothing 52 } 53 else 54 { 55 LPCWSTR costString = app.GetString(IDS_REPAIR_COST); 56 wchar_t temp[256]; 57 swprintf(temp, 256, costString, m_repairMenu->cost); 58 m_costString = temp; 59 if(!m_repairMenu->getSlot(AnvilMenu::RESULT_SLOT)->mayPickup(dynamic_pointer_cast<Player>(m_inventory->player->shared_from_this()))) 60 { 61 expensive = true; 62 } 63 } 64 } 65 setCostLabel(m_costString, expensive); 66 67 if(initData) delete initData; 68 69 setIgnoreInput(false); 70 71 app.SetRichPresenceContext(iPad, CONTEXT_GAME_STATE_ANVIL); 72} 73 74wstring UIScene_AnvilMenu::getMoviePath() 75{ 76 if(app.GetLocalPlayerCount() > 1) 77 { 78 return L"AnvilMenuSplit"; 79 } 80 else 81 { 82 return L"AnvilMenu"; 83 } 84} 85 86void UIScene_AnvilMenu::handleReload() 87{ 88 Initialize( m_iPad, m_menu, true, AnvilMenu::INV_SLOT_START, eSectionAnvilUsing, eSectionAnvilMax ); 89 90 m_slotListItem1.addSlots(AnvilMenu::INPUT_SLOT, 1); 91 m_slotListItem2.addSlots(AnvilMenu::ADDITIONAL_SLOT, 1); 92 m_slotListResult.addSlots(AnvilMenu::RESULT_SLOT, 1); 93} 94 95void UIScene_AnvilMenu::tick() 96{ 97 UIScene_AbstractContainerMenu::tick(); 98 99 handleTick(); 100} 101 102int UIScene_AnvilMenu::getSectionColumns(ESceneSection eSection) 103{ 104 int cols = 0; 105 switch( eSection ) 106 { 107 case eSectionAnvilItem1: 108 cols = 1; 109 break; 110 case eSectionAnvilItem2: 111 cols = 1; 112 break; 113 case eSectionAnvilResult: 114 cols = 1; 115 break; 116 case eSectionAnvilInventory: 117 cols = 9; 118 break; 119 case eSectionAnvilUsing: 120 cols = 9; 121 break; 122 default: 123 assert( false ); 124 break; 125 } 126 return cols; 127} 128 129int UIScene_AnvilMenu::getSectionRows(ESceneSection eSection) 130{ 131 int rows = 0; 132 switch( eSection ) 133 { 134 case eSectionAnvilItem1: 135 rows = 1; 136 break; 137 case eSectionAnvilItem2: 138 rows = 1; 139 break; 140 case eSectionAnvilResult: 141 rows = 1; 142 break; 143 case eSectionAnvilInventory: 144 rows = 3; 145 break; 146 case eSectionAnvilUsing: 147 rows = 1; 148 break; 149 default: 150 assert( false ); 151 break; 152 } 153 return rows; 154} 155 156void UIScene_AnvilMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition ) 157{ 158 switch( eSection ) 159 { 160 case eSectionAnvilItem1: 161 pPosition->x = m_slotListItem1.getXPos(); 162 pPosition->y = m_slotListItem1.getYPos(); 163 break; 164 case eSectionAnvilItem2: 165 pPosition->x = m_slotListItem2.getXPos(); 166 pPosition->y = m_slotListItem2.getYPos(); 167 break; 168 case eSectionAnvilResult: 169 pPosition->x = m_slotListResult.getXPos(); 170 pPosition->y = m_slotListResult.getYPos(); 171 break; 172 case eSectionAnvilName: 173 pPosition->x = m_textInputAnvil.getXPos(); 174 pPosition->y = m_textInputAnvil.getYPos(); 175 break; 176 case eSectionAnvilInventory: 177 pPosition->x = m_slotListInventory.getXPos(); 178 pPosition->y = m_slotListInventory.getYPos(); 179 break; 180 case eSectionAnvilUsing: 181 pPosition->x = m_slotListHotbar.getXPos(); 182 pPosition->y = m_slotListHotbar.getYPos(); 183 break; 184 default: 185 assert( false ); 186 break; 187 } 188} 189 190void UIScene_AnvilMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize ) 191{ 192 UIVec2D sectionSize; 193 194 switch( eSection ) 195 { 196 case eSectionAnvilItem1: 197 sectionSize.x = m_slotListItem1.getWidth(); 198 sectionSize.y = m_slotListItem1.getHeight(); 199 break; 200 case eSectionAnvilItem2: 201 sectionSize.x = m_slotListItem2.getWidth(); 202 sectionSize.y = m_slotListItem2.getHeight(); 203 break; 204 case eSectionAnvilResult: 205 sectionSize.x = m_slotListResult.getWidth(); 206 sectionSize.y = m_slotListResult.getHeight(); 207 break; 208 case eSectionAnvilName: 209 sectionSize.x = m_textInputAnvil.getWidth(); 210 sectionSize.y = m_textInputAnvil.getHeight(); 211 break; 212 case eSectionAnvilInventory: 213 sectionSize.x = m_slotListInventory.getWidth(); 214 sectionSize.y = m_slotListInventory.getHeight(); 215 break; 216 case eSectionAnvilUsing: 217 sectionSize.x = m_slotListHotbar.getWidth(); 218 sectionSize.y = m_slotListHotbar.getHeight(); 219 break; 220 default: 221 assert( false ); 222 break; 223 } 224 225 if(IsSectionSlotList(eSection)) 226 { 227 int rows = getSectionRows(eSection); 228 int cols = getSectionColumns(eSection); 229 230 pSize->x = sectionSize.x/cols; 231 pSize->y = sectionSize.y/rows; 232 233 int itemCol = iItemIndex % cols; 234 int itemRow = iItemIndex/cols; 235 236 pPosition->x = itemCol * pSize->x; 237 pPosition->y = itemRow * pSize->y; 238 } 239 else 240 { 241 GetPositionOfSection(eSection, pPosition); 242 pSize->x = sectionSize.x; 243 pSize->y = sectionSize.y; 244 } 245} 246 247void UIScene_AnvilMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y) 248{ 249 int cols = getSectionColumns(eSection); 250 251 int index = (y * cols) + x; 252 253 UIControl_SlotList *slotList = NULL; 254 switch( eSection ) 255 { 256 case eSectionAnvilItem1: 257 slotList = &m_slotListItem1; 258 break; 259 case eSectionAnvilItem2: 260 slotList = &m_slotListItem2; 261 break; 262 case eSectionAnvilResult: 263 slotList = &m_slotListResult; 264 break; 265 case eSectionAnvilInventory: 266 slotList = &m_slotListInventory; 267 break; 268 case eSectionAnvilUsing: 269 slotList = &m_slotListHotbar; 270 break; 271 default: 272 assert( false ); 273 break; 274 } 275 276 slotList->setHighlightSlot(index); 277} 278 279UIControl *UIScene_AnvilMenu::getSection(ESceneSection eSection) 280{ 281 UIControl *control = NULL; 282 switch( eSection ) 283 { 284 case eSectionAnvilItem1: 285 control = &m_slotListItem1; 286 break; 287 case eSectionAnvilItem2: 288 control = &m_slotListItem2; 289 break; 290 case eSectionAnvilResult: 291 control = &m_slotListResult; 292 break; 293 case eSectionAnvilName: 294 control = &m_textInputAnvil; 295 break; 296 case eSectionAnvilInventory: 297 control = &m_slotListInventory; 298 break; 299 case eSectionAnvilUsing: 300 control = &m_slotListHotbar; 301 break; 302 default: 303 assert( false ); 304 break; 305 } 306 return control; 307} 308 309int UIScene_AnvilMenu::KeyboardCompleteCallback(LPVOID lpParam,bool bRes) 310{ 311 // 4J HEG - No reason to set value if keyboard was cancelled 312 UIScene_AnvilMenu *pClass=(UIScene_AnvilMenu *)lpParam; 313 pClass->setIgnoreInput(false); 314 315 if (bRes) 316 { 317 uint16_t pchText[128]; 318 ZeroMemory(pchText, 128 * sizeof(uint16_t) ); 319 InputManager.GetText(pchText); 320 pClass->setEditNameValue((wchar_t *)pchText); 321 pClass->m_itemName = (wchar_t *)pchText; 322 pClass->updateItemName(); 323 } 324 return 0; 325} 326 327void UIScene_AnvilMenu::handleEditNamePressed() 328{ 329 setIgnoreInput(true); 330#if defined(__PS3__) || defined(__ORBIS__) || defined __PSVITA__ 331 int language = XGetLanguage(); 332 switch(language) 333 { 334 case XC_LANGUAGE_JAPANESE: 335 case XC_LANGUAGE_KOREAN: 336 case XC_LANGUAGE_TCHINESE: 337 InputManager.RequestKeyboard(app.GetString(IDS_TITLE_RENAME),m_textInputAnvil.getLabel(),(DWORD)m_iPad,30,&UIScene_AnvilMenu::KeyboardCompleteCallback,this,C_4JInput::EKeyboardMode_Default); 338 break; 339 default: 340 // 4J Stu - Use a different keyboard for non-asian languages so we don't have prediction on 341 InputManager.RequestKeyboard(app.GetString(IDS_TITLE_RENAME),m_textInputAnvil.getLabel(),(DWORD)m_iPad,30,&UIScene_AnvilMenu::KeyboardCompleteCallback,this,C_4JInput::EKeyboardMode_Alphabet_Extended); 342 break; 343 } 344#else 345 InputManager.RequestKeyboard(app.GetString(IDS_TITLE_RENAME),m_textInputAnvil.getLabel(),(DWORD)m_iPad,30,&UIScene_AnvilMenu::KeyboardCompleteCallback,this,C_4JInput::EKeyboardMode_Default); 346#endif 347} 348 349void UIScene_AnvilMenu::setEditNameValue(const wstring &name) 350{ 351 m_textInputAnvil.setLabel(name); 352} 353 354void UIScene_AnvilMenu::setEditNameEditable(bool enabled) 355{ 356} 357 358void UIScene_AnvilMenu::setCostLabel(const wstring &label, bool canAfford) 359{ 360 IggyDataValue result; 361 IggyDataValue value[2]; 362 363 IggyStringUTF16 stringVal; 364 stringVal.string = (IggyUTF16*)label.c_str(); 365 stringVal.length = label.length(); 366 value[0].type = IGGY_DATATYPE_string_UTF16; 367 value[0].string16 = stringVal; 368 369 value[1].type = IGGY_DATATYPE_boolean; 370 value[1].boolval = canAfford; 371 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetCostLabel , 2 , value ); 372} 373 374void UIScene_AnvilMenu::showCross(bool show) 375{ 376 if(m_showingCross != show) 377 { 378 IggyDataValue result; 379 IggyDataValue value[1]; 380 381 value[0].type = IGGY_DATATYPE_boolean; 382 value[0].boolval = show; 383 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowRedCross , 1 , value ); 384 385 m_showingCross = show; 386 } 387} 388 389void UIScene_AnvilMenu::handleDestroy() 390{ 391#ifdef __PSVITA__ 392 app.DebugPrintf("missing InputManager.DestroyKeyboard on Vita !!!!!!\n"); 393#endif 394 395 // another player destroyed the anvil, so shut down the keyboard if it is displayed 396#if ( defined __PS3__ || defined __ORBIS__ || defined _DURANGO) 397 InputManager.DestroyKeyboard(); 398#endif 399 UIScene_AbstractContainerMenu::handleDestroy(); 400}