the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#ifdef _DEBUG_MENUS_ENABLED
4#include "UI.h"
5#include "UIScene_DebugOverlay.h"
6#include "..\..\Minecraft.h"
7#include "..\..\MinecraftServer.h"
8#include "..\..\GameRenderer.h"
9#include "..\..\MultiPlayerLevel.h"
10#include "ClientConnection.h"
11#include "MultiPlayerLocalPlayer.h"
12#include "..\..\..\Minecraft.World\StringHelpers.h"
13#include "..\..\..\Minecraft.World\net.minecraft.world.item.h"
14#include "..\..\..\Minecraft.World\net.minecraft.world.level.h"
15#include "..\..\..\Minecraft.World\net.minecraft.world.level.storage.h"
16#include "..\..\..\Minecraft.World\net.minecraft.commands.common.h"
17#include "..\..\..\Minecraft.World\net.minecraft.world.item.enchantment.h"
18
19UIScene_DebugOverlay::UIScene_DebugOverlay(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
20{
21 // Setup all the Iggy references we need for this scene
22 initialiseMovie();
23
24 Minecraft *pMinecraft = Minecraft::GetInstance();
25 WCHAR TempString[256];
26 swprintf( (WCHAR *)TempString, 256, L"Set fov (%d)", (int)pMinecraft->gameRenderer->GetFovVal());
27 m_sliderFov.init(TempString,eControl_FOV,0,100,(int)pMinecraft->gameRenderer->GetFovVal());
28
29 float currentTime = pMinecraft->level->getLevelData()->getGameTime() % 24000;
30 swprintf( (WCHAR *)TempString, 256, L"Set time (unsafe) (%d)", (int)currentTime);
31 m_sliderTime.init(TempString,eControl_Time,0,240,currentTime/100);
32
33 m_buttonRain.init(L"Toggle Rain",eControl_Rain);
34 m_buttonThunder.init(L"Toggle Thunder",eControl_Thunder);
35 m_buttonSchematic.init(L"Create Schematic",eControl_Schematic);
36 m_buttonResetTutorial.init(L"Reset profile tutorial progress",eControl_ResetTutorial);
37 m_buttonSetCamera.init(L"Set camera",eControl_SetCamera);
38 m_buttonSetDay.init(L"Set Day", eControl_SetDay);
39 m_buttonSetNight.init(L"Set Night", eControl_SetNight);
40
41 m_buttonListItems.init(eControl_Items);
42
43 int listId = 0;
44 for(unsigned int i = 0; i < Item::items.length; ++i)
45 {
46 if(Item::items[i] != NULL)
47 {
48 m_itemIds.push_back(i);
49 m_buttonListItems.addItem(app.GetString(Item::items[i]->getDescriptionId()), listId);
50 ++listId;
51 }
52 }
53
54 m_buttonListEnchantments.init(eControl_Enchantments);
55
56 for(unsigned int i = 0; i < Enchantment::validEnchantments.size(); ++i )
57 {
58 Enchantment *ench = Enchantment::validEnchantments.at(i);
59
60 for(unsigned int level = ench->getMinLevel(); level <= ench->getMaxLevel(); ++level)
61 {
62 m_enchantmentIdAndLevels.push_back(pair<int,int>(ench->id,level));
63 m_buttonListEnchantments.addItem(app.GetString( ench->getDescriptionId() ) + _toString<int>(level) );
64 }
65 }
66
67 m_buttonListMobs.init(eControl_Mobs);
68 m_buttonListMobs.addItem( L"Chicken" );
69 m_mobFactories.push_back(eTYPE_CHICKEN);
70 m_buttonListMobs.addItem( L"Cow" );
71 m_mobFactories.push_back(eTYPE_COW);
72 m_buttonListMobs.addItem( L"Pig" );
73 m_mobFactories.push_back(eTYPE_PIG);
74 m_buttonListMobs.addItem( L"Sheep" );
75 m_mobFactories.push_back(eTYPE_SHEEP);
76 m_buttonListMobs.addItem( L"Squid" );
77 m_mobFactories.push_back(eTYPE_SQUID);
78 m_buttonListMobs.addItem( L"Wolf" );
79 m_mobFactories.push_back(eTYPE_WOLF);
80 m_buttonListMobs.addItem( L"Creeper" );
81 m_mobFactories.push_back(eTYPE_CREEPER);
82 m_buttonListMobs.addItem( L"Ghast" );
83 m_mobFactories.push_back(eTYPE_GHAST);
84 m_buttonListMobs.addItem( L"Pig Zombie" );
85 m_mobFactories.push_back(eTYPE_PIGZOMBIE);
86 m_buttonListMobs.addItem( L"Skeleton" );
87 m_mobFactories.push_back(eTYPE_SKELETON);
88 m_buttonListMobs.addItem( L"Slime" );
89 m_mobFactories.push_back(eTYPE_SLIME);
90 m_buttonListMobs.addItem( L"Spider" );
91 m_mobFactories.push_back(eTYPE_SPIDER);
92 m_buttonListMobs.addItem( L"Zombie" );
93 m_mobFactories.push_back(eTYPE_ZOMBIE);
94 m_buttonListMobs.addItem( L"Enderman" );
95 m_mobFactories.push_back(eTYPE_ENDERMAN);
96 m_buttonListMobs.addItem( L"Silverfish" );
97 m_mobFactories.push_back(eTYPE_SILVERFISH);
98 m_buttonListMobs.addItem( L"Cave Spider" );
99 m_mobFactories.push_back(eTYPE_CAVESPIDER);
100 m_buttonListMobs.addItem( L"Mooshroom" );
101 m_mobFactories.push_back(eTYPE_MUSHROOMCOW);
102 m_buttonListMobs.addItem( L"Snow Golem" );
103 m_mobFactories.push_back(eTYPE_SNOWMAN);
104 m_buttonListMobs.addItem( L"Ender Dragon" );
105 m_mobFactories.push_back(eTYPE_ENDERDRAGON);
106 m_buttonListMobs.addItem( L"Blaze" );
107 m_mobFactories.push_back(eTYPE_BLAZE);
108 m_buttonListMobs.addItem( L"Magma Cube" );
109 m_mobFactories.push_back(eTYPE_LAVASLIME);
110}
111
112wstring UIScene_DebugOverlay::getMoviePath()
113{
114 return L"DebugMenu";
115}
116
117void UIScene_DebugOverlay::customDraw(IggyCustomDrawCallbackRegion *region)
118{
119 Minecraft *pMinecraft = Minecraft::GetInstance();
120 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return;
121
122 int itemId = -1;
123 swscanf((wchar_t*)region->name,L"item_%d",&itemId);
124 if (itemId == -1 || itemId > Item::ITEM_NUM_COUNT || Item::items[itemId] == NULL)
125 {
126 app.DebugPrintf("This is not the control we are looking for\n");
127 }
128 else
129 {
130 shared_ptr<ItemInstance> item = shared_ptr<ItemInstance>( new ItemInstance(itemId,1,0) );
131 if(item != NULL) customDrawSlotControl(region,m_iPad,item,1.0f,false,false);
132 }
133}
134
135void UIScene_DebugOverlay::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
136{
137 ui.AnimateKeyPress(iPad, key, repeat, pressed, released);
138
139 switch(key)
140 {
141 case ACTION_MENU_CANCEL:
142 if(pressed)
143 {
144 navigateBack();
145 }
146 break;
147 case ACTION_MENU_OK:
148 case ACTION_MENU_UP:
149 case ACTION_MENU_DOWN:
150 case ACTION_MENU_PAGEUP:
151 case ACTION_MENU_PAGEDOWN:
152 case ACTION_MENU_LEFT:
153 case ACTION_MENU_RIGHT:
154 if(pressed)
155 {
156 sendInputToMovie(key, repeat, pressed, released);
157 }
158 break;
159 }
160}
161
162void UIScene_DebugOverlay::handlePress(F64 controlId, F64 childId)
163{
164 switch((int)controlId)
165 {
166 case eControl_Items:
167 {
168 app.DebugPrintf("UIScene_DebugOverlay::handlePress for itemsList: %f\n", childId);
169 int id = childId;
170 //app.SetXuiServerAction(m_iPad, eXuiServerAction_DropItem, (void *)m_itemIds[id]);
171 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad());
172 conn->send( GiveItemCommand::preparePacket(dynamic_pointer_cast<Player>(Minecraft::GetInstance()->localplayers[ProfileManager.GetPrimaryPad()]), m_itemIds[id]) );
173 }
174 break;
175 case eControl_Mobs:
176 {
177 int id = childId;
178 if(id<m_mobFactories.size())
179 {
180 app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_SpawnMob,(void *)m_mobFactories[id]);
181 }
182 }
183 break;
184 case eControl_Enchantments:
185 {
186 int id = childId;
187 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad());
188 conn->send( EnchantItemCommand::preparePacket(dynamic_pointer_cast<Player>(Minecraft::GetInstance()->localplayers[ProfileManager.GetPrimaryPad()]), m_enchantmentIdAndLevels[id].first, m_enchantmentIdAndLevels[id].second) );
189 }
190 break;
191 case eControl_Schematic:
192 {
193#ifndef _CONTENT_PACKAGE
194 ui.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_DebugCreateSchematic,NULL,eUILayer_Debug);
195#endif
196 }
197 break;
198 case eControl_SetCamera:
199 {
200#ifndef _CONTENT_PACKAGE
201 ui.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_DebugSetCamera,NULL,eUILayer_Debug);
202#endif
203 }
204 break;
205 case eControl_Rain:
206 {
207 //app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_ToggleRain);
208 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad());
209 conn->send( ToggleDownfallCommand::preparePacket() );
210 }
211 break;
212 case eControl_Thunder:
213 app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_ToggleThunder);
214 break;
215 case eControl_ResetTutorial:
216 Tutorial::debugResetPlayerSavedProgress( ProfileManager.GetPrimaryPad() );
217 break;
218 case eControl_SetDay:
219 {
220 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad());
221 conn->send( TimeCommand::preparePacket(false) );
222 }
223 break;
224 case eControl_SetNight:
225 {
226 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad());
227 conn->send( TimeCommand::preparePacket(true) );
228 }
229 break;
230 };
231}
232
233void UIScene_DebugOverlay::handleSliderMove(F64 sliderId, F64 currentValue)
234{
235 switch((int)sliderId)
236 {
237 case eControl_Time:
238 {
239 Minecraft *pMinecraft = Minecraft::GetInstance();
240
241 // Need to set the time on both levels to stop the flickering as the local level
242 // tries to predict the time
243 // Only works if we are on the host machine, but shouldn't break if not
244 MinecraftServer::SetTime(currentValue * 100);
245 pMinecraft->level->getLevelData()->setGameTime(currentValue * 100);
246
247 WCHAR TempString[256];
248 float currentTime = currentValue * 100;
249 swprintf( (WCHAR *)TempString, 256, L"Set time (unsafe) (%d)", (int)currentTime);
250 m_sliderTime.setLabel(TempString);
251 }
252 break;
253 case eControl_FOV:
254 {
255 Minecraft *pMinecraft = Minecraft::GetInstance();
256 pMinecraft->gameRenderer->SetFovVal((float)currentValue);
257
258 WCHAR TempString[256];
259 swprintf( (WCHAR *)TempString, 256, L"Set fov (%d)", (int)currentValue);
260 m_sliderFov.setLabel(TempString);
261 }
262 break;
263 };
264}
265#endif