mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-03 18:14:01 +00:00
Replace DebugButton in the key config menu with a nicer and UI-focusable button
This commit is contained in:
parent
cd17e34094
commit
d49531f486
6 changed files with 136 additions and 20 deletions
|
@ -1059,6 +1059,7 @@ void AquariaMenuItem::toggleHighlight(bool state)
|
||||||
glowFont->alpha.interpolateTo(0, 0.2);
|
glowFont->alpha.interpolateTo(0, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onToggleHighlight(highlighted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AquariaMenuItem::onUpdate(float dt)
|
void AquariaMenuItem::onUpdate(float dt)
|
||||||
|
@ -1140,3 +1141,79 @@ bool AquariaMenuItem::isCursorInMenuItem()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AquariaButton::AquariaButton(const std::string texbase, TTFFont *font)
|
||||||
|
: activeColor(1,1,1), activeAlpha(0.5f)
|
||||||
|
, inactiveColor(0,0,0), inactiveAlpha(0.5f)
|
||||||
|
, buttonlabel(new TTFText(font))
|
||||||
|
, _texbase(texbase), pressed(0), lastpressed(0)
|
||||||
|
{
|
||||||
|
useQuad(texbase + "-button-up");
|
||||||
|
addChild(buttonlabel, PM_POINTER);
|
||||||
|
buttonlabel->setAlign(ALIGN_CENTER);
|
||||||
|
buttonlabel->position = Vector(0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AquariaButton::goUp()
|
||||||
|
{
|
||||||
|
quad->setTexture(_texbase + "-button-up");
|
||||||
|
buttonlabel->position = Vector(0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AquariaButton::goDown()
|
||||||
|
{
|
||||||
|
quad->setTexture(_texbase + "-button-down");
|
||||||
|
buttonlabel->position = Vector(0, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AquariaButton::action(int actionID, int state, int source)
|
||||||
|
{
|
||||||
|
if(actionID == ACTION_PRIMARY)
|
||||||
|
{
|
||||||
|
if(state)
|
||||||
|
pressed |= 1;
|
||||||
|
else
|
||||||
|
pressed &= ~1;
|
||||||
|
}
|
||||||
|
else if(actionID == ACTION_SECONDARY)
|
||||||
|
{
|
||||||
|
if(state)
|
||||||
|
pressed |= 2;
|
||||||
|
else
|
||||||
|
pressed &= ~2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AquariaButton::onUpdate(float dt)
|
||||||
|
{
|
||||||
|
AquariaMenuItem::onUpdate(dt);
|
||||||
|
|
||||||
|
/*if(pressed != lastpressed)
|
||||||
|
{
|
||||||
|
if(pressed)
|
||||||
|
goDown();
|
||||||
|
else
|
||||||
|
goUp();
|
||||||
|
lastpressed = pressed;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void AquariaButton::onToggleHighlight(bool on)
|
||||||
|
{
|
||||||
|
if(on)
|
||||||
|
{
|
||||||
|
quad->color.interpolateTo(activeColor, 0.1);
|
||||||
|
quad->alpha.interpolateTo(activeAlpha, 0.1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
quad->color.interpolateTo(inactiveColor, 0.1);
|
||||||
|
quad->alpha.interpolateTo(inactiveAlpha, 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AquariaButton::setButtonLabel(const std::string& s)
|
||||||
|
{
|
||||||
|
buttonlabel->setText(s);
|
||||||
|
}
|
||||||
|
|
|
@ -100,7 +100,8 @@ protected:
|
||||||
bool highlighted;
|
bool highlighted;
|
||||||
void toggleHighlight(bool v);
|
void toggleHighlight(bool v);
|
||||||
void onClick();
|
void onClick();
|
||||||
void onUpdate(float dt);
|
virtual void onUpdate(float dt);
|
||||||
|
virtual void onToggleHighlight(bool on) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class AquariaSaveSlot : public AquariaGuiQuad
|
class AquariaSaveSlot : public AquariaGuiQuad
|
||||||
|
@ -248,6 +249,32 @@ protected:
|
||||||
std::vector<AquariaComboBoxItem*> shownItems;
|
std::vector<AquariaComboBoxItem*> shownItems;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AquariaButton : public AquariaMenuItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AquariaButton(const std::string texbase, TTFFont *font);
|
||||||
|
|
||||||
|
void setButtonLabel(const std::string& s);
|
||||||
|
void goDown();
|
||||||
|
void goUp();
|
||||||
|
|
||||||
|
Vector activeColor;
|
||||||
|
float activeAlpha;
|
||||||
|
Vector inactiveColor;
|
||||||
|
float inactiveAlpha;
|
||||||
|
|
||||||
|
TTFText * const buttonlabel;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void action(int actionID, int state, int source);
|
||||||
|
virtual void onUpdate(float dt);
|
||||||
|
virtual void onToggleHighlight(bool on);
|
||||||
|
|
||||||
|
std::string _texbase;
|
||||||
|
int pressed;
|
||||||
|
int lastpressed;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,18 +31,6 @@ const Vector opt_save_original = Vector(350, 350), opt_cancel_original = Vector(
|
||||||
const int KEYCONFIG_FIRST_COL_DISTANCE = 170;
|
const int KEYCONFIG_FIRST_COL_DISTANCE = 170;
|
||||||
const int KEYCONFIG_COL_DISTANCE = 105;
|
const int KEYCONFIG_COL_DISTANCE = 105;
|
||||||
|
|
||||||
class KeyConfigMenuReceiver : public DebugButtonReceiver
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void buttonPress(DebugButton *db)
|
|
||||||
{
|
|
||||||
themenu->switchToKeyConfigPage(db->buttonID);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static KeyConfigMenuReceiver keyConfigRecv;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --------- Private class defs, not used outside ---------------
|
// --------- Private class defs, not used outside ---------------
|
||||||
|
|
||||||
|
@ -2043,12 +2031,21 @@ void InGameMenu::create()
|
||||||
{
|
{
|
||||||
const float w = 100;
|
const float w = 100;
|
||||||
const std::string& label = SB(2150+i);
|
const std::string& label = SB(2150+i);
|
||||||
DebugButton *b = new DebugButton(i, &keyConfigRecv, w);
|
AquariaButton *b = new AquariaButton("gui/simpleblue", &dsq->fontArialSmall);
|
||||||
|
b->scale = Vector(0.8f, 0.8f);
|
||||||
b->position = Vector(150 + offx + i * (w+10), offy);
|
b->position = Vector(150 + offx + i * (w+10), offy);
|
||||||
b->label->setText(label);
|
b->setButtonLabel(label);
|
||||||
|
const Vector color(0.45f, 0.45f, 0.7f);
|
||||||
|
b->inactiveColor = color;
|
||||||
|
b->inactiveAlpha = 0.5f;
|
||||||
|
b->quad->color = color;
|
||||||
keyConfigBg->addChild(b, PM_POINTER);
|
keyConfigBg->addChild(b, PM_POINTER);
|
||||||
keyCategoryButtons.push_back(b);
|
keyCategoryButtons.push_back(b);
|
||||||
}
|
}
|
||||||
|
keyCategoryButtons[0]->event.set(MakeFunctionEvent(InGameMenu, switchToKeyConfigPage1));
|
||||||
|
keyCategoryButtons[1]->event.set(MakeFunctionEvent(InGameMenu, switchToKeyConfigPage2));
|
||||||
|
keyCategoryButtons[2]->event.set(MakeFunctionEvent(InGameMenu, switchToKeyConfigPage3));
|
||||||
|
|
||||||
offy += 2*yi;
|
offy += 2*yi;
|
||||||
|
|
||||||
TTFText *header_action = new TTFText(&dsq->fontArialSmall);
|
TTFText *header_action = new TTFText(&dsq->fontArialSmall);
|
||||||
|
@ -3802,15 +3799,26 @@ void InGameMenu::switchToKeyConfigPage(int page)
|
||||||
{
|
{
|
||||||
group_keyConfig[i]->setHidden(true);
|
group_keyConfig[i]->setHidden(true);
|
||||||
group_keyConfig[i]->alpha = 0;
|
group_keyConfig[i]->alpha = 0;
|
||||||
keyCategoryButtons[i]->inactiveColor = Vector(0, 0, 0.5f);
|
keyCategoryButtons[i]->goUp();
|
||||||
keyCategoryButtons[i]->inactiveAlpha = 0.5f;
|
|
||||||
}
|
}
|
||||||
keyCategoryButtons[page]->inactiveColor = Vector(0.3f, 0.3f, 0.7f);
|
keyCategoryButtons[page]->goDown();
|
||||||
keyCategoryButtons[page]->inactiveAlpha = 0.7f;
|
|
||||||
group_keyConfig[page]->setHidden(false);
|
group_keyConfig[page]->setHidden(false);
|
||||||
group_keyConfig[page]->alpha = 1;
|
group_keyConfig[page]->alpha = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InGameMenu::switchToKeyConfigPage1()
|
||||||
|
{
|
||||||
|
switchToKeyConfigPage(0);
|
||||||
|
}
|
||||||
|
void InGameMenu::switchToKeyConfigPage2()
|
||||||
|
{
|
||||||
|
switchToKeyConfigPage(1);
|
||||||
|
}
|
||||||
|
void InGameMenu::switchToKeyConfigPage3()
|
||||||
|
{
|
||||||
|
switchToKeyConfigPage(2);
|
||||||
|
}
|
||||||
|
|
||||||
void InGameMenu::toggleOptionsMenu(bool f, bool skipBackup, bool isKeyConfig)
|
void InGameMenu::toggleOptionsMenu(bool f, bool skipBackup, bool isKeyConfig)
|
||||||
{
|
{
|
||||||
const float t = 0;
|
const float t = 0;
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Recipe;
|
||||||
class RoundedRect;
|
class RoundedRect;
|
||||||
class DebugButton;
|
class DebugButton;
|
||||||
class TTFText;
|
class TTFText;
|
||||||
|
class AquariaButton;
|
||||||
|
|
||||||
|
|
||||||
enum MenuPage
|
enum MenuPage
|
||||||
|
@ -207,10 +208,13 @@ private:
|
||||||
|
|
||||||
RenderObject *group_keyConfig[NUM_KEY_CONFIG_PAGES];
|
RenderObject *group_keyConfig[NUM_KEY_CONFIG_PAGES];
|
||||||
RoundedRect *keyConfigBg;
|
RoundedRect *keyConfigBg;
|
||||||
std::vector<DebugButton*> keyCategoryButtons;
|
std::vector<AquariaButton*> keyCategoryButtons;
|
||||||
std::vector<AquariaKeyConfig*> keyConfigs;
|
std::vector<AquariaKeyConfig*> keyConfigs;
|
||||||
RenderObject *createBasicKeyConfig();
|
RenderObject *createBasicKeyConfig();
|
||||||
void switchToKeyConfigPage(int page);
|
void switchToKeyConfigPage(int page);
|
||||||
|
void switchToKeyConfigPage1();
|
||||||
|
void switchToKeyConfigPage2();
|
||||||
|
void switchToKeyConfigPage3();
|
||||||
Quad *options;
|
Quad *options;
|
||||||
AquariaComboBox *actionSetBox;
|
AquariaComboBox *actionSetBox;
|
||||||
AquariaCheckBox *actionSetCheck;
|
AquariaCheckBox *actionSetCheck;
|
||||||
|
|
BIN
files/gfx/gui/simpleblue-button-down.png
Normal file
BIN
files/gfx/gui/simpleblue-button-down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 406 B |
BIN
files/gfx/gui/simpleblue-button-up.png
Normal file
BIN
files/gfx/gui/simpleblue-button-up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 514 B |
Loading…
Add table
Reference in a new issue