2020-03-11 16:38:01 +01:00
|
|
|
extends VBoxContainer
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-01-31 20:01:34 +01:00
|
|
|
# Copyright (c) 2019-2020 Péter Magyar
|
2019-12-22 19:20:38 +01:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
export (PackedScene) var aura_entry_scene : PackedScene
|
|
|
|
|
|
|
|
export (NodePath) var name_text_path : NodePath
|
2020-08-03 21:58:38 +02:00
|
|
|
export (NodePath) var level_text_path : NodePath
|
2019-11-20 14:30:34 +01:00
|
|
|
export (NodePath) var health_range_path : NodePath
|
2019-12-03 23:22:35 +01:00
|
|
|
export (NodePath) var health_text_path : NodePath
|
2020-03-11 16:38:01 +01:00
|
|
|
export (NodePath) var resource_range_path : NodePath
|
|
|
|
export (NodePath) var resource_text_path : NodePath
|
2019-11-20 14:30:34 +01:00
|
|
|
export (NodePath) var aura_grid_path : NodePath
|
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
var _name_text : Label
|
2020-08-03 21:58:38 +02:00
|
|
|
var _level_text : Label
|
2019-12-03 23:22:35 +01:00
|
|
|
var _health_range : Range
|
|
|
|
var _health_text : Label
|
2020-03-11 16:38:01 +01:00
|
|
|
var _resource_range : Range
|
|
|
|
var _resource_text : Label
|
2019-12-03 23:22:35 +01:00
|
|
|
var _aura_grid : GridContainer
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
var _player : Entity
|
2020-03-11 16:38:01 +01:00
|
|
|
var _mana : ManaResource
|
2020-06-20 16:15:24 +02:00
|
|
|
var _health : EntityResourceHealth
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready() -> void:
|
2019-12-03 23:22:35 +01:00
|
|
|
_name_text = get_node(name_text_path) as Label
|
2020-08-03 21:58:38 +02:00
|
|
|
_level_text = get_node(level_text_path) as Label
|
2019-12-03 23:22:35 +01:00
|
|
|
_health_range = get_node(health_range_path) as Range
|
|
|
|
_health_text = get_node(health_text_path) as Label
|
2020-03-11 16:38:01 +01:00
|
|
|
_resource_range = get_node(resource_range_path) as Range
|
|
|
|
_resource_text = get_node(resource_text_path) as Label
|
2019-12-03 23:22:35 +01:00
|
|
|
_aura_grid = get_node(aura_grid_path) as GridContainer
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
func set_player(p_player : Entity) -> void:
|
2019-12-03 23:22:35 +01:00
|
|
|
if not _player == null and is_instance_valid(_player):
|
2020-04-29 01:10:10 +02:00
|
|
|
_player.getc_health().disconnect("changed", self, "_on_player_health_changed")
|
2020-04-28 11:46:56 +02:00
|
|
|
_player.disconnect("notification_caura", self, "on_notification_caura")
|
2020-04-28 19:09:06 +02:00
|
|
|
_player.disconnect("diecd", self, "diecd")
|
2020-03-11 16:38:01 +01:00
|
|
|
_player.disconnect("centity_resource_added", self, "centity_resource_added")
|
2020-08-03 21:58:38 +02:00
|
|
|
_player.disconnect("con_level_changed", self, "con_level_changed")
|
|
|
|
|
2020-03-11 16:38:01 +01:00
|
|
|
if _mana != null:
|
|
|
|
_mana.disconnect("changed", self, "_on_mana_changed")
|
|
|
|
_mana = null
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
for a in _aura_grid.get_children():
|
|
|
|
_aura_grid.remove_child(a)
|
2019-11-20 14:30:34 +01:00
|
|
|
a.queue_free();
|
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
_player = null
|
2019-11-20 14:30:34 +01:00
|
|
|
set_process(false)
|
|
|
|
|
|
|
|
if p_player == null:
|
|
|
|
hide()
|
|
|
|
return
|
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
_player = p_player
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
for index in range(_player.aura_getc_count()):
|
|
|
|
var aura : AuraData = _player.aura_getc(index)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-04-28 11:46:56 +02:00
|
|
|
on_notification_caura(SpellEnums.NOTIFICATION_AURA_ADDED, aura)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-04-28 11:46:56 +02:00
|
|
|
_player.connect("notification_caura", self, "on_notification_caura")
|
2020-04-28 19:09:06 +02:00
|
|
|
_player.connect("diecd", self, "diecd", [], CONNECT_DEFERRED)
|
2020-03-11 16:38:01 +01:00
|
|
|
_player.connect("centity_resource_added", self, "centity_resource_added")
|
2020-08-03 21:58:38 +02:00
|
|
|
_player.connect("con_level_changed", self, "con_level_changed")
|
2020-03-11 16:38:01 +01:00
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
for i in range(_player.resource_getc_count()):
|
|
|
|
centity_resource_added(_player.resource_getc_index(i))
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-06-20 16:15:24 +02:00
|
|
|
_health = _player.getc_health()
|
|
|
|
_on_player_health_changed()
|
|
|
|
_health.connect("changed", self, "_on_player_health_changed")
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
_name_text.text = _player.centity_name
|
2020-08-03 21:58:38 +02:00
|
|
|
_level_text.text = str(_player.clevel)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
set_process(true)
|
|
|
|
show()
|
2020-03-11 16:38:01 +01:00
|
|
|
|
|
|
|
func centity_resource_added(res : EntityResource):
|
|
|
|
if res is ManaResource:
|
2020-06-20 16:15:24 +02:00
|
|
|
_mana = res as ManaResource
|
2020-03-11 16:38:01 +01:00
|
|
|
_mana.connect("changed", self, "_on_mana_changed")
|
2020-06-20 16:15:24 +02:00
|
|
|
_on_mana_changed()
|
2020-03-11 16:38:01 +01:00
|
|
|
|
2020-06-20 16:15:24 +02:00
|
|
|
func _on_mana_changed() -> void:
|
|
|
|
if _mana.max_value == 0:
|
2020-03-11 16:38:01 +01:00
|
|
|
_resource_range.min_value = 0
|
|
|
|
_resource_range.max_value = 1
|
|
|
|
_resource_range.value = 0
|
|
|
|
|
|
|
|
_resource_text.text = ""
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
_resource_range.min_value = 0
|
2020-06-20 16:15:24 +02:00
|
|
|
_resource_range.max_value = _mana.max_value
|
|
|
|
_resource_range.value = _mana.current_value
|
2020-03-11 16:38:01 +01:00
|
|
|
|
2020-06-20 16:15:24 +02:00
|
|
|
_resource_text.text = str(_mana.current_value) + "/" + str(_mana.max_value)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-04-28 11:46:56 +02:00
|
|
|
func on_notification_caura(what : int, aura_data : AuraData) -> void:
|
|
|
|
if what == SpellEnums.NOTIFICATION_AURA_ADDED:
|
|
|
|
var created_node : Node = aura_entry_scene.instance()
|
|
|
|
|
|
|
|
_aura_grid.add_child(created_node)
|
|
|
|
created_node.owner = _aura_grid
|
|
|
|
|
|
|
|
created_node.set_aura_data(aura_data)
|
|
|
|
elif what == SpellEnums.NOTIFICATION_AURA_REMOVED:
|
|
|
|
for bn in _aura_grid.get_children():
|
|
|
|
if bn.get_aura_data() == aura_data:
|
|
|
|
_aura_grid.remove_child(bn)
|
|
|
|
bn.queue_free()
|
|
|
|
return
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-06-20 16:15:24 +02:00
|
|
|
func _on_player_health_changed() -> void:
|
|
|
|
if _health.max_value == 0:
|
2019-12-03 23:22:35 +01:00
|
|
|
_health_range.min_value = 0
|
|
|
|
_health_range.max_value = 1
|
|
|
|
_health_range.value = 0
|
|
|
|
|
|
|
|
_health_text.text = ""
|
|
|
|
|
2019-11-20 14:30:34 +01:00
|
|
|
return
|
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
_health_range.min_value = 0
|
2020-06-20 16:15:24 +02:00
|
|
|
_health_range.max_value = _health.max_value
|
|
|
|
_health_range.value = _health.current_value
|
2019-12-03 23:22:35 +01:00
|
|
|
|
2020-06-20 16:15:24 +02:00
|
|
|
_health_text.text = str(_health.current_value) + "/" + str(_health.max_value)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
func diecd(entity : Entity) -> void:
|
2019-11-20 14:30:34 +01:00
|
|
|
set_player(null)
|
2020-08-03 21:58:38 +02:00
|
|
|
|
|
|
|
func con_level_changed(entity: Entity, level: int):
|
|
|
|
_level_text.text = str(entity.clevel)
|