2018-08-05 18:25:15 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
signal character_selected( slot )
|
|
|
|
signal return_button_pressed
|
|
|
|
|
|
|
|
func _ready():
|
2018-08-08 12:31:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
var config_file = ConfigFile.new()
|
|
|
|
var err = config_file.load( "user://player.cfg" )
|
|
|
|
if err:
|
|
|
|
print("Error code when loading player config file: ", err)
|
|
|
|
|
|
|
|
var last_slot = 0
|
|
|
|
for section in config_file.get_sections():
|
|
|
|
last_slot = int(section)
|
|
|
|
var character_name = config_file.get_value( section, "name" )
|
|
|
|
|
|
|
|
var slot_box = HBoxContainer.new()
|
|
|
|
slot_box.size_flags_horizontal = SIZE_FILL
|
|
|
|
slot_box.size_flags_vertical = SIZE_EXPAND
|
|
|
|
$h_box_container/character_slots.add_child( slot_box )
|
|
|
|
slot_box.set_owner( $h_box_container/character_slots )
|
|
|
|
|
|
|
|
var label_name = Label.new()
|
|
|
|
label_name.text = character_name
|
|
|
|
slot_box.add_child( label_name )
|
|
|
|
label_name.set_owner( slot_box )
|
|
|
|
|
|
|
|
var choose_button = Button.new()
|
|
|
|
choose_button.text = "choose"
|
|
|
|
slot_box.add_child( choose_button )
|
|
|
|
choose_button.set_owner( slot_box )
|
|
|
|
choose_button.connect( "pressed", self, "_on_choose_pressed", [int(section)] )
|
2018-08-08 12:55:50 +00:00
|
|
|
|
|
|
|
var delete_button = Button.new()
|
|
|
|
delete_button.text = "delete"
|
|
|
|
slot_box.add_child( delete_button )
|
|
|
|
delete_button.set_owner( slot_box )
|
|
|
|
delete_button.connect( "pressed", self, "_on_delete_pressed", [int(section), slot_box] )
|
2018-08-08 12:31:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
var create_new_characer_button = Button.new()
|
|
|
|
create_new_characer_button.text = "Create"
|
|
|
|
create_new_characer_button.hint_tooltip = "Create a new character"
|
|
|
|
$h_box_container/character_slots.add_child( create_new_characer_button )
|
|
|
|
create_new_characer_button.set_owner( $h_box_container/character_slots )
|
|
|
|
create_new_characer_button.connect( "pressed", self, "_on_choose_pressed", [int(last_slot)+1] )
|
2018-08-05 18:25:15 +00:00
|
|
|
|
2018-08-08 08:46:16 +00:00
|
|
|
func _on_return_button_pressed():
|
|
|
|
emit_signal( "return_button_pressed" )
|
|
|
|
|
2018-08-08 12:31:51 +00:00
|
|
|
func _on_choose_pressed( slot ):
|
|
|
|
emit_signal( "character_selected", slot )
|
2018-08-08 12:55:50 +00:00
|
|
|
func _on_delete_pressed( slot, node_to_delete ):
|
|
|
|
var config_file = ConfigFile.new()
|
|
|
|
var err = config_file.load( "user://player.cfg" )
|
|
|
|
if err:
|
|
|
|
print("Error code when loading player config file: ", err)
|
|
|
|
config_file.erase_section( str(slot) )
|
|
|
|
config_file.save( "user://player.cfg" )
|
2018-08-08 12:31:51 +00:00
|
|
|
|
2018-08-08 12:55:50 +00:00
|
|
|
var parent = node_to_delete.get_parent()
|
|
|
|
parent.remove_child( node_to_delete )
|
2018-08-08 12:31:51 +00:00
|
|
|
|
2018-08-05 18:25:15 +00:00
|
|
|
func _on_slot0_character_button_pressed():
|
2018-08-08 12:31:51 +00:00
|
|
|
emit_signal( "character_selected", 0 )
|
2018-08-08 08:46:16 +00:00
|
|
|
func _on_slot1_character_button_pressed():
|
|
|
|
emit_signal( "character_selected", 1 )
|
2018-08-05 18:25:15 +00:00
|
|
|
|
|
|
|
|
2018-08-05 19:36:20 +00:00
|
|
|
|
2018-08-08 08:46:16 +00:00
|
|
|
|
|
|
|
|