Outline item component
This commit is contained in:
@@ -44,62 +44,12 @@ var custom_data: Dictionary = {}
|
||||
# ]
|
||||
export(Array) var count_textures = []
|
||||
|
||||
var outline: ItemOutline
|
||||
|
||||
var isHighlighted: 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()
|
||||
register_components()
|
||||
|
||||
|
||||
func _process(_delta) -> void:
|
||||
if(is_interactive == false):
|
||||
return
|
||||
|
||||
if isHighlighted != lastHighlightState:
|
||||
if isHighlighted:
|
||||
outline.show()
|
||||
else:
|
||||
outline.hide()
|
||||
lastHighlightState = isHighlighted
|
||||
pass
|
||||
|
||||
func highlight(value: bool):
|
||||
isHighlighted = 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)
|
||||
|
||||
func has_component(key: String)->bool:
|
||||
return components.has(key)
|
||||
@@ -110,8 +60,12 @@ func get_component(key: String):
|
||||
return null
|
||||
|
||||
func register_components():
|
||||
autoload_components()
|
||||
for child in get_children():
|
||||
if(child is ESCItemComponent):
|
||||
child = child as ESCItemComponent
|
||||
components[child.get_component_type()] = child
|
||||
child.register(custom_data)
|
||||
|
||||
func autoload_components():
|
||||
add_child(ESCItemComponentOutline.new())
|
||||
@@ -8,8 +8,10 @@ export(bool) var selectable = false
|
||||
|
||||
# A player is always movable
|
||||
func _init():
|
||||
._init()
|
||||
is_movable = true
|
||||
_force_registration = true
|
||||
|
||||
|
||||
|
||||
# Ready function
|
||||
|
||||
@@ -252,9 +252,9 @@ func element_focused(element_id: String) -> void:
|
||||
if target_obj is ESCItem or ESCItemWithTooltip:
|
||||
$tooltip_layer/tooltip.set_target(target_obj.tooltip_name)
|
||||
$tooltip_layer/tooltip.set_target_object(target_obj)
|
||||
target_obj.highlight(true)
|
||||
target_obj.get_component('outline').highlight(true)
|
||||
if last_target != null:
|
||||
last_target.highlight(false)
|
||||
last_target.get_component('outline').highlight(false)
|
||||
last_target = target_obj
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ func element_unfocused() -> void:
|
||||
$tooltip_layer/tooltip.set_target("")
|
||||
$tooltip_layer/tooltip.set_target_object(null)
|
||||
if(last_target != null):
|
||||
last_target.highlight(false)
|
||||
last_target.get_component('outline').highlight(false)
|
||||
last_target = null
|
||||
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ func get_component_type():
|
||||
|
||||
func register(custom_data: Dictionary):
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
extends ESCItemComponent
|
||||
class_name ESCItemComponentOutline
|
||||
|
||||
var outline: ItemOutline
|
||||
|
||||
var isHighlighted: bool
|
||||
var lastHighlightState: bool
|
||||
|
||||
func get_component_type():
|
||||
return "outline"
|
||||
|
||||
func _ready():
|
||||
var collision = get_parent().collision
|
||||
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))
|
||||
collision.add_child(outline)
|
||||
outline.hide()
|
||||
|
||||
|
||||
func highlight(value: bool):
|
||||
isHighlighted = value
|
||||
|
||||
func _process(_delta: float):
|
||||
if not escoria.action_manager.is_object_actionable(get_global_id()):
|
||||
return
|
||||
if isHighlighted != lastHighlightState:
|
||||
if isHighlighted:
|
||||
outline.show()
|
||||
else:
|
||||
outline.hide()
|
||||
lastHighlightState = isHighlighted
|
||||
|
||||
func _input(event):
|
||||
if(event.is_action_pressed("ui_show_hints")):
|
||||
highlight(true)
|
||||
elif (event.is_action_released("ui_show_hints")):
|
||||
highlight(false)
|
||||
Reference in New Issue
Block a user