the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 519 lines 15 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.entity.h" 4#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h" 5#include "..\..\Minecraft.h" 6#include "UIScene_BeaconMenu.h" 7 8UIScene_BeaconMenu::UIScene_BeaconMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer) 9{ 10 // Setup all the Iggy references we need for this scene 11 initialiseMovie(); 12 13 m_labelPrimary.init(IDS_CONTAINER_BEACON_PRIMARY_POWER); 14 m_labelSecondary.init(IDS_CONTAINER_BEACON_SECONDARY_POWER); 15 16 m_buttonsPowers[eControl_Primary1].setVisible(false); 17 m_buttonsPowers[eControl_Primary2].setVisible(false); 18 m_buttonsPowers[eControl_Primary3].setVisible(false); 19 m_buttonsPowers[eControl_Primary4].setVisible(false); 20 m_buttonsPowers[eControl_Primary5].setVisible(false); 21 m_buttonsPowers[eControl_Secondary1].setVisible(false); 22 m_buttonsPowers[eControl_Secondary2].setVisible(false); 23 24 BeaconScreenInput *initData = (BeaconScreenInput *)_initData; 25 26 Minecraft *pMinecraft = Minecraft::GetInstance(); 27 if( pMinecraft->localgameModes[initData->iPad] != NULL ) 28 { 29 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[initData->iPad]; 30 m_previousTutorialState = gameMode->getTutorial()->getCurrentState(); 31 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Beacon_Menu, this); 32 } 33 34 m_beacon = initData->beacon; 35 36 BeaconMenu *menu = new BeaconMenu(initData->inventory, initData->beacon); 37 38 Initialize( initData->iPad, menu, true, BeaconMenu::INV_SLOT_START, eSectionBeaconUsing, eSectionBeaconMax ); 39 40 m_slotListActivator.addSlots(BeaconMenu::PAYMENT_SLOT, 1); 41 42 m_slotListActivatorIcons.addSlots(m_menu->getSize(),4); 43 44 //app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_BEACON); 45 46 delete initData; 47} 48 49wstring UIScene_BeaconMenu::getMoviePath() 50{ 51 if(app.GetLocalPlayerCount() > 1) 52 { 53 return L"BeaconMenuSplit"; 54 } 55 else 56 { 57 return L"BeaconMenu"; 58 } 59} 60 61void UIScene_BeaconMenu::handleReload() 62{ 63 Initialize( m_iPad, m_menu, true, BeaconMenu::INV_SLOT_START, eSectionBeaconUsing, eSectionBeaconMax ); 64 65 m_slotListActivator.addSlots(BeaconMenu::PAYMENT_SLOT, 1); 66 67 m_slotListActivatorIcons.addSlots(m_menu->getSize(),4); 68} 69 70void UIScene_BeaconMenu::tick() 71{ 72 UIScene_AbstractContainerMenu::tick(); 73 74 handleTick(); 75} 76 77int UIScene_BeaconMenu::getSectionColumns(ESceneSection eSection) 78{ 79 int cols = 0; 80 switch( eSection ) 81 { 82 case eSectionBeaconItem: 83 cols = 1; 84 break; 85 case eSectionBeaconInventory: 86 cols = 9; 87 break; 88 case eSectionBeaconUsing: 89 cols = 9; 90 break; 91 default: 92 assert( false ); 93 break; 94 }; 95 return cols; 96} 97 98int UIScene_BeaconMenu::getSectionRows(ESceneSection eSection) 99{ 100 int rows = 0; 101 switch( eSection ) 102 { 103 case eSectionBeaconItem: 104 rows = 1; 105 break; 106 case eSectionBeaconInventory: 107 rows = 3; 108 break; 109 case eSectionBeaconUsing: 110 rows = 1; 111 break; 112 default: 113 assert( false ); 114 break; 115 }; 116 return rows; 117} 118 119void UIScene_BeaconMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition ) 120{ 121 switch( eSection ) 122 { 123 case eSectionBeaconItem: 124 pPosition->x = m_slotListActivator.getXPos(); 125 pPosition->y = m_slotListActivator.getYPos(); 126 break; 127 case eSectionBeaconInventory: 128 pPosition->x = m_slotListInventory.getXPos(); 129 pPosition->y = m_slotListInventory.getYPos(); 130 break; 131 case eSectionBeaconUsing: 132 pPosition->x = m_slotListHotbar.getXPos(); 133 pPosition->y = m_slotListHotbar.getYPos(); 134 break; 135 136 case eSectionBeaconPrimaryTierOneOne: 137 pPosition->x = m_buttonsPowers[eControl_Primary1].getXPos(); 138 pPosition->y = m_buttonsPowers[eControl_Primary1].getYPos(); 139 break; 140 case eSectionBeaconPrimaryTierOneTwo: 141 pPosition->x = m_buttonsPowers[eControl_Primary2].getXPos(); 142 pPosition->y = m_buttonsPowers[eControl_Primary2].getYPos(); 143 break; 144 case eSectionBeaconPrimaryTierTwoOne: 145 pPosition->x = m_buttonsPowers[eControl_Primary3].getXPos(); 146 pPosition->y = m_buttonsPowers[eControl_Primary3].getYPos(); 147 break; 148 case eSectionBeaconPrimaryTierTwoTwo: 149 pPosition->x = m_buttonsPowers[eControl_Primary4].getXPos(); 150 pPosition->y = m_buttonsPowers[eControl_Primary4].getYPos(); 151 break; 152 case eSectionBeaconPrimaryTierThree: 153 pPosition->x = m_buttonsPowers[eControl_Primary5].getXPos(); 154 pPosition->y = m_buttonsPowers[eControl_Primary5].getYPos(); 155 break; 156 case eSectionBeaconSecondaryOne: 157 pPosition->x = m_buttonsPowers[eControl_Secondary1].getXPos(); 158 pPosition->y = m_buttonsPowers[eControl_Secondary1].getYPos(); 159 break; 160 case eSectionBeaconSecondaryTwo: 161 pPosition->x = m_buttonsPowers[eControl_Secondary2].getXPos(); 162 pPosition->y = m_buttonsPowers[eControl_Secondary2].getYPos(); 163 break; 164 case eSectionBeaconConfirm: 165 pPosition->x = m_buttonConfirm.getXPos(); 166 pPosition->y = m_buttonConfirm.getYPos(); 167 break; 168 default: 169 assert( false ); 170 break; 171 }; 172} 173 174void UIScene_BeaconMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize ) 175{ 176 UIVec2D sectionSize; 177 switch( eSection ) 178 { 179 case eSectionBeaconItem: 180 sectionSize.x = m_slotListActivator.getWidth(); 181 sectionSize.y = m_slotListActivator.getHeight(); 182 break; 183 case eSectionBeaconInventory: 184 sectionSize.x = m_slotListInventory.getWidth(); 185 sectionSize.y = m_slotListInventory.getHeight(); 186 break; 187 case eSectionBeaconUsing: 188 sectionSize.x = m_slotListHotbar.getWidth(); 189 sectionSize.y = m_slotListHotbar.getHeight(); 190 break; 191 192 case eSectionBeaconPrimaryTierOneOne: 193 sectionSize.x = m_buttonsPowers[eControl_Primary1].getWidth(); 194 sectionSize.y = m_buttonsPowers[eControl_Primary1].getHeight(); 195 break; 196 case eSectionBeaconPrimaryTierOneTwo: 197 sectionSize.x = m_buttonsPowers[eControl_Primary2].getWidth(); 198 sectionSize.y = m_buttonsPowers[eControl_Primary2].getHeight(); 199 break; 200 case eSectionBeaconPrimaryTierTwoOne: 201 sectionSize.x = m_buttonsPowers[eControl_Primary3].getWidth(); 202 sectionSize.y = m_buttonsPowers[eControl_Primary3].getHeight(); 203 break; 204 case eSectionBeaconPrimaryTierTwoTwo: 205 sectionSize.x = m_buttonsPowers[eControl_Primary4].getWidth(); 206 sectionSize.y = m_buttonsPowers[eControl_Primary4].getHeight(); 207 break; 208 case eSectionBeaconPrimaryTierThree: 209 sectionSize.x = m_buttonsPowers[eControl_Primary5].getWidth(); 210 sectionSize.y = m_buttonsPowers[eControl_Primary5].getHeight(); 211 break; 212 case eSectionBeaconSecondaryOne: 213 sectionSize.x = m_buttonsPowers[eControl_Secondary1].getWidth(); 214 sectionSize.y = m_buttonsPowers[eControl_Secondary1].getHeight(); 215 break; 216 case eSectionBeaconSecondaryTwo: 217 sectionSize.x = m_buttonsPowers[eControl_Secondary2].getWidth(); 218 sectionSize.y = m_buttonsPowers[eControl_Secondary2].getHeight(); 219 break; 220 case eSectionBeaconConfirm: 221 sectionSize.x = m_buttonConfirm.getWidth(); 222 sectionSize.y = m_buttonConfirm.getHeight(); 223 break; 224 default: 225 assert( false ); 226 break; 227 }; 228 229 if(IsSectionSlotList(eSection)) 230 { 231 int rows = getSectionRows(eSection); 232 int cols = getSectionColumns(eSection); 233 234 pSize->x = sectionSize.x/cols; 235 pSize->y = sectionSize.y/rows; 236 237 int itemCol = iItemIndex % cols; 238 int itemRow = iItemIndex/cols; 239 240 pPosition->x = itemCol * pSize->x; 241 pPosition->y = itemRow * pSize->y; 242 } 243 else 244 { 245 GetPositionOfSection(eSection, pPosition); 246 pSize->x = sectionSize.x; 247 pSize->y = sectionSize.y; 248 } 249} 250 251void UIScene_BeaconMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y) 252{ 253 int cols = getSectionColumns(eSection); 254 255 int index = (y * cols) + x; 256 257 UIControl_SlotList *slotList = NULL; 258 switch( eSection ) 259 { 260 case eSectionBeaconItem: 261 slotList = &m_slotListActivator; 262 break; 263 case eSectionBeaconInventory: 264 slotList = &m_slotListInventory; 265 break; 266 case eSectionBeaconUsing: 267 slotList = &m_slotListHotbar; 268 break; 269 default: 270 assert( false ); 271 break; 272 }; 273 274 slotList->setHighlightSlot(index); 275} 276 277UIControl *UIScene_BeaconMenu::getSection(ESceneSection eSection) 278{ 279 UIControl *control = NULL; 280 switch( eSection ) 281 { 282 case eSectionBeaconItem: 283 control = &m_slotListActivator; 284 break; 285 case eSectionBeaconInventory: 286 control = &m_slotListInventory; 287 break; 288 case eSectionBeaconUsing: 289 control = &m_slotListHotbar; 290 break; 291 292 case eSectionBeaconPrimaryTierOneOne: 293 control = &m_buttonsPowers[eControl_Primary1]; 294 break; 295 case eSectionBeaconPrimaryTierOneTwo: 296 control = &m_buttonsPowers[eControl_Primary2]; 297 break; 298 case eSectionBeaconPrimaryTierTwoOne: 299 control = &m_buttonsPowers[eControl_Primary3]; 300 break; 301 case eSectionBeaconPrimaryTierTwoTwo: 302 control = &m_buttonsPowers[eControl_Primary4]; 303 break; 304 case eSectionBeaconPrimaryTierThree: 305 control = &m_buttonsPowers[eControl_Primary5]; 306 break; 307 case eSectionBeaconSecondaryOne: 308 control = &m_buttonsPowers[eControl_Secondary1]; 309 break; 310 case eSectionBeaconSecondaryTwo: 311 control = &m_buttonsPowers[eControl_Secondary2]; 312 break; 313 case eSectionBeaconConfirm: 314 control = &m_buttonConfirm; 315 break; 316 317 default: 318 assert( false ); 319 break; 320 }; 321 return control; 322} 323 324void UIScene_BeaconMenu::customDraw(IggyCustomDrawCallbackRegion *region) 325{ 326 Minecraft *pMinecraft = Minecraft::GetInstance(); 327 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return; 328 329 shared_ptr<ItemInstance> item = nullptr; 330 int slotId = -1; 331 swscanf((wchar_t*)region->name,L"slot_%d",&slotId); 332 333 if(slotId >= 0 && slotId >= m_menu->getSize() ) 334 { 335 int icon = slotId - m_menu->getSize(); 336 switch(icon) 337 { 338 case 0: 339 item = shared_ptr<ItemInstance>(new ItemInstance(Item::emerald) ); 340 break; 341 case 1: 342 item = shared_ptr<ItemInstance>(new ItemInstance(Item::diamond) ); 343 break; 344 case 2: 345 item = shared_ptr<ItemInstance>(new ItemInstance(Item::goldIngot) ); 346 break; 347 case 3: 348 item = shared_ptr<ItemInstance>(new ItemInstance(Item::ironIngot) ); 349 break; 350 default: 351 assert(false); 352 break; 353 }; 354 if(item != NULL) customDrawSlotControl(region,m_iPad,item,1.0f,item->isFoil(),true); 355 } 356 else 357 { 358 UIScene_AbstractContainerMenu::customDraw(region); 359 } 360} 361 362void UIScene_BeaconMenu::SetConfirmButtonEnabled(bool enabled) 363{ 364 m_buttonConfirm.SetButtonActive(enabled); 365} 366 367void UIScene_BeaconMenu::AddPowerButton(int id, int icon, int tier, int count, bool active, bool selected) 368{ 369 switch(tier) 370 { 371 case 0: 372 if(count == 0) 373 { 374 m_buttonsPowers[eControl_Primary1].SetData(id, icon,active,selected); 375 m_buttonsPowers[eControl_Primary1].setVisible(true); 376 } 377 else 378 { 379 m_buttonsPowers[eControl_Primary2].SetData(id, icon,active,selected); 380 m_buttonsPowers[eControl_Primary2].setVisible(true); 381 } 382 break; 383 case 1: 384 if(count == 0) 385 { 386 m_buttonsPowers[eControl_Primary3].SetData(id, icon,active,selected); 387 m_buttonsPowers[eControl_Primary3].setVisible(true); 388 } 389 else 390 { 391 m_buttonsPowers[eControl_Primary4].SetData(id, icon,active,selected); 392 m_buttonsPowers[eControl_Primary4].setVisible(true); 393 } 394 break; 395 case 2: 396 m_buttonsPowers[eControl_Primary5].SetData(id, icon,active,selected); 397 m_buttonsPowers[eControl_Primary5].setVisible(true); 398 break; 399 case 3: 400 if(count == 0) 401 { 402 m_buttonsPowers[eControl_Secondary1].SetData(id, icon,active,selected); 403 m_buttonsPowers[eControl_Secondary1].setVisible(true); 404 } 405 else 406 { 407 m_buttonsPowers[eControl_Secondary2].SetData(id, icon,active,selected); 408 m_buttonsPowers[eControl_Secondary2].setVisible(true); 409 } 410 break; 411 }; 412} 413 414int UIScene_BeaconMenu::GetPowerButtonId(ESceneSection eSection) 415{ 416 switch(eSection) 417 { 418 case eSectionBeaconPrimaryTierOneOne: 419 return m_buttonsPowers[eControl_Primary1].GetData(); 420 break; 421 case eSectionBeaconPrimaryTierOneTwo: 422 return m_buttonsPowers[eControl_Primary2].GetData(); 423 break; 424 case eSectionBeaconPrimaryTierTwoOne: 425 return m_buttonsPowers[eControl_Primary3].GetData(); 426 break; 427 case eSectionBeaconPrimaryTierTwoTwo: 428 return m_buttonsPowers[eControl_Primary4].GetData(); 429 break; 430 case eSectionBeaconPrimaryTierThree: 431 return m_buttonsPowers[eControl_Primary5].GetData(); 432 break; 433 case eSectionBeaconSecondaryOne: 434 return m_buttonsPowers[eControl_Secondary1].GetData(); 435 break; 436 case eSectionBeaconSecondaryTwo: 437 return m_buttonsPowers[eControl_Secondary2].GetData(); 438 break; 439 }; 440 return 0; 441} 442 443bool UIScene_BeaconMenu::IsPowerButtonSelected(ESceneSection eSection) 444{ 445 switch(eSection) 446 { 447 case eSectionBeaconPrimaryTierOneOne: 448 return m_buttonsPowers[eControl_Primary1].IsButtonSelected(); 449 break; 450 case eSectionBeaconPrimaryTierOneTwo: 451 return m_buttonsPowers[eControl_Primary2].IsButtonSelected(); 452 break; 453 case eSectionBeaconPrimaryTierTwoOne: 454 return m_buttonsPowers[eControl_Primary3].IsButtonSelected(); 455 break; 456 case eSectionBeaconPrimaryTierTwoTwo: 457 return m_buttonsPowers[eControl_Primary4].IsButtonSelected(); 458 break; 459 case eSectionBeaconPrimaryTierThree: 460 return m_buttonsPowers[eControl_Primary5].IsButtonSelected(); 461 break; 462 case eSectionBeaconSecondaryOne: 463 return m_buttonsPowers[eControl_Secondary1].IsButtonSelected(); 464 break; 465 case eSectionBeaconSecondaryTwo: 466 return m_buttonsPowers[eControl_Secondary2].IsButtonSelected(); 467 break; 468 }; 469 return false; 470} 471 472void UIScene_BeaconMenu::SetPowerButtonSelected(ESceneSection eSection) 473{ 474 switch(eSection) 475 { 476 case eSectionBeaconPrimaryTierOneOne: 477 case eSectionBeaconPrimaryTierOneTwo: 478 case eSectionBeaconPrimaryTierTwoOne: 479 case eSectionBeaconPrimaryTierTwoTwo: 480 case eSectionBeaconPrimaryTierThree: 481 m_buttonsPowers[eControl_Primary1].SetButtonSelected(false); 482 m_buttonsPowers[eControl_Primary2].SetButtonSelected(false); 483 m_buttonsPowers[eControl_Primary3].SetButtonSelected(false); 484 m_buttonsPowers[eControl_Primary4].SetButtonSelected(false); 485 m_buttonsPowers[eControl_Primary5].SetButtonSelected(false); 486 break; 487 case eSectionBeaconSecondaryOne: 488 case eSectionBeaconSecondaryTwo: 489 m_buttonsPowers[eControl_Secondary1].SetButtonSelected(false); 490 m_buttonsPowers[eControl_Secondary2].SetButtonSelected(false); 491 break; 492 }; 493 494 495 switch(eSection) 496 { 497 case eSectionBeaconPrimaryTierOneOne: 498 return m_buttonsPowers[eControl_Primary1].SetButtonSelected(true); 499 break; 500 case eSectionBeaconPrimaryTierOneTwo: 501 return m_buttonsPowers[eControl_Primary2].SetButtonSelected(true); 502 break; 503 case eSectionBeaconPrimaryTierTwoOne: 504 return m_buttonsPowers[eControl_Primary3].SetButtonSelected(true); 505 break; 506 case eSectionBeaconPrimaryTierTwoTwo: 507 return m_buttonsPowers[eControl_Primary4].SetButtonSelected(true); 508 break; 509 case eSectionBeaconPrimaryTierThree: 510 return m_buttonsPowers[eControl_Primary5].SetButtonSelected(true); 511 break; 512 case eSectionBeaconSecondaryOne: 513 return m_buttonsPowers[eControl_Secondary1].SetButtonSelected(true); 514 break; 515 case eSectionBeaconSecondaryTwo: 516 return m_buttonsPowers[eControl_Secondary2].SetButtonSelected(true); 517 break; 518 }; 519}