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 "..\Minecraft.World\CustomPayloadPacket.h"
3#include "..\Minecraft.World\net.minecraft.world.inventory.h"
4#include "..\Minecraft.World\net.minecraft.world.level.tile.entity.h"
5#include "..\Minecraft.World\net.minecraft.world.effect.h"
6#include "..\Minecraft.World\HtmlString.h"
7#include "IUIScene_BeaconMenu.h"
8#include "Minecraft.h"
9#include "MultiPlayerLocalPlayer.h"
10#include "ClientConnection.h"
11
12IUIScene_BeaconMenu::IUIScene_BeaconMenu()
13{
14 m_beacon = nullptr;
15 m_initPowerButtons = true;
16}
17
18IUIScene_AbstractContainerMenu::ESceneSection IUIScene_BeaconMenu::GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY )
19{
20 ESceneSection newSection = eSection;
21
22 int xOffset = 0;
23
24 // Find the new section if there is one
25 switch( eSection )
26 {
27 case eSectionBeaconInventory:
28 if(eTapDirection == eTapStateDown) newSection = eSectionBeaconUsing;
29 else if(eTapDirection == eTapStateUp)
30 {
31 if( *piTargetX < 4 )
32 {
33 newSection = eSectionBeaconPrimaryTierThree;
34 }
35 else if ( *piTargetX < 7)
36 {
37 newSection = eSectionBeaconItem;
38 }
39 else
40 {
41 newSection = eSectionBeaconConfirm;
42 }
43 }
44 break;
45 case eSectionBeaconUsing:
46 if(eTapDirection == eTapStateDown)
47 {
48 if( *piTargetX < 2)
49 {
50 newSection = eSectionBeaconPrimaryTierOneOne;
51 }
52 else if( *piTargetX < 5)
53 {
54 newSection = eSectionBeaconPrimaryTierOneTwo;
55 }
56 else if( *piTargetX > 8 && GetPowerButtonId(eSectionBeaconSecondaryTwo) > 0)
57 {
58 newSection = eSectionBeaconSecondaryTwo;
59 }
60 else
61 {
62 newSection = eSectionBeaconSecondaryOne;
63 }
64 }
65 else if(eTapDirection == eTapStateUp) newSection = eSectionBeaconInventory;
66 break;
67 case eSectionBeaconItem:
68 if(eTapDirection == eTapStateDown)
69 {
70 newSection = eSectionBeaconInventory;
71 xOffset = -5;
72 }
73 else if(eTapDirection == eTapStateUp) newSection = eSectionBeaconSecondaryOne;
74 else if(eTapDirection == eTapStateLeft) newSection = eSectionBeaconConfirm;
75 else if(eTapDirection == eTapStateRight) newSection = eSectionBeaconConfirm;
76 break;
77 case eSectionBeaconPrimaryTierOneOne:
78 if(eTapDirection == eTapStateDown) newSection = eSectionBeaconPrimaryTierTwoOne;
79 else if(eTapDirection == eTapStateUp)
80 {
81 newSection = eSectionBeaconUsing;
82 xOffset = -1;
83 }
84 else if(eTapDirection == eTapStateLeft) newSection = eSectionBeaconPrimaryTierOneTwo;
85 else if(eTapDirection == eTapStateRight) newSection = eSectionBeaconPrimaryTierOneTwo;
86 break;
87 case eSectionBeaconPrimaryTierOneTwo:
88 if(eTapDirection == eTapStateDown) newSection = eSectionBeaconPrimaryTierTwoTwo;
89 else if(eTapDirection == eTapStateUp)
90 {
91 newSection = eSectionBeaconUsing;
92 xOffset = -3;
93 }
94 else if(eTapDirection == eTapStateLeft) newSection = eSectionBeaconPrimaryTierOneOne;
95 else if(eTapDirection == eTapStateRight) newSection = eSectionBeaconPrimaryTierOneOne;
96 break;
97 case eSectionBeaconPrimaryTierTwoOne:
98 if(eTapDirection == eTapStateDown) newSection = eSectionBeaconPrimaryTierThree;
99 else if(eTapDirection == eTapStateUp) newSection = eSectionBeaconPrimaryTierOneOne;
100 else if(eTapDirection == eTapStateLeft)
101 {
102 if(GetPowerButtonId(eSectionBeaconSecondaryTwo) > 0)
103 {
104 newSection = eSectionBeaconSecondaryTwo;
105 }
106 else
107 {
108 newSection = eSectionBeaconSecondaryOne;
109 }
110 }
111 else if(eTapDirection == eTapStateRight) newSection = eSectionBeaconPrimaryTierTwoTwo;
112 break;
113 case eSectionBeaconPrimaryTierTwoTwo:
114 if(eTapDirection == eTapStateDown) newSection = eSectionBeaconPrimaryTierThree;
115 else if(eTapDirection == eTapStateUp) newSection = eSectionBeaconPrimaryTierOneTwo;
116 else if(eTapDirection == eTapStateLeft) newSection = eSectionBeaconPrimaryTierTwoOne;
117 else if(eTapDirection == eTapStateRight) newSection = eSectionBeaconSecondaryOne;
118 break;
119 case eSectionBeaconPrimaryTierThree:
120 if(eTapDirection == eTapStateDown)
121 {
122 newSection = eSectionBeaconInventory;
123 xOffset = -3;
124 }
125 else if(eTapDirection == eTapStateUp) newSection = eSectionBeaconPrimaryTierTwoOne;
126 break;
127 case eSectionBeaconSecondaryOne:
128 if(eTapDirection == eTapStateDown) newSection = eSectionBeaconItem;
129 else if(eTapDirection == eTapStateUp)
130 {
131 newSection = eSectionBeaconUsing;
132 xOffset = -7;
133 }
134 else if(eTapDirection == eTapStateLeft) newSection = eSectionBeaconPrimaryTierTwoTwo;
135 else if(eTapDirection == eTapStateRight)
136 {
137 if(GetPowerButtonId(eSectionBeaconSecondaryTwo) > 0)
138 {
139 newSection = eSectionBeaconSecondaryTwo;
140 }
141 else
142 {
143 newSection = eSectionBeaconPrimaryTierTwoOne;
144 }
145 }
146 break;
147 case eSectionBeaconSecondaryTwo:
148 if(eTapDirection == eTapStateDown) newSection = eSectionBeaconItem;
149 else if(eTapDirection == eTapStateUp)
150 {
151 newSection = eSectionBeaconUsing;
152 xOffset = -8;
153 }
154 else if(eTapDirection == eTapStateLeft) newSection = eSectionBeaconSecondaryOne;
155 else if(eTapDirection == eTapStateRight) newSection = eSectionBeaconPrimaryTierTwoOne;
156 break;
157 case eSectionBeaconConfirm:
158 if(eTapDirection == eTapStateDown)
159 {
160 newSection = eSectionBeaconInventory;
161 xOffset = -8;
162 }
163 else if(eTapDirection == eTapStateUp)
164 {
165 newSection = eSectionBeaconSecondaryOne;
166 }
167 else if(eTapDirection == eTapStateLeft) newSection = eSectionBeaconItem;
168 else if(eTapDirection == eTapStateRight) newSection = eSectionBeaconItem;
169 break;
170 default:
171 assert(false);
172 break;
173 }
174
175 updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, piTargetY, xOffset);
176
177 return newSection;
178}
179
180int IUIScene_BeaconMenu::getSectionStartOffset(IUIScene_AbstractContainerMenu::ESceneSection eSection)
181{
182 int offset = 0;
183 switch( eSection )
184 {
185 case eSectionBeaconItem:
186 offset = BeaconMenu::PAYMENT_SLOT;
187 break;
188 case eSectionBeaconInventory:
189 offset = BeaconMenu::INV_SLOT_START;
190 break;
191 case eSectionBeaconUsing:
192 offset = BeaconMenu::USE_ROW_SLOT_START;
193 break;
194 default:
195 assert( false );
196 break;
197 }
198 return offset;
199}
200
201bool IUIScene_BeaconMenu::IsSectionSlotList( ESceneSection eSection )
202{
203 switch( eSection )
204 {
205 case eSectionBeaconItem:
206 case eSectionBeaconInventory:
207 case eSectionBeaconUsing:
208 return true;
209 }
210 return false;
211}
212
213void IUIScene_BeaconMenu::handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey)
214{
215 switch(eSection)
216 {
217 case eSectionBeaconConfirm:
218 {
219 if( (m_beacon->getItem(0) == NULL) || (m_beacon->getPrimaryPower() <= 0) ) return;
220 ByteArrayOutputStream baos;
221 DataOutputStream dos(&baos);
222 dos.writeInt(m_beacon->getPrimaryPower());
223 dos.writeInt(m_beacon->getSecondaryPower());
224
225 Minecraft::GetInstance()->localplayers[getPad()]->connection->send(shared_ptr<CustomPayloadPacket>(new CustomPayloadPacket(CustomPayloadPacket::SET_BEACON_PACKET, baos.toByteArray())));
226
227 if (m_beacon->getPrimaryPower() > 0)
228 {
229 int effectId = m_beacon->getPrimaryPower();
230
231 bool active = true;
232 bool selected = false;
233
234 int tier = 3;
235 if (tier >= m_beacon->getLevels())
236 {
237 active = false;
238 }
239 else if (effectId == m_beacon->getSecondaryPower())
240 {
241 selected = true;
242 }
243
244 AddPowerButton(GetId(tier, m_beacon->getPrimaryPower()), MobEffect::effects[m_beacon->getPrimaryPower()]->getIcon(), tier, 1, active, selected);
245 }
246 }
247 break;
248 case eSectionBeaconPrimaryTierOneOne:
249 case eSectionBeaconPrimaryTierOneTwo:
250 case eSectionBeaconPrimaryTierTwoOne:
251 case eSectionBeaconPrimaryTierTwoTwo:
252 case eSectionBeaconPrimaryTierThree:
253 case eSectionBeaconSecondaryOne:
254 case eSectionBeaconSecondaryTwo:
255 if(IsPowerButtonSelected(eSection))
256 {
257 return;
258 }
259
260 int id = GetPowerButtonId(eSection);
261 int effectId = (id & 0xff);
262 int tier = (id >> 8);
263
264 if (tier < 3)
265 {
266 m_beacon->setPrimaryPower(effectId);
267 }
268 else
269 {
270 m_beacon->setSecondaryPower(effectId);
271 }
272 SetPowerButtonSelected(eSection);
273 break;
274 };
275}
276
277void IUIScene_BeaconMenu::handleTick()
278{
279 if (m_initPowerButtons && m_beacon->getLevels() >= 0)
280 {
281 m_initPowerButtons = false;
282 for (int tier = 0; tier <= 2; tier++)
283 {
284 int count = BeaconTileEntity::BEACON_EFFECTS_EFFECTS;//BEACON_EFFECTS[tier].length;
285 int totalWidth = count * 22 + (count - 1) * 2;
286
287 for (int c = 0; c < count; c++)
288 {
289 if(BeaconTileEntity::BEACON_EFFECTS[tier][c] == NULL) continue;
290
291 int effectId = BeaconTileEntity::BEACON_EFFECTS[tier][c]->id;
292 int icon = BeaconTileEntity::BEACON_EFFECTS[tier][c]->getIcon();
293
294 bool active = true;
295 bool selected = false;
296
297 if (tier >= m_beacon->getLevels())
298 {
299 active = false;
300 }
301 else if (effectId == m_beacon->getPrimaryPower())
302 {
303 selected = true;
304 }
305
306 AddPowerButton(GetId(tier, effectId), icon, tier, c, active, selected);
307 }
308 }
309
310 {
311 int tier = 3;
312
313 int count = BeaconTileEntity::BEACON_EFFECTS_EFFECTS + 1;//BEACON_EFFECTS[tier].length + 1;
314 int totalWidth = count * 22 + (count - 1) * 2;
315
316 for (int c = 0; c < count - 1; c++)
317 {
318 if(BeaconTileEntity::BEACON_EFFECTS[tier][c] == NULL) continue;
319
320 int effectId = BeaconTileEntity::BEACON_EFFECTS[tier][c]->id;
321 int icon = BeaconTileEntity::BEACON_EFFECTS[tier][c]->getIcon();
322
323 bool active = true;
324 bool selected = false;
325
326 if (tier >= m_beacon->getLevels())
327 {
328 active = false;
329 }
330 else if (effectId == m_beacon->getSecondaryPower())
331 {
332 selected = true;
333 }
334
335 AddPowerButton(GetId(tier, effectId), icon, tier, c, active, selected);
336 }
337 if (m_beacon->getPrimaryPower() > 0)
338 {
339 int effectId = m_beacon->getPrimaryPower();
340
341 bool active = true;
342 bool selected = false;
343
344 if (tier >= m_beacon->getLevels())
345 {
346 active = false;
347 }
348 else if (effectId == m_beacon->getSecondaryPower())
349 {
350 selected = true;
351 }
352
353 AddPowerButton(GetId(tier, m_beacon->getPrimaryPower()), MobEffect::effects[m_beacon->getPrimaryPower()]->getIcon(), tier, 1, active, selected);
354 }
355 }
356 }
357
358 SetConfirmButtonEnabled( (m_beacon->getItem(0) != NULL) && (m_beacon->getPrimaryPower() > 0) );
359}
360
361int IUIScene_BeaconMenu::GetId(int tier, int effectId)
362{
363 return (tier << 8) | effectId;
364}
365
366vector<HtmlString> *IUIScene_BeaconMenu::GetSectionHoverText(ESceneSection eSection)
367{
368 vector<HtmlString> *desc = NULL;
369 switch(eSection)
370 {
371 case eSectionBeaconSecondaryTwo:
372 if(GetPowerButtonId(eSectionBeaconSecondaryTwo) == 0)
373 {
374 // This isn't visible
375 break;
376 }
377 // Fall through otherwise
378 case eSectionBeaconPrimaryTierOneOne:
379 case eSectionBeaconPrimaryTierOneTwo:
380 case eSectionBeaconPrimaryTierTwoOne:
381 case eSectionBeaconPrimaryTierTwoTwo:
382 case eSectionBeaconPrimaryTierThree:
383 case eSectionBeaconSecondaryOne:
384 {
385 int id = GetPowerButtonId(eSection);
386 int effectId = (id & 0xff);
387
388 desc = new vector<HtmlString>();
389
390 HtmlString string( app.GetString(MobEffect::effects[effectId]->getDescriptionId()), eHTMLColor_White );
391 desc->push_back( string );
392 }
393 break;
394 }
395 return desc;
396}
397
398bool IUIScene_BeaconMenu::IsVisible( ESceneSection eSection )
399{
400 switch( eSection )
401 {
402 case eSectionBeaconSecondaryTwo:
403 if(GetPowerButtonId(eSectionBeaconSecondaryTwo) == 0)
404 {
405 // This isn't visible
406 return false;
407 }
408 }
409 return true;
410}