plant pick menu

This commit is contained in:
Rendo 2025-08-03 02:09:11 +05:00
commit 32453f2e9d
18 changed files with 121 additions and 39 deletions

View file

@ -17,6 +17,7 @@ warnings/check_angle_interpolation_type_conflicting=false
config/name="Liberation of the Neighbourville"
config/version="0.3.0"
run/main_scene="uid://boxt0hfowqe66"
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.png"
config/windows_native_icon="res://icon.ico"

View file

@ -1,10 +1,13 @@
[gd_resource type="Resource" script_class="SeedpacketResource" load_steps=2 format=3 uid="uid://d1nwlatkrtkpe"]
[gd_resource type="Resource" script_class="SeedpacketResource" load_steps=3 format=3 uid="uid://d1nwlatkrtkpe"]
[ext_resource type="Script" uid="uid://dtjdfji87kybn" path="res://scripts/resources/entity_resource.gd" id="1_giqbo"]
[ext_resource type="Texture2D" uid="uid://d4btl7vqi4v0q" path="res://assets/sprites/plants/aloe.tres" id="1_qou1a"]
[resource]
script = ExtResource("1_giqbo")
cost = 0.0
recharge_time = 3.0
preview = ExtResource("1_qou1a")
cost = 75.0
recharge_time = 5.0
initial_recharge_percent = 1.0
order = 0
metadata/_custom_type_script = "uid://dtjdfji87kybn"

View file

@ -13,4 +13,5 @@ preview = SubResource("AtlasTexture_fl6wr")
cost = 75.0
recharge_time = 5.0
initial_recharge_percent = 1.0
order = 0
metadata/_custom_type_script = "uid://dtjdfji87kybn"

View file

@ -1,14 +0,0 @@
[gd_scene format=3 uid="uid://b1mbgkjvq5j76"]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 0
offset_right = 189.0
offset_bottom = 128.0

View file

@ -0,0 +1,34 @@
[gd_scene load_steps=4 format=3 uid="uid://boxt0hfowqe66"]
[ext_resource type="Script" uid="uid://crlumefuo1biu" path="res://scripts/gui/plant_pick/seedpacket_generator.gd" id="1_celhi"]
[ext_resource type="Script" uid="uid://co3yto3q7mnm7" path="res://scripts/level/level_data.gd" id="2_pdbkq"]
[ext_resource type="Script" uid="uid://cbrhnb4tp4pem" path="res://scripts/gui/hotbar.gd" id="3_qyndx"]
[node name="PlantsPickTest" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="GridContainer" type="GridContainer" parent="."]
layout_mode = 0
anchor_left = 0.27
anchor_top = 0.48
anchor_right = 0.74
anchor_bottom = 0.94
columns = 3
script = ExtResource("1_celhi")
metadata/_edit_use_anchors_ = true
[node name="LevelData" type="Node" parent="."]
script = ExtResource("2_pdbkq")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 0
offset_left = 69.0
offset_top = 12.0
offset_right = 479.0
offset_bottom = 75.0
script = ExtResource("3_qyndx")

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=11 format=3 uid="uid://bi4c34ii72y46"]
[gd_scene load_steps=12 format=3 uid="uid://bi4c34ii72y46"]
[ext_resource type="Texture2D" uid="uid://dxyf557m4mq1p" path="res://assets/sprites/gui/EmptyPlantCard.png" id="1_4rm55"]
[ext_resource type="Script" uid="uid://cepaa3acqx70d" path="res://scripts/gui/seedpacket/seedpacket.gd" id="1_c8vxi"]
[ext_resource type="Texture2D" uid="uid://cabpf23ndlvx0" path="res://assets/sprites/gui/Selection.tres" id="3_fon4l"]
[ext_resource type="Script" uid="uid://bppehhpn0u7ep" path="res://scripts/gui/seedpacket/seedpacket_cost_label.gd" id="3_tntkr"]
[ext_resource type="Script" uid="uid://bx7k7g0ebkwef" path="res://scripts/gui/seedpacket/seedpacket_progressbar.gd" id="4_gr8e8"]
[ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="5_2cmc5"]
@ -36,6 +37,7 @@ script = ExtResource("1_c8vxi")
clip_children = 2
layout_mode = 2
texture_normal = ExtResource("1_4rm55")
texture_focused = ExtResource("3_fon4l")
stretch_mode = 0
[node name="Cost" type="Label" parent="TextureButton"]
@ -65,6 +67,7 @@ offset_left = -27.0
offset_top = -26.0
offset_right = 24.984
offset_bottom = -2.984
mouse_filter = 2
[node name="Preview" type="TextureRect" parent="TextureButton/PreviewContainer"]
layout_mode = 1
@ -79,6 +82,7 @@ offset_right = -0.0800018
offset_bottom = -0.0259933
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
expand_mode = 1
stretch_mode = 5
@ -89,6 +93,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme_override_styles/background = SubResource("StyleBoxEmpty_tntkr")
theme_override_styles/fill = SubResource("StyleBoxFlat_gr8e8")
max_value = 1.0
@ -96,7 +101,7 @@ fill_mode = 3
show_percentage = false
script = ExtResource("4_gr8e8")
[node name="AvaiabilityRect" type="ColorRect" parent="TextureButton"]
[node name="Availability" type="ColorRect" parent="TextureButton"]
visible = false
layout_mode = 1
anchors_preset = 15
@ -104,6 +109,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
color = Color(0, 0, 0, 0.247059)
[node name="Forbidden" type="TextureRect" parent="TextureButton"]

View file

@ -2,7 +2,7 @@ extends Node
class_name GameRegistry
static func load_resources(directory : String, recursion : bool) -> Array[Resource]:
static func load_resources(directory : String, recursion : bool = true) -> Array[Resource]:
var result : Array[Resource] = []
var dir = DirAccess.open(directory)
if dir == null:

View file

@ -1,8 +1,8 @@
extends Node
@warning_ignore_start("unused_signal")
## Event bus for levels in Liberation Of Neighborville
class_name LevelSignals
#region Field

View file

@ -33,6 +33,8 @@ func deal_damage(amount : float, source : Entity):
delta_context.delta = -amount
hp_changed.emit(delta_context)
damaged.emit()
hp -= amount
if hp <= 0:
hp = 0

14
scripts/gui/hotbar.gd Normal file
View file

@ -0,0 +1,14 @@
extends Node
func _ready() -> void:
LevelEventBus.hotbar_packets_update.connect(on_hotbar_updated)
func on_hotbar_updated(hotbar : Array[SeedpacketResource]):
for child in get_children():
child.queue_free()
for seedpacket in hotbar:
var packet = preload("res://scenes/gui/seedpacket.tscn").instantiate()
packet.held_resource = seedpacket
add_child(packet)
packet.set_handler(HotbarHandler.new(packet))

View file

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

View file

@ -0,0 +1,15 @@
extends Node
const SEEDPACKET_SCENE := preload("res://scenes/gui/seedpacket.tscn")
func _ready() -> void:
var plants = GameRegistry.load_resources("res://resources/")
for plant in plants:
var seedpacket = SEEDPACKET_SCENE.instantiate()
seedpacket.held_resource = plant
add_child(seedpacket)
var handler = PickableHandler.new(seedpacket)
seedpacket.set_handler(handler)

View file

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

View file

@ -6,11 +6,11 @@ class_name HotbarHandler
## Is current state valid for use?
var valid_state : bool = false
var valid_state : bool = true
var enough_sun : bool = true
func _init(seedpacket : Seedpacket) -> void:
super._init(seedpacket)
func _init(packet : Seedpacket) -> void:
super._init(packet)
LevelEventBus.state_changed.connect(on_level_state_changed)
LevelEventBus.sun_count_updated.connect(on_sun_count_updated)
@ -29,4 +29,4 @@ func on_level_state_changed(state : LevelData.LevelStates):
func on_sun_count_updated(to : float):
enough_sun = to >= seedpacket.held_resource.cost
seedpacket.update_contents()

View file

@ -6,8 +6,8 @@ var chosen : bool
var locked : bool = false
var forbidden : bool = false
func _init(seedpacket : Seedpacket) -> void:
super._init(seedpacket)
func _init(packet : Seedpacket) -> void:
super._init(packet)
LevelEventBus.hotbar_packets_update.connect(on_hotbar_changed)
func exit() -> void:
@ -19,3 +19,7 @@ func is_avaiable() -> bool:
func on_hotbar_changed(to : Array[SeedpacketResource]):
chosen = to.has(seedpacket.held_resource)
seedpacket.update_contents()
func on_updated_contents():
seedpacket.forbidden.visible = forbidden
seedpacket.locked.visible = locked

View file

@ -4,17 +4,18 @@ extends AspectRatioContainer
class_name Seedpacket
@onready var button := $TextureButton
@onready var preview :=$TextureButton/PreviewContainer/Preview
@onready var cost := $TextureButton/Cost
@onready var avaibility := $TextureButton/AvaiabilityRect
@onready var recharge_timer := $RechargeTimer
@onready var forbidden_rect := $TextureButton/Forbidden
@onready var locked_rect := $TextureButton/Locked
@onready var button : TextureButton = $TextureButton
@onready var cost_label : Label = $TextureButton/Cost
@onready var preview_texture : TextureRect = $TextureButton/PreviewContainer/Preview
@onready var availability : ColorRect = $TextureButton/Availability
@onready var forbidden : TextureRect = $TextureButton/Forbidden
@onready var locked : TextureRect = $TextureButton/Locked
@onready var recharge_timer : Timer = $RechargeTimer
var held_resource : SeedpacketResource
var handler : SeedpacketHandler
func _process(_delta: float) -> void:
button.disabled = recharge_timer.time_left > 0 or handler.is_avaiable() == false
@ -31,13 +32,14 @@ func set_handler(to : SeedpacketHandler):
update_contents()
func update_contents():
cost.text = str(held_resource.cost)
preview.texture = held_resource.preview
avaibility.visible = handler.is_avaiable() == false
cost_label.text = str(int(held_resource.cost))
preview_texture.texture = held_resource.preview
availability.visible = handler.is_avaiable() == false
handler.on_updated_contents()
func on_packet_placed(packet : SeedpacketResource):
if held_resource != packet: return
recharge_timer.start()
disconnect_placement()
func disconnect_placement():

View file

@ -4,5 +4,5 @@ extends Label
const BASE_FONT_SIZE := 10
const BASE_HEIGHT := 11
func _process(delta: float) -> void:
func _process(_delta: float) -> void:
label_settings.font_size = int(BASE_FONT_SIZE * (size.y/BASE_HEIGHT))

View file

@ -5,6 +5,18 @@ class_name LevelData
static var state : LevelStates = LevelStates.NotInGame
static var sun_count : float
var hotbar_seedpackets : Array[SeedpacketResource]
func _ready() -> void:
LevelEventBus.packet_selected.connect(on_seedpacket_clicked)
func on_seedpacket_clicked(seedpacket : SeedpacketResource):
if hotbar_seedpackets.has(seedpacket):
hotbar_seedpackets.erase(seedpacket)
else:
hotbar_seedpackets.append(seedpacket)
LevelEventBus.hotbar_packets_update.emit(hotbar_seedpackets)
## Possible states of level
enum LevelStates {
## The game is during plant pick stage