challenge-editor/scene/select.gd
2024-09-27 17:51:20 +08:00

181 lines
6.0 KiB
GDScript

extends Control
var selected_button:Button
@onready var btn_group:Array[Button]=[]
signal enter_script(id:String)
signal continue_script
signal back
const SELECTED = preload("res://res/ui/ui_003_select/selected.tres")
const UNSELECTED = preload("res://res/ui/ui_003_select/unselected.tres")
const SELECT_BUTTON = preload("res://scene/select_button.tscn")
var data:Dictionary={
"history":[
],
"fantasy":[
],
"reality":[
],
"eschatological":[
],
}
var now_selected_script:String="history"
var now_selected_script_id:String
func _ready() -> void:
init_button_connection()
#generate_debug_data(20)
get_global_script_data()
load_now_script()
func load_now_script():
btn_group.clear()
for i in %btn_add_pos.get_children():
i.queue_free()
var now_select_array:Array=data[now_selected_script]
for i in now_select_array.size():
var new_btn=SELECT_BUTTON.instantiate()
new_btn.id=now_select_array[i]["id"]
%btn_add_pos.add_child(new_btn)
new_btn.set_texture(Global.get_texture(now_select_array[i]["side_texture"]))
new_btn.pressed.connect(side_btn_clicked.bind(i))
btn_group.append(new_btn)
side_btn_clicked(0)
%btn_scroll.set_deferred("scroll_vertical", 0)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func side_btn_clicked(ind:int):
if ind>=btn_group.size():
now_selected_script_id=""
return
var btn=btn_group[ind]
if btn!=selected_button:
if selected_button!=null:
selected_button.is_selected=false
btn.is_selected=true
selected_button=btn
var now_select_array:Array=data[now_selected_script]
set_script_texture(Global.get_texture(now_select_array[ind]["texture"]))
%script_name.text=now_select_array[ind]["name"]
%script_introduction.text=now_select_array[ind]["introduction"]
now_selected_script_id=btn.id
pass
func get_global_script_data():
var glbdt=Global.get_all_script_data()
data["history"]=glbdt[0].values()
data["fantasy"]=glbdt[1].values()
data["reality"]=glbdt[2].values()
data["eschatological"]=glbdt[3].values()
func generate_debug_data(debug_size:int):
var arr=[[],[],[],[]]
for i in debug_size:
arr[0].append({
"name":"历史测试剧本"+str(i),
"id":"history"+str(i),
"introduction":"历史测试剧本"+str(i)+"介绍测试",
"btn_texture":"res://res/ui/ui_003_select/test.png",
"texture":"res://res/ui/ui_003_select/test.png"
})
arr[1].append({
"name":"奇幻测试剧本"+str(i),
"id":"fantasy"+str(i),
"introduction":"奇幻测试剧本"+str(i)+"介绍测试",
"btn_texture":"res://res/ui/ui_003_select/test.png",
"texture":"res://res/ui/ui_003_select/test.png"
})
arr[2].append({
"name":"现实测试剧本"+str(i),
"id":"reality"+str(i),
"introduction":"现实测试剧本"+str(i)+"介绍测试",
"btn_texture":"res://res/ui/ui_003_select/test.png",
"texture":"res://res/ui/ui_003_select/test.png"
})
arr[3].append({
"name":"末世测试剧本"+str(i),
"id":"eschatological"+str(i),
"introduction":"末世测试剧本"+str(i)+"介绍测试",
"btn_texture":"res://res/ui/ui_003_select/test.png",
"texture":"res://res/ui/ui_003_select/test.png"
})
data={
"history":arr[0],
"fantasy":arr[1],
"reality":arr[2],
"eschatological":arr[3],
}
func set_script_texture(texture:Texture2D):
%script_texture.texture=texture
%texture_animation.stop()
%texture_animation.play("open")
func on_button_down(texture:Control) -> void:
texture.modulate=Color(0.5,0.5,0.5,1)
pass # Replace with function body.
func on_button_up(texture:Control) -> void:
texture.modulate=Color(1,1,1,1)
pass # Replace with function body.
func bottom_button_pressed(script_name:String):
if now_selected_script!=script_name:
now_selected_script=script_name
load_now_script()
func init_button_connection():
%history_button.button_down.connect(on_button_down.bind(%history_texture))
%fantasy_button.button_down.connect(on_button_down.bind(%fantasy_texture))
%reality_button.button_down.connect(on_button_down.bind(%reality_texture))
%eschatological_button.button_down.connect(on_button_down.bind(%eschatological_texture))
%continue_button.button_down.connect(on_button_down.bind(%continue_texture))
%history_button.button_up.connect(on_button_up.bind(%history_texture))
%fantasy_button.button_up.connect(on_button_up.bind(%fantasy_texture))
%reality_button.button_up.connect(on_button_up.bind(%reality_texture))
%eschatological_button.button_up.connect(on_button_up.bind(%eschatological_texture))
%continue_button.button_up.connect(on_button_up.bind(%continue_texture))
%history_button.pressed.connect(bottom_button_pressed.bind("history"))
%fantasy_button.pressed.connect(bottom_button_pressed.bind("fantasy"))
%reality_button.pressed.connect(bottom_button_pressed.bind("reality"))
%eschatological_button.pressed.connect(bottom_button_pressed.bind("eschatological"))
%enter_button.button_down.connect(on_button_down.bind(%enter_texture))
%enter_button.button_up.connect(on_button_up.bind(%enter_texture))
func _on_enter_button_pressed() -> void:
enter_script.emit(now_selected_script_id)
var script_data=Global.get_script_data(now_selected_script_id)
if script_data!=null:
Global.now_game_data["script_data"]=script_data
Global.set_now_scene(script_data["init_scene"])
$DrawerContainer2.change_open(true)
pass # Replace with function body.
func _on_continue_button_pressed() -> void:
continue_script.emit()
pass # Replace with function body.
func _on_back_button_pressed() -> void:
back.emit()
pass # Replace with function body.
func _on_character_select_back() -> void:
$DrawerContainer.change_open(false)
pass # Replace with function body.
func _on_difficulty_selection_back() -> void:
$DrawerContainer2.change_open(false)
pass # Replace with function body.
func _on_difficulty_selection_select(ind: int) -> void:
$DrawerContainer.change_open(true)
%character_select.fresh()
pass # Replace with function body.
func _on_character_select_start_game(character_data: Dictionary) -> void:
pass # Replace with function body.