seedpacket base
This commit is contained in:
parent
e1931f27e1
commit
2a7c402cd0
16 changed files with 345 additions and 24 deletions
61
scripts/gui/seedpacket/seedpacket.gd
Normal file
61
scripts/gui/seedpacket/seedpacket.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
extends AspectRatioContainer
|
||||
|
||||
@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
|
||||
|
||||
var held_resource : SeedpacketResource
|
||||
var forbidden : bool = false
|
||||
var locked : bool = false
|
||||
var hotbar : bool = false
|
||||
var disabled : bool = false
|
||||
|
||||
#region Godot methods
|
||||
func _ready() -> void:
|
||||
LevelEventBus.entity_placed.connect(on_entity_placed)
|
||||
LevelEventBus.sun_count_updated.connect(on_sun_count_updated)
|
||||
LevelEventBus.state_changed.connect(on_level_state_changed)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
button.disabled = recharge_timer.time_left > 0 or forbidden or locked or disabled
|
||||
update_contents()
|
||||
#endregion
|
||||
|
||||
#region Signal methods
|
||||
func on_pressed():
|
||||
LevelEventBus.packet_selected.emit(held_resource)
|
||||
if LevelData.state == LevelData.LevelStates.Game:
|
||||
LevelEventBus.packet_selected_during_game.emit(held_resource)
|
||||
|
||||
func on_entity_placed(entity : SeedpacketResource):
|
||||
if entity == held_resource:
|
||||
recharge_timer.start()
|
||||
#endregion
|
||||
|
||||
func set_resource(to : SeedpacketResource):
|
||||
held_resource = to
|
||||
update_contents()
|
||||
|
||||
func update_contents():
|
||||
cost.text = str(held_resource.cost)
|
||||
preview.texture = held_resource.preview
|
||||
avaibility.visible = forbidden or locked or disabled
|
||||
locked_rect.visible = locked
|
||||
forbidden_rect.visible = forbidden
|
||||
|
||||
func on_sun_count_updated(to : float):
|
||||
if hotbar:
|
||||
disabled = held_resource.cost < to
|
||||
|
||||
func on_level_state_changed(state : LevelData.LevelStates):
|
||||
match state:
|
||||
LevelData.LevelStates.Game:
|
||||
disabled = held_resource.cost < LevelData.sun_count
|
||||
LevelData.LevelStates.PlantPick:
|
||||
disabled = false
|
||||
_:
|
||||
disabled = true
|
||||
1
scripts/gui/seedpacket/seedpacket.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cepaa3acqx70d
|
||||
8
scripts/gui/seedpacket/seedpacket_cost_label.gd
Normal file
8
scripts/gui/seedpacket/seedpacket_cost_label.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
@tool
|
||||
extends Label
|
||||
|
||||
const BASE_FONT_SIZE := 10
|
||||
const BASE_HEIGHT := 11
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
label_settings.font_size = int(BASE_FONT_SIZE * (size.y/BASE_HEIGHT))
|
||||
1
scripts/gui/seedpacket/seedpacket_cost_label.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket_cost_label.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bppehhpn0u7ep
|
||||
6
scripts/gui/seedpacket/seedpacket_progressbar.gd
Normal file
6
scripts/gui/seedpacket/seedpacket_progressbar.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends ProgressBar
|
||||
|
||||
@onready var timer := $"../../RechargeTimer"
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
value = timer.time_left/timer.wait_time
|
||||
1
scripts/gui/seedpacket/seedpacket_progressbar.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket_progressbar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bx7k7g0ebkwef
|
||||
Loading…
Add table
Add a link
Reference in a new issue