aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/UI/IUIScene_EnchantingMenu.cpp
blob: fbbf7c24ff4c1202eaf2c4e4a13f6963c1ebb190 (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
#include "stdafx.h"
#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"
#include "..\..\Minecraft.h"
#include "..\..\MultiplayerLocalPlayer.h"
#include "IUIScene_EnchantingMenu.h"

IUIScene_AbstractContainerMenu::ESceneSection IUIScene_EnchantingMenu::GetSectionAndSlotInDirection( IUIScene_AbstractContainerMenu::ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY )
{
	IUIScene_AbstractContainerMenu::ESceneSection newSection = eSection;
	int xOffset = 0;

	// Find the new section if there is one
	switch( eSection )
	{
		case eSectionEnchantInventory:
			if(eTapDirection == eTapStateDown)
			{
				newSection = eSectionEnchantUsing;
			}
			else if(eTapDirection == eTapStateUp)
			{
				if( *piTargetX >= ENCHANT_SCENE_ENCHANT_BUTTONS_UP_OFFSET)
				{
					newSection = eSectionEnchantButton3;
				}
				else
				{
					newSection = eSectionEnchantSlot;
				}
			}
			break;
		case eSectionEnchantUsing:
			if(eTapDirection == eTapStateDown)
			{
				if( *piTargetX >= ENCHANT_SCENE_ENCHANT_BUTTONS_UP_OFFSET)
				{
					newSection = eSectionEnchantButton1;
				}
				else
				{
					newSection = eSectionEnchantSlot;
				}
			}
			else if(eTapDirection == eTapStateUp)
			{
				newSection = eSectionEnchantInventory;
			}
			break;
		case eSectionEnchantSlot:
			if(eTapDirection == eTapStateDown)
			{
				newSection = eSectionEnchantInventory;
				xOffset = ENCHANT_SCENE_INGREDIENT_SLOT_DOWN_OFFSET;
			}
			else if(eTapDirection == eTapStateUp)
			{
				newSection = eSectionEnchantUsing;
				xOffset = ENCHANT_SCENE_INGREDIENT_SLOT_DOWN_OFFSET;
			}
			else if(eTapDirection == eTapStateLeft || eTapDirection == eTapStateRight)
			{
				newSection = eSectionEnchantButton1;
			}
			break;
		case eSectionEnchantButton1:
			if(eTapDirection == eTapStateDown)
			{
				newSection = eSectionEnchantButton2;
			}
			else if(eTapDirection == eTapStateUp)
			{
				newSection = eSectionEnchantUsing;
				xOffset = ENCHANT_SCENE_ENCHANT_BUTTONS_DOWN_OFFSET;
			}
			else if(eTapDirection == eTapStateLeft || eTapDirection == eTapStateRight)
			{
				newSection = eSectionEnchantSlot;
			}
			break;
		case eSectionEnchantButton2:
			if(eTapDirection == eTapStateDown)
			{
				newSection = eSectionEnchantButton3;
			}
			else if(eTapDirection == eTapStateUp)
			{
				newSection = eSectionEnchantButton1;
			}
			else if(eTapDirection == eTapStateLeft || eTapDirection == eTapStateRight)
			{
				newSection = eSectionEnchantSlot;
			}
			break;
		case eSectionEnchantButton3:
			if(eTapDirection == eTapStateDown)
			{
				newSection = eSectionEnchantInventory;
				xOffset = ENCHANT_SCENE_ENCHANT_BUTTONS_DOWN_OFFSET;
			}
			else if(eTapDirection == eTapStateUp)
			{
				newSection = eSectionEnchantButton2;
			}
			else if(eTapDirection == eTapStateLeft || eTapDirection == eTapStateRight)
			{
				newSection = eSectionEnchantSlot;
			}
			break;
		default:
			assert( false );
			break;
	}

	updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, piTargetY, xOffset);

	return newSection;
}

void IUIScene_EnchantingMenu::handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey)
{
	int index = -1;
	// Old xui code
#if 0
	HXUIOBJ hFocusObject = GetFocus(iPad);
	if(hFocusObject == m_enchant1->m_hObj) index = 0;
	else if(hFocusObject == m_enchant2->m_hObj) index = 1;
	else if(hFocusObject == m_enchant3->m_hObj) index = 2;
#endif

	switch(eSection)
	{
	case eSectionEnchantButton1:
		index = 0;
		break;
	case eSectionEnchantButton2:
		index = 1;
		break;
	case eSectionEnchantButton3:
		index = 2;
		break;
	};
	Minecraft *pMinecraft = Minecraft::GetInstance();
	if (index >= 0 && m_menu->clickMenuButton(dynamic_pointer_cast<Player>(pMinecraft->localplayers[iPad]), index))
	{
		pMinecraft->localgameModes[iPad]->handleInventoryButtonClick(m_menu->containerId, index);
	}
}

int IUIScene_EnchantingMenu::getSectionStartOffset(ESceneSection eSection)
{
	int offset = 0;
	switch( eSection )
	{
	case eSectionEnchantSlot:
		offset = 0;
		break;
	case eSectionEnchantInventory:
		offset = 1;
		break;
	case eSectionEnchantUsing:
		offset = 1 + 27;
		break;
	default:
		assert( false );
		break;
	};
	return offset;
}

bool IUIScene_EnchantingMenu::IsSectionSlotList( ESceneSection eSection )
{
	switch( eSection )
	{
		case eSectionEnchantInventory:
		case eSectionEnchantUsing:
		case eSectionEnchantSlot:
			return true;
	}
	return false;
}

EnchantmentMenu *IUIScene_EnchantingMenu::getMenu()
{
	return static_cast<EnchantmentMenu *>(m_menu);
}