Card drag
This commit is contained in:
parent
621bcf75cb
commit
0418606bd8
11 changed files with 92 additions and 0 deletions
|
|
@ -10,3 +10,7 @@ class_name CardResource
|
|||
@export var preview: Texture2D
|
||||
@export var experimental: bool = false
|
||||
@export var background: Texture2D = preload("uid://c6akwwb58fidc")
|
||||
|
||||
@export_group("Reference")
|
||||
@export var name_key: StringName
|
||||
@export var description_key: StringName
|
||||
|
|
|
|||
|
|
@ -2,10 +2,38 @@ extends TextureRect
|
|||
|
||||
class_name Card
|
||||
|
||||
const PIXEL_PER_ROTATION: float = 32.
|
||||
const ROTATION = PI/6.
|
||||
|
||||
@export var card_resource: CardResource
|
||||
var dragged: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
$UnitPreview.texture = card_resource.preview
|
||||
texture = card_resource.background
|
||||
$CostBubble/Cost.text = str(card_resource.cost)
|
||||
$ExperimentalBadge.visible = card_resource.experimental
|
||||
$Name.text = tr(card_resource.name_key)
|
||||
$Description.text = tr(card_resource.description_key)
|
||||
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
dragged = true
|
||||
top_level = true
|
||||
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
|
||||
top_level = false
|
||||
accept_event()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not dragged:
|
||||
rotation = lerp(rotation,0.,0.25)
|
||||
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
|
||||
rotation = lerp(rotation,clamp(relative_x/PIXEL_PER_ROTATION*ROTATION,-ROTATION,ROTATION),0.25)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@
|
|||
[ext_resource type="Texture2D" uid="uid://c3p3hl0epd5rg" path="res://cards/templates/cost-bubble.png" id="3_4k7q8"]
|
||||
[ext_resource type="Texture2D" uid="uid://b5vvxpoic7glj" path="res://cards/templates/experimental.png" id="4_f61jr"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_jsqqk"]
|
||||
line_spacing = 1.0
|
||||
font_size = 12
|
||||
font_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="Card" type="TextureRect" unique_id=267582807]
|
||||
anchors_preset = -1
|
||||
anchor_right = 0.098000005
|
||||
|
|
@ -66,3 +71,22 @@ offset_bottom = 33.0
|
|||
grow_horizontal = 0
|
||||
mouse_filter = 2
|
||||
texture = ExtResource("4_f61jr")
|
||||
|
||||
[node name="Name" type="Label" parent="." unique_id=1153228998]
|
||||
layout_mode = 0
|
||||
offset_left = 12.0
|
||||
offset_top = 82.0
|
||||
offset_right = 104.0
|
||||
offset_bottom = 105.0
|
||||
label_settings = SubResource("LabelSettings_jsqqk")
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Description" type="Label" parent="." unique_id=364325297]
|
||||
layout_mode = 0
|
||||
offset_left = 12.0
|
||||
offset_top = 99.0
|
||||
offset_right = 104.0
|
||||
offset_bottom = 163.0
|
||||
label_settings = SubResource("LabelSettings_jsqqk")
|
||||
autowrap_mode = 2
|
||||
text_overrun_behavior = 4
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@
|
|||
[resource]
|
||||
script = ExtResource("2_61y7x")
|
||||
preview = ExtResource("2_m3011")
|
||||
name_key = &"doh"
|
||||
description_key = &"doh_desc"
|
||||
metadata/_custom_type_script = "uid://bmc0rqt8jb8vh"
|
||||
|
|
|
|||
|
|
@ -8,4 +8,6 @@
|
|||
script = ExtResource("2_r84ts")
|
||||
cost = 1
|
||||
preview = ExtResource("2_uc1ms")
|
||||
name_key = &"fosma"
|
||||
description_key = &"fosma_desc"
|
||||
metadata/_custom_type_script = "uid://bmc0rqt8jb8vh"
|
||||
|
|
|
|||
|
|
@ -9,4 +9,6 @@ script = ExtResource("2_ongak")
|
|||
preview = ExtResource("2_xu3vf")
|
||||
experimental = true
|
||||
background = ExtResource("1_ongak")
|
||||
name_key = &"zlosma"
|
||||
description_key = &"zlosma_desc"
|
||||
metadata/_custom_type_script = "uid://bmc0rqt8jb8vh"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue