Skip to content

Commit

Permalink
dialog box added with text edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayantan0013 committed Jan 4, 2021
1 parent 43a61ec commit 9af661b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
14 changes: 10 additions & 4 deletions scenes/dialog.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://assets/dialogue_system/next.png" type="Texture" id=1]
[ext_resource path="res://scenes/DialogueLoader.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/dialogue_Ui/paper_hor.png" type="Texture" id=4]
[ext_resource path="res://scenes/dialogue_controller.gd" type="Script" id=5]

Expand Down Expand Up @@ -95,7 +94,14 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Tween" type="Tween" parent="DialogueSystem"]
[node name="TextEdit" type="TextEdit" parent="DialogueSystem/DialogBox/box"]
margin_left = 29.0
margin_top = 83.0
margin_right = 589.0
margin_bottom = 139.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="DialogueLoader" parent="DialogueSystem" instance=ExtResource( 3 )]
[node name="Tween" type="Tween" parent="DialogueSystem"]
[connection signal="button_down" from="DialogueSystem/DialogBox/box/Button" to="." method="_on_Button_button_down"]
49 changes: 36 additions & 13 deletions scenes/dialogue_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ func set_state(new_state: Dictionary) -> void:
state = new_state

func process_state(new_state: Dictionary) -> void:
speaker.text = new_state["character"]+ ":"
dialogue.text = new_state["text"]
tween.interpolate_property(dialogue, "visible_characters", 0, dialogue.text.length(), 0.08 * dialogue.text.length())
tween.start()
if new_state['type'] == 'assertive':
speaker.set_visible(true)
dialogue.set_visible(true)
$DialogueSystem/DialogBox/box/TextEdit.set_visible(false)
speaker.text = new_state["character"]+ ":"
dialogue.text = new_state["text"]
tween.interpolate_property(dialogue, "visible_characters", 0, dialogue.text.length(), 0.08 * dialogue.text.length())
tween.start()
elif new_state['type'] == 'user_input':
speaker.set_visible(false)
dialogue.set_visible(false)
$DialogueSystem/DialogBox/box/TextEdit.set_visible(true)



func _ready() -> void:
system.set_visible(false)
Expand All @@ -34,15 +44,28 @@ func _ready() -> void:
# process_state(state)

func _on_Button_button_down() -> void:
tween.stop(dialogue)
dialogue.visible_characters = dialogue.text.length()
index += 1
if index < loadedDialogue.size():
set_state(loadedDialogue[String(index)])
process_state(state)
else:
system.set_visible(false)
emit_signal("completed")
if state['type'] == 'assertive':
tween.stop(dialogue)
dialogue.visible_characters = dialogue.text.length()
index += 1
if index < loadedDialogue.size():
set_state(loadedDialogue[String(index)])
process_state(state)
else:
system.set_visible(false)
emit_signal("completed")
elif state['type'] == 'user_input':
if $DialogueSystem/DialogBox/box/TextEdit.text == state['text']:
index += 1
if index < loadedDialogue.size():
set_state(loadedDialogue[String(index)])
process_state(state)
else:
system.set_visible(false)
emit_signal("completed")
else :
$DialogueSystem/DialogBox/box/TextEdit.text = ''


func start() -> void:
loadedDialogue = DialogueLoader.load_dialogue()
Expand Down
2 changes: 1 addition & 1 deletion scenes/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func _ready():


func _on_initial_story_completed():
system_main.set_dialogue_file_path ("res://resources/dialogue/lesson1.json")
system_main.set_dialogue_file_path ("res://resources/dialogue/obj1.json")
system_main.start()

0 comments on commit 9af661b

Please sign in to comment.