Add creature dragging
This commit is contained in:
parent
942edf5556
commit
1b2ee1a076
18 changed files with 280 additions and 34 deletions
|
@ -18,14 +18,7 @@ position = Vector2(156, 90)
|
|||
texture = ExtResource("3_kjcur")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
autostart = true
|
||||
|
||||
[node name="Timer2" type="Timer" parent="."]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
autostart = true
|
||||
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||
[connection signal="timeout" from="Timer2" to="." method="_on_timer_timeout"]
|
||||
|
|
6
MouseSignals.tscn
Normal file
6
MouseSignals.tscn
Normal file
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://dcmh5yv0fjmsb"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/mouse_signals.gd" id="1_mpp7j"]
|
||||
|
||||
[node name="MouseSignals" type="Node2D" groups=["mouse_signals"]]
|
||||
script = ExtResource("1_mpp7j")
|
6
NoCreMouseSignals.tscn
Normal file
6
NoCreMouseSignals.tscn
Normal file
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://5g4mecc4tb6f"]
|
||||
|
||||
[ext_resource type="Script" path="res://no_cre_build_signals.gd" id="1_bgmgm"]
|
||||
|
||||
[node name="MouseSignals" type="Node2D"]
|
||||
script = ExtResource("1_bgmgm")
|
|
@ -7,25 +7,72 @@ extends Base
|
|||
const CURSOR_UI = preload("res://components/Cursor/hover-1.png")
|
||||
const CURSOR_HOLD = preload("res://components/Cursor/grab-1.png")
|
||||
const CURSOR = preload("res://components/Cursor/normal-1.png")
|
||||
const CREATURE = preload("res://src/Creature.tscn")
|
||||
var rotation_tween
|
||||
|
||||
var cursor_tween
|
||||
var hovered_objects = 0
|
||||
var holding = false
|
||||
var held_item
|
||||
var grabbed_creature
|
||||
var signal_object
|
||||
var original_window
|
||||
var original_position
|
||||
var timer = 0
|
||||
var hover_timer = 0
|
||||
|
||||
func _ready() -> void:
|
||||
Persister.data_persisted.connect(_on_data_persisted)
|
||||
Triggerer.listen("grab_creature", _on_grab_creature)
|
||||
Triggerer.listen("hovered", _on_hovered)
|
||||
|
||||
for child in get_parent().get_children():
|
||||
if child.is_in_group("mouse_signals"):
|
||||
signal_object = child
|
||||
|
||||
|
||||
func _on_hovered(_data):
|
||||
hover_timer = 0.125
|
||||
|
||||
|
||||
func _on_grab_creature(data):
|
||||
held_item = data.creature
|
||||
print("GRAB")
|
||||
grabbed_creature = CREATURE.instantiate()
|
||||
grabbed_creature.key = data.creature
|
||||
mouse_control.add_child(grabbed_creature)
|
||||
grabbed_creature.position = Vector2(0, 0)
|
||||
holding = true
|
||||
|
||||
original_window = data.old_window
|
||||
original_position = data.old_position
|
||||
|
||||
func let_go():
|
||||
if holding and grabbed_creature:
|
||||
if get_window().get_window_id() == 0 and not Persister.get_value("hovered"):
|
||||
var new_creature = CREATURE.instantiate()
|
||||
new_creature.key = grabbed_creature.key
|
||||
new_creature.position = original_position
|
||||
original_window.add_child(new_creature)
|
||||
|
||||
if get_window().get_window_id() == 0:
|
||||
Persister.persist_data("grabbing", false)
|
||||
|
||||
if signal_object and signal_object.mouse_in_window:
|
||||
var new_creature = CREATURE.instantiate()
|
||||
new_creature.key = grabbed_creature.key
|
||||
new_creature.global_position = grabbed_creature.global_position
|
||||
get_window().add_child(new_creature)
|
||||
grabbed_creature.queue_free()
|
||||
grabbed_creature = null
|
||||
|
||||
|
||||
|
||||
holding = false
|
||||
|
||||
func _on_release():
|
||||
holding = false
|
||||
print("RElEASED %d" % [get_window().get_window_id()])
|
||||
let_go()
|
||||
Triggerer.trigger("released")
|
||||
|
||||
var overlapping_areas = mouse_control.get_overlapping_areas()
|
||||
overlapping_areas.sort_custom(func(a, b):
|
||||
return a.z_index > b.z_index
|
||||
|
@ -85,8 +132,14 @@ func _process(delta):
|
|||
#Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
|
||||
mouse_control.position = mouse_control.get_global_mouse_position()
|
||||
|
||||
if held_item:
|
||||
held_item.position = mouse_control.position
|
||||
if timer > 0:
|
||||
timer -= delta
|
||||
if timer <= 0:
|
||||
let_go()
|
||||
|
||||
if hover_timer > 0:
|
||||
hover_timer -= delta
|
||||
timer = 0
|
||||
|
||||
if not Input.is_action_pressed("left_click"):
|
||||
sprite_2d.rotation = move_toward(sprite_2d.rotation, 0, delta)
|
||||
|
|
|
@ -13,15 +13,19 @@ var _connections = {}
|
|||
|
||||
## Trigger an event to be read in by other objects
|
||||
func trigger(key: String, data: Dictionary = {}) -> void:
|
||||
_info("Triggered key ∧%s∧" % [key])
|
||||
#_info("Triggered key ∧%s∧" % [key])
|
||||
|
||||
data.trigger = key
|
||||
|
||||
if _connections.has(key):
|
||||
_connections[key] = _connections[key].filter(func(x): return x.is_valid())
|
||||
|
||||
for callback in _connections[key]:
|
||||
callback.call(data)
|
||||
|
||||
if _connections.has("any"):
|
||||
_connections["any"] = _connections["any"].filter(func(x): return x.is_valid())
|
||||
|
||||
for callback in _connections["any"]:
|
||||
callback.call(data)
|
||||
|
||||
|
|
14
main.gd
14
main.gd
|
@ -7,6 +7,7 @@ const ZONE = preload("res://src/Zone.tscn")
|
|||
const UI_BUTTONS = preload("res://src/UIButtons.tscn")
|
||||
const PAUSE_WINDOW = preload("res://src/PauseWindow.tscn")
|
||||
const BUILD_WINDOW = preload("res://src/BuildWindow.tscn")
|
||||
const CREATURE_WINDOW = preload("res://src/CreatureWindow.tscn")
|
||||
|
||||
var build_object
|
||||
|
||||
|
@ -41,10 +42,6 @@ func _on_spawn_window(data) -> void:
|
|||
get_tree().root.add_child(new_window)
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
Triggerer.trigger("spawn_window", {"key": ["farm", "desert", "lake", "forest"].pick_random()})
|
||||
|
||||
|
||||
func _on_quit(_data) -> void:
|
||||
get_tree().quit()
|
||||
|
||||
|
@ -58,3 +55,12 @@ func _on_build_menu(data):
|
|||
build_object = new_window
|
||||
else:
|
||||
build_object.queue_free()
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
var new_window = CREATURE_WINDOW.instantiate()
|
||||
var new_cursor = CURSOR.instantiate()
|
||||
new_window.add_child(new_cursor)
|
||||
add_child(new_window)
|
||||
|
||||
Triggerer.trigger("spawn_window", {"key": ["forest"].pick_random()})
|
||||
|
|
22
no_cre_build_signals.gd
Normal file
22
no_cre_build_signals.gd
Normal file
|
@ -0,0 +1,22 @@
|
|||
extends Node2D
|
||||
|
||||
var mouse_in_window
|
||||
|
||||
func _ready() -> void:
|
||||
Triggerer.listen("released", _on_released)
|
||||
|
||||
|
||||
func _on_released(_data):
|
||||
if mouse_in_window:
|
||||
get_window().grab_focus()
|
||||
|
||||
|
||||
func _notification(blah):
|
||||
match blah:
|
||||
NOTIFICATION_WM_MOUSE_EXIT:
|
||||
mouse_in_window = false
|
||||
NOTIFICATION_WM_MOUSE_ENTER:
|
||||
mouse_in_window = true
|
||||
|
||||
if not Persister.get_value("grabbing"):
|
||||
get_window().grab_focus()
|
Binary file not shown.
Before Width: | Height: | Size: 667 B After Width: | Height: | Size: 1.3 KiB |
|
@ -23,6 +23,7 @@ Triggerer="*res://components/Triggerer/Triggerer.tscn"
|
|||
Persister="*res://components/Persister/Persister.tscn"
|
||||
Achievements="*res://components/Achievements/Achievements.tscn"
|
||||
Dialogue="*res://components/Dialogue/Dialogue.tscn"
|
||||
Cursor="*res://components/Cursor/Cursor.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://b5gq1bw4bj56b"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://rfc6w6wnl1c2"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://5g4mecc4tb6f" path="res://NoCreMouseSignals.tscn" id="1_33eve"]
|
||||
[ext_resource type="Theme" uid="uid://ck7603ob4gflc" path="res://Fonts/Theme.tres" id="1_ta3q3"]
|
||||
[ext_resource type="Script" path="res://src/build_window.gd" id="1_y8qy0"]
|
||||
[ext_resource type="Script" path="res://small_wave.gd" id="3_0qyx5"]
|
||||
[ext_resource type="PackedScene" uid="uid://dykc1mgg5uopw" path="res://components/Cursor/MouseHandler.tscn" id="4_3uk60"]
|
||||
|
||||
[sub_resource type="RichTextEffect" id="RichTextEffect_lhkb8"]
|
||||
script = ExtResource("3_0qyx5")
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ehvvg"]
|
||||
size = Vector2(52, 73)
|
||||
|
||||
[node name="BuildWindow" type="Window"]
|
||||
canvas_item_default_texture_filter = 0
|
||||
position = Vector2i(0, 36)
|
||||
|
@ -14,6 +19,8 @@ size = Vector2i(900, 500)
|
|||
always_on_top = true
|
||||
content_scale_factor = 4.0
|
||||
|
||||
[node name="MouseSignals" parent="." instance=ExtResource("1_33eve")]
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
|
@ -94,6 +101,12 @@ offset_bottom = 86.24
|
|||
bbcode_enabled = true
|
||||
text = "[center]20G"
|
||||
|
||||
[node name="MouseHandler" parent="Control/HBoxContainer/Upgrade" instance=ExtResource("4_3uk60")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Control/HBoxContainer/Upgrade/MouseHandler"]
|
||||
position = Vector2(16.5, 20)
|
||||
shape = SubResource("RectangleShape2D_ehvvg")
|
||||
|
||||
[node name="Upgrade2" type="ColorRect" parent="Control/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(32, 40)
|
||||
layout_mode = 2
|
||||
|
@ -119,6 +132,12 @@ offset_bottom = 86.24
|
|||
bbcode_enabled = true
|
||||
text = "[center]20G"
|
||||
|
||||
[node name="MouseHandler2" parent="Control/HBoxContainer/Upgrade2" instance=ExtResource("4_3uk60")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Control/HBoxContainer/Upgrade2/MouseHandler2"]
|
||||
position = Vector2(16.5, 20)
|
||||
shape = SubResource("RectangleShape2D_ehvvg")
|
||||
|
||||
[node name="Upgrade3" type="ColorRect" parent="Control/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(32, 40)
|
||||
layout_mode = 2
|
||||
|
@ -143,3 +162,13 @@ offset_right = 56.38
|
|||
offset_bottom = 86.24
|
||||
bbcode_enabled = true
|
||||
text = "[center]20G"
|
||||
|
||||
[node name="MouseHandler3" parent="Control/HBoxContainer/Upgrade3" instance=ExtResource("4_3uk60")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Control/HBoxContainer/Upgrade3/MouseHandler3"]
|
||||
position = Vector2(16.5, 20)
|
||||
shape = SubResource("RectangleShape2D_ehvvg")
|
||||
|
||||
[connection signal="clicked" from="Control/HBoxContainer/Upgrade/MouseHandler" to="Control" method="_on_mouse_handler_clicked"]
|
||||
[connection signal="clicked" from="Control/HBoxContainer/Upgrade2/MouseHandler2" to="Control" method="_on_mouse_handler_2_clicked"]
|
||||
[connection signal="clicked" from="Control/HBoxContainer/Upgrade3/MouseHandler3" to="Control" method="_on_mouse_handler_3_clicked"]
|
||||
|
|
16
src/CreatureWindow.tscn
Normal file
16
src/CreatureWindow.tscn
Normal file
|
@ -0,0 +1,16 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dcaqcebxdrgu7"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/creature_window.gd" id="1_eufhm"]
|
||||
[ext_resource type="PackedScene" uid="uid://dcmh5yv0fjmsb" path="res://MouseSignals.tscn" id="2_3cu4o"]
|
||||
|
||||
[node name="CreatureWindow" type="Window"]
|
||||
canvas_item_default_texture_filter = 0
|
||||
position = Vector2i(0, 36)
|
||||
size = Vector2i(300, 300)
|
||||
always_on_top = true
|
||||
content_scale_factor = 4.0
|
||||
|
||||
[node name="Node2D" type="Node2D" parent="."]
|
||||
script = ExtResource("1_eufhm")
|
||||
|
||||
[node name="MouseSignals" parent="." instance=ExtResource("2_3cu4o")]
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://bqd2ulwe0bsrb"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://dmsrxabynq46i"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/buttons.gd" id="1_rc6dx"]
|
||||
[ext_resource type="PackedScene" uid="uid://br46gg7k10wt2" path="res://src/ui/ActionButton.tscn" id="1_ydcg5"]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c1bqwhwmkp8aw"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://c1bqwhwmkp8aw"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/zone.gd" id="1_gihyf"]
|
||||
[ext_resource type="Script" path="res://src/mouse_signals.gd" id="2_28mh4"]
|
||||
|
||||
[node name="Zone" type="Window"]
|
||||
canvas_item_default_texture_filter = 0
|
||||
|
@ -12,3 +13,6 @@ content_scale_factor = 4.0
|
|||
script = ExtResource("1_gihyf")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
|
||||
[node name="MouseSignals" type="Node2D" parent="." groups=["mouse_signals"]]
|
||||
script = ExtResource("2_28mh4")
|
||||
|
|
|
@ -2,7 +2,6 @@ extends Control
|
|||
|
||||
var upgrade_pool = Data.data.upgrades.keys()
|
||||
var zone_pool = Data.data.zones.keys()
|
||||
var current_zone
|
||||
|
||||
@onready var cards = [
|
||||
{
|
||||
|
@ -19,9 +18,16 @@ var current_zone
|
|||
}
|
||||
]
|
||||
|
||||
var chosen_cards = [
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
|
||||
func _ready() -> void:
|
||||
upgrade_pool.shuffle()
|
||||
zone_pool.shuffle()
|
||||
Persister.change_value("gold", 100) # TEMP
|
||||
|
||||
var screen_size = DisplayServer.screen_get_size(0)
|
||||
|
||||
|
@ -40,13 +46,43 @@ func _update_card(index):
|
|||
var cost
|
||||
|
||||
if index == 2:
|
||||
if zone_pool.size() == 0:
|
||||
zone_pool = Data.data.zones.keys()
|
||||
zone_pool.shuffle()
|
||||
choice = zone_pool.pop_back()
|
||||
card_data = Data.data.zones[choice]
|
||||
cost = 20
|
||||
else:
|
||||
if upgrade_pool.size() == 0:
|
||||
upgrade_pool = Data.data.upgrades.keys()
|
||||
upgrade_pool.shuffle()
|
||||
choice = upgrade_pool.pop_back()
|
||||
card_data = Data.data.upgrades[choice]
|
||||
cost = card_data.cost
|
||||
|
||||
cards[index].title.text = "[center]%s" % [card_data.name]
|
||||
cards[index].cost.text = "[center]%d G" % [cost]
|
||||
card_data.key = choice
|
||||
chosen_cards[index] = card_data
|
||||
|
||||
|
||||
func _on_mouse_handler_clicked() -> void:
|
||||
_buy_upgrade(0)
|
||||
|
||||
|
||||
func _on_mouse_handler_2_clicked() -> void:
|
||||
_buy_upgrade(1)
|
||||
|
||||
|
||||
func _on_mouse_handler_3_clicked() -> void:
|
||||
_buy_upgrade(2)
|
||||
|
||||
|
||||
func _buy_upgrade(index):
|
||||
var card_data = chosen_cards[index]
|
||||
if Persister.get_value("gold", PersisterEnums.Scope.UNKNOWN, 0) >= (card_data.cost if card_data.has("cost") else 20):
|
||||
Persister.change_value("gold", -(card_data.cost if card_data.has("cost") else 20))
|
||||
_update_card(index)
|
||||
|
||||
if index == 2:
|
||||
Triggerer.trigger("spawn_window", {"key": card_data.key})
|
||||
|
|
|
@ -7,17 +7,12 @@ var key
|
|||
|
||||
@onready var sprite_2d: Sprite2D = $Sprite2D
|
||||
|
||||
var grabbed = false
|
||||
|
||||
func _ready() -> void:
|
||||
sprite_2d.texture = image
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_released("left_click"):
|
||||
grabbed = false
|
||||
|
||||
|
||||
func _on_mouse_handler_clicked() -> void:
|
||||
Triggerer.trigger("grab_creature", {"creature": self})
|
||||
grabbed = true
|
||||
Triggerer.trigger("grab_creature", {"creature": key, "old_window": get_window(), "old_position": position})
|
||||
Persister.persist_data("grabbing", true)
|
||||
queue_free()
|
||||
|
|
43
src/creature_window.gd
Normal file
43
src/creature_window.gd
Normal file
|
@ -0,0 +1,43 @@
|
|||
extends Node2D
|
||||
|
||||
var minutes_left = 6 * 24
|
||||
var creatures_spawned = 0
|
||||
var spawn_times = []
|
||||
|
||||
const CREATURE = preload("res://src/Creature.tscn")
|
||||
|
||||
var mouse_in_window = false
|
||||
|
||||
func _ready() -> void:
|
||||
Persister.change_value("creature_amount", 4)
|
||||
Triggerer.listen("minutes", _on_minutes)
|
||||
Triggerer.listen("day", _on_day)
|
||||
_generate_spawn_times()
|
||||
|
||||
var screen_size = DisplayServer.screen_get_size(0)
|
||||
|
||||
get_window().position = Vector2i(50, screen_size.y - 300 - 50) + DisplayServer.screen_get_position(0)
|
||||
|
||||
|
||||
|
||||
func _on_minutes(_data):
|
||||
minutes_left -= 1
|
||||
|
||||
if spawn_times.has(minutes_left):
|
||||
var new_creature = CREATURE.instantiate()
|
||||
new_creature.position = Vector2(50, 50)
|
||||
new_creature.key = Data.data.creatures.keys().pick_random()
|
||||
add_child(new_creature)
|
||||
|
||||
|
||||
func _on_day(_data):
|
||||
minutes_left = 6 * 24
|
||||
creatures_spawned = 0
|
||||
_generate_spawn_times()
|
||||
|
||||
|
||||
func _generate_spawn_times():
|
||||
spawn_times = []
|
||||
|
||||
for i in range(0, 4):
|
||||
spawn_times.push_back(randi_range(2, 6 * 24 - 2))
|
37
src/mouse_signals.gd
Normal file
37
src/mouse_signals.gd
Normal file
|
@ -0,0 +1,37 @@
|
|||
extends Node2D
|
||||
|
||||
var mouse_in_window
|
||||
#
|
||||
#
|
||||
#func _on_creature_window_mouse_entered() -> void:
|
||||
#print("ENTERED")
|
||||
#mouse_in_window = true
|
||||
#
|
||||
#
|
||||
#func _on_creature_window_mouse_exited() -> void:
|
||||
#print("EXITED")
|
||||
#mouse_in_window = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Triggerer.listen("released", _on_released)
|
||||
|
||||
|
||||
func _on_released(_data):
|
||||
if mouse_in_window:
|
||||
get_window().grab_focus()
|
||||
|
||||
|
||||
func _notification(blah):
|
||||
match blah:
|
||||
NOTIFICATION_WM_MOUSE_EXIT:
|
||||
#print('Mouse left window')
|
||||
mouse_in_window = false
|
||||
Persister.change_value("hovered", -1)
|
||||
NOTIFICATION_WM_MOUSE_ENTER:
|
||||
#print('Mouse entered window')
|
||||
mouse_in_window = true
|
||||
Persister.change_value("hovered", 1)
|
||||
|
||||
if not Persister.get_value("grabbing"):
|
||||
get_window().grab_focus()
|
|
@ -17,11 +17,6 @@ func _ready() -> void:
|
|||
title = data.name
|
||||
sprite_2d.texture = image
|
||||
sprite_2d.position = Vector2(int(data.size[0]) * 12 / 2, int(data.size[1]) * 12 / 2)
|
||||
|
||||
var new_creature = CREATURE.instantiate()
|
||||
new_creature.position = Vector2(50, 50)
|
||||
new_creature.key = "1x1-1"
|
||||
add_child(new_creature)
|
||||
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue