2019-11-20 14:30:34 +01:00
|
|
|
extends Container
|
|
|
|
|
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 (NodePath) var name_text_path : NodePath
|
|
|
|
export (NodePath) var level_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
|
2020-03-10 15:33:48 +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 xp_range_path : NodePath
|
|
|
|
|
|
|
|
var _name_text : Label
|
|
|
|
var _level_text : Label
|
|
|
|
var _health_range : Range
|
2019-12-03 23:22:35 +01:00
|
|
|
var _health_text : Label
|
2020-03-10 15:33:48 +01:00
|
|
|
var _resource_range : Range
|
|
|
|
var _resource_text : Label
|
2019-11-20 14:30:34 +01:00
|
|
|
var _xp_range : Range
|
|
|
|
|
|
|
|
var _player : Entity
|
|
|
|
|
2020-03-10 15:33:48 +01:00
|
|
|
var _mana : ManaResource
|
|
|
|
|
2019-11-20 14:30:34 +01:00
|
|
|
func _ready() -> void:
|
|
|
|
_name_text = get_node(name_text_path)
|
|
|
|
_level_text = get_node(level_text_path)
|
|
|
|
_health_range = get_node(health_range_path)
|
2019-12-03 23:22:35 +01:00
|
|
|
_health_text = get_node(health_text_path)
|
2020-03-10 15:33:48 +01:00
|
|
|
_resource_range = get_node(resource_range_path)
|
|
|
|
_resource_text = get_node(resource_text_path)
|
2019-11-20 14:30:34 +01:00
|
|
|
_xp_range = get_node(xp_range_path)
|
|
|
|
|
|
|
|
func set_player(p_player: Entity) -> void:
|
|
|
|
if not _player == null:
|
2020-04-29 01:10:10 +02:00
|
|
|
_player.getc_health().disconnect("changed", self, "_on_player_health_changed")
|
2019-11-20 14:30:34 +01:00
|
|
|
_player.disconnect("cname_changed", self, "cname_changed")
|
|
|
|
_player.disconnect("con_level_up", self, "clevel_changed")
|
|
|
|
_player.disconnect("con_level_changed", self, "clevel_changed")
|
2020-04-28 20:49:03 +02:00
|
|
|
_player.disconnect("notification_cxp_gained", self, "notification_cxp_gained")
|
2020-03-11 16:38:01 +01:00
|
|
|
_player.disconnect("centity_resource_added", self, "centity_resource_added")
|
|
|
|
|
|
|
|
if _mana != null:
|
|
|
|
_mana.disconnect("changed", self, "_on_mana_changed")
|
|
|
|
_mana = null
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
_player = null
|
|
|
|
|
|
|
|
if p_player == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
_player = p_player
|
|
|
|
|
|
|
|
_player.connect("cname_changed", self, "cname_changed")
|
2020-04-28 20:49:03 +02:00
|
|
|
_player.connect("notification_ccharacter_level_up", self, "clevel_changed")
|
2020-02-19 12:19:28 +01:00
|
|
|
_player.connect("con_character_level_changed", self, "clevel_changed")
|
2020-04-28 20:49:03 +02:00
|
|
|
_player.connect("notification_cxp_gained", self, "notification_cxp_gained")
|
2020-03-11 16:38:01 +01:00
|
|
|
_player.connect("centity_resource_added", self, "centity_resource_added")
|
2019-11-20 14:30:34 +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))
|
2020-03-10 15:33:48 +01:00
|
|
|
|
2020-04-29 01:10:10 +02:00
|
|
|
var health = _player.getc_health()
|
2019-11-20 14:30:34 +01:00
|
|
|
_on_player_health_changed(health)
|
2020-04-27 18:40:20 +02:00
|
|
|
health.connect("changed", self, "_on_player_health_changed")
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
_name_text.text = _player.centity_name
|
2020-02-20 12:21:31 +01:00
|
|
|
_level_text.text = str(_player.ccharacter_level)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
|
|
|
clevel_changed(_player, 0)
|
2020-04-28 20:49:03 +02:00
|
|
|
notification_cxp_gained(_player, 0)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-03-11 16:38:01 +01:00
|
|
|
func centity_resource_added(res : EntityResource):
|
|
|
|
if res is ManaResource:
|
|
|
|
_mana = res as ManaResource
|
|
|
|
|
|
|
|
_mana.connect("changed", self, "_on_mana_changed")
|
|
|
|
_on_mana_changed(_mana)
|
|
|
|
|
2020-04-27 18:40:20 +02:00
|
|
|
func _on_player_health_changed(health: EntityResource) -> void:
|
|
|
|
if health.max_value == 0:
|
2019-11-20 14:30:34 +01:00
|
|
|
_health_range.min_value = 0
|
|
|
|
_health_range.max_value = 1
|
|
|
|
_health_range.value = 0
|
2019-12-03 23:22:35 +01:00
|
|
|
|
|
|
|
_health_text.text = ""
|
|
|
|
|
2019-11-20 14:30:34 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
_health_range.min_value = 0
|
2020-04-27 18:40:20 +02:00
|
|
|
_health_range.max_value = health.max_value
|
|
|
|
_health_range.value = health.current_value
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-04-27 18:40:20 +02:00
|
|
|
_health_text.text = str(health.current_value) + "/" + str(health.max_value)
|
2019-12-03 23:22:35 +01:00
|
|
|
|
2020-03-10 15:33:48 +01:00
|
|
|
func _on_mana_changed(resource: EntityResource) -> void:
|
2020-03-11 16:38:01 +01:00
|
|
|
if resource.max_value == 0:
|
2020-03-10 15:33:48 +01:00
|
|
|
_resource_range.min_value = 0
|
|
|
|
_resource_range.max_value = 1
|
|
|
|
_resource_range.value = 0
|
|
|
|
|
2020-03-11 16:38:01 +01:00
|
|
|
_resource_text.text = ""
|
2020-03-10 15:33:48 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
_resource_range.min_value = 0
|
2020-03-11 16:38:01 +01:00
|
|
|
_resource_range.max_value = resource.max_value
|
|
|
|
_resource_range.value = resource.current_value
|
2020-03-10 15:33:48 +01:00
|
|
|
|
2020-03-11 16:38:01 +01:00
|
|
|
_resource_text.text = str(resource.current_value) + "/" + str(resource.max_value)
|
2020-03-10 15:33:48 +01:00
|
|
|
|
2019-11-20 14:30:34 +01:00
|
|
|
func cname_changed(entity: Entity) -> void:
|
|
|
|
_name_text.text = _player.centity_name
|
|
|
|
|
|
|
|
func clevel_changed(entity: Entity, value : int) -> void:
|
2020-02-20 12:21:31 +01:00
|
|
|
_level_text.text = str(_player.ccharacter_level)
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-06-15 15:23:47 +02:00
|
|
|
var xpreq : int = ESS.get_resource_db().get_xp_data().get_character_xp(_player.ccharacter_level)
|
|
|
|
|
|
|
|
if xpreq == 0:
|
|
|
|
_xp_range.value = 0
|
|
|
|
_xp_range.min_value = 0
|
|
|
|
_xp_range.max_value = 1
|
|
|
|
return
|
|
|
|
|
2019-11-20 14:30:34 +01:00
|
|
|
_xp_range.min_value = 0
|
2020-06-15 15:23:47 +02:00
|
|
|
_xp_range.max_value = xpreq
|
2019-11-20 14:30:34 +01:00
|
|
|
|
2020-04-28 20:49:03 +02:00
|
|
|
func notification_cxp_gained(entity: Entity, val: int) -> void:
|
2020-02-20 12:21:31 +01:00
|
|
|
_xp_range.value = _player.ccharacter_xp
|
2019-11-20 14:30:34 +01:00
|
|
|
|