feat: choice system
This commit is contained in:
90
dialogues/choice.gd
Normal file
90
dialogues/choice.gd
Normal file
@ -0,0 +1,90 @@
|
||||
extends Node
|
||||
|
||||
@onready var bubbles: HBoxContainer = %Bubbles
|
||||
@onready var bubbles_back: TileMapLayer = %BubblesBack
|
||||
@onready var bubbles_interior: TileMapLayer = %BubblesInterior
|
||||
@onready var bubble_label: RichTextLabel = %BubbleLabel
|
||||
|
||||
@onready var ui_flicker_timer: Timer = $UIFlickerTimer
|
||||
@onready var e_ui_button: TextureRect = %E
|
||||
@onready var next_label: Label = %NextLabel
|
||||
|
||||
@onready var choices_container: MarginContainer = %ChoicesContainer
|
||||
@onready var accept_indicator: ColorRect = %AcceptIndicator
|
||||
@onready var accept_label: Label = %AcceptLabel
|
||||
@onready var reject_indicator: ColorRect = %RejectIndicator
|
||||
@onready var reject_label: Label = %RejectLabel
|
||||
|
||||
@export_multiline var choice = ""
|
||||
@export var accept_option = ""
|
||||
@export var reject_option = ""
|
||||
|
||||
@onready var wait_a_sec: Timer = $WaitASec
|
||||
|
||||
signal accepted
|
||||
signal rejected
|
||||
|
||||
var is_accept_selected = true
|
||||
var is_choice_happening = false
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not is_choice_happening:
|
||||
return
|
||||
|
||||
if Input.is_action_just_pressed("move_right"):
|
||||
is_accept_selected = false
|
||||
update_ui()
|
||||
|
||||
if Input.is_action_just_pressed("move_left"):
|
||||
is_accept_selected = true
|
||||
update_ui()
|
||||
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
stop_choice()
|
||||
|
||||
|
||||
func update_ui():
|
||||
accept_indicator.visible = is_accept_selected
|
||||
reject_indicator.visible = not is_accept_selected
|
||||
|
||||
func toggle_ui():
|
||||
e_ui_button.visible = not e_ui_button.visible
|
||||
|
||||
func start_choice():
|
||||
bubbles.visible = true
|
||||
bubbles_back.visible = true
|
||||
bubbles_interior.visible = true
|
||||
bubble_label.visible = true
|
||||
e_ui_button.visible = true
|
||||
next_label.visible = true
|
||||
choices_container.visible = true
|
||||
|
||||
accept_label.text = accept_option
|
||||
reject_label.text = reject_option
|
||||
|
||||
is_accept_selected = true
|
||||
update_ui()
|
||||
|
||||
wait_a_sec.start()
|
||||
|
||||
func stop_choice():
|
||||
is_choice_happening = false
|
||||
|
||||
ui_flicker_timer.stop()
|
||||
|
||||
bubbles.visible = false
|
||||
bubbles_back.visible = false
|
||||
bubbles_interior.visible = false
|
||||
bubble_label.visible = false
|
||||
e_ui_button.visible = false
|
||||
next_label.visible = false
|
||||
choices_container.visible = false
|
||||
|
||||
if is_accept_selected:
|
||||
accepted.emit()
|
||||
else:
|
||||
rejected.emit()
|
||||
|
||||
func _on_wait_a_sec_timeout() -> void:
|
||||
is_choice_happening = true
|
||||
ui_flicker_timer.start()
|
1
dialogues/choice.gd.uid
Normal file
1
dialogues/choice.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://b65dvbdgyplnm
|
17
dialogues/choice.tscn
Normal file
17
dialogues/choice.tscn
Normal file
@ -0,0 +1,17 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c2axd06m2g28y"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b65dvbdgyplnm" path="res://dialogues/choice.gd" id="1_ht8c8"]
|
||||
|
||||
[node name="Choice" type="Node"]
|
||||
script = ExtResource("1_ht8c8")
|
||||
|
||||
[node name="UIFlickerTimer" type="Timer" parent="."]
|
||||
wait_time = 0.5
|
||||
ignore_time_scale = true
|
||||
|
||||
[node name="WaitASec" type="Timer" parent="."]
|
||||
wait_time = 0.5
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="UIFlickerTimer" to="." method="toggle_ui"]
|
||||
[connection signal="timeout" from="WaitASec" to="." method="_on_wait_a_sec_timeout"]
|
@ -13,7 +13,6 @@ extends Node
|
||||
@onready var e_ui_button: TextureRect = %E
|
||||
@onready var next_label: Label = %NextLabel
|
||||
|
||||
|
||||
@export_multiline var dialogue = ""
|
||||
@export var start_with_left = false
|
||||
@export var left_picture: Texture2D
|
||||
@ -31,7 +30,6 @@ func _ready() -> void:
|
||||
is_left_speaking = start_with_left
|
||||
left_speaker.texture = left_picture
|
||||
right_speaker.texture = right_picture
|
||||
display_profiles()
|
||||
|
||||
e_ui_button.visible = false
|
||||
next_label.visible = false
|
||||
@ -70,15 +68,18 @@ func load_next_dialogue():
|
||||
|
||||
func on_dialogue_started():
|
||||
bubbles.visible = true
|
||||
bubble_label.visible = true
|
||||
bubbles_back.visible = true
|
||||
bubbles_interior.visible = true
|
||||
|
||||
display_profiles()
|
||||
is_dialogue_ongoing = true
|
||||
time_between_letters.start()
|
||||
load_next_dialogue()
|
||||
|
||||
func end_dialogue():
|
||||
bubbles.visible = false
|
||||
bubble_label.visible = false
|
||||
bubbles_back.visible = false
|
||||
bubbles_interior.visible = false
|
||||
e_ui_button.visible = false
|
||||
|
Reference in New Issue
Block a user