iw6-lui/lui/luibutton.dec.lua
2024-09-12 17:25:45 +02:00

416 lines
11 KiB
Lua

LUI.UIButton = {}
LUI.UIButton.popupActive = function ( f1_arg0, f1_arg1 )
f1_arg0.m_ignoreMouseFocus = true
end
LUI.UIButton.popupInactive = function ( f2_arg0, f2_arg1 )
f2_arg0.m_ignoreMouseFocus = nil
end
LUI.UIButton.MouseEnter = function ( f3_arg0, f3_arg1 )
if f3_arg0.m_leftMouseDown == nil then
if f3_arg0:canFocus( FocusType.MouseOver ) and not f3_arg0:isInFocus() then
if f3_arg0.disabled then
f3_arg0:processEvent( {
name = "button_over_disable"
} )
else
f3_arg0:processEvent( {
name = "button_over",
controller = f3_arg1.controller
} )
end
end
elseif f3_arg0.m_leftMouseDown ~= nil then
f3_arg0:processEvent( {
name = "button_over_down"
} )
end
end
LUI.UIButton.MouseLeave = function ( f4_arg0, f4_arg1 )
if f4_arg0.m_leftMouseDown == nil then
if f4_arg0.m_focusable and not f4_arg0:isInFocus() then
if f4_arg0.disabled then
f4_arg0:processEvent( {
name = "button_disable"
} )
else
f4_arg0:processEvent( {
name = "button_up"
} )
end
end
else
f4_arg0:processEvent( {
name = "button_down"
} )
end
end
LUI.UIButton.LeftMouseDown = function ( f5_arg0, f5_arg1 )
f5_arg0:processEvent( {
name = "button_over_down"
} )
end
LUI.UIButton.RightMouseDown = function ( f6_arg0, f6_arg1 )
f6_arg0:processEvent( {
name = "button_over_down"
} )
end
LUI.UIButton.LeftMouseUp = function ( f7_arg0, f7_arg1 )
if f7_arg1.inside then
if f7_arg0.disabled then
f7_arg0:processEvent( {
name = "button_over_disable"
} )
else
f7_arg0:processEvent( {
name = "button_over",
controller = f7_arg1.controller,
focusType = FocusType.MouseOver
} )
end
if not f7_arg0.disabled then
if not f7_arg0.properties or not f7_arg0.properties.muteAction then
Engine.PlaySound( f7_arg0.actionSFX )
end
local f7_local0 = f7_arg0:processEvent( {
name = "button_action",
controller = f7_arg1.controller,
mouse = true
} )
f7_arg0:processEvent( {
name = "button_down",
controller = f7_arg1.controller,
mouse = true
} )
if f7_local0 then
return f7_local0
end
elseif f7_arg0.properties and f7_arg0.properties.disableSound then
Engine.PlaySound( f7_arg0.properties.disableSound )
end
if f7_arg0.properties and f7_arg0.properties.allowDisabledAction then
f7_arg0:processEvent( {
name = "button_action_disable",
controller = f7_arg1.controller
} )
end
elseif not f7_arg0.disabled then
f7_arg0:processEvent( {
name = "button_up"
} )
end
end
LUI.UIButton.RightMouseUp = function ( f8_arg0, f8_arg1 )
if f8_arg1.inside then
if f8_arg0.disabled then
f8_arg0:processEvent( {
name = "button_over_disable",
controller = f8_arg1.controller
} )
else
f8_arg0:processEvent( {
name = "button_over",
controller = f8_arg1.controller
} )
end
if not f8_arg0.disabled then
local f8_local0 = f8_arg0:processEvent( {
name = "button_actionsecondary",
controller = f8_arg1.controller,
mouse = true
} )
if f8_local0 then
return f8_local0
end
end
else
f8_arg0:processEvent( {
name = "button_up"
} )
end
end
LUI.UIButton.excludeButtons = {
secondary = true,
alt1 = true,
alt2 = true,
right_trigger = true,
left_trigger = true,
shoulderl = true,
shoulderr = true,
start = true
}
LUI.UIButton.GamepadButton = function ( f9_arg0, f9_arg1 )
if f9_arg0:handleGamepadButton( f9_arg1 ) then
return true
elseif f9_arg0:isInFocus() and f9_arg1.down == true then
if f9_arg1.button == "primary" then
if not f9_arg0.properties or not f9_arg0.properties.muteAction then
Engine.PlaySound( f9_arg0.actionSFX )
end
if not f9_arg0.disabled then
local f9_local0
if not f9_arg1.qualifier or f9_arg1.qualifier ~= ButtonQualifiers.Keyboard then
f9_local0 = false
else
f9_local0 = true
end
f9_arg0:processEvent( {
name = "button_action",
controller = f9_arg1.controller,
keyboard = f9_local0
} )
f9_arg0:processEvent( {
name = "button_down",
controller = f9_arg1.controller,
keyboard = f9_local0
} )
else
if f9_arg0.properties and f9_arg0.properties.disableSound then
Engine.PlaySound( f9_arg0.properties.disableSound )
end
if f9_arg0.properties and f9_arg0.properties.allowDisabledAction then
f9_arg0:processEvent( {
name = "button_action_disable",
controller = f9_arg1.controller
} )
end
end
if f9_arg0.m_eventHandlers.button_action ~= nil then
return true
end
elseif f9_arg1.button == "left" then
if not f9_arg0.disabled then
f9_arg0:processEvent( {
name = "button_left",
controller = f9_arg1.controller
} )
end
if f9_arg0.m_eventHandlers.button_left ~= nil then
return true
end
elseif f9_arg1.button == "right" then
if not f9_arg0.disabled then
f9_arg0:processEvent( {
name = "button_right",
controller = f9_arg1.controller
} )
end
if f9_arg0.m_eventHandlers.button_right ~= nil then
return true
end
elseif LUI.UIButton.excludeButtons[f9_arg1.button] and f9_arg0.m_eventHandlers["button_" .. f9_arg1.button] ~= nil then
DebugPrint( "Warning: event handler specified for button_" .. f9_arg1.button .. " on a UIButton id = " .. f9_arg0.id .. ", this won't work anymore, use a UIBindButton" )
end
end
return f9_arg0:dispatchEventToChildren( f9_arg1 )
end
LUI.UIButton.gainFocus = function ( f10_arg0, f10_arg1 )
local f10_local0 = f10_arg0:isInFocus()
LUI.UIElement.gainFocus( f10_arg0, f10_arg1 )
if not f10_local0 and f10_arg0:isInFocus() and f10_arg0.gainFocusSFX ~= nil and f10_arg1.focusType ~= FocusType.MenuFlow then
Engine.PlaySound( f10_arg0.gainFocusSFX )
end
if f10_arg0.disabled then
f10_arg0:processEvent( {
name = "button_over_disable",
dispatchChildren = true,
focusType = f10_arg1.focusType
} )
else
f10_arg0:processEvent( {
name = "button_over",
controller = f10_arg1.controller,
dispatchChildren = true,
focusType = f10_arg1.focusType
} )
end
end
LUI.UIButton.loseFocus = function ( f11_arg0, f11_arg1 )
LUI.UIElement.loseFocus( f11_arg0, f11_arg1 )
if f11_arg0.disabled then
f11_arg0:processEvent( {
name = "button_disable",
dispatchChildren = true
} )
else
f11_arg0:processEvent( {
name = "button_up",
dispatchChildren = true
} )
end
end
LUI.UIButton.Up = function ( f12_arg0, f12_arg1 )
f12_arg0:dispatchEventToChildren( f12_arg1 )
if f12_arg0:isInFocus() then
f12_arg0:processEvent( {
name = "gain_focus"
} )
end
end
LUI.UIButton.Over = function ( f13_arg0, f13_arg1 )
if f13_arg0.disabled and f13_arg0:hasAnimationState( "button_over_disabled" ) then
f13_arg0:animateToState( "button_over_disabled", f13_arg0.disableDuration )
elseif f13_arg0:hasAnimationState( "button_over" ) then
f13_arg0:animateToState( "button_over", f13_arg0.overDuration, f13_arg0.overEaseIn, f13_arg0.overEaseOut )
end
end
LUI.UIButton.ElementUp = function ( f14_arg0, f14_arg1 )
end
LUI.UIButton.ElementDown = function ( f15_arg0, f15_arg1 )
if f15_arg0:hasAnimationState( "button_down" ) then
f15_arg0:animateToState( "button_down", f15_arg0.downDuration )
else
LUI.UIButton.ElementUp( f15_arg0, f15_arg1 )
end
f15_arg0:dispatchEventToChildren( f15_arg1 )
end
LUI.UIButton.ElementOverDown = function ( f16_arg0, f16_arg1 )
if f16_arg0:hasAnimationState( "button_over_down" ) then
f16_arg0:animateToState( "button_over_down", f16_arg0.overDownDuration )
else
LUI.UIButton.Over( f16_arg0, f16_arg1 )
end
f16_arg0:dispatchEventToChildren( f16_arg1 )
end
LUI.UIButton.ElementEnable = function ( f17_arg0, f17_arg1 )
f17_arg0.disabled = nil
f17_arg0:dispatchEventToChildren( f17_arg1 )
if f17_arg0:isInFocus() then
f17_arg0:processEvent( {
name = "button_over",
dispatchChildren = true,
controller = f17_arg1.controller
} )
else
f17_arg0:processEvent( {
name = "button_up",
dispatchChildren = true
} )
end
end
LUI.UIButton.ElementDisable = function ( f18_arg0, f18_arg1 )
f18_arg0.disabled = true
f18_arg0:dispatchEventToChildren( f18_arg1 )
if f18_arg0:isInFocus() then
f18_arg0:processEvent( {
name = "button_over_disable",
dispatchChildren = true
} )
else
f18_arg0:processEvent( {
name = "button_disable",
dispatchChildren = true
} )
end
end
LUI.UIButton.UpdateOutsideList = function ( f19_arg0, f19_arg1 )
f19_arg0.m_outsideParentList = f19_arg1.outside_list
end
LUI.UIButton.Enable = function ( f20_arg0, f20_arg1 )
f20_arg0:processEvent( {
name = "enable",
dispatchChildren = true
} )
if f20_arg0:isInFocus() then
f20_arg0:processEvent( {
name = "button_over",
dispatchChildren = true,
controller = f20_arg1.controller
} )
else
f20_arg0:processEvent( {
name = "button_up",
dispatchChildren = true
} )
end
end
LUI.UIButton.Disable = function ( f21_arg0 )
f21_arg0:processEvent( {
name = "disable",
dispatchChildren = true
} )
if f21_arg0:isInFocus() then
f21_arg0:processEvent( {
name = "button_over_disable",
dispatchChildren = true
} )
else
f21_arg0:processEvent( {
name = "button_disable",
dispatchChildren = true
} )
end
end
LUI.UIButton.SetupElement = function ( f22_arg0 )
f22_arg0:registerEventHandlerIfFree( "enable", LUI.UIButton.ElementEnable )
f22_arg0:registerEventHandlerIfFree( "disable", LUI.UIButton.ElementDisable )
f22_arg0:registerEventHandlerIfFree( "button_up", LUI.UIButton.Up )
f22_arg0:registerEventHandlerIfFree( "button_over", LUI.UIButton.Over )
f22_arg0:registerEventHandlerIfFree( "button_down", LUI.UIButton.ElementDown )
f22_arg0:registerEventHandlerIfFree( "button_over_down", LUI.UIButton.ElementOverDown )
end
LUI.UIButton.SetGainFocusSFX = function ( f23_arg0, f23_arg1 )
f23_arg0.gainFocusSFX = f23_arg1
end
LUI.UIButton.SetActionSFX = function ( f24_arg0, f24_arg1 )
f24_arg0.actionSFX = f24_arg1
end
LUI.UIButton.build = function ( f25_arg0, f25_arg1 )
return LUI.UIButton.new()
end
LUI.UIButton.new = function ( menu, controller )
local self = LUI.UIElement.new( menu )
self.id = "LUIButton"
self:makeFocusable()
self:setHandleMouse( true )
self.enable = LUI.UIButton.Enable
self.disable = LUI.UIButton.Disable
self.lock = LUI.UIButton.Disable
self.actionEventName = controller
self.setActionEventName = LUI.UIButton.setActionEventName
self.setGainFocusSFX = LUI.UIButton.SetGainFocusSFX
self.setActionSFX = LUI.UIButton.SetActionSFX
self.gainFocusSFX = CoD.SFX.MouseOver
self.actionSFX = CoD.SFX.MouseClick
self:registerEventHandler( "mouseenter", LUI.UIButton.MouseEnter )
self:registerEventHandler( "mouseleave", LUI.UIButton.MouseLeave )
self:registerEventHandler( "leftmousedown", LUI.UIButton.LeftMouseDown )
self:registerEventHandler( "leftmouseup", LUI.UIButton.LeftMouseUp )
self:registerEventHandler( "rightmousedown", LUI.UIButton.RightMouseDown )
self:registerEventHandler( "rightmouseup", LUI.UIButton.RightMouseUp )
self:registerEventHandler( "gamepad_button", LUI.UIButton.GamepadButton )
self:registerEventHandler( "gain_focus", LUI.UIButton.gainFocus )
self:registerEventHandler( "lose_focus", LUI.UIButton.loseFocus )
self:registerEventHandler( "popup_active", LUI.UIButton.popupActive )
self:registerEventHandler( "popup_inactive", LUI.UIButton.popupInactive )
self:registerEventHandler( "update_outside_list", LUI.UIButton.UpdateOutsideList )
LUI.UIButton.SetupElement( self )
return self
end