better encapsulation, reduce GameLoop.cpp depending on StepMania.cpp: move
CheckForChangedInputDevicesAndRemap into InputMapper
This commit is contained in:
@@ -512,6 +512,45 @@ void InputMapper::SaveMappingsToDisk()
|
|||||||
ini.WriteFile( SpecialFiles::KEYMAPS_PATH );
|
ini.WriteFile( SpecialFiles::KEYMAPS_PATH );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InputMapper::CheckForChangedInputDevicesAndRemap( CString &sMessage )
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// update last seen joysticks
|
||||||
|
//
|
||||||
|
vector<InputDevice> vDevices;
|
||||||
|
vector<CString> vsDescriptions;
|
||||||
|
INPUTMAN->GetDevicesAndDescriptions( vDevices, vsDescriptions );
|
||||||
|
CString sInputDevices = join( ",", vsDescriptions );
|
||||||
|
|
||||||
|
if( PREFSMAN->m_sLastSeenInputDevices.Get() == sInputDevices )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vector<CString> vsLastSeen;
|
||||||
|
split( PREFSMAN->m_sLastSeenInputDevices, ",", vsLastSeen );
|
||||||
|
|
||||||
|
vector<CString> vsConnects, vsDisconnects;
|
||||||
|
GetConnectsDisconnects( vsLastSeen, vsDescriptions, vsDisconnects, vsConnects );
|
||||||
|
|
||||||
|
sMessage.clear();
|
||||||
|
if( !vsConnects.empty() )
|
||||||
|
sMessage += "Connected: " + join( "\n", vsConnects ) + "\n";
|
||||||
|
if( !vsDisconnects.empty() )
|
||||||
|
sMessage += "Disconnected: " + join( "\n", vsDisconnects ) + "\n";
|
||||||
|
|
||||||
|
if( PREFSMAN->m_bAutoMapOnJoyChange )
|
||||||
|
{
|
||||||
|
sMessage += "Remapping all joysticks.";
|
||||||
|
AutoMapJoysticksForCurrentGame();
|
||||||
|
SaveMappingsToDisk();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG->Info( sMessage );
|
||||||
|
|
||||||
|
PREFSMAN->m_sLastSeenInputDevices.Set( sInputDevices );
|
||||||
|
PREFSMAN->SavePrefsToDisk();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void InputMapper::SetInputMap( const DeviceInput &DeviceI, const GameInput &GameI, int iSlotIndex )
|
void InputMapper::SetInputMap( const DeviceInput &DeviceI, const GameInput &GameI, int iSlotIndex )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public:
|
|||||||
|
|
||||||
void AddDefaultMappingsForCurrentGameIfUnmapped();
|
void AddDefaultMappingsForCurrentGameIfUnmapped();
|
||||||
void AutoMapJoysticksForCurrentGame();
|
void AutoMapJoysticksForCurrentGame();
|
||||||
|
bool CheckForChangedInputDevicesAndRemap( CString &sMessageOut );
|
||||||
|
|
||||||
bool IsMapped( const DeviceInput &DeviceI );
|
bool IsMapped( const DeviceInput &DeviceI );
|
||||||
bool IsMapped( const GameInput &GameI );
|
bool IsMapped( const GameInput &GameI );
|
||||||
|
|||||||
@@ -292,47 +292,6 @@ void StepMania::ResetGame()
|
|||||||
PREFSMAN->SavePrefsToDisk();
|
PREFSMAN->SavePrefsToDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepMania::CheckForChangedInputDevicesAndRemap()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// update last seen joysticks
|
|
||||||
//
|
|
||||||
vector<InputDevice> vDevices;
|
|
||||||
vector<CString> vsDescriptions;
|
|
||||||
INPUTMAN->GetDevicesAndDescriptions( vDevices, vsDescriptions );
|
|
||||||
CString sInputDevices = join( ",", vsDescriptions );
|
|
||||||
|
|
||||||
if( PREFSMAN->m_sLastSeenInputDevices.Get() != sInputDevices )
|
|
||||||
{
|
|
||||||
vector<CString> vsLastSeen;
|
|
||||||
split( PREFSMAN->m_sLastSeenInputDevices, ",", vsLastSeen );
|
|
||||||
|
|
||||||
vector<CString> vsConnects, vsDisconnects;
|
|
||||||
GetConnectsDisconnects( vsLastSeen, vsDescriptions, vsDisconnects, vsConnects );
|
|
||||||
|
|
||||||
CString sMessage;
|
|
||||||
|
|
||||||
if( !vsConnects.empty() )
|
|
||||||
sMessage += "Connected: " + join( "\n", vsConnects ) + "\n";
|
|
||||||
if( !vsDisconnects.empty() )
|
|
||||||
sMessage += "Disconnected: " + join( "\n", vsDisconnects ) + "\n";
|
|
||||||
|
|
||||||
if( PREFSMAN->m_bAutoMapOnJoyChange )
|
|
||||||
{
|
|
||||||
sMessage += "Remapping all joysticks.";
|
|
||||||
INPUTMAPPER->AutoMapJoysticksForCurrentGame();
|
|
||||||
INPUTMAPPER->SaveMappingsToDisk();
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG->Info( sMessage );
|
|
||||||
SCREENMAN->SystemMessage( sMessage );
|
|
||||||
|
|
||||||
PREFSMAN->m_sLastSeenInputDevices.Set( sInputDevices );
|
|
||||||
}
|
|
||||||
|
|
||||||
PREFSMAN->SavePrefsToDisk();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ChangeAppPri()
|
static bool ChangeAppPri()
|
||||||
{
|
{
|
||||||
if( PREFSMAN->m_BoostAppPriority.Get() == PrefsManager::BOOST_NO )
|
if( PREFSMAN->m_BoostAppPriority.Get() == PrefsManager::BOOST_NO )
|
||||||
@@ -1142,7 +1101,9 @@ int main(int argc, char* argv[])
|
|||||||
SCREENMAN->SetNewScreen( CommonMetrics::INITIAL_SCREEN );
|
SCREENMAN->SetNewScreen( CommonMetrics::INITIAL_SCREEN );
|
||||||
|
|
||||||
// Do this after ThemeChanged so that we can show a system message
|
// Do this after ThemeChanged so that we can show a system message
|
||||||
StepMania::CheckForChangedInputDevicesAndRemap();
|
CString sMessage;
|
||||||
|
if( INPUTMAPPER->CheckForChangedInputDevicesAndRemap(sMessage) )
|
||||||
|
SCREENMAN->SystemMessage( sMessage );
|
||||||
|
|
||||||
CodeDetector::RefreshCacheItems();
|
CodeDetector::RefreshCacheItems();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ namespace StepMania
|
|||||||
void ApplyGraphicOptions();
|
void ApplyGraphicOptions();
|
||||||
void NORETURN HandleException( CString error );
|
void NORETURN HandleException( CString error );
|
||||||
void ResetGame();
|
void ResetGame();
|
||||||
void CheckForChangedInputDevicesAndRemap();
|
|
||||||
void ChangeCurrentGame( const Game* g );
|
void ChangeCurrentGame( const Game* g );
|
||||||
void FocusChanged( bool bHasFocus );
|
void FocusChanged( bool bHasFocus );
|
||||||
bool AppHasFocus();
|
bool AppHasFocus();
|
||||||
|
|||||||
Reference in New Issue
Block a user