MenuWidget_PDA_AudioFiles.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. static const int MAX_AUDIO_ITEMS = 3;
  24. /*
  25. ========================
  26. idMenuWidget_PDA_AudioFiles::~idMenuWidget_PDA_AudioFiles
  27. ========================
  28. */
  29. idMenuWidget_PDA_AudioFiles::~idMenuWidget_PDA_AudioFiles() {
  30. }
  31. /*
  32. ========================
  33. idMenuWidget_PDA_AudioFiles::Initialize
  34. ========================
  35. */
  36. void idMenuWidget_PDA_AudioFiles::Initialize( idMenuHandler * data ) {
  37. idMenuWidget_DynamicList * pdaAudioList = new (TAG_SWF) idMenuWidget_DynamicList();
  38. pdaAudioList->SetSpritePath( GetSpritePath(), "info", "options" );
  39. pdaAudioList->SetNumVisibleOptions( MAX_AUDIO_ITEMS );
  40. pdaAudioList->SetWrappingAllowed( true );
  41. while ( pdaAudioList->GetChildren().Num() < MAX_AUDIO_ITEMS ) {
  42. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  43. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_SELECT_PDA_AUDIO, pdaAudioList->GetChildren().Num() );
  44. buttonWidget->Initialize( data );
  45. pdaAudioList->AddChild( buttonWidget );
  46. }
  47. pdaAudioList->Initialize( data );
  48. AddChild( pdaAudioList );
  49. }
  50. /*
  51. ========================
  52. idMenuWidget_PDA_AudioFiles::Update
  53. ========================
  54. */
  55. void idMenuWidget_PDA_AudioFiles::Update() {
  56. if ( GetSWFObject() == NULL ) {
  57. return;
  58. }
  59. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  60. if ( !BindSprite( root ) || GetSprite() == NULL ) {
  61. return;
  62. }
  63. idPlayer * player = gameLocal.GetLocalPlayer();
  64. if ( player == NULL ) {
  65. return;
  66. }
  67. if ( pdaIndex > player->GetInventory().pdas.Num() ) {
  68. return;
  69. }
  70. const idDeclPDA * pda = player->GetInventory().pdas[ pdaIndex ];
  71. idSWFScriptObject * dataObj = GetSprite()->GetScriptObject()->GetNestedObj( "info" );
  72. if ( dataObj != NULL && pda != NULL ) {
  73. idSWFTextInstance * txtOwner = dataObj->GetNestedText( "txtOwner" );
  74. if ( txtOwner != NULL ) {
  75. idStr ownerText = idLocalization::GetString( "#str_04203" );
  76. ownerText.Append( ": ");
  77. ownerText.Append( pda->GetFullName() );
  78. txtOwner->SetText( ownerText.c_str() );
  79. }
  80. idMenuWidget_DynamicList * const audioList = dynamic_cast< idMenuWidget_DynamicList * >( &GetChildByIndex( 0 ) );
  81. if ( audioList != NULL ) {
  82. audioFileNames.Clear();
  83. if ( pda->GetNumAudios() == 0 ) {
  84. idList< idStr > audioName;
  85. audioName.Append( idLocalization::GetString( "#str_04168" ) );
  86. audioList->GetChildByIndex( 0 ).SetState( WIDGET_STATE_DISABLED );
  87. audioFileNames.Append( audioName );
  88. } else {
  89. audioList->GetChildByIndex( 0 ).SetState( WIDGET_STATE_NORMAL );
  90. const idDeclAudio *aud = NULL;
  91. for ( int index = 0; index < pda->GetNumAudios(); ++index ) {
  92. idList< idStr > audioName;
  93. aud = pda->GetAudioByIndex( index );
  94. if ( aud != NULL ) {
  95. audioName.Append( aud->GetAudioName() );
  96. } else {
  97. audioName.Append( "" );
  98. }
  99. audioFileNames.Append( audioName );
  100. }
  101. }
  102. audioList->SetListData( audioFileNames );
  103. if ( audioList->BindSprite( root ) ) {
  104. audioList->Update();
  105. }
  106. }
  107. }
  108. //idSWFSpriteInstance * dataSprite = dataObj->GetSprite();
  109. }
  110. /*
  111. ========================
  112. idMenuWidget_PDA_AudioFiles::ObserveEvent
  113. ========================
  114. */
  115. void idMenuWidget_PDA_AudioFiles::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) {
  116. const idMenuWidget_Button * const button = dynamic_cast< const idMenuWidget_Button * >( &widget );
  117. if ( button == NULL ) {
  118. return;
  119. }
  120. const idMenuWidget * const listWidget = button->GetParent();
  121. if ( listWidget == NULL ) {
  122. return;
  123. }
  124. switch ( event.type ) {
  125. case WIDGET_EVENT_FOCUS_ON: {
  126. const idMenuWidget_DynamicList * const list = dynamic_cast< const idMenuWidget_DynamicList * const >( listWidget );
  127. if ( GetSprite() != NULL ) {
  128. if ( list->GetViewIndex() == 0 ) {
  129. GetSprite()->PlayFrame( "rollOff" );
  130. } else if ( ( pdaIndex == 0 || GetSprite()->GetCurrentFrame() <= 2 || GetSprite()->GetCurrentFrame() > GetSprite()->FindFrame( "idle" ) ) && list->GetViewIndex() != 0 ) {
  131. GetSprite()->PlayFrame( "rollOn" );
  132. }
  133. }
  134. pdaIndex = list->GetViewIndex();
  135. if ( GetParent() != NULL && menuData != NULL && menuData->ActiveScreen() == PDA_AREA_USER_DATA ) {
  136. GetParent()->Update();
  137. } else {
  138. Update();
  139. }
  140. idMenuWidget_DynamicList * const audioList = dynamic_cast< idMenuWidget_DynamicList * >( &GetChildByIndex( 0 ) );
  141. if ( audioList != NULL ) {
  142. audioList->SetFocusIndex( 0 );
  143. audioList->SetViewIndex( 0 );
  144. }
  145. break;
  146. }
  147. case WIDGET_EVENT_FOCUS_OFF: {
  148. idMenuWidget_DynamicList * const audioList = dynamic_cast< idMenuWidget_DynamicList * >( &GetChildByIndex( 0 ) );
  149. if ( audioList != NULL ) {
  150. audioList->SetFocusIndex( 0 );
  151. audioList->SetViewIndex( 0 );
  152. }
  153. Update();
  154. break;
  155. }
  156. }
  157. }