From 766610586f405c39fc7a6e9864229b7f35b60273 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 25 Feb 2020 14:01:54 +0100 Subject: [PATCH] Item spell support. --- HEADS | 2 +- game/data/item_templates/2_test.tres | 4 +- .../3_chest_of_the_infinite_wisdom.tres | 4 +- game/data/spells/14_amplify_pain_rank_1.tres | 1 + game/scripts/auras/aura_script.gd | 4 + game/ui/bags/Bag.tscn | 67 +--------------- game/ui/bags/BagEntry.gd | 17 ++--- game/ui/bags/EquipmentSlot.gd | 12 +++ game/ui/bags/EquipmentSlot.tscn | 2 +- game/ui/bags/ItemPupop.gd | 19 ++++- game/ui/bags/ItemTooltip.tscn | 76 +++++++++++++++++++ 11 files changed, 128 insertions(+), 80 deletions(-) create mode 100644 game/ui/bags/ItemTooltip.tscn diff --git a/HEADS b/HEADS index 069be9b0..7f8c80fa 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"engine": {"3.2": "f1a77a7e0a41dde8b59aa66eba29ddaf737b6b18", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "a08917370cdef0884042bdb49fb80ece0b2e76ec"}, "entity_spell_system": {"master": "7666d11b2da6b6dc8cda20f72d388eacc7e4ce6b"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "0a4072b9b8f1a1d35c0e38aaa04e0858ea6eacb0"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "00f6c128bd0e9799b7f7f86e118ed68277fbe27d"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "prop_tool": {"master": "df438053ebc900966f8f842fc65f0264f1271d49"}} \ No newline at end of file +{"engine": {"3.2": "f4e3701893bdf6b304ee114745def2f8ac4aa822", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "a08917370cdef0884042bdb49fb80ece0b2e76ec"}, "entity_spell_system": {"master": "c5c0f2cddd74c849017fa5138bc6ebdeb76dcd80"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "5b32345181338f06a7751c924af2b57807ba99cd"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "00f6c128bd0e9799b7f7f86e118ed68277fbe27d"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "prop_tool": {"master": "df438053ebc900966f8f842fc65f0264f1271d49"}} \ No newline at end of file diff --git a/game/data/item_templates/2_test.tres b/game/data/item_templates/2_test.tres index 63d88503..32bea07e 100644 --- a/game/data/item_templates/2_test.tres +++ b/game/data/item_templates/2_test.tres @@ -1,7 +1,8 @@ -[gd_resource type="ItemTemplate" load_steps=3 format=2] +[gd_resource type="ItemTemplate" load_steps=4 format=2] [ext_resource path="res://scripts/items/ItemTemplateGD.gd" type="Script" id=1] [ext_resource path="res://data/icons/3_iron_bar.tres" type="Texture" id=2] +[ext_resource path="res://data/spells/13_aspect_of_bees_rank_1.tres" type="Spell" id=3] [resource] resource_name = "Iron Bar" @@ -9,4 +10,5 @@ id = 2 text_name = "Iron Bar" stack_size = 10 icon = ExtResource( 2 ) +use_spell = ExtResource( 3 ) script = ExtResource( 1 ) diff --git a/game/data/item_templates/3_chest_of_the_infinite_wisdom.tres b/game/data/item_templates/3_chest_of_the_infinite_wisdom.tres index 4f17dc3c..1566c03b 100644 --- a/game/data/item_templates/3_chest_of_the_infinite_wisdom.tres +++ b/game/data/item_templates/3_chest_of_the_infinite_wisdom.tres @@ -1,8 +1,9 @@ -[gd_resource type="ItemTemplate" load_steps=4 format=2] +[gd_resource type="ItemTemplate" load_steps=5 format=2] [ext_resource path="res://scripts/items/ItemTemplateGD.gd" type="Script" id=1] [ext_resource path="res://data/item_visuals/1_chest_of_the_infinite_wisdom.tres" type="ItemVisual" id=2] [ext_resource path="res://data/icons/4_chest_of_the_infinite_wisdom.tres" type="Texture" id=3] +[ext_resource path="res://data/spells/14_amplify_pain_rank_1.tres" type="Spell" id=4] [resource] resource_name = "Chest of the Infinite Wisdom" @@ -14,6 +15,7 @@ armor_type = 1 equip_slot = 3 item_visual = ExtResource( 2 ) icon = ExtResource( 3 ) +use_spell = ExtResource( 4 ) item_stat_modifier_count = 2 Modifiers_0/stat_id = 8 Modifiers_0/min_base_mod = 1000.0 diff --git a/game/data/spells/14_amplify_pain_rank_1.tres b/game/data/spells/14_amplify_pain_rank_1.tres index 68c03730..9f8a7824 100644 --- a/game/data/spells/14_amplify_pain_rank_1.tres +++ b/game/data/spells/14_amplify_pain_rank_1.tres @@ -27,6 +27,7 @@ text_name = "Amplify Pain" text_description = "Range: 26m. Casttime: {3}. Causes your damage over time effects to tick." +cooldown_cooldown = 16.0 range_range = 26.0 cast_cast_time = 1.5 damage_type = 16 diff --git a/game/scripts/auras/aura_script.gd b/game/scripts/auras/aura_script.gd index 164f0bd8..4c344c12 100644 --- a/game/scripts/auras/aura_script.gd +++ b/game/scripts/auras/aura_script.gd @@ -25,6 +25,10 @@ class_name AuraGD func _handle_aura_damage(aura_data : AuraData, damage_info : SpellDamageInfo) -> void: randomize() + if damage_info.dealer == null: + printerr("_handle_aura_damage: damage_info.dealer is null! ") + return + damage_info.damage = damage_min + (randi() % (damage_max - damage_min)) damage_info.damage *= damage_info.dealer.scharacter_level / float(EntityEnums.MAX_CHARACTER_LEVEL) damage_info.damage_source_type = aura_data.aura.damage_type diff --git a/game/ui/bags/Bag.tscn b/game/ui/bags/Bag.tscn index 67acfdb4..692b664e 100644 --- a/game/ui/bags/Bag.tscn +++ b/game/ui/bags/Bag.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://ui/bags/InventoryGUI.gd" type="Script" id=2] [ext_resource path="res://ui/bags/BagEntry.tscn" type="PackedScene" id=3] [ext_resource path="res://ui/bags/EquipmentSlot.tscn" type="PackedScene" id=4] -[ext_resource path="res://ui/bags/ItemPupop.gd" type="Script" id=5] +[ext_resource path="res://ui/bags/ItemTooltip.tscn" type="PackedScene" id=5] [node name="Inventory" type="PanelContainer"] anchor_right = 1.0 @@ -256,68 +256,5 @@ margin_right = 1020.0 margin_bottom = 596.0 mouse_filter = 2 -[node name="ItemTooltip" type="PopupPanel" parent="TooltipContainer"] -margin_right = 295.0 -margin_bottom = 223.0 -script = ExtResource( 5 ) -__meta__ = { -"_edit_use_anchors_": false -} -name_path = NodePath("../ItemTooltip/VBoxContainer/HBoxContainer/VBoxContainer/NameLabel") -description_path = NodePath("../ItemTooltip/VBoxContainer/DescriptionLabel") - -[node name="VBoxContainer" type="VBoxContainer" parent="TooltipContainer/ItemTooltip"] -margin_left = 4.0 -margin_top = 4.0 -margin_right = 291.0 -margin_bottom = 219.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="HBoxContainer" type="HBoxContainer" parent="TooltipContainer/ItemTooltip/VBoxContainer"] -margin_right = 287.0 -margin_bottom = 26.0 - -[node name="VBoxContainer" type="VBoxContainer" parent="TooltipContainer/ItemTooltip/VBoxContainer/HBoxContainer"] -margin_right = 249.0 -margin_bottom = 26.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -alignment = 1 - -[node name="NameLabel" type="RichTextLabel" parent="TooltipContainer/ItemTooltip/VBoxContainer/HBoxContainer/VBoxContainer"] -margin_top = 4.0 -margin_right = 249.0 -margin_bottom = 22.0 -rect_min_size = Vector2( 0, 18 ) -size_flags_horizontal = 3 -bbcode_enabled = true - -[node name="Button" type="Button" parent="TooltipContainer/ItemTooltip/VBoxContainer/HBoxContainer"] -margin_left = 257.0 -margin_right = 287.0 -margin_bottom = 26.269 -rect_min_size = Vector2( 30, 20 ) -text = "X" - -[node name="HSeparator" type="HSeparator" parent="TooltipContainer/ItemTooltip/VBoxContainer"] -margin_top = 34.0 -margin_right = 287.0 -margin_bottom = 42.0 -size_flags_horizontal = 3 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="DescriptionLabel" type="RichTextLabel" parent="TooltipContainer/ItemTooltip/VBoxContainer"] -margin_top = 50.0 -margin_right = 287.0 -margin_bottom = 215.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -bbcode_enabled = true +[node name="ItemTooltip" parent="TooltipContainer" instance=ExtResource( 5 )] [connection signal="pressed" from="VBoxContainer/HBoxContainer/CloseButton" to="." method="hide"] -[connection signal="pressed" from="TooltipContainer/ItemTooltip/VBoxContainer/HBoxContainer/Button" to="TooltipContainer/ItemTooltip" method="hide"] diff --git a/game/ui/bags/BagEntry.gd b/game/ui/bags/BagEntry.gd index 9f4b5775..a8d92b51 100644 --- a/game/ui/bags/BagEntry.gd +++ b/game/ui/bags/BagEntry.gd @@ -57,7 +57,7 @@ func _ready() -> void: _stack_counter = get_node(stack_counter) as Label - button.connect("pressed", self, "_on_button_pressed") + button.connect("button_up", self, "_on_button_pressed") #func _exit_tree(): # if item != null: @@ -124,8 +124,8 @@ func setup_icon() -> void: if item.item_template.use_spell != null: var spell : Spell = item.item_template.use_spell - spell_id = spell.spell_id - has_gcd = spell.cooldown_global_cooldown + spell_id = spell.id + has_gcd = spell.cooldown_global_cooldown_enabled else: spell_id = 0 has_gcd = false @@ -134,10 +134,6 @@ func setup_icon() -> void: -func _on_button_pressed() -> void: - #if spell_id != 0: - # player.crequest_spell_cast(button_entry.item_id) - pass func set_button_entry_data(ii : ItemInstance) -> void: if item != null and item.item_template.stack_size > 1: @@ -238,13 +234,14 @@ func _cgcd_started(value :float) -> void: func _cgcd_finished() -> void: gcd = 0 - -func _pressed(): + +func _on_button_pressed() -> void: +#func _pressed(): if _tooltip != null and item != null: var pos : Vector2 = rect_global_position pos.x += rect_size.x - _tooltip.set_item(item) + _tooltip.set_item(player, item) _tooltip.popup(Rect2(pos, _tooltip.rect_size)) # _tooltip.pac diff --git a/game/ui/bags/EquipmentSlot.gd b/game/ui/bags/EquipmentSlot.gd index b5279894..8e4e37cb 100644 --- a/game/ui/bags/EquipmentSlot.gd +++ b/game/ui/bags/EquipmentSlot.gd @@ -33,6 +33,8 @@ var _item_instance : ItemInstance func _ready(): _texture = get_node(texture_path) as TextureRect + + connect("button_up", self, "_on_button_pressed") func set_tooltip_node(tooltip : Popup) -> void: _tooltip = tooltip @@ -101,3 +103,13 @@ func con_equip_success(entity: Entity, pequip_slot: int, item: ItemInstance, old return _texture.texture = item.item_template.icon + +func _on_button_pressed() -> void: +#func _pressed(): + if _tooltip != null and _item_instance != null: + var pos : Vector2 = rect_global_position + pos.x += rect_size.x + + _tooltip.set_item(_player, _item_instance) + _tooltip.popup(Rect2(pos, _tooltip.rect_size)) +# _tooltip.pac diff --git a/game/ui/bags/EquipmentSlot.tscn b/game/ui/bags/EquipmentSlot.tscn index da21a9ac..971fc466 100644 --- a/game/ui/bags/EquipmentSlot.tscn +++ b/game/ui/bags/EquipmentSlot.tscn @@ -29,7 +29,7 @@ __meta__ = { [node name="TextureRect" type="TextureRect" parent="MarginContainer"] margin_left = 5.0 margin_top = 5.0 -margin_right = 76.0 +margin_right = 45.0 margin_bottom = 45.0 mouse_filter = 2 size_flags_horizontal = 3 diff --git a/game/ui/bags/ItemPupop.gd b/game/ui/bags/ItemPupop.gd index b95e8cc0..9258022f 100644 --- a/game/ui/bags/ItemPupop.gd +++ b/game/ui/bags/ItemPupop.gd @@ -22,14 +22,31 @@ extends PopupPanel export(NodePath) var name_path : NodePath export(NodePath) var description_path : NodePath +export(NodePath) var use_button_path : NodePath var _name : RichTextLabel var _description : RichTextLabel +var _use_button : Button + +var _entity : Entity +var _item : ItemInstance func _ready(): _name = get_node(name_path) as RichTextLabel _description = get_node(description_path) as RichTextLabel + _use_button = get_node(use_button_path) as Button -func set_item(item : ItemInstance) -> void: +func set_item(entity : Entity, item : ItemInstance) -> void: + _entity = entity + _item = item + _name.bbcode_text = item.item_template.text_name # _description.text = item.item_template. + + if item.item_template.use_spell != null: + _use_button.show() + else: + _use_button.hide() + +func use_button_pressed(): + _entity.crequest_use_item(_item.item_template.id) diff --git a/game/ui/bags/ItemTooltip.tscn b/game/ui/bags/ItemTooltip.tscn new file mode 100644 index 00000000..ac37109e --- /dev/null +++ b/game/ui/bags/ItemTooltip.tscn @@ -0,0 +1,76 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://ui/bags/ItemPupop.gd" type="Script" id=1] + +[node name="ItemTooltip" type="PopupPanel"] +margin_right = 295.0 +margin_bottom = 223.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} +name_path = NodePath("../ItemTooltip/VBoxContainer/HBoxContainer/VBoxContainer/NameLabel") +description_path = NodePath("../ItemTooltip/VBoxContainer/DescriptionLabel") +use_button_path = NodePath("VBoxContainer/UseButton") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +margin_left = 4.0 +margin_top = 4.0 +margin_right = 291.0 +margin_bottom = 219.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +margin_right = 287.0 +margin_bottom = 26.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"] +margin_right = 253.0 +margin_bottom = 26.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +alignment = 1 + +[node name="NameLabel" type="RichTextLabel" parent="VBoxContainer/HBoxContainer/VBoxContainer"] +margin_top = 4.0 +margin_right = 253.0 +margin_bottom = 22.0 +rect_min_size = Vector2( 0, 18 ) +size_flags_horizontal = 3 +bbcode_enabled = true + +[node name="Button" type="Button" parent="VBoxContainer/HBoxContainer"] +margin_left = 257.0 +margin_right = 287.0 +margin_bottom = 26.269 +rect_min_size = Vector2( 30, 20 ) +text = "X" + +[node name="HSeparator" type="HSeparator" parent="VBoxContainer"] +margin_top = 34.0 +margin_right = 287.0 +margin_bottom = 38.0 +size_flags_horizontal = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="UseButton" type="Button" parent="VBoxContainer"] +margin_top = 46.0 +margin_right = 287.0 +margin_bottom = 72.269 +text = "Use" + +[node name="DescriptionLabel" type="RichTextLabel" parent="VBoxContainer"] +margin_top = 80.0 +margin_right = 287.0 +margin_bottom = 215.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +bbcode_enabled = true +[connection signal="pressed" from="VBoxContainer/HBoxContainer/Button" to="." method="hide"] +[connection signal="pressed" from="VBoxContainer/UseButton" to="." method="use_button_pressed"]