Some improvements

This commit is contained in:
rendo 2026-02-19 19:33:33 +05:00
commit f816a8b886
4 changed files with 81 additions and 17 deletions

View file

@ -19,13 +19,18 @@ func _ready() -> void:
func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
dragged = true
var pos = global_position
top_level = true
global_position = pos
accept_event()
func _input(event: InputEvent) -> void:
if dragged and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
dragged = false
var pos = global_position
top_level = false
global_position = pos
accept_event()
func _process(_delta: float) -> void:
@ -34,6 +39,6 @@ func _process(_delta: float) -> void:
return
var mouse_pos = get_global_mouse_position()-get_combined_pivot_offset()
position = lerp(position,mouse_pos,0.25)
var relative_x = mouse_pos.x - position.x
global_position = lerp(global_position,mouse_pos,0.25)
var relative_x = mouse_pos.x - global_position.x
rotation = lerp(rotation,clamp(relative_x/PIXEL_PER_ROTATION*ROTATION,-ROTATION,ROTATION),0.25)

View file

@ -2,6 +2,7 @@
[ext_resource type="Texture2D" uid="uid://b2pm032d5tqwb" path="res://sprites/field.png" id="1_iywne"]
[ext_resource type="PackedScene" uid="uid://dl3ve6prnn2m6" path="res://cards/card.tscn" id="2_p57ef"]
[ext_resource type="Script" uid="uid://caf4h6lok18so" path="res://ui/hand.gd" id="2_u5sy4"]
[ext_resource type="Resource" uid="uid://e7kiu3wcf0ff" path="res://cards/resources/fosma.tres" id="3_u5sy4"]
[ext_resource type="Resource" uid="uid://djqlx7bmcs5gj" path="res://cards/resources/doh.tres" id="4_gee14"]
[ext_resource type="Resource" uid="uid://b6kiwb0marpng" path="res://cards/resources/zlosma.tres" id="5_0tnpc"]
@ -14,23 +15,53 @@ centered = false
[node name="PlayerInterface" type="CanvasLayer" parent="." unique_id=269857956]
[node name="Card" parent="." unique_id=267582807 instance=ExtResource("2_p57ef")]
offset_left = 401.0
offset_top = 466.0
offset_right = 514.0
offset_bottom = 635.0
[node name="Hand" type="Control" parent="PlayerInterface" unique_id=403305026]
layout_mode = 3
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 0
pivot_offset_ratio = Vector2(0.5, 0.5)
script = ExtResource("2_u5sy4")
[node name="Card" parent="PlayerInterface/Hand" unique_id=267582807 instance=ExtResource("2_p57ef")]
layout_mode = 0
anchors_preset = 0
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 402.0
offset_right = 515.0
offset_bottom = 169.0
card_resource = ExtResource("3_u5sy4")
[node name="Card2" parent="." unique_id=1229293312 instance=ExtResource("2_p57ef")]
offset_left = 544.0
offset_top = 467.0
offset_right = 657.0
offset_bottom = 636.0
[node name="Card2" parent="PlayerInterface/Hand" unique_id=1229293312 instance=ExtResource("2_p57ef")]
layout_mode = 0
anchors_preset = 0
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 519.0
offset_right = 632.0
offset_bottom = 169.0
card_resource = ExtResource("4_gee14")
[node name="Card3" parent="." unique_id=1907397406 instance=ExtResource("2_p57ef")]
offset_left = 698.0
offset_top = 471.0
offset_right = 811.0
offset_bottom = 640.0
[node name="Card4" parent="PlayerInterface/Hand" unique_id=1427311772 instance=ExtResource("2_p57ef")]
layout_mode = 0
anchors_preset = 0
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 804.0
offset_right = 917.0
offset_bottom = 169.0
card_resource = ExtResource("3_u5sy4")
[node name="Card3" parent="PlayerInterface/Hand" unique_id=1907397406 instance=ExtResource("2_p57ef")]
layout_mode = 0
anchors_preset = 0
anchor_right = 0.0
anchor_bottom = 0.0
offset_left = 636.0
offset_right = 749.0
offset_bottom = 169.0
card_resource = ExtResource("5_0tnpc")

27
ui/hand.gd Normal file
View file

@ -0,0 +1,27 @@
@tool
extends Control
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
var calculated_size: Vector2 = Vector2.ZERO
for card: Card in get_children():
calculated_size += card.get_rect().size
calculated_size.y /= get_child_count()
var offset: float = 0.
for i in range(get_child_count()):
var card:Card = get_child(i)
offset += card.get_rect().size.x
if card.top_level:
continue
var calculated_position: Vector2 = get_combined_pivot_offset() - calculated_size * Vector2(1.-1./get_child_count(),1) + Vector2.RIGHT*offset
card.position = lerp(card.position,calculated_position,0.25)
func resort_by_position():
var children: Array = get_children()

1
ui/hand.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://caf4h6lok18so