1
0
Fork 0

Command input fixes

This commit is contained in:
Michaël Lemaire 2022-10-24 01:09:57 +02:00
parent a1fc8d912a
commit 3e67210261
3 changed files with 32 additions and 28 deletions

View File

@ -23,19 +23,16 @@ signal clicked
@export var code: String
func _compose():
$badge/icon.texture = icon
$badge.self_modulate = color
%icon.texture = icon
%badge.self_modulate = color
super._compose()
func _on_click_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
get_viewport().set_input_as_handled()
clicked.emit()
func apply(container: Node2D, pos: Vector2):
if get_parent() != container:
if get_parent():
get_parent().remove_child(self)
container.add_child(self)
position = pos
func _on_badge_pressed():
clicked.emit()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=5 format=3 uid="uid://b3l4jfjieucrc"]
[gd_scene load_steps=4 format=3 uid="uid://b3l4jfjieucrc"]
[ext_resource type="Script" path="res://core/ui/command.gd" id="1_bwbsk"]
@ -14,23 +14,27 @@ fill = 1
fill_from = Vector2(0.5, 0.5)
fill_to = Vector2(0.5, 0)
[sub_resource type="CircleShape2D" id="CircleShape2D_7etna"]
radius = 80.0
[node name="command" type="Node2D"]
script = ExtResource("1_bwbsk")
color = Color(0, 0, 0, 1)
code = ""
[node name="badge" type="Sprite2D" parent="."]
texture = SubResource("GradientTexture2D_3dnb6")
[node name="badge" type="TextureButton" parent="."]
unique_name_in_owner = true
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -80.0
offset_top = -80.0
offset_right = 80.0
offset_bottom = 80.0
grow_horizontal = 2
grow_vertical = 2
texture_normal = SubResource("GradientTexture2D_3dnb6")
[node name="icon" type="Sprite2D" parent="badge"]
[node name="icon" type="Sprite2D" parent="."]
unique_name_in_owner = true
[node name="click" type="Area2D" parent="."]
monitoring = false
monitorable = false
[node name="area" type="CollisionShape2D" parent="click"]
shape = SubResource("CircleShape2D_7etna")
[connection signal="input_event" from="click" to="." method="_on_click_input_event"]
[connection signal="pressed" from="badge" to="." method="_on_badge_pressed"]

View File

@ -35,7 +35,7 @@ func _show_command_wheel(pos: Vector2):
# TODO only available
command = command.duplicate()
command.color = player.color
command.connect("clicked", _on_wheel_command_clicked.bind(command))
command.connect("clicked", _on_wheel_command_clicked.bind(command), CONNECT_ONE_SHOT)
%wheel.add_child(command)
wheel.visible = true
@ -46,6 +46,9 @@ func _on_wheel_command_clicked(command: Command):
commands_changed.emit(player, %active.get_children())
func background_clicked(pos):
if camera:
pos = camera.get_canvas_transform().inverse() * pos
_show_command_wheel(pos)
if %wheel.visible:
%wheel.visible = false
else:
if camera:
pos = camera.get_canvas_transform().inverse() * pos
_show_command_wheel(pos)