ArkSol/scripts/planet_panel.gd

114 lines
2.9 KiB
GDScript

extends Panel
@onready var name_label = $Name_Label
@onready var info_label = $Info_Label
@onready var buildings_container = $Buildings
@onready var send_button = $SendButton
func _ready():
send_button.connect("pressed", Callable(self, "_on_send_resources_pressed"))
var planet: Planet = null
func _process(delta: float) -> void:
_update_info()
func show_for_planet(p: Planet):
planet = p
name_label.text = p.pname
_update_info()
_create_building_buttons()
show()
func hide_panel():
hide()
planet = null
func _update_info():
if not planet:
return
# Tekst informacji wzorowany na print_data z Planet.gd
var text = "🌍 %s\n" % planet.pname
text += "Biosfera: %.2f (+%.2f)\n" % [planet.biosfere, planet.bonuses.get("biosfere", 0.0)]
text += "Zasobność surowców: %.2f\n" % planet.res_rich
text += "Limit populacji: %s\n" % GameData.format_number(planet.max_pop)
text += "Populacja: %d\n" % int(planet.population)
text += "Status: %s\n" % ("Skolonizowana" if planet.is_colonized else "Nieskolonizowana")
# Surowce
var has_any_resource = false
for key in planet.resources.keys():
var res = planet.resources[key]
if res.has("exist") and res["exist"]:
if not has_any_resource:
text += "Zasoby:\n"
has_any_resource = true
var display_name = tr(key)
text += "%s: %.2f +(%s)\n" % [
display_name,
round(res.get("amount",0)*100)/100.0,
planet.check_growth()
]
# Budynki
if planet.buildings.size() > 0:
text += "Budynki na planecie:\n"
for b in planet.buildings:
var data = BuildingsList.BUILDINGS[b.id]
var status = tr("Under construction") if b.is_building else tr("ready")
text += "- %s [%s]\n" % [tr(data.name), status]
info_label.text = text
func _create_building_buttons():
# Usuń stare przyciski
for child in buildings_container.get_children():
child.queue_free()
# Tworzymy nowe przyciski dla wszystkich budynków w definicjach
for b_id in BuildingsList.BUILDINGS.keys():
var b_data = BuildingsList.BUILDINGS[b_id]
var btn = TextureButton.new()
btn.texture_normal = load(b_data.texture)
#btn.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_COVERED
#btn.ignore_texture_size = true
btn.connect("pressed", Callable(self, "_on_building_pressed").bind(b_id))
buildings_container.add_child(btn)
func _on_building_pressed(b_id):
if not planet:
return
planet.add_building(b_id)
_update_info()
func _on_button_pressed() -> void:
hide_panel()
#do usuniecia po testach
func _on_send_resources_pressed():
if not planet:
return
for res_name in planet.resources.keys():
var res = planet.resources[res_name]
if res.has("amount") and res["amount"] > 0:
# Jeżeli gracz ma ten typ zasobu, dodaj
if PlayerData.resources.has(res_name):
PlayerData.resources[res_name] += res["amount"]
res["amount"] = 0
planet.resources[res_name] = res
PlayerData.emit_signal("stats_changed")
# Emituj sygnał tylko raz, po zakończeniu pętli