145 lines
3.8 KiB
GDScript
145 lines
3.8 KiB
GDScript
extends Panel
|
|
|
|
@onready var tech_container = $Technologies
|
|
|
|
|
|
|
|
# Ścieżka do tekstur technologii (tu możesz dać swoje grafiki)
|
|
const DEFAULT_ICON = preload("res://assets/tech/Mining_Drill.png")
|
|
|
|
var dragging := false
|
|
var drag_offset := Vector2.ZERO
|
|
signal building_buttons_update
|
|
signal ships_buttons_update
|
|
|
|
func _gui_input(event):
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
|
if event.pressed:
|
|
# Kliknięto na panel → zaczynamy drag
|
|
dragging = true
|
|
drag_offset = get_local_mouse_position()
|
|
else:
|
|
# Zwolniono przycisk → kończymy drag
|
|
dragging = false
|
|
elif event is InputEventMouseMotion and dragging:
|
|
# Przesuwamy panel względem pozycji myszy
|
|
position += event.relative
|
|
|
|
func _ready():
|
|
_create_technology_buttons()
|
|
|
|
|
|
func _create_technology_buttons():
|
|
# Wyczyść stare przyciski
|
|
for c in tech_container.get_children():
|
|
c.queue_free()
|
|
|
|
for tech_id in Technologies.TECHNOLOGIES.keys():
|
|
var tech = Technologies.TECHNOLOGIES[tech_id]
|
|
var btn = TextureButton.new()
|
|
|
|
# 🔹 Ustaw ikonę technologii z pola "texture"
|
|
if tech.has("texture") and tech.texture != "":
|
|
btn.texture_normal = load(tech.texture)
|
|
else:
|
|
# Fallback na domyślną ikonę, jeśli brak tekstury w danych
|
|
btn.texture_normal = DEFAULT_ICON
|
|
|
|
btn.custom_minimum_size = Vector2(96, 96)
|
|
|
|
btn.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
|
|
|
# 🔹 Tooltip z opisem i kosztami
|
|
var cost_text = ""
|
|
for cost_name in tech.cost.keys():
|
|
cost_text += "%s: %d " % [tr(cost_name), tech.cost[cost_name]]
|
|
|
|
btn.tooltip_text = "%s\n%s\n%s %s" % [
|
|
tr(tech.name),
|
|
tr(tech.description),
|
|
tr("Koszt:"),
|
|
cost_text.strip_edges()
|
|
]
|
|
|
|
# 🔹 Jeśli gracz już ma tę technologię
|
|
if tech_id in PlayerData.unlocked_techs:
|
|
btn.modulate = Color(0.6, 0.6, 0.6) # wyszarz
|
|
btn.disabled = true
|
|
btn.tooltip_text += "\n[✓] " + tr("Odkryta")
|
|
|
|
# 🔹 Jeśli brakuje wymaganych technologii
|
|
elif not _check_requirements(tech.requires):
|
|
btn.modulate = Color(0.5, 0.5, 0.5)
|
|
btn.disabled = true
|
|
btn.tooltip_text += "\n[!] " + tr("Wymagania niespełnione")
|
|
|
|
else:
|
|
# 🔹 Po kliknięciu rozpocznij badanie technologii
|
|
btn.connect("pressed", Callable(self, "_on_technology_pressed").bind(tech_id))
|
|
|
|
tech_container.add_child(btn)
|
|
|
|
|
|
|
|
func _check_requirements(requirements: Array) -> bool:
|
|
if requirements.is_empty():
|
|
return true
|
|
for req in requirements:
|
|
if req not in PlayerData.unlocked_techs:
|
|
return false
|
|
return true
|
|
|
|
|
|
func _on_technology_pressed(tech_id):
|
|
var tech = Technologies.TECHNOLOGIES[tech_id]
|
|
|
|
# Jeśli gracz już ma tę technologię — nic nie rób
|
|
if tech_id in PlayerData.unlocked_techs:
|
|
print("Gracz już ma technologię:", tech_id)
|
|
return
|
|
|
|
# Sprawdź wymagania
|
|
for req in tech.requires:
|
|
if req not in PlayerData.unlocked_techs:
|
|
print("Brak wymaganej technologii:", req)
|
|
return
|
|
|
|
# Sprawdź, czy gracz ma wystarczające zasoby i naukę
|
|
for cost_name in tech.cost.keys():
|
|
var required_amount = tech.cost[cost_name]
|
|
var has_enough = false
|
|
|
|
if cost_name == "science":
|
|
has_enough = PlayerData.since_doc >= required_amount
|
|
else:
|
|
if PlayerData.resources.has(cost_name):
|
|
has_enough = PlayerData.resources[cost_name] >= required_amount
|
|
|
|
if not has_enough:
|
|
print("Brak zasobu:", cost_name)
|
|
return
|
|
|
|
# Odejmij koszty
|
|
for cost_name in tech.cost.keys():
|
|
if cost_name == "science":
|
|
PlayerData.since_doc -= tech.cost[cost_name]
|
|
else:
|
|
PlayerData.resources[cost_name] -= tech.cost[cost_name]
|
|
|
|
# Dodaj technologię do odblokowanych
|
|
PlayerData.unlocked_techs.append(tech_id)
|
|
print("Odblokowano technologię:", tech.name)
|
|
emit_signal("building_buttons_update")
|
|
emit_signal("ships_buttons_update")
|
|
|
|
|
|
# Opcjonalnie: powiadom o zmianach
|
|
PlayerData.emit_signal("stats_changed")
|
|
|
|
_create_technology_buttons()
|
|
|
|
|
|
func _on_button_pressed() -> void:
|
|
hide()
|