From 36d462ffd6fc501ea75ed256e9c77130e03f0563 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 4 Dec 2004 04:39:51 +0000 Subject: [PATCH] figure out secondary button names dynamically --- stepmania/src/GameManager.cpp | 60 ++++++++++++++++++++++++++ stepmania/src/GameManager.h | 2 + stepmania/src/ScreenMapControllers.cpp | 2 +- stepmania/src/ScreenTestInput.cpp | 3 +- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/stepmania/src/GameManager.cpp b/stepmania/src/GameManager.cpp index 0cda1fec38..da50cad7e8 100644 --- a/stepmania/src/GameManager.cpp +++ b/stepmania/src/GameManager.cpp @@ -2862,6 +2862,66 @@ const Style* GameManager::GameAndStringToStyle( const Game *game, CString sStyle return NULL; } + +CString GameManager::GetSecondaryMenuButtonName( const Game *pGame, GameButton gb ) const +{ + /* + * Each GameButton can be used in gameplay (if any gameplay style maps to + * it) and/or map to a menu button (if m_DedicatedMenuButton or m_SecondaryMenuButton + * map to it). + * + * If a button is only used in gameplay, return ""; the primary description is + * sufficient. + * + * If a button is only used in menus, return "(dedicated)" if any other button + * maps to the same MenuButton; otherwise return "". + * + * If a button is used in both gameplay and menus, return szSecondaryNames[] for + * the MenuButton. + */ + vector aStyles; + this->GetStylesForGame( pGame, aStyles ); + bool bUsedInGameplay = false; + for( unsigned i = 0; i < aStyles.size(); ++i ) + { + const Style *pStyle = aStyles[i]; + FOREACH_GameController(gc) + { + const StyleInput si = pStyle->GameInputToStyleInput( GameInput(gc,gb) ); + if( si.IsValid() ) + bUsedInGameplay = true; + } + } + + static const char *szSecondaryNames[NUM_MENU_BUTTONS] = + { + "(MenuLeft)", + "(MenuRight)", + "(MenuUp)", + "(MenuDown)", + "(MenuStart)", + "(MenuBack)", + "(Coin)", + "(Operator)" + }; + + FOREACH_MenuButton(m) + { + if( !bUsedInGameplay && pGame->m_DedicatedMenuButton[m] == gb ) + { + if( pGame->m_SecondaryMenuButton[m] == pGame->m_DedicatedMenuButton[m] || + pGame->m_SecondaryMenuButton[m] == GAME_BUTTON_INVALID ) + return ""; + else + return "(dedicated)"; + } + else if( bUsedInGameplay && pGame->m_SecondaryMenuButton[m] == gb ) + return szSecondaryNames[m]; + } + + return ""; // only used in gameplay +} + /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/GameManager.h b/stepmania/src/GameManager.h index d5c72b62f8..20d70cd213 100644 --- a/stepmania/src/GameManager.h +++ b/stepmania/src/GameManager.h @@ -7,6 +7,7 @@ class Style; class Game; #include "GameConstantsAndTypes.h" +#include "GameInput.h" class GameManager { @@ -34,6 +35,7 @@ public: static const Game* StringToGameType( CString sGameType ); const Style* GameAndStringToStyle( const Game* pGame, CString sStyle ); static CString StyleToThemedString( const Style* s ); + CString GetSecondaryMenuButtonName( const Game *pGame, GameButton gb ) const; }; extern GameManager* GAMEMAN; // global and accessable from anywhere in our program diff --git a/stepmania/src/ScreenMapControllers.cpp b/stepmania/src/ScreenMapControllers.cpp index 51654c23fe..bb97573f73 100644 --- a/stepmania/src/ScreenMapControllers.cpp +++ b/stepmania/src/ScreenMapControllers.cpp @@ -49,7 +49,7 @@ ScreenMapControllers::ScreenMapControllers( CString sClassName ) : ScreenWithMen for( int b=0; bGetCurrentGame()->m_iButtonsPerController; b++ ) { CString sName = GAMESTATE->GetCurrentGame()->m_szButtonNames[b]; - CString sSecondary = GAMESTATE->GetCurrentGame()->m_szSecondaryFunction[b]; + CString sSecondary = GAMEMAN->GetSecondaryMenuButtonName( GAMESTATE->GetCurrentGame(), b ); m_textName[b].LoadFromFont( THEME->GetPathToF("Common title") ); m_textName[b].SetXY( SCREEN_CENTER_X, -6 ); diff --git a/stepmania/src/ScreenTestInput.cpp b/stepmania/src/ScreenTestInput.cpp index 03f69685bb..b153d4d4e8 100644 --- a/stepmania/src/ScreenTestInput.cpp +++ b/stepmania/src/ScreenTestInput.cpp @@ -8,6 +8,7 @@ #include "ThemeManager.h" #include "Game.h" #include "ScreenDimensions.h" +#include "GameManager.h" REGISTER_SCREEN_CLASS( ScreenTestInput ); @@ -58,7 +59,7 @@ void ScreenTestInput::Update( float fDeltaTime ) if( INPUTMAPPER->DeviceToGame(di,gi) ) { CString sName = GAMESTATE->GetCurrentGame()->m_szButtonNames[gi.button]; - CString sSecondary = GAMESTATE->GetCurrentGame()->m_szSecondaryFunction[gi.button]; + CString sSecondary = GAMEMAN->GetSecondaryMenuButtonName( GAMESTATE->GetCurrentGame(), gi.button ); sTemp += ssprintf(" (Controller %d %s) %s", gi.controller+1, sName.c_str(), sSecondary.c_str() ); }