- Added logic to guiButtonBaseCtrl so if highlighted and is part of a group, will signal the siblings in the group as well

- Standardizes highlighting behavior between keybind and mouse highlighting of buttons
- Standardized onHighlighted callback for buttonBase
- Fixed handling of up/down nav with gamepad stick
- Added logic to make holding down nav keybinds iterate over buttons in menu lists
This commit is contained in:
Areloch 2023-12-27 11:42:43 -06:00
parent 36d00e09d3
commit f5ab97242f
4 changed files with 301 additions and 247 deletions

View file

@ -84,12 +84,15 @@ IMPLEMENT_CALLBACK( GuiButtonBaseCtrl, onMouseDragged, void, (), (),
"the mouse button still pressed."); "the mouse button still pressed.");
IMPLEMENT_CALLBACK(GuiButtonBaseCtrl, onHighlighted, void, (bool highlighted), (highlighted), IMPLEMENT_CALLBACK(GuiButtonBaseCtrl, onHighlighted, void, (bool highlighted), (highlighted),
"Called when the status of the button being highlighted changes."); "This is called when the highlighted state of the button is changed.");
ImplementEnumType(GuiButtonType, ImplementEnumType(GuiButtonType,
"Type of button control.\n\n" "Type of button control.\n\n"
"@ingroup GuiButtons") "@ingroup GuiButtons")
{ GuiButtonBaseCtrl::ButtonTypePush, "PushButton", "A button that triggers an action when clicked." }, {
GuiButtonBaseCtrl::ButtonTypePush, "PushButton", "A button that triggers an action when clicked."
},
{ GuiButtonBaseCtrl::ButtonTypeCheck, "ToggleButton", "A button that is toggled between on and off state." }, { GuiButtonBaseCtrl::ButtonTypeCheck, "ToggleButton", "A button that is toggled between on and off state." },
{ GuiButtonBaseCtrl::ButtonTypeRadio, "RadioButton", "A button placed in groups for presenting choices." }, { GuiButtonBaseCtrl::ButtonTypeRadio, "RadioButton", "A button placed in groups for presenting choices." },
EndImplementEnumType; EndImplementEnumType;
@ -292,7 +295,7 @@ void GuiButtonBaseCtrl::onMouseEnter(const GuiEvent &event)
{ {
mDepressed = true; mDepressed = true;
mHighlighted = true; mHighlighted = true;
onHighlighted_callback(true); onHighlighted_callback(mHighlighted);
} }
else else
{ {
@ -300,7 +303,8 @@ void GuiButtonBaseCtrl::onMouseEnter(const GuiEvent &event)
SFX->playOnce(mProfile->getSoundButtonOverProfile()); SFX->playOnce(mProfile->getSoundButtonOverProfile());
mHighlighted = true; mHighlighted = true;
onHighlighted_callback(true); messageSiblings(mRadioGroup);
onHighlighted_callback(mHighlighted);
} }
} }
@ -315,7 +319,8 @@ void GuiButtonBaseCtrl::onMouseLeave(const GuiEvent &)
if (isMouseLocked()) if (isMouseLocked())
mDepressed = false; mDepressed = false;
mHighlighted = false; mHighlighted = false;
onHighlighted_callback(false); onHighlighted_callback(mHighlighted);
messageSiblings(mRadioGroup);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -464,7 +469,9 @@ void GuiButtonBaseCtrl::onAction()
void GuiButtonBaseCtrl::onMessage(GuiControl* sender, S32 msg) void GuiButtonBaseCtrl::onMessage(GuiControl* sender, S32 msg)
{ {
Parent::onMessage(sender, msg); Parent::onMessage(sender, msg);
if( mRadioGroup == msg && mButtonType == ButtonTypeRadio ) if (mRadioGroup == msg)
{
if (mButtonType == ButtonTypeRadio)
{ {
setUpdate(); setUpdate();
mStateOn = (sender == this); mStateOn = (sender == this);
@ -473,6 +480,23 @@ void GuiButtonBaseCtrl::onMessage( GuiControl *sender, S32 msg )
if (mConsoleVariable[0]) if (mConsoleVariable[0])
Con::setBoolVariable(mConsoleVariable, mStateOn); Con::setBoolVariable(mConsoleVariable, mStateOn);
} }
else if (mButtonType == ButtonTypePush)
{
mHighlighted = (sender == this);
onHighlighted_callback(mHighlighted);
}
}
}
void GuiButtonBaseCtrl::setHighlighted(bool highlighted)
{
mHighlighted = highlighted;
onHighlighted_callback(mHighlighted);
if (mRadioGroup != -1)
{
messageSiblings(mRadioGroup);
}
} }
//============================================================================= //=============================================================================

View file

@ -96,18 +96,9 @@ class GuiButtonBaseCtrl : public GuiControl
bool getStateOn() const { return mStateOn; } bool getStateOn() const { return mStateOn; }
void setDepressed(bool depressed) { mDepressed = depressed; } void setDepressed(bool depressed) { mDepressed = depressed; }
void resetState() void resetState() { mDepressed = false; mHighlighted = false; }
{
mDepressed = false;
mHighlighted = false;
onHighlighted_callback(false);
}
void setHighlighted(bool highlighted) void setHighlighted(bool highlighted);
{
mHighlighted = highlighted;
onHighlighted_callback(highlighted);
}
bool isHighlighted() { return mHighlighted; } bool isHighlighted() { return mHighlighted; }
void acceleratorKeyPress(U32 index); void acceleratorKeyPress(U32 index);

View file

@ -83,6 +83,8 @@ $guiContent = new GuiControl(MainMenuGui) {
profile = "GuiMenuButtonProfile"; profile = "GuiMenuButtonProfile";
command = "$pref::HostMultiPlayer=false;\nCanvas.pushDialog(ChooseLevelMenu);"; command = "$pref::HostMultiPlayer=false;\nCanvas.pushDialog(ChooseLevelMenu);";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
class="MainMenuButton";
groupNum = 1;
}; };
new GuiButtonCtrl(MainMenuCreateSrvrBtn) { new GuiButtonCtrl(MainMenuCreateSrvrBtn) {
text = "Create Server"; text = "Create Server";
@ -91,6 +93,8 @@ $guiContent = new GuiControl(MainMenuGui) {
profile = "GuiMenuButtonProfile"; profile = "GuiMenuButtonProfile";
command = "$pref::HostMultiPlayer=true;Canvas.pushDialog(ChooseLevelMenu);"; command = "$pref::HostMultiPlayer=true;Canvas.pushDialog(ChooseLevelMenu);";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
class="MainMenuButton";
groupNum = 1;
}; };
new GuiButtonCtrl(MainMenuJoinSrvrBtn) { new GuiButtonCtrl(MainMenuJoinSrvrBtn) {
text = "Join Server"; text = "Join Server";
@ -99,6 +103,8 @@ $guiContent = new GuiControl(MainMenuGui) {
profile = "GuiMenuButtonProfile"; profile = "GuiMenuButtonProfile";
command = "Canvas.pushDialog(JoinServerMenu);"; command = "Canvas.pushDialog(JoinServerMenu);";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
class="MainMenuButton";
groupNum = 1;
}; };
new GuiButtonCtrl(MainMenuOptionBtn) { new GuiButtonCtrl(MainMenuOptionBtn) {
text = "Options"; text = "Options";
@ -107,6 +113,8 @@ $guiContent = new GuiControl(MainMenuGui) {
profile = "GuiMenuButtonProfile"; profile = "GuiMenuButtonProfile";
command = "Canvas.pushDialog(OptionsMenu);"; command = "Canvas.pushDialog(OptionsMenu);";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
class="MainMenuButton";
groupNum = 1;
}; };
new GuiButtonCtrl(MainMenuWorldEditBtn) { new GuiButtonCtrl(MainMenuWorldEditBtn) {
text = "Open World Editor (F11)"; text = "Open World Editor (F11)";
@ -115,6 +123,8 @@ $guiContent = new GuiControl(MainMenuGui) {
profile = "GuiMenuButtonProfile"; profile = "GuiMenuButtonProfile";
command = "fastLoadWorldEdit(1);"; command = "fastLoadWorldEdit(1);";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
class="MainMenuButton";
groupNum = 1;
}; };
new GuiButtonCtrl(MainMenuGuiEditBtn) { new GuiButtonCtrl(MainMenuGuiEditBtn) {
text = "Open GUI Editor (F10)"; text = "Open GUI Editor (F10)";
@ -123,6 +133,8 @@ $guiContent = new GuiControl(MainMenuGui) {
profile = "GuiMenuButtonProfile"; profile = "GuiMenuButtonProfile";
command = "fastLoadGUIEdit(1);"; command = "fastLoadGUIEdit(1);";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
class="MainMenuButton";
groupNum = 1;
}; };
new GuiButtonCtrl(MainMenuExitBtn) { new GuiButtonCtrl(MainMenuExitBtn) {
text = "Exit"; text = "Exit";
@ -131,6 +143,8 @@ $guiContent = new GuiControl(MainMenuGui) {
profile = "GuiMenuButtonProfile"; profile = "GuiMenuButtonProfile";
command = "quit();"; command = "quit();";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
class="MainMenuButton";
groupNum = 1;
}; };
}; };
}; };

View file

@ -1,3 +1,6 @@
$BaseUI::scrollSpeedTimeMs = 250;
$BaseUI::scrollSchedule = 0;
function MainMenuGui::onAdd(%this) function MainMenuGui::onAdd(%this)
{ {
} }
@ -38,6 +41,12 @@ function BaseUINavigatePrev(%val)
$MenuList.listPosition = 0; $MenuList.listPosition = 0;
$MenuList.syncGUI(); $MenuList.syncGUI();
$BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "BaseUINavigatePrev", 1);
}
else
{
cancel($BaseUI::scrollSchedule);
} }
} }
@ -50,15 +59,25 @@ function BaseUINavigateNext(%val)
$MenuList.listPosition = $MenuList.getCount()-1; $MenuList.listPosition = $MenuList.getCount()-1;
$MenuList.syncGUI(); $MenuList.syncGUI();
$BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "BaseUINavigateNext", 1);
}
else
{
cancel($BaseUI::scrollSchedule);
} }
} }
function BaseUIStickNavigate(%val) function BaseUIStickNavigate(%val)
{ {
if(%val == -1) if(%val == 1)
BaseUINavigateNext(1); BaseUINavigateNext(1);
else if(%val == 1) else if(%val == -1)
mainMenuNavigateDown(1); BaseUINavigatePrev(1);
else
{
cancel($BaseUI::scrollSchedule);
}
} }
function BaseUIBackOut(%val) function BaseUIBackOut(%val)
@ -79,7 +98,7 @@ function BaseUIBackOut(%val)
function MainMenuButtonList::syncGUI(%this) function MainMenuButtonList::syncGUI(%this)
{ {
%this.callOnChildren("setHighlighted", false); //%this.callOnChildren("setHighlighted", false);
%btn = %this.getObject(%this.listPosition); %btn = %this.getObject(%this.listPosition);
%btn.setHighlighted(true); %btn.setHighlighted(true);
@ -93,6 +112,12 @@ function MainMenuButtonList::syncGUI(%this)
MainMenuGoButton.setBitmap(BaseUIActionMap.getCommandButtonBitmap(%device, "BaseUIActivateSelected")); MainMenuGoButton.setBitmap(BaseUIActionMap.getCommandButtonBitmap(%device, "BaseUIActivateSelected"));
} }
function MainMenuButton::onHighlighted(%this, %highlighted)
{
if(%highlighted)
$MenuList.listPosition = MainMenuButtonList.getObjectIndex(%this);
}
function BaseUIActivateSelected() function BaseUIActivateSelected()
{ {
%btn = $MenuList.getObject($MenuList.listPosition); %btn = $MenuList.getObject($MenuList.listPosition);