MenuWidget_DevList.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 "../precompiled.h"
  22. #include "../MainMenuLocal.h"
  23. /*
  24. ================================================================================================
  25. idMenuWidget_DevList
  26. Extends the standard list widget to support the developer menu.
  27. ================================================================================================
  28. */
  29. namespace {
  30. /*
  31. ================================================
  32. DevList_NavigateForward
  33. ================================================
  34. */
  35. class DevList_NavigateForward : public idSWFScriptFunction_RefCounted {
  36. public:
  37. DevList_NavigateForward( idMenuWidget_DevList * devList_, const int optionIndex_ ) :
  38. devList( devList_ ),
  39. optionIndex( optionIndex_ ) {
  40. }
  41. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  42. devList->NavigateForward( optionIndex );
  43. return idSWFScriptVar();
  44. }
  45. private:
  46. idMenuWidget_DevList * devList;
  47. int optionIndex;
  48. };
  49. }
  50. /*
  51. ========================
  52. idMenuWidget_DevList::Initialize
  53. ========================
  54. */
  55. void idMenuWidget_DevList::Initialize() {
  56. AddEventAction( WIDGET_EVENT_SCROLL_DOWN ).Set( WIDGET_ACTION_START_REPEATER, WIDGET_ACTION_SCROLL_VERTICAL, 1 );
  57. AddEventAction( WIDGET_EVENT_SCROLL_UP ).Set( WIDGET_ACTION_START_REPEATER, WIDGET_ACTION_SCROLL_VERTICAL, -1 );
  58. AddEventAction( WIDGET_EVENT_SCROLL_DOWN_RELEASE ).Set( WIDGET_ACTION_STOP_REPEATER );
  59. AddEventAction( WIDGET_EVENT_SCROLL_UP_RELEASE ).Set( WIDGET_ACTION_STOP_REPEATER );
  60. int optionIndex = 0;
  61. while ( GetChildren().Num() < GetNumVisibleOptions() ) {
  62. idMenuWidget_Button * const buttonWidget = new ( TAG_MENU ) idMenuWidget_Button();
  63. buttonWidget->AddEventAction( WIDGET_EVENT_PRESS ).Set( new ( TAG_SWF ) DevList_NavigateForward( this, optionIndex++ ) );
  64. AddChild( buttonWidget );
  65. }
  66. }
  67. /*
  68. ========================
  69. idMenuWidget_DevList::GetTotalNumberOfOptions
  70. ========================
  71. */
  72. int idMenuWidget_DevList::GetTotalNumberOfOptions() const {
  73. if ( devMenuList == NULL ) {
  74. return 0;
  75. }
  76. return devMenuList->devMenuList.Num();
  77. }
  78. /*
  79. ========================
  80. idMenuWidget_DevList::GoToFirstMenu
  81. ========================
  82. */
  83. void idMenuWidget_DevList::GoToFirstMenu() {
  84. devMapListInfos.Clear();
  85. indexInfo_t & info = devMapListInfos.Alloc();
  86. info.name = "devmenuoption/main";
  87. devMenuList = NULL;
  88. RecalculateDevMenu();
  89. }
  90. /*
  91. ========================
  92. idMenuWidget_DevList::NavigateForward
  93. ========================
  94. */
  95. void idMenuWidget_DevList::NavigateForward( const int optionIndex ) {
  96. if ( devMenuList == NULL ) {
  97. return;
  98. }
  99. const int focusedIndex = GetViewOffset() + optionIndex;
  100. const idDeclDevMenuList::idDevMenuOption & devOption = devMenuList->devMenuList[ focusedIndex ];
  101. if ( ( devOption.devMenuDisplayName.Length() == 0 ) || ( devOption.devMenuDisplayName.Cmp( "..." ) == 0 ) ) {
  102. return;
  103. }
  104. if ( devOption.devMenuSubList != NULL ) {
  105. indexInfo_t & indexes = devMapListInfos.Alloc();
  106. indexes.name = devOption.devMenuSubList->GetName();
  107. indexes.focusIndex = GetFocusIndex();
  108. indexes.viewIndex = GetViewIndex();
  109. indexes.viewOffset = GetViewOffset();
  110. RecalculateDevMenu();
  111. SetViewIndex( 0 );
  112. SetViewOffset( 0 );
  113. Update();
  114. // NOTE: This must be done after the Update() because it MAY change the sprites that
  115. // children refer to
  116. GetChildByIndex( 0 ).SetState( WIDGET_STATE_SELECTED );
  117. ForceFocusIndex( 0 );
  118. SetFocusIndex( 0 );
  119. gameLocal->GetMainMenu()->ClearWidgetActionRepeater();
  120. } else {
  121. cmdSystem->AppendCommandText( va( "loadDevMenuOption %s %d\n", devMapListInfos[ devMapListInfos.Num() - 1 ].name, focusedIndex ) );
  122. }
  123. }
  124. /*
  125. ========================
  126. idMenuWidget_DevList::NavigateBack
  127. ========================
  128. */
  129. void idMenuWidget_DevList::NavigateBack() {
  130. assert( devMapListInfos.Num() != 0 );
  131. if ( devMapListInfos.Num() == 1 ) {
  132. // Important that this goes through as a DIRECT event, since more than likely the list
  133. // widget will have the parent's focus, so a standard ReceiveEvent() here would turn
  134. // into an infinite recursion.
  135. idWidgetEvent event( WIDGET_EVENT_BACK, 0, NULL, idSWFParmList() );
  136. idWidgetAction action;
  137. action.Set( WIDGET_ACTION_GO_BACK, MENU_ROOT );
  138. HandleAction( action, event );
  139. return;
  140. }
  141. // NOTE: we need a copy here, since it's about to be removed from the list
  142. const indexInfo_t indexes = devMapListInfos[ devMapListInfos.Num() - 1 ];
  143. assert( indexes.focusIndex < GetChildren().Num() );
  144. assert( ( indexes.viewIndex - indexes.viewOffset ) < GetNumVisibleOptions() );
  145. devMapListInfos.RemoveIndex( devMapListInfos.Num() - 1 );
  146. RecalculateDevMenu();
  147. SetViewIndex( indexes.viewIndex );
  148. SetViewOffset( indexes.viewOffset );
  149. Update();
  150. // NOTE: This must be done AFTER Update() because so that it is sure to refer to the proper sprite
  151. GetChildByIndex( indexes.focusIndex ).SetState( WIDGET_STATE_SELECTED );
  152. ForceFocusIndex( indexes.focusIndex );
  153. SetFocusIndex( indexes.focusIndex );
  154. gameLocal->GetMainMenu()->ClearWidgetActionRepeater();
  155. }
  156. /*
  157. ========================
  158. idMenuWidget_DevList::RecalculateDevMenu
  159. ========================
  160. */
  161. void idMenuWidget_DevList::RecalculateDevMenu() {
  162. if ( devMapListInfos.Num() > 0 ) {
  163. const idDeclDevMenuList * const devMenuListDecl = idDeclDevMenuList::resourceList.Load( devMapListInfos[ devMapListInfos.Num() - 1 ].name, false );
  164. if ( devMenuListDecl != NULL ) {
  165. devMenuList = devMenuListDecl;
  166. }
  167. }
  168. idSWFScriptObject & root = gameLocal->GetMainMenu()->GetSWF()->GetRootObject();
  169. for ( int i = 0; i < GetChildren().Num(); ++i ) {
  170. idMenuWidget & child = GetChildByIndex( i );
  171. child.SetSpritePath( GetSpritePath(), va( "option%d", i ) );
  172. if ( child.BindSprite( root ) ) {
  173. child.SetState( WIDGET_STATE_NORMAL );
  174. child.GetSprite()->StopFrame( 1 );
  175. }
  176. }
  177. }