challenge-editor/scene/event.gd

78 lines
2.6 KiB
GDScript3
Raw Normal View History

2024-09-19 12:04:52 +08:00
extends Control
const EVENT_CHOICE_BUTTON = preload("res://scene/event_choice_button.tscn")
@onready var choice_add_pos: VBoxContainer = $MarginContainer/NinePatchRect/VBoxContainer/VBoxContainer/choice_add_pos
@onready var event_texture: TextureRect = $MarginContainer/HBoxContainer/event_texture
@onready var event_intro: Label = $MarginContainer/NinePatchRect/VBoxContainer/event_intro
@onready var event_name: Label = $MarginContainer/NinePatchRect/TextureRect/event_name
2024-09-19 17:56:05 +08:00
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var audio_stream_player: AudioStreamPlayer = $AudioStreamPlayer
2024-09-19 12:04:52 +08:00
var data:Dictionary
2024-10-01 19:11:46 +08:00
var choice_data:Array=[]
2024-09-19 17:56:05 +08:00
var text_ratio_tween:Tween
2024-09-19 12:04:52 +08:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
#通过事件ID初始化界面
func set_event_data(id:String):
data=Global.get_event_data(id)
for i in choice_add_pos.get_children():
i.queue_free()
event_texture.texture=Global.get_texture(data["texture"])
event_intro.text=data["text"]
event_name.text=data["name"]
var choice_data=data["choice"]
2024-10-01 19:11:46 +08:00
self.choice_data=choice_data.duplicate(true)
2024-09-19 12:04:52 +08:00
for i in choice_data:
2024-10-01 19:11:46 +08:00
var enable:bool=true
if i.has("condition"):
var condition_data:Array=i["condition"]
for j in condition_data:
enable=enable and Global.call_condition_triger(j["type"],j["data"])
pass
print(enable)
2024-09-19 12:04:52 +08:00
var new_btn=EVENT_CHOICE_BUTTON.instantiate()
choice_add_pos.add_child(new_btn)
new_btn.set_data(i)
2024-09-19 17:56:05 +08:00
new_btn.click.connect(choice_click)
2024-10-01 19:11:46 +08:00
new_btn.set_disable(not enable)
2024-09-19 17:56:05 +08:00
animation_player.play("open")
func choice_click(event_data:Dictionary):
2024-09-20 20:20:14 +08:00
if not event_data.has("triger"):
return
2024-09-19 17:56:05 +08:00
for i in event_data["triger"]:
2024-09-22 11:48:18 +08:00
Global.call_triger(i["type"],i["data"])
2024-09-19 17:56:05 +08:00
pass
2024-10-01 19:11:46 +08:00
change_choice(self.choice_data)
2024-09-19 17:56:05 +08:00
pass
2024-09-22 11:48:18 +08:00
func change_texture(texture_id:String):
event_texture.texture=Global.get_texture(texture_id)
func change_text(text:String):
event_intro.text=text
func change_choice(choice_data:Array):
for i in choice_add_pos.get_children():
i.queue_free()
2024-10-01 19:11:46 +08:00
self.choice_data=choice_data.duplicate(true)
2024-09-22 11:48:18 +08:00
for i in choice_data:
2024-10-01 19:11:46 +08:00
var enable:bool=true
if i.has("condition"):
var condition_data:Array=i["condition"]
for j in condition_data:
enable=enable and Global.call_condition_triger(j["type"],j["data"])
print(enable)
2024-09-22 11:48:18 +08:00
var new_btn=EVENT_CHOICE_BUTTON.instantiate()
choice_add_pos.add_child(new_btn)
new_btn.set_data(i)
new_btn.click.connect(choice_click)
2024-10-01 19:11:46 +08:00
new_btn.set_disable(not enable)
2024-09-22 11:48:18 +08:00
pass