aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/UI/UIScene_CreativeMenu.cpp
blob: ba2cd84525f342fc1dcb931d05b709801c253e63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#include "stdafx.h"
#include "UI.h"
#include "UIScene_CreativeMenu.h"

#include "..\Minecraft.World\JavaMath.h"
#include "..\..\LocalPlayer.h"
#include "..\Tutorial\Tutorial.h"
#include "..\Tutorial\TutorialMode.h"
#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"
#include "..\..\..\Minecraft.World\net.minecraft.world.item.h"

#ifdef __PSVITA__
#define GAME_CREATIVE_TOUCHUPDATE_TIMER_ID 0
#define GAME_CREATIVE_TOUCHUPDATE_TIMER_TIME 100
#endif

UIScene_CreativeMenu::UIScene_CreativeMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer)
{
	// Setup all the Iggy references we need for this scene
	initialiseMovie();

	InventoryScreenInput *initData = static_cast<InventoryScreenInput *>(_initData);

	shared_ptr<SimpleContainer> creativeContainer = std::make_shared<SimpleContainer>(0, L"", false, TabSpec::MAX_SIZE);
	itemPickerMenu = new ItemPickerMenu(creativeContainer, initData->player->inventory);

	Initialize( initData->iPad, itemPickerMenu, false, -1, eSectionInventoryCreativeUsing, eSectionInventoryCreativeMax, initData->bNavigateBack);

	m_labelInventory.setLabel( L"" );
	m_bFirstCall=true;

	//m_slotListContainer.addSlots(0,TabSpec::MAX_SIZE);
	//m_slotListHotbar.addSlots(TabSpec::MAX_SIZE,TabSpec::MAX_SIZE + 9);
	for(unsigned int i = 0; i < TabSpec::MAX_SIZE; ++i)
	{
		m_slotListContainer.addSlot(i);
	}

	for(unsigned int i = TabSpec::MAX_SIZE; i < TabSpec::MAX_SIZE + 9; ++i)
	{
		m_slotListHotbar.addSlot(i);
	}

	Minecraft *pMinecraft = Minecraft::GetInstance();
	if( pMinecraft->localgameModes[initData->iPad] != nullptr )
	{
		TutorialMode *gameMode = static_cast<TutorialMode *>(pMinecraft->localgameModes[initData->iPad]);
		m_previousTutorialState = gameMode->getTutorial()->getCurrentState();
		gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Creative_Inventory_Menu, this);
	}

	if(initData) delete initData;

	m_curTab = eCreativeInventoryTab_COUNT;
	switchTab(eCreativeInventoryTab_BuildingBlocks);

#ifdef __PSVITA__
	// initialise vita touch controls with ids
	for(unsigned int i = 0; i < ETouchInput_Count; ++i)
	{
		m_TouchInput[i].init(i);
	}
#endif
}

wstring UIScene_CreativeMenu::getMoviePath()
{
	if(app.GetLocalPlayerCount() > 1)
	{
		return L"CreativeMenuSplit";
	}
	else
	{
		return L"CreativeMenu";
	}
}

#ifdef __PSVITA__
UIControl* UIScene_CreativeMenu::GetMainPanel()
{
	return &m_controlMainPanel;
}

void UIScene_CreativeMenu::handleTouchInput(unsigned int iPad, S32 x, S32 y, int iId, bool bPressed, bool bRepeat, bool bReleased)
{
	// perform action on release
	if(bReleased)
	{
		if(iId >= eCreativeInventoryTab_BuildingBlocks && iId <= eCreativeInventoryTab_Misc)
		{
			switchTab((ECreativeInventoryTabs)iId);
			ui.PlayUISFX(eSFX_Focus);
		}
	}
	if(bRepeat && iId == ETouchInput_TouchSlider && specs[m_curTab]->getPageCount() > 1)
	{
		// calculate relative touch position on slider
		float fPosition = ((float)y - (float)m_TouchInput[ETouchInput_TouchSlider].getYPos() - m_controlMainPanel.getYPos()) /  (float)m_TouchInput[ETouchInput_TouchSlider].getHeight();
		
		// clamp
		if(fPosition > 1)
			fPosition = 1.0f;
		else if(fPosition < 0)
			fPosition = 0.0f;

		// calculate page position according to page count
		int iCurrentPage = Math::round(fPosition * (specs[m_curTab]->getPageCount() - 1));
		
		// set tab page
		m_tabPage[m_curTab] = iCurrentPage;

		// update tab
		switchTab(m_curTab);
	}
}

void UIScene_CreativeMenu::handleTouchBoxRebuild()
{
	addTimer(GAME_CREATIVE_TOUCHUPDATE_TIMER_ID,GAME_CREATIVE_TOUCHUPDATE_TIMER_TIME);
}

void UIScene_CreativeMenu::handleTimerComplete(int id)
{
	if(id == GAME_CREATIVE_TOUCHUPDATE_TIMER_ID)
	{
		// we cannot rebuild touch boxes in an iggy callback because it requires further iggy calls
		GetMainPanel()->UpdateControl();
		ui.TouchBoxRebuild(this);
		killTimer(GAME_CREATIVE_TOUCHUPDATE_TIMER_ID);
	}
}
#endif

void UIScene_CreativeMenu::handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey)
{
	switch(eSection)
	{
	case eSectionInventoryCreativeTab_0:
	case eSectionInventoryCreativeTab_1:
	case eSectionInventoryCreativeTab_2:
	case eSectionInventoryCreativeTab_3:
	case eSectionInventoryCreativeTab_4:
	case eSectionInventoryCreativeTab_5:
	case eSectionInventoryCreativeTab_6:
	case eSectionInventoryCreativeTab_7:
		{
			ECreativeInventoryTabs tab = static_cast<ECreativeInventoryTabs>((int)eCreativeInventoryTab_BuildingBlocks + (int)eSection - (int)eSectionInventoryCreativeTab_0);
			if(tab != m_curTab)
			{
				switchTab(tab);
				ui.PlayUISFX(eSFX_Focus);
			}
		}
		break;
	case eSectionInventoryCreativeSlider:
		ScrollBar(this->m_pointerPos);
		break;
	}
}

void UIScene_CreativeMenu::handleReload()
{
	Initialize( m_iPad, m_menu, false, -1, eSectionInventoryCreativeUsing, eSectionInventoryCreativeMax, m_bNavigateBack );

	for(unsigned int i = 0; i < TabSpec::MAX_SIZE; ++i)
	{
		m_slotListContainer.addSlot(i);
	}

	for(unsigned int i = TabSpec::MAX_SIZE; i < TabSpec::MAX_SIZE + 9; ++i)
	{
		m_slotListHotbar.addSlot(i);
	}
	
	ECreativeInventoryTabs lastTab = m_curTab;
	m_curTab = eCreativeInventoryTab_COUNT;
	switchTab(lastTab);
}

void UIScene_CreativeMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
{
	// 4J-PB - going to ignore repeats on this scene
	if(repeat) return;

	//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");
	ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released);

	int dir = 1;
	switch(key)
	{
	case VK_PAD_LSHOULDER:
		dir = -1;
		// Fall through intentional
	case VK_PAD_RSHOULDER:
		{		
			ECreativeInventoryTabs tab = static_cast<ECreativeInventoryTabs>(m_curTab + dir);
			if (tab < 0) tab = static_cast<ECreativeInventoryTabs>(eCreativeInventoryTab_COUNT - 1);
			if (tab >= eCreativeInventoryTab_COUNT) tab = eCreativeInventoryTab_BuildingBlocks;
			switchTab(tab);
			ui.PlayUISFX(eSFX_Focus);
		}
		break;
	case VK_PAD_LTRIGGER:
		// change the potion strength
		{
			++m_tabDynamicPos[m_curTab];
			if(m_tabDynamicPos[m_curTab] >= specs[m_curTab]->m_dynamicGroupsCount) m_tabDynamicPos[m_curTab] = 0;
			switchTab(m_curTab);
		}
		break;
	default:
		UIScene_AbstractContainerMenu::handleInput(iPad,key,repeat,pressed,released,handled);
		break;
	}
}

void UIScene_CreativeMenu::updateTabHighlightAndText(ECreativeInventoryTabs tab)
{
	IggyDataValue result;
	IggyDataValue value[1];

	value[0].type = IGGY_DATATYPE_number;
	value[0].number = static_cast<F64>(tab);

	IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ) , m_funcSetActiveTab , 1 , value );

	m_labelInventory.setLabel(app.GetString(specs[tab]->m_descriptionId));
}

int UIScene_CreativeMenu::getSectionColumns(ESceneSection eSection)
{
	int cols = 0;
	switch( eSection )
	{
	case eSectionInventoryCreativeSelector:
		cols = 10;
		break;
	case eSectionInventoryCreativeUsing:
		cols = 9;
		break;
	default:
		assert( false );
		break;
	}
	return cols;
}

int UIScene_CreativeMenu::getSectionRows(ESceneSection eSection)
{
	int rows = 0;
	switch( eSection )
	{
	case eSectionInventoryCreativeSelector:
		rows = 5;
		break;
	case eSectionInventoryCreativeUsing:
		rows = 1;
		break;
	default:
		assert( false );
		break;
	}
	return rows;
}

void UIScene_CreativeMenu::GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition )
{
	switch( eSection )
	{
	case eSectionInventoryCreativeSelector:
		pPosition->x = m_slotListContainer.getXPos();
		pPosition->y = m_slotListContainer.getYPos();
		break;
	case eSectionInventoryCreativeUsing:
		pPosition->x = m_slotListHotbar.getXPos();
		pPosition->y = m_slotListHotbar.getYPos();
		break;
	case eSectionInventoryCreativeTab_0:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_0].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_0].getYPos();
		break;
	case eSectionInventoryCreativeTab_1:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_1].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_1].getYPos();
		break;
	case eSectionInventoryCreativeTab_2:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_2].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_2].getYPos();
		break;
	case eSectionInventoryCreativeTab_3:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_3].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_3].getYPos();
		break;
	case eSectionInventoryCreativeTab_4:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_4].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_4].getYPos();
		break;
	case eSectionInventoryCreativeTab_5:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_5].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_5].getYPos();
		break;
	case eSectionInventoryCreativeTab_6:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_6].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_6].getYPos();
		break;
	case eSectionInventoryCreativeTab_7:
		pPosition->x = m_TouchInput[ETouchInput_TouchPanel_7].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchPanel_7].getYPos();
		break;
	case eSectionInventoryCreativeSlider:
		pPosition->x = m_TouchInput[ETouchInput_TouchSlider].getXPos();
		pPosition->y = m_TouchInput[ETouchInput_TouchSlider].getYPos();
		break;
	default:
		assert( false );
		break;
	}
}

void UIScene_CreativeMenu::GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize )
{
	UIVec2D sectionSize;

	switch( eSection )
	{
	case eSectionInventoryCreativeSelector:
		sectionSize.x = m_slotListContainer.getWidth();
		sectionSize.y = m_slotListContainer.getHeight();
		break;
	case eSectionInventoryCreativeUsing:
		sectionSize.x = m_slotListHotbar.getWidth();
		sectionSize.y = m_slotListHotbar.getHeight();
		break;
	case eSectionInventoryCreativeTab_0:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_0].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_0].getHeight();
		break;
	case eSectionInventoryCreativeTab_1:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_1].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_1].getHeight();
		break;
	case eSectionInventoryCreativeTab_2:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_2].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_2].getHeight();
		break;
	case eSectionInventoryCreativeTab_3:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_3].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_3].getHeight();
		break;
	case eSectionInventoryCreativeTab_4:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_4].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_4].getHeight();
		break;
	case eSectionInventoryCreativeTab_5:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_5].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_5].getHeight();
		break;
	case eSectionInventoryCreativeTab_6:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_6].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_6].getHeight();
		break;
	case eSectionInventoryCreativeTab_7:
		sectionSize.x = m_TouchInput[ETouchInput_TouchPanel_7].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchPanel_7].getHeight();
		break;
	case eSectionInventoryCreativeSlider:
		sectionSize.x = m_TouchInput[ETouchInput_TouchSlider].getWidth();
		sectionSize.y = m_TouchInput[ETouchInput_TouchSlider].getHeight();
		break;
	default:
		assert( false );
		break;
	}

	if(IsSectionSlotList(eSection))
	{
		int rows = getSectionRows(eSection);
		int cols = getSectionColumns(eSection);

		pSize->x = sectionSize.x/cols;
		pSize->y = sectionSize.y/rows;

		int itemCol = iItemIndex % cols;
		int itemRow = iItemIndex/cols;

		pPosition->x = itemCol * pSize->x;
		pPosition->y = itemRow * pSize->y;
	}
	else
	{
		GetPositionOfSection(eSection, pPosition);
		pSize->x = sectionSize.x;
		pSize->y = sectionSize.y;
	}
}

void UIScene_CreativeMenu::setSectionSelectedSlot(ESceneSection eSection, int x, int y)
{
	int cols = getSectionColumns(eSection);

	int index = (y * cols) + x;

	UIControl_SlotList *slotList = nullptr;
	switch( eSection )
	{
	case eSectionInventoryCreativeSelector:
		slotList = &m_slotListContainer;
		break;
	case eSectionInventoryCreativeUsing:
		slotList = &m_slotListHotbar;
		break;
	default:
		assert( false );
		break;
	}

	slotList->setHighlightSlot(index);
}

UIControl *UIScene_CreativeMenu::getSection(ESceneSection eSection)
{
	UIControl *control = nullptr;
	switch( eSection )
	{
	case eSectionInventoryCreativeSelector:
		control = &m_slotListContainer;
		break;
	case eSectionInventoryCreativeUsing:
		control = &m_slotListHotbar;
		break;
	case eSectionInventoryCreativeTab_0:
		control = &m_TouchInput[ETouchInput_TouchPanel_0];
		break;
	case eSectionInventoryCreativeTab_1:
		control = &m_TouchInput[ETouchInput_TouchPanel_1];
		break;
	case eSectionInventoryCreativeTab_2:
		control = &m_TouchInput[ETouchInput_TouchPanel_2];
		break;
	case eSectionInventoryCreativeTab_3:
		control = &m_TouchInput[ETouchInput_TouchPanel_3];
		break;
	case eSectionInventoryCreativeTab_4:
		control = &m_TouchInput[ETouchInput_TouchPanel_4];
		break;
	case eSectionInventoryCreativeTab_5:
		control = &m_TouchInput[ETouchInput_TouchPanel_5];
		break;
	case eSectionInventoryCreativeTab_6:
		control = &m_TouchInput[ETouchInput_TouchPanel_6];
		break;
	case eSectionInventoryCreativeTab_7:
		control = &m_TouchInput[ETouchInput_TouchPanel_7];
		break;
	case eSectionInventoryCreativeSlider:
		control = &m_TouchInput[ETouchInput_TouchSlider];
		break;
	default:
		assert( false );
		break;
	}
	return control;
}

void UIScene_CreativeMenu::updateScrollCurrentPage(int currentPage, int pageCount)
{
	IggyDataValue result;
	IggyDataValue value[2];

	value[0].type = IGGY_DATATYPE_number;
	value[0].number = static_cast<F64>(pageCount);

	value[1].type = IGGY_DATATYPE_number;
	value[1].number = static_cast<F64>(currentPage) - 1;

	IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ) , m_funcSetScrollBar , 2 , value );
}