the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 264 lines 7.5 kB view raw
1#include "stdafx.h" 2#include "..\..\Minecraft.h" 3#include "..\..\MultiPlayerLocalPlayer.h" 4#include "..\..\..\Minecraft.World\net.minecraft.world.effect.h" 5#include "..\..\..\Minecraft.World\net.minecraft.world.item.h" 6#include "..\..\..\Minecraft.World\net.minecraft.world.entity.ai.attributes.h" 7#include "..\..\..\Minecraft.World\net.minecraft.world.entity.monster.h" 8#include "IUIScene_HUD.h" 9 10IUIScene_HUD::IUIScene_HUD() 11{ 12 m_lastActiveSlot = -1; 13 m_iGuiScale = -1; 14 m_bToolTipsVisible = true; 15 m_lastExpProgress = 0.0f; 16 m_lastExpLevel = 0; 17 m_iCurrentHealth = 0; 18 m_lastMaxHealth = 20; 19 m_lastHealthBlink = false; 20 m_lastHealthPoison = false; 21 m_iCurrentFood = -1; 22 m_lastFoodPoison = false; 23 m_lastAir = 10; 24 m_currentExtraAir = 0; 25 m_lastArmour = 0; 26 m_showHealth = true; 27 m_showHorseHealth = true; 28 m_showFood = true; 29 m_showAir = true; 30 m_showArmour = true; 31 m_showExpBar = true; 32 m_bRegenEffectEnabled = false; 33 m_iFoodSaturation = 0; 34 m_lastDragonHealth = 0.0f; 35 m_showDragonHealth = false; 36 m_ticksWithNoBoss = 0; 37 m_uiSelectedItemOpacityCountDown = 0; 38 m_displayName = L""; 39 m_lastShowDisplayName = true; 40 m_bRidingHorse = true; 41 m_horseHealth = 1; 42 m_lastHealthWither = true; 43 m_iCurrentHealthAbsorb = -1; 44 m_horseJumpProgress = 1.0f; 45 m_iHeartOffsetIndex = -1; 46 m_bHealthAbsorbActive = false; 47 m_iHorseMaxHealth = -1; 48 m_bIsJumpable = false; 49} 50 51void IUIScene_HUD::updateFrameTick() 52{ 53 int iPad = getPad(); 54 Minecraft *pMinecraft = Minecraft::GetInstance(); 55 56 int iGuiScale; 57 58 if(pMinecraft->localplayers[iPad]->m_iScreenSection == C4JRender::VIEWPORT_TYPE_FULLSCREEN) 59 { 60 iGuiScale=app.GetGameSettings(iPad,eGameSetting_UISize); 61 } 62 else 63 { 64 iGuiScale=app.GetGameSettings(iPad,eGameSetting_UISizeSplitscreen); 65 } 66 SetHudSize(iGuiScale); 67 68 SetDisplayName(ProfileManager.GetDisplayName(iPad)); 69 70 SetTooltipsEnabled(((ui.GetMenuDisplayed(ProfileManager.GetPrimaryPad())) || (app.GetGameSettings(ProfileManager.GetPrimaryPad(),eGameSetting_Tooltips) != 0))); 71 72 SetActiveSlot(pMinecraft->localplayers[iPad]->inventory->selected); 73 74 if (pMinecraft->localgameModes[iPad]->canHurtPlayer()) 75 { 76 renderPlayerHealth(); 77 } 78 else 79 { 80 //SetRidingHorse(false, 0); 81 shared_ptr<Entity> riding = pMinecraft->localplayers[iPad]->riding; 82 if(riding == NULL) 83 { 84 SetRidingHorse(false, false, 0); 85 } 86 else 87 { 88 SetRidingHorse(true, pMinecraft->localplayers[iPad]->isRidingJumpable(), 0); 89 } 90 ShowHorseHealth(false); 91 m_horseHealth = 0; 92 ShowHealth(false); 93 ShowFood(false); 94 ShowAir(false); 95 ShowArmour(false); 96 ShowExpBar(false); 97 SetHealthAbsorb(0); 98 } 99 100 if(pMinecraft->localplayers[iPad]->isRidingJumpable()) 101 { 102 SetHorseJumpBarProgress(pMinecraft->localplayers[iPad]->getJumpRidingScale()); 103 } 104 else if (pMinecraft->localgameModes[iPad]->hasExperience()) 105 { 106 // Update xp progress 107 ShowExpBar(true); 108 109 SetExpBarProgress(pMinecraft->localplayers[iPad]->experienceProgress, pMinecraft->localplayers[iPad]->getXpNeededForNextLevel()); 110 111 // Update xp level 112 SetExpLevel(pMinecraft->localplayers[iPad]->experienceLevel); 113 } 114 else 115 { 116 ShowExpBar(false); 117 SetExpLevel(0); 118 } 119 120 if(m_uiSelectedItemOpacityCountDown>0) 121 { 122 --m_uiSelectedItemOpacityCountDown; 123 124 // 4J Stu - Timing here is kept the same as on Xbox360, even though we do it differently now and do the fade out in Flash rather than directly setting opacity 125 if(m_uiSelectedItemOpacityCountDown < (SharedConstants::TICKS_PER_SECOND * 1) ) 126 { 127 HideSelectedLabel(); 128 m_uiSelectedItemOpacityCountDown = 0; 129 } 130 } 131 132 unsigned char ucAlpha=app.GetGameSettings(ProfileManager.GetPrimaryPad(),eGameSetting_InterfaceOpacity); 133 float fVal; 134 135 if(ucAlpha<80) 136 { 137 // if we are in a menu, set the minimum opacity for tooltips to 15% 138 if(ui.GetMenuDisplayed(iPad) && (ucAlpha<15)) 139 { 140 ucAlpha=15; 141 } 142 143 // check if we have the timer running for the opacity 144 unsigned int uiOpacityTimer=app.GetOpacityTimer(iPad); 145 if(uiOpacityTimer!=0) 146 { 147 if(uiOpacityTimer<10) 148 { 149 float fStep=(80.0f-(float)ucAlpha)/10.0f; 150 fVal=0.01f*(80.0f-((10.0f-(float)uiOpacityTimer)*fStep)); 151 } 152 else 153 { 154 fVal=0.01f*80.0f; 155 } 156 } 157 else 158 { 159 fVal=0.01f*(float)ucAlpha; 160 } 161 } 162 else 163 { 164 // if we are in a menu, set the minimum opacity for tooltips to 15% 165 if(ui.GetMenuDisplayed(iPad) && (ucAlpha<15)) 166 { 167 ucAlpha=15; 168 } 169 fVal=0.01f*(float)ucAlpha; 170 } 171 SetOpacity(fVal); 172 173 bool bDisplayGui=app.GetGameStarted() && !ui.GetMenuDisplayed(iPad) && !(app.GetXuiAction(iPad)==eAppAction_AutosaveSaveGameCapturedThumbnail) && app.GetGameSettings(iPad,eGameSetting_DisplayHUD)!=0; 174 if(bDisplayGui && pMinecraft->localplayers[iPad] != NULL) 175 { 176 SetVisible(true); 177 } 178 else 179 { 180 SetVisible(false); 181 } 182} 183 184void IUIScene_HUD::renderPlayerHealth() 185{ 186 Minecraft *pMinecraft = Minecraft::GetInstance(); 187 int iPad = getPad(); 188 189 ShowHealth(true); 190 191 SetRegenerationEffect(pMinecraft->localplayers[iPad]->hasEffect(MobEffect::regeneration)); 192 193 // Update health 194 bool blink = pMinecraft->localplayers[iPad]->invulnerableTime / 3 % 2 == 1; 195 if (pMinecraft->localplayers[iPad]->invulnerableTime < 10) blink = false; 196 int currentHealth = pMinecraft->localplayers[iPad]->getHealth(); 197 int oldHealth = pMinecraft->localplayers[iPad]->lastHealth; 198 bool bHasPoison = pMinecraft->localplayers[iPad]->hasEffect(MobEffect::poison); 199 bool bHasWither = pMinecraft->localplayers[iPad]->hasEffect(MobEffect::wither); 200 AttributeInstance *maxHealthAttribute = pMinecraft->localplayers[iPad]->getAttribute(SharedMonsterAttributes::MAX_HEALTH); 201 float maxHealth = (float)maxHealthAttribute->getValue(); 202 float totalAbsorption = pMinecraft->localplayers[iPad]->getAbsorptionAmount(); 203 204 // Update armour 205 int armor = pMinecraft->localplayers[iPad]->getArmorValue(); 206 207 SetHealth(currentHealth, oldHealth, blink, bHasPoison || bHasWither, bHasWither); 208 SetHealthAbsorb(totalAbsorption); 209 210 if(armor > 0) 211 { 212 ShowArmour(true); 213 SetArmour(armor); 214 } 215 else 216 { 217 ShowArmour(false); 218 } 219 220 shared_ptr<Entity> riding = pMinecraft->localplayers[iPad]->riding; 221 222 if(riding == NULL || riding && !riding->instanceof(eTYPE_LIVINGENTITY)) 223 { 224 SetRidingHorse(false, false, 0); 225 226 ShowFood(true); 227 ShowHorseHealth(false); 228 m_horseHealth = 0; 229 230 // Update food 231 //bool foodBlink = false; 232 FoodData *foodData = pMinecraft->localplayers[iPad]->getFoodData(); 233 int food = foodData->getFoodLevel(); 234 int oldFood = foodData->getLastFoodLevel(); 235 bool hasHungerEffect = pMinecraft->localplayers[iPad]->hasEffect(MobEffect::hunger); 236 int saturationLevel = pMinecraft->localplayers[iPad]->getFoodData()->getSaturationLevel(); 237 238 SetFood(food, oldFood, hasHungerEffect); 239 SetFoodSaturationLevel(saturationLevel); 240 241 // Update air 242 if (pMinecraft->localplayers[iPad]->isUnderLiquid(Material::water)) 243 { 244 ShowAir(true); 245 int count = (int) ceil((pMinecraft->localplayers[iPad]->getAirSupply() - 2) * 10.0f / Player::TOTAL_AIR_SUPPLY); 246 int extra = (int) ceil((pMinecraft->localplayers[iPad]->getAirSupply()) * 10.0f / Player::TOTAL_AIR_SUPPLY) - count; 247 SetAir(count, extra); 248 } 249 else 250 { 251 ShowAir(false); 252 } 253 } 254 else if(riding->instanceof(eTYPE_LIVINGENTITY) ) 255 { 256 shared_ptr<LivingEntity> living = dynamic_pointer_cast<LivingEntity>(riding); 257 int riderCurrentHealth = (int) ceil(living->getHealth()); 258 float maxRiderHealth = living->getMaxHealth(); 259 260 SetRidingHorse(true, pMinecraft->localplayers[iPad]->isRidingJumpable(), maxRiderHealth); 261 SetHorseHealth(riderCurrentHealth); 262 ShowHorseHealth(true); 263 } 264}