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 "XUI_HUD.h"
3#include "..\..\Minecraft.h"
4#include "..\..\Gui.h"
5#include "..\..\MultiplayerLocalPlayer.h"
6#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"
7#include "..\..\..\Minecraft.World\Random.h"
8#include "..\..\..\Minecraft.World\net.minecraft.world.effect.h"
9#include "..\..\..\Minecraft.World\net.minecraft.world.level.material.h"
10
11HRESULT CXuiSceneHud::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
12{
13 m_iPad = *(int *)pInitData->pvInitData;
14
15 MapChildControls();
16
17 XuiElementGetPosition(m_hObj,&m_OriginalPosition);
18
19 m_tickCount = 0;
20
21 return S_OK;
22}
23
24HRESULT CXuiSceneHud::OnCustomMessage_Splitscreenplayer(bool bJoining, BOOL& bHandled)
25{
26 bHandled=true;
27
28 app.ReloadHudScene(m_iPad, bJoining);
29
30 return S_OK;
31}
32
33HRESULT CXuiSceneHud::OnCustomMessage_TickScene()
34{
35 Minecraft *pMinecraft = Minecraft::GetInstance();
36 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return S_OK;
37
38 ++m_tickCount;
39
40 int iGuiScale;
41
42 if(pMinecraft->localplayers[m_iPad]->m_iScreenSection == C4JRender::VIEWPORT_TYPE_FULLSCREEN)
43 {
44 iGuiScale=app.GetGameSettings(m_iPad,eGameSetting_UISize);
45 }
46 else
47 {
48 iGuiScale=app.GetGameSettings(m_iPad,eGameSetting_UISizeSplitscreen);
49 }
50
51 int startFrame = 0;
52 switch(iGuiScale)
53 {
54 case 0:
55 XuiElementFindNamedFrame(m_hObj, L"ScaleSmall", &startFrame);
56 break;
57 case 1:
58 XuiElementFindNamedFrame(m_hObj, L"Normal", &startFrame);
59 break;
60 case 2:
61 XuiElementFindNamedFrame(m_hObj, L"ScaleLarge", &startFrame);
62 break;
63 }
64 if(startFrame >= 0) XuiElementPlayTimeline( m_hObj, startFrame, startFrame, startFrame, FALSE, TRUE);
65
66 // Move the whole hud group if we are not in fullscreen
67 if(pMinecraft->localplayers[m_iPad]->m_iScreenSection != C4JRender::VIEWPORT_TYPE_FULLSCREEN)
68 {
69 int iTooltipsYOffset = 0;
70 // if tooltips are off, set the y offset to zero
71 if(app.GetGameSettings(m_iPad,eGameSetting_Tooltips)==0)
72 {
73 switch(iGuiScale)
74 {
75 case 0:
76 iTooltipsYOffset=28;//screenHeight/10;
77 break;
78 case 2:
79 iTooltipsYOffset=28;//screenHeight/10;
80 break;
81 case 1:
82 default:
83 iTooltipsYOffset=28;//screenHeight/10;
84 break;
85 }
86 }
87
88 float fHeight, fWidth;
89 GetBounds(&fWidth, &fHeight);
90
91 int iSafezoneYHalf = 0;
92 switch(pMinecraft->localplayers[m_iPad]->m_iScreenSection)
93 {
94 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
95 break;
96 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
97 iSafezoneYHalf = -fHeight/10;// 5% (need to treat the whole screen is 2x this screen)
98 break;
99 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
100 iSafezoneYHalf = (fHeight/2)-(fHeight/10);// 5% (need to treat the whole screen is 2x this screen)
101 break;
102 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
103 iSafezoneYHalf = (fHeight/2)-(fHeight/10);// 5% (need to treat the whole screen is 2x this screen)
104 break;
105 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
106 break;
107 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
108 break;
109 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
110 iSafezoneYHalf = -fHeight/10; // 5% (the whole screen is 2x this screen)
111 break;
112 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
113 iSafezoneYHalf = -fHeight/10; // 5% (the whole screen is 2x this screen)
114 break;
115 };
116
117 D3DXVECTOR3 pos;
118 m_hudGroup.GetPosition(&pos);
119 pos.y = iTooltipsYOffset + iSafezoneYHalf;
120 m_hudGroup.SetPosition(&pos);
121 }
122
123 // Update inventory
124 float opacity = 1.0f;
125 GetOpacity(&opacity);
126 int selected = pMinecraft->localplayers[m_iPad]->inventory->selected;
127 for(unsigned int j = 0; j < 9; ++j)
128 {
129 m_hotbarIcon[j]->SetSlot(m_hotbarIcon[j]->m_hObj,pMinecraft->localplayers[m_iPad]->inventoryMenu->getSlot(InventoryMenu::USE_ROW_SLOT_START + j));
130 m_hotbarIcon[j]->SetUserIndex(m_hotbarIcon[j]->m_hObj, m_iPad );
131
132 if(j == selected)
133 {
134 m_hotbarIcon[j]->SetEnable(FALSE); //Makes the selected overlay display
135 }
136 else
137 {
138 m_hotbarIcon[j]->SetEnable(TRUE); //Hides the selected overlay display
139 }
140
141 m_hotbarIcon[j]->SetAlpha( m_hotbarIcon[j]->m_hObj, opacity );
142 }
143
144 // Update xp progress
145 if (pMinecraft->localgameModes[m_iPad]->canHurtPlayer())
146 {
147 int xpNeededForNextLevel = pMinecraft->localplayers[m_iPad]->getXpNeededForNextLevel();
148 int progress = (int)(pMinecraft->localplayers[m_iPad]->experienceProgress *xpNeededForNextLevel);
149
150 m_ExperienceProgress.SetShow(TRUE);
151 m_ExperienceProgress.SetRange(0,xpNeededForNextLevel);
152 m_ExperienceProgress.SetValue(progress);
153 }
154 else
155 {
156 m_ExperienceProgress.SetShow(FALSE);
157 }
158
159 // Update xp level
160 if (pMinecraft->localgameModes[m_iPad]->hasExperience() && pMinecraft->localplayers[m_iPad]->experienceLevel > 0)
161 {
162 m_xpLevel.SetShow(TRUE);
163
164 wchar_t formatted[10];
165 swprintf(formatted, 10, L"%d",pMinecraft->localplayers[m_iPad]->experienceLevel);
166
167 m_xpLevel.SetText(formatted);
168 }
169 else
170 {
171 m_xpLevel.SetShow(FALSE);
172 }
173
174 if (pMinecraft->localgameModes[m_iPad]->canHurtPlayer())
175 {
176 m_random.setSeed(m_tickCount * 312871);
177
178 // Update health
179 int heartOffsetIndex = -1;
180 if (pMinecraft->localplayers[m_iPad]->hasEffect(MobEffect::regeneration))
181 {
182 heartOffsetIndex = m_tickCount % 25;
183 }
184
185 bool blink = pMinecraft->localplayers[m_iPad]->invulnerableTime / 3 % 2 == 1;
186 if (pMinecraft->localplayers[m_iPad]->invulnerableTime < 10) blink = false;
187 int iHealth = pMinecraft->localplayers[m_iPad]->getHealth();
188 int iLastHealth = pMinecraft->localplayers[m_iPad]->lastHealth;
189 bool bHasPoison = pMinecraft->localplayers[m_iPad]->hasEffect(MobEffect::poison);
190 for (int icon = 0; icon < Player::MAX_HEALTH / 2; icon++)
191 {
192 if(blink)
193 {
194 if (icon * 2 + 1 < iLastHealth || icon * 2 + 1 < iHealth)
195 {
196 // Full
197 if(bHasPoison)
198 {
199 m_healthIcon[icon].PlayVisualRange(L"FullPoisonFlash",NULL,L"FullPoisonFlash");
200 }
201 else
202 {
203 m_healthIcon[icon].PlayVisualRange(L"FullFlash",NULL,L"FullFlash");
204 }
205 }
206 else if (icon * 2 + 1 == iLastHealth || icon * 2 + 1 == iHealth)
207 {
208 // Half
209 if(bHasPoison)
210 {
211 m_healthIcon[icon].PlayVisualRange(L"HalfPoisonFlash",NULL,L"HalfPoisonFlash");
212 }
213 else
214 {
215 m_healthIcon[icon].PlayVisualRange(L"HalfFlash",NULL,L"HalfFlash");
216 }
217 }
218 else
219 {
220 // Empty
221 m_healthIcon[icon].PlayVisualRange(L"NormalFlash",NULL,L"NormalFlash");
222 }
223 }
224 else
225 {
226 if (icon * 2 + 1 < iHealth)
227 {
228 // Full
229 if(bHasPoison)
230 {
231 m_healthIcon[icon].PlayVisualRange(L"FullPoison",NULL,L"FullPoison");
232 }
233 else
234 {
235 m_healthIcon[icon].PlayVisualRange(L"Full",NULL,L"Full");
236 }
237 }
238 else if (icon * 2 + 1 == iHealth)
239 {
240 // Half
241 if(bHasPoison)
242 {
243 m_healthIcon[icon].PlayVisualRange(L"HalfPoison",NULL,L"HalfPoison");
244 }
245 else
246 {
247 m_healthIcon[icon].PlayVisualRange(L"Half",NULL,L"Half");
248 }
249 }
250 else
251 {
252 // Empty
253 m_healthIcon[icon].PlayVisualRange(L"Normal",NULL,L"Normal");
254 }
255 }
256
257 float yo = 0;
258 if (iHealth <= 4)
259 {
260 yo = (float)m_random.nextInt(2) * (iGuiScale+1);
261 }
262 if (icon == heartOffsetIndex)
263 {
264 yo = -2.0f * (iGuiScale+1);
265 }
266
267 D3DXVECTOR3 pos;
268 m_healthIcon[icon].GetPosition(&pos);
269 // TODO - 4J Stu - This should be scaled based on gui scale and overall size (ie full, split or 480)
270 pos.y = yo;
271 m_healthIcon[icon].SetPosition(&pos);
272
273 }
274
275 // Update food
276 bool foodBlink = false;
277 FoodData *foodData = pMinecraft->localplayers[m_iPad]->getFoodData();
278 int food = foodData->getFoodLevel();
279 int oldFood = foodData->getLastFoodLevel();
280 bool hasHungerEffect = pMinecraft->localplayers[m_iPad]->hasEffect(MobEffect::hunger);
281 int saturationLevel = pMinecraft->localplayers[m_iPad]->getFoodData()->getSaturationLevel();
282 for (int icon = 0; icon < 10; icon++)
283 {
284 if(foodBlink)
285 {
286 if (icon * 2 + 1 < oldFood || icon * 2 + 1 < food)
287 {
288 // Full
289 if(hasHungerEffect)
290 {
291 m_foodIcon[icon].PlayVisualRange(L"FullPoisonFlash",NULL,L"FullPoisonFlash");
292 }
293 else
294 {
295 m_foodIcon[icon].PlayVisualRange(L"FullFlash",NULL,L"FullFlash");
296 }
297 }
298 else if (icon * 2 + 1 == oldFood || icon * 2 + 1 == food)
299 {
300 // Half
301 if(hasHungerEffect)
302 {
303 m_foodIcon[icon].PlayVisualRange(L"HalfPoisonFlash",NULL,L"HalfPoisonFlash");
304 }
305 else
306 {
307 m_foodIcon[icon].PlayVisualRange(L"HalfFlash",NULL,L"HalfFlash");
308 }
309 }
310 else
311 {
312 // Empty
313 m_foodIcon[icon].PlayVisualRange(L"NormalFlash",NULL,L"NormalFlash");
314 }
315 }
316 else
317 {
318 if (icon * 2 + 1 < food)
319 {
320 // Full
321 if(hasHungerEffect)
322 {
323 m_foodIcon[icon].PlayVisualRange(L"FullPoison",NULL,L"FullPoison");
324 }
325 else
326 {
327 m_foodIcon[icon].PlayVisualRange(L"Full",NULL,L"Full");
328 }
329 }
330 else if (icon * 2 + 1 == food)
331 {
332 // Half
333 if(hasHungerEffect)
334 {
335 m_foodIcon[icon].PlayVisualRange(L"HalfPoison",NULL,L"HalfPoison");
336 }
337 else
338 {
339 m_foodIcon[icon].PlayVisualRange(L"Half",NULL,L"Half");
340 }
341 }
342 else
343 {
344 // Empty
345 if(hasHungerEffect)
346 {
347 m_foodIcon[icon].PlayVisualRange(L"NormalPoison",NULL,L"NormalPoison");
348 }
349 else
350 {
351 m_foodIcon[icon].PlayVisualRange(L"Normal",NULL,L"Normal");
352 }
353 }
354 }
355
356
357 float yo = 0;
358 if (saturationLevel <= 0)
359 {
360 if ((m_tickCount % (food * 3 + 1)) == 0)
361 {
362 yo = (float)(m_random.nextInt(3) - 1) * (iGuiScale+1);
363 }
364 }
365
366 D3DXVECTOR3 pos;
367 m_foodIcon[icon].GetPosition(&pos);
368 // TODO - 4J Stu - This should be scaled based on gui scale and overall size (ie full, split or 480)
369 pos.y = yo;
370 m_foodIcon[icon].SetPosition(&pos);
371 }
372
373 // Update armour
374 int armor = pMinecraft->localplayers[m_iPad]->getArmorValue();
375 if(armor > 0)
376 {
377 m_armourGroup.SetShow(TRUE);
378 for (int icon = 0; icon < 10; icon++)
379 {
380 if (icon * 2 + 1 < armor) m_armourIcon[icon].PlayVisualRange(L"Full",NULL,L"Full");
381 else if (icon * 2 + 1 == armor) m_armourIcon[icon].PlayVisualRange(L"Half",NULL,L"Half");
382 else if (icon * 2 + 1 > armor) m_armourIcon[icon].PlayVisualRange(L"Normal",NULL,L"Normal");
383 }
384 }
385 else
386 {
387 m_armourGroup.SetShow(FALSE);
388 }
389
390 // Update air
391 if (pMinecraft->localplayers[m_iPad]->isUnderLiquid(Material::water))
392 {
393 m_airGroup.SetShow(TRUE);
394 int count = (int) ceil((pMinecraft->localplayers[m_iPad]->getAirSupply() - 2) * 10.0f / Player::TOTAL_AIR_SUPPLY);
395 int extra = (int) ceil((pMinecraft->localplayers[m_iPad]->getAirSupply()) * 10.0f / Player::TOTAL_AIR_SUPPLY) - count;
396 for (int icon = 0; icon < 10; icon++)
397 {
398 // Air bubbles
399 if (icon < count)
400 {
401 m_airIcon[icon].SetShow(TRUE);
402 m_airIcon[icon].PlayVisualRange(L"Bubble",NULL,L"Bubble");
403 }
404 else if(icon < count + extra)
405 {
406 m_airIcon[icon].SetShow(TRUE);
407 m_airIcon[icon].PlayVisualRange(L"Pop",NULL,L"Pop");
408 }
409 else m_airIcon[icon].SetShow(FALSE);
410 }
411 }
412 else
413 {
414 m_airGroup.SetShow(FALSE);
415 }
416 }
417 else
418 {
419 m_healthGroup.SetShow(FALSE);
420 m_foodGroup.SetShow(FALSE);
421 m_armourGroup.SetShow(FALSE);
422 m_airGroup.SetShow(FALSE);
423 }
424 return S_OK;
425}
426
427HRESULT CXuiSceneHud::OnCustomMessage_DLCInstalled()
428{
429 // mounted DLC may have changed
430 bool bPauseMenuDisplayed=false;
431 bool bInGame=(Minecraft::GetInstance()->level!=NULL);
432 // ignore this if we have menus up - they'll deal with it
433 for(int i=0;i<XUSER_MAX_COUNT;i++)
434 {
435 if(app.IsPauseMenuDisplayed(i))
436 {
437 bPauseMenuDisplayed=true;
438 break;
439 }
440 }
441
442 if(bInGame && !bPauseMenuDisplayed)
443 {
444 app.StartInstallDLCProcess(ProfileManager.GetPrimaryPad());
445 }
446
447 // this will send a CustomMessage_DLCMountingComplete when done
448 return S_OK;
449}
450
451
452HRESULT CXuiSceneHud::OnCustomMessage_DLCMountingComplete()
453{
454 // A join from invite may have installed the trial pack during the game.
455 // Need to switch to the texture pack if it's not being used yet, and turn off background downloads
456
457 // what texture pack are we using?
458 // TexturePack *tPack = Minecraft::GetInstance()->skins->getSelected();
459 // if(tPack->getDLCParentPackId()!=app.GetRequiredTexturePackID())
460 // {
461 // app.DebugPrintf("DLC install finished, and the game is using a texture pack that isn't the required one\n");
462 // }
463 return S_OK;
464}