This commit is contained in:
thrust26 2019-06-14 21:49:39 +02:00
parent 3b1be03f74
commit d969d9152b
3 changed files with 64 additions and 98 deletions

View File

@ -167,109 +167,49 @@ void PhysicalKeyboardHandler::enableControllerEvents()
switch (myRightMode)
{
case kPaddlesMode:
enableRightPaddlesMapping();
enableMappings(RightPaddlesEvents, kPaddlesMode);
break;
case kKeypadMode:
enableRightKeypadMapping();
enableMappings(RightKeypadEvents, kKeypadMode);
break;
default:
enableRightJoystickMapping();
enableMappings(RightJoystickEvents, kJoystickMode);
break;
}
switch (myLeftMode)
{
case kPaddlesMode:
enableLeftPaddlesMapping();
enableMappings(LeftPaddlesEvents, kPaddlesMode);
break;
case kKeypadMode:
enableLeftKeypadMapping();
enableMappings(LeftKeypadEvents, kKeypadMode);
break;
default:
enableLeftJoystickMapping();
enableMappings(LeftJoystickEvents, kJoystickMode);
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableLeftJoystickMapping(bool enable)
void PhysicalKeyboardHandler::enableMappings(const EventSet events, EventMode mode, bool enable)
{
for (const auto& event: LeftJoystickEvents)
{
// copy from controller specific mode into emulation mode
std::vector<KeyMap::Mapping> mappings = myKeyMap.getEventMapping(event, kJoystickMode);
enableMappings(event, mappings, enable);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableRightJoystickMapping(bool enable)
{
for (const auto& event: RightJoystickEvents)
{
// copy from controller specific mode into emulation mode
std::vector<KeyMap::Mapping> mappings = myKeyMap.getEventMapping(event, kJoystickMode);
enableMappings(event, mappings, enable);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableLeftPaddlesMapping(bool enable)
{
for (const auto& event: LeftPaddlesEvents)
for (const auto& event : events)
{
// copy from controller mode into emulation mode
std::vector<KeyMap::Mapping> mappings = myKeyMap.getEventMapping(event, kPaddlesMode);
enableMappings(event, mappings, enable);
}
}
std::vector<KeyMap::Mapping> mappings = myKeyMap.getEventMapping(event, mode);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableRightPaddlesMapping(bool enable)
{
for (const auto& event: RightPaddlesEvents)
{
// copy from controller mode into emulation mode
std::vector<KeyMap::Mapping> mappings = myKeyMap.getEventMapping(event, kPaddlesMode);
enableMappings(event, mappings, enable);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableLeftKeypadMapping(bool enable)
{
for (const auto& event: LeftKeypadEvents)
{
// copy from controller mode into emulation mode
std::vector<KeyMap::Mapping> mappings = myKeyMap.getEventMapping(event, kKeypadMode);
enableMappings(event, mappings, enable);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableRightKeypadMapping(bool enable)
{
for (const auto& event: RightKeypadEvents)
{
// copy from controller mode into emulation mode
std::vector<KeyMap::Mapping> mappings = myKeyMap.getEventMapping(event, kKeypadMode);
enableMappings(event, mappings, enable);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PhysicalKeyboardHandler::enableMappings(Event::Type event, std::vector<KeyMap::Mapping> mappings, bool enable)
{
for (const auto& mapping: mappings)
{
if (enable)
myKeyMap.add(event, kEmulationMode, mapping.key, mapping.mod);
else
myKeyMap.eraseEvent(event, kEmulationMode);
for (const auto& mapping : mappings)
{
if (enable)
myKeyMap.add(event, kEmulationMode, mapping.key, mapping.mod);
else
myKeyMap.eraseEvent(event, kEmulationMode);
}
}
}
@ -321,12 +261,12 @@ void PhysicalKeyboardHandler::saveMapping()
{
myOSystem.settings().setValue("event_ver", Event::VERSION);
// remove controller specific events in emulation mode mapping
enableLeftJoystickMapping(false);
enableRightJoystickMapping(false);
enableLeftPaddlesMapping(false);
enableRightPaddlesMapping(false);
enableLeftKeypadMapping(false);
enableRightKeypadMapping(false);
enableMappings(LeftJoystickEvents, kJoystickMode, false);
enableMappings(LeftPaddlesEvents, kPaddlesMode, false);
enableMappings(LeftKeypadEvents, kKeypadMode, false);
enableMappings(RightJoystickEvents, kJoystickMode, false);
enableMappings(RightPaddlesEvents, kPaddlesMode, false);
enableMappings(RightKeypadEvents, kKeypadMode, false);
myOSystem.settings().setValue("keymap_emu", myKeyMap.saveMapping(kEmulationMode));
// restore current controller's event mappings
enableControllerEvents();
@ -336,12 +276,6 @@ void PhysicalKeyboardHandler::saveMapping()
myOSystem.settings().setValue("keymap_ui", myKeyMap.saveMapping(kMenuMode));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string PhysicalKeyboardHandler::getMappingDesc(Event::Type event, EventMode mode) const
{
return myKeyMap.getEventMappingDesc(event, getEventMode(event, mode));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalKeyboardHandler::addMapping(Event::Type event, EventMode mode,
StellaKey key, StellaMod mod)
@ -385,6 +319,16 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool pre
EventHandlerState estate = myHandler.state();
// special handling for CompuMate in emulation modes
if ((estate == EventHandlerState::EMULATION || estate == EventHandlerState::PAUSE) &&
myOSystem.console().leftController().type() == Controller::Type::CompuMate)
{
if (myKeyMap.get(kEmulationMode, key, mod) != Event::ExitMode &&
CompuMateKeys.find(key) != CompuMateKeys.end())
// supress all events (except exit mode) using CompuMate keys
return;
}
// Arrange the logic to take advantage of short-circuit evaluation
if(!(StellaModTest::isControl(mod) || StellaModTest::isShift(mod) || StellaModTest::isAlt(mod)))
{
@ -669,3 +613,25 @@ PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::DefaultKeypa
{Event::KeyboardOne0, KBDK_PERIOD},
{Event::KeyboardOnePound, KBDK_SLASH},
};
PhysicalKeyboardHandler::StellaKeySet PhysicalKeyboardHandler::CompuMateKeys = {
{KBDK_0}, {KBDK_1}, {KBDK_2}, {KBDK_3}, {KBDK_4},
{KBDK_5}, {KBDK_6}, {KBDK_7}, {KBDK_8}, {KBDK_9},
{KBDK_A}, {KBDK_B}, {KBDK_C}, {KBDK_D}, {KBDK_E},
{KBDK_F}, {KBDK_G}, {KBDK_H}, {KBDK_I}, {KBDK_J},
{KBDK_K}, {KBDK_L}, {KBDK_M}, {KBDK_N}, {KBDK_O},
{KBDK_P}, {KBDK_Q}, {KBDK_R}, {KBDK_S}, {KBDK_T},
{KBDK_U}, {KBDK_V}, {KBDK_W}, {KBDK_X}, {KBDK_Y},
{KBDK_Z},
{KBDK_COMMA},
{KBDK_PERIOD},
{KBDK_RETURN}, {KBDK_KP_ENTER},
{KBDK_SPACE},
{KBDK_BACKSPACE},
{KBDK_EQUALS},
{KBDK_MINUS},
{KBDK_SLASH},
{KBDK_LEFTBRACKET},
{KBDK_RIGHTBRACKET},
{KBDK_APOSTROPHE}
};

View File

@ -55,7 +55,10 @@ class PhysicalKeyboardHandler
void eraseMapping(Event::Type event, EventMode mode);
void saveMapping();
string getMappingDesc(Event::Type, EventMode mode) const;
string getMappingDesc(Event::Type event, EventMode mode) const {
return myKeyMap.getEventMappingDesc(event, getEventMode(event, mode));
}
/** Bind a physical keyboard event to a virtual event/action. */
bool addMapping(Event::Type event, EventMode mode, StellaKey key, StellaMod mod);
@ -83,6 +86,9 @@ class PhysicalKeyboardHandler
};
using EventMappingArray = std::vector<EventMapping>;
// Used for CompuMate keys only
using StellaKeySet = std::set<StellaKey>;
void setDefaultKey(EventMapping map, Event::Type event = Event::NoType,
EventMode mode = kEmulationMode, bool updateDefaults = false);
@ -97,13 +103,7 @@ class PhysicalKeyboardHandler
void enableControllerEvents();
void enableLeftJoystickMapping(bool enable = true);
void enableRightJoystickMapping(bool enable = true);
void enableLeftPaddlesMapping(bool enable = true);
void enableRightPaddlesMapping(bool enable = true);
void enableLeftKeypadMapping(bool enable = true);
void enableRightKeypadMapping(bool enable = true);
void enableMappings(Event::Type event, std::vector<KeyMap::Mapping> mappings, bool enable);
void enableMappings(const EventSet events, EventMode mode, bool enable = true);
OSystem& myOSystem;
EventHandler& myHandler;
@ -141,6 +141,8 @@ class PhysicalKeyboardHandler
static EventMappingArray DefaultJoystickMapping;
static EventMappingArray DefaultPaddleMapping;
static EventMappingArray DefaultKeypadMapping;
static StellaKeySet CompuMateKeys;
};
#endif

View File

@ -1517,8 +1517,6 @@ void EventHandler::setState(EventHandlerState state)
case EventHandlerState::EMULATION:
myOSystem.sound().mute(false);
enableTextEvents(false);
if(myOSystem.console().leftController().type() == Controller::Type::CompuMate)
myPKeyHandler->useModKeys() = false;
break;
case EventHandlerState::PAUSE: