1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-08-06 22:30:20 +00:00

improvements to key config menu

- hide actionset selection if only 1 set is present
- show keys pressed
- highlight "tabs" a bit more visually
- rumble selected controller on device select change
This commit is contained in:
fgenesis 2020-07-07 16:24:03 +02:00
parent 04bf58ab91
commit 53b027067a
4 changed files with 76 additions and 23 deletions

View file

@ -2020,17 +2020,24 @@ void InGameMenu::create()
keyConfigBg->addChild(nextJoystickBtn, PM_POINTER); keyConfigBg->addChild(nextJoystickBtn, PM_POINTER);
joystickNameText = new TTFText(&dsq->fontArialSmallest); joystickNameText = new TTFText(&dsq->fontArialSmallest);
joystickNameText->position = Vector(offx + 100 + 32, offy + 390); joystickNameText->position = Vector(offx + 100 + 32, offy + 380);
keyConfigBg->addChild(joystickNameText, PM_POINTER); keyConfigBg->addChild(joystickNameText, PM_POINTER);
joystickGUIDText = new TTFText(&dsq->fontArialSmallest); joystickGUIDText = new TTFText(&dsq->fontArialSmallest);
joystickGUIDText->position = Vector(offx + 100 + 32, offy + 390 + 15); joystickGUIDText->position = Vector(offx + 100 + 32, offy + 380 + 15);
joystickGUIDText->color = Vector(0.5f, 0.5f, 0.5f); joystickGUIDText->color = Vector(0.5f, 0.5f, 0.5f);
keyConfigBg->addChild(joystickGUIDText, PM_POINTER); keyConfigBg->addChild(joystickGUIDText, PM_POINTER);
joystickButtonsText = new TTFText(&dsq->fontArialSmallest);
joystickButtonsText->position = Vector(offx + 100 + 32, offy + 380 + 30);
joystickButtonsText->color = Vector(0.7f, 0.7f, 0.7f);
keyConfigBg->addChild(joystickButtonsText, PM_POINTER);
updateJoystickText(); updateJoystickText();
actionSetBox = NULL;
actionSetCheck = NULL;
if(dsq->user.control.actionSets.size() > 1)
{ {
float x = offx; float x = offx;
TTFText *header_actionset = new TTFText(&dsq->fontArialSmall); TTFText *header_actionset = new TTFText(&dsq->fontArialSmall);
@ -2058,6 +2065,14 @@ void InGameMenu::create()
offy += 40; offy += 40;
Quad *keyConfigPagesBg = new Quad;
keyConfigPagesBg->alphaMod = 0.6f;
keyConfigPagesBg->color = Vector(0.2f,0.2f,0.3f);
keyConfigPagesBg->position = Vector(0, offy);
keyConfigPagesBg->setWidthHeight(580, 40);
keyConfigBg->addChild(keyConfigPagesBg, PM_POINTER);
keyConfigPagesBg->moveToBack();
TTFText *header_tabs = new TTFText(&dsq->fontArialSmall); TTFText *header_tabs = new TTFText(&dsq->fontArialSmall);
header_tabs->setText(SB(2130)); header_tabs->setText(SB(2130));
header_tabs->position = Vector(offx, offy); header_tabs->position = Vector(offx, offy);
@ -2190,7 +2205,8 @@ void InGameMenu::create()
addKeyConfigLine(kk, SB(2132), "Screenshot", offx, y+=yi); addKeyConfigLine(kk, SB(2132), "Screenshot", offx, y+=yi);
} }
actionSetBox->moveToFront(); if(actionSetBox)
actionSetBox->moveToFront();
#undef SB #undef SB
@ -3972,19 +3988,22 @@ void InGameMenu::updateKeyConfigMenu(float dt)
if(!keyConfigMenu) if(!keyConfigMenu)
return; return;
bool isopen = actionSetBox->isOpen(); bool isopen = actionSetBox && actionSetBox->isOpen();
AquariaMenuItem::currentGuiInputLevel = isopen ? 50 : 0; AquariaMenuItem::currentGuiInputLevel = isopen ? 50 : 0;
float a = isopen ? 0.0f : 1.0f; float a = isopen ? 0.0f : 1.0f;
// HACK: debug buttons ignore input at < 1 alpha // HACK: debug buttons ignore input at < 1 alpha
for(size_t i = 0; i < keyCategoryButtons.size(); ++i) for(size_t i = 0; i < keyCategoryButtons.size(); ++i)
keyCategoryButtons[i]->alpha = a; keyCategoryButtons[i]->alpha = a;
const int curAS = actionSetBox->getSelectedItem(); if(actionSetBox)
if(selectedActionSetIdx != curAS) {
switchToActionSet(curAS); const int curAS = actionSetBox->getSelectedItem();
if(selectedActionSetIdx != curAS)
switchToActionSet(curAS);
dsq->user.control.actionSets[selectedActionSetIdx].enabled dsq->user.control.actionSets[selectedActionSetIdx].enabled
= actionSetCheck->getValue(); = actionSetCheck->getValue();
}
updateJoystickText(); updateJoystickText();
} }
@ -4186,8 +4205,11 @@ void InGameMenu::onDebugSave()
void InGameMenu::switchToActionSet(int idx) void InGameMenu::switchToActionSet(int idx)
{ {
selectedActionSetIdx = idx; selectedActionSetIdx = idx;
actionSetBox->setSelectedItem(idx); if(actionSetBox)
actionSetCheck->setValue(dsq->user.control.actionSets[idx].enabled); {
actionSetBox->setSelectedItem(idx);
actionSetCheck->setValue(dsq->user.control.actionSets[idx].enabled);
}
for(size_t i = 0; i < keyConfigs.size(); ++i) for(size_t i = 0; i < keyConfigs.size(); ++i)
keyConfigs[i]->setActionSetIndex(idx); keyConfigs[i]->setActionSetIndex(idx);
} }
@ -4223,6 +4245,9 @@ void InGameMenu::nextJoystick()
} }
while (!j); while (!j);
if(j)
j->rumble(0.3f, 0.3f, 0.2f);
as.assignJoystickIdx(i, true); as.assignJoystickIdx(i, true);
if(as.joystickID < 0) if(as.joystickID < 0)
as.joystickName = "NONE"; as.joystickName = "NONE";
@ -4233,8 +4258,16 @@ void InGameMenu::updateJoystickText()
{ {
ActionSet& as = dsq->user.control.actionSets[selectedActionSetIdx]; ActionSet& as = dsq->user.control.actionSets[selectedActionSetIdx];
Joystick *j = core->getJoystick(as.joystickID); Joystick *j = core->getJoystick(as.joystickID);
std::ostringstream jbt;
if(j) if(j)
{
joystickNameText->setText(j->getName()); joystickNameText->setText(j->getName());
int numb = j->getNumButtons();
for(int i = 0; i < numb; ++i)
if(j->getButton(i))
jbt << i << " ";
}
else if(as.joystickID == ACTIONSET_REASSIGN_JOYSTICK) else if(as.joystickID == ACTIONSET_REASSIGN_JOYSTICK)
{ {
std::string s = "("; std::string s = "(";
@ -4247,6 +4280,8 @@ void InGameMenu::updateJoystickText()
else else
joystickNameText->setText(stringbank.get(2139)); joystickNameText->setText(stringbank.get(2139));
joystickButtonsText->setText(jbt.str());
if(j && as.joystickID >= 0) if(j && as.joystickID >= 0)
joystickGUIDText->setText(as.joystickGUID); joystickGUIDText->setText(as.joystickGUID);
else else

View file

@ -221,7 +221,7 @@ private:
AquariaComboBox *actionSetBox; AquariaComboBox *actionSetBox;
AquariaCheckBox *actionSetCheck; AquariaCheckBox *actionSetCheck;
int selectedActionSetIdx; int selectedActionSetIdx;
TTFText *joystickNameText, *joystickGUIDText; TTFText *joystickNameText, *joystickGUIDText, *joystickButtonsText;
void updateActionSetComboBox(); void updateActionSetComboBox();
void switchToActionSet(int idx); void switchToActionSet(int idx);
void nextJoystick(); void nextJoystick();

View file

@ -45,6 +45,8 @@ Joystick::Joystick()
clearRumbleTime= 0; clearRumbleTime= 0;
numJoyAxes = 0; numJoyAxes = 0;
numHats = 0;
numButtons = 0;
clearAxes(); clearAxes();
s1ax = 0; s1ax = 0;
@ -136,7 +138,8 @@ bool Joystick::init(int stick)
if(numJoyAxes > MAX_JOYSTICK_AXIS) if(numJoyAxes > MAX_JOYSTICK_AXIS)
numJoyAxes = MAX_JOYSTICK_AXIS; numJoyAxes = MAX_JOYSTICK_AXIS;
numHats = SDL_JoystickNumHats(sdl_joy);
numButtons = SDL_JoystickNumButtons(sdl_joy);
return true; return true;
@ -243,7 +246,7 @@ void Joystick::update(float dt)
} }
if (sdl_controller) if (sdl_controller)
{ {
for(int i = 0; i < numJoyAxes; ++i) for(unsigned i = 0; i < numJoyAxes; ++i)
{ {
Sint16 ax = SDL_GameControllerGetAxis(sdl_controller, (SDL_GameControllerAxis)i); Sint16 ax = SDL_GameControllerGetAxis(sdl_controller, (SDL_GameControllerAxis)i);
axisRaw[i] = float(ax)/32768.0f; axisRaw[i] = float(ax)/32768.0f;
@ -265,7 +268,7 @@ void Joystick::update(float dt)
#endif #endif
// Note: this connects with the else above when the SDL2 path is compiled! // Note: this connects with the else above when the SDL2 path is compiled!
{ {
for(int i = 0; i < numJoyAxes; ++i) for(unsigned i = 0; i < numJoyAxes; ++i)
{ {
Sint16 ax = SDL_JoystickGetAxis(sdl_joy, i); Sint16 ax = SDL_JoystickGetAxis(sdl_joy, i);
axisRaw[i] = float(ax)/32768.0f; axisRaw[i] = float(ax)/32768.0f;
@ -290,8 +293,10 @@ void Joystick::update(float dt)
else else
#endif #endif
{ {
for (unsigned i = 0; i < MAX_JOYSTICK_BTN; i++) for (unsigned i = 0; i < numButtons; i++)
buttonBitmask |= !!SDL_JoystickGetButton(sdl_joy, i) << i; buttonBitmask |= !!SDL_JoystickGetButton(sdl_joy, i) << i;
//for (unsigned i = 0; i < numHats; i++)
} }
} }
@ -310,7 +315,7 @@ bool Joystick::anyButton() const
return !!buttonBitmask;; return !!buttonBitmask;;
} }
int Joystick::getNumAxes() const unsigned Joystick::getNumAxes() const
{ {
#ifdef BBGE_BUILD_SDL2 #ifdef BBGE_BUILD_SDL2
return sdl_controller ? SDL_CONTROLLER_AXIS_MAX : numJoyAxes; return sdl_controller ? SDL_CONTROLLER_AXIS_MAX : numJoyAxes;
@ -319,12 +324,22 @@ int Joystick::getNumAxes() const
#endif #endif
} }
unsigned Joystick::getNumButtons() const
{
return numButtons;
}
unsigned Joystick::getNumHats() const
{
return numHats;
}
float Joystick::getAxisUncalibrated(int id) const float Joystick::getAxisUncalibrated(int id) const
{ {
return id < MAX_JOYSTICK_AXIS ? axisRaw[id] : 0.0f; return id < MAX_JOYSTICK_AXIS ? axisRaw[id] : 0.0f;
} }
const char *Joystick::getAxisName(int axis) const const char *Joystick::getAxisName(unsigned axis) const
{ {
if(axis >= numJoyAxes) if(axis >= numJoyAxes)
return NULL; return NULL;
@ -335,7 +350,7 @@ const char *Joystick::getAxisName(int axis) const
return NULL; return NULL;
} }
const char *Joystick::getButtonName(int btn) const const char *Joystick::getButtonName(unsigned btn) const
{ {
#ifdef BBGE_BUILD_SDL2 #ifdef BBGE_BUILD_SDL2
if(sdl_controller) if(sdl_controller)

View file

@ -13,6 +13,7 @@
#define MAX_JOYSTICK_BTN 32 #define MAX_JOYSTICK_BTN 32
#define MAX_JOYSTICK_AXIS 32 #define MAX_JOYSTICK_AXIS 32
#define MAX_JOYSTICK_HATS 8
const static float JOY_AXIS_THRESHOLD = 0.6f; const static float JOY_AXIS_THRESHOLD = 0.6f;
@ -38,14 +39,16 @@ public:
bool anyButton() const; bool anyButton() const;
bool getButton(size_t id) const { return !!(buttonBitmask & (1u << id)); } bool getButton(size_t id) const { return !!(buttonBitmask & (1u << id)); }
float getAxisUncalibrated(int id) const; float getAxisUncalibrated(int id) const;
int getNumAxes() const; unsigned getNumAxes() const;
unsigned getNumButtons() const;
unsigned getNumHats() const;
int getIndex() const { return stickIndex; } int getIndex() const { return stickIndex; }
int getInstanceID() const { return instanceID; } int getInstanceID() const { return instanceID; }
inline bool isEnabled() const { return enabled; } inline bool isEnabled() const { return enabled; }
inline void setEnabled(bool on) { enabled = on; } inline void setEnabled(bool on) { enabled = on; }
const char *getAxisName(int axis) const; const char *getAxisName(unsigned axis) const;
const char *getButtonName(int btn) const; const char *getButtonName(unsigned btn) const;
const char *getName() const; const char *getName() const;
const char *getGUID() const; const char *getGUID() const;
@ -59,7 +62,7 @@ private:
int stickIndex; int stickIndex;
int instanceID; int instanceID;
unsigned buttonBitmask; unsigned buttonBitmask;
int numJoyAxes; unsigned numJoyAxes, numHats, numButtons;
SDL_Joystick *sdl_joy; SDL_Joystick *sdl_joy;
float axisRaw[MAX_JOYSTICK_AXIS]; float axisRaw[MAX_JOYSTICK_AXIS];
std::string name; std::string name;