MenuWidget_CommandBar.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_CommandBar
  26. Provides a paged view of this widgets children. Each child is expected to take on the following
  27. naming scheme. Children outside of the given window size (NumVisibleOptions) are not rendered,
  28. and will affect which type of arrow indicators are shown.
  29. This transparently supports the "UseCircleForAccept" behavior that we need for Japanese PS3 SKU.
  30. SWF object structure
  31. --------------------
  32. COMMANDBAR
  33. joy#
  34. img (Frames: platform)
  35. txt_info (Text)
  36. ================================================================================================
  37. */
  38. static const char * const BUTTON_NAMES[] = {
  39. "joy1",
  40. "joy2",
  41. "joy3",
  42. "joy4",
  43. "joy10",
  44. "tab"
  45. };
  46. compile_time_assert( sizeof( BUTTON_NAMES ) / sizeof( BUTTON_NAMES[ 0 ] ) == idMenuWidget_CommandBar::MAX_BUTTONS );
  47. /*
  48. ========================
  49. idMenuWidget_CommandBar::ClearAllButtons
  50. ========================
  51. */
  52. void idMenuWidget_CommandBar::ClearAllButtons() {
  53. for ( int index = 0; index < MAX_BUTTONS; ++index ) {
  54. buttons[index].label.Clear();
  55. buttons[index].action.Set( WIDGET_ACTION_NONE );
  56. }
  57. }
  58. /*
  59. ========================
  60. idMenuWidget_CommandBar::Update
  61. ========================
  62. */
  63. void idMenuWidget_CommandBar::Update() {
  64. if ( GetSWFObject() == NULL ) {
  65. return;
  66. }
  67. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  68. if ( !BindSprite( root ) ) {
  69. return;
  70. }
  71. const int BASE_PADDING = 35;
  72. const int PER_BUTTON_PADDING = 65;
  73. const int ALIGNMENT_SCALE = ( GetAlignment() == LEFT ) ? 1 : -1;
  74. int xPos = ALIGNMENT_SCALE * BASE_PADDING;
  75. // Setup the button order.
  76. idStaticList< button_t, MAX_BUTTONS > buttonOrder;
  77. for ( int i = 0; i < buttonOrder.Max(); ++i ) {
  78. buttonOrder.Append( static_cast< button_t >( i ) );
  79. }
  80. // NOTE: Special consideration is done for JPN PS3 where the standard accept button is
  81. // swapped with the standard back button. i.e. In US: X = Accept, O = Back, but in JPN
  82. // X = Back, O = Accept.
  83. if ( GetSWFObject()->UseCircleForAccept() ) {
  84. buttonOrder[ BUTTON_JOY2 ] = BUTTON_JOY1;
  85. buttonOrder[ BUTTON_JOY1 ] = BUTTON_JOY2;
  86. }
  87. // FIXME: handle animating in of the button bar?
  88. GetSprite()->SetVisible( true );
  89. idStr shortcutName;
  90. for ( int i = 0; i < buttonOrder.Num(); ++i ) {
  91. const char * const buttonName = BUTTON_NAMES[ buttonOrder[ i ] ];
  92. idSWFSpriteInstance * const buttonSprite = GetSprite()->GetScriptObject()->GetSprite( buttonName );
  93. if ( buttonSprite == NULL ) {
  94. continue;
  95. }
  96. idSWFTextInstance * const buttonText = buttonSprite->GetScriptObject()->GetText( "txt_info" );
  97. if ( buttonText == NULL ) {
  98. continue;
  99. }
  100. idSWFSpriteInstance * const imageSprite = buttonSprite->GetScriptObject()->GetSprite( "img" );
  101. if ( imageSprite == NULL ) {
  102. continue;
  103. }
  104. if ( buttons[ i ].action.GetType() != WIDGET_ACTION_NONE ) {
  105. idSWFScriptObject * const shortcutKeys = GetSWFObject()->GetGlobal( "shortcutKeys" ).GetObject();
  106. if ( verify( shortcutKeys != NULL ) ) {
  107. buttonSprite->GetScriptObject()->Set( "onPress", new WrapWidgetSWFEvent( this, WIDGET_EVENT_COMMAND, i ) );
  108. // bind the main action - need to use all caps here because shortcuts are stored that way
  109. shortcutName = buttonName;
  110. shortcutName.ToUpper();
  111. shortcutKeys->Set( shortcutName, buttonSprite->GetScriptObject() );
  112. // Some other keys have additional bindings. Remember that the button here is
  113. // actually the virtual button, and the physical button could be swapped based
  114. // on the UseCircleForAccept business on JPN PS3.
  115. switch ( i ) {
  116. case BUTTON_JOY1: {
  117. shortcutKeys->Set( "ENTER", buttonSprite->GetScriptObject() );
  118. break;
  119. }
  120. case BUTTON_JOY2: {
  121. shortcutKeys->Set( "ESCAPE", buttonSprite->GetScriptObject() );
  122. shortcutKeys->Set( "BACKSPACE", buttonSprite->GetScriptObject() );
  123. break;
  124. }
  125. case BUTTON_TAB: {
  126. shortcutKeys->Set( "K_TAB", buttonSprite->GetScriptObject() );
  127. break;
  128. }
  129. }
  130. }
  131. if ( buttons[ i ].label.IsEmpty() ) {
  132. buttonSprite->SetVisible( false );
  133. } else {
  134. imageSprite->SetVisible( true );
  135. imageSprite->StopFrame( menuData->GetPlatform() + 1 );
  136. buttonSprite->SetVisible( true );
  137. buttonSprite->SetXPos( xPos );
  138. buttonText->SetText( buttons[ i ].label );
  139. xPos += ALIGNMENT_SCALE * ( buttonText->GetTextLength() + PER_BUTTON_PADDING );
  140. }
  141. } else {
  142. buttonSprite->SetVisible( false );
  143. idSWFScriptObject * const shortcutKeys = GetSWFObject()->GetGlobal( "shortcutKeys" ).GetObject();
  144. if ( verify( shortcutKeys != NULL ) ) {
  145. buttonSprite->GetScriptObject()->Set( "onPress", NULL );
  146. // bind the main action - need to use all caps here because shortcuts are stored that way
  147. shortcutName = buttonName;
  148. shortcutName.ToUpper();
  149. shortcutKeys->Set( shortcutName, buttonSprite->GetScriptObject() );
  150. }
  151. }
  152. }
  153. }
  154. /*
  155. ========================
  156. idMenuWidget_CommandBar::ReceiveEvent
  157. ========================
  158. */
  159. bool idMenuWidget_CommandBar::ExecuteEvent( const idWidgetEvent & event ) {
  160. if ( event.type == WIDGET_EVENT_COMMAND ) {
  161. if ( verify( event.arg >= 0 && event.arg < buttons.Num() ) ) {
  162. HandleAction( buttons[ event.arg ].action, event, this );
  163. }
  164. return true;
  165. } else {
  166. return idMenuWidget::ExecuteEvent( event );
  167. }
  168. }