2020-09-13 17:08:52 +02:00
|
|
|
extends Control
|
|
|
|
|
2021-04-15 11:52:32 +02:00
|
|
|
# Copyright (c) 2019-2021 Péter Magyar
|
2020-09-13 17:08:52 +02: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.
|
|
|
|
|
|
|
|
export(NodePath) var opener_button_path : NodePath
|
|
|
|
var opener_button : BaseButton
|
|
|
|
|
|
|
|
export(NodePath) var spell_entry_container_path : NodePath
|
|
|
|
export(NodePath) var prev_button_path : NodePath
|
|
|
|
export(NodePath) var next_button_path : NodePath
|
|
|
|
|
|
|
|
export(bool) var show_not_learned : bool = true
|
|
|
|
export(bool) var show_not_learnable : bool = false
|
|
|
|
|
|
|
|
var _spell_entry_container : Node
|
|
|
|
var _item_entries : Array
|
|
|
|
|
|
|
|
var _prev_button : Button
|
|
|
|
var _next_button : Button
|
|
|
|
|
|
|
|
var _player : Entity
|
2021-08-05 22:07:34 +02:00
|
|
|
var _vendor : Entity
|
2020-09-13 17:08:52 +02:00
|
|
|
|
|
|
|
var _page : int = 0
|
|
|
|
var _max_pages : int = 0
|
|
|
|
|
|
|
|
var _vendor_item_data : VendorItemData
|
|
|
|
|
2021-08-05 22:07:34 +02:00
|
|
|
var _timer : float = 0
|
|
|
|
|
2020-09-13 17:08:52 +02:00
|
|
|
func _ready() -> void:
|
|
|
|
opener_button = get_node_or_null(opener_button_path) as BaseButton
|
|
|
|
|
|
|
|
_item_entries.clear()
|
|
|
|
|
|
|
|
_spell_entry_container = get_node(spell_entry_container_path)
|
|
|
|
|
|
|
|
for i in range(_spell_entry_container.get_child_count()):
|
|
|
|
_item_entries.append(_spell_entry_container.get_child(i))
|
|
|
|
|
|
|
|
_prev_button = get_node(prev_button_path)
|
|
|
|
_next_button = get_node(next_button_path)
|
|
|
|
|
|
|
|
_prev_button.connect("pressed", self, "dec_page")
|
|
|
|
_next_button.connect("pressed", self, "inc_page")
|
|
|
|
|
|
|
|
connect("visibility_changed", self, "_visibility_changed")
|
2021-08-05 22:07:34 +02:00
|
|
|
|
|
|
|
set_process(false)
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
_timer += delta
|
|
|
|
|
|
|
|
if _timer > 1:
|
|
|
|
_timer = 0
|
|
|
|
|
|
|
|
if _player == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
var target : Entity = _player.getc_target()
|
|
|
|
|
|
|
|
if target != _vendor:
|
|
|
|
hide()
|
2021-08-05 23:01:31 +02:00
|
|
|
|
|
|
|
if !_player.isc_target_in_interact_range():
|
2021-08-05 22:07:34 +02:00
|
|
|
hide()
|
2020-09-13 17:08:52 +02:00
|
|
|
|
|
|
|
func inc_page() -> void:
|
|
|
|
if _vendor_item_data == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
_page += 1
|
|
|
|
|
|
|
|
if _page > _max_pages:
|
|
|
|
_page = _max_pages
|
|
|
|
|
|
|
|
refresh_entries()
|
|
|
|
|
|
|
|
func dec_page() -> void:
|
|
|
|
if _vendor_item_data == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
_page -= 1
|
|
|
|
|
|
|
|
if _page < 0:
|
|
|
|
_page = 0
|
|
|
|
|
|
|
|
refresh_entries()
|
|
|
|
|
|
|
|
func refresh_entries() -> void:
|
|
|
|
if _player == null || _vendor_item_data == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
var i : int = 0
|
|
|
|
var n : int = 0
|
|
|
|
# for n in range(len(_item_entries)):
|
|
|
|
while n < len(_item_entries):
|
|
|
|
var spindex : int = i + (_page * len(_item_entries))
|
|
|
|
|
|
|
|
if spindex >= _vendor_item_data.get_num_vendor_datas():
|
2020-09-15 01:18:00 +02:00
|
|
|
_item_entries[n].set_vendor_item(_player, null, 0)
|
2020-09-13 17:08:52 +02:00
|
|
|
i += 1
|
|
|
|
n += 1
|
|
|
|
continue
|
|
|
|
|
|
|
|
var vide : VendorItemDataEntry = _vendor_item_data.get_vendor_data(spindex)
|
|
|
|
|
|
|
|
if !vide:
|
|
|
|
continue
|
|
|
|
|
2020-09-15 01:18:00 +02:00
|
|
|
_item_entries[n].set_vendor_item(_player, vide, spindex)
|
2020-09-13 17:08:52 +02:00
|
|
|
i += 1
|
|
|
|
n += 1
|
|
|
|
|
|
|
|
|
|
|
|
func refresh_all() -> void:
|
|
|
|
if _player == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
if _vendor_item_data == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
_max_pages = int(_vendor_item_data.get_num_vendor_datas() / len(_item_entries))
|
|
|
|
|
|
|
|
if _page > _max_pages:
|
|
|
|
_page = _max_pages
|
|
|
|
|
|
|
|
refresh_entries()
|
|
|
|
|
|
|
|
|
|
|
|
func _visibility_changed() -> void:
|
|
|
|
if visible:
|
|
|
|
if !_player:
|
|
|
|
return
|
|
|
|
|
|
|
|
var t : Entity = _player.ctarget
|
|
|
|
|
|
|
|
if !t:
|
|
|
|
return
|
|
|
|
|
2020-10-18 18:07:24 +02:00
|
|
|
_vendor_item_data = t.getc_entity_data().entity_class_data.get_vendor_item_data()
|
2020-09-13 17:08:52 +02:00
|
|
|
|
|
|
|
_page = 0
|
|
|
|
refresh_all()
|
2021-08-05 22:07:34 +02:00
|
|
|
else:
|
|
|
|
_vendor = null
|
2020-09-13 17:08:52 +02:00
|
|
|
|
2021-08-05 22:07:34 +02:00
|
|
|
set_process(visible)
|
2020-09-13 17:08:52 +02:00
|
|
|
|
|
|
|
func set_player(p_player: Entity) -> void:
|
|
|
|
if _player != null:
|
|
|
|
_player.disconnect("onc_open_winow_request", self, "onc_open_winow_request")
|
|
|
|
|
|
|
|
_player = p_player
|
|
|
|
|
|
|
|
_player.connect("onc_open_winow_request", self, "onc_open_winow_request")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func onc_open_winow_request(window_id : int) -> void:
|
|
|
|
if window_id != EntityEnums.ENTITY_WINDOW_VENDOR:
|
|
|
|
return
|
|
|
|
|
2021-08-05 22:07:34 +02:00
|
|
|
_vendor = _player.getc_target()
|
|
|
|
|
2020-09-13 17:08:52 +02:00
|
|
|
show()
|
|
|
|
|
|
|
|
# if player.has_signal("player_moved") && !player.is_connected("player_moved", self, "on_player_moved"):
|
|
|
|
# player.connect("player_moved", self, "on_player_moved", [], CONNECT_ONESHOT)
|