challenge-editor/scene/basic_message.gd
2024-11-08 00:44:27 +08:00

318 lines
11 KiB
GDScript

extends Control
const ABILITY_BUTTON = preload("res://scene/ability_button.tscn")
const ATTRIBUTE = preload("res://scene/attribute.tscn")
const SELECTED = preload("res://res/ui/ui_005_basic_message/selected.tres")
const BASIC_MES_SKIN_CARD = preload("res://scene/basic_mes_skin_card.tscn")
const START_CONFIG_MES = preload("res://scene/start_config_mes.tscn")
const BAG_SIDE_CARD = preload("res://scene/bag_side_card.tscn")
const SKILL_CONFIG_CARD_DOWN = preload("res://scene/skill_config_card_down.tscn")
const SKILL_CONFIG_CARD_UP = preload("res://scene/skill_config_card_up.tscn")
var data:Dictionary
##当前是在游戏外编辑还是在游戏内编辑
@export var is_in_game:bool=false
@onready var button_group:Array[Button]=[$VBoxContainer/TextureRect/HBoxContainer/Button, $VBoxContainer/TextureRect/HBoxContainer/Button2, $VBoxContainer/TextureRect/HBoxContainer/Button3, $VBoxContainer/TextureRect/HBoxContainer/Button4, $VBoxContainer/TextureRect/HBoxContainer/Button5, $VBoxContainer/TextureRect/HBoxContainer/Button6]
@onready var now_selected_button:Button=$VBoxContainer/TextureRect/HBoxContainer/Button
var now_character_use_equip_page:int=0
@onready var equipment_group=[%ornaments_equipment1, %ornaments_equipment2, %ornaments_equipment3,%ornaments_equipment4,%hand_equipment1,%hand_equipment2, %head_equipment, %body_equipment]
#面板关闭信号
signal close
var now_selected_mes:StartConfigMes
func init_from_data():
for i in equipment_group.size():
equipment_group[i].index=i
for i in %special_container.get_children():
i.queue_free()
for i in %ability_container.get_children():
i.queue_free()
%character.texture=Database.get_texture(CharacterTool.get_skin_now_use_data(data)["character"])
var basic_data=data["basic_mes"]
match int(basic_data["type"]):
0:
%category.text="历史"
1:
%category.text="奇幻"
2:
%category.text="现实"
3:
%category.text="末世"
%place.text=basic_data["place"]
#缺少性别
%race.text=basic_data["race"]
%birthday.text=basic_data["birthday"]
%introduction.text=basic_data["introduction"]
var basic_attribute:Dictionary=data["basic_attribute"]
var fight_attribute:Dictionary={}
if is_in_game:
fight_attribute=CharacterTool.cacul_fight_attribute(data)
for i in %basic_attribute.get_children():
i.queue_free()
for i in %fight_attribute.get_children():
i.queue_free()
for i in basic_attribute.keys():
var new_attribute=ATTRIBUTE.instantiate()
new_attribute.data={
"name":CharacterTool.get_name_by_attribute_key(i),
"value":basic_attribute[i]
}
%basic_attribute.add_child(new_attribute)
for i in fight_attribute.keys():
var new_attribute=ATTRIBUTE.instantiate()
new_attribute.data={
"name":CharacterTool.get_name_by_attribute_key(i),
"value":fight_attribute[i]
}
%fight_attribute.add_child(new_attribute)
pass
if data.has("special"):
var special_data=data["special"]
for i in special_data:
var charactr_special_data=Database.get_special_data(i)
if charactr_special_data==null:
continue
var new_button=ABILITY_BUTTON.instantiate()
new_button.show_mes=charactr_special_data["introduction"]
new_button.text=charactr_special_data["name"]
%special_container.add_child(new_button)
if data.has("ability"):
var ability_data=data["ability"]
for i in ability_data:
var new_button=ABILITY_BUTTON.instantiate()
new_button.show_mes=i["introduction"]
new_button.text=i["name"]
%ability_container.add_child(new_button)
%character_name.text=data["name"]
var star_arr=%star_container.get_children()
var star_num:int=data["star"]
for i in star_arr.size():
if i<star_num:
star_arr[i].show()
else:
star_arr[i].hide()
#关系
if data.has("favor"):
for i in %favor.get_children():
i.queue_free()
for i in data["favor"].keys():
var new_label=Label.new()
new_label.text=Database.get_npc_name(i)+":"+str(data["favor"][i])
%favor.add_child(new_label)
new_label.add_theme_font_size_override("font_size",26)
#声望
if data.has("reputation"):
for i in %reputation.get_children():
i.queue_free()
for i in data["reputation"].keys():
var new_label=Label.new()
new_label.text=i+":"+str(data["reputation"][i])
%reputation.add_child(new_label)
new_label.add_theme_font_size_override("font_size",26)
for i in %start_config_mes_add_pos.get_children():
i.queue_free()
##加载开局
var start_config_arr:Array=data["start"]
var start_now_use:int=data["start_now_use"]
var unclocked_start:Array=data["unclocked_start"]
for i in start_config_arr.size():
var new_start:StartConfigMes=START_CONFIG_MES.instantiate()
%start_config_mes_add_pos.add_child(new_start)
new_start.index=i
if i==start_now_use:
new_start.state=1
now_selected_mes=new_start
elif float(i) in unclocked_start:
new_start.state=0
else:
new_start.state=-1
new_start.set_data(start_config_arr[i])
new_start.click.connect(start_config_mes_click)
for i in %skin_card_add_pos.get_children():
i.queue_free()
var skin_data_arr:Array=data["skin"]
var skin_now_use:int=data["skin_now_use"]
var unlocked_skin=data["unlocked_skin"]
for i in skin_data_arr.size():
var new_skin_card:BasicMesSkinCard=BASIC_MES_SKIN_CARD.instantiate()
%skin_card_add_pos.add_child(new_skin_card)
new_skin_card.index=i
if i==skin_now_use:
new_skin_card.state=1
now_selected_skin_card=new_skin_card
elif float(i) in unlocked_skin:
new_skin_card.state=0
else:
new_skin_card.state=-1
new_skin_card.set_data(skin_data_arr[i])
new_skin_card.click.connect(skin_card_click)
#装备界面
if is_in_game:
for i in %bag_side_card_add_pos.get_children():
i.queue_free()
var bag_equip:Array=Global.get_all_equip_index_and_data_in_bag()
var ind_arr:Array=bag_equip[0]
var data_arr:Array=bag_equip[1]
for i in ind_arr.size():
var new_card=BAG_SIDE_CARD.instantiate()
new_card.equip_index=ind_arr[i]
%bag_side_card_add_pos.add_child(new_card)
new_card.set_data(data_arr[i])
pass
now_character_use_equip_page=Global.get_character_page_now_use()
var now_use_equip_data_arr=Global.get_now_character_equip_use()
for i in equipment_group.size():
equipment_group[i].page=now_character_use_equip_page
equipment_group[i].set_data(now_use_equip_data_arr[i])
#技能配置
if is_in_game:
for i in %skill_config_card_up_add_pos.get_children():
i.queue_free()
for i in %skill_config_card_down_add_pos.get_children():
i.queue_free()
var character_skill:Array=Global.get_now_character_skill()
var bag=Global.get_all_skill_index_and_data_in_bag()
var bag_index:Array=bag[0]
var bag_skill_data:Array=bag[1]
for i in character_skill.size():
var new_card=SKILL_CONFIG_CARD_UP.instantiate()
%skill_config_card_up_add_pos.add_child(new_card)
new_card.click.connect(card_up_click.bind(i))
new_card.set_data(character_skill[i])
for i in bag_skill_data.size():
var new_card=SKILL_CONFIG_CARD_DOWN.instantiate()
%skill_config_card_down_add_pos.add_child(new_card)
new_card.click.connect(card_down_click.bind(bag_index[i]))
new_card.set_data(bag_skill_data[i])
pass
pass
#角色装备技能被点击触发
func card_up_click(ind:int):
Global.remove_skill_card_ind_to_bag(ind)
fresh()
pass
#背包技能被点击触发
func card_down_click(ind:int):
Global.add_sill_card_from_bag_to_character(ind)
fresh()
pass
#开局按钮被点击触发
func start_config_mes_click(mes:StartConfigMes,ind:int):
now_selected_mes.state=0
mes.state=1
now_selected_mes=mes
#添加开局选择修饰
Database.add_character_embellich_data(data["id"],"start",ind)
data=Database.get_character_data(data["id"])
init_from_data()
pass
var now_selected_skin_card:BasicMesSkinCard
func connect_button():
for i in button_group.size():
button_group[i].pressed.connect(selected.bind(i))
#当第几个皮肤卡片被点击时
func skin_card_click(skin:BasicMesSkinCard,skin_index:int):
#添加皮肤修饰器
Database.add_character_embellich_data(data["id"],"skin",skin_index)
%character.texture=Database.get_texture(data["skin"][skin_index]["character"])
now_selected_skin_card.state=0
skin.state=1
now_selected_skin_card=skin
pass
func selected(ind:int):
if now_selected_button!=null:
var new_st=StyleBoxEmpty.new()
now_selected_button.add_theme_stylebox_override("normal",new_st)
now_selected_button.add_theme_stylebox_override("pressed",new_st)
now_selected_button.add_theme_stylebox_override("hover",new_st)
now_selected_button.add_theme_stylebox_override("hover_pressed",new_st)
now_selected_button=button_group[ind]
now_selected_button.add_theme_stylebox_override("normal",SELECTED)
now_selected_button.add_theme_stylebox_override("pressed",SELECTED)
now_selected_button.add_theme_stylebox_override("hover",SELECTED)
now_selected_button.add_theme_stylebox_override("hover_pressed",SELECTED)
%TabContainer.set_current_tab(ind)
pass
func _ready() -> void:
##向背包中添加物品
#Global.add_item_to_bag(Global.get_item_data("item_01"))
#Global.add_item_to_bag(Global.get_item_data("item_02"))
#Global.add_item_to_bag(Global.get_item_data("item_03"))
#Global.add_item_to_bag(Global.get_item_data("item_04"))
#Global.add_item_to_bag(Global.get_item_data("item_05"))
#Global.add_item_to_bag(Global.get_item_data("item_01"))
#Global.add_item_to_bag(Global.get_item_data("item_02"))
#Global.add_item_to_bag(Global.get_item_data("item_03"))
#Global.add_item_to_bag(Global.get_item_data("item_04"))
#Global.add_item_to_bag(Global.get_item_data("item_05"))
#Global.add_item_to_bag(Global.get_item_data("item_01"))
#Global.add_item_to_bag(Global.get_item_data("item_02"))
#Global.add_item_to_bag(Global.get_item_data("item_03"))
#Global.add_item_to_bag(Global.get_item_data("item_04"))
#Global.add_item_to_bag(Global.get_item_data("item_05"))
#Global.add_item_to_bag(Global.get_item_data("item_01"))
#Global.add_item_to_bag(Global.get_item_data("item_02"))
#Global.add_item_to_bag(Global.get_item_data("item_03"))
#Global.add_item_to_bag(Global.get_item_data("item_04"))
#Global.add_item_to_bag(Global.get_item_data("item_05"))
#Global.add_item_to_bag(Global.get_item_data("item_01"))
#Global.add_item_to_bag(Global.get_item_data("item_02"))
#Global.add_item_to_bag(Global.get_item_data("item_03"))
#Global.add_item_to_bag(Global.get_item_data("item_04"))
#Global.add_item_to_bag(Global.get_item_data("item_05"))
if is_in_game:
$VBoxContainer/TextureRect/HBoxContainer/Button6.hide()
$VBoxContainer/TextureRect/HBoxContainer/Button4.show()
$VBoxContainer/TextureRect/HBoxContainer/Button5.show()
else:
$VBoxContainer/TextureRect/HBoxContainer/Button6.show()
$VBoxContainer/TextureRect/HBoxContainer/Button4.hide()
$VBoxContainer/TextureRect/HBoxContainer/Button5.hide()
pass
for i in equipment_group:
i.fresh.connect(fresh)
#Global.set_now_character("test_character_01")
if is_in_game:
data=Global.get_now_character_data()
init_from_data()
connect_button()
func _on_back_button_pressed() -> void:
self.hide()
close.emit()
pass # Replace with function body.
#切换装备页按钮按下时
func _on_bag_tab_button_pressed(n: int) -> void:
Global.change_character_equip_now_use(n-1)
data=Global.get_now_character_data()
init_from_data()
pass # Replace with function body.
func fresh():
data=Global.get_now_character_data()
init_from_data()
pass