2020-05-20 17:19:52 -05:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// global vars
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
$BUTTON_A = 0;
|
|
|
|
|
$BUTTON_B = 1;
|
|
|
|
|
$BUTTON_X = 2;
|
|
|
|
|
$BUTTON_Y = 3;
|
|
|
|
|
$BUTTON_BACK = 4;
|
|
|
|
|
$BUTTON_START = 5;
|
|
|
|
|
$BUTTON_LTRIGGER = 6;
|
|
|
|
|
$BUTTON_RTRIGGER = 7;
|
|
|
|
|
$BUTTON_LSHOULDER = 8;
|
|
|
|
|
$BUTTON_RSHOULDER = 9;
|
|
|
|
|
$BUTTON_LSTICK = 10;
|
|
|
|
|
$BUTTON_RSTICK = 11;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
function UIMenuButtonList::onInputEvent(%this, %device, %action, %state)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
if(%state)
|
|
|
|
|
$activeMenuButtonContainer.processInputs(%device, %action);
|
2020-05-20 17:19:52 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
function UIMenuButtonList::onAxisEvent(%this, %device, %action, %axisVal)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
$activeMenuButtonContainer.processAxisEvent(%device, %action);
|
2020-05-20 17:19:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sets the command and text for the specified button. If %text and %command
|
|
|
|
|
/// are left empty, the button will be disabled and hidden.
|
|
|
|
|
/// Note: This command is not executed when the A button is pressed. That
|
|
|
|
|
/// command is executed directly from the GuiGameList___Ctrl. This command is
|
|
|
|
|
/// for the graphical hint and to allow a mouse equivalent.
|
|
|
|
|
///
|
|
|
|
|
/// \param %button (constant) The button to set. See: $BUTTON_A, _B, _X, _Y
|
|
|
|
|
/// \param %text (string) The text to display next to the A button graphic.
|
|
|
|
|
/// \param %command (string) The command executed when the A button is pressed.
|
2020-07-23 00:22:15 -05:00
|
|
|
function MenuInputButton::set(%this, %gamepadButton, %keyboardButton, %text, %command, %gamepadOnly)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
%set = (! ((%text $= "") && (%command $= "")));
|
2020-07-23 00:22:15 -05:00
|
|
|
%this.setText(%text);
|
|
|
|
|
%this.setActive(%set);
|
|
|
|
|
%this.setVisible(%set);
|
2020-05-20 17:19:52 -05:00
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
%this.gamepadButton = %gamepadButton;
|
|
|
|
|
%this.keyboardButton = %keyboardButton;
|
2020-05-20 17:19:52 -05:00
|
|
|
|
|
|
|
|
if(%gamepadOnly $= "")
|
|
|
|
|
%gamepadOnly = false;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
%this.gamepadOnly = %gamepadOnly;
|
2020-05-20 17:19:52 -05:00
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
%this.Command = %command;
|
2020-05-20 17:19:52 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
function MenuInputButton::refresh(%this)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
|
|
|
|
|
%set = (! ((%this.text $= "") && (%this.command $= "")));
|
2020-05-20 17:19:52 -05:00
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
//Special-case of where we're in keyboard+mouse mode, but the menubutton is gamepad only mode, so we early out
|
|
|
|
|
if(%this.gamepadOnly && $activeControllerName $= "K&M")
|
|
|
|
|
%set = false;
|
|
|
|
|
|
|
|
|
|
%this.setActive(%set);
|
|
|
|
|
%this.setVisible(%set);
|
|
|
|
|
|
|
|
|
|
if(!%this.isActive())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if($activeControllerName !$= "K&M")
|
|
|
|
|
{
|
|
|
|
|
if(%this.gamepadButton !$= "")
|
|
|
|
|
{
|
|
|
|
|
%path = "";
|
|
|
|
|
if($activeControllerName $= "PS4 Controller")
|
|
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/inputs/PS4/PS4_";
|
|
|
|
|
|
|
|
|
|
if(%this.gamepadButton $= "A")
|
|
|
|
|
%path = %path @ "Cross";
|
|
|
|
|
else if(%this.gamepadButton $= "B")
|
|
|
|
|
%path = %path @ "Circle";
|
|
|
|
|
else if(%this.gamepadButton $= "X")
|
|
|
|
|
%path = %path @ "Square";
|
|
|
|
|
else if(%this.gamepadButton $= "Y")
|
|
|
|
|
%path = %path @ "Triangle";
|
|
|
|
|
else if(%this.gamepadButton $= "LB")
|
|
|
|
|
%path = %path @ "L1";
|
|
|
|
|
else if(%this.gamepadButton $= "LT")
|
|
|
|
|
%path = %path @ "L2";
|
|
|
|
|
else if(%this.gamepadButton $= "RB")
|
|
|
|
|
%path = %path @ "R1";
|
|
|
|
|
else if(%this.gamepadButton $= "RT")
|
|
|
|
|
%path = %path @ "R2";
|
|
|
|
|
//else
|
|
|
|
|
// continue;
|
|
|
|
|
}
|
|
|
|
|
else if($activeControllerName $= "Nintendo Switch Pro Controller")
|
|
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/inputs/Switch/Switch_";
|
|
|
|
|
|
|
|
|
|
if(%this.gamepadButton $= "A")
|
|
|
|
|
%path = %path @ "B";
|
|
|
|
|
else if(%this.gamepadButton $= "B")
|
|
|
|
|
%path = %path @ "A";
|
|
|
|
|
else if(%this.gamepadButton $= "X")
|
|
|
|
|
%path = %path @ "Y";
|
|
|
|
|
else if(%this.gamepadButton $= "Y")
|
|
|
|
|
%path = %path @ "X";
|
|
|
|
|
else if(%this.gamepadButton $= "LB")
|
|
|
|
|
%path = %path @ "LB";
|
|
|
|
|
else if(%this.gamepadButton $= "LT")
|
|
|
|
|
%path = %path @ "LT";
|
|
|
|
|
else if(%this.gamepadButton $= "RB")
|
|
|
|
|
%path = %path @ "RB";
|
|
|
|
|
else if(%this.gamepadButton $= "RT")
|
|
|
|
|
%path = %path @ "RT";
|
|
|
|
|
//else
|
|
|
|
|
// continue;
|
|
|
|
|
}
|
|
|
|
|
else if($activeControllerName !$= "")
|
|
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/inputs/Xbox/Xbox_";
|
|
|
|
|
|
|
|
|
|
%path = %path @ %this.gamepadButton;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(%this.keyboardButton !$= "")
|
|
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/Inputs/Keyboard & Mouse/Keyboard_Black_" @ %this.keyboardButton;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-20 17:19:52 -05:00
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
%this.setBitmap(%path);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MenuInputButtonContainer::refresh(%this)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
%count = %this.getCount();
|
|
|
|
|
for(%i=0; %i < %count; %i++)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
%btn = %this.getObject(%i);
|
2020-05-20 17:19:52 -05:00
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
%btn.refresh();
|
2020-05-20 17:19:52 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
function MenuInputButtonContainer::setActive(%this)
|
|
|
|
|
{
|
|
|
|
|
if(isObject($activeMenuButtonContainer))
|
|
|
|
|
$activeMenuButtonContainer.hidden = true;
|
|
|
|
|
|
|
|
|
|
$activeMenuButtonContainer = %this;
|
|
|
|
|
$activeMenuButtonContainer.hidden = false;
|
|
|
|
|
$activeMenuButtonContainer.refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MenuInputButtonContainer::checkGamepad(%this)
|
|
|
|
|
{
|
|
|
|
|
%controllerName = SDLInputManager::JoystickNameForIndex(0);
|
|
|
|
|
|
|
|
|
|
$activeControllerName = %controllerName;
|
|
|
|
|
|
|
|
|
|
if($activeControllerName $= "")
|
|
|
|
|
$activeControllerName = "K&M";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function MenuInputButtonContainer::refreshButtons(%this)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
//Set up our basic buttons
|
2020-07-23 00:22:15 -05:00
|
|
|
for(%i=0; %i < %this.getCount(); %i++)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
%btn = %this.getObject(%i);
|
2020-05-20 17:19:52 -05:00
|
|
|
|
|
|
|
|
%set = (! ((%btn.text $= "") && (%btn.command $= "")));
|
|
|
|
|
|
|
|
|
|
//Special-case of where we're in keyboard+mouse mode, but the menubutton is gamepad only mode, so we early out
|
2020-07-23 00:22:15 -05:00
|
|
|
if(%btn.gamepadOnly && $activeControllerName $= "K&M")
|
2020-05-20 17:19:52 -05:00
|
|
|
%set = false;
|
|
|
|
|
|
|
|
|
|
%btn.setActive(%set);
|
|
|
|
|
%btn.setVisible(%set);
|
|
|
|
|
|
|
|
|
|
if(!%btn.isActive())
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName !$= "K&M")
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
if(%btn.gamepadButton !$= "")
|
|
|
|
|
{
|
|
|
|
|
%path = "";
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName $= "PS4 Controller")
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/inputs/PS4/PS4_";
|
|
|
|
|
|
|
|
|
|
if(%btn.gamepadButton $= "A")
|
|
|
|
|
%path = %path @ "Cross";
|
|
|
|
|
else if(%btn.gamepadButton $= "B")
|
|
|
|
|
%path = %path @ "Circle";
|
|
|
|
|
else if(%btn.gamepadButton $= "X")
|
|
|
|
|
%path = %path @ "Square";
|
|
|
|
|
else if(%btn.gamepadButton $= "Y")
|
|
|
|
|
%path = %path @ "Triangle";
|
|
|
|
|
else if(%btn.gamepadButton $= "LB")
|
|
|
|
|
%path = %path @ "L1";
|
|
|
|
|
else if(%btn.gamepadButton $= "LT")
|
|
|
|
|
%path = %path @ "L2";
|
|
|
|
|
else if(%btn.gamepadButton $= "RB")
|
|
|
|
|
%path = %path @ "R1";
|
|
|
|
|
else if(%btn.gamepadButton $= "RT")
|
|
|
|
|
%path = %path @ "R2";
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-07-23 00:22:15 -05:00
|
|
|
else if($activeControllerName $= "Nintendo Switch Pro Controller")
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/inputs/Switch/Switch_";
|
|
|
|
|
|
|
|
|
|
if(%btn.gamepadButton $= "A")
|
|
|
|
|
%path = %path @ "B";
|
|
|
|
|
else if(%btn.gamepadButton $= "B")
|
|
|
|
|
%path = %path @ "A";
|
|
|
|
|
else if(%btn.gamepadButton $= "X")
|
|
|
|
|
%path = %path @ "Y";
|
|
|
|
|
else if(%btn.gamepadButton $= "Y")
|
|
|
|
|
%path = %path @ "X";
|
|
|
|
|
else if(%btn.gamepadButton $= "LB")
|
|
|
|
|
%path = %path @ "LB";
|
|
|
|
|
else if(%btn.gamepadButton $= "LT")
|
|
|
|
|
%path = %path @ "LT";
|
|
|
|
|
else if(%btn.gamepadButton $= "RB")
|
|
|
|
|
%path = %path @ "RB";
|
|
|
|
|
else if(%btn.gamepadButton $= "RT")
|
|
|
|
|
%path = %path @ "RT";
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-07-23 00:22:15 -05:00
|
|
|
else if($activeControllerName !$= "")
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/inputs/Xbox/Xbox_";
|
|
|
|
|
|
|
|
|
|
%path = %path @ %btn.gamepadButton;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(%btn.keyboardButton !$= "")
|
|
|
|
|
{
|
|
|
|
|
%path = "data/ui/images/Inputs/Keyboard & Mouse/Keyboard_Black_" @ %btn.keyboardButton;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%btn.setBitmap(%path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
function MenuInputButtonContainer::processInputs(%this, %device, %action)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
//check to see if our status has changed
|
|
|
|
|
%changed = false;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
%oldDevice = $activeControllerName;
|
2020-05-20 17:19:52 -05:00
|
|
|
|
|
|
|
|
if(startsWith(%device, "Keyboard"))
|
|
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName !$= %device)
|
2020-05-20 17:19:52 -05:00
|
|
|
%changed = true;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
$activeControllerName = "K&M";
|
2020-05-20 17:19:52 -05:00
|
|
|
Canvas.showCursor();
|
|
|
|
|
}
|
|
|
|
|
else if(startsWith(%device, "Mouse"))
|
|
|
|
|
{
|
|
|
|
|
if(startsWith(%action, "button"))
|
|
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName !$= %device)
|
2020-05-20 17:19:52 -05:00
|
|
|
%changed = true;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
$activeControllerName = "K&M";
|
2020-05-20 17:19:52 -05:00
|
|
|
Canvas.showCursor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
if(%this.checkGamepad())
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
Canvas.hideCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName !$= %device)
|
2020-05-20 17:19:52 -05:00
|
|
|
%changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(%changed)
|
2020-07-23 00:22:15 -05:00
|
|
|
%this.refresh();
|
2020-05-20 17:19:52 -05:00
|
|
|
|
|
|
|
|
//Now process the input for the button accelerator, if applicable
|
|
|
|
|
//Set up our basic buttons
|
2020-07-23 00:22:15 -05:00
|
|
|
for(%i=0; %i < %this.getCount(); %i++)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
%btn = %this.getObject(%i);
|
2020-05-20 17:19:52 -05:00
|
|
|
|
|
|
|
|
if(!%btn.isActive())
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName !$= "K&M")
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
if(%action $= "btn_a")
|
|
|
|
|
%action = "A";
|
|
|
|
|
else if(%action $= "btn_b")
|
|
|
|
|
%action = "B";
|
|
|
|
|
else if(%action $= "btn_x")
|
|
|
|
|
%action = "X";
|
|
|
|
|
else if(%action $= "btn_y")
|
|
|
|
|
%action = "Y";
|
|
|
|
|
else if(%action $= "btn_r")
|
2020-05-20 17:19:52 -05:00
|
|
|
%action = "RB";
|
|
|
|
|
else if(%action $= "btn_l")
|
|
|
|
|
%action = "LB";
|
|
|
|
|
|
|
|
|
|
if(%btn.gamepadButton $= %action)
|
|
|
|
|
{
|
|
|
|
|
eval(%btn.command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(%action $= "return")
|
|
|
|
|
%action = "enter";
|
|
|
|
|
else if(%action $= "escape")
|
|
|
|
|
%action = "esc";
|
|
|
|
|
|
|
|
|
|
if(%btn.keyboardButton $= %action)
|
|
|
|
|
{
|
|
|
|
|
eval(%btn.command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
function MenuInputButtonContainer::processAxisEvent(%this, %device, %action, %axisVal)
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
%changed = false;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
%oldDevice = $activeControllerName;
|
2020-05-20 17:19:52 -05:00
|
|
|
|
|
|
|
|
if(startsWith(%device, "Mouse"))
|
|
|
|
|
{
|
|
|
|
|
if(startsWith(%action, "button"))
|
|
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName !$= %device)
|
2020-05-20 17:19:52 -05:00
|
|
|
%changed = true;
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
$activeControllerName = "K&M";
|
2020-05-20 17:19:52 -05:00
|
|
|
Canvas.showCursor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-23 00:22:15 -05:00
|
|
|
if(%this.checkGamepad())
|
2020-05-20 17:19:52 -05:00
|
|
|
{
|
|
|
|
|
Canvas.hideCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:22:15 -05:00
|
|
|
if($activeControllerName !$= %device)
|
2020-05-20 17:19:52 -05:00
|
|
|
%changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(%changed)
|
2020-07-23 00:22:15 -05:00
|
|
|
%this.refresh();
|
2020-05-20 17:19:52 -05:00
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
function onSDLDeviceConnected(%sdlIndex, %deviceName, %deviceType)
|
|
|
|
|
{
|
|
|
|
|
/*if(GamepadButtonsGui.checkGamepad())
|
|
|
|
|
{
|
|
|
|
|
GamepadButtonsGui.hidden = false;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onSDLDeviceDisconnected(%sdlIndex)
|
|
|
|
|
{
|
|
|
|
|
/*if(!GamepadButtonsGui.checkGamepad())
|
|
|
|
|
{
|
|
|
|
|
GamepadButtonsGui.hidden = true;
|
|
|
|
|
}*/
|
|
|
|
|
}
|