plant pick menu
This commit is contained in:
parent
73a2fe42ad
commit
32453f2e9d
18 changed files with 121 additions and 39 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
extends Node
|
||||
|
||||
@warning_ignore_start("unused_signal")
|
||||
## Event bus for levels in Liberation Of Neighborville
|
||||
|
||||
class_name LevelSignals
|
||||
|
||||
#region Field
|
||||
|
||||
|
|
|
|||
|
|
@ -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
14
scripts/gui/hotbar.gd
Normal 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))
|
||||
1
scripts/gui/hotbar.gd.uid
Normal file
1
scripts/gui/hotbar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cbrhnb4tp4pem
|
||||
15
scripts/gui/plant_pick/seedpacket_generator.gd
Normal file
15
scripts/gui/plant_pick/seedpacket_generator.gd
Normal 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)
|
||||
|
||||
1
scripts/gui/plant_pick/seedpacket_generator.gd.uid
Normal file
1
scripts/gui/plant_pick/seedpacket_generator.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://crlumefuo1biu
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue