mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-04-07 23:27:12 +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:
parent
04bf58ab91
commit
53b027067a
4 changed files with 76 additions and 23 deletions
|
@ -2020,17 +2020,24 @@ void InGameMenu::create()
|
|||
keyConfigBg->addChild(nextJoystickBtn, PM_POINTER);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
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();
|
||||
|
||||
actionSetBox = NULL;
|
||||
actionSetCheck = NULL;
|
||||
if(dsq->user.control.actionSets.size() > 1)
|
||||
{
|
||||
float x = offx;
|
||||
TTFText *header_actionset = new TTFText(&dsq->fontArialSmall);
|
||||
|
@ -2058,6 +2065,14 @@ void InGameMenu::create()
|
|||
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);
|
||||
header_tabs->setText(SB(2130));
|
||||
header_tabs->position = Vector(offx, offy);
|
||||
|
@ -2190,7 +2205,8 @@ void InGameMenu::create()
|
|||
addKeyConfigLine(kk, SB(2132), "Screenshot", offx, y+=yi);
|
||||
}
|
||||
|
||||
actionSetBox->moveToFront();
|
||||
if(actionSetBox)
|
||||
actionSetBox->moveToFront();
|
||||
|
||||
|
||||
#undef SB
|
||||
|
@ -3972,19 +3988,22 @@ void InGameMenu::updateKeyConfigMenu(float dt)
|
|||
if(!keyConfigMenu)
|
||||
return;
|
||||
|
||||
bool isopen = actionSetBox->isOpen();
|
||||
bool isopen = actionSetBox && actionSetBox->isOpen();
|
||||
AquariaMenuItem::currentGuiInputLevel = isopen ? 50 : 0;
|
||||
float a = isopen ? 0.0f : 1.0f;
|
||||
// HACK: debug buttons ignore input at < 1 alpha
|
||||
for(size_t i = 0; i < keyCategoryButtons.size(); ++i)
|
||||
keyCategoryButtons[i]->alpha = a;
|
||||
|
||||
const int curAS = actionSetBox->getSelectedItem();
|
||||
if(selectedActionSetIdx != curAS)
|
||||
switchToActionSet(curAS);
|
||||
if(actionSetBox)
|
||||
{
|
||||
const int curAS = actionSetBox->getSelectedItem();
|
||||
if(selectedActionSetIdx != curAS)
|
||||
switchToActionSet(curAS);
|
||||
|
||||
dsq->user.control.actionSets[selectedActionSetIdx].enabled
|
||||
= actionSetCheck->getValue();
|
||||
dsq->user.control.actionSets[selectedActionSetIdx].enabled
|
||||
= actionSetCheck->getValue();
|
||||
}
|
||||
|
||||
updateJoystickText();
|
||||
}
|
||||
|
@ -4186,8 +4205,11 @@ void InGameMenu::onDebugSave()
|
|||
void InGameMenu::switchToActionSet(int idx)
|
||||
{
|
||||
selectedActionSetIdx = idx;
|
||||
actionSetBox->setSelectedItem(idx);
|
||||
actionSetCheck->setValue(dsq->user.control.actionSets[idx].enabled);
|
||||
if(actionSetBox)
|
||||
{
|
||||
actionSetBox->setSelectedItem(idx);
|
||||
actionSetCheck->setValue(dsq->user.control.actionSets[idx].enabled);
|
||||
}
|
||||
for(size_t i = 0; i < keyConfigs.size(); ++i)
|
||||
keyConfigs[i]->setActionSetIndex(idx);
|
||||
}
|
||||
|
@ -4223,6 +4245,9 @@ void InGameMenu::nextJoystick()
|
|||
}
|
||||
while (!j);
|
||||
|
||||
if(j)
|
||||
j->rumble(0.3f, 0.3f, 0.2f);
|
||||
|
||||
as.assignJoystickIdx(i, true);
|
||||
if(as.joystickID < 0)
|
||||
as.joystickName = "NONE";
|
||||
|
@ -4233,8 +4258,16 @@ void InGameMenu::updateJoystickText()
|
|||
{
|
||||
ActionSet& as = dsq->user.control.actionSets[selectedActionSetIdx];
|
||||
Joystick *j = core->getJoystick(as.joystickID);
|
||||
std::ostringstream jbt;
|
||||
|
||||
if(j)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::string s = "(";
|
||||
|
@ -4247,6 +4280,8 @@ void InGameMenu::updateJoystickText()
|
|||
else
|
||||
joystickNameText->setText(stringbank.get(2139));
|
||||
|
||||
joystickButtonsText->setText(jbt.str());
|
||||
|
||||
if(j && as.joystickID >= 0)
|
||||
joystickGUIDText->setText(as.joystickGUID);
|
||||
else
|
||||
|
|
|
@ -221,7 +221,7 @@ private:
|
|||
AquariaComboBox *actionSetBox;
|
||||
AquariaCheckBox *actionSetCheck;
|
||||
int selectedActionSetIdx;
|
||||
TTFText *joystickNameText, *joystickGUIDText;
|
||||
TTFText *joystickNameText, *joystickGUIDText, *joystickButtonsText;
|
||||
void updateActionSetComboBox();
|
||||
void switchToActionSet(int idx);
|
||||
void nextJoystick();
|
||||
|
|
|
@ -45,6 +45,8 @@ Joystick::Joystick()
|
|||
|
||||
clearRumbleTime= 0;
|
||||
numJoyAxes = 0;
|
||||
numHats = 0;
|
||||
numButtons = 0;
|
||||
clearAxes();
|
||||
|
||||
s1ax = 0;
|
||||
|
@ -136,7 +138,8 @@ bool Joystick::init(int stick)
|
|||
if(numJoyAxes > MAX_JOYSTICK_AXIS)
|
||||
numJoyAxes = MAX_JOYSTICK_AXIS;
|
||||
|
||||
|
||||
numHats = SDL_JoystickNumHats(sdl_joy);
|
||||
numButtons = SDL_JoystickNumButtons(sdl_joy);
|
||||
|
||||
|
||||
return true;
|
||||
|
@ -243,7 +246,7 @@ void Joystick::update(float dt)
|
|||
}
|
||||
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);
|
||||
axisRaw[i] = float(ax)/32768.0f;
|
||||
|
@ -265,7 +268,7 @@ void Joystick::update(float dt)
|
|||
#endif
|
||||
// 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);
|
||||
axisRaw[i] = float(ax)/32768.0f;
|
||||
|
@ -290,8 +293,10 @@ void Joystick::update(float dt)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
for (unsigned i = 0; i < MAX_JOYSTICK_BTN; i++)
|
||||
for (unsigned i = 0; i < numButtons; 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;;
|
||||
}
|
||||
|
||||
int Joystick::getNumAxes() const
|
||||
unsigned Joystick::getNumAxes() const
|
||||
{
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
return sdl_controller ? SDL_CONTROLLER_AXIS_MAX : numJoyAxes;
|
||||
|
@ -319,12 +324,22 @@ int Joystick::getNumAxes() const
|
|||
#endif
|
||||
}
|
||||
|
||||
unsigned Joystick::getNumButtons() const
|
||||
{
|
||||
return numButtons;
|
||||
}
|
||||
|
||||
unsigned Joystick::getNumHats() const
|
||||
{
|
||||
return numHats;
|
||||
}
|
||||
|
||||
float Joystick::getAxisUncalibrated(int id) const
|
||||
{
|
||||
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)
|
||||
return NULL;
|
||||
|
@ -335,7 +350,7 @@ const char *Joystick::getAxisName(int axis) const
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const char *Joystick::getButtonName(int btn) const
|
||||
const char *Joystick::getButtonName(unsigned btn) const
|
||||
{
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
if(sdl_controller)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#define MAX_JOYSTICK_BTN 32
|
||||
#define MAX_JOYSTICK_AXIS 32
|
||||
#define MAX_JOYSTICK_HATS 8
|
||||
|
||||
const static float JOY_AXIS_THRESHOLD = 0.6f;
|
||||
|
||||
|
@ -38,14 +39,16 @@ public:
|
|||
bool anyButton() const;
|
||||
bool getButton(size_t id) const { return !!(buttonBitmask & (1u << id)); }
|
||||
float getAxisUncalibrated(int id) const;
|
||||
int getNumAxes() const;
|
||||
unsigned getNumAxes() const;
|
||||
unsigned getNumButtons() const;
|
||||
unsigned getNumHats() const;
|
||||
int getIndex() const { return stickIndex; }
|
||||
int getInstanceID() const { return instanceID; }
|
||||
inline bool isEnabled() const { return enabled; }
|
||||
inline void setEnabled(bool on) { enabled = on; }
|
||||
|
||||
const char *getAxisName(int axis) const;
|
||||
const char *getButtonName(int btn) const;
|
||||
const char *getAxisName(unsigned axis) const;
|
||||
const char *getButtonName(unsigned btn) const;
|
||||
const char *getName() const;
|
||||
const char *getGUID() const;
|
||||
|
||||
|
@ -59,7 +62,7 @@ private:
|
|||
int stickIndex;
|
||||
int instanceID;
|
||||
unsigned buttonBitmask;
|
||||
int numJoyAxes;
|
||||
unsigned numJoyAxes, numHats, numButtons;
|
||||
SDL_Joystick *sdl_joy;
|
||||
float axisRaw[MAX_JOYSTICK_AXIS];
|
||||
std::string name;
|
||||
|
|
Loading…
Add table
Reference in a new issue