challenge-editor/scene/basic_message.gd
2024-09-11 17:44:37 +08:00

184 lines
5.3 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")
var data={
"character":{
"name":"角色名字",
"star":5,
"skin":[
{
"name":"皮肤1",
"card_face":"卡面图片路径",
"character":"角色图片路径"
}
],
"skin_now_use":0
},
"basic_mes":{
"script_category":"剧本类别",
"place":"地点",
"sex":0, #0为男1为女
"race":"种族",
"birthday":"xxxx-xx-xx",
"introduction":"这是一个介绍",
"basic_attribute":[
{
"name":"体质",
"value":100,
},
{
"name":"敏捷",
"value":100,
},
{
"name":"智力",
"value":100,
},
{
"name":"感知",
"value":100,
},
],
"fight_attribute":[
{
"name":"生命",
"value":100,
},
{
"name":"精神",
"value":100,
},
{
"name":"物理攻击",
"value":100,
},
{
"name":"法术强度",
"value":100,
},
]
},
"special":[
{
"name":"倾国倾城",
"introduction":"鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果"
}
],
"ability":[
{
"name":"武学 LV3",
"introduction":"鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果鼠标点击显示具体效果"
}
],
"favor":[{
"name":"姐姐",
"value":100
}
],
"reputation":[
{
"name":"某地区",
"value":100
}
]
}
@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
func init_from_data():
for i in %special_container.get_children():
i.queue_free()
for i in %ability_container.get_children():
i.queue_free()
if data.has("basic_mes"):
var basic_data=data["basic_mes"]
%category.text=basic_data["script_category"]
%place.text=basic_data["place"]
#缺少性别
%race.text=basic_data["race"]
%birthday.text=basic_data["birthday"]
%introduction.text=basic_data["introduction"]
var basic_attribute=basic_data["basic_attribute"]
var fight_attribute=basic_data["fight_attribute"]
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:
var new_attribute=ATTRIBUTE.instantiate()
new_attribute.data=i
%basic_attribute.add_child(new_attribute)
for i in fight_attribute:
var new_attribute=ATTRIBUTE.instantiate()
new_attribute.data=i
%fight_attribute.add_child(new_attribute)
pass
if data.has("special"):
var special_data=data["special"]
for i in special_data:
var new_button=ABILITY_BUTTON.instantiate()
new_button.show_mes=i["introduction"]
new_button.text=i["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)
if data.has("character"):
var character_data=data["character"]
%character_name.text=character_data["name"]
var star_arr=%star_container.get_children()
var star_num:int=character_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"]:
var new_label=Label.new()
new_label.text=i["name"]+":"+str(i["value"])
%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"]:
var new_label=Label.new()
new_label.text=i["name"]+":"+str(i["value"])
%reputation.add_child(new_label)
new_label.add_theme_font_size_override("font_size",26)
pass
func connect_button():
for i in button_group.size():
button_group[i].pressed.connect(selected.bind(i))
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:
init_from_data()
connect_button()