2019-11-20 14:30:34 +01:00
|
|
|
extends UnitFrame
|
|
|
|
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# 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 (PackedScene) var aura_entry_scene : PackedScene
|
|
|
|
|
|
|
|
export (NodePath) var name_text_path : NodePath
|
|
|
|
export (NodePath) var health_range_path : NodePath
|
2019-12-03 23:22:35 +01:00
|
|
|
export (NodePath) var health_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
|
|
|
|
var _health_range : Range
|
|
|
|
var _health_text : Label
|
|
|
|
var _aura_grid : GridContainer
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
var _player : Entity
|
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
|
|
|
|
_health_range = get_node(health_range_path) as Range
|
|
|
|
_health_text = get_node(health_text_path) as Label
|
|
|
|
_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):
|
|
|
|
_player.get_health().disconnect("c_changed", self, "_on_player_health_changed")
|
|
|
|
_player.disconnect("caura_added", self, "on_caura_added")
|
|
|
|
_player.disconnect("caura_removed", self, "on_caura_removed")
|
|
|
|
_player.disconnect("cdied", self, "cdied")
|
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
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
for index in range(_player.cget_aura_count()):
|
|
|
|
var aura : AuraData = _player.cget_aura(index)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
on_caura_added(aura)
|
|
|
|
|
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
_player.connect("caura_added", self, "on_caura_added")
|
|
|
|
_player.connect("caura_removed", self, "on_caura_removed")
|
|
|
|
_player.connect("cdied", self, "cdied")
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
var health = _player.get_health()
|
2019-11-20 14:30:34 +01:00
|
|
|
_on_player_health_changed(health)
|
|
|
|
health.connect("c_changed", self, "_on_player_health_changed")
|
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
_name_text.text = _player.centity_name
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
set_process(true)
|
|
|
|
show()
|
|
|
|
|
|
|
|
func on_caura_added(aura_data : AuraData) -> void:
|
|
|
|
var created_node : Node = aura_entry_scene.instance()
|
|
|
|
|
2019-12-03 23:22:35 +01:00
|
|
|
_aura_grid.add_child(created_node)
|
|
|
|
created_node.owner = _aura_grid
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
created_node.set_aura_data(aura_data)
|
|
|
|
|
|
|
|
func on_caura_removed(aura_data : AuraData) -> void:
|
2019-12-03 23:22:35 +01:00
|
|
|
for bn in _aura_grid.get_children():
|
2019-11-20 14:30:34 +01:00
|
|
|
if bn.get_aura_data() == aura_data:
|
2019-12-03 23:22:35 +01:00
|
|
|
_aura_grid.remove_child(bn)
|
2019-11-20 14:30:34 +01:00
|
|
|
bn.queue_free()
|
|
|
|
return
|
|
|
|
|
|
|
|
func _on_player_health_changed(health : Stat) -> void:
|
|
|
|
if health.cmax == 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
|
|
|
|
_health_range.max_value = health.cmax
|
|
|
|
_health_range.value = health.ccurrent
|
|
|
|
|
|
|
|
_health_text.text = str(health.ccurrent) + "/" + str(health.cmax)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
func cdied(entity : Entity) -> void:
|
|
|
|
set_player(null)
|