2019-11-20 14:05:35 +01:00
|
|
|
extends Control
|
|
|
|
|
2021-04-15 11:52:32 +02:00
|
|
|
# Copyright (c) 2019-2021 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:05:35 +01:00
|
|
|
|
|
|
|
export(PackedScene) var character_entry : PackedScene
|
|
|
|
export(NodePath) var menu_path : NodePath
|
|
|
|
export(NodePath) var name_imput_path : NodePath
|
|
|
|
export(NodePath) var container_path : NodePath
|
|
|
|
export(ButtonGroup) var character_creation_button_group : ButtonGroup
|
|
|
|
export(String) var character_folder : String
|
|
|
|
|
|
|
|
var container : Node
|
|
|
|
var name_line_edit : LineEdit
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
name_line_edit = get_node(name_imput_path)
|
|
|
|
container = get_node(container_path)
|
|
|
|
|
2020-03-19 21:15:07 +01:00
|
|
|
var profile : PlayerProfile = ProfileManager.getc_player_profile()
|
|
|
|
|
2019-11-20 14:05:35 +01:00
|
|
|
var fb : Button = null
|
|
|
|
|
2020-04-14 17:04:59 +02:00
|
|
|
for i in range(ESS.get_resource_db().get_entity_data_count()):
|
|
|
|
var d : EntityData = ESS.get_resource_db().get_entity_data_index(i)
|
|
|
|
|
|
|
|
if not d.is_playable:
|
|
|
|
continue
|
2019-11-20 14:05:35 +01:00
|
|
|
|
|
|
|
var ce : Button = character_entry.instance() as Button
|
|
|
|
|
|
|
|
if fb == null:
|
|
|
|
fb = ce
|
|
|
|
|
|
|
|
container.add_child(ce)
|
|
|
|
ce.owner = container
|
|
|
|
|
|
|
|
ce.id = d.id
|
2020-04-19 18:27:38 +02:00
|
|
|
var class_profile : ClassProfile = profile.get_class_profile(d.resource_path)
|
2020-03-20 03:32:44 +01:00
|
|
|
ce.set_class_name(d.entity_class_data.text_name, class_profile.level, class_profile)
|
2019-11-20 14:05:35 +01:00
|
|
|
ce.group = character_creation_button_group
|
|
|
|
|
|
|
|
if fb != null:
|
|
|
|
fb.pressed = true
|
2021-07-31 15:09:54 +02:00
|
|
|
|
|
|
|
connect("visibility_changed", self, "on_visibility_changed")
|
2019-11-20 14:05:35 +01:00
|
|
|
|
|
|
|
func create() -> void:
|
|
|
|
if name_line_edit.text == "":
|
|
|
|
return
|
|
|
|
|
|
|
|
var file_name : String = "user://" + character_folder + "/" + name_line_edit.text
|
|
|
|
|
|
|
|
var f : File = File.new()
|
|
|
|
|
|
|
|
if f.file_exists(file_name):
|
|
|
|
return
|
|
|
|
|
|
|
|
var active : BaseButton = character_creation_button_group.get_pressed_button()
|
|
|
|
|
|
|
|
var id : int = active.id
|
|
|
|
|
2020-04-18 14:35:28 +02:00
|
|
|
var ent : Entity = ESS.entity_spawner.spawn_player_for_menu(id, name_line_edit.text, self)
|
2019-11-20 14:05:35 +01:00
|
|
|
if f.open(file_name, File.WRITE) == OK:
|
|
|
|
f.store_string(to_json(ent.to_dict()))
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
ent.queue_free()
|
|
|
|
|
|
|
|
get_node(menu_path).switch_to_menu(Menu.StartMenuTypes.CHARACTER_SELECT)
|
|
|
|
|
2021-07-31 15:09:54 +02:00
|
|
|
func focus() -> void:
|
|
|
|
name_line_edit.grab_focus()
|
|
|
|
|
|
|
|
func on_visibility_changed():
|
|
|
|
if visible:
|
|
|
|
focus()
|