MenuScreen_Shell_PressStart.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. #include "../../framework/Common_local.h"
  24. static const int NUM_GAME_SELECTIONS_VISIBLE = 5;
  25. extern idCVar g_demoMode;
  26. namespace {
  27. /*
  28. ================================================
  29. UICmd_RegisterUser
  30. ================================================
  31. */
  32. class UICmd_RegisterUser : public idSWFScriptFunction_RefCounted {
  33. public:
  34. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  35. if ( parms.Num() != 1 ) {
  36. idLib::Warning( "No device specified when registering mouse user" );
  37. return idSWFScriptVar();
  38. }
  39. const int device = parms[ 0 ].ToInteger();
  40. session->GetSignInManager().RegisterLocalUser( device );
  41. return idSWFScriptVar();
  42. }
  43. };
  44. }
  45. /*
  46. ========================
  47. idMenuScreen_Shell_PressStart::Initialize
  48. ========================
  49. */
  50. void idMenuScreen_Shell_PressStart::Initialize( idMenuHandler * data ) {
  51. idMenuScreen::Initialize( data );
  52. if ( data != NULL ) {
  53. menuGUI = data->GetGUI();
  54. }
  55. SetSpritePath( "menuStart" );
  56. itemList = new (TAG_SWF) idMenuWidget_Carousel();
  57. itemList->SetSpritePath( GetSpritePath(), "info", "options" );
  58. itemList->SetNumVisibleOptions( NUM_GAME_SELECTIONS_VISIBLE );
  59. while ( itemList->GetChildren().Num() < NUM_GAME_SELECTIONS_VISIBLE ) {
  60. idMenuWidget_Button * const buttonWidget = new (TAG_SWF) idMenuWidget_Button();
  61. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( WIDGET_ACTION_PRESS_FOCUSED, itemList->GetChildren().Num() );
  62. buttonWidget->Initialize( data );
  63. itemList->AddChild( buttonWidget );
  64. }
  65. itemList->Initialize( data );
  66. AddChild( itemList );
  67. AddEventAction( WIDGET_EVENT_SCROLL_LEFT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_LEFT_START_REPEATER, WIDGET_EVENT_SCROLL_LEFT ) );
  68. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_RIGHT_START_REPEATER, WIDGET_EVENT_SCROLL_RIGHT ) );
  69. AddEventAction( WIDGET_EVENT_SCROLL_LEFT_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_LEFT_RELEASE ) );
  70. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_RIGHT_RELEASE ) );
  71. AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_UP_START_REPEATER, WIDGET_EVENT_SCROLL_UP ) );
  72. AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_DOWN_START_REPEATER, WIDGET_EVENT_SCROLL_DOWN ) );
  73. AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_UP_RELEASE ) );
  74. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_DOWN_RELEASE ) );
  75. AddEventAction( WIDGET_EVENT_SCROLL_LEFT_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_LEFT_START_REPEATER, WIDGET_EVENT_SCROLL_LEFT_LSTICK ) );
  76. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT_LSTICK ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_SCROLL_RIGHT_START_REPEATER, WIDGET_EVENT_SCROLL_RIGHT_LSTICK ) );
  77. AddEventAction( WIDGET_EVENT_SCROLL_LEFT_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_LEFT_LSTICK_RELEASE ) );
  78. AddEventAction( WIDGET_EVENT_SCROLL_RIGHT_LSTICK_RELEASE ).Set( new (TAG_SWF) idWidgetActionHandler( this, WIDGET_ACTION_EVENT_STOP_REPEATER, WIDGET_EVENT_SCROLL_RIGHT_LSTICK_RELEASE ) );
  79. doomCover = declManager->FindMaterial( "guis/assets/mainmenu/doom_cover.tga" );
  80. doom2Cover = declManager->FindMaterial( "guis/assets/mainmenu/doom2_cover.tga" );
  81. doom3Cover = declManager->FindMaterial( "guis/assets/mainmenu/doom3_cover.tga" );
  82. startButton = new idMenuWidget_Button();
  83. startButton->SetSpritePath( GetSpritePath(), "info", "btnStart" );
  84. AddChild( startButton );
  85. }
  86. /*
  87. ========================
  88. idMenuScreen_Shell_Root::Update
  89. ========================
  90. */
  91. void idMenuScreen_Shell_PressStart::Update() {
  92. if ( !g_demoMode.GetBool() ) {
  93. if ( menuData != NULL ) {
  94. idMenuWidget_CommandBar * cmdBar = menuData->GetCmdBar();
  95. if ( cmdBar != NULL ) {
  96. cmdBar->ClearAllButtons();
  97. idMenuWidget_CommandBar::buttonInfo_t * buttonInfo;
  98. buttonInfo = cmdBar->GetButton( idMenuWidget_CommandBar::BUTTON_JOY1 );
  99. if ( menuData->GetPlatform() != 2 ) {
  100. buttonInfo->label = "#str_SWF_SELECT";
  101. }
  102. buttonInfo->action.Set( WIDGET_ACTION_PRESS_FOCUSED );
  103. }
  104. }
  105. }
  106. idMenuScreen::Update();
  107. }
  108. /*
  109. ========================
  110. idMenuScreen_Shell_PressStart::ShowScreen
  111. ========================
  112. */
  113. void idMenuScreen_Shell_PressStart::ShowScreen( const mainMenuTransition_t transitionType ) {
  114. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  115. if ( BindSprite( root ) ) {
  116. if ( g_demoMode.GetBool() ) {
  117. idList<const idMaterial *> coverIcons;
  118. if ( itemList != NULL ) {
  119. itemList->SetListImages( coverIcons );
  120. }
  121. if ( startButton != NULL ) {
  122. startButton->BindSprite( root );
  123. startButton->SetLabel( idLocalization::GetString( "#str_swf_press_start" ) );
  124. }
  125. idSWFSpriteInstance * backing = GetSprite()->GetScriptObject()->GetNestedSprite( "backing" );
  126. if ( backing != NULL ) {
  127. backing->SetVisible( false );
  128. }
  129. } else {
  130. idList<const idMaterial *> coverIcons;
  131. coverIcons.Append( doomCover );
  132. coverIcons.Append( doom3Cover );
  133. coverIcons.Append( doom2Cover );
  134. if ( itemList != NULL ) {
  135. itemList->SetListImages( coverIcons );
  136. itemList->SetFocusIndex( 1, true );
  137. itemList->SetViewIndex( 1 );
  138. itemList->SetMoveToIndex( 1 );
  139. }
  140. if ( startButton != NULL ) {
  141. startButton->BindSprite( root );
  142. startButton->SetLabel( "" );
  143. }
  144. idSWFSpriteInstance * backing = GetSprite()->GetScriptObject()->GetNestedSprite( "backing" );
  145. if ( backing != NULL ) {
  146. backing->SetVisible( true );
  147. }
  148. }
  149. }
  150. idMenuScreen::ShowScreen( transitionType );
  151. }
  152. /*
  153. ========================
  154. idMenuScreen_Shell_PressStart::HideScreen
  155. ========================
  156. */
  157. void idMenuScreen_Shell_PressStart::HideScreen( const mainMenuTransition_t transitionType ) {
  158. idMenuScreen::HideScreen( transitionType );
  159. }
  160. /*
  161. ========================
  162. idMenuScreen_Shell_PressStart::HandleAction
  163. ========================
  164. */
  165. bool idMenuScreen_Shell_PressStart::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) {
  166. if ( menuData == NULL ) {
  167. return true;
  168. }
  169. if ( menuData->ActiveScreen() != SHELL_AREA_START ) {
  170. return false;
  171. }
  172. widgetAction_t actionType = action.GetType();
  173. const idSWFParmList & parms = action.GetParms();
  174. switch ( actionType ) {
  175. case WIDGET_ACTION_PRESS_FOCUSED: {
  176. if ( itemList == NULL ) {
  177. return true;
  178. }
  179. if ( event.parms.Num() != 1 ) {
  180. return true;
  181. }
  182. if ( itemList->GetMoveToIndex() != itemList->GetViewIndex() ) {
  183. return true;
  184. }
  185. if ( parms.Num() > 0 ) {
  186. const int index = parms[0].ToInteger();
  187. if ( index != 0 ) {
  188. itemList->MoveToIndex( index );
  189. Update();
  190. }
  191. }
  192. if ( itemList->GetMoveToIndex() == 0 ) {
  193. common->SwitchToGame( DOOM_CLASSIC );
  194. } else if ( itemList->GetMoveToIndex() == 1 ) {
  195. if ( session->GetSignInManager().GetMasterLocalUser() == NULL ) {
  196. const int device = event.parms[ 0 ].ToInteger();
  197. session->GetSignInManager().RegisterLocalUser( device );
  198. } else {
  199. menuData->SetNextScreen( SHELL_AREA_ROOT, MENU_TRANSITION_SIMPLE );
  200. }
  201. } else if ( itemList->GetMoveToIndex() == 2 ) {
  202. common->SwitchToGame( DOOM2_CLASSIC );
  203. }
  204. return true;
  205. }
  206. case WIDGET_ACTION_START_REPEATER: {
  207. idWidgetAction repeatAction;
  208. widgetAction_t repeatActionType = static_cast< widgetAction_t >( parms[ 0 ].ToInteger() );
  209. assert( parms.Num() == 2 );
  210. repeatAction.Set( repeatActionType, parms[ 1 ] );
  211. menuData->StartWidgetActionRepeater( widget, repeatAction, event );
  212. return true;
  213. }
  214. case WIDGET_ACTION_STOP_REPEATER: {
  215. menuData->ClearWidgetActionRepeater();
  216. return true;
  217. }
  218. case WIDGET_ACTION_SCROLL_HORIZONTAL: {
  219. if ( itemList == NULL ) {
  220. return true;
  221. }
  222. if ( itemList->GetTotalNumberOfOptions() <= 1 ) {
  223. return true;
  224. }
  225. idLib::Printf( "scroll \n" );
  226. if ( itemList->GetMoveDiff() > 0 ) {
  227. itemList->MoveToIndex( itemList->GetMoveToIndex(), true );
  228. }
  229. int direction = parms[0].ToInteger();
  230. if ( direction == 1 ) {
  231. if ( itemList->GetViewIndex() == itemList->GetTotalNumberOfOptions() - 1 ) {
  232. return true;
  233. } else {
  234. itemList->MoveToIndex( 1 );
  235. }
  236. } else {
  237. if ( itemList->GetViewIndex() == 0 ) {
  238. return true;
  239. } else {
  240. itemList->MoveToIndex( ( itemList->GetNumVisibleOptions() / 2 ) + 1 );
  241. }
  242. }
  243. return true;
  244. }
  245. }
  246. return idMenuWidget::HandleAction( action, event, widget, forceHandled );
  247. }