the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 871 lines 25 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIScene_HUD.h" 4#include "BossMobGuiInfo.h" 5#include "..\..\Minecraft.h" 6#include "..\..\MultiplayerLocalPlayer.h" 7#include "..\..\..\Minecraft.World\net.minecraft.world.entity.boss.enderdragon.h" 8#include "..\..\EnderDragonRenderer.h" 9#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h" 10#include "..\..\..\Minecraft.World\StringHelpers.h" 11 12UIScene_HUD::UIScene_HUD(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) 13{ 14 m_bSplitscreen = false; 15 16 // Setup all the Iggy references we need for this scene 17 initialiseMovie(); 18 19 SetDragonLabel( app.GetString( IDS_BOSS_ENDERDRAGON_HEALTH ) ); 20 SetSelectedLabel(L""); 21 22 for(unsigned int i = 0; i < CHAT_LINES_COUNT; ++i) 23 { 24 m_labelChatText[i].init(L""); 25 } 26 m_labelJukebox.init(L""); 27 28 addTimer(0, 100); 29} 30 31wstring UIScene_HUD::getMoviePath() 32{ 33 switch( m_parentLayer->getViewport() ) 34 { 35 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: 36 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM: 37 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT: 38 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT: 39 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT: 40 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT: 41 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT: 42 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT: 43 m_bSplitscreen = true; 44 return L"HUDSplit"; 45 break; 46 case C4JRender::VIEWPORT_TYPE_FULLSCREEN: 47 default: 48 m_bSplitscreen = false; 49 return L"HUD"; 50 break; 51 } 52} 53 54void UIScene_HUD::updateSafeZone() 55{ 56 // Distance from edge 57 F64 safeTop = 0.0; 58 F64 safeBottom = 0.0; 59 F64 safeLeft = 0.0; 60 F64 safeRight = 0.0; 61 62 switch( m_parentLayer->getViewport() ) 63 { 64 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: 65 safeTop = getSafeZoneHalfHeight(); 66 safeLeft = getSafeZoneHalfWidth(); 67 safeRight = getSafeZoneHalfWidth(); 68 break; 69 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM: 70 safeBottom = getSafeZoneHalfHeight(); 71 safeLeft = getSafeZoneHalfWidth(); 72 safeRight = getSafeZoneHalfWidth(); 73 break; 74 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT: 75 safeLeft = getSafeZoneHalfWidth(); 76 safeTop = getSafeZoneHalfHeight(); 77 safeBottom = getSafeZoneHalfHeight(); 78 break; 79 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT: 80 safeRight = getSafeZoneHalfWidth(); 81 safeTop = getSafeZoneHalfHeight(); 82 safeBottom = getSafeZoneHalfHeight(); 83 break; 84 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT: 85 safeTop = getSafeZoneHalfHeight(); 86 safeLeft = getSafeZoneHalfWidth(); 87 break; 88 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT: 89 safeTop = getSafeZoneHalfHeight(); 90 safeRight = getSafeZoneHalfWidth(); 91 break; 92 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT: 93 safeBottom = getSafeZoneHalfHeight(); 94 safeLeft = getSafeZoneHalfWidth(); 95 break; 96 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT: 97 safeBottom = getSafeZoneHalfHeight(); 98 safeRight = getSafeZoneHalfWidth(); 99 break; 100 case C4JRender::VIEWPORT_TYPE_FULLSCREEN: 101 default: 102 safeTop = getSafeZoneHalfHeight(); 103 safeBottom = getSafeZoneHalfHeight(); 104 safeLeft = getSafeZoneHalfWidth(); 105 safeRight = getSafeZoneHalfWidth(); 106 break; 107 } 108 setSafeZone(safeTop, safeBottom, safeLeft, safeRight); 109} 110 111void UIScene_HUD::tick() 112{ 113 UIScene::tick(); 114 if(getMovie() && app.GetGameStarted()) 115 { 116 Minecraft *pMinecraft = Minecraft::GetInstance(); 117 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) 118 { 119 return; 120 } 121 122 // Is boss present? 123 bool noBoss = BossMobGuiInfo::name.empty() || BossMobGuiInfo::displayTicks <= 0; 124 if (noBoss) 125 { 126 if (m_showDragonHealth) 127 { 128 // No boss and health is visible 129 if(m_ticksWithNoBoss <= 20) 130 { 131 ++m_ticksWithNoBoss; 132 } 133 else 134 { 135 ShowDragonHealth(false); 136 } 137 } 138 } 139 else 140 { 141 BossMobGuiInfo::displayTicks--; 142 143 m_ticksWithNoBoss = 0; 144 SetDragonHealth(BossMobGuiInfo::healthProgress); 145 146 if (!m_showDragonHealth) 147 { 148 SetDragonLabel(BossMobGuiInfo::name); 149 ShowDragonHealth(true); 150 } 151 } 152 } 153} 154 155void UIScene_HUD::customDraw(IggyCustomDrawCallbackRegion *region) 156{ 157 Minecraft *pMinecraft = Minecraft::GetInstance(); 158 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return; 159 160 int slot = -1; 161 swscanf((wchar_t*)region->name,L"slot_%d",&slot); 162 if (slot == -1) 163 { 164 app.DebugPrintf("This is not the control we are looking for\n"); 165 } 166 else 167 { 168 Slot *invSlot = pMinecraft->localplayers[m_iPad]->inventoryMenu->getSlot(InventoryMenu::USE_ROW_SLOT_START + slot); 169 shared_ptr<ItemInstance> item = invSlot->getItem(); 170 if(item != NULL) 171 { 172 unsigned char ucAlpha=app.GetGameSettings(ProfileManager.GetPrimaryPad(),eGameSetting_InterfaceOpacity); 173 float fVal; 174 175 if(ucAlpha<80) 176 { 177 // check if we have the timer running for the opacity 178 unsigned int uiOpacityTimer=app.GetOpacityTimer(m_iPad); 179 if(uiOpacityTimer!=0) 180 { 181 if(uiOpacityTimer<10) 182 { 183 float fStep=(80.0f-(float)ucAlpha)/10.0f; 184 fVal=0.01f*(80.0f-((10.0f-(float)uiOpacityTimer)*fStep)); 185 } 186 else 187 { 188 fVal=0.01f*80.0f; 189 } 190 } 191 else 192 { 193 fVal=0.01f*(float)ucAlpha; 194 } 195 } 196 else 197 { 198 fVal=0.01f*(float)ucAlpha; 199 } 200 customDrawSlotControl(region,m_iPad,item,fVal,item->isFoil(),true); 201 } 202 } 203} 204 205void UIScene_HUD::handleReload() 206{ 207 m_lastActiveSlot = -1; 208 m_iGuiScale = -1; 209 m_bToolTipsVisible = true; 210 m_lastExpProgress = 0.0f; 211 m_lastExpLevel = 0; 212 m_iCurrentHealth = 0; 213 m_lastMaxHealth = 20; 214 m_lastHealthBlink = false; 215 m_lastHealthPoison = false; 216 m_iCurrentFood = -1; 217 m_lastFoodPoison = false; 218 m_lastAir = 10; 219 m_currentExtraAir = 0; 220 m_lastArmour = 0; 221 m_showHealth = true; 222 m_showHorseHealth = true; 223 m_showFood = true; 224 m_showAir = false; // get's initialised invisible anyways, by setting it to false we ensure it will remain visible when switching in and out of split screen! 225 m_showArmour = true; 226 m_showExpBar = true; 227 m_bRegenEffectEnabled = false; 228 m_iFoodSaturation = 0; 229 m_lastDragonHealth = 0.0f; 230 m_showDragonHealth = false; 231 m_ticksWithNoBoss = 0; 232 m_uiSelectedItemOpacityCountDown = 0; 233 m_displayName = L""; 234 m_lastShowDisplayName = true; 235 m_bRidingHorse = true; 236 m_horseHealth = 1; 237 m_lastHealthWither = true; 238 m_iCurrentHealthAbsorb = -1; 239 m_horseJumpProgress = 1.0f; 240 m_iHeartOffsetIndex = -1; 241 m_bHealthAbsorbActive = false; 242 m_iHorseMaxHealth = -1; 243 244 m_labelDisplayName.setVisible(m_lastShowDisplayName); 245 246 SetDragonLabel(BossMobGuiInfo::name); 247 SetSelectedLabel(L""); 248 249 for(unsigned int i = 0; i < CHAT_LINES_COUNT; ++i) 250 { 251 m_labelChatText[i].init(L""); 252 } 253 m_labelJukebox.init(L""); 254 255 int iGuiScale; 256 Minecraft *pMinecraft = Minecraft::GetInstance(); 257 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localplayers[m_iPad]->m_iScreenSection == C4JRender::VIEWPORT_TYPE_FULLSCREEN) 258 { 259 iGuiScale=app.GetGameSettings(m_iPad,eGameSetting_UISize); 260 } 261 else 262 { 263 iGuiScale=app.GetGameSettings(m_iPad,eGameSetting_UISizeSplitscreen); 264 } 265 SetHudSize(iGuiScale); 266 267 SetDisplayName(ProfileManager.GetDisplayName(m_iPad)); 268 269 repositionHud(); 270 271 SetTooltipsEnabled(((ui.GetMenuDisplayed(ProfileManager.GetPrimaryPad())) || (app.GetGameSettings(ProfileManager.GetPrimaryPad(),eGameSetting_Tooltips) != 0))); 272} 273 274int UIScene_HUD::getPad() 275{ 276 return m_iPad; 277} 278 279void UIScene_HUD::SetOpacity(float opacity) 280{ 281 setOpacity(opacity); 282} 283 284void UIScene_HUD::SetVisible(bool visible) 285{ 286 setVisible(visible); 287} 288 289void UIScene_HUD::SetHudSize(int scale) 290{ 291 if(scale != m_iGuiScale) 292 { 293 m_iGuiScale = scale; 294 295 IggyDataValue result; 296 IggyDataValue value[1]; 297 value[0].type = IGGY_DATATYPE_number; 298 value[0].number = scale; 299 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcLoadHud , 1 , value ); 300 } 301} 302 303void UIScene_HUD::SetExpBarProgress(float progress, int xpNeededForNextLevel) 304{ 305 if(progress != m_lastExpProgress) 306 { 307 m_lastExpProgress = progress; 308 309 IggyDataValue result; 310 IggyDataValue value[1]; 311 value[0].type = IGGY_DATATYPE_number; 312 value[0].number = progress; 313 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetExpBarProgress , 1 , value ); 314 } 315} 316 317void UIScene_HUD::SetExpLevel(int level) 318{ 319 if(level != m_lastExpLevel) 320 { 321 m_lastExpLevel = level; 322 323 IggyDataValue result; 324 IggyDataValue value[1]; 325 value[0].type = IGGY_DATATYPE_number; 326 value[0].number = level; 327 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetPlayerLevel , 1 , value ); 328 } 329} 330 331void UIScene_HUD::SetActiveSlot(int slot) 332{ 333 if(slot != m_lastActiveSlot) 334 { 335 m_lastActiveSlot = slot; 336 337 IggyDataValue result; 338 IggyDataValue value[1]; 339 value[0].type = IGGY_DATATYPE_number; 340 value[0].number = slot; 341 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetActiveSlot , 1 , value ); 342 } 343} 344 345void UIScene_HUD::SetHealth(int iHealth, int iLastHealth, bool bBlink, bool bPoison, bool bWither) 346{ 347 int maxHealth = max(iHealth, iLastHealth); 348 if(maxHealth != m_lastMaxHealth || bBlink != m_lastHealthBlink || bPoison != m_lastHealthPoison || bWither != m_lastHealthWither) 349 { 350 m_lastMaxHealth = maxHealth; 351 m_lastHealthBlink = bBlink; 352 m_lastHealthPoison = bPoison; 353 m_lastHealthWither = bWither; 354 355 IggyDataValue result; 356 IggyDataValue value[4]; 357 value[0].type = IGGY_DATATYPE_number; 358 value[0].number = maxHealth; 359 value[1].type = IGGY_DATATYPE_boolean; 360 value[1].boolval = bBlink; 361 value[2].type = IGGY_DATATYPE_boolean; 362 value[2].boolval = bPoison; 363 value[3].type = IGGY_DATATYPE_boolean; 364 value[3].boolval = bWither; 365 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetHealth , 4 , value ); 366 } 367} 368 369void UIScene_HUD::SetFood(int iFood, int iLastFood, bool bPoison) 370{ 371 // Ignore iLastFood as food doesn't flash 372 int maxFood = iFood; //, iLastFood); 373 if(maxFood != m_iCurrentFood || bPoison != m_lastFoodPoison) 374 { 375 m_iCurrentFood = maxFood; 376 m_lastFoodPoison = bPoison; 377 378 IggyDataValue result; 379 IggyDataValue value[2]; 380 value[0].type = IGGY_DATATYPE_number; 381 value[0].number = maxFood; 382 value[1].type = IGGY_DATATYPE_boolean; 383 value[1].boolval = bPoison; 384 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetFood , 2 , value ); 385 } 386} 387 388void UIScene_HUD::SetAir(int iAir, int extra) 389{ 390 if(iAir != m_lastAir) 391 { 392 app.DebugPrintf("SetAir to %d\n", iAir); 393 m_lastAir = iAir; 394 395 IggyDataValue result; 396 IggyDataValue value[1]; 397 value[0].type = IGGY_DATATYPE_number; 398 value[0].number = iAir; 399 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetAir , 1 , value ); 400 } 401} 402 403void UIScene_HUD::SetArmour(int iArmour) 404{ 405 if(iArmour != m_lastArmour) 406 { 407 app.DebugPrintf("SetArmour to %d\n", iArmour); 408 m_lastArmour = iArmour; 409 410 IggyDataValue result; 411 IggyDataValue value[1]; 412 value[0].type = IGGY_DATATYPE_number; 413 value[0].number = iArmour; 414 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetArmour , 1 , value ); 415 } 416} 417 418void UIScene_HUD::ShowHealth(bool show) 419{ 420 if(show != m_showHealth) 421 { 422 app.DebugPrintf("ShowHealth to %s\n", show?"TRUE":"FALSE"); 423 m_showHealth = show; 424 425 IggyDataValue result; 426 IggyDataValue value[1]; 427 value[0].type = IGGY_DATATYPE_boolean; 428 value[0].boolval = show; 429 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowHealth , 1 , value ); 430 } 431} 432 433void UIScene_HUD::ShowHorseHealth(bool show) 434{ 435 if(show != m_showHorseHealth) 436 { 437 app.DebugPrintf("ShowHorseHealth to %s\n", show?"TRUE":"FALSE"); 438 m_showHorseHealth = show; 439 440 IggyDataValue result; 441 IggyDataValue value[1]; 442 value[0].type = IGGY_DATATYPE_boolean; 443 value[0].boolval = show; 444 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowHorseHealth , 1 , value ); 445 } 446} 447 448void UIScene_HUD::ShowFood(bool show) 449{ 450 if(show != m_showFood) 451 { 452 app.DebugPrintf("ShowFood to %s\n", show?"TRUE":"FALSE"); 453 m_showFood = show; 454 455 IggyDataValue result; 456 IggyDataValue value[1]; 457 value[0].type = IGGY_DATATYPE_boolean; 458 value[0].boolval = show; 459 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowFood , 1 , value ); 460 } 461} 462 463void UIScene_HUD::ShowAir(bool show) 464{ 465 if(show != m_showAir) 466 { 467 app.DebugPrintf("ShowAir to %s\n", show?"TRUE":"FALSE"); 468 m_showAir = show; 469 470 IggyDataValue result; 471 IggyDataValue value[1]; 472 value[0].type = IGGY_DATATYPE_boolean; 473 value[0].boolval = show; 474 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowAir , 1 , value ); 475 } 476} 477 478void UIScene_HUD::ShowArmour(bool show) 479{ 480 if(show != m_showArmour) 481 { 482 app.DebugPrintf("ShowArmour to %s\n", show?"TRUE":"FALSE"); 483 m_showArmour = show; 484 485 IggyDataValue result; 486 IggyDataValue value[1]; 487 value[0].type = IGGY_DATATYPE_boolean; 488 value[0].boolval = show; 489 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowArmour , 1 , value ); 490 } 491} 492 493void UIScene_HUD::ShowExpBar(bool show) 494{ 495 if(show != m_showExpBar) 496 { 497 app.DebugPrintf("ShowExpBar to %s\n", show?"TRUE":"FALSE"); 498 m_showExpBar = show; 499 500 IggyDataValue result; 501 IggyDataValue value[1]; 502 value[0].type = IGGY_DATATYPE_boolean; 503 value[0].boolval = show; 504 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowExpbar , 1 , value ); 505 } 506} 507 508void UIScene_HUD::SetRegenerationEffect(bool bEnabled) 509{ 510 if(bEnabled != m_bRegenEffectEnabled) 511 { 512 app.DebugPrintf("SetRegenerationEffect to %s\n", bEnabled?"TRUE":"FALSE"); 513 m_bRegenEffectEnabled = bEnabled; 514 515 IggyDataValue result; 516 IggyDataValue value[1]; 517 value[0].type = IGGY_DATATYPE_boolean; 518 value[0].boolval = bEnabled; 519 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetRegenerationEffect , 1 , value ); 520 } 521} 522 523void UIScene_HUD::SetFoodSaturationLevel(int iSaturation) 524{ 525 if(iSaturation != m_iFoodSaturation) 526 { 527 app.DebugPrintf("Set saturation to %d\n", iSaturation); 528 m_iFoodSaturation = iSaturation; 529 530 IggyDataValue result; 531 IggyDataValue value[1]; 532 value[0].type = IGGY_DATATYPE_number; 533 value[0].number = iSaturation; 534 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetFoodSaturationLevel , 1 , value ); 535 } 536} 537 538void UIScene_HUD::SetDragonHealth(float health) 539{ 540 if(health != m_lastDragonHealth) 541 { 542 app.DebugPrintf("Set dragon health to %f\n", health); 543 m_lastDragonHealth = health; 544 545 IggyDataValue result; 546 IggyDataValue value[1]; 547 value[0].type = IGGY_DATATYPE_number; 548 value[0].number = health; 549 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetDragonHealth , 1 , value ); 550 } 551} 552 553void UIScene_HUD::SetDragonLabel(const wstring &label) 554{ 555 IggyDataValue result; 556 IggyDataValue value[1]; 557 IggyStringUTF16 stringVal; 558 stringVal.string = (IggyUTF16*)label.c_str(); 559 stringVal.length = label.length(); 560 value[0].type = IGGY_DATATYPE_string_UTF16; 561 value[0].string16 = stringVal; 562 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetDragonLabel , 1 , value ); 563} 564 565void UIScene_HUD::ShowDragonHealth(bool show) 566{ 567 if(show != m_showDragonHealth) 568 { 569 app.DebugPrintf("ShowDragonHealth to %s\n", show?"TRUE":"FALSE"); 570 m_showDragonHealth = show; 571 572 IggyDataValue result; 573 IggyDataValue value[1]; 574 value[0].type = IGGY_DATATYPE_boolean; 575 value[0].boolval = show; 576 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowDragonHealth , 1 , value ); 577 } 578} 579 580void UIScene_HUD::SetSelectedLabel(const wstring &label) 581{ 582 // 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 583 if(!label.empty()) m_uiSelectedItemOpacityCountDown = SharedConstants::TICKS_PER_SECOND * 3; 584 585 IggyDataValue result; 586 IggyDataValue value[1]; 587 IggyStringUTF16 stringVal; 588 stringVal.string = (IggyUTF16*)label.c_str(); 589 stringVal.length = label.length(); 590 value[0].type = IGGY_DATATYPE_string_UTF16; 591 value[0].string16 = stringVal; 592 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetSelectedLabel , 1 , value ); 593} 594 595void UIScene_HUD::HideSelectedLabel() 596{ 597 IggyDataValue result; 598 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcHideSelectedLabel , 0 , NULL ); 599} 600 601 602void UIScene_HUD::SetRidingHorse(bool ridingHorse, bool bIsJumpable, int maxHorseHealth) 603{ 604 if(m_bRidingHorse != ridingHorse || maxHorseHealth != m_iHorseMaxHealth) 605 { 606 app.DebugPrintf("SetRidingHorse to %s\n", ridingHorse?"TRUE":"FALSE"); 607 m_bRidingHorse = ridingHorse; 608 m_bIsJumpable = bIsJumpable; 609 m_iHorseMaxHealth = maxHorseHealth; 610 611 IggyDataValue result; 612 IggyDataValue value[3]; 613 value[0].type = IGGY_DATATYPE_boolean; 614 value[0].boolval = ridingHorse; 615 value[1].type = IGGY_DATATYPE_boolean; 616 value[1].boolval = bIsJumpable; 617 value[2].type = IGGY_DATATYPE_number; 618 value[2].number = maxHorseHealth; 619 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetRidingHorse , 3 , value ); 620 } 621} 622 623void UIScene_HUD::SetHorseHealth(int health, bool blink /*= false*/) 624{ 625 if(m_bRidingHorse && m_horseHealth != health) 626 { 627 app.DebugPrintf("SetHorseHealth to %d\n", health); 628 m_horseHealth = health; 629 630 IggyDataValue result; 631 IggyDataValue value[2]; 632 value[0].type = IGGY_DATATYPE_number; 633 value[0].number = health; 634 value[1].type = IGGY_DATATYPE_boolean; 635 value[1].boolval = blink; 636 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetHorseHealth , 2 , value ); 637 } 638} 639 640void UIScene_HUD::SetHorseJumpBarProgress(float progress) 641{ 642 if(m_bRidingHorse && m_horseJumpProgress != progress) 643 { 644 app.DebugPrintf("SetHorseJumpBarProgress to %f\n", progress); 645 m_horseJumpProgress = progress; 646 647 IggyDataValue result; 648 IggyDataValue value[1]; 649 value[0].type = IGGY_DATATYPE_number; 650 value[0].number = progress; 651 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetHorseJumpBarProgress , 1 , value ); 652 } 653} 654 655void UIScene_HUD::SetHealthAbsorb(int healthAbsorb) 656{ 657 if(m_iCurrentHealthAbsorb != healthAbsorb) 658 { 659 app.DebugPrintf("SetHealthAbsorb to %d\n", healthAbsorb); 660 m_iCurrentHealthAbsorb = healthAbsorb; 661 662 IggyDataValue result; 663 IggyDataValue value[2]; 664 value[0].type = IGGY_DATATYPE_boolean; 665 value[0].boolval = healthAbsorb > 0; 666 value[1].type = IGGY_DATATYPE_number; 667 value[1].number = healthAbsorb; 668 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetHealthAbsorb , 2 , value ); 669 } 670} 671 672void UIScene_HUD::render(S32 width, S32 height, C4JRender::eViewportType viewport) 673{ 674 if(m_bSplitscreen) 675 { 676 S32 xPos = 0; 677 S32 yPos = 0; 678 switch( viewport ) 679 { 680 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM: 681 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT: 682 yPos = (S32)(ui.getScreenHeight() / 2); 683 break; 684 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT: 685 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT: 686 xPos = (S32)(ui.getScreenWidth() / 2); 687 break; 688 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT: 689 xPos = (S32)(ui.getScreenWidth() / 2); 690 yPos = (S32)(ui.getScreenHeight() / 2); 691 break; 692 } 693 ui.setupRenderPosition(xPos, yPos); 694 695 S32 tileXStart = 0; 696 S32 tileYStart = 0; 697 S32 tileWidth = width; 698 S32 tileHeight = height; 699 700 switch( viewport ) 701 { 702 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT: 703 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT: 704 tileHeight = (S32)(ui.getScreenHeight()); 705 break; 706 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: 707 tileWidth = (S32)(ui.getScreenWidth()); 708 tileYStart = (S32)(m_movieHeight / 2); 709 break; 710 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM: 711 tileWidth = (S32)(ui.getScreenWidth()); 712 tileYStart = (S32)(m_movieHeight / 2); 713 break; 714 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT: 715 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT: 716 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT: 717 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT: 718 tileYStart = (S32)(m_movieHeight / 2); 719 break; 720 } 721 722 IggyPlayerSetDisplaySize( getMovie(), m_movieWidth, m_movieHeight ); 723 724 m_renderWidth = tileWidth; 725 m_renderHeight = tileHeight; 726 727 IggyPlayerDrawTilesStart ( getMovie() ); 728 IggyPlayerDrawTile ( getMovie() , 729 tileXStart , 730 tileYStart , 731 tileXStart + tileWidth , 732 tileYStart + tileHeight , 733 0 ); 734 IggyPlayerDrawTilesEnd ( getMovie() ); 735 } 736 else 737 { 738 UIScene::render(width, height, viewport); 739 } 740} 741 742void UIScene_HUD::handleTimerComplete(int id) 743{ 744 Minecraft *pMinecraft = Minecraft::GetInstance(); 745 746 bool anyVisible = false; 747 if(pMinecraft->localplayers[m_iPad]!= NULL) 748 { 749 Gui *pGui = pMinecraft->gui; 750 //DWORD messagesToDisplay = min( CHAT_LINES_COUNT, pGui->getMessagesCount(m_iPad) ); 751 for( unsigned int i = 0; i < CHAT_LINES_COUNT; ++i ) 752 { 753 float opacity = pGui->getOpacity(m_iPad, i); 754 if( opacity > 0 ) 755 { 756 m_controlLabelBackground[i].setOpacity(opacity); 757 m_labelChatText[i].setOpacity(opacity); 758 m_labelChatText[i].setLabel( pGui->getMessagesCount(m_iPad) ? pGui->getMessage(m_iPad,i) : L"" ); 759 760 anyVisible = true; 761 } 762 else 763 { 764 m_controlLabelBackground[i].setOpacity(0); 765 m_labelChatText[i].setOpacity(0); 766 m_labelChatText[i].setLabel(L""); 767 } 768 } 769 if(pGui->getJukeboxOpacity(m_iPad) > 0) anyVisible = true; 770 m_labelJukebox.setOpacity( pGui->getJukeboxOpacity(m_iPad) ); 771 m_labelJukebox.setLabel( pGui->getJukeboxMessage(m_iPad) ); 772 } 773 else 774 { 775 for( unsigned int i = 0; i < CHAT_LINES_COUNT; ++i ) 776 { 777 m_controlLabelBackground[i].setOpacity(0); 778 m_labelChatText[i].setOpacity(0); 779 m_labelChatText[i].setLabel(L""); 780 } 781 m_labelJukebox.setOpacity( 0 ); 782 } 783 784 //setVisible(anyVisible); 785} 786 787void UIScene_HUD::repositionHud() 788{ 789 if(!m_bSplitscreen) return; 790 791 S32 width = 0; 792 S32 height = 0; 793 m_parentLayer->getRenderDimensions( width, height ); 794 795 switch( m_parentLayer->getViewport() ) 796 { 797 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT: 798 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT: 799 height = (S32)(ui.getScreenHeight()); 800 break; 801 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: 802 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM: 803 width = (S32)(ui.getScreenWidth()); 804 break; 805 } 806 807 app.DebugPrintf(app.USER_SR, "Reposition HUD with dims %d, %d\n", width, height ); 808 809 IggyDataValue result; 810 IggyDataValue value[2]; 811 value[0].type = IGGY_DATATYPE_number; 812 value[0].number = width; 813 value[1].type = IGGY_DATATYPE_number; 814 value[1].number = height; 815 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcRepositionHud , 2 , value ); 816} 817 818void UIScene_HUD::ShowDisplayName(bool show) 819{ 820 m_lastShowDisplayName = show; 821 m_labelDisplayName.setVisible(show); 822} 823 824void UIScene_HUD::SetDisplayName(const wstring &displayName) 825{ 826 if(displayName.compare(m_displayName) != 0) 827 { 828 m_displayName = displayName; 829 830 IggyDataValue result; 831 IggyDataValue value[1]; 832 IggyStringUTF16 stringVal; 833 stringVal.string = (IggyUTF16*)displayName.c_str(); 834 stringVal.length = displayName.length(); 835 value[0].type = IGGY_DATATYPE_string_UTF16; 836 value[0].string16 = stringVal; 837 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetDisplayName , 1 , value ); 838 839 m_labelDisplayName.setVisible(m_lastShowDisplayName); 840 } 841} 842 843void UIScene_HUD::SetTooltipsEnabled(bool bEnabled) 844{ 845 if(m_bToolTipsVisible != bEnabled) 846 { 847 m_bToolTipsVisible = bEnabled; 848 849 IggyDataValue result; 850 IggyDataValue value[1]; 851 value[0].type = IGGY_DATATYPE_boolean; 852 value[0].boolval = bEnabled; 853 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetTooltipsEnabled , 1 , value ); 854 } 855} 856 857void UIScene_HUD::handleGameTick() 858{ 859 if(getMovie() && app.GetGameStarted()) 860 { 861 Minecraft *pMinecraft = Minecraft::GetInstance(); 862 if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) 863 { 864 m_parentLayer->showComponent(m_iPad, eUIScene_HUD,false); 865 return; 866 } 867 m_parentLayer->showComponent(m_iPad, eUIScene_HUD,true); 868 869 updateFrameTick(); 870 } 871}