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 "UIScene_ContainerMenu.h"
4
5#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"
6#include "..\..\..\Minecraft.World\net.minecraft.world.item.h"
7#include "..\..\..\Minecraft.World\net.minecraft.stats.h"
8#include "..\..\LocalPlayer.h"
9#include "..\..\Minecraft.h"
10#include "..\Tutorial\Tutorial.h"
11#include "..\Tutorial\TutorialMode.h"
12#include "..\Tutorial\TutorialEnum.h"
13
14UIScene_ContainerMenu::UIScene_ContainerMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer)
15{
16 ContainerScreenInput *initData = (ContainerScreenInput *)_initData;
17 m_bLargeChest = (initData->container->getContainerSize() > 3*9)?true:false;
18
19 // Setup all the Iggy references we need for this scene
20 initialiseMovie();
21
22 m_labelChest.init(initData->container->getName());
23
24 ContainerMenu* menu = new ContainerMenu( initData->inventory, initData->container );
25
26 Minecraft *pMinecraft = Minecraft::GetInstance();
27 if( pMinecraft->localgameModes[iPad] != NULL )
28 {
29 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[initData->iPad];
30 m_previousTutorialState = gameMode->getTutorial()->getCurrentState();
31 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Container_Menu, this);
32 }
33
34 int containerSize = menu->getSize() - (27 + 9);
35
36 Initialize( initData->iPad, menu, true, containerSize, eSectionContainerUsing, eSectionContainerMax);
37
38 m_slotListContainer.addSlots(0, containerSize);
39
40 if(initData) delete initData;
41}
42
43wstring UIScene_ContainerMenu::getMoviePath()
44{
45 if(m_bLargeChest)
46 {
47 if(app.GetLocalPlayerCount() > 1)
48 {
49 return L"ChestLargeMenuSplit";
50 }
51 else
52 {
53 return L"ChestLargeMenu";
54 }
55 }
56 else
57 {
58 if(app.GetLocalPlayerCount() > 1)
59 {
60 return L"ChestMenuSplit";
61 }
62 else
63 {
64 return L"ChestMenu";
65 }
66 }
67}
68
69void UIScene_ContainerMenu::handleReload()
70{
71 int containerSize = m_menu->getSize() - (27 + 9);
72
73 Initialize( m_iPad, m_menu, true, containerSize, eSectionContainerUsing, eSectionContainerMax );
74
75 m_slotListContainer.addSlots(0, containerSize);
76}
77
78int UIScene_ContainerMenu::getSectionColumns(ESceneSection eSection)
79{
80 int cols = 0;
81 switch( eSection )
82 {
83 case eSectionContainerChest:
84 cols = 9;
85 break;
86 case eSectionContainerInventory:
87 cols = 9;
88 break;
89 case eSectionContainerUsing:
90 cols = 9;
91 break;
92 default:
93 assert( false );
94 break;
95 }
96 return cols;
97}
98
99int UIScene_ContainerMenu::getSectionRows(ESceneSection eSection)
100{
101 int rows = 0;
102 switch( eSection )
103 {
104 case eSectionContainerChest:
105 rows = (m_menu->getSize() - (27 + 9)) / 9;
106 break;
107 case eSectionContainerInventory:
108 rows = 3;
109 break;
110 case eSectionContainerUsing:
111 rows = 1;
112 break;
113 default:
114 assert( false );
115 break;
116 }
117 return rows;
118}
119
120void UIScene_ContainerMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition )
121{
122 switch( eSection )
123 {
124 case eSectionContainerChest:
125 pPosition->x = m_slotListContainer.getXPos();
126 pPosition->y = m_slotListContainer.getYPos();
127 break;
128 case eSectionContainerInventory:
129 pPosition->x = m_slotListInventory.getXPos();
130 pPosition->y = m_slotListInventory.getYPos();
131 break;
132 case eSectionContainerUsing:
133 pPosition->x = m_slotListHotbar.getXPos();
134 pPosition->y = m_slotListHotbar.getYPos();
135 break;
136 default:
137 assert( false );
138 break;
139 }
140}
141
142void UIScene_ContainerMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize )
143{
144 UIVec2D sectionSize;
145
146 switch( eSection )
147 {
148 case eSectionContainerChest:
149 sectionSize.x = m_slotListContainer.getWidth();
150 sectionSize.y = m_slotListContainer.getHeight();
151 break;
152 case eSectionContainerInventory:
153 sectionSize.x = m_slotListInventory.getWidth();
154 sectionSize.y = m_slotListInventory.getHeight();
155 break;
156 case eSectionContainerUsing:
157 sectionSize.x = m_slotListHotbar.getWidth();
158 sectionSize.y = m_slotListHotbar.getHeight();
159 break;
160 default:
161 assert( false );
162 break;
163 }
164
165 int rows = getSectionRows(eSection);
166 int cols = getSectionColumns(eSection);
167
168 pSize->x = sectionSize.x/cols;
169 pSize->y = sectionSize.y/rows;
170
171 int itemCol = iItemIndex % cols;
172 int itemRow = iItemIndex/cols;
173
174 pPosition->x = itemCol * pSize->x;
175 pPosition->y = itemRow * pSize->y;
176}
177
178void UIScene_ContainerMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y)
179{
180 int cols = getSectionColumns(eSection);
181
182 int index = (y * cols) + x;
183
184 UIControl_SlotList *slotList = NULL;
185 switch( eSection )
186 {
187 case eSectionContainerChest:
188 slotList = &m_slotListContainer;
189 break;
190 case eSectionContainerInventory:
191 slotList = &m_slotListInventory;
192 break;
193 case eSectionContainerUsing:
194 slotList = &m_slotListHotbar;
195 break;
196 default:
197 assert( false );
198 break;
199 }
200
201 slotList->setHighlightSlot(index);
202}
203
204UIControl *UIScene_ContainerMenu::getSection(ESceneSection eSection)
205{
206 UIControl *control = NULL;
207 switch( eSection )
208 {
209 case eSectionContainerChest:
210 control = &m_slotListContainer;
211 break;
212 case eSectionContainerInventory:
213 control = &m_slotListInventory;
214 break;
215 case eSectionContainerUsing:
216 control = &m_slotListHotbar;
217 break;
218 default:
219 assert( false );
220 break;
221 }
222 return control;
223}