MenuWidget_CommandBar.cpp (7045B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 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. 23 24 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. 25 26 =========================================================================== 27 */ 28 #pragma hdrstop 29 #include "../../idLib/precompiled.h" 30 #include "../Game_local.h" 31 32 /* 33 ================================================================================================ 34 idMenuWidget_CommandBar 35 36 Provides a paged view of this widgets children. Each child is expected to take on the following 37 naming scheme. Children outside of the given window size (NumVisibleOptions) are not rendered, 38 and will affect which type of arrow indicators are shown. 39 40 This transparently supports the "UseCircleForAccept" behavior that we need for Japanese PS3 SKU. 41 42 SWF object structure 43 -------------------- 44 COMMANDBAR 45 joy# 46 img (Frames: platform) 47 txt_info (Text) 48 ================================================================================================ 49 */ 50 51 static const char * const BUTTON_NAMES[] = { 52 "joy1", 53 "joy2", 54 "joy3", 55 "joy4", 56 "joy10", 57 "tab" 58 }; 59 compile_time_assert( sizeof( BUTTON_NAMES ) / sizeof( BUTTON_NAMES[ 0 ] ) == idMenuWidget_CommandBar::MAX_BUTTONS ); 60 61 /* 62 ======================== 63 idMenuWidget_CommandBar::ClearAllButtons 64 ======================== 65 */ 66 void idMenuWidget_CommandBar::ClearAllButtons() { 67 for ( int index = 0; index < MAX_BUTTONS; ++index ) { 68 buttons[index].label.Clear(); 69 buttons[index].action.Set( WIDGET_ACTION_NONE ); 70 } 71 } 72 73 /* 74 ======================== 75 idMenuWidget_CommandBar::Update 76 ======================== 77 */ 78 void idMenuWidget_CommandBar::Update() { 79 80 if ( GetSWFObject() == NULL ) { 81 return; 82 } 83 84 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 85 86 if ( !BindSprite( root ) ) { 87 return; 88 } 89 90 const int BASE_PADDING = 35; 91 const int PER_BUTTON_PADDING = 65; 92 const int ALIGNMENT_SCALE = ( GetAlignment() == LEFT ) ? 1 : -1; 93 94 int xPos = ALIGNMENT_SCALE * BASE_PADDING; 95 96 // Setup the button order. 97 idStaticList< button_t, MAX_BUTTONS > buttonOrder; 98 for ( int i = 0; i < buttonOrder.Max(); ++i ) { 99 buttonOrder.Append( static_cast< button_t >( i ) ); 100 } 101 102 // NOTE: Special consideration is done for JPN PS3 where the standard accept button is 103 // swapped with the standard back button. i.e. In US: X = Accept, O = Back, but in JPN 104 // X = Back, O = Accept. 105 if ( GetSWFObject()->UseCircleForAccept() ) { 106 buttonOrder[ BUTTON_JOY2 ] = BUTTON_JOY1; 107 buttonOrder[ BUTTON_JOY1 ] = BUTTON_JOY2; 108 } 109 110 // FIXME: handle animating in of the button bar? 111 GetSprite()->SetVisible( true ); 112 113 idStr shortcutName; 114 for ( int i = 0; i < buttonOrder.Num(); ++i ) { 115 const char * const buttonName = BUTTON_NAMES[ buttonOrder[ i ] ]; 116 117 idSWFSpriteInstance * const buttonSprite = GetSprite()->GetScriptObject()->GetSprite( buttonName ); 118 if ( buttonSprite == NULL ) { 119 continue; 120 } 121 idSWFTextInstance * const buttonText = buttonSprite->GetScriptObject()->GetText( "txt_info" ); 122 if ( buttonText == NULL ) { 123 continue; 124 } 125 idSWFSpriteInstance * const imageSprite = buttonSprite->GetScriptObject()->GetSprite( "img" ); 126 if ( imageSprite == NULL ) { 127 continue; 128 } 129 130 if ( buttons[ i ].action.GetType() != WIDGET_ACTION_NONE ) { 131 idSWFScriptObject * const shortcutKeys = GetSWFObject()->GetGlobal( "shortcutKeys" ).GetObject(); 132 if ( verify( shortcutKeys != NULL ) ) { 133 buttonSprite->GetScriptObject()->Set( "onPress", new WrapWidgetSWFEvent( this, WIDGET_EVENT_COMMAND, i ) ); 134 135 // bind the main action - need to use all caps here because shortcuts are stored that way 136 shortcutName = buttonName; 137 shortcutName.ToUpper(); 138 shortcutKeys->Set( shortcutName, buttonSprite->GetScriptObject() ); 139 140 // Some other keys have additional bindings. Remember that the button here is 141 // actually the virtual button, and the physical button could be swapped based 142 // on the UseCircleForAccept business on JPN PS3. 143 switch ( i ) { 144 case BUTTON_JOY1: { 145 shortcutKeys->Set( "ENTER", buttonSprite->GetScriptObject() ); 146 break; 147 } 148 case BUTTON_JOY2: { 149 shortcutKeys->Set( "ESCAPE", buttonSprite->GetScriptObject() ); 150 shortcutKeys->Set( "BACKSPACE", buttonSprite->GetScriptObject() ); 151 break; 152 } 153 case BUTTON_TAB: { 154 shortcutKeys->Set( "K_TAB", buttonSprite->GetScriptObject() ); 155 break; 156 } 157 } 158 } 159 160 if ( buttons[ i ].label.IsEmpty() ) { 161 buttonSprite->SetVisible( false ); 162 } else { 163 imageSprite->SetVisible( true ); 164 imageSprite->StopFrame( menuData->GetPlatform() + 1 ); 165 buttonSprite->SetVisible( true ); 166 buttonSprite->SetXPos( xPos ); 167 buttonText->SetText( buttons[ i ].label ); 168 xPos += ALIGNMENT_SCALE * ( buttonText->GetTextLength() + PER_BUTTON_PADDING ); 169 } 170 } else { 171 buttonSprite->SetVisible( false ); 172 idSWFScriptObject * const shortcutKeys = GetSWFObject()->GetGlobal( "shortcutKeys" ).GetObject(); 173 if ( verify( shortcutKeys != NULL ) ) { 174 buttonSprite->GetScriptObject()->Set( "onPress", NULL ); 175 // bind the main action - need to use all caps here because shortcuts are stored that way 176 shortcutName = buttonName; 177 shortcutName.ToUpper(); 178 shortcutKeys->Set( shortcutName, buttonSprite->GetScriptObject() ); 179 } 180 } 181 } 182 } 183 184 /* 185 ======================== 186 idMenuWidget_CommandBar::ReceiveEvent 187 ======================== 188 */ 189 bool idMenuWidget_CommandBar::ExecuteEvent( const idWidgetEvent & event ) { 190 if ( event.type == WIDGET_EVENT_COMMAND ) { 191 if ( verify( event.arg >= 0 && event.arg < buttons.Num() ) ) { 192 HandleAction( buttons[ event.arg ].action, event, this ); 193 } 194 return true; 195 } else { 196 return idMenuWidget::ExecuteEvent( event ); 197 } 198 }