Files
itgmania212121/stepmania/src/InputMapper.h
T

136 lines
5.2 KiB
C++
Raw Normal View History

2004-06-08 01:24:17 +00:00
/* InputMapper - Holds user-chosen input preferences and saves it between sessions. */
2006-09-02 20:17:17 +00:00
#ifndef INPUT_MAPPER_H
#define INPUT_MAPPER_H
2002-04-16 17:31:00 +00:00
#include "RageInputDevice.h"
2002-04-16 17:31:00 +00:00
#include "GameInput.h"
#include "MenuInput.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2002-04-16 17:31:00 +00:00
const int NUM_GAME_TO_DEVICE_SLOTS = 5; // five device inputs may map to one game input
const int NUM_SHOWN_GAME_TO_DEVICE_SLOTS = 3;
const int NUM_USER_GAME_TO_DEVICE_SLOTS = 2;
2002-04-16 17:31:00 +00:00
class InputScheme
{
public:
const char *m_szName;
int m_iButtonsPerController;
char m_szButtonNames[NUM_GameButton][60]; // The name used by the button graphics system. e.g. "left", "right", "middle C", "snare"
GameButton m_DedicatedMenuButton[NUM_MenuButton];
GameButton m_SecondaryMenuButton[NUM_MenuButton];
DeviceButton m_iDefaultKeyboardKey[NUM_GameController][NUM_GameButton]; // default keyboard keys only have an effect the current game is this game
int GetNumGameplayButtons() const;
GameButton ButtonNameToIndex( const RString &sButtonName ) const;
MenuButton GameInputToMenuButton( GameInput GameI ) const;
void MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const;
};
2002-04-16 17:31:00 +00:00
class InputMapper
{
public:
InputMapper();
~InputMapper();
void SetInputScheme( const InputScheme *pInputScheme );
const InputScheme *GetInputScheme() const;
2002-04-16 17:31:00 +00:00
void ReadMappingsFromDisk();
void SaveMappingsToDisk();
void ClearAllMappings();
2002-04-16 17:31:00 +00:00
2005-10-15 16:47:44 +00:00
void SetInputMap( const DeviceInput &DeviceI, const GameInput &GameI, int iSlotIndex );
void ClearFromInputMap( const DeviceInput &DeviceI );
2005-12-09 03:05:17 +00:00
bool ClearFromInputMap( const GameInput &GameI, int iSlotIndex );
void AddDefaultMappingsForCurrentGameIfUnmapped();
2003-05-28 02:35:05 +00:00
void AutoMapJoysticksForCurrentGame();
2006-01-22 01:00:06 +00:00
bool CheckForChangedInputDevicesAndRemap( RString &sMessageOut );
2005-10-15 16:47:44 +00:00
bool IsMapped( const DeviceInput &DeviceI );
2002-04-16 17:31:00 +00:00
2005-10-15 16:47:44 +00:00
bool DeviceToGame( const DeviceInput &DeviceI, GameInput& GameI ); // return true if there is a mapping from device to pad
2006-09-13 08:24:21 +00:00
bool GameToDevice( const GameInput &GameI, int iSlotNum, DeviceInput& DeviceI ); // return true if there is a mapping from pad to device
2002-04-16 17:31:00 +00:00
2006-09-14 20:37:41 +00:00
MenuButton GameToMenu( const GameInput &GameI );
2006-09-14 20:45:51 +00:00
void MenuToGame( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] );
PlayerNumber ControllerToPlayerNumber( GameController controller );
2002-04-16 17:31:00 +00:00
2006-07-01 02:16:38 +00:00
float GetSecsHeld( const GameInput &GameI, MultiPlayer mp = MultiPlayer_INVALID );
2006-09-14 20:45:51 +00:00
float GetSecsHeld( MenuButton MenuI, PlayerNumber pn );
2002-10-18 19:01:32 +00:00
2006-09-08 04:04:40 +00:00
bool IsBeingPressed( const GameInput &GameI, MultiPlayer mp = MultiPlayer_INVALID, const DeviceInputList *pButtonState = NULL );
2006-09-14 20:45:51 +00:00
bool IsBeingPressed( MenuButton MenuI, PlayerNumber pn );
2002-04-16 17:31:00 +00:00
2005-10-15 16:47:44 +00:00
void ResetKeyRepeat( const GameInput &GameI );
2006-09-14 20:45:51 +00:00
void ResetKeyRepeat( MenuButton MenuI, PlayerNumber pn );
void RepeatStopKey( const GameInput &GameI );
void RepeatStopKey( MenuButton MenuI, PlayerNumber pn );
2006-09-13 08:23:28 +00:00
struct Mapping
{
2004-08-13 00:27:52 +00:00
bool IsEndMarker() const { return iSlotIndex==-1; }
int iSlotIndex; // -1 == end marker
DeviceButton deviceButton;
2004-08-13 00:27:52 +00:00
GameButton gb;
2006-09-13 08:23:28 +00:00
/*
* If this is true, this is an auxilliary mapping assigned to the second
* player. If two of the same device are found, and the device has secondary
* entries, the later entries take precedence. This way, if a Pump pad is
* found, it'll map P1 to the primary pad and P2 to the secondary pad.
* (We can't tell if a slave pad is actually there.) Then, if a second primary
* is found (DEVICE_PUMP2), 2P will be mapped to it.
*/
2004-08-13 00:27:52 +00:00
bool SecondController;
};
2005-08-30 16:22:48 +00:00
static InputDevice MultiPlayerToInputDevice( MultiPlayer mp );
static MultiPlayer InputDeviceToMultiPlayer( InputDevice id );
void Unmap( InputDevice device );
2004-08-13 00:27:52 +00:00
void ApplyMapping( const Mapping *maps, GameController gc, InputDevice device );
2002-04-16 17:31:00 +00:00
protected:
// all the DeviceInputs that map to a GameInput
2006-09-27 04:39:51 +00:00
DeviceInput m_GItoDI[NUM_GameController][NUM_GameButton][NUM_GAME_TO_DEVICE_SLOTS];
2002-04-16 17:31:00 +00:00
void UpdateTempDItoGI();
const InputScheme *m_pInputScheme;
2002-04-16 17:31:00 +00:00
};
2002-05-19 01:59:48 +00:00
extern InputMapper* INPUTMAPPER; // global and accessable from anywhere in our program
#endif
2004-06-08 01:24:17 +00:00
/*
* (c) 2001-2003 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/