improved dialogs and launcher navigation with joysticks (left and right)

This commit is contained in:
thrust26 2019-04-13 15:44:19 +02:00
parent 0cfc88e10c
commit 4e1c13ce6d
5 changed files with 46 additions and 15 deletions

View File

@ -302,21 +302,18 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
break;
case kMenuMode: // Default menu/UI events
if(stick == 0)
{
setDefaultAxis( 0, 0, 0, Event::UILeft );
setDefaultAxis( 0, 0, 1, Event::UIRight );
setDefaultAxis( 0, 1, 0, Event::UIUp );
setDefaultAxis( 0, 1, 1, Event::UIDown );
setDefaultAxis( stick, 0, 0, Event::UINavPrev );
setDefaultAxis( stick, 0, 1, Event::UINavNext );
setDefaultAxis( stick, 1, 0, Event::UIUp );
setDefaultAxis( stick, 1, 1, Event::UIDown );
// Left joystick (assume joystick zero, button zero)
setDefaultBtn( 0, 0, Event::UISelect );
// Left joystick (assume joystick zero, button zero)
setDefaultBtn( stick, 0, Event::UISelect );
setDefaultHat( 0, 0, JoyHat::LEFT, Event::UILeft );
setDefaultHat( 0, 0, JoyHat::RIGHT, Event::UIRight );
setDefaultHat( 0, 0, JoyHat::UP, Event::UIUp );
setDefaultHat( 0, 0, JoyHat::DOWN, Event::UIDown );
}
setDefaultHat( stick, 0, JoyHat::LEFT, Event::UINavPrev );
setDefaultHat( stick, 0, JoyHat::RIGHT, Event::UINavNext );
setDefaultHat( stick, 0, JoyHat::UP, Event::UIUp );
setDefaultHat( stick, 0, JoyHat::DOWN, Event::UIDown );
break;
default:

View File

@ -572,11 +572,16 @@ void Dialog::handleJoyUp(int stick, int button)
_focusedWidget->handleJoyUp(stick, button);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type Dialog::getJoyAxisEvent(int stick, int axis, int value)
{
return instance().eventHandler().eventForJoyAxis(stick, axis, value, kMenuMode);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyAxis(int stick, int axis, int value)
{
Event::Type e =
instance().eventHandler().eventForJoyAxis(stick, axis, value, kMenuMode);
Event::Type e = getJoyAxisEvent(stick, axis, value);
// Unless a widget has claimed all responsibility for data, we assume
// that if an event exists for the given data, it should have priority.

View File

@ -142,6 +142,7 @@ class Dialog : public GuiObject
virtual void handleJoyAxis(int stick, int axis, int value);
virtual bool handleJoyHat(int stick, int hat, JoyHat value);
virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
virtual Event::Type getJoyAxisEvent(int stick, int axis, int value);
Widget* findWidget(int x, int y) const; // Find the widget at pos x,y if any

View File

@ -491,6 +491,33 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod)
Dialog::handleKeyDown(key, mod);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Event::Type LauncherDialog::getJoyAxisEvent(int stick, int axis, int value)
{
Event::Type e = instance().eventHandler().eventForJoyAxis(stick, axis, value, kMenuMode);
if(myUseMinimalUI)
{
// map axis events for launcher
switch(e)
{
case Event::UINavPrev:
// convert unused previous item event into page-up event
e = Event::UIPgUp;
break;
case Event::UINavNext:
// convert unused next item event into page-down event
e = Event::UIPgDown;
break;
default:
break;
}
}
return e;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleMouseDown(int x, int y, MouseButton b, int clickCount)
{

View File

@ -88,6 +88,7 @@ class LauncherDialog : public Dialog
void handleKeyDown(StellaKey key, StellaMod mod) override;
void handleMouseDown(int x, int y, MouseButton b, int clickCount) override;
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
Event::Type LauncherDialog::getJoyAxisEvent(int stick, int axis, int value) override;
void loadConfig() override;
void updateListing(const string& nameToSelect = "");