Changed some Control to Node2D to fix some z-index issues
This commit is contained in:
parent
7c703fa210
commit
db3ec0aa67
|
@ -1,5 +1,5 @@
|
|||
tool
|
||||
extends Panel
|
||||
extends Node2D
|
||||
|
||||
signal played(card, anchor)
|
||||
|
||||
|
@ -19,7 +19,7 @@ func _ready():
|
|||
set_portrait(portrait)
|
||||
set_title(title)
|
||||
set_spawned_unit(spawned_unit)
|
||||
base_position = rect_position
|
||||
base_position = position
|
||||
|
||||
func set_title(val):
|
||||
title = val
|
||||
|
@ -57,11 +57,11 @@ func can_be_used_on_anchor(anchor):
|
|||
return false
|
||||
|
||||
func set_hand_location(loc: Vector2):
|
||||
rect_position = loc
|
||||
position = loc
|
||||
base_position = loc
|
||||
|
||||
func update_anchors():
|
||||
var position = rect_global_position + rect_size / 2 if dragged else null
|
||||
var position = global_position if dragged else null
|
||||
selected_anchor = BattleHelper.update_anchors(get_tree(), position, funcref(self, "can_be_used_on_anchor"))
|
||||
|
||||
func play(anchor):
|
||||
|
@ -74,21 +74,18 @@ func play(anchor):
|
|||
func return_to_base():
|
||||
AnimHelper.linear_goto(self, base_position, 0.3)
|
||||
|
||||
func _gui_input(event):
|
||||
if event is InputEventMouseButton and event.button_index == 1:
|
||||
if event.pressed:
|
||||
dragged = true
|
||||
modulate = Color(1, 1, 1, 0.5)
|
||||
elif dragged:
|
||||
dragged = false
|
||||
modulate = Color(1, 1, 1, 1)
|
||||
func on_dragged(active, relative, absolute):
|
||||
if dragged != active:
|
||||
dragged = active
|
||||
modulate = Color(1, 1, 1, 0.5) if dragged else Color(1, 1, 1, 1)
|
||||
|
||||
if not dragged:
|
||||
if selected_anchor:
|
||||
play(selected_anchor)
|
||||
else:
|
||||
return_to_base()
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
if event.button_mask == BUTTON_LEFT:
|
||||
set_position(rect_position + event.relative)
|
||||
|
||||
if relative:
|
||||
set_position(position + relative)
|
||||
|
||||
update_anchors()
|
||||
|
|
|
@ -4,30 +4,21 @@
|
|||
[ext_resource path="res://cards/base_card.gd" type="Script" id=2]
|
||||
[ext_resource path="res://theme/ui.tres" type="Theme" id=3]
|
||||
[ext_resource path="res://theme/fonts/daggersquare.regular.otf" type="DynamicFontData" id=4]
|
||||
[ext_resource path="res://cards/base_card_portrait.png" type="Texture" id=5]
|
||||
[ext_resource path="res://helpers/drag.gd" type="Script" id=5]
|
||||
[ext_resource path="res://units/points.tscn" type="PackedScene" id=6]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 22
|
||||
font_data = ExtResource( 4 )
|
||||
|
||||
[node name="card" type="Panel"]
|
||||
[node name="card" type="Node2D"]
|
||||
self_modulate = Color( 1, 1, 1, 0 )
|
||||
margin_left = -90.0
|
||||
margin_top = -120.0
|
||||
margin_right = 90.0
|
||||
margin_bottom = 120.0
|
||||
mouse_default_cursor_shape = 6
|
||||
theme = ExtResource( 3 )
|
||||
z_index = 30
|
||||
z_as_relative = false
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
portrait = ExtResource( 5 )
|
||||
|
||||
[node name="background" type="Sprite" parent="."]
|
||||
position = Vector2( 90, 120 )
|
||||
z_as_relative = false
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="title" type="Label" parent="."]
|
||||
|
@ -48,14 +39,18 @@ __meta__ = {
|
|||
[node name="portrait" type="Sprite" parent="."]
|
||||
position = Vector2( 90, 140 )
|
||||
scale = Vector2( 0.6, 0.6 )
|
||||
texture = ExtResource( 5 )
|
||||
|
||||
[node name="points" parent="." instance=ExtResource( 6 )]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_top = 78.0
|
||||
margin_bottom = 123.0
|
||||
rect_scale = Vector2( 0.5, 0.5 )
|
||||
position = Vector2( 90, 220 )
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
|
||||
[node name="drag" type="Control" parent="."]
|
||||
margin_right = 180.0
|
||||
margin_bottom = 240.0
|
||||
script = ExtResource( 5 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="dragged" from="drag" to="." method="on_dragged"]
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
extends Control
|
||||
|
||||
signal dragged(active, relative, absolute)
|
||||
|
||||
func _gui_input(event):
|
||||
if event is InputEventMouseButton and event.button_index == 1:
|
||||
emit_signal("dragged", event.pressed, Vector2(), event.global_position)
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
if event.button_mask == BUTTON_LEFT:
|
||||
emit_signal("dragged", true, event.relative, event.global_position)
|
|
@ -14,7 +14,7 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://arenas/anchor.gd"
|
||||
}, {
|
||||
"base": "Panel",
|
||||
"base": "Node2D",
|
||||
"class": "BaseUnit",
|
||||
"language": "GDScript",
|
||||
"path": "res://units/base_unit.gd"
|
||||
|
@ -24,7 +24,7 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://arenas/route.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"base": "Sprite",
|
||||
"class": "UnitPoints",
|
||||
"language": "GDScript",
|
||||
"path": "res://units/points.gd"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
tool
|
||||
extends Panel
|
||||
extends Node2D
|
||||
|
||||
class_name BaseUnit
|
||||
|
||||
|
@ -85,8 +85,7 @@ func can_be_used_on_anchor(anchor):
|
|||
return playable and anchor is Anchor and anchor.is_connected_to(get_parent()) and (anchor.is_empty() or can_target(anchor.get_content()))
|
||||
|
||||
func update_anchors():
|
||||
var cursor = rect_global_position + dragged if dragged else null
|
||||
selected_anchor = BattleHelper.update_anchors(get_tree(), cursor, funcref(self, "can_be_used_on_anchor"))
|
||||
selected_anchor = BattleHelper.update_anchors(get_tree(), dragged, funcref(self, "can_be_used_on_anchor"))
|
||||
|
||||
func play(anchor):
|
||||
if playable:
|
||||
|
@ -101,11 +100,11 @@ func play(anchor):
|
|||
func move_to(anchor):
|
||||
if $points.move:
|
||||
$points.move -= 1
|
||||
var position = rect_global_position
|
||||
var old_position = global_position
|
||||
anchor.set_content(self)
|
||||
rect_position = position - anchor.position
|
||||
$sprite.rotation = atan2(-rect_position.y, -rect_position.x)
|
||||
AnimHelper.linear_goto(self, Vector2(-50, -50))
|
||||
set_position(old_position - anchor.position)
|
||||
$sprite.rotation = atan2(-position.y, -position.x)
|
||||
AnimHelper.linear_goto(self, Vector2())
|
||||
|
||||
func get_points() -> UnitPoints:
|
||||
if $points is UnitPoints:
|
||||
|
@ -145,26 +144,24 @@ func return_to_base():
|
|||
$move_hint.visible = false
|
||||
$move_hint.set_point_position(1, Vector2(0, 0))
|
||||
|
||||
func _gui_input(event):
|
||||
func on_dragged(active, relative, absolute):
|
||||
if not playable:
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton and event.button_index == 1:
|
||||
if event.pressed:
|
||||
dragged = event.position
|
||||
$move_hint.visible = true
|
||||
elif dragged:
|
||||
dragged = null
|
||||
$move_hint.visible = false
|
||||
if selected_anchor:
|
||||
play(selected_anchor)
|
||||
else:
|
||||
return_to_base()
|
||||
|
||||
if event is InputEventMouseMotion and event.button_mask == BUTTON_LEFT:
|
||||
dragged = event.position
|
||||
|
||||
if dragged and not active:
|
||||
if selected_anchor:
|
||||
play(selected_anchor)
|
||||
else:
|
||||
return_to_base()
|
||||
|
||||
$move_hint.visible = active
|
||||
|
||||
if active:
|
||||
dragged = absolute
|
||||
else:
|
||||
dragged = null
|
||||
|
||||
update_anchors()
|
||||
|
||||
if dragged:
|
||||
$move_hint.set_point_position(1, selected_anchor.global_position - rect_global_position if selected_anchor else dragged)
|
||||
$move_hint.set_point_position(1, (selected_anchor.global_position if selected_anchor else dragged) - global_position)
|
||||
|
|
|
@ -1,39 +1,40 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://units/base_unit.gd" type="Script" id=1]
|
||||
[ext_resource path="res://units/falcon.png" type="Texture" id=2]
|
||||
[ext_resource path="res://units/points.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://theme/ui.tres" type="Theme" id=4]
|
||||
[ext_resource path="res://helpers/drag.gd" type="Script" id=4]
|
||||
|
||||
[node name="unit" type="Panel"]
|
||||
[node name="unit" type="Node2D"]
|
||||
modulate = Color( 0.5, 0.5, 0.5, 1 )
|
||||
self_modulate = Color( 1, 1, 1, 0 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="sprite" type="Sprite" parent="."]
|
||||
z_index = 10
|
||||
z_as_relative = false
|
||||
|
||||
[node name="points" parent="." instance=ExtResource( 3 )]
|
||||
modulate = Color( 1, 0.3, 0.3, 1 )
|
||||
position = Vector2( 0, 100 )
|
||||
z_index = 20
|
||||
z_as_relative = false
|
||||
|
||||
[node name="move_hint" type="Line2D" parent="."]
|
||||
visible = false
|
||||
z_index = 30
|
||||
z_as_relative = false
|
||||
points = PoolVector2Array( 0, 0, 50, 50 )
|
||||
width = 18.0
|
||||
antialiased = true
|
||||
|
||||
[node name="drag" type="Control" parent="."]
|
||||
margin_left = -50.0
|
||||
margin_top = -50.0
|
||||
margin_right = 50.0
|
||||
margin_bottom = 50.0
|
||||
theme = ExtResource( 4 )
|
||||
script = ExtResource( 1 )
|
||||
script = ExtResource( 4 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
sprite = ExtResource( 2 )
|
||||
|
||||
[node name="sprite" type="Sprite" parent="."]
|
||||
position = Vector2( 50, 50 )
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="points" parent="." instance=ExtResource( 3 )]
|
||||
modulate = Color( 1, 0.3, 0.3, 1 )
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_top = 70.0
|
||||
margin_bottom = 115.0
|
||||
|
||||
[node name="move_hint" type="Line2D" parent="."]
|
||||
visible = false
|
||||
points = PoolVector2Array( 50, 50, 0, 0 )
|
||||
width = 18.0
|
||||
antialiased = true
|
||||
[connection signal="dragged" from="drag" to="." method="on_dragged"]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
tool
|
||||
extends Control
|
||||
extends Sprite
|
||||
|
||||
class_name UnitPoints
|
||||
|
||||
|
|
|
@ -4,22 +4,19 @@
|
|||
[ext_resource path="res://theme/ui.tres" type="Theme" id=2]
|
||||
[ext_resource path="res://units/points.gd" type="Script" id=3]
|
||||
|
||||
[node name="points" type="Control"]
|
||||
margin_left = -150.0
|
||||
margin_right = 150.0
|
||||
margin_bottom = 45.0
|
||||
rect_pivot_offset = Vector2( 150, 22.5 )
|
||||
theme = ExtResource( 2 )
|
||||
script = ExtResource( 3 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="hud" type="Sprite" parent="."]
|
||||
position = Vector2( 150, 23 )
|
||||
[node name="points" type="Sprite"]
|
||||
texture = ExtResource( 1 )
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="hud" type="Control" parent="."]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
theme = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_group_": true
|
||||
"_edit_group_": true,
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="move" type="Label" parent="hud"]
|
||||
|
|
Loading…
Reference in New Issue