146 lines
4.9 KiB
GDScript
146 lines
4.9 KiB
GDScript
extends Control
|
|
var selected_button:Button
|
|
@onready var btn_group:Array[Button]=[]
|
|
|
|
signal enter_script(id:String)
|
|
signal continue_script
|
|
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":[
|
|
|
|
],
|
|
"continue":{
|
|
|
|
}
|
|
}
|
|
var now_selected_script:String="history"
|
|
var now_selected_script_id:String
|
|
func _ready() -> void:
|
|
init_button_connection()
|
|
generate_debug_data(20)
|
|
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(load(now_select_array[i]["btn_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):
|
|
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(load(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
|
|
print(btn.id)
|
|
pass
|
|
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)
|
|
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:
|
|
pass # Replace with function body.
|