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_CreativeMenu.h"
4
5#include "..\Minecraft.World\JavaMath.h"
6#include "..\..\LocalPlayer.h"
7#include "..\Tutorial\Tutorial.h"
8#include "..\Tutorial\TutorialMode.h"
9#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"
10#include "..\..\..\Minecraft.World\net.minecraft.world.item.h"
11
12#ifdef __PSVITA__
13#define GAME_CREATIVE_TOUCHUPDATE_TIMER_ID 0
14#define GAME_CREATIVE_TOUCHUPDATE_TIMER_TIME 100
15#endif
16
17UIScene_CreativeMenu::UIScene_CreativeMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer)
18{
19 // Setup all the Iggy references we need for this scene
20 initialiseMovie();
21
22 InventoryScreenInput *initData = (InventoryScreenInput *)_initData;
23
24 shared_ptr<SimpleContainer> creativeContainer = shared_ptr<SimpleContainer>(new SimpleContainer( 0, L"", false, TabSpec::MAX_SIZE ));
25 itemPickerMenu = new ItemPickerMenu(creativeContainer, initData->player->inventory);
26
27 Initialize( initData->iPad, itemPickerMenu, false, -1, eSectionInventoryCreativeUsing, eSectionInventoryCreativeMax, initData->bNavigateBack);
28
29 m_labelInventory.setLabel( L"" );
30 m_bFirstCall=true;
31
32 //m_slotListContainer.addSlots(0,TabSpec::MAX_SIZE);
33 //m_slotListHotbar.addSlots(TabSpec::MAX_SIZE,TabSpec::MAX_SIZE + 9);
34 for(unsigned int i = 0; i < TabSpec::MAX_SIZE; ++i)
35 {
36 m_slotListContainer.addSlot(i);
37 }
38
39 for(unsigned int i = TabSpec::MAX_SIZE; i < TabSpec::MAX_SIZE + 9; ++i)
40 {
41 m_slotListHotbar.addSlot(i);
42 }
43
44 Minecraft *pMinecraft = Minecraft::GetInstance();
45 if( pMinecraft->localgameModes[initData->iPad] != NULL )
46 {
47 TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[initData->iPad];
48 m_previousTutorialState = gameMode->getTutorial()->getCurrentState();
49 gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Creative_Inventory_Menu, this);
50 }
51
52 if(initData) delete initData;
53
54 m_curTab = eCreativeInventoryTab_COUNT;
55 switchTab(eCreativeInventoryTab_BuildingBlocks);
56
57#ifdef __PSVITA__
58 // initialise vita touch controls with ids
59 for(unsigned int i = 0; i < ETouchInput_Count; ++i)
60 {
61 m_TouchInput[i].init(i);
62 }
63#endif
64}
65
66wstring UIScene_CreativeMenu::getMoviePath()
67{
68 if(app.GetLocalPlayerCount() > 1)
69 {
70 return L"CreativeMenuSplit";
71 }
72 else
73 {
74 return L"CreativeMenu";
75 }
76}
77
78#ifdef __PSVITA__
79UIControl* UIScene_CreativeMenu::GetMainPanel()
80{
81 return &m_controlMainPanel;
82}
83
84void UIScene_CreativeMenu::handleTouchInput(unsigned int iPad, S32 x, S32 y, int iId, bool bPressed, bool bRepeat, bool bReleased)
85{
86 // perform action on release
87 if(bReleased)
88 {
89 if(iId >= eCreativeInventoryTab_BuildingBlocks && iId <= eCreativeInventoryTab_Misc)
90 {
91 switchTab((ECreativeInventoryTabs)iId);
92 ui.PlayUISFX(eSFX_Focus);
93 }
94 }
95 if(bRepeat && iId == ETouchInput_TouchSlider && specs[m_curTab]->getPageCount() > 1)
96 {
97 // calculate relative touch position on slider
98 float fPosition = ((float)y - (float)m_TouchInput[ETouchInput_TouchSlider].getYPos() - m_controlMainPanel.getYPos()) / (float)m_TouchInput[ETouchInput_TouchSlider].getHeight();
99
100 // clamp
101 if(fPosition > 1)
102 fPosition = 1.0f;
103 else if(fPosition < 0)
104 fPosition = 0.0f;
105
106 // calculate page position according to page count
107 int iCurrentPage = Math::round(fPosition * (specs[m_curTab]->getPageCount() - 1));
108
109 // set tab page
110 m_tabPage[m_curTab] = iCurrentPage;
111
112 // update tab
113 switchTab(m_curTab);
114 }
115}
116
117void UIScene_CreativeMenu::handleTouchBoxRebuild()
118{
119 addTimer(GAME_CREATIVE_TOUCHUPDATE_TIMER_ID,GAME_CREATIVE_TOUCHUPDATE_TIMER_TIME);
120}
121
122void UIScene_CreativeMenu::handleTimerComplete(int id)
123{
124 if(id == GAME_CREATIVE_TOUCHUPDATE_TIMER_ID)
125 {
126 // we cannot rebuild touch boxes in an iggy callback because it requires further iggy calls
127 GetMainPanel()->UpdateControl();
128 ui.TouchBoxRebuild(this);
129 killTimer(GAME_CREATIVE_TOUCHUPDATE_TIMER_ID);
130 }
131}
132#endif
133
134void UIScene_CreativeMenu::handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey)
135{
136 switch(eSection)
137 {
138 case eSectionInventoryCreativeTab_0:
139 case eSectionInventoryCreativeTab_1:
140 case eSectionInventoryCreativeTab_2:
141 case eSectionInventoryCreativeTab_3:
142 case eSectionInventoryCreativeTab_4:
143 case eSectionInventoryCreativeTab_5:
144 case eSectionInventoryCreativeTab_6:
145 case eSectionInventoryCreativeTab_7:
146 {
147 ECreativeInventoryTabs tab = (ECreativeInventoryTabs)((int)eCreativeInventoryTab_BuildingBlocks + (int)eSection - (int)eSectionInventoryCreativeTab_0);
148 if(tab != m_curTab)
149 {
150 switchTab(tab);
151 ui.PlayUISFX(eSFX_Focus);
152 }
153 }
154 break;
155 case eSectionInventoryCreativeSlider:
156 ScrollBar(this->m_pointerPos);
157 break;
158 }
159}
160
161void UIScene_CreativeMenu::handleReload()
162{
163 Initialize( m_iPad, m_menu, false, -1, eSectionInventoryCreativeUsing, eSectionInventoryCreativeMax, m_bNavigateBack );
164
165 for(unsigned int i = 0; i < TabSpec::MAX_SIZE; ++i)
166 {
167 m_slotListContainer.addSlot(i);
168 }
169
170 for(unsigned int i = TabSpec::MAX_SIZE; i < TabSpec::MAX_SIZE + 9; ++i)
171 {
172 m_slotListHotbar.addSlot(i);
173 }
174
175 ECreativeInventoryTabs lastTab = m_curTab;
176 m_curTab = eCreativeInventoryTab_COUNT;
177 switchTab(lastTab);
178}
179
180void UIScene_CreativeMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
181{
182 // 4J-PB - going to ignore repeats on this scene
183 if(repeat) return;
184
185 //app.DebugPrintf("UIScene_CreativeMenu handling input for pad %d, key %d, down- %s, pressed- %s, released- %s\n", iPad, key, down?"TRUE":"FALSE", pressed?"TRUE":"FALSE", released?"TRUE":"FALSE");
186 ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released);
187
188 int dir = 1;
189 switch(key)
190 {
191 case VK_PAD_LSHOULDER:
192 dir = -1;
193 // Fall through intentional
194 case VK_PAD_RSHOULDER:
195 {
196 ECreativeInventoryTabs tab = (ECreativeInventoryTabs)(m_curTab + dir);
197 if (tab < 0) tab = (ECreativeInventoryTabs)(eCreativeInventoryTab_COUNT - 1);
198 if (tab >= eCreativeInventoryTab_COUNT) tab = eCreativeInventoryTab_BuildingBlocks;
199 switchTab(tab);
200 ui.PlayUISFX(eSFX_Focus);
201 }
202 break;
203 case VK_PAD_LTRIGGER:
204 // change the potion strength
205 {
206 ++m_tabDynamicPos[m_curTab];
207 if(m_tabDynamicPos[m_curTab] >= specs[m_curTab]->m_dynamicGroupsCount) m_tabDynamicPos[m_curTab] = 0;
208 switchTab(m_curTab);
209 }
210 break;
211 default:
212 UIScene_AbstractContainerMenu::handleInput(iPad,key,repeat,pressed,released,handled);
213 break;
214 }
215}
216
217void UIScene_CreativeMenu::updateTabHighlightAndText(ECreativeInventoryTabs tab)
218{
219 IggyDataValue result;
220 IggyDataValue value[1];
221
222 value[0].type = IGGY_DATATYPE_number;
223 value[0].number = (F64)tab;
224
225 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ) , m_funcSetActiveTab , 1 , value );
226
227 m_labelInventory.setLabel(app.GetString(specs[tab]->m_descriptionId));
228}
229
230int UIScene_CreativeMenu::getSectionColumns(ESceneSection eSection)
231{
232 int cols = 0;
233 switch( eSection )
234 {
235 case eSectionInventoryCreativeSelector:
236 cols = 10;
237 break;
238 case eSectionInventoryCreativeUsing:
239 cols = 9;
240 break;
241 default:
242 assert( false );
243 break;
244 }
245 return cols;
246}
247
248int UIScene_CreativeMenu::getSectionRows(ESceneSection eSection)
249{
250 int rows = 0;
251 switch( eSection )
252 {
253 case eSectionInventoryCreativeSelector:
254 rows = 5;
255 break;
256 case eSectionInventoryCreativeUsing:
257 rows = 1;
258 break;
259 default:
260 assert( false );
261 break;
262 }
263 return rows;
264}
265
266void UIScene_CreativeMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition )
267{
268 switch( eSection )
269 {
270 case eSectionInventoryCreativeSelector:
271 pPosition->x = m_slotListContainer.getXPos();
272 pPosition->y = m_slotListContainer.getYPos();
273 break;
274 case eSectionInventoryCreativeUsing:
275 pPosition->x = m_slotListHotbar.getXPos();
276 pPosition->y = m_slotListHotbar.getYPos();
277 break;
278 case eSectionInventoryCreativeTab_0:
279 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_0].getXPos();
280 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_0].getYPos();
281 break;
282 case eSectionInventoryCreativeTab_1:
283 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_1].getXPos();
284 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_1].getYPos();
285 break;
286 case eSectionInventoryCreativeTab_2:
287 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_2].getXPos();
288 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_2].getYPos();
289 break;
290 case eSectionInventoryCreativeTab_3:
291 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_3].getXPos();
292 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_3].getYPos();
293 break;
294 case eSectionInventoryCreativeTab_4:
295 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_4].getXPos();
296 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_4].getYPos();
297 break;
298 case eSectionInventoryCreativeTab_5:
299 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_5].getXPos();
300 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_5].getYPos();
301 break;
302 case eSectionInventoryCreativeTab_6:
303 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_6].getXPos();
304 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_6].getYPos();
305 break;
306 case eSectionInventoryCreativeTab_7:
307 pPosition->x = m_TouchInput[ETouchInput_TouchPanel_7].getXPos();
308 pPosition->y = m_TouchInput[ETouchInput_TouchPanel_7].getYPos();
309 break;
310 case eSectionInventoryCreativeSlider:
311 pPosition->x = m_TouchInput[ETouchInput_TouchSlider].getXPos();
312 pPosition->y = m_TouchInput[ETouchInput_TouchSlider].getYPos();
313 break;
314 default:
315 assert( false );
316 break;
317 }
318}
319
320void UIScene_CreativeMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize )
321{
322 UIVec2D sectionSize;
323
324 switch( eSection )
325 {
326 case eSectionInventoryCreativeSelector:
327 sectionSize.x = m_slotListContainer.getWidth();
328 sectionSize.y = m_slotListContainer.getHeight();
329 break;
330 case eSectionInventoryCreativeUsing:
331 sectionSize.x = m_slotListHotbar.getWidth();
332 sectionSize.y = m_slotListHotbar.getHeight();
333 break;
334 case eSectionInventoryCreativeTab_0:
335 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_0].getWidth();
336 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_0].getHeight();
337 break;
338 case eSectionInventoryCreativeTab_1:
339 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_1].getWidth();
340 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_1].getHeight();
341 break;
342 case eSectionInventoryCreativeTab_2:
343 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_2].getWidth();
344 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_2].getHeight();
345 break;
346 case eSectionInventoryCreativeTab_3:
347 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_3].getWidth();
348 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_3].getHeight();
349 break;
350 case eSectionInventoryCreativeTab_4:
351 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_4].getWidth();
352 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_4].getHeight();
353 break;
354 case eSectionInventoryCreativeTab_5:
355 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_5].getWidth();
356 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_5].getHeight();
357 break;
358 case eSectionInventoryCreativeTab_6:
359 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_6].getWidth();
360 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_6].getHeight();
361 break;
362 case eSectionInventoryCreativeTab_7:
363 sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_7].getWidth();
364 sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_7].getHeight();
365 break;
366 case eSectionInventoryCreativeSlider:
367 sectionSize.x = m_TouchInput[ETouchInput_TouchSlider].getWidth();
368 sectionSize.y = m_TouchInput[ETouchInput_TouchSlider].getHeight();
369 break;
370 default:
371 assert( false );
372 break;
373 }
374
375 if(IsSectionSlotList(eSection))
376 {
377 int rows = getSectionRows(eSection);
378 int cols = getSectionColumns(eSection);
379
380 pSize->x = sectionSize.x/cols;
381 pSize->y = sectionSize.y/rows;
382
383 int itemCol = iItemIndex % cols;
384 int itemRow = iItemIndex/cols;
385
386 pPosition->x = itemCol * pSize->x;
387 pPosition->y = itemRow * pSize->y;
388 }
389 else
390 {
391 GetPositionOfSection(eSection, pPosition);
392 pSize->x = sectionSize.x;
393 pSize->y = sectionSize.y;
394 }
395}
396
397void UIScene_CreativeMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y)
398{
399 int cols = getSectionColumns(eSection);
400
401 int index = (y * cols) + x;
402
403 UIControl_SlotList *slotList = NULL;
404 switch( eSection )
405 {
406 case eSectionInventoryCreativeSelector:
407 slotList = &m_slotListContainer;
408 break;
409 case eSectionInventoryCreativeUsing:
410 slotList = &m_slotListHotbar;
411 break;
412 default:
413 assert( false );
414 break;
415 }
416
417 slotList->setHighlightSlot(index);
418}
419
420UIControl *UIScene_CreativeMenu::getSection(ESceneSection eSection)
421{
422 UIControl *control = NULL;
423 switch( eSection )
424 {
425 case eSectionInventoryCreativeSelector:
426 control = &m_slotListContainer;
427 break;
428 case eSectionInventoryCreativeUsing:
429 control = &m_slotListHotbar;
430 break;
431 case eSectionInventoryCreativeTab_0:
432 control = &m_TouchInput[ETouchInput_TouchPanel_0];
433 break;
434 case eSectionInventoryCreativeTab_1:
435 control = &m_TouchInput[ETouchInput_TouchPanel_1];
436 break;
437 case eSectionInventoryCreativeTab_2:
438 control = &m_TouchInput[ETouchInput_TouchPanel_2];
439 break;
440 case eSectionInventoryCreativeTab_3:
441 control = &m_TouchInput[ETouchInput_TouchPanel_3];
442 break;
443 case eSectionInventoryCreativeTab_4:
444 control = &m_TouchInput[ETouchInput_TouchPanel_4];
445 break;
446 case eSectionInventoryCreativeTab_5:
447 control = &m_TouchInput[ETouchInput_TouchPanel_5];
448 break;
449 case eSectionInventoryCreativeTab_6:
450 control = &m_TouchInput[ETouchInput_TouchPanel_6];
451 break;
452 case eSectionInventoryCreativeTab_7:
453 control = &m_TouchInput[ETouchInput_TouchPanel_7];
454 break;
455 case eSectionInventoryCreativeSlider:
456 control = &m_TouchInput[ETouchInput_TouchSlider];
457 break;
458 default:
459 assert( false );
460 break;
461 }
462 return control;
463}
464
465void UIScene_CreativeMenu::updateScrollCurrentPage(int currentPage, int pageCount)
466{
467 IggyDataValue result;
468 IggyDataValue value[2];
469
470 value[0].type = IGGY_DATATYPE_number;
471 value[0].number = (F64)pageCount;
472
473 value[1].type = IGGY_DATATYPE_number;
474 value[1].number = (F64)currentPage - 1;
475
476 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ) , m_funcSetScrollBar , 2 , value );
477}