Implemented group highlight on hover
It's not currently stable, but it's ok for now.
This commit is contained in:
19
token.gd
19
token.gd
@@ -2,6 +2,7 @@ extends Node2D
|
||||
class_name Token
|
||||
|
||||
signal token_clicked
|
||||
signal token_hovered(entered: bool)
|
||||
|
||||
enum token_type {TYPE_1, TYPE_2, TYPE_3, TYPE_4}
|
||||
enum token_state {NONE, HIGHLIGHT}
|
||||
@@ -17,7 +18,7 @@ func _ready():
|
||||
color_polygon = $Color
|
||||
highlight_polygon = $highlight_indicator
|
||||
debug_label = $"Debug Label"
|
||||
|
||||
|
||||
func set_type(type: token_type):
|
||||
self.type = type
|
||||
match self.type:
|
||||
@@ -29,7 +30,7 @@ func set_type(type: token_type):
|
||||
color_polygon.color = Color.BLUE
|
||||
token_type.TYPE_4:
|
||||
color_polygon.color = Color.GOLD
|
||||
|
||||
|
||||
func set_debug_label(text: String):
|
||||
debug_label.text = text
|
||||
|
||||
@@ -38,6 +39,18 @@ func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int)
|
||||
# emit event up to parent on click
|
||||
if Input.is_action_just_pressed("select"):
|
||||
token_clicked.emit()
|
||||
|
||||
|
||||
func set_highlighted(highlight: bool):
|
||||
state = token_state.HIGHLIGHT if highlight else token_state.NONE
|
||||
match state:
|
||||
token_state.HIGHLIGHT:
|
||||
highlight_polygon.visible = true
|
||||
token_state.NONE:
|
||||
highlight_polygon.visible = false
|
||||
|
||||
|
||||
func _on_area_2d_mouse_entered() -> void:
|
||||
token_hovered.emit(true)
|
||||
|
||||
func _on_area_2d_mouse_exited() -> void:
|
||||
token_hovered.emit(false)
|
||||
|
||||
Reference in New Issue
Block a user