152 lines
3.6 KiB
GDScript
152 lines
3.6 KiB
GDScript
extends Node2D
|
|
|
|
var category
|
|
var item
|
|
|
|
var item_filter = ""
|
|
var config
|
|
var ini
|
|
var sheet
|
|
var sort = "alphabetically"
|
|
|
|
func _enter_tree() -> void:
|
|
ini = "res://02 - Configurations/" + category + ".ini"
|
|
%new_item_name.visible = false
|
|
%delete.visible = false
|
|
%item_name.visible = false
|
|
%save.visible = false
|
|
%new_item.text = "New " + category
|
|
%filter.placeholder_text = "Filter " + category
|
|
%new_item_name.placeholder_text = "Set " + category + " name"
|
|
%save.text = "Save " + category
|
|
#print(category)
|
|
list_items()
|
|
|
|
func _on_close_button_up() -> void:
|
|
queue_free()
|
|
|
|
func list_items() -> void:
|
|
config = ConfigFile.new()
|
|
config.load(ini)
|
|
print(ini)
|
|
var k = config.get_sections()
|
|
if sort == "alphabetically":
|
|
k.sort()
|
|
#print(str(k))
|
|
var i = 0
|
|
%list.item_count = k.size()
|
|
#print(str(%list.item_count))
|
|
for j in k:
|
|
if item_filter == "":
|
|
%list.set_item_text(i,str(j))
|
|
i = i+1
|
|
elif item_filter.to_lower() in j.to_lower():
|
|
%list.set_item_text(i,str(j))
|
|
i = i+1
|
|
#print(j)
|
|
else:
|
|
%list.item_count = %list.item_count -1
|
|
#print(str(%list.item_count))
|
|
|
|
|
|
func refresh_view():
|
|
%item_name.text = item
|
|
if item != "":
|
|
config = ConfigFile.new()
|
|
config.load(ini)
|
|
%save.visible = false
|
|
|
|
|
|
func _on_list_item_selected(index: int) -> void:
|
|
item = %list.get_item_text(index)
|
|
#print(%list.get_item_text(index))
|
|
%delete.text = "Delete " + %list.get_item_text(index)
|
|
%delete.visible = true
|
|
%item_name.visible = true
|
|
if sheet:
|
|
remove_child(sheet)
|
|
sheet = load("res://01 - Menus/03 - Sheets/item.tscn").instantiate()
|
|
sheet.item = item
|
|
sheet.category = category
|
|
sheet.position.x = 512
|
|
sheet.position.y = 256
|
|
add_child(sheet)
|
|
refresh_view()
|
|
|
|
|
|
func _on_filter_text_changed(new_text: String) -> void:
|
|
item_filter = new_text
|
|
#print(str(%list.get_selected_items()))
|
|
list_items()
|
|
if %list.item_count == 1:
|
|
%list.select(0)
|
|
else:
|
|
%list.select(0)
|
|
%list.deselect(0)
|
|
|
|
|
|
func _on_new_item_button_up() -> void:
|
|
%new_item_name.visible = true
|
|
%new_item_name.grab_focus()
|
|
|
|
|
|
func _on_new_item_name_text_submitted(new_text: String) -> void:
|
|
config = ConfigFile.new()
|
|
item = new_text
|
|
config.load(ini)
|
|
config.set_value(item,"type",category)
|
|
config.save(ini)
|
|
%new_item_name.text = ""
|
|
%new_item_name.visible = false
|
|
# sheet.save()
|
|
refresh_view()
|
|
list_items()
|
|
|
|
|
|
func _on_new_item_name_editing_toggled(toggled_on: bool) -> void:
|
|
if !toggled_on:
|
|
%new_item_name.text = ""
|
|
%new_item_name.visible = false
|
|
|
|
|
|
func _on_delete_button_up() -> void:
|
|
config = ConfigFile.new()
|
|
config.load(ini)
|
|
config.erase_section(item)
|
|
config.save(ini)
|
|
list_items()
|
|
item = ""
|
|
%delete.visible = false
|
|
%item_name.visible = false
|
|
remove_child(sheet)
|
|
refresh_view()
|
|
|
|
|
|
func _on_save_button_up() -> void:
|
|
sheet.save()
|
|
%save.visible = false
|
|
|
|
func show_save():
|
|
%save.visible = true
|
|
|
|
func set_menu_items(pixel_x,pixel_y,ui_scale):
|
|
%ui_background.size.y = pixel_y
|
|
%close.position.y = pixel_y - 96 * ui_scale
|
|
%new_item.position.y = pixel_y - 192 * ui_scale
|
|
%new_item_name.position.y = pixel_y - 192 * ui_scale
|
|
%delete.position.y = pixel_y - 286 * ui_scale
|
|
%filter.position.y = pixel_y - 384 * ui_scale
|
|
%list.position = (Vector2(128,128)) * ui_scale
|
|
%list.size.y = pixel_y/ui_scale - 620
|
|
if pixel_x < pixel_y: #mobile
|
|
%ui_background.size.x = pixel_x
|
|
for i in [%close,%new_item,%filter,%delete,%save,%new_item_name,%list]:
|
|
i.scale = Vector2(ui_scale,ui_scale)
|
|
i.size.x = pixel_x/ui_scale - 128
|
|
i.position.x = 64 * ui_scale
|
|
else:
|
|
%ui_background.size.x = 512.0 * ui_scale
|
|
for i in [%close,%new_item,%filter,%delete,%save,%new_item_name,%list]:
|
|
i.scale = Vector2(ui_scale,ui_scale)
|
|
i.size.x = 448
|
|
i.position.x = 32 * ui_scale
|