ArkSol/scripts/station_panel.gd
2025-11-14 14:59:50 +01:00

70 lines
1.5 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Panel
var dragging := false
var drag_offset := Vector2.ZERO
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
var current_station = null
func show_for_station(station):
self.visible = true
current_station = station
func _on_button_2_pressed() -> void:
self.visible = false
func _on_button_pressed() -> void:
build_ship("frigate")
func _on_button_3_pressed() -> void:
build_ship("transport")
func build_ship(type: String):
if current_station == null:
print("Brak stacji nie można budować statku")
return
var cost = ShipsType.SHIP_TYPES[type].cost
# 1. Sprawdź zasoby gracza
for res in cost.keys():
if PlayerData.resources[res] < cost[res]:
print("Brakuje:", res)
return
# 2. Odejmij zasoby gracza
for res in cost.keys():
PlayerData.resources[res] -= cost[res]
PlayerData.emit_signal("stats_changed")
# 3. Stwórz statek
var ship = preload("res://scenes/ship.tscn").instantiate()
ship.setup(type)
# POZYCJA SPAWNU — np. obok stacji
ship.position = current_station.position + Vector2(15, 15)
# Dodaj do sceny
get_tree().root.get_node("Galaxy").add_child(ship)
print("Zbudowano statek:", type)