the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "UI.h"
3#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"
4#include "..\..\..\Minecraft.World\net.minecraft.world.entity.animal.h"
5#include "MultiPlayerLocalPlayer.h"
6#include "..\..\Minecraft.h"
7#include "UIScene_HorseInventoryMenu.h"
8
9UIScene_HorseInventoryMenu::UIScene_HorseInventoryMenu(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 HorseScreenInput *initData = (HorseScreenInput *)_initData;
15
16 m_labelHorse.init( initData->container->getName() );
17 m_inventory = initData->inventory;
18 m_horse = initData->horse;
19
20 Minecraft *pMinecraft = Minecraft::GetInstance();
21 if( pMinecraft->localgameModes[iPad] != NULL )
22 {
23 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[iPad];
24 m_previousTutorialState = gameMode->getTutorial()->getCurrentState();
25 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Horse_Menu, this);
26 }
27
28 HorseInventoryMenu *horseMenu = new HorseInventoryMenu(initData->inventory, initData->container, initData->horse);
29
30 int startSlot = EntityHorse::INV_BASE_COUNT;
31 if(m_horse->isChestedHorse())
32 {
33 startSlot += EntityHorse::INV_DONKEY_CHEST_COUNT;
34 }
35 Initialize( iPad, horseMenu, true, startSlot, eSectionHorseUsing, eSectionHorseMax );
36
37 m_slotSaddle.addSlots(EntityHorse::INV_SLOT_SADDLE,1);
38 m_slotArmor.addSlots(EntityHorse::INV_SLOT_ARMOR,1);
39
40 if(m_horse->isChestedHorse())
41 {
42 // also starts at one, because a donkey can't wear armor!
43 m_slotListChest.addSlots(EntityHorse::INV_BASE_COUNT, EntityHorse::INV_DONKEY_CHEST_COUNT);
44 }
45
46 // remove horse inventory
47 if(!m_horse->isChestedHorse())
48 SetHasInventory(false);
49
50 // cannot wear armor? remove armor slot!
51 if(!m_horse->canWearArmor())
52 SetIsDonkey(true);
53
54 if(initData) delete initData;
55
56 setIgnoreInput(false);
57
58 //app.SetRichPresenceContext(iPad, CONTEXT_GAME_STATE_HORSE);
59}
60
61wstring UIScene_HorseInventoryMenu::getMoviePath()
62{
63 if(app.GetLocalPlayerCount() > 1)
64 {
65 return L"HorseInventoryMenuSplit";
66 }
67 else
68 {
69 return L"HorseInventoryMenu";
70 }
71}
72
73void UIScene_HorseInventoryMenu::handleReload()
74{
75 int startSlot = EntityHorse::INV_BASE_COUNT;
76 if(m_horse->isChestedHorse())
77 {
78 startSlot += EntityHorse::INV_DONKEY_CHEST_COUNT;
79 }
80 Initialize( m_iPad, m_menu, true, startSlot, eSectionHorseUsing, eSectionHorseMax );
81
82 m_slotSaddle.addSlots(EntityHorse::INV_SLOT_SADDLE,1);
83 m_slotArmor.addSlots(EntityHorse::INV_SLOT_ARMOR,1);
84
85 if(m_horse->isChestedHorse())
86 {
87 // also starts at one, because a donkey can't wear armor!
88 m_slotListChest.addSlots(EntityHorse::INV_BASE_COUNT, EntityHorse::INV_DONKEY_CHEST_COUNT);
89 }
90
91 // remove horse inventory
92 if(!m_horse->isChestedHorse())
93 SetHasInventory(false);
94
95 // cannot wear armor? remove armor slot!
96 if(!m_horse->canWearArmor())
97 SetIsDonkey(true);
98}
99
100int UIScene_HorseInventoryMenu::getSectionColumns(ESceneSection eSection)
101{
102 int cols = 0;
103 switch( eSection )
104 {
105 case eSectionHorseArmor:
106 cols = 1;
107 break;
108 case eSectionHorseSaddle:
109 cols = 1;
110 break;
111 case eSectionHorseChest:
112 cols = 5;
113 break;
114 case eSectionHorseInventory:
115 cols = 9;
116 break;
117 case eSectionHorseUsing:
118 cols = 9;
119 break;
120 default:
121 assert( false );
122 break;
123 }
124 return cols;
125}
126
127int UIScene_HorseInventoryMenu::getSectionRows(ESceneSection eSection)
128{
129 int rows = 0;
130 switch( eSection )
131 {
132 case eSectionHorseArmor:
133 rows = 1;
134 break;
135 case eSectionHorseSaddle:
136 rows = 1;
137 break;
138 case eSectionHorseChest:
139 rows = 3;
140 break;
141 case eSectionHorseInventory:
142 rows = 3;
143 break;
144 case eSectionHorseUsing:
145 rows = 1;
146 break;
147 default:
148 assert( false );
149 break;
150 }
151 return rows;
152}
153
154void UIScene_HorseInventoryMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition )
155{
156 switch( eSection )
157 {
158 case eSectionHorseArmor:
159 pPosition->x = m_slotArmor.getXPos();
160 pPosition->y = m_slotArmor.getYPos();
161 break;
162 case eSectionHorseSaddle:
163 pPosition->x = m_slotSaddle.getXPos();
164 pPosition->y = m_slotSaddle.getYPos();
165 break;
166 case eSectionHorseChest:
167 pPosition->x = m_slotListChest.getXPos();
168 pPosition->y = m_slotListChest.getYPos();
169 break;
170 case eSectionHorseInventory:
171 pPosition->x = m_slotListInventory.getXPos();
172 pPosition->y = m_slotListInventory.getYPos();
173 break;
174 case eSectionHorseUsing:
175 pPosition->x = m_slotListHotbar.getXPos();
176 pPosition->y = m_slotListHotbar.getYPos();
177 break;
178 default:
179 assert( false );
180 break;
181 }
182}
183
184void UIScene_HorseInventoryMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize )
185{
186 UIVec2D sectionSize;
187
188 switch( eSection )
189 {
190 case eSectionHorseArmor:
191 sectionSize.x = m_slotArmor.getWidth();
192 sectionSize.y = m_slotArmor.getHeight();
193 break;
194 case eSectionHorseSaddle:
195 sectionSize.x = m_slotSaddle.getWidth();
196 sectionSize.y = m_slotSaddle.getHeight();
197 break;
198 case eSectionHorseChest:
199 sectionSize.x = m_slotListChest.getWidth();
200 sectionSize.y = m_slotListChest.getHeight();
201 break;
202 case eSectionHorseInventory:
203 sectionSize.x = m_slotListInventory.getWidth();
204 sectionSize.y = m_slotListInventory.getHeight();
205 break;
206 case eSectionHorseUsing:
207 sectionSize.x = m_slotListHotbar.getWidth();
208 sectionSize.y = m_slotListHotbar.getHeight();
209 break;
210 default:
211 assert( false );
212 break;
213 }
214
215 if(IsSectionSlotList(eSection))
216 {
217 int rows = getSectionRows(eSection);
218 int cols = getSectionColumns(eSection);
219
220 pSize->x = sectionSize.x/cols;
221 pSize->y = sectionSize.y/rows;
222
223 int itemCol = iItemIndex % cols;
224 int itemRow = iItemIndex/cols;
225
226 pPosition->x = itemCol * pSize->x;
227 pPosition->y = itemRow * pSize->y;
228 }
229 else
230 {
231 GetPositionOfSection(eSection, pPosition);
232 pSize->x = sectionSize.x;
233 pSize->y = sectionSize.y;
234 }
235}
236
237void UIScene_HorseInventoryMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y)
238{
239 int cols = getSectionColumns(eSection);
240
241 int index = (y * cols) + x;
242
243 UIControl_SlotList *slotList = NULL;
244 switch( eSection )
245 {
246 case eSectionHorseArmor:
247 slotList = &m_slotArmor;
248 break;
249 case eSectionHorseSaddle:
250 slotList = &m_slotSaddle;
251 break;
252 case eSectionHorseChest:
253 slotList = &m_slotListChest;
254 break;
255 case eSectionHorseInventory:
256 slotList = &m_slotListInventory;
257 break;
258 case eSectionHorseUsing:
259 slotList = &m_slotListHotbar;
260 break;
261 default:
262 assert( false );
263 break;
264 }
265
266 slotList->setHighlightSlot(index);
267}
268
269UIControl *UIScene_HorseInventoryMenu::getSection(ESceneSection eSection)
270{
271 UIControl *control = NULL;
272 switch( eSection )
273 {
274 case eSectionHorseArmor:
275 control = &m_slotArmor;
276 break;
277 case eSectionHorseSaddle:
278 control = &m_slotSaddle;
279 break;
280 case eSectionHorseChest:
281 control = &m_slotListChest;
282 break;
283 case eSectionHorseInventory:
284 control = &m_slotListInventory;
285 break;
286 case eSectionHorseUsing:
287 control = &m_slotListHotbar;
288 break;
289 default:
290 assert( false );
291 break;
292 }
293 return control;
294}
295
296void UIScene_HorseInventoryMenu::customDraw(IggyCustomDrawCallbackRegion *region)
297{
298 Minecraft *pMinecraft = Minecraft::GetInstance();
299 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return;
300
301 if(wcscmp((wchar_t *)region->name,L"horse")==0)
302 {
303 // Setup GDraw, normal game render states and matrices
304 CustomDrawData *customDrawRegion = ui.setupCustomDraw(this,region);
305 delete customDrawRegion;
306
307 m_horsePreview.render(region);
308
309 // Finish GDraw and anything else that needs to be finalised
310 ui.endCustomDraw(region);
311 }
312 else
313 {
314 UIScene_AbstractContainerMenu::customDraw(region);
315 }
316}
317
318void UIScene_HorseInventoryMenu::SetHasInventory(bool bHasInventory)
319{
320 app.DebugPrintf("SetHasInventory to %d\n", bHasInventory);
321
322 IggyDataValue result;
323 IggyDataValue value[1];
324 value[0].type = IGGY_DATATYPE_boolean;
325 value[0].boolval = bHasInventory;
326 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetHasInventory , 1 , value );
327}
328
329void UIScene_HorseInventoryMenu::SetIsDonkey(bool bSetIsDonkey)
330{
331 app.DebugPrintf("SetIsDonkey to %d\n", bSetIsDonkey);
332
333 IggyDataValue result;
334 IggyDataValue value[1];
335 value[0].type = IGGY_DATATYPE_boolean;
336 value[0].boolval = bSetIsDonkey;
337 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetIsDonkey , 1 , value );
338}