MenuWidget_PDA_UserData.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_UserData::Update
  26. ========================
  27. */
  28. void idMenuWidget_PDA_UserData::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. if ( pdaIndex > player->GetInventory().pdas.Num() ) {
  41. return;
  42. }
  43. const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ];
  44. idSWFScriptObject * dataObj = GetSprite()->GetScriptObject();
  45. if ( dataObj != NULL && pda != NULL ) {
  46. idSWFTextInstance * txtName = dataObj->GetNestedText( "txtName" );
  47. idSWFTextInstance * txtId = dataObj->GetNestedText( "txtId" );
  48. idSWFTextInstance * txtLocation = dataObj->GetNestedText( "txtLocation" );
  49. idSWFTextInstance * txtRank = dataObj->GetNestedText( "txtRank" );
  50. idSWFTextInstance * txtClearance = dataObj->GetNestedText( "txtClearance" );
  51. idSWFTextInstance * txtLocHeading = dataObj->GetNestedText( "txtLocHeading" );
  52. if ( txtName != NULL ) {
  53. if ( pdaIndex == 0 ) {
  54. txtName->SetIgnoreColor( false );
  55. txtName->SetText( session->GetLocalUserName(0) );
  56. } else {
  57. txtName->SetIgnoreColor( false );
  58. txtName->SetText( pda->GetFullName() );
  59. }
  60. }
  61. if ( txtLocHeading != NULL ) {
  62. if ( pdaIndex == 0 ) {
  63. txtLocHeading->SetText( idLocalization::GetString( "#str_02516" ) ); // location
  64. } else {
  65. txtLocHeading->SetText( idLocalization::GetString( "#str_02515" ) ); // post
  66. }
  67. }
  68. if ( txtId != NULL ) {
  69. txtId->SetText( pda->GetID() );
  70. }
  71. if ( txtLocation != NULL ) {
  72. if ( pdaIndex == 0 ) {
  73. idLocationEntity *locationEntity = gameLocal.LocationForPoint( player->GetEyePosition() );
  74. if ( locationEntity ) {
  75. txtLocation->SetText( locationEntity->GetLocation() );
  76. } else {
  77. txtLocation->SetText( idLocalization::GetString( "#str_02911" ) );
  78. }
  79. } else {
  80. txtLocation->SetText( pda->GetPost() );
  81. }
  82. }
  83. if ( txtRank != NULL ) {
  84. txtRank->SetText( pda->GetTitle() );
  85. }
  86. if ( txtClearance != NULL ) {
  87. const char *security = pda->GetSecurity();
  88. if ( *security == NULL ) {
  89. txtClearance->SetText( idLocalization::GetString( "#str_00066" ) );
  90. } else {
  91. txtClearance->SetText( security );
  92. }
  93. }
  94. }
  95. }
  96. /*
  97. ========================
  98. idMenuWidget_Help::ObserveEvent
  99. ========================
  100. */
  101. void idMenuWidget_PDA_UserData::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
  102. const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
  103. if ( button == NULL ) {
  104. return;
  105. }
  106. const idMenuWidget * const listWidget = button->GetParent();
  107. if ( listWidget == NULL ) {
  108. return;
  109. }
  110. switch ( event.type ) {
  111. case WIDGET_EVENT_FOCUS_ON: {
  112. const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
  113. pdaIndex = list->GetViewIndex();
  114. if ( GetParent() != NULL && menuData != NULL && menuData->ActiveScreen() == PDA_AREA_USER_DATA ) {
  115. GetParent()->Update();
  116. } else {
  117. Update();
  118. }
  119. break;
  120. }
  121. case WIDGET_EVENT_FOCUS_OFF: {
  122. // Don't do anything when losing focus. Focus updates come in pairs, so we can
  123. // skip doing anything on the "lost focus" event, and instead do updates on the
  124. // "got focus" event.
  125. break;
  126. }
  127. case WIDGET_EVENT_ROLL_OVER: {
  128. const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
  129. pdaIndex = list->GetViewIndex();
  130. Update();
  131. break;
  132. }
  133. case WIDGET_EVENT_ROLL_OUT: {
  134. const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
  135. pdaIndex = list->GetViewIndex();
  136. Update();
  137. break;
  138. }
  139. }
  140. }