require 'scripts/gui/gui_button.lua'

--------------------------------------------------------------------------------
-- GUIButtonNoPressedEnter Object script
-- 
-- States
-- * idle
-- * pressed
--
-- Attributes 
-- * listener : script component that listens to the element events.
-- * clickable : area for click detection. If not present, it is automatically
--               created.
-- * autoAdjustClickableArea : flag that determines automatic adjusment of the 
--                             clickable area according to the currrent visual.
-- * idleVisual : visual for idle state.
-- * focusedVisual : visual for focused state.
-- * pressedVisual : visual for pressed state.
-- * pressedAnimation : reference to the animator to launch on press
-- * releasedAnimation : reference to the animator to launch on release
-- * clickedAnimation : reference to the animator to launch on click
--
-- Events
-- * onElementFocus(element)
-- * onElementUnfocus(element)
-- * onButtonPress(button, positionX, positionY)
-- * onButtonRelease(button, positionX, positionY)
-- * onButtonClick(button)
--
--------------------------------------------------------------------------------

GUIButtonNoPressedEnter = class(GUIButton)

GUIButtonNoPressedEnter.states = class(GUIButton.states)

--------------------------------------------------------------------------------
-- State pressed callbacks
--------------------------------------------------------------------------------
GUIButtonNoPressedEnter.states.pressed = class()

GUIButtonNoPressedEnter.states.pressed.enter = function(element, previousState)
	GUI:debugPrint("GUIButtonNoPressedEnter : enter pressed " .. tostring(element), "states")
	if element.pressedVisual ~= nil then
		element:enableVisual(element.pressedVisual)
	else
		element:enableVisual(element.idleVisual)
	end
	
	if element.pressedAnimation ~= nil then
		GUI:debugPrint("GUIButtonNoPressedEnter : play pressed animation", "animations")
		Component_enable(element.pressedAnimation)
		AnimatorComponent_setSpeed(element.pressedAnimation, 1.0)
		AnimatorComponent_play(element.pressedAnimation)
	end
end
	
GUIButtonNoPressedEnter.states.pressed.leave = function(element, nextState)
	GUI:debugPrint("GUIButtonNoPressedEnter : leave pressed " .. tostring(element), "states")
	GUI.pressedEnterMode = false
	if element.pressedVisual ~= nil then
		element:disableVisual(element.pressedVisual)
	else
		element:disableVisual(element.idleVisual)
	end
	
	if element.pressedAnimation ~= nil and (not element.clickedAnimation or not Component_isEnabled(element.clickedAnimation) or not AnimatorComponent_isPlaying(element.clickedAnimation)) then
		GUI:debugPrint("GUIButtonNoPressedEnter : play released animation", "animations")
		--Component_enable(element.releasedAnimation)
		--AnimatorComponent_play(element.releasedAnimation)
		AnimatorComponent_setSpeed(element.pressedAnimation, -1.0)
		AnimatorComponent_play(element.pressedAnimation)
	end
end
