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_InventoryMenu.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 "..\..\..\Minecraft.World\net.minecraft.world.effect.h"
9#include "..\..\MultiplayerLocalPlayer.h"
10#include "..\..\Minecraft.h"
11#include "..\..\Options.h"
12#include "..\..\EntityRenderDispatcher.h"
13#include "..\..\Lighting.h"
14#include "..\Tutorial\Tutorial.h"
15#include "..\Tutorial\TutorialMode.h"
16#include "..\Tutorial\TutorialEnum.h"
17
18#define INVENTORY_UPDATE_EFFECTS_TIMER_ID (10)
19#define INVENTORY_UPDATE_EFFECTS_TIMER_TIME (1000) // 1 second
20
21UIScene_InventoryMenu::UIScene_InventoryMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer)
22{
23 // Setup all the Iggy references we need for this scene
24 initialiseMovie();
25
26 InventoryScreenInput *initData = (InventoryScreenInput *)_initData;
27
28 Minecraft *pMinecraft = Minecraft::GetInstance();
29 if( pMinecraft->localgameModes[initData->iPad] != NULL )
30 {
31 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[initData->iPad];
32 m_previousTutorialState = gameMode->getTutorial()->getCurrentState();
33 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Inventory_Menu, this);
34 }
35
36 InventoryMenu *menu = (InventoryMenu *)initData->player->inventoryMenu;
37
38 initData->player->awardStat(GenericStats::openInventory(),GenericStats::param_openInventory());
39
40 Initialize( initData->iPad, menu, false, InventoryMenu::INV_SLOT_START, eSectionInventoryUsing, eSectionInventoryMax, initData->bNavigateBack );
41
42 m_slotListArmor.addSlots(InventoryMenu::ARMOR_SLOT_START, InventoryMenu::ARMOR_SLOT_END - InventoryMenu::ARMOR_SLOT_START);
43
44 if(initData) delete initData;
45
46 for(unsigned int i = 0; i < MobEffect::NUM_EFFECTS; ++i)
47 {
48 m_bEffectTime[i] = 0;
49 }
50
51 updateEffectsDisplay();
52 addTimer(INVENTORY_UPDATE_EFFECTS_TIMER_ID,INVENTORY_UPDATE_EFFECTS_TIMER_TIME);
53}
54
55wstring UIScene_InventoryMenu::getMoviePath()
56{
57 if(app.GetLocalPlayerCount() > 1)
58 {
59 return L"InventoryMenuSplit";
60 }
61 else
62 {
63 return L"InventoryMenu";
64 }
65}
66
67void UIScene_InventoryMenu::handleReload()
68{
69 Initialize( m_iPad, m_menu, false, InventoryMenu::INV_SLOT_START, eSectionInventoryUsing, eSectionInventoryMax, m_bNavigateBack );
70
71 m_slotListArmor.addSlots(InventoryMenu::ARMOR_SLOT_START, InventoryMenu::ARMOR_SLOT_END - InventoryMenu::ARMOR_SLOT_START);
72
73 for(unsigned int i = 0; i < MobEffect::NUM_EFFECTS; ++i)
74 {
75 m_bEffectTime[i] = 0;
76 }
77}
78
79int UIScene_InventoryMenu::getSectionColumns(ESceneSection eSection)
80{
81 int cols = 0;
82 switch( eSection )
83 {
84 case eSectionInventoryArmor:
85 cols = 1;
86 break;
87 case eSectionInventoryInventory:
88 cols = 9;
89 break;
90 case eSectionInventoryUsing:
91 cols = 9;
92 break;
93 default:
94 assert( false );
95 break;
96 }
97 return cols;
98}
99
100int UIScene_InventoryMenu::getSectionRows(ESceneSection eSection)
101{
102 int rows = 0;
103 switch( eSection )
104 {
105 case eSectionInventoryArmor:
106 rows = 4;
107 break;
108 case eSectionInventoryInventory:
109 rows = 3;
110 break;
111 case eSectionInventoryUsing:
112 rows = 1;
113 break;
114 default:
115 assert( false );
116 break;
117 }
118 return rows;
119}
120
121void UIScene_InventoryMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition )
122{
123 switch( eSection )
124 {
125 case eSectionInventoryArmor:
126 pPosition->x = m_slotListArmor.getXPos();
127 pPosition->y = m_slotListArmor.getYPos();
128 break;
129 case eSectionInventoryInventory:
130 pPosition->x = m_slotListInventory.getXPos();
131 pPosition->y = m_slotListInventory.getYPos();
132 break;
133 case eSectionInventoryUsing:
134 pPosition->x = m_slotListHotbar.getXPos();
135 pPosition->y = m_slotListHotbar.getYPos();
136 break;
137 default:
138 assert( false );
139 break;
140 }
141}
142
143void UIScene_InventoryMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize )
144{
145 UIVec2D sectionSize;
146
147 switch( eSection )
148 {
149 case eSectionInventoryArmor:
150 sectionSize.x = m_slotListArmor.getWidth();
151 sectionSize.y = m_slotListArmor.getHeight();
152 break;
153 case eSectionInventoryInventory:
154 sectionSize.x = m_slotListInventory.getWidth();
155 sectionSize.y = m_slotListInventory.getHeight();
156 break;
157 case eSectionInventoryUsing:
158 sectionSize.x = m_slotListHotbar.getWidth();
159 sectionSize.y = m_slotListHotbar.getHeight();
160 break;
161 default:
162 assert( false );
163 break;
164 }
165
166 int rows = getSectionRows(eSection);
167 int cols = getSectionColumns(eSection);
168
169 pSize->x = sectionSize.x/cols;
170 pSize->y = sectionSize.y/rows;
171
172 int itemCol = iItemIndex % cols;
173 int itemRow = iItemIndex/cols;
174
175 pPosition->x = itemCol * pSize->x;
176 pPosition->y = itemRow * pSize->y;
177}
178
179void UIScene_InventoryMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y)
180{
181 int cols = getSectionColumns(eSection);
182
183 int index = (y * cols) + x;
184
185 UIControl_SlotList *slotList = NULL;
186 switch( eSection )
187 {
188 case eSectionInventoryArmor:
189 slotList = &m_slotListArmor;
190 break;
191 case eSectionInventoryInventory:
192 slotList = &m_slotListInventory;
193 break;
194 case eSectionInventoryUsing:
195 slotList = &m_slotListHotbar;
196 break;
197 }
198
199 slotList->setHighlightSlot(index);
200}
201
202UIControl *UIScene_InventoryMenu::getSection(ESceneSection eSection)
203{
204 UIControl *control = NULL;
205 switch( eSection )
206 {
207 case eSectionInventoryArmor:
208 control = &m_slotListArmor;
209 break;
210 case eSectionInventoryInventory:
211 control = &m_slotListInventory;
212 break;
213 case eSectionInventoryUsing:
214 control = &m_slotListHotbar;
215 break;
216 }
217 return control;
218}
219
220void UIScene_InventoryMenu::customDraw(IggyCustomDrawCallbackRegion *region)
221{
222 Minecraft *pMinecraft = Minecraft::GetInstance();
223 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return;
224
225 if(wcscmp((wchar_t *)region->name,L"player")==0)
226 {
227 // Setup GDraw, normal game render states and matrices
228 CustomDrawData *customDrawRegion = ui.setupCustomDraw(this,region);
229 delete customDrawRegion;
230
231 m_playerPreview.render(region);
232
233 // Finish GDraw and anything else that needs to be finalised
234 ui.endCustomDraw(region);
235 }
236 else
237 {
238 UIScene_AbstractContainerMenu::customDraw(region);
239 }
240}
241
242void UIScene_InventoryMenu::handleTimerComplete(int id)
243{
244 if(id == INVENTORY_UPDATE_EFFECTS_TIMER_ID)
245 {
246 updateEffectsDisplay();
247 }
248}
249
250void UIScene_InventoryMenu::updateEffectsDisplay()
251{
252 // Update with the current effects
253 Minecraft *pMinecraft = Minecraft::GetInstance();
254 shared_ptr<MultiplayerLocalPlayer> player = pMinecraft->localplayers[m_iPad];
255
256 if(player == NULL) return;
257
258 vector<MobEffectInstance *> *activeEffects = player->getActiveEffects();
259
260 // 4J - TomK setup time update value array size to update the active effects
261 int iValue = 0;
262 IggyDataValue *UpdateValue = new IggyDataValue[activeEffects->size()*2];
263
264 for(AUTO_VAR(it, activeEffects->begin()); it != activeEffects->end(); ++it)
265 {
266 MobEffectInstance *effect = *it;
267
268 if(effect->getDuration() >= m_bEffectTime[effect->getId()])
269 {
270 wstring effectString = app.GetString( effect->getDescriptionId() );//I18n.get(effect.getDescriptionId()).trim();
271 if (effect->getAmplifier() > 0)
272 {
273 wstring potencyString = L"";
274 switch(effect->getAmplifier())
275 {
276 case 1:
277 potencyString = L" ";
278 potencyString += app.GetString( IDS_POTION_POTENCY_1 );
279 break;
280 case 2:
281 potencyString = L" ";
282 potencyString += app.GetString( IDS_POTION_POTENCY_2 );
283 break;
284 case 3:
285 potencyString = L" ";
286 potencyString += app.GetString( IDS_POTION_POTENCY_3 );
287 break;
288 default:
289 potencyString = app.GetString( IDS_POTION_POTENCY_0 );
290 break;
291 }
292 effectString += potencyString;
293 }
294 int icon = 0;
295 MobEffect *mobEffect = MobEffect::effects[effect->getId()];
296 if (mobEffect->hasIcon())
297 {
298 icon = mobEffect->getIcon();
299 }
300 IggyDataValue result;
301 IggyDataValue value[3];
302 value[0].type = IGGY_DATATYPE_number;
303 value[0].number = icon;
304
305 IggyStringUTF16 stringVal;
306 stringVal.string = (IggyUTF16*)effectString.c_str();
307 stringVal.length = effectString.length();
308 value[1].type = IGGY_DATATYPE_string_UTF16;
309 value[1].string16 = stringVal;
310
311 int seconds = effect->getDuration() / SharedConstants::TICKS_PER_SECOND;
312 value[2].type = IGGY_DATATYPE_number;
313 value[2].number = seconds;
314 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcAddEffect , 3 , value );
315 }
316
317 if(MobEffect::effects[effect->getId()]->hasIcon())
318 {
319 // 4J - TomK set ids and remaining duration so we can update the timers accurately in one call! (this prevents performance related timer sync issues, especially on PSVita)
320 UpdateValue[iValue].type = IGGY_DATATYPE_number;
321 UpdateValue[iValue].number = MobEffect::effects[effect->getId()]->getIcon();
322 UpdateValue[iValue + 1].type = IGGY_DATATYPE_number;
323 UpdateValue[iValue + 1].number = (int)(effect->getDuration() / SharedConstants::TICKS_PER_SECOND);
324 iValue+=2;
325 }
326
327 m_bEffectTime[effect->getId()] = effect->getDuration();
328 }
329
330 IggyDataValue result;
331 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcUpdateEffects , activeEffects->size()*2 , UpdateValue );
332
333 delete activeEffects;
334}