another final fix for #620

This commit is contained in:
thrust26 2020-04-22 08:25:35 +02:00
parent f290f9ead1
commit 2938ca2fc6
2 changed files with 22 additions and 7 deletions

View File

@ -67,13 +67,28 @@ PhysicalKeyboardHandler::PhysicalKeyboardHandler(OSystem& system, EventHandler&
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalKeyboardHandler::isMappingUsed(EventMapping map)
bool PhysicalKeyboardHandler::isMappingUsed(EventMode mode, const EventMapping& map) const
{
for(int i = 0; i < int(EventMode::kNumModes); ++i)
if(myKeyMap.check(EventMode(i), map.key, map.mod))
return true;
// Menu events can only interfere with
// - other menu events
if(mode == EventMode::kMenuMode)
return myKeyMap.check(EventMode::kMenuMode, map.key, map.mod);
return false;
// Controller events can interfere with
// - other events of the same controller
// - and common emulation events
if(mode != EventMode::kCommonMode)
return myKeyMap.check(mode, map.key, map.mod)
|| myKeyMap.check(EventMode::kCommonMode, map.key, map.mod);
// Common emulation events can interfere with
// - other common emulation events
// - and all controller events
return myKeyMap.check(EventMode::kCommonMode, map.key, map.mod)
|| myKeyMap.check(EventMode::kJoystickMode, map.key, map.mod)
|| myKeyMap.check(EventMode::kPaddlesMode, map.key, map.mod)
|| myKeyMap.check(EventMode::kKeypadMode, map.key, map.mod)
|| myKeyMap.check(EventMode::kCompuMateMode, map.key, map.mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -93,7 +108,7 @@ void PhysicalKeyboardHandler::setDefaultKey(EventMapping map, Event::Type event,
// if there is no existing mapping for the event and
// the default mapping for the event is unused, set default key for event
if (myKeyMap.getEventMapping(map.event, mode).size() == 0 &&
!isMappingUsed(map))
!isMappingUsed(mode, map))
{
addMapping(map.event, mode, map.key, StellaMod(map.mod));
}

View File

@ -88,7 +88,7 @@ class PhysicalKeyboardHandler
using EventMappingArray = std::vector<EventMapping>;
// Checks if the given mapping is used by any event mode
bool isMappingUsed(EventMapping map);
bool isMappingUsed(EventMode mode, const EventMapping& map) const;
void setDefaultKey(EventMapping map, Event::Type event = Event::NoType,
EventMode mode = EventMode::kEmulationMode, bool updateDefaults = false);