add way of tracking scenes

This commit is contained in:
Robin Hübner 2018-09-21 03:48:13 +02:00
parent 2ae288a3d6
commit cd0ed4b891
7 changed files with 763 additions and 294 deletions

10
game.gd
View File

@ -41,6 +41,16 @@ const Characters = {
} }
} }
const Scenes = {
# MENUS
MAIN_MENU = "res://menus/main_menu.tscn",
# GAME
SCENE = "res://scene.tscn"
}
func _register_functions(): func _register_functions():
pass pass

View File

@ -7,6 +7,7 @@ onready var quit_btn = get_node("split/buttons/quit_btn")
func _ready(): func _ready():
# signals for buttens
start_btn.connect("pressed", self, "_on_start_pressed") start_btn.connect("pressed", self, "_on_start_pressed")
load_btn.connect("pressed", self, "_on_load_pressed") load_btn.connect("pressed", self, "_on_load_pressed")
options_btn.connect("pressed", self, "_on_options_pressed") options_btn.connect("pressed", self, "_on_options_pressed")
@ -14,7 +15,7 @@ func _ready():
func _on_start_pressed(): func _on_start_pressed():
pass SceneSwitcher.goto_scene(Game.Scenes.SCENE)
func _on_load_pressed(): func _on_load_pressed():
pass pass

View File

@ -2,7 +2,7 @@
[ext_resource path="res://menus/main_menu.gd" type="Script" id=1] [ext_resource path="res://menus/main_menu.gd" type="Script" id=1]
[node name="main_menu" type="Control"] [node name="main_menu" type="Control" index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -28,9 +28,9 @@ mouse_filter = 0
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
split_offset = 0 split_offset = -64
collapsed = false collapsed = false
dragger_visibility = 0 dragger_visibility = 1
[node name="title" type="Label" parent="split" index="0"] [node name="title" type="Label" parent="split" index="0"]
@ -38,9 +38,9 @@ anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_top = 140.0 margin_top = 108.0
margin_right = 1024.0 margin_right = 1024.0
margin_bottom = 154.0 margin_bottom = 122.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 2 mouse_filter = 2
@ -60,7 +60,7 @@ anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_top = 306.0 margin_top = 242.0
margin_right = 1024.0 margin_right = 1024.0
margin_bottom = 600.0 margin_bottom = 600.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )

View File

@ -11,7 +11,7 @@ config_version=3
[application] [application]
config/name="godot-vn" config/name="godot-vn"
run/main_scene="res://scene.tscn" run/main_scene="res://menus/main_menu.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[autoload] [autoload]

View File

@ -1,17 +1,10 @@
[gd_scene load_steps=5 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://scene.gd" type="Script" id=1] [ext_resource path="res://scene.gd" type="Script" id=1]
[ext_resource path="res://dialog_layer.gd" type="Script" id=2] [ext_resource path="res://dialog_layer.gd" type="Script" id=2]
[ext_resource path="res://dialog.gd" type="Script" id=3] [ext_resource path="res://ui/dialog_box.tscn" type="PackedScene" id=3]
[sub_resource type="StyleBoxEmpty" id=1] [node name="scene" type="Node2D"]
content_margin_left = -1.0
content_margin_right = -1.0
content_margin_top = -1.0
content_margin_bottom = -1.0
[node name="scene" type="Node2D" index="0"]
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -27,281 +20,6 @@ transform = Transform2D( 1, 0, 0, 1, 0, 0 )
script = ExtResource( 2 ) script = ExtResource( 2 )
dialog_path = "res://dialog/introduction.txt" dialog_path = "res://dialog/introduction.txt"
[node name="dialog_box" type="Control" parent="dialog_layer" index="0"] [node name="dialog_box" parent="dialog_layer" index="0" instance=ExtResource( 3 )]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
script = ExtResource( 3 )
[node name="audio_player" type="AudioStreamPlayer" parent="dialog_layer/dialog_box" index="0"]
stream = null
volume_db = 0.0
pitch_scale = 1.0
autoplay = false
mix_target = 0
bus = "Master"
[node name="top_panel" type="HBoxContainer" parent="dialog_layer/dialog_box" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 0.0
margin_top = 16.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 2
_sections_unfolded = [ "Margin", "Size Flags", "Theme", "custom_constants" ]
[node name="auto_btn" type="Button" parent="dialog_layer/dialog_box/top_panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 847.0
margin_right = 887.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_colors/font_color_disabled = Color( 0.378906, 0.378906, 0.378906, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_hover = Color( 1, 0.647059, 0, 1 )
custom_colors/font_color_pressed = Color( 1, 0.647059, 0, 1 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "auto"
flat = true
align = 1
_sections_unfolded = [ "custom_constants" ]
[node name="ffwd_btn" type="Button" parent="dialog_layer/dialog_box/top_panel" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 891.0
margin_right = 926.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_colors/font_color_disabled = Color( 0.378906, 0.378906, 0.378906, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_hover = Color( 1, 0.647059, 0, 1 )
custom_colors/font_color_pressed = Color( 1, 0.647059, 0, 1 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "fast"
flat = true
align = 1
[node name="menu_btn" type="Button" parent="dialog_layer/dialog_box/top_panel" index="2"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 930.0
margin_right = 1002.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_colors/font_color_disabled = Color( 0.378906, 0.378906, 0.378906, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_hover = Color( 1, 0.647059, 0, 1 )
custom_colors/font_color_pressed = Color( 1, 0.647059, 0, 1 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = " | menu"
flat = true
align = 1
[node name="spacing" type="Control" parent="dialog_layer/dialog_box/top_panel" index="3"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1006.0
margin_right = 1024.0
margin_bottom = 20.0
rect_min_size = Vector2( 18, 0 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
_sections_unfolded = [ "Rect" ]
[node name="body_container" type="PanelContainer" parent="dialog_layer/dialog_box" index="2"]
anchor_left = 0.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -100.0
grow_vertical = 0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_styles/panel = SubResource( 1 )
_sections_unfolded = [ "Grow Direction", "Mouse", "Size Flags", "custom_styles" ]
[node name="bottom_panel" type="VBoxContainer" parent="dialog_layer/dialog_box/body_container" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
margin_bottom = 100.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Grow Direction", "Mouse" ]
[node name="subject_margin" type="MarginContainer" parent="dialog_layer/dialog_box/body_container/bottom_panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_constants/margin_right = 0
custom_constants/margin_top = 0
custom_constants/margin_left = 4
custom_constants/margin_bottom = 0
_sections_unfolded = [ "Mouse", "custom_constants" ]
[node name="subject_panel" type="HBoxContainer" parent="dialog_layer/dialog_box/body_container/bottom_panel/subject_margin" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 4.0
margin_right = 1024.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Mouse" ]
[node name="subject_label" type="Label" parent="dialog_layer/dialog_box/body_container/bottom_panel/subject_margin/subject_panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 60.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Arborator"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Margin" ]
[node name="body_margin" type="MarginContainer" parent="dialog_layer/dialog_box/body_container/bottom_panel" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 18.0
margin_right = 1024.0
margin_bottom = 48.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_constants/margin_top = 8
custom_constants/margin_left = 8
custom_constants/margin_bottom = 8
_sections_unfolded = [ "Margin", "Mouse", "custom_constants" ]
[node name="body_label" type="Label" parent="dialog_layer/dialog_box/body_container/bottom_panel/body_margin" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 8.0
margin_top = 8.0
margin_right = 1024.0
margin_bottom = 22.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Sup new kid, you skippin?"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Margin", "Mouse", "Rect", "Size Flags" ]

450
ui/dialog_box.gd Normal file
View File

@ -0,0 +1,450 @@
extends Control
# load from dialog vm
const Dialog = preload("res://dialog_vm.gd")
const DialogController = preload("res://dialog_controller.gd")
# classes from there
const DialogSegment = Dialog.DialogSegment
const DialogWithSubjectSegment = Dialog.DialogWithSubjectSegment
const DialogWithSubjectExpressionSegment = Dialog.DialogWithSubjectExpressionSegment
const QuestionSegment = Dialog.QuestionSegment
const ChoiceSegment = Dialog.ChoiceSegment
const ChoiceWithJump = Dialog.ChoiceWithJump
const Choice = Dialog.Choice
const WaitSegment = Dialog.YieldCallSegment
# resources specific to this dialogy thingy
const DialogChoices = preload("res://ui/dialog_choices.tscn")
const DialogChoice = preload("res://ui/dialog_choice.tscn")
var IS_DEBUG = false
var current_dialog
var current_dialog_controller
# ui elements
onready var advance_button = get_node("top_panel/auto_btn")
onready var fastforward_button = get_node("top_panel/ffwd_btn")
onready var title_label = get_node("body_container/bottom_panel/subject_margin/subject_panel/subject_label")
onready var body_container = get_node("body_container")
onready var body_label = get_node("body_container/bottom_panel/body_margin/body_label")
# clickable regions, for accessibility
onready var top_panel = get_node("top_panel")
onready var audio_player = get_node("audio_player")
# params to set from outside
var dialog_path
# activeness
var active
# tween to fade in/out
var tween
# timer
var timer
# anim player, if any
var anim_player
# linkin in ur get_node relative to where you want
var get_node_fnc
# various main dialog related constants
# signals
signal entered_dialog
signal exited_frame
# character related signals
signal on_speaker_expression_changed(spkr, expr)
signal on_dialog_init(d)
signal on_dialog_completed(d)
# setters
func set_auto_advance(v):
current_dialog_controller.set_advance_state(v)
advance_button.pressed = v
# signals from dialog controller
func _on_printing_changed(v):
pass
# next_arrow.visible = v
func _on_reading_speed_changed(new_value):
current_dialog_controller.set_reading_speed(new_value)
func set_advance_state():
current_dialog_controller.set_advance_state(advance_button.is_pressed())
func set_fastforward_state():
var ffwd_pressed = fastforward_button.is_pressed()
current_dialog_controller.set_fastforward_state(fastforward_button.is_pressed())
advance_button.set_disabled(ffwd_pressed)
# init functions, must be called before use
func set_dialog_path(path):
dialog_path = path
func set_dialog_vm(vm):
current_dialog = vm
func set_dialog_controller(c):
current_dialog_controller = c
func set_dialog_anim_player(p):
anim_player = p
func set_get_character_function(fnc):
get_node_fnc = fnc
func _ready():
advance_button.connect("pressed", self, "set_advance_state")
fastforward_button.connect("pressed", self, "set_fastforward_state")
# clicking to advance
body_container.connect("gui_input", self, "_on_body_click")
top_panel.connect("gui_input", self, "_on_body_click")
Game.connect("on_reading_speed_changed", self, "_on_reading_speed_changed")
Game.connect("on_settings_enter", self, "_on_settings_enter")
Game.connect("on_settings_exit", self, "_on_settings_exit")
tween = Tween.new()
add_child(tween)
timer = Timer.new()
add_child(timer)
func _on_body_click(ev):
current_dialog_controller._on_body_click(is_active(), ev)
func _register_func(r, reg_name, func_name):
if r.has(reg_name):
r[reg_name].set_instance(self)
else:
r[reg_name] = funcref(self, func_name)
func _register_functions():
var r = current_dialog.get_local_registry()
# normal functions
_register_func(r, "SET_EXPR", "_set_expr_fnc")
_register_func(r, "FLIP", "_flip_char")
_register_func(r, "HIDE", "_hide_char")
_register_func(r, "SHOW", "_show_char")
# yieldy function
_register_func(r, "WAIT", "_wait_dialog_fnc")
# anim shite, also yieldy
_register_func(r, "PLAY_ANIM", "_play_anim_fnc")
# PLAY AND WAIT; HOW ABOUT DEM APPLES
_register_func(r, "PLAY_ANIM_WITH_WAIT", "_play_wait_with_anim_fnc")
func _play_wait_with_anim_fnc(args):
if args.size() == 2:
var anim_name = args[0]
var wait_time = float(args[1])
if anim_player:
anim_player.play(anim_name)
timer.one_shot = true
timer.wait_time = wait_time
timer.start()
return [timer, "timeout"]
func _play_anim_fnc(args):
if args.size() == 1:
var anim_name = args[0]
if anim_player:
anim_player.play(anim_name)
return [anim_player, "animation_finished"]
func _wait_dialog_fnc(args):
if args.size() == 1:
var time = float(args[0])
print("Dialog: waiting for: %f seconds" % time)
timer.wait_time = time
timer.one_shot = true
timer.start()
return [timer, "timeout"]
func _set_expr_fnc(args):
if args.size() == 2:
var speaker = args[0]
var expr = args[1]
_set_speaker_expression(speaker, expr)
func _show_char(args):
var char_name = args[0]
var character = get_node_fnc.call(char_name)
_do_show_char(character)
func _do_show_char(c):
tween.interpolate_property(
c, "modulate:a", c.modulate.a, 1.0,
1.0, Tween.TRANS_QUAD,
Tween.EASE_IN_OUT
)
tween.start()
func _hide_char(args):
var char_name = args[0]
var character = get_node_fnc.call(char_name)
_do_hide_char(character)
func _do_hide_char(c):
tween.interpolate_property(
c, "modulate:a", c.modulate.a, 0.0,
1.0, Tween.TRANS_QUAD,
Tween.EASE_IN_OUT
)
tween.start()
func _flip_char(args):
var char_name = args[0]
var character = get_node_fnc.call(char_name)
_do_flip_char(character)
func _do_flip_char(c):
c.flip_h = !c.flip_h
func _on_settings_enter(s):
if is_active():
visible = false
func _on_settings_exit(s):
if is_active():
visible = true
func reload_dialog():
initialize_dialog()
func get_local_registry():
return current_dialog.get_local_registry()
func initialize_dialog():
assert(dialog_path != null)
var dialog_file = File.new()
dialog_file.open(dialog_path, File.READ)
var text = dialog_file.get_as_text()
dialog_file.close()
var dialog = Dialog.dialog_from_text(text)
current_dialog = dialog
# also setup kv store for dialog variables
current_dialog.set_registry(Game.current_registry)
# set up controller too yes
current_dialog_controller = DialogController.new(dialog, audio_player)
# register functions
_register_functions()
# signals
current_dialog_controller.connect("on_update_dialog", self, "_on_update_dialog")
current_dialog_controller.connect("on_dialog_completed", self, "_on_dialog_completed")
current_dialog_controller.connect("on_printing_changed", self, "_on_printing_changed")
emit_signal("on_dialog_init", self)
func _on_dialog_completed(d):
emit_signal("on_dialog_completed", self)
exit_frame()
func _on_update_dialog(s):
_update_dialog(s)
func _fade_in():
var FADE_TIME = 1.0
tween.interpolate_property(
self,
"modulate:a", 0.0, 1.0, FADE_TIME,
Tween.TRANS_QUAD, Tween.EASE_IN
)
tween.start()
func _fade_out():
var FADE_TIME = 1.0
tween.interpolate_property(
self,
"modulate:a", 1.0, 0.0, FADE_TIME,
Tween.TRANS_QUAD, Tween.EASE_OUT
)
tween.start()
yield(tween, "tween_completed")
visible = false
func enter_frame():
_fade_in()
var r = Game.current_registry
r["IS_IN_DIALOG"] = true
# reload if is debug
if IS_DEBUG: reload_dialog()
active = true
visible = true
current_dialog.reset()
# next_arrow.visible = false
emit_signal("entered_dialog")
# dialogs
var first_segment = current_dialog.advance()
_update_dialog(first_segment)
func is_active():
return active
func exit_frame():
_fade_out()
# HACK: cludge to reset state
advance_button.set_pressed(false)
fastforward_button.set_pressed(false)
advance_button.emit_signal("pressed")
fastforward_button.emit_signal("pressed")
current_dialog_controller.reset()
active = false
var r = Game.current_registry
r["IS_IN_DIALOG"] = false
emit_signal("exited_frame")
func _set_speaker_subject(subject):
if Game.Characters.has(subject):
var data = Game.Characters[subject]
var subject_name = data.name
var subject_colour = data.name_colour
var subject_voice = data.voice
current_dialog_controller.chars_per_second = Game.DEFAULT_CHARS_PER_SECOND * data.talking_speed
_set_speaker_name(subject_name, subject_colour)
if subject_voice != null:
_set_speaker_voice(subject_voice)
else:
var subject_name = subject
current_dialog_controller.chars_per_second = Game.DEFAULT_CHARS_PER_SECOND
_set_speaker_name(subject_name, Color(1, 1, 1))
func _get_speaker_name():
return title_label.text
func _set_speaker_name(speaker_name, colour = Color(1, 1, 1)):
title_label.set_text(speaker_name)
title_label.modulate = colour
func _set_speaker_voice(voice_sample):
audio_player.stream = voice_sample
func _set_speaker_expression(speaker, expression):
emit_signal("on_speaker_expression_changed", speaker, expression)
# temporary maybe
func _setup_question(new_question):
body_container.add_child(new_question)
current_dialog_controller.waiting_for_answer = true
func _question_answered_yes(qs):
body_container.remove_child(qs)
current_dialog_controller.waiting_for_answer = false
current_dialog_controller._advance_dialog()
func _question_answered_no(qs):
body_container.remove_child(qs)
current_dialog_controller.waiting_for_answer = false
exit_frame()
func _choice_made(choice_modal, choice):
if IS_DEBUG: print("chose: ", choice.get_choice())
# Game.add_history_entry("you", choice.get_choice())
remove_child(choice_modal)
if choice is ChoiceWithJump:
# HACK: fix this later or make this unnecessary
var current_segment = current_dialog.jump(choice.target)
call_deferred("_update_dialog", current_segment)
else:
_update_dialog(choice)
current_dialog_controller.waiting_for_answer = false
# loop de loop
func _update_dialog(segment):
if segment is ChoiceSegment:
var choices = segment.get_choices()
# create new dialog choices and shit
var new_choices = DialogChoices.instance()
var vbox = new_choices.get_node("vbox")
for choice in choices:
var new_choice = DialogChoice.instance()
new_choice.text = choice.get_choice()
new_choice.connect("pressed", self, "_choice_made", [new_choices, choice])
vbox.add_child(new_choice)
add_child(new_choices)
elif segment is Choice:
var new_content = segment.get_response()
if typeof(new_content) == TYPE_OBJECT and (new_content is DialogWithSubjectSegment or new_content is DialogWithSubjectExpressionSegment):
_update_dialog(new_content)
else:
body_label.text = new_content
# Game.add_history_entry(_get_speaker_name(), new_content)
elif segment is DialogSegment or segment is DialogWithSubjectSegment or segment is DialogWithSubjectExpressionSegment:
var new_content = segment.get_content()
body_label.visible_characters = 0
body_label.text = new_content
if segment is DialogWithSubjectSegment:
_set_speaker_subject(segment.subject)
# Game.add_history_entry(_get_speaker_name(), new_content)
elif segment is DialogWithSubjectExpressionSegment:
_set_speaker_subject(segment.subject)
_set_speaker_expression(segment.subject, segment.expression)
# Game.add_history_entry("%s (%s)" % [_get_speaker_name(), segment.expression], new_content)
else:
pass
# Game.add_history_entry(_get_speaker_name(), new_content)
elif segment is WaitSegment:
var new_content = segment.get_content()
body_label.visible_characters = 0
body_label.text = new_content
# whatever subject you want during functions to wait on, animations and such
_set_speaker_subject("")
else:
print("encountered unknown segment: " + segment.get_content())
current_dialog_controller.update_logic_dialog(segment)
func _process(delta):
if is_active():
current_dialog_controller.tick(delta, body_label)

290
ui/dialog_box.tscn Normal file
View File

@ -0,0 +1,290 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://ui/dialog_box.gd" type="Script" id=1]
[sub_resource type="StyleBoxEmpty" id=1]
content_margin_left = -1.0
content_margin_right = -1.0
content_margin_top = -1.0
content_margin_bottom = -1.0
[node name="dialog_box" type="Control" index="0"]
editor/display_folded = true
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
script = ExtResource( 1 )
[node name="audio_player" type="AudioStreamPlayer" parent="." index="0"]
stream = null
volume_db = 0.0
pitch_scale = 1.0
autoplay = false
mix_target = 0
bus = "Master"
[node name="top_panel" type="HBoxContainer" parent="." index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 0.0
margin_top = 16.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 2
_sections_unfolded = [ "Margin", "Size Flags", "Theme", "custom_constants" ]
[node name="auto_btn" type="Button" parent="top_panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 847.0
margin_right = 887.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_colors/font_color_disabled = Color( 0.378906, 0.378906, 0.378906, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_hover = Color( 1, 0.647059, 0, 1 )
custom_colors/font_color_pressed = Color( 1, 0.647059, 0, 1 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "auto"
flat = true
align = 1
_sections_unfolded = [ "custom_constants" ]
[node name="ffwd_btn" type="Button" parent="top_panel" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 891.0
margin_right = 926.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_colors/font_color_disabled = Color( 0.378906, 0.378906, 0.378906, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_hover = Color( 1, 0.647059, 0, 1 )
custom_colors/font_color_pressed = Color( 1, 0.647059, 0, 1 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "fast"
flat = true
align = 1
[node name="menu_btn" type="Button" parent="top_panel" index="2"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 930.0
margin_right = 1002.0
margin_bottom = 20.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_colors/font_color_disabled = Color( 0.378906, 0.378906, 0.378906, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_color_hover = Color( 1, 0.647059, 0, 1 )
custom_colors/font_color_pressed = Color( 1, 0.647059, 0, 1 )
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = " | menu"
flat = true
align = 1
[node name="spacing" type="Control" parent="top_panel" index="3"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1006.0
margin_right = 1024.0
margin_bottom = 20.0
rect_min_size = Vector2( 18, 0 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
_sections_unfolded = [ "Rect" ]
[node name="body_container" type="PanelContainer" parent="." index="2"]
anchor_left = 0.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -100.0
grow_vertical = 0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_styles/panel = SubResource( 1 )
_sections_unfolded = [ "Grow Direction", "Mouse", "Size Flags", "custom_styles" ]
[node name="bottom_panel" type="VBoxContainer" parent="body_container" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
margin_bottom = 100.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Grow Direction", "Mouse" ]
[node name="subject_margin" type="MarginContainer" parent="body_container/bottom_panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1024.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_constants/margin_right = 0
custom_constants/margin_top = 0
custom_constants/margin_left = 4
custom_constants/margin_bottom = 0
_sections_unfolded = [ "Mouse", "custom_constants" ]
[node name="subject_panel" type="HBoxContainer" parent="body_container/bottom_panel/subject_margin" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 4.0
margin_right = 1024.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Mouse" ]
[node name="subject_label" type="Label" parent="body_container/bottom_panel/subject_margin/subject_panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 60.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Arborator"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Margin" ]
[node name="body_margin" type="MarginContainer" parent="body_container/bottom_panel" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 18.0
margin_right = 1024.0
margin_bottom = 48.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_constants/margin_top = 8
custom_constants/margin_left = 8
custom_constants/margin_bottom = 8
_sections_unfolded = [ "Margin", "Mouse", "custom_constants" ]
[node name="body_label" type="Label" parent="body_container/bottom_panel/body_margin" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 8.0
margin_top = 8.0
margin_right = 1024.0
margin_bottom = 22.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "Sup new kid, you skippin?"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Margin", "Mouse", "Rect", "Size Flags" ]