add highlight indicator to token
not yet scripted
This commit is contained in:
5
grid.gd
5
grid.gd
@@ -21,7 +21,7 @@ func _ready():
|
||||
var token_node: Token = token.instantiate()
|
||||
add_child(token_node)
|
||||
token_node.position = Vector2(offset*column, offset*row)
|
||||
token_node.set_type(randi_range(0,3 ))
|
||||
token_node.set_type(randi_range(0,3) as Token.token_type)
|
||||
token_node.set_debug_label(str(row) + "," + str(column))
|
||||
token_node.token_clicked.connect(_on_token_clicked.bind([row,column]))
|
||||
grid[row].append(token_node)
|
||||
@@ -33,6 +33,9 @@ func _process(_delta: float) -> void:
|
||||
|
||||
func _on_token_clicked(token_coord):
|
||||
print(str(token_coord) + ", " + str(get_group_of_token(token_coord)))
|
||||
|
||||
func highlight_group(group: Array):
|
||||
pass
|
||||
|
||||
func populate_grid():
|
||||
pass
|
||||
|
||||
11
token.gd
11
token.gd
@@ -4,14 +4,18 @@ class_name Token
|
||||
signal token_clicked
|
||||
|
||||
enum token_type {TYPE_1, TYPE_2, TYPE_3, TYPE_4}
|
||||
enum token_state {NONE, HIGHLIGHT}
|
||||
|
||||
var type: token_type = token_type.TYPE_1
|
||||
var state: token_state = token_state.NONE
|
||||
|
||||
var color_polygon
|
||||
var color_polygon: Polygon2D
|
||||
var highlight_polygon: Polygon2D
|
||||
var debug_label: Label
|
||||
|
||||
func _ready():
|
||||
color_polygon = $Color
|
||||
highlight_polygon = $highlight_indicator
|
||||
debug_label = $"Debug Label"
|
||||
|
||||
func set_type(type: token_type):
|
||||
@@ -24,7 +28,7 @@ func set_type(type: token_type):
|
||||
token_type.TYPE_3:
|
||||
color_polygon.color = Color.BLUE
|
||||
token_type.TYPE_4:
|
||||
color_polygon.color = Color.YELLOW
|
||||
color_polygon.color = Color.GOLD
|
||||
|
||||
func set_debug_label(text: String):
|
||||
debug_label.text = text
|
||||
@@ -34,3 +38,6 @@ 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
|
||||
|
||||
25
token.tscn
25
token.tscn
@@ -7,12 +7,12 @@
|
||||
outline_size = 2
|
||||
outline_color = Color(0, 0, 0, 1)
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_bd72f"]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0ucay"]
|
||||
size = Vector2(51, 51)
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_bd72f"]
|
||||
blend_mode = 1
|
||||
|
||||
[node name="Token" type="Node2D"]
|
||||
script = ExtResource("1_0ucay")
|
||||
|
||||
@@ -25,13 +25,6 @@ offset_bottom = 41.0
|
||||
text = "1,1"
|
||||
label_settings = SubResource("LabelSettings_0ucay")
|
||||
|
||||
[node name="Color" type="Polygon2D" parent="."]
|
||||
z_index = 1
|
||||
material = SubResource("CanvasItemMaterial_bd72f")
|
||||
position = Vector2(6, 6)
|
||||
color = Color(0.84101, 0.000705212, 0.866408, 1)
|
||||
polygon = PackedVector2Array(0, 0, 40, 0, 40, 40, 0, 40)
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
scale = Vector2(0.4, 0.4)
|
||||
texture = ExtResource("1_bd72f")
|
||||
@@ -43,4 +36,16 @@ centered = false
|
||||
position = Vector2(26, 25.5)
|
||||
shape = SubResource("RectangleShape2D_0ucay")
|
||||
|
||||
[node name="Color" type="Polygon2D" parent="."]
|
||||
material = SubResource("CanvasItemMaterial_bd72f")
|
||||
position = Vector2(6, 6)
|
||||
color = Color(0.84101, 0.000705212, 0.866408, 1)
|
||||
polygon = PackedVector2Array(0, 0, 40, 0, 40, 40, 0, 40)
|
||||
|
||||
[node name="highlight_indicator" type="Polygon2D" parent="."]
|
||||
position = Vector2(52.8333, 76.6667)
|
||||
scale = Vector2(0.427083, 0.319444)
|
||||
polygon = PackedVector2Array(-112, -96, -16, -96, -64, -168)
|
||||
uv = PackedVector2Array(-112, -96, -16, -96, -72, -160)
|
||||
|
||||
[connection signal="input_event" from="Area2D" to="." method="_on_area_2d_input_event"]
|
||||
|
||||
Reference in New Issue
Block a user