Implemented sorting for the spellbook, and the ability to hide spells that the player cannot learn. Also spells are now color-coded based on what the character knows.

This commit is contained in:
Relintai 2019-11-29 14:10:45 +01:00
parent ea654acf7f
commit 4e76fb3c2f
8 changed files with 131 additions and 32 deletions

View File

@ -4,7 +4,7 @@
[ext_resource path="res://data/icons/naturalist/aspect_of_scorpions.tres" type="Texture" id=2]
[ext_resource path="res://data/auras/10_aspect_of_scorpions_rank_1.tres" type="Aura" id=3]
[ext_resource path="res://data/effect_data/aspect_of_scorpions.tres" type="SpellEffectVisual" id=4]
[ext_resource path="res://data/spells/27_aspect_of_scorpions.tres" type="Spell" id=5]
[ext_resource path="res://data/spells/2_test_cast_spell.tres" type="Spell" id=5]
[resource]
resource_name = "Aspect of Scorpions"

View File

@ -1,8 +1,9 @@
[gd_resource type="Spell" load_steps=4 format=2]
[gd_resource type="Spell" load_steps=5 format=2]
[ext_resource path="res://scripts/spells/gd_spell_script.gd" type="Script" id=1]
[ext_resource path="res://data/icons/naturalist/aspect_of_wasps.tres" type="Texture" id=2]
[ext_resource path="res://data/auras/11_aspect_of_wasps_rank1.tres" type="Aura" id=3]
[ext_resource path="res://data/spells/2_test_cast_spell.tres" type="Spell" id=4]
[resource]
resource_name = "Aspect of Wasps"
@ -23,4 +24,5 @@ aoe_targetType = 541
aoe_movement_type = 99418736
aoe_colliderType = 541
projectile_type = 541
training_required_spell = ExtResource( 4 )
script = ExtResource( 1 )

View File

@ -1,8 +1,9 @@
[gd_resource type="Spell" load_steps=4 format=2]
[gd_resource type="Spell" load_steps=5 format=2]
[ext_resource path="res://scripts/spells/gd_spell_script.gd" type="Script" id=1]
[ext_resource path="res://data/icons/naturalist/aspect_of_wolves.tres" type="Texture" id=2]
[ext_resource path="res://data/auras/12_aspect_of_wolves_rank_1.tres" type="Aura" id=3]
[ext_resource path="res://data/spells/2_test_cast_spell.tres" type="Spell" id=4]
[resource]
resource_name = "Aspect of Wolves"
@ -23,4 +24,5 @@ aoe_targetType = 1129071960
aoe_movement_type = 2190112
aoe_colliderType = 1058050193
projectile_type = -1039400960
training_required_spell = ExtResource( 4 )
script = ExtResource( 1 )

View File

@ -1,8 +1,9 @@
[gd_resource type="Spell" load_steps=4 format=2]
[gd_resource type="Spell" load_steps=5 format=2]
[ext_resource path="res://scripts/spells/gd_spell_script.gd" type="Script" id=1]
[ext_resource path="res://data/icons/naturalist/aspect_of_bees.tres" type="Texture" id=2]
[ext_resource path="res://data/auras/13_aspect_of_bees_rank_1.tres" type="Aura" id=3]
[ext_resource path="res://data/spells/2_test_cast_spell.tres" type="Spell" id=4]
[resource]
resource_name = "Aspect of Bees"
@ -26,4 +27,5 @@ aoe_targetType = -1910718371
aoe_movement_type = 1611610192
aoe_colliderType = -298046312
projectile_type = 1065353216
training_required_spell = ExtResource( 4 )
script = ExtResource( 1 )

View File

@ -4,10 +4,12 @@ extends Control
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
export (NodePath) var spell_entry_container_path : NodePath
export (NodePath) var prev_button_path : NodePath
export (NodePath) var next_button_path : NodePath
export (NodePath) var spell_points_label_path : NodePath
export(NodePath) var spell_entry_container_path : NodePath
export(NodePath) var prev_button_path : NodePath
export(NodePath) var next_button_path : NodePath
export(NodePath) var spell_points_label_path : NodePath
export(bool) var show_not_learnable : bool = false
var _spell_entry_container : Node
var _spell_entries : Array
@ -23,6 +25,8 @@ var _max_pages : int = 0
var _entity_data : EntityData
var _character_class : EntityClassData
var _spells : Array
func _ready() -> void:
_spell_entries.clear()
@ -66,24 +70,37 @@ func refresh_entries() -> void:
if _character_class == null or _player == null:
return
for i in range(len(_spell_entries)):
var i : int = 0
var n : int = 0
# for n in range(len(_spell_entries)):
while n < len(_spell_entries):
var spindex : int = i + (_page * len(_spell_entries))
if spindex >= _character_class.get_num_spells():
if spindex >= _spells.size():
_spell_entries[i].set_spell(_player, null)
i += 1
n += 1
continue
var spell : Spell = _character_class.get_spell(spindex)
var spell : Spell = _spells[spindex]
_spell_entries[i].set_spell(_player, spell)
if not show_not_learnable:
if not _player.hasc_spell(spell) and spell.training_required_spell \
and not _player.hasc_spell(spell.training_required_spell):
i += 1
continue
_spell_entries[n].set_spell(_player, spell)
i += 1
n += 1
func refresh_all() -> void:
if _player == null:
return
_entity_data = _player.centity_data
_character_class = _entity_data.entity_class_data
if _character_class == null:
return
@ -105,10 +122,52 @@ func _visibility_changed() -> void:
func set_player(p_player: Entity) -> void:
if _player != null:
_player.disconnect("cfree_spell_points_changed", self, "cfree_spell_points_changed")
_player.disconnect("centity_data_changed", self, "centity_data_changed")
_player = p_player
_player.connect("cfree_spell_points_changed", self, "cfree_spell_points_changed")
_player.connect("centity_data_changed", self, "centity_data_changed")
if _player != null:
centity_data_changed(_player.centity_data)
else:
centity_data_changed(null)
func cfree_spell_points_changed(entity: Entity, value: int) -> void:
_spell_points_label.text = "Free spell points: " + str(_player.getc_free_spell_points())
func centity_data_changed(data: EntityData):
_spells.clear()
_entity_data = null
_character_class = null
if data == null:
return
_entity_data = _player.centity_data
_character_class = _entity_data.entity_class_data
if _character_class == null:
return
for i in range(_character_class.get_num_spells()):
_spells.append(_character_class.get_spell(i))
_spells.sort_custom(CustomSpellSorter, "sort")
class CustomSpellSorter:
static func sort(a, b):
var res = a.text_name.casecmp_to(b.text_name)
if res == 0:
if a.rank < b.rank:
return true
return false
elif res == 1:
return false
return true

View File

@ -16,6 +16,7 @@ spell_entry_container_path = NodePath("PagedContent/GridContainer")
prev_button_path = NodePath("PagedContent/Controls/HBoxContainer/Button2")
next_button_path = NodePath("PagedContent/Controls/HBoxContainer/Button")
spell_points_label_path = NodePath("PagedContent/Controls/HBoxContainer/SpellPoints")
show_not_learnable = true
[node name="PagedContent" type="VBoxContainer" parent="."]
margin_left = 4.0

View File

@ -4,14 +4,17 @@ extends Control
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
export (NodePath) var icon_path : NodePath
export (NodePath) var name_label_path : NodePath
#export (NodePath) var description_label_path : NodePath
export (NodePath) var known_label_path : NodePath
export (NodePath) var learn_button_path : NodePath
export (NodePath) var spell_button_path : NodePath
export (NodePath) var popup_path : NodePath
export(NodePath) var icon_path : NodePath
export(NodePath) var name_label_path : NodePath
#export(NodePath) var description_label_path : NodePath
export(NodePath) var known_label_path : NodePath
export(NodePath) var learn_button_path : NodePath
export(NodePath) var spell_button_path : NodePath
export(NodePath) var popup_path : NodePath
export(Color) var known_color : Color = Color.white
export(Color) var not_known_color : Color = Color.gray
export(Color) var unlearnable_color : Color = Color.gray
var _icon : TextureRect
var _name_label : Label
@ -22,6 +25,8 @@ var _popup : Popup
var _spell : Spell
var _player : Entity
var _spell_known : bool
func _ready() -> void:
_icon = get_node(icon_path) as TextureRect
_name_label = get_node(name_label_path) as Label
@ -46,12 +51,7 @@ func set_spell(p_player : Entity, p_spell: Spell) -> void:
_popup.set_spell(_spell)
if not _spell == null:
if _player.hasc_spell(p_spell):
get_node(known_label_path).show()
get_node(learn_button_path).hide()
else:
get_node(known_label_path).hide()
get_node(learn_button_path).show()
_spell_known = _player.hasc_spell(p_spell)
_icon.texture = _spell.icon
_name_label.text = _spell.text_name + " (Rank " + str(_spell.rank) + ")"
@ -60,6 +60,8 @@ func set_spell(p_player : Entity, p_spell: Spell) -> void:
_name_label.text = "....."
update_spell_indicators()
func learn_spell() -> void:
if _player == null or _spell == null:
return
@ -71,16 +73,45 @@ func learn_spell() -> void:
func cspell_added(entity: Entity, spell: Spell) -> void:
if spell == _spell:
get_node(known_label_path).show()
get_node(learn_button_path).hide()
_spell_known = true
update_spell_indicators()
func cspell_removed(entity: Entity, spell: Spell) -> void:
if spell == _spell:
get_node(known_label_path).hide()
get_node(learn_button_path).show()
_spell_known = false
update_spell_indicators()
func spell_button_pressed() -> void:
var pos : Vector2 = _spell_button.rect_global_position
pos.x += _spell_button.rect_size.x
_popup.popup(Rect2(pos, _popup.rect_size))
func update_spell_indicators():
if _spell_known:
get_node(known_label_path).show()
get_node(learn_button_path).hide()
modulate = known_color
else:
if _spell != null:
if _spell.training_required_spell:
if not _player.hasc_spell(_spell.training_required_spell):
get_node(known_label_path).hide()
get_node(learn_button_path).show()
modulate = unlearnable_color
return
get_node(known_label_path).hide()
get_node(learn_button_path).show()
modulate = not_known_color
modulate = not_known_color

View File

@ -23,6 +23,8 @@ known_label_path = NodePath("SpellEntryPopup/VBoxContainer/PanelContainer")
learn_button_path = NodePath("SpellEntryPopup/VBoxContainer/LearnButton")
spell_button_path = NodePath("PanelContainer/HBoxContainer/Button")
popup_path = NodePath("SpellEntryPopup")
not_known_color = Color( 0.596078, 0.596078, 0.596078, 1 )
unlearnable_color = Color( 0.772549, 0.192157, 0.192157, 1 )
[node name="PanelContainer" type="PanelContainer" parent="."]
anchor_right = 1.0
@ -63,7 +65,7 @@ size_flags_vertical = 3
expand = true
[node name="SpellName" type="Label" parent="PanelContainer/HBoxContainer"]
margin_left = 63.0
margin_left = 59.0
margin_top = 20.0
margin_right = 278.0
margin_bottom = 35.0