feat: added town name setting
This commit is contained in:
parent
a8b292aa03
commit
fc177656c5
8 changed files with 134 additions and 24 deletions
|
@ -1,7 +1,6 @@
|
|||
extends Window
|
||||
class_name DragonEditor
|
||||
|
||||
|
||||
@onready var hat: AnimatedSprite2D = $CanvasLayer/Dragon/Hat
|
||||
@onready var shirt: AnimatedSprite2D = $CanvasLayer/Dragon/Shirt
|
||||
@onready var decor: AnimatedSprite2D = $CanvasLayer/Dragon/Decor
|
||||
|
@ -12,24 +11,26 @@ class_name DragonEditor
|
|||
@export var decor_outfits: DragonOutfit
|
||||
@export var dragon_colors: DragonOutfit
|
||||
|
||||
var _save_load: SaveLoad = SaveLoad.new()
|
||||
|
||||
@onready var dragon_name: LineEdit = $CanvasLayer/NameLabel/LineEdit
|
||||
|
||||
@onready var dragger: DraggableWindow = $CanvasLayer/Dragger
|
||||
|
||||
signal on_create_dragon(properties: DragonProperties)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_save_load.load()
|
||||
|
||||
hat.visible = false
|
||||
shirt.visible = false
|
||||
decor.visible = false
|
||||
dragon.play('idle')
|
||||
|
||||
hat_outfits.index = 0
|
||||
shirt_outfits.index = 0
|
||||
decor_outfits.index = 0
|
||||
dragon_colors.index = 0
|
||||
|
||||
|
||||
hat_outfits.reset()
|
||||
shirt_outfits.reset()
|
||||
decor_outfits.reset()
|
||||
dragon_colors.reset()
|
||||
|
||||
dragger.on_drag.connect(_on_drag)
|
||||
|
||||
|
||||
|
@ -64,7 +65,18 @@ func _pick_next_animation(sprite: AnimatedSprite2D, outfits: DragonOutfit):
|
|||
return
|
||||
sprite.visible = true
|
||||
sprite.set_sprite_frames(animation)
|
||||
sprite.play('idle')
|
||||
_restart_animations()
|
||||
|
||||
|
||||
func _restart_animations():
|
||||
hat.set_frame(0)
|
||||
hat.play('idle')
|
||||
shirt.set_frame(0)
|
||||
shirt.play('idle')
|
||||
decor.set_frame(0)
|
||||
decor.play('idle')
|
||||
dragon.set_frame(0)
|
||||
dragon.play('idle')
|
||||
|
||||
|
||||
func _pick_previous_animation(sprite: AnimatedSprite2D, outfits: DragonOutfit):
|
||||
|
@ -74,14 +86,14 @@ func _pick_previous_animation(sprite: AnimatedSprite2D, outfits: DragonOutfit):
|
|||
return
|
||||
sprite.visible = true
|
||||
sprite.set_sprite_frames(animation)
|
||||
sprite.play('idle')
|
||||
_restart_animations()
|
||||
|
||||
|
||||
func _on_create_pressed() -> void:
|
||||
if dragon_name.text.is_empty():
|
||||
return
|
||||
|
||||
var properties = DragonProperties.new(dragon_name.text, "tower", hat_outfits.index, shirt_outfits.index, decor_outfits.index, dragon_colors.index)
|
||||
|
||||
var properties = DragonProperties.new(dragon_name.text, _save_load.get_tower_name(), dragon_colors.get_current_index(), hat_outfits.get_current_index(), shirt_outfits.get_current_index(), decor_outfits.get_current_index())
|
||||
on_create_dragon.emit(properties)
|
||||
queue_free()
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ class_name GameManager
|
|||
|
||||
@export var dragon_template: PackedScene
|
||||
@export var dragon_ingame: PackedScene
|
||||
@export var name_setter: PackedScene
|
||||
@export var dragon_spots: Array[Node2D]
|
||||
|
||||
@export var clock: PackedScene
|
||||
|
@ -32,15 +33,31 @@ func _ready():
|
|||
await get_tree().process_frame
|
||||
move_window_to_bottom_right()
|
||||
_load_game()
|
||||
if _save_load.get_tower_name() == "":
|
||||
_show_name_setter_screen()
|
||||
_queue_dragon_instantiation()
|
||||
|
||||
var clock_window: Window = clock.instantiate()
|
||||
add_child(clock_window)
|
||||
|
||||
|
||||
func _show_name_setter_screen():
|
||||
var setter: NameSetter = name_setter.instantiate()
|
||||
setter.set_save_load(_save_load)
|
||||
add_child(setter)
|
||||
|
||||
var display_index: int = DisplayServer.window_get_current_screen()
|
||||
var work_area_position: Vector2i = DisplayServer.screen_get_usable_rect(display_index).position
|
||||
var work_area_size: Vector2i = DisplayServer.screen_get_usable_rect(display_index).size
|
||||
|
||||
var new_position: Vector2i = work_area_position + Vector2i(work_area_size.x / 2.0 - setter.size.x / 2.0, work_area_size.y / 2.0 - setter.size.y / 2.0)
|
||||
setter.position = new_position
|
||||
|
||||
|
||||
func _queue_dragon_instantiation():
|
||||
await get_tree().create_timer(rng.randf_range(min_dragon_instantiation_time, max_dragon_instantiation_time)).timeout
|
||||
_instantiate_random_dragon()
|
||||
if _save_load.get_tower_name() != "":
|
||||
_instantiate_random_dragon()
|
||||
_queue_dragon_instantiation()
|
||||
|
||||
|
||||
|
@ -50,7 +67,7 @@ func _instantiate_random_dragon():
|
|||
return
|
||||
|
||||
for i in range(5):
|
||||
dragon_sharing.receive("potato")
|
||||
dragon_sharing.receive(_save_load.get_tower_name())
|
||||
var dragon: DragonProperties = await dragon_sharing.on_dragon_received
|
||||
if dragon == null:
|
||||
return
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=13 format=3 uid="uid://ctytpqaed0yqx"]
|
||||
[gd_scene load_steps=14 format=3 uid="uid://ctytpqaed0yqx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scenes/main.gd" id="1_sugp2"]
|
||||
[ext_resource type="PackedScene" uid="uid://c7nfcgjxqeg7l" path="res://scenes/window/dragon_popup.tscn" id="2_jyhfs"]
|
||||
[ext_resource type="PackedScene" uid="uid://bj5ptaniasaaj" path="res://scenes/clock/clock.tscn" id="4_a8y0u"]
|
||||
[ext_resource type="PackedScene" uid="uid://miutbdsgccd1" path="res://scenes/dragons/dragon.tscn" id="4_jyhfs"]
|
||||
[ext_resource type="Script" uid="uid://cj4l3a6a8ro0r" path="res://scenes/create_button.gd" id="4_tbgi4"]
|
||||
[ext_resource type="PackedScene" uid="uid://cdlipr8l1k38a" path="res://scenes/name_setter/name_setter.tscn" id="4_trceg"]
|
||||
[ext_resource type="PackedScene" uid="uid://fut42ruut302" path="res://scenes/dragon_editor/dragon_editor.tscn" id="5_tefeu"]
|
||||
[ext_resource type="Script" uid="uid://oc6mw86npbii" path="res://scenes/list_button.gd" id="9_choun"]
|
||||
[ext_resource type="PackedScene" uid="uid://tubxrqxjic6r" path="res://scenes/dragon_list/dragon_list.tscn" id="10_ya4ey"]
|
||||
|
@ -17,6 +18,7 @@
|
|||
script = ExtResource("1_sugp2")
|
||||
dragon_template = ExtResource("2_jyhfs")
|
||||
dragon_ingame = ExtResource("4_jyhfs")
|
||||
name_setter = ExtResource("4_trceg")
|
||||
dragon_spots = [NodePath("DragonSpot1"), NodePath("DragonSpot2"), NodePath("DragonSpot3")]
|
||||
clock = ExtResource("4_a8y0u")
|
||||
min_dragon_instantiation_time = 2.0
|
||||
|
|
20
scenes/name_setter/name_setter.gd
Normal file
20
scenes/name_setter/name_setter.gd
Normal file
|
@ -0,0 +1,20 @@
|
|||
extends Window
|
||||
class_name NameSetter
|
||||
|
||||
|
||||
var save_load: SaveLoad
|
||||
@onready var name_edit: LineEdit = $Name
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func set_save_load(save_load: SaveLoad) -> void:
|
||||
self.save_load = save_load
|
||||
|
||||
|
||||
func _on_submit_pressed() -> void:
|
||||
if not name_edit.text.is_empty():
|
||||
save_load.set_tower_name(name_edit.text)
|
||||
queue_free()
|
1
scenes/name_setter/name_setter.gd.uid
Normal file
1
scenes/name_setter/name_setter.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://drulv5ptupx2w
|
38
scenes/name_setter/name_setter.tscn
Normal file
38
scenes/name_setter/name_setter.tscn
Normal file
|
@ -0,0 +1,38 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cdlipr8l1k38a"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://drulv5ptupx2w" path="res://scenes/name_setter/name_setter.gd" id="1_f3gk5"]
|
||||
|
||||
[node name="NameSetter" type="Window"]
|
||||
position = Vector2i(0, 36)
|
||||
size = Vector2i(500, 250)
|
||||
unresizable = true
|
||||
always_on_top = true
|
||||
script = ExtResource("1_f3gk5")
|
||||
|
||||
[node name="Instructions" type="Label" parent="."]
|
||||
offset_right = 500.0
|
||||
offset_bottom = 146.0
|
||||
text = "En aquesta torreta, present a la cantonada del teu escriptori, hi viuran uns dracs que t’acompanyaran en el teu dia a dia. Fins i tot et vindran a visitar dracs d'altres torretes!
|
||||
|
||||
Per començar, posa un nom a la teva torreta.
|
||||
És el primer pas per fer-la teva."
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 2
|
||||
|
||||
[node name="Name" type="LineEdit" parent="."]
|
||||
offset_left = 84.0
|
||||
offset_top = 163.0
|
||||
offset_right = 423.0
|
||||
offset_bottom = 214.0
|
||||
placeholder_text = "Nom"
|
||||
alignment = 1
|
||||
max_length = 16
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
offset_left = 220.0
|
||||
offset_top = 218.0
|
||||
offset_right = 287.0
|
||||
offset_bottom = 249.0
|
||||
text = "Assigna"
|
||||
|
||||
[connection signal="pressed" from="Button" to="." method="_on_submit_pressed"]
|
|
@ -4,15 +4,19 @@ class_name DragonOutfit
|
|||
|
||||
@export var allow_null: bool
|
||||
@export var outfits: Array[SpriteFrames]
|
||||
var index: int = 0
|
||||
var _index: int = 0
|
||||
|
||||
|
||||
func _init(outfits: Array[SpriteFrames] = []):
|
||||
self.outfits = outfits
|
||||
|
||||
|
||||
func reset() -> void:
|
||||
_index = 0
|
||||
|
||||
|
||||
func pick_next() -> SpriteFrames:
|
||||
index += 1
|
||||
_index += 1
|
||||
if allow_null:
|
||||
return _pick_nullable()
|
||||
else:
|
||||
|
@ -20,7 +24,7 @@ func pick_next() -> SpriteFrames:
|
|||
|
||||
|
||||
func pick_previous() -> SpriteFrames:
|
||||
index -= 1
|
||||
_index -= 1
|
||||
if allow_null:
|
||||
return _pick_nullable()
|
||||
else:
|
||||
|
@ -28,16 +32,16 @@ func pick_previous() -> SpriteFrames:
|
|||
|
||||
|
||||
func _pick_nullable() -> SpriteFrames:
|
||||
index %= (len(outfits) + 1)
|
||||
if index == 0:
|
||||
_index %= (len(outfits) + 1)
|
||||
if _index == 0:
|
||||
return null
|
||||
|
||||
return outfits[index - 1]
|
||||
return outfits[_index - 1]
|
||||
|
||||
|
||||
func _pick_non_nullable() -> SpriteFrames:
|
||||
index %= len(outfits)
|
||||
return outfits[index]
|
||||
_index %= len(outfits)
|
||||
return outfits[_index]
|
||||
|
||||
|
||||
func get_texture(index: int) -> SpriteFrames:
|
||||
|
@ -45,3 +49,10 @@ func get_texture(index: int) -> SpriteFrames:
|
|||
return null
|
||||
|
||||
return outfits[index]
|
||||
|
||||
|
||||
func get_current_index() -> int:
|
||||
if allow_null:
|
||||
return _index - 1
|
||||
else:
|
||||
return _index
|
||||
|
|
|
@ -25,6 +25,7 @@ func load() -> void:
|
|||
contents_to_save.get_or_add('coins', 0)
|
||||
contents_to_save.get_or_add('dragons', [])
|
||||
contents_to_save.get_or_add('items', [])
|
||||
contents_to_save.get_or_add('tower_name', "")
|
||||
|
||||
|
||||
func get_coins() -> int:
|
||||
|
@ -35,6 +36,14 @@ func set_coins(coins: int) -> void:
|
|||
contents_to_save['coins'] = coins
|
||||
|
||||
|
||||
func get_tower_name() -> String:
|
||||
return contents_to_save['tower_name']
|
||||
|
||||
|
||||
func set_tower_name(name: String) -> void:
|
||||
contents_to_save['tower_name'] = name
|
||||
|
||||
|
||||
func clear_dragons() -> void:
|
||||
contents_to_save['dragons'] = []
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue