Files
imnotsick/screening_desk.gd
T
2025-06-16 01:12:48 +02:00

278 lines
8.9 KiB
GDScript

extends Control
@onready var panel_container = $Background/HBoxContainer/MarginContainer/VBoxContainer/FaceMarginContainer/PanelContainer
@onready var margin_container = $Background/HBoxContainer/MarginContainer/VBoxContainer/FaceMarginContainer/PanelContainer/MarginContainer
@onready var patient_file = $Background/HBoxContainer/MarginContainer/VBoxContainer/FaceMarginContainer/PanelContainer/MarginContainer/FileContainer/PatientFile
@onready var patient_file_title = $Background/HBoxContainer/MarginContainer/VBoxContainer/FaceMarginContainer/PanelContainer/MarginContainer/FileContainer/HBoxContainer/PatientFileTitle
@onready var patient_recording = $Background/HBoxContainer/MarginContainer/VBoxContainer/FaceMarginContainer/PanelContainer/MarginContainer/RecordingContainer/Recording
@onready var patient_recording_title = $Background/HBoxContainer/MarginContainer/VBoxContainer/FaceMarginContainer/PanelContainer/MarginContainer/RecordingContainer/HBoxContainer/RecordTitle
@onready var face_zoom = $Background/HBoxContainer/MarginContainer/VBoxContainer/FaceMarginContainer/FaceZoom
@onready var alone_controls = $Background/HBoxContainer/MarginContainer/VBoxContainer/ControlsMarginContainer/Alone
@onready var patient_controls = $Background/HBoxContainer/MarginContainer/VBoxContainer/ControlsMarginContainer/Patient
@onready var end_of_day_controls = $Background/HBoxContainer/MarginContainer/VBoxContainer/ControlsMarginContainer/EndOfDay
@onready var patient_texture = $Background/HBoxContainer/Desk/PatientTextureRect
@onready var patient_dialogue_resource: Resource
@onready var end_of_day_dialogue_resource = load("res://Dialogues/end_of_day.dialogue")
@onready var balloon: Node
@onready var patient_emotions : Dictionary
signal recovery_pressed
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#Connecting signals
alone_controls.get_node("PatientFile").pressed.connect(self._on_patient_file_pressed)
alone_controls.get_node("Guidebook").pressed.connect(self._on_guidebook_pressed)
alone_controls.get_node("CallNextPatient").pressed.connect(self._on_call_next_patient_pressed)
patient_controls.get_node("PatientFile").pressed.connect(self._on_patient_file_pressed)
patient_controls.get_node("Guidebook").pressed.connect(self._on_guidebook_pressed)
patient_controls.get_node("PatientRecording").pressed.connect(self._on_patient_recording_pressed)
patient_controls.get_node("Examine").pressed.connect(self._on_examine_pressed)
patient_controls.get_node("Containment").pressed.connect(self._on_containment_pressed)
patient_controls.get_node("PsychWard").pressed.connect(self._on_psych_ward_pressed)
end_of_day_controls.get_node("Recovery").pressed.connect(self._on_recovery_pressed)
#Hiding everything
self.hide()
#Hiding Top Right Panel
panel_container.hide()
for node in margin_container.get_children():
node.hide()
face_zoom.hide()
#Hiding Bottom Right Panel
alone_controls.hide()
patient_controls.hide()
end_of_day_controls.hide()
#Hiding Patient
patient_texture.hide()
#Sets Up New Patient
func new_patient(patient_id):
#Loading Patient Files
var file_path: String = "res://Dialogues/Patients/patient_" + patient_id + "_file.txt"
var file = FileAccess.open(file_path, FileAccess.READ)
var file_content = file.get_as_text()
patient_file.text = file_content
patient_file_title.text = "\nPATIENT FILE #" + patient_id
file.close()
#Loading Patient Recording
patient_recording.text = ""
patient_recording_title.text = "\nPATIENT RECORDING #" + patient_id
#Loading Patient Texture
file_path = "res://Art/Patients/patient_" + patient_id + "/patient_" + patient_id + "_full.png"
patient_texture.texture = load(file_path)
#Loading Face Emotions
var face: Resource
var emotion_branch: Dictionary
for emotion in ["neutral", "smiling", "angry", "scared", "sad"]:
file_path = "res://Art/Patients/patient_" + patient_id + "/patient_" + patient_id + "_" + emotion + ".png"
face = load(file_path)
if face != null:
emotion_branch = {emotion: face}
patient_emotions.merge(emotion_branch)
#Loading Default Face
face_zoom.texture = patient_emotions["neutral"]
#Loading Dialogue Resource
var dialogue_resource_path = "res://Dialogues/Patients/patient_" + patient_id + ".dialogue"
patient_dialogue_resource = load(dialogue_resource_path)
#Show patient file
func _on_patient_file_pressed():
for node in margin_container.get_children():
node.hide()
panel_container.show()
face_zoom.hide()
margin_container.get_node("FileContainer").show()
#Show guidebook
func _on_guidebook_pressed():
for node in margin_container.get_children():
node.hide()
panel_container.show()
face_zoom.hide()
margin_container.get_node("Rules").show()
#Brings in next patient
func _on_call_next_patient_pressed():
#Hiding and Showing appropriate scenes
var scenes_to_hide = [alone_controls, panel_container] + margin_container.get_children()
var scenes_to_show = [patient_controls,patient_texture,face_zoom]
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished
#Starting Dialogue
start_balloon(patient_dialogue_resource, "start")
#Shows patient recording
func _on_patient_recording_pressed():
for node in margin_container.get_children():
node.hide()
panel_container.show()
face_zoom.hide()
margin_container.get_node("RecordingContainer").show()
#Records the dialogues
func _recording_text(dialogue_line):
var line = dialogue_line.text
var character = dialogue_line.character
var character_colour : String
patient_recording.append_text("\n\n")
#Adjusting Character Colour
if character != "":
if character == "You":
character_colour = "[color=darkgreen]"
else :
character_colour = "[color=darkred]"
patient_recording.append_text(character_colour + character + "[/color]\n")
patient_recording.append_text(line)
#Show face zoom
func _on_examine_pressed():
for node in margin_container.get_children():
node.hide()
panel_container.hide()
face_zoom.show()
#Change emotions following dialogue tags
func _change_emotion(dialogue_line) -> void:
var line_tag = dialogue_line.tags
if line_tag.is_empty() == false:
var new_emotion = line_tag[0]
print("Emotion changed to ", new_emotion)
face_zoom.texture = patient_emotions[new_emotion]
func _on_containment_pressed():
#Ask for confirmation
var lambda = func(): clear_patient("containment")
var choice_text = "[center]Do you really want to send this patient to [color=darkred]Containment[/color] ?[/center]"
UI.ask_confirmation(lambda, Callable(), choice_text)
func _on_psych_ward_pressed():
#Ask for confirmation
var lambda = func(): clear_patient("psych_ward")
var choice_text = "[center]Do you really want to send this patient to the [color=darkgreen]Psych Ward[/color] ?[/center]"
UI.ask_confirmation(lambda, Callable(), choice_text)
#Starting dialogue
func start_balloon(dialogue_resource: Resource, start_title: String):
#Freeing Previous Balloon and Disconnecting DialogueManager signals
clean_balloon()
#Instantiating a custom balloon
var Balloon: Resource = load("res://Dialogues/balloon_small.tscn")
balloon = Balloon.instantiate()
get_tree().current_scene.add_child(balloon)
#Starting Dialogue and connecting DialogueManager signals
DialogueManager.got_dialogue.connect(_change_emotion)
DialogueManager.got_dialogue.connect(_recording_text)
balloon.start(dialogue_resource, start_title)
#Clears patient and transitions towards next patient or end of day
func clear_patient(choice:String):
#Hiding Patient Controls and showing Patient Face
patient_controls.hide()
_on_examine_pressed()
#Final Patient Dialogue
start_balloon(patient_dialogue_resource, choice)
await DialogueManager.dialogue_ended
#Transitioning
var scenes_to_hide = [patient_controls, patient_texture, face_zoom, panel_container] + margin_container.get_children()
var scenes_to_show:Array[Node]
Globals.patient_count += 1
if Globals.patient_count < Globals.daily_patient_limit:
scenes_to_show.append(alone_controls)
else:
scenes_to_show.append(end_of_day_controls)
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished
if Globals.patient_count < Globals.daily_patient_limit:
#Setting Up Next Patient
new_patient("564")
else:
Globals.patient_count = 1
#Starting End of Day Dialogue
var start_title = "end_of_day_" + str(Globals.day_count)
start_balloon(end_of_day_dialogue_resource, start_title)
func _on_recovery_pressed():
clean_balloon()
recovery_pressed.emit()
#Cleaning balloon
func clean_balloon():
#Freeing Previous Balloon and Disconnecting DialogueManager signals
if is_instance_valid(balloon):
balloon.queue_free()
if DialogueManager.is_connected("got_dialogue", _change_emotion):
DialogueManager.disconnect("got_dialogue", _change_emotion)
if DialogueManager.is_connected("got_dialogue", _recording_text):
DialogueManager.disconnect("got_dialogue", _recording_text)