the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 284 lines 7.2 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_EnchantingMenu.h" 7 8UIScene_EnchantingMenu::UIScene_EnchantingMenu(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_enchantButton[0].init(0); 14 m_enchantButton[1].init(1); 15 m_enchantButton[2].init(2); 16 17 EnchantingScreenInput *initData = (EnchantingScreenInput *)_initData; 18 19 m_labelEnchant.init( initData->name.empty() ? app.GetString(IDS_ENCHANT) : initData->name ); 20 21 Minecraft *pMinecraft = Minecraft::GetInstance(); 22 if( pMinecraft->localgameModes[initData->iPad] != NULL ) 23 { 24 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[initData->iPad]; 25 m_previousTutorialState = gameMode->getTutorial()->getCurrentState(); 26 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Enchanting_Menu, this); 27 } 28 29 EnchantmentMenu *menu = new EnchantmentMenu(initData->inventory, initData->level, initData->x, initData->y, initData->z); 30 31 Initialize( initData->iPad, menu, true, EnchantmentMenu::INV_SLOT_START, eSectionEnchantUsing, eSectionEnchantMax ); 32 33 m_slotListIngredient.addSlots(EnchantmentMenu::INGREDIENT_SLOT, 1); 34 35 app.SetRichPresenceContext(m_iPad,CONTEXT_GAME_STATE_ENCHANTING); 36 37 delete initData; 38} 39 40wstring UIScene_EnchantingMenu::getMoviePath() 41{ 42 if(app.GetLocalPlayerCount() > 1) 43 { 44 return L"EnchantingMenuSplit"; 45 } 46 else 47 { 48 return L"EnchantingMenu"; 49 } 50} 51 52void UIScene_EnchantingMenu::handleReload() 53{ 54 Initialize( m_iPad, m_menu, true, EnchantmentMenu::INV_SLOT_START, eSectionEnchantUsing, eSectionEnchantMax ); 55 56 m_slotListIngredient.addSlots(EnchantmentMenu::INGREDIENT_SLOT, 1); 57} 58 59int UIScene_EnchantingMenu::getSectionColumns(ESceneSection eSection) 60{ 61 int cols = 0; 62 switch( eSection ) 63 { 64 case eSectionEnchantSlot: 65 cols = 1; 66 break; 67 case eSectionEnchantInventory: 68 cols = 9; 69 break; 70 case eSectionEnchantUsing: 71 cols = 9; 72 break; 73 default: 74 assert( false ); 75 break; 76 }; 77 return cols; 78} 79 80int UIScene_EnchantingMenu::getSectionRows(ESceneSection eSection) 81{ 82 int rows = 0; 83 switch( eSection ) 84 { 85 case eSectionEnchantSlot: 86 rows = 1; 87 break; 88 case eSectionEnchantInventory: 89 rows = 3; 90 break; 91 case eSectionEnchantUsing: 92 rows = 1; 93 break; 94 default: 95 assert( false ); 96 break; 97 }; 98 return rows; 99} 100 101void UIScene_EnchantingMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition ) 102{ 103 switch( eSection ) 104 { 105 case eSectionEnchantSlot: 106 pPosition->x = m_slotListIngredient.getXPos(); 107 pPosition->y = m_slotListIngredient.getYPos(); 108 break; 109 case eSectionEnchantInventory: 110 pPosition->x = m_slotListInventory.getXPos(); 111 pPosition->y = m_slotListInventory.getYPos(); 112 break; 113 case eSectionEnchantUsing: 114 pPosition->x = m_slotListHotbar.getXPos(); 115 pPosition->y = m_slotListHotbar.getYPos(); 116 break; 117 case eSectionEnchantButton1: 118 pPosition->x = m_enchantButton[0].getXPos(); 119 pPosition->y = m_enchantButton[0].getYPos(); 120 break; 121 case eSectionEnchantButton2: 122 pPosition->x = m_enchantButton[1].getXPos(); 123 pPosition->y = m_enchantButton[1].getYPos(); 124 break; 125 case eSectionEnchantButton3: 126 pPosition->x = m_enchantButton[2].getXPos(); 127 pPosition->y = m_enchantButton[2].getYPos(); 128 break; 129 default: 130 assert( false ); 131 break; 132 }; 133} 134 135void UIScene_EnchantingMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize ) 136{ 137 UIVec2D sectionSize; 138 switch( eSection ) 139 { 140 case eSectionEnchantSlot: 141 sectionSize.x = m_slotListIngredient.getWidth(); 142 sectionSize.y = m_slotListIngredient.getHeight(); 143 break; 144 case eSectionEnchantInventory: 145 sectionSize.x = m_slotListInventory.getWidth(); 146 sectionSize.y = m_slotListInventory.getHeight(); 147 break; 148 case eSectionEnchantUsing: 149 sectionSize.x = m_slotListHotbar.getWidth(); 150 sectionSize.y = m_slotListHotbar.getHeight(); 151 break; 152 case eSectionEnchantButton1: 153 sectionSize.x = m_enchantButton[0].getWidth(); 154 sectionSize.y = m_enchantButton[0].getHeight(); 155 break; 156 case eSectionEnchantButton2: 157 sectionSize.x = m_enchantButton[1].getWidth(); 158 sectionSize.y = m_enchantButton[1].getHeight(); 159 break; 160 case eSectionEnchantButton3: 161 sectionSize.x = m_enchantButton[2].getWidth(); 162 sectionSize.y = m_enchantButton[2].getHeight(); 163 break; 164 default: 165 assert( false ); 166 break; 167 }; 168 169 if(IsSectionSlotList(eSection)) 170 { 171 int rows = getSectionRows(eSection); 172 int cols = getSectionColumns(eSection); 173 174 pSize->x = sectionSize.x/cols; 175 pSize->y = sectionSize.y/rows; 176 177 int itemCol = iItemIndex % cols; 178 int itemRow = iItemIndex/cols; 179 180 pPosition->x = itemCol * pSize->x; 181 pPosition->y = itemRow * pSize->y; 182 } 183 else 184 { 185 GetPositionOfSection(eSection, pPosition); 186 pSize->x = sectionSize.x; 187 pSize->y = sectionSize.y; 188 } 189} 190 191void UIScene_EnchantingMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y) 192{ 193 int cols = getSectionColumns(eSection); 194 195 int index = (y * cols) + x; 196 197 UIControl_SlotList *slotList = NULL; 198 switch( eSection ) 199 { 200 case eSectionEnchantSlot: 201 slotList = &m_slotListIngredient; 202 break; 203 case eSectionEnchantInventory: 204 slotList = &m_slotListInventory; 205 break; 206 case eSectionEnchantUsing: 207 slotList = &m_slotListHotbar; 208 break; 209 default: 210 assert( false ); 211 break; 212 }; 213 214 slotList->setHighlightSlot(index); 215} 216 217UIControl *UIScene_EnchantingMenu::getSection(ESceneSection eSection) 218{ 219 UIControl *control = NULL; 220 switch( eSection ) 221 { 222 case eSectionEnchantSlot: 223 control = &m_slotListIngredient; 224 break; 225 case eSectionEnchantInventory: 226 control = &m_slotListInventory; 227 break; 228 case eSectionEnchantUsing: 229 control = &m_slotListHotbar; 230 break; 231 case eSectionEnchantButton1: 232 control = &m_enchantButton[0]; 233 break; 234 case eSectionEnchantButton2: 235 control = &m_enchantButton[1]; 236 break; 237 case eSectionEnchantButton3: 238 control = &m_enchantButton[2]; 239 break; 240 default: 241 assert( false ); 242 break; 243 }; 244 return control; 245} 246 247void UIScene_EnchantingMenu::customDraw(IggyCustomDrawCallbackRegion *region) 248{ 249 Minecraft *pMinecraft = Minecraft::GetInstance(); 250 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return; 251 252 253 if(wcscmp((wchar_t *)region->name,L"EnchantmentBook")==0) 254 { 255 // Setup GDraw, normal game render states and matrices 256 CustomDrawData *customDrawRegion = ui.setupCustomDraw(this,region); 257 delete customDrawRegion; 258 259 m_enchantBook.render(region); 260 261 // Finish GDraw and anything else that needs to be finalised 262 ui.endCustomDraw(region); 263 } 264 else 265 { 266 int slotId = -1; 267 swscanf((wchar_t*)region->name,L"slot_Button%d",&slotId); 268 if(slotId >= 0) 269 { 270 // Setup GDraw, normal game render states and matrices 271 CustomDrawData *customDrawRegion = ui.setupCustomDraw(this,region); 272 delete customDrawRegion; 273 274 m_enchantButton[slotId-1].render(region); 275 276 // Finish GDraw and anything else that needs to be finalised 277 ui.endCustomDraw(region); 278 } 279 else 280 { 281 UIScene_AbstractContainerMenu::customDraw(region); 282 } 283 } 284}