Command Ui flow fixes
This commit is contained in:
parent
3e67210261
commit
83b9617edd
|
@ -21,17 +21,11 @@ code = ""
|
|||
|
||||
[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
|
||||
self_modulate = Color(0, 0, 0, 1)
|
||||
offset_left = -80.0
|
||||
offset_top = -80.0
|
||||
offset_right = 80.0
|
||||
offset_bottom = 80.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
offset_right = -80.0
|
||||
offset_bottom = -80.0
|
||||
texture_normal = SubResource("GradientTexture2D_3dnb6")
|
||||
|
||||
[node name="icon" type="Sprite2D" parent="."]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
extends Node
|
||||
extends Node2D
|
||||
|
||||
@export var player: Node:
|
||||
set(val):
|
||||
|
@ -26,29 +26,45 @@ func _show_command_wheel(pos: Vector2):
|
|||
var wheel := %wheel as Node2D
|
||||
wheel.position = pos
|
||||
|
||||
# TODO center cam ?
|
||||
if camera:
|
||||
camera.global_position = pos
|
||||
|
||||
for command in %wheel.get_children():
|
||||
command.queue_free()
|
||||
|
||||
var inc := PI * 2.0 / %stock.get_child_count()
|
||||
var idx := 0
|
||||
for command in %stock.get_children():
|
||||
# TODO only available
|
||||
command = command.duplicate()
|
||||
command.color = player.color
|
||||
command.position = Vector2.from_angle(inc * idx) * 200.0
|
||||
command.connect("clicked", _on_wheel_command_clicked.bind(command), CONNECT_ONE_SHOT)
|
||||
var line := Line2D.new()
|
||||
line.add_point(Vector2.ZERO)
|
||||
line.add_point(command.position)
|
||||
%wheel.add_child(line)
|
||||
%wheel.add_child(command)
|
||||
idx += 1
|
||||
|
||||
wheel.visible = true
|
||||
%wheelanim.play("show")
|
||||
|
||||
func _on_wheel_command_clicked(command: Command):
|
||||
command.apply(%active, %wheel.position)
|
||||
%wheel.visible = false
|
||||
command.apply(%active, %wheel.position)
|
||||
command.scale *= 0.5
|
||||
command.connect("clicked", _on_active_command_clicked.bind(command))
|
||||
commands_changed.emit(player, %active.get_children())
|
||||
|
||||
func _on_active_command_clicked(command: Command):
|
||||
command.queue_free()
|
||||
commands_changed.emit(player, %active.get_children())
|
||||
|
||||
func background_clicked(pos):
|
||||
if %wheel.visible:
|
||||
%wheel.visible = false
|
||||
%wheelanim.play("hide")
|
||||
else:
|
||||
if camera:
|
||||
pos = camera.get_canvas_transform().inverse() * pos
|
||||
pos = get_viewport().canvas_transform.affine_inverse() * pos
|
||||
_show_command_wheel(pos)
|
||||
|
|
|
@ -1,16 +1,113 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://xoup4vukp3ni"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://xoup4vukp3ni"]
|
||||
|
||||
[ext_resource type="Script" path="res://core/ui/commands.gd" id="1_8b4dn"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_mqivy"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("wheel:visible")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("wheel:scale")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1e-05, 1e-05)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ia7aa"]
|
||||
resource_name = "hide"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("wheel:visible")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0.5),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [false]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("wheel:scale")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1, 1), Vector2(1e-05, 1e-05)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ipugp"]
|
||||
resource_name = "show"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("wheel:visible")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("wheel:scale")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector2(1e-05, 1e-05), Vector2(1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_uuvsr"]
|
||||
_data = {
|
||||
"RESET": SubResource("Animation_mqivy"),
|
||||
"hide": SubResource("Animation_ia7aa"),
|
||||
"show": SubResource("Animation_ipugp")
|
||||
}
|
||||
|
||||
[node name="commands" type="Node2D"]
|
||||
script = ExtResource("1_8b4dn")
|
||||
|
||||
[node name="wheelanim" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_uuvsr")
|
||||
}
|
||||
|
||||
[node name="stock" type="Node2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
|
||||
[node name="wheel" type="Node2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="active" type="Node2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
z_index = -1000
|
||||
|
||||
[node name="wheel" type="Node2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
scale = Vector2(1e-05, 1e-05)
|
||||
z_index = 1000
|
||||
|
|
|
@ -1,36 +1,39 @@
|
|||
extends Control
|
||||
extends Node
|
||||
|
||||
signal scrolled(diff: Vector2)
|
||||
signal clicked(pos: Vector2)
|
||||
signal zoomed(diff: float)
|
||||
|
||||
var pressed = false
|
||||
var pressed := false
|
||||
var pressed_start := Vector2.ZERO
|
||||
|
||||
func _ready():
|
||||
get_viewport().connect("size_changed", resize)
|
||||
resize()
|
||||
|
||||
func resize():
|
||||
set_deferred("size", get_viewport().size)
|
||||
%clickarea.set_deferred("size", get_viewport().size)
|
||||
|
||||
func _gui_input(event):
|
||||
func _on_clickarea_gui_input(event: InputEvent):
|
||||
if event is InputEventMouseMotion:
|
||||
if event.button_mask & MOUSE_BUTTON_LEFT:
|
||||
pressed = false
|
||||
if event.position.distance_to(pressed_start) > 3.0:
|
||||
pressed = false
|
||||
scrolled.emit(event.relative)
|
||||
accept_event()
|
||||
%clickarea.accept_event()
|
||||
if event is InputEventMouseButton:
|
||||
if event.pressed:
|
||||
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||
zoomed.emit(signf(event.factor))
|
||||
accept_event()
|
||||
%clickarea.accept_event()
|
||||
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||
zoomed.emit(-signf(event.factor))
|
||||
accept_event()
|
||||
%clickarea.accept_event()
|
||||
elif event.button_index == MOUSE_BUTTON_LEFT:
|
||||
pressed = true
|
||||
pressed_start = event.position
|
||||
else:
|
||||
if event.button_index == MOUSE_BUTTON_LEFT and pressed:
|
||||
accept_event()
|
||||
%clickarea.accept_event()
|
||||
pressed = false
|
||||
clicked.emit(event.position)
|
||||
|
|
|
@ -2,7 +2,14 @@
|
|||
|
||||
[ext_resource type="Script" path="res://core/ui/inputs.gd" id="1_wm60j"]
|
||||
|
||||
[node name="inputs" type="Control"]
|
||||
[node name="inputs" type="Node"]
|
||||
script = ExtResource("1_wm60j")
|
||||
|
||||
[node name="layer" type="CanvasLayer" parent="."]
|
||||
layer = -10
|
||||
|
||||
[node name="clickarea" type="Control" parent="layer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
@ -12,4 +19,5 @@ grow_vertical = 2
|
|||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
mouse_force_pass_scroll_events = false
|
||||
script = ExtResource("1_wm60j")
|
||||
|
||||
[connection signal="gui_input" from="layer/clickarea" to="." method="_on_clickarea_gui_input"]
|
||||
|
|
24
main.tscn
24
main.tscn
|
@ -12,13 +12,14 @@
|
|||
|
||||
[node name="camera" parent="." instance=ExtResource("1_7evrt")]
|
||||
|
||||
[node name="backui" type="CanvasLayer" parent="."]
|
||||
layer = -1
|
||||
[node name="inputs" parent="." instance=ExtResource("2_wkcj2")]
|
||||
|
||||
[node name="inputs" parent="backui" instance=ExtResource("2_wkcj2")]
|
||||
[node name="commands" parent="." node_paths=PackedStringArray("player", "camera") instance=ExtResource("4_1gkbi")]
|
||||
player = NodePath("../world/player1")
|
||||
camera = NodePath("../camera")
|
||||
available_commands = [ExtResource("5_fi2mi")]
|
||||
|
||||
[node name="world" type="CanvasLayer" parent="."]
|
||||
follow_viewport_enabled = true
|
||||
[node name="world" type="Node2D" parent="."]
|
||||
|
||||
[node name="player1" parent="world" instance=ExtResource("2_o4smw")]
|
||||
color = Color(0, 0, 1, 1)
|
||||
|
@ -38,12 +39,7 @@ player = NodePath("../../player1")
|
|||
position = Vector2(929, 429)
|
||||
player = NodePath("../../player2")
|
||||
|
||||
[node name="commands" parent="world" node_paths=PackedStringArray("player", "camera") instance=ExtResource("4_1gkbi")]
|
||||
player = NodePath("../player1")
|
||||
camera = NodePath("../../camera")
|
||||
available_commands = [ExtResource("5_fi2mi")]
|
||||
|
||||
[connection signal="clicked" from="backui/inputs" to="world/commands" method="background_clicked"]
|
||||
[connection signal="scrolled" from="backui/inputs" to="camera" method="scroll"]
|
||||
[connection signal="zoomed" from="backui/inputs" to="camera" method="change_zoom"]
|
||||
[connection signal="commands_changed" from="world/commands" to="world/battlefield" method="_on_commands_changed"]
|
||||
[connection signal="clicked" from="inputs" to="commands" method="background_clicked"]
|
||||
[connection signal="scrolled" from="inputs" to="camera" method="scroll"]
|
||||
[connection signal="zoomed" from="inputs" to="camera" method="change_zoom"]
|
||||
[connection signal="commands_changed" from="commands" to="world/battlefield" method="_on_commands_changed"]
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
icon = ExtResource("2_6sktn")
|
||||
code = "delivery"
|
||||
|
||||
[node name="icon" parent="badge" index="0"]
|
||||
[node name="icon" parent="." index="1"]
|
||||
texture = ExtResource("2_6sktn")
|
||||
|
|
Loading…
Reference in New Issue