85 lines
3.6 KiB
GDScript3
Raw Normal View History

2024-05-27 13:05:36 -04:00
class_name Tavern extends Control
@onready var data: Data = $/root/Root/Data
@onready var selected: GridContainer = $NinePatchRect3/GridContainer
@onready var library: GridContainer = $NinePatchRect2/GridContainer
@onready var zone: Control = $NinePatchRect/zone
@onready var icon = $NinePatchRect/zone/Icon
@onready var nam = $NinePatchRect/zone/Name
@onready var rarity = $NinePatchRect/zone/Rarity
@onready var description = $NinePatchRect/zone/Description
@onready var damage = $NinePatchRect/zone/Damage
@onready var buttonBase: PackedScene = load("res://Scenes/UI/spellButton.tscn")
2024-05-27 19:54:22 -04:00
@onready var choice = $Choice
2024-05-27 13:05:36 -04:00
var selectedButton: SpellButton
# Called when the node enters the scene tree for the first time.
func _ready():
var spells: Array[Spell] = data.unlockedSpells.duplicate()
for spell: Spell in data.spellbook.spells:
if (spell == null): continue
spells.erase(spell)
var button: SpellButton = buttonBase.instantiate()
button.spell = spell
button.connect("spellClicked", displaySpell)
selected.add_child(button)
for spell: Spell in spells:
var button: SpellButton = buttonBase.instantiate()
button.spell = spell
button.connect("spellClicked", displaySpell)
library.add_child(button)
func displaySpell(spellButton: SpellButton):
zone.show()
selectedButton = spellButton
icon.texture = selectedButton.spell.icon
nam.text = "[center]%s[/center]" % selectedButton.spell.name
rarity.text = "[center]%s[/center]" % data.Rarity.find_key(selectedButton.spell.rarity)
description.text = "[center]%s[/center]" % selectedButton.spell.description
var text: String = "Damage: %s\nBackfire Strength: %s\nFire Resistance: %s\nIce Resistance: %s\nPoison Resistance: %s\nStone Resistance: %s"
if (selectedButton.spell.damage < 0): text = "Healing: %s\nBackfire Strength: %s\nFire Resistance: %s\nIce Resistance: %s\nPoison Resistance: %s\nStone Resistance: %s"
2024-05-27 13:05:36 -04:00
var resistances: Dictionary = selectedButton.spell.blockStrength
damage.text = text % [selectedButton.spell.damage if selectedButton.spell.damage >= 0 else -selectedButton.spell.damage, selectedButton.spell.backfireStrength, 100 - resistances[Data.Element.FIRE] * 100, 100 - resistances[Data.Element.ICE] * 100, 100 - resistances[Data.Element.POISON] * 100, 100 - resistances[Data.Element.STONE] * 100]
2024-05-27 19:54:22 -04:00
if (selectedButton in selected.get_children()):
choice.get_child(0).text = "[center]Remove[/center]"
if (selected.get_child_count() == 1):
choice.disabled = true
choice.modulate = Color("fff8cf87")
else:
choice.disabled = false
choice.modulate = Color("fff8cf")
else:
choice.get_child(0).text = "[center]Select[/center]"
if (selected.get_child_count() >= 5):
choice.disabled = true
choice.modulate = Color("fff8cf87")
else:
choice.disabled = false
choice.modulate = Color("fff8cf")
func _on_choice_pressed():
if (selectedButton in selected.get_children()):
data.spellbook.spells.erase(selectedButton.spell)
selected.remove_child(selectedButton)
library.add_child(selectedButton)
else:
data.spellbook.spells.append(selectedButton.spell)
library.remove_child(selectedButton)
selected.add_child(selectedButton)
func _on_main_menu_pressed():
var m: Control = load(data.locations[data.Location.MAINMENU]).instantiate()
$/root/Root.add_child(m)
data.musicPlayer.setLoc(Data.Location.MAINMENU)
data.loc = data.Location.MAINMENU
self.queue_free()
func _on_continue_pressed():
var a: Node2D = load(data.locations[data.Location.ARENA]).instantiate()
$/root/Root.add_child(a)
data.musicPlayer.setLoc(Data.Location.ARENA)
data.loc = data.Location.ARENA
self.queue_free()
data.playing = true