Use worker for research
This commit is contained in:
@@ -5,6 +5,7 @@ const RESEARCH_ROW_SCENE: PackedScene = preload("res://core/research/research_ro
|
||||
|
||||
@onready var _title_label: Label = $ScrollContainer/VBoxContainer/TitleLabel
|
||||
@onready var _research_rows_container: VBoxContainer = $ScrollContainer/VBoxContainer/ResearchRows
|
||||
@onready var _buy_worker_button: Button = $ScrollContainer/VBoxContainer/HBoxContainer/BuyWorkerButton
|
||||
|
||||
var _game_state: LevelGameState
|
||||
var _research_rows: Dictionary = {}
|
||||
@@ -18,9 +19,12 @@ func _ready() -> void:
|
||||
|
||||
_game_state.research_xp_changed.connect(_on_research_xp_changed)
|
||||
_game_state.research_level_up.connect(_on_research_level_up)
|
||||
_game_state.currency_changed.connect(_on_currency_changed)
|
||||
_game_state.research_workers_changed.connect(_on_research_workers_changed)
|
||||
|
||||
_build_research_rows()
|
||||
_refresh_all()
|
||||
_refresh_worker_button()
|
||||
|
||||
func _build_research_rows() -> void:
|
||||
for child in _research_rows_container.get_children():
|
||||
@@ -109,3 +113,43 @@ func activate_research(research_id: StringName) -> void:
|
||||
if _research_rows.has(research_id):
|
||||
var row: ResearchRow = _research_rows[research_id]
|
||||
row.set_active(true)
|
||||
|
||||
func _on_currency_changed(currency_id: StringName, _new_amount: BigNumber) -> void:
|
||||
if currency_id == &"worker":
|
||||
_refresh_worker_button()
|
||||
|
||||
func _on_research_workers_changed(_new_count: int) -> void:
|
||||
_refresh_worker_button()
|
||||
|
||||
func _can_buy_worker() -> bool:
|
||||
if _game_state == null:
|
||||
return false
|
||||
|
||||
var worker_currency: BigNumber = _game_state.get_currency_amount_by_id(&"worker")
|
||||
|
||||
return worker_currency.mantissa >= 1.0
|
||||
|
||||
func _buy_worker() -> void:
|
||||
if _game_state == null:
|
||||
return
|
||||
|
||||
_game_state.assign_worker_to_research()
|
||||
|
||||
func _on_buy_worker_pressed() -> void:
|
||||
_buy_worker()
|
||||
_refresh_worker_button()
|
||||
|
||||
func _refresh_worker_button() -> void:
|
||||
if _buy_worker_button == null:
|
||||
return
|
||||
|
||||
if _game_state == null:
|
||||
_buy_worker_button.disabled = true
|
||||
return
|
||||
|
||||
var can_buy: bool = _can_buy_worker()
|
||||
_buy_worker_button.disabled = not can_buy
|
||||
|
||||
var worker_currency: BigNumber = _game_state.get_currency_amount_by_id(&"worker")
|
||||
var research_workers: int = _game_state.get_research_workers()
|
||||
_buy_worker_button.text = "Assign Worker to Research (%d available, %d assigned)" % [int(worker_currency.mantissa), research_workers]
|
||||
|
||||
Reference in New Issue
Block a user