khanat-client/scenes/interfaces/creatures_menu/creatures_menu_ui.gd

55 lines
1.7 KiB
GDScript3
Raw Permalink Normal View History

2020-03-21 09:10:26 +00:00
extends Control
signal new_pressed( slot )
signal cancel_pressed
signal select_pressed( creature_filename )
var slots_number = 0
var slots = {}
func _ready():
2021-01-21 21:03:44 +00:00
var files = []
var directory = Directory.new()
if directory.dir_exists( "user://creatures/" ):
directory.open( "user://creatures/" )
directory.list_dir_begin()
while true:
var file = directory.get_next()
if file == "":
break
elif not file.begins_with( "." ) and not directory.current_is_dir():
files.append( file )
directory.list_dir_end()
for file in files:
var creature_box = preload( "res://scenes/interfaces/creatures_menu/creature_box.tscn" ).instance()
creature_box.get_node( "label" ).text = file
creature_box.slot = self.slots_number
creature_box.creature_filename = file
creature_box.connect( "select_pressed", self, "_on_creature_box_select_pressed" )
creature_box.connect( "delete_pressed", self, "_on_creature_box_delete_pressed" )
$screen_box/scroll_container/v_box_container/creatures_box.add_child( creature_box )
self.slots[ self.slots_number ] = creature_box
self.slots_number += 1
var creature = Creatures.Ra_old2.new()
creature.from_file( file )
creature_box.get_node( "label" ).text = creature.pseudonym
2020-03-21 09:10:26 +00:00
func _on_new_pressed():
2021-01-21 21:03:44 +00:00
emit_signal( "new_pressed", self.slots_number )
2020-03-21 09:10:26 +00:00
func _on_cancel_pressed():
2021-01-21 21:03:44 +00:00
emit_signal( "cancel_pressed" )
2020-03-21 09:10:26 +00:00
func _on_creature_box_select_pressed( slot ):
2021-01-21 21:03:44 +00:00
emit_signal( "select_pressed", self.slots[ slot ].creature_filename )
2020-03-21 09:10:26 +00:00
func _on_creature_box_delete_pressed( slot ):
2021-01-21 21:03:44 +00:00
if self.slots[ slot ].creature_filename:
var dir = Directory.new()
dir.remove( "user://creatures/" + self.slots[ slot ].creature_filename )
self.slots[ slot ].queue_free()