challenge-editor/scene/select.gd

189 lines
6.2 KiB
GDScript3
Raw Normal View History

2024-09-10 14:55:19 +08:00
extends Control
2024-09-11 22:50:02 +08:00
var selected_button:Button
@onready var btn_group:Array[Button]=[]
signal enter_script(id:String)
signal continue_script
2024-09-18 17:57:10 +08:00
signal back
2024-09-10 16:40:42 +08:00
const SELECTED = preload("res://res/ui/ui_003_select/selected.tres")
const UNSELECTED = preload("res://res/ui/ui_003_select/unselected.tres")
2024-09-11 22:50:02 +08:00
const SELECT_BUTTON = preload("res://scene/select_button.tscn")
2024-09-10 14:55:19 +08:00
2024-09-11 22:50:02 +08:00
var data:Dictionary={
"history":[
],
"fantasy":[
],
"reality":[
],
"eschatological":[
],
2024-09-19 17:56:05 +08:00
2024-09-11 22:50:02 +08:00
}
var now_selected_script:String="history"
var now_selected_script_id:String
func _ready() -> void:
init_button_connection()
2024-09-19 12:04:52 +08:00
#generate_debug_data(20)
get_global_script_data()
2024-09-11 22:50:02 +08:00
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)
2024-10-04 18:08:33 +08:00
new_btn.set_texture(Database.get_texture(now_select_array[i]["side_texture"]))
2024-09-11 22:50:02 +08:00
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)
2024-09-10 14:55:19 +08:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func side_btn_clicked(ind:int):
2024-09-19 12:04:52 +08:00
if ind>=btn_group.size():
now_selected_script_id=""
return
2024-09-11 22:50:02 +08:00
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]
2024-10-04 18:08:33 +08:00
set_script_texture(Database.get_texture(now_select_array[ind]["texture"]))
2024-09-11 22:50:02 +08:00
%script_name.text=now_select_array[ind]["name"]
%script_introduction.text=now_select_array[ind]["introduction"]
now_selected_script_id=btn.id
2024-09-19 17:56:05 +08:00
2024-09-10 14:55:19 +08:00
pass
2024-09-19 12:04:52 +08:00
func get_global_script_data():
2024-10-04 18:08:33 +08:00
var glbdt=Database.get_all_script_data()
2024-09-19 12:04:52 +08:00
data["history"]=glbdt[0].values()
data["fantasy"]=glbdt[1].values()
data["reality"]=glbdt[2].values()
data["eschatological"]=glbdt[3].values()
2024-09-11 22:50:02 +08:00
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)
2024-10-04 18:08:33 +08:00
var script_data=Database.get_script_data(now_selected_script_id)
2024-09-26 11:49:53 +08:00
if script_data!=null:
Global.now_game_data["script_data"]=script_data
Global.set_now_scene(script_data["init_scene"])
2024-10-11 17:14:54 +08:00
Global.set_now_time(script_data["init_date"],script_data["finish_date"])
2024-09-26 11:49:53 +08:00
$DrawerContainer2.change_open(true)
pass # Replace with function body.
2024-09-11 22:50:02 +08:00
func _on_continue_button_pressed() -> void:
continue_script.emit()
2024-10-10 18:09:32 +08:00
%save_and_load.fresh()
%save_and_load.show()
2024-09-11 22:50:02 +08:00
pass # Replace with function body.
func _on_back_button_pressed() -> void:
2024-09-18 17:57:10 +08:00
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)
2024-09-11 22:50:02 +08:00
pass # Replace with function body.
2024-09-20 12:02:11 +08:00
func _on_difficulty_selection_select(ind: int) -> void:
$DrawerContainer.change_open(true)
2024-09-27 17:51:20 +08:00
%character_select.fresh()
2024-09-20 12:02:11 +08:00
pass # Replace with function body.
func _on_character_select_start_game(character_data: Dictionary) -> void:
pass # Replace with function body.
2024-10-10 18:09:32 +08:00
func _on_save_and_load_close() -> void:
%save_and_load.hide()
pass # Replace with function body.