MenuScreen_PDA_VideoDisks.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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_VIDEO_ITEMS = 5;
  24. /*
  25. ========================
  26. idMenuScreen_PDA_VideoDisks::Initialize
  27. ========================
  28. */
  29. void idMenuScreen_PDA_VideoDisks::Initialize( idMenuHandler * data ) {
  30. if ( data != NULL ) {
  31. menuGUI = data->GetGUI();
  32. }
  33. SetSpritePath( "menuVideo" );
  34. videoDetails.SetSpritePath( GetSpritePath(), "info", "details" );
  35. videoDetails.Initialize( data );
  36. videoDetails.SetNoAutoFree( true );
  37. scrollbar.SetSpritePath( GetSpritePath(), "info", "videoList", "scrollbar" );
  38. scrollbar.Initialize( data );
  39. scrollbar.SetNoAutoFree( true );
  40. pdaVideoList.SetSpritePath( GetSpritePath(), "info", "videoList", "options" );
  41. pdaVideoList.SetNumVisibleOptions( MAX_VIDEO_ITEMS );
  42. pdaVideoList.SetWrappingAllowed( true );
  43. pdaVideoList.SetNoAutoFree( true );
  44. while ( pdaVideoList.GetChildren().Num() < MAX_VIDEO_ITEMS ) {
  45. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  46. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_SELECT_PDA_VIDEO, pdaVideoList.GetChildren().Num() );
  47. buttonWidget->RegisterEventObserver( &videoDetails );
  48. buttonWidget->RegisterEventObserver( &scrollbar );
  49. buttonWidget->Initialize( data );
  50. pdaVideoList.AddChild( buttonWidget );
  51. }
  52. pdaVideoList.Initialize( data );
  53. pdaVideoList.AddChild( &scrollbar );
  54. AddChild( &pdaVideoList );
  55. AddChild( &videoDetails );
  56. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK ) );
  57. AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK ) );
  58. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_LSTICK_RELEASE ) );
  59. AddEventAction( WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_LSTICK_RELEASE ) );
  60. AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  61. AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  62. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  63. AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( &pdaVideoList, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  64. AddEventAction( WIDGET_EVENT_TAB_NEXT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_NEXT, WIDGET_EVENT_TAB_NEXT ) );
  65. AddEventAction( WIDGET_EVENT_TAB_PREV ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_TAB_PREV, WIDGET_EVENT_TAB_PREV ) );
  66. idMenuScreen::Initialize( data );
  67. }
  68. /*
  69. ========================
  70. idMenuScreen_PDA_VideoDisks::Update
  71. ========================
  72. */
  73. void idMenuScreen_PDA_VideoDisks::Update() {
  74. idPlayer * player = gameLocal.GetLocalPlayer();
  75. if ( menuData != NULL ) {
  76. idMenuWidget_CommandBar * cmdBar = dynamic_cast< idMenuWidget_CommandBar * const >( menuData->GetChildFromIndex( PDA_WIDGET_CMD_BAR ) );
  77. if ( cmdBar != NULL ) {
  78. cmdBar->ClearAllButtons();
  79. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  80. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY2 );
  81. if ( menuData->GetPlatform() != 2 ) {
  82. buttonInfo->label = "#str_01345";
  83. }
  84. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  85. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_TAB );
  86. buttonInfo->label = "";
  87. buttonInfo->action.Set( WIDGET_ACTION_GO_BACK );
  88. if ( player != NULL && player->GetInventory().videos.Num() > 0 ) {
  89. if ( player->GetVideoMaterial() == NULL ) {
  90. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  91. if ( menuData->GetPlatform() != 2 ) {
  92. buttonInfo->label = "#str_swf_play";
  93. }
  94. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  95. } else {
  96. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  97. if ( menuData->GetPlatform() != 2 ) {
  98. buttonInfo->label = "#str_swf_stop";
  99. }
  100. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  101. }
  102. }
  103. }
  104. }
  105. if ( player != NULL ) {
  106. //if ( pdaVideoList == NULL ) {
  107. // idMenuScreen::Update();
  108. // return;
  109. //}
  110. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  111. int index = pdaVideoList.GetViewIndex();
  112. const idDeclVideo * video = player->GetVideo( index );
  113. if ( video == NULL ) {
  114. idMenuScreen::Update();
  115. return;
  116. }
  117. if ( player->GetVideoMaterial() != NULL ) {
  118. // update video material
  119. if ( BindSprite( root ) && GetSprite() != NULL ) {
  120. idSWFSpriteInstance * videoSprite = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "details", "video", "img" );
  121. const idMaterial * mat = player->GetVideoMaterial();
  122. if ( videoSprite != NULL && mat != NULL ) {
  123. videoSprite->SetMaterial( mat );
  124. }
  125. }
  126. } else {
  127. idSWFSpriteInstance * videoSprite = GetSprite()->GetScriptObject()->GetNestedSprite( "info", "details", "video", "img" );
  128. if ( videoSprite != NULL ) {
  129. videoSprite->SetMaterial( video->GetPreview() );
  130. }
  131. }
  132. }
  133. idMenuScreen::Update();
  134. }
  135. /*
  136. ========================
  137. idMenuScreen_PDA_VideoDisks::ShowScreen
  138. ========================
  139. */
  140. void idMenuScreen_PDA_VideoDisks::ShowScreen( const mainMenuTransition_t transitionType ) {
  141. videoItems.Clear();
  142. idPlayer * player = gameLocal.GetLocalPlayer();
  143. if ( player != NULL ) {
  144. int numVideos = player->GetInventory().videos.Num();
  145. for ( int i = 0; i < numVideos; ++i ) {
  146. const idDeclVideo * video = player->GetVideo( i );
  147. if( video != NULL ) {
  148. idList< idStr > item;
  149. item.Append( video->GetVideoName() );
  150. videoItems.Append( item );
  151. }
  152. }
  153. }
  154. pdaVideoList.SetListData( videoItems );
  155. idMenuScreen::ShowScreen( transitionType );
  156. }
  157. /*
  158. ========================
  159. idMenuScreen_PDA_VideoDisks::ToggleVideoDiskPlay
  160. ========================
  161. */
  162. void idMenuScreen_PDA_VideoDisks::ToggleVideoDiskPlay() {
  163. idPlayer * player = gameLocal.GetLocalPlayer();
  164. if ( player == NULL ) {
  165. return;
  166. }
  167. int index = pdaVideoList.GetViewIndex();
  168. const idDeclVideo * video = player->GetVideo( index );
  169. if ( video == NULL ) {
  170. return;
  171. }
  172. if ( video == activeVideo ) {
  173. player->EndVideoDisk();
  174. activeVideo = NULL;
  175. return;
  176. }
  177. activeVideo = video;
  178. if ( player->GetVideoMaterial() == NULL ) {
  179. player->PlayVideoDisk( video );
  180. } else {
  181. player->EndVideoDisk();
  182. }
  183. }
  184. /*
  185. ========================
  186. idMenuScreen_PDA_VideoDisks::SelectedVideoToPlay
  187. ========================
  188. */
  189. void idMenuScreen_PDA_VideoDisks::SelectedVideoToPlay( int index ) {
  190. idPlayer * player = gameLocal.GetLocalPlayer();
  191. if ( player == NULL ) {
  192. return;
  193. }
  194. player->EndVideoDisk();
  195. if ( menuData != NULL ) {
  196. idMenuHandler_PDA * pdaHandler = dynamic_cast< idMenuHandler_PDA * const >( menuData );
  197. pdaHandler->ClearVideoPlaying();
  198. }
  199. pdaVideoList.SetViewIndex( pdaVideoList.GetViewOffset() + index );
  200. pdaVideoList.SetFocusIndex( index );
  201. const idDeclVideo * video = player->GetVideo( pdaVideoList.GetViewOffset() + index );
  202. if ( video == NULL ) {
  203. return;
  204. }
  205. if ( video == activeVideo ) {
  206. activeVideo = NULL;
  207. return;
  208. }
  209. activeVideo = video;
  210. player->PlayVideoDisk( video );
  211. }
  212. /*
  213. ========================
  214. idMenuScreen_PDA_VideoDisks::HideScreen
  215. ========================
  216. */
  217. void idMenuScreen_PDA_VideoDisks::HideScreen( const mainMenuTransition_t transitionType ) {
  218. idMenuScreen::HideScreen( transitionType );
  219. }
  220. /*
  221. ========================
  222. idMenuScreen_PDA_VideoDisks::HandleAction
  223. ========================
  224. */
  225. bool idMenuScreen_PDA_VideoDisks::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  226. if ( menuData == NULL ) {
  227. return true;
  228. }
  229. if ( menuData->ActiveScreen() != PDA_AREA_VIDEO_DISKS ) {
  230. return false;
  231. }
  232. widgetAction_t actionType = action.GetType();
  233. const idSWFParmList & parms = action.GetParms();
  234. switch ( actionType ) {
  235. case WIDGET_ACTION_GO_BACK: {
  236. menuData->SetNextScreen( PDA_AREA_INVALID, MENU_TRANSITION_ADVANCE );
  237. return true;
  238. }
  239. case WIDGET_ACTION_START_REPEATER: {
  240. idWidgetAction repeatAction;
  241. widgetAction_t repeatActionType = static_cast< widgetAction_t >( parms[ 0 ].ToInteger() );
  242. assert( parms.Num() == 2 );
  243. repeatAction.Set( repeatActionType, parms[ 1 ] );
  244. if ( menuData != NULL ) {
  245. menuData->StartWidgetActionRepeater( widget, repeatAction, event );
  246. }
  247. return true;
  248. }
  249. case WIDGET_ACTION_STOP_REPEATER: {
  250. if ( menuData != NULL ) {
  251. menuData->ClearWidgetActionRepeater();
  252. }
  253. return true;
  254. }
  255. case WIDGET_ACTION_PRESS_FOCUSED: {
  256. ToggleVideoDiskPlay();
  257. Update();
  258. return true;
  259. }
  260. }
  261. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  262. }