Outline item component

This commit is contained in:
2023-10-08 03:14:13 +02:00
parent e6de1f1323
commit cdf85cd1c5
6 changed files with 57 additions and 55 deletions

View File

@@ -44,63 +44,13 @@ var custom_data: Dictionary = {}
# ] # ]
export(Array) var count_textures = [] 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(): 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() 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): func set_tooltip(action: String, text: String):
tooltips[action] = text 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: func has_component(key: String)->bool:
return components.has(key) return components.has(key)
@@ -110,8 +60,12 @@ func get_component(key: String):
return null return null
func register_components(): func register_components():
autoload_components()
for child in get_children(): for child in get_children():
if(child is ESCItemComponent): if(child is ESCItemComponent):
child = child as ESCItemComponent child = child as ESCItemComponent
components[child.get_component_type()] = child components[child.get_component_type()] = child
child.register(custom_data) child.register(custom_data)
func autoload_components():
add_child(ESCItemComponentOutline.new())

View File

@@ -8,10 +8,12 @@ export(bool) var selectable = false
# A player is always movable # A player is always movable
func _init(): func _init():
._init()
is_movable = true is_movable = true
_force_registration = true _force_registration = true
# Ready function # Ready function
func _ready(): func _ready():
if selectable: if selectable:

View File

@@ -252,9 +252,9 @@ func element_focused(element_id: String) -> void:
if target_obj is ESCItem or ESCItemWithTooltip: if target_obj is ESCItem or ESCItemWithTooltip:
$tooltip_layer/tooltip.set_target(target_obj.tooltip_name) $tooltip_layer/tooltip.set_target(target_obj.tooltip_name)
$tooltip_layer/tooltip.set_target_object(target_obj) $tooltip_layer/tooltip.set_target_object(target_obj)
target_obj.highlight(true) target_obj.get_component('outline').highlight(true)
if last_target != null: if last_target != null:
last_target.highlight(false) last_target.get_component('outline').highlight(false)
last_target = target_obj last_target = target_obj
@@ -262,7 +262,7 @@ func element_unfocused() -> void:
$tooltip_layer/tooltip.set_target("") $tooltip_layer/tooltip.set_target("")
$tooltip_layer/tooltip.set_target_object(null) $tooltip_layer/tooltip.set_target_object(null)
if(last_target != null): if(last_target != null):
last_target.highlight(false) last_target.get_component('outline').highlight(false)
last_target = null last_target = null

View File

@@ -11,4 +11,3 @@ func get_component_type():
func register(custom_data: Dictionary): func register(custom_data: Dictionary):
pass pass

View File

@@ -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)

View File

@@ -204,7 +204,7 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://addons/escoria-core/game/scenes/dialogs/esc_dialog_options_chooser.gd" "path": "res://addons/escoria-core/game/scenes/dialogs/esc_dialog_options_chooser.gd"
}, { }, {
"base": "StateMachine", "base": "Node",
"class": "ESCDialogPlayer", "class": "ESCDialogPlayer",
"language": "GDScript", "language": "GDScript",
"path": "res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd" "path": "res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd"
@@ -289,6 +289,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://gymkhana/addons/escoria-ui-return-monkey-island/item_components/ESCItemComponent.gd" "path": "res://gymkhana/addons/escoria-ui-return-monkey-island/item_components/ESCItemComponent.gd"
}, { }, {
"base": "ESCItemComponent",
"class": "ESCItemComponentOutline",
"language": "GDScript",
"path": "res://gymkhana/addons/escoria-ui-return-monkey-island/item_components/ESCItemComponentOutline.gd"
}, {
"base": "Resource", "base": "Resource",
"class": "ESCItemCountManager", "class": "ESCItemCountManager",
"language": "GDScript", "language": "GDScript",
@@ -791,6 +796,7 @@ _global_script_class_icons={
"ESCInventoryManager": "", "ESCInventoryManager": "",
"ESCItem": "res://addons/escoria-core/design/esc_item.svg", "ESCItem": "res://addons/escoria-core/design/esc_item.svg",
"ESCItemComponent": "", "ESCItemComponent": "",
"ESCItemComponentOutline": "",
"ESCItemCountManager": "", "ESCItemCountManager": "",
"ESCItemWithTooltip": "res://addons/escoria-core/design/esc_item.svg", "ESCItemWithTooltip": "res://addons/escoria-core/design/esc_item.svg",
"ESCLocation": "res://addons/escoria-core/design/esc_location.svg", "ESCLocation": "res://addons/escoria-core/design/esc_location.svg",