97 lines
4.2 KiB
GDScript
97 lines
4.2 KiB
GDScript
extends Control
|
|
const DATA := preload("res://scripts/planets/alien_research.gd")
|
|
const MENU := preload("res://scripts/planets/freighter_menu.gd")
|
|
const COLORS := [Color("dfb775"), Color("e68c77"), Color("79cba8"), Color("7bc9e6")]
|
|
var progress: Resource
|
|
var refreshed: Callable
|
|
var points: Dictionary = {}
|
|
|
|
func _ready() -> void:
|
|
custom_minimum_size = Vector2(290, 294)
|
|
resized.connect(_build)
|
|
_build()
|
|
|
|
func _build() -> void:
|
|
for child in get_children():
|
|
remove_child(child)
|
|
child.queue_free()
|
|
points.clear()
|
|
var width := maxf(290, size.x)
|
|
_add_skill("general", Vector2(width * 0.5, 38), COLORS[0])
|
|
for i in range(3):
|
|
var branch: String = DATA.BRANCHES[i]
|
|
var x := width * (float(i) + 0.5) / 3.0
|
|
_add_skill(branch, Vector2(x, 137), COLORS[i + 1])
|
|
_add_placeholder(branch + "_a", Vector2(x - 31, 252))
|
|
_add_placeholder(branch + "_b", Vector2(x + 31, 252))
|
|
var caption := MENU.label(self, ["BROŃ", "KADŁUB", "TARCZE"][i], 12, MENU.MUTED)
|
|
caption.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
caption.position = Vector2(x - 55, 177)
|
|
caption.size = Vector2(110, 18)
|
|
caption.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
queue_redraw()
|
|
|
|
func _add_skill(id: String, center: Vector2, color: Color) -> void:
|
|
points[id] = center
|
|
var learned: bool = progress.alien_skills.get(id, false)
|
|
var prerequisite := DATA.parent(id)
|
|
var unlocked: bool = prerequisite.is_empty() or progress.alien_skills.get(prerequisite, false)
|
|
var button := MENU.button(self, "", _purchase.bind(id), learned)
|
|
button.set_script(preload("res://scripts/planets/research_skill_button.gd"))
|
|
button.name = id
|
|
button.position = center - Vector2(28, 34)
|
|
button.size = Vector2(56, 68)
|
|
button.disabled = learned or not unlocked or progress.analysis_samples < DATA.cost(id)
|
|
var status := "Zbadano" if learned else "Koszt: %d próbek" % DATA.cost(id)
|
|
if not unlocked: status += "\nWymaga: " + DATA.title(prerequisite)
|
|
elif not learned and progress.analysis_samples < DATA.cost(id): status += "\nZa mało próbek"
|
|
button.tooltip_text = DATA.title(id) + "\n" + DATA.description(id) + "\n" + status
|
|
var icon := TextureRect.new()
|
|
icon.texture = load("res://assets/freighter/research/" + id.split("_")[0] + ".png")
|
|
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
icon.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
|
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
icon.position = Vector2(4, 2)
|
|
icon.size = Vector2(48, 48)
|
|
if not unlocked: icon.modulate = Color(0.5, 0.55, 0.55, 0.65)
|
|
button.add_child(icon)
|
|
var price := MENU.label(button, "✓" if learned else str(DATA.cost(id)), 12, color if unlocked else MENU.MUTED)
|
|
price.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
price.position = Vector2(0, 48)
|
|
price.size = Vector2(56, 16)
|
|
price.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
|
|
func _add_placeholder(id: String, center: Vector2) -> void:
|
|
points[id] = center
|
|
var slot := MENU.button(self, "", func(): pass)
|
|
slot.name = id
|
|
slot.disabled = true
|
|
slot.focus_mode = Control.FOCUS_NONE
|
|
slot.mouse_default_cursor_shape = Control.CURSOR_ARROW
|
|
slot.set_script(preload("res://scripts/planets/research_skill_button.gd"))
|
|
slot.position = center - Vector2(28, 34)
|
|
slot.size = Vector2(56, 68)
|
|
slot.tooltip_text = "Pusty slot\nMiejsce na przyszłe badanie."
|
|
var mark := MENU.label(slot, "·", 24, MENU.MUTED)
|
|
mark.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
mark.position = Vector2(0, 16)
|
|
mark.size = Vector2(56, 28)
|
|
mark.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
|
|
func _purchase(id: String) -> void:
|
|
if DATA.purchase(progress, id): refreshed.call()
|
|
|
|
func _draw() -> void:
|
|
for id in points:
|
|
var prerequisite := DATA.parent(id)
|
|
if prerequisite.is_empty(): continue
|
|
var start: Vector2 = points[prerequisite] + Vector2(0, 62 if "_" in id else 34)
|
|
var end: Vector2 = points[id] - Vector2(0, 34)
|
|
var active: bool = id in DATA.ACTIVE_IDS and progress.alien_skills.get(prerequisite, false)
|
|
var color := Color("79b9a4") if active else Color("3c5158")
|
|
var middle := (start.y + end.y) * 0.5
|
|
if "_" in id: middle = end.y - 12
|
|
draw_polyline(PackedVector2Array([start, Vector2(start.x, middle), Vector2(end.x, middle), end]), color, 1.5, true)
|
|
|