challenge-editor/scene/warehouse.gd
2024-10-10 18:09:32 +08:00

78 lines
2.1 KiB
GDScript

extends Control
signal close
const WAREHOUSE_CARD = preload("res://scene/warehouse_card.tscn")
const WAREHOUSE_TAB = preload("res://scene/warehouse_tab.tscn")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
var now_selected_type:int=-1
func fresh():
%item_panel.hide()
for i in %tab_add_pos.get_children():
i.queue_free()
for i in %card_add_pos.get_children():
i.queue_free()
var all_main_type=Database.get_all_main_type()
var type_all=WAREHOUSE_TAB.instantiate()
%tab_add_pos.add_child(type_all)
type_all.set_text("全部")
type_all.click.connect(type_click.bind(-1))
if now_selected_type<0:
type_all.selected=true
else:
type_all.selected=false
for i in all_main_type:
var new_tab=WAREHOUSE_TAB.instantiate()
%tab_add_pos.add_child(new_tab)
if i==now_selected_type:
new_tab.selected=true
else:
new_tab.selected=false
new_tab.set_text(Database.get_type_name(int(i)))
new_tab.click.connect(type_click.bind(int(i)))
var item=Global.get_all_item_game_data()
if now_selected_type<0:
for i in item.size():
var new_card=WAREHOUSE_CARD.instantiate()
%card_add_pos.add_child(new_card)
new_card.set_data(item[i])
new_card.item_index_in_all=i
new_card.click.connect(item_card_click.bind(i))
else:
for i in item.size():
if int(item[i]["type"])==now_selected_type:
var new_card=WAREHOUSE_CARD.instantiate()
%card_add_pos.add_child(new_card)
new_card.set_data(item[i])
new_card.item_index_in_all=i
new_card.click.connect(item_card_click.bind(i))
pass
pass
func type_click(type:int):
now_selected_type=type
fresh()
pass
func item_card_click(ind:int):
var item_data=Global.get_all_item_game_data()[ind]
%item_panel.show()
%name.text=ItemTool.get_name_from_item_data(item_data)
%introduction.text=ItemTool.get_introduction_from_item_data(item_data)
pass
func _on_back_pressed() -> void:
close.emit()
self.hide()
pass # Replace with function body.
func _on_empty_pressed() -> void:
%item_panel.hide()
pass # Replace with function body.