require 'scripts/gui/gui_button.lua'

GUIButtonTurbo = class(GUIButton)

GUIButtonTurbo.states = class(GUIButton.states)

GUIButtonTurbo.states.turbo = class()

GUIButtonTurbo.states.turbo.state = 0

function GUIButtonTurbo:sendCommand(command)
	GUI:debugPrint("GUIButtonTurbo sendCommand " .. tostring(command.id) .. " self = " .. tostring(self), "commands")
		
	if command.id == GUI_COMMAND_PRESS then
		GUI:debugPrint("GUIButtonTurbo pressed " .. tostring(self), "actions")
		GUI.pressMode = "repeat"
		self:setState("pressed")
		if self.listener ~= nil and self.listener.onButtonPress ~= nil then
			if self.states.turbo.state == 0 then
				self.states.turbo.startPressedTime = GUI.currentTime
				self.states.turbo.state = 1
				self.listener:onButtonPress(self, command.posX, command.posY)
			elseif self.states.turbo.state ~= 0 then
				if self.states.turbo.state == 1 then
					if GUI.currentTime - self.states.turbo.startPressedTime > GUI.REPEAT_DELAY then
						self.states.turbo.state = 2
						self.listener:onButtonPress(self, command.posX, command.posY)
					end
				elseif self.states.turbo.state == 2 then
					if GUI.currentTime - self.states.turbo.startPressedTime > GUI.REPEAT_RATE then
						self.states.turbo.startPressedTime = GUI.currentTime
						self.listener:onButtonPress(self, command.posX, command.posY)
					end
				end
			end
		end
		return true
		
	elseif command.id == GUI_COMMAND_RELEASE then
		GUI:debugPrint("GUIButtonTurbo released " .. tostring(self), "actions")
		GUI.pressMode = "once"
		self:setState("idle")
		self.states.turbo.state = 0
		if self.listener ~= nil and self.listener.onButtonRelease ~= nil then
			self.listener:onButtonRelease(self, command.posX, command.posY)
		end

		return true
		
	elseif command.id == GUI_COMMAND_CLICK then
		-- GUI:debugPrint("GUIButtonTurboRepeat clicked " .. tostring(self), "actions")
		
		-- if self.listener ~= nil and self.listener.onButtonClick ~= nil then
		-- 	self.listener:onButtonClick(self)
		-- end

		-- self:playClickedAnimation()
		
		return true
	else 
		return GUIElement.sendCommand(self, command)
	end
	
end







