mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
- 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
127 lines
3.1 KiB
Plaintext
127 lines
3.1 KiB
Plaintext
$BaseUI::scrollSpeedTimeMs = 250;
|
|
$BaseUI::scrollSchedule = 0;
|
|
|
|
function MainMenuGui::onAdd(%this)
|
|
{
|
|
}
|
|
|
|
function MainMenuGui::onWake(%this)
|
|
{
|
|
$MenuList = MainMenuButtonList;
|
|
$MenuList.listPosition = 0;
|
|
}
|
|
|
|
function MainMenuGui::onSleep(%this)
|
|
{
|
|
}
|
|
|
|
if(!isObject( BaseUIActionMap ) )
|
|
{
|
|
new ActionMap(BaseUIActionMap){};
|
|
|
|
BaseUIActionMap.bind( keyboard, w, BaseUINavigatePrev );
|
|
BaseUIActionMap.bind( keyboard, s, BaseUINavigateNext );
|
|
BaseUIActionMap.bind( gamepad, yaxis, "D", "-0.23 0.23", BaseUIStickNavigate );
|
|
BaseUIActionMap.bind( gamepad, upov, BaseUINavigatePrev );
|
|
BaseUIActionMap.bind( gamepad, dpov, BaseUINavigateNext );
|
|
|
|
BaseUIActionMap.bind( keyboard, Enter, BaseUIActivateSelected );
|
|
BaseUIActionMap.bind( gamepad, btn_a, BaseUIActivateSelected );
|
|
|
|
BaseUIActionMap.bind( keyboard, Escape, BaseUIBackOut );
|
|
BaseUIActionMap.bind( gamepad, btn_b, BaseUIBackOut );
|
|
}
|
|
|
|
function BaseUINavigatePrev(%val)
|
|
{
|
|
if(%val)
|
|
{
|
|
$MenuList.listPosition -= 1;
|
|
if($MenuList.listPosition < 0)
|
|
$MenuList.listPosition = 0;
|
|
|
|
$MenuList.syncGUI();
|
|
|
|
$BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "BaseUINavigatePrev", 1);
|
|
}
|
|
else
|
|
{
|
|
cancel($BaseUI::scrollSchedule);
|
|
}
|
|
}
|
|
|
|
function BaseUINavigateNext(%val)
|
|
{
|
|
if(%val)
|
|
{
|
|
$MenuList.listPosition += 1;
|
|
if($MenuList.listPosition >= $MenuList.getCount())
|
|
$MenuList.listPosition = $MenuList.getCount()-1;
|
|
|
|
$MenuList.syncGUI();
|
|
|
|
$BaseUI::scrollSchedule = schedule($BaseUI::scrollSpeedTimeMs, 0, "BaseUINavigateNext", 1);
|
|
}
|
|
else
|
|
{
|
|
cancel($BaseUI::scrollSchedule);
|
|
}
|
|
}
|
|
|
|
function BaseUIStickNavigate(%val)
|
|
{
|
|
if(%val == 1)
|
|
BaseUINavigateNext(1);
|
|
else if(%val == -1)
|
|
BaseUINavigatePrev(1);
|
|
else
|
|
{
|
|
cancel($BaseUI::scrollSchedule);
|
|
}
|
|
}
|
|
|
|
function BaseUIBackOut(%val)
|
|
{
|
|
//we can't navigate further back than the MainMenuGui
|
|
if(%val && Canvas.getObject(Canvas.getCount()-1).getId() != MainMenuGui.getId())
|
|
{
|
|
Canvas.popDialog();
|
|
%topMenu = Canvas.getObject(Canvas.getCount()-1);
|
|
if(isObject(%topMenu))
|
|
{
|
|
//re-kick the on-wake so we can be fully up to date and relevently
|
|
//contexted
|
|
%topMenu.onWake();
|
|
}
|
|
}
|
|
}
|
|
|
|
function MainMenuButtonList::syncGUI(%this)
|
|
{
|
|
//%this.callOnChildren("setHighlighted", false);
|
|
|
|
%btn = %this.getObject(%this.listPosition);
|
|
%btn.setHighlighted(true);
|
|
|
|
//
|
|
//Update the button imagery to comply to the last input device we'd used
|
|
%device = Canvas.getLastInputDevice();
|
|
if(%device $= "mouse")
|
|
%device = "keyboard";
|
|
|
|
MainMenuGoButton.setBitmap(BaseUIActionMap.getCommandButtonBitmap(%device, "BaseUIActivateSelected"));
|
|
}
|
|
|
|
function MainMenuButton::onHighlighted(%this, %highlighted)
|
|
{
|
|
if(%highlighted)
|
|
$MenuList.listPosition = MainMenuButtonList.getObjectIndex(%this);
|
|
}
|
|
|
|
function BaseUIActivateSelected()
|
|
{
|
|
%btn = $MenuList.getObject($MenuList.listPosition);
|
|
|
|
if(%btn.isMethod("performClick"))
|
|
%btn.performClick();
|
|
} |