tool
extends ESCItem
class_name ESCItemWithTooltip, "res://addons/escoria-core/design/esc_item.svg"

# Action 1 Label text
export(String) var action1_text = ""

# Action 2 Label text
export(String) var action2_text = ""

# Action 3 tooltip text if item in inventory
export(String) var action3_text = ""

# Action 4 tooltip text if item in inventory
export(String) var action4_text = ""

export(Dictionary) var tooltips = {}

# Action 3 tooltip texts if item is target. Dictionary with tool's global id as key.
export(Dictionary) var action3_target_texts = {}

# Action 4 tooltip texts if item is target. Dictionary with tool's global id as key.
export(Dictionary) var action4_target_texts = {}

# If action used by player is in this list, this is a valid target (second item in combination)
export(Array) var target_when_selected_action_is_in = []

var outline: ItemOutline

var highlight: bool
var lastHighlightState: bool

var active: bool

# React to the mouse entering the item by emitting the respective signal
func mouse_entered():
	active = true
	if escoria.action_manager.is_object_actionable(global_id):
		emit_signal("mouse_entered_item", self)


# React to the mouse exiting the item by emitting the respective signal
func mouse_exited():
	active = false
	emit_signal("mouse_exited_item",  self)

func _ready():
	if collision is CollisionPolygon2D:
		outline = ItemOutline.new()
		outline.polygon =  collision.get("polygon")
		outline.color = Color(1,1,1,0.2)
		outline.set_outline_width(2.0)
		outline.set_outline_color(Color(1,1,1,1))
		##outline.offset = Vector2(1,1)
		collision.add_child(outline)
		outline.hide()

func _process(_delta) -> void:
	if(is_interactive == false):
		return
	
	if highlight != lastHighlightState:
		if highlight:
			outline.show()
		else:
			outline.hide()
		lastHighlightState = highlight
	pass

func highlight(value: bool):
	highlight = value

func set_tooltip(action: String, text: String):
	tooltips[action] =  text
	
func _input(event):
	if(event.is_action_pressed("ui_show_hints")):
		highlight(true)
	elif (event.is_action_released("ui_show_hints")):
		if(!active):
			highlight(false)
