MenuWidget_PDA_Objective.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../../idLib/precompiled.h"
  22. #include "../Game_local.h"
  23. /*
  24. ========================
  25. idMenuWidget_PDA_Objective::Update
  26. ========================
  27. */
  28. void idMenuWidget_PDA_Objective::Update() {
  29. if ( GetSWFObject() == NULL ) {
  30. return;
  31. }
  32. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  33. if ( !BindSprite( root ) || GetSprite() == NULL ) {
  34. return;
  35. }
  36. idPlayer * player = gameLocal.GetLocalPlayer();
  37. if ( player == NULL ) {
  38. return;
  39. }
  40. idSWFScriptObject * dataObj = GetSprite()->GetScriptObject()->GetNestedObj( "info" );
  41. idSWFSpriteInstance * dataSprite = dataObj->GetSprite();
  42. if ( dataObj != NULL && dataSprite != NULL ) {
  43. idSWFSpriteInstance * img = dataObj->GetNestedSprite( "objImg", "img" );
  44. if ( player->GetInventory().objectiveNames.Num() == 0 ) {
  45. dataSprite->StopFrame( 1 );
  46. } else {
  47. int numObjectives = player->GetInventory().objectiveNames.Num();
  48. int objStartIndex = 0;
  49. if ( numObjectives == 1 ) {
  50. dataSprite->StopFrame( 2 );
  51. objStartIndex = 0;
  52. } else {
  53. dataSprite->StopFrame( 3 );
  54. objStartIndex = 1;
  55. }
  56. idSWFTextInstance * txtDesc = dataObj->GetNestedText( "txtDesc" );
  57. int displayCount = 0;
  58. for ( int index = numObjectives - 1; displayCount < 2 && index >= 0; --index ) {
  59. if ( img != NULL ) {
  60. if ( player->GetInventory().objectiveNames[index].screenshot == NULL ) {
  61. img->SetVisible( false );
  62. } else {
  63. img->SetVisible( true );
  64. img->SetMaterial( player->GetInventory().objectiveNames[index].screenshot );
  65. }
  66. }
  67. idSWFSpriteInstance * objSel = dataObj->GetNestedSprite( va( "obj%d", objStartIndex - displayCount ), "sel" );
  68. idSWFTextInstance * txtNote = dataObj->GetNestedText( va( "obj%d", objStartIndex - displayCount ), "txtVal" );
  69. if ( objSel != NULL ) {
  70. if ( displayCount == 0 ) {
  71. objSel->SetVisible( true );
  72. } else {
  73. objSel->SetVisible( false );
  74. }
  75. }
  76. if ( txtNote != NULL ) {
  77. txtNote->SetText( player->GetInventory().objectiveNames[index].title.c_str() );
  78. }
  79. if ( displayCount == 0 ) {
  80. txtDesc->SetText( player->GetInventory().objectiveNames[index].text.c_str() );
  81. }
  82. displayCount++;
  83. }
  84. }
  85. // Set the main objective text
  86. idTarget_SetPrimaryObjective * mainObj = player->GetPrimaryObjective();
  87. idSWFTextInstance * txtMainObj = dataObj->GetNestedText( "txtObj" );
  88. if ( txtMainObj != NULL ) {
  89. if ( mainObj != NULL ) {
  90. txtMainObj->SetText( mainObj->spawnArgs.GetString( "text", idLocalization::GetString( "#str_04253" ) ) );
  91. } else {
  92. txtMainObj->SetText( idLocalization::GetString( "#str_02526" ) );
  93. }
  94. }
  95. }
  96. }
  97. /*
  98. ========================
  99. idMenuWidget_Help::ObserveEvent
  100. ========================
  101. */
  102. void idMenuWidget_PDA_Objective::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
  103. const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
  104. if ( button == NULL ) {
  105. return;
  106. }
  107. const idMenuWidget * const listWidget = button->GetParent();
  108. if ( listWidget == NULL ) {
  109. return;
  110. }
  111. switch ( event.type ) {
  112. case WIDGET_EVENT_FOCUS_ON: {
  113. const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
  114. if ( GetSprite() != NULL ) {
  115. if ( list->GetViewIndex() == 0 ) {
  116. GetSprite()->PlayFrame( "rollOn" );
  117. } else if ( pdaIndex == 0 && list->GetViewIndex() != 0 ) {
  118. GetSprite()->PlayFrame( "rollOff" );
  119. }
  120. }
  121. pdaIndex = list->GetViewIndex();
  122. Update();
  123. break;
  124. }
  125. }
  126. }