Bladeren bron

Add choice buttons ; Run async using yield

master
Non0w 4 jaren geleden
bovenliggende
commit
00a186093b
10 gewijzigde bestanden met toevoegingen van 95 en 80 verwijderingen
  1. +10
    -8
      addons/yarn_spinner/yarn_runner.gd
  2. +0
    -5
      addons/yarn_spinner/yarn_spinner_importer.gd
  3. +13
    -0
      main/scenes/ChoicesBox.tscn
  4. +34
    -0
      main/scenes/LogPanel.tscn
  5. +9
    -3
      main/scenes/test_viteuf.tscn
  6. +1
    -1
      main/scripts/ChoicesBox.gd
  7. +0
    -0
      main/scripts/LogPanel.gd
  8. +22
    -18
      main/scripts/test_viteuf.gd
  9. +2
    -2
      project.godot
  10. +4
    -43
      yarn/scenes/YarnSpinner.tscn

+ 10
- 8
addons/yarn_spinner/yarn_runner.gd Bestand weergeven

@@ -5,12 +5,13 @@ var YarnScript = preload("yarn_script.gd")
export (Resource) var yarnScript

var say_func : FuncRef = null
var choices_func : FuncRef = null

func run_all():
var next_node = yarnScript.nodes["Start"]
while next_node != null:
print("-> Jump to " + next_node["title"])
var next_node_key = run_body(next_node["body"])
var next_node_key = yield(run_body(next_node["body"]), "completed")
if (yarnScript.nodes.has(next_node_key)):
next_node = yarnScript.nodes[next_node_key]
else:
@@ -21,25 +22,26 @@ func run_body(body):
if element["type"] == "jump":
return element["node"]
elif element["type"] == "choice_blocks":
var block = decide_choice_block(element["blocks"])
var block = yield(decide_choice_block(element["blocks"]), "completed")
print(block)
return block["node"] # todo change later with "-> choices"
elif element["type"] == "condition_blocks":
var block = decide_condition_block(element["blocks"])
var next_node_key = run_body(block["body"])
var next_node_key = yield(run_body(block["body"]), "completed")
if next_node_key != "":
return next_node_key
else:
if say_func == null or !say_func.is_valid():
print(element)
else:
say_func.call_func(element)
yield(say_func.call_func(element), "completed")
return ""

export var choice = 0

func decide_choice_block(blocks):
return blocks[choice]
if choices_func == null or !choices_func.is_valid():
return blocks[0]
else:
return yield(choices_func.call_func(blocks), "completed")

func decide_condition_block(blocks):
for block in blocks:


+ 0
- 5
addons/yarn_spinner/yarn_spinner_importer.gd Bestand weergeven

@@ -220,11 +220,6 @@ func get_preset_name(preset):

func get_import_options(preset):
match preset:
Presets.DEFAULT:
return [{
"name": "use_red_anyway",
"default_value": false
}]
_:
return []



+ 13
- 0
main/scenes/ChoicesBox.tscn Bestand weergeven

@@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://main/scripts/ChoicesBox.gd" type="Script" id=1]

[node name="ChoicesBox" type="VBoxContainer"]
anchor_left = 0.3
anchor_top = 0.1
anchor_right = 0.7
anchor_bottom = 0.45
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

+ 34
- 0
main/scenes/LogPanel.tscn Bestand weergeven

@@ -0,0 +1,34 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://main/scripts/LogPanel.gd" type="Script" id=1]

[node name="LogPanel" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Panel" type="Panel" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0

[node name="RichTextLabel" type="RichTextLabel" parent="."]
anchor_left = 0.02
anchor_top = 0.05
anchor_right = 0.98
anchor_bottom = 0.95
__meta__ = {
"_edit_use_anchors_": false
}

[node name="TextButton" type="Button" parent="."]
modulate = Color( 1, 1, 1, 0.235294 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -49.0
flat = true
__meta__ = {
"_edit_use_anchors_": false
}

+ 9
- 3
main/scenes/test_viteuf.tscn Bestand weergeven

@@ -1,8 +1,10 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=6 format=2]

[ext_resource path="res://main/scripts/test_viteuf.gd" type="Script" id=1]
[ext_resource path="res://main/dialogues/test.yarn" type="Resource" id=2]
[ext_resource path="res://addons/yarn_spinner/yarn_runner.gd" type="Script" id=3]
[ext_resource path="res://main/scenes/LogPanel.tscn" type="PackedScene" id=4]
[ext_resource path="res://main/scenes/ChoicesBox.tscn" type="PackedScene" id=5]

[node name="Node" type="Control"]
anchor_right = 1.0
@@ -16,6 +18,10 @@ __meta__ = {
script = ExtResource( 3 )
yarnScript = ExtResource( 2 )

[node name="RichTextLabel" type="RichTextLabel" parent="."]
anchor_right = 1.0
[node name="LogPanel" parent="." instance=ExtResource( 4 )]
anchor_bottom = 0.6

[node name="ChoicesBox" parent="." instance=ExtResource( 5 )]
anchor_top = 0.6
anchor_bottom = 1.0
alignment = 1

yarn/scripts/ChoicesBox.gd → main/scripts/ChoicesBox.gd Bestand weergeven

@@ -11,7 +11,7 @@ func on_choices(choices_list):
for choice in choices_list:
var choiceButton := Button.new()
choiceButton.text = choice["text"]
choiceButton.connect("pressed", self, "on_choice_made", [choice["marker"]])
choiceButton.connect("pressed", self, "on_choice_made", [choice])
add_child(choiceButton)
var res = yield(self, "choice_made")
hide()

yarn/scripts/LogPanel.gd → main/scripts/LogPanel.gd Bestand weergeven


+ 22
- 18
main/scripts/test_viteuf.gd Bestand weergeven

@@ -1,24 +1,28 @@
extends Control

func _ready():
$YarnRunner.say_func = funcref(self, "say")
$YarnRunner.run_all()
# $ChoicesBox.hide()
# $LogPanel.hide()
on_dialogue_start()
$YarnRunner.say_func = funcref(self, "on_new_line")
$YarnRunner.choices_func = funcref(self, "on_choices")
yield($YarnRunner.run_all(), "completed")
on_dialogue_end()

func say(element):
$RichTextLabel.text += str(element["raw"]) + "\n"
func on_dialogue_start():
$LogPanel.show()
$ChoicesBox.show()
$LogPanel.clear()
$ChoicesBox.clear()

func exec(stri):
var expr := Expression.new()
print("input : " + stri)
var err := expr.parse(stri)
if err == OK:
var res = expr.execute()
print("res : " + str(res))
else:
print("err : " + str(err))

func jajoujaj():
print("jaaaja")
func on_new_line(line):
yield($LogPanel.on_new_line(line["text"]), "completed")
var current_node = "Start"
var current_line = 0
func on_choices(choices_list):
print(choices_list)
return yield($ChoicesBox.on_choices(choices_list), "completed")

func on_dialogue_end():
pass
# $ChoicesBox.hide()
# $LogPanel.hide()

+ 2
- 2
project.godot Bestand weergeven

@@ -12,12 +12,12 @@ _global_script_classes=[ {
"base": "VBoxContainer",
"class": "ChoicesBox",
"language": "GDScript",
"path": "res://yarn/scripts/ChoicesBox.gd"
"path": "res://main/scripts/ChoicesBox.gd"
}, {
"base": "Control",
"class": "LogPanel",
"language": "GDScript",
"path": "res://yarn/scripts/LogPanel.gd"
"path": "res://main/scripts/LogPanel.gd"
}, {
"base": "Node",
"class": "YarnImporter",


+ 4
- 43
yarn/scenes/YarnSpinner.tscn Bestand weergeven

@@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://yarn/scripts/LogPanel.gd" type="Script" id=1]
[ext_resource path="res://yarn/scripts/ChoicesBox.gd" type="Script" id=2]
[ext_resource path="res://main/scenes/ChoicesBox.tscn" type="PackedScene" id=1]
[ext_resource path="res://main/scenes/LogPanel.tscn" type="PackedScene" id=2]
[ext_resource path="res://yarn/scripts/YarnSpinner.gd" type="Script" id=3]

[node name="YarnSpinner" type="Control"]
@@ -12,45 +12,6 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="ChoicesBox" type="VBoxContainer" parent="."]
anchor_left = 0.3
anchor_top = 0.1
anchor_right = 0.7
anchor_bottom = 0.45
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ChoicesBox" parent="." instance=ExtResource( 1 )]

[node name="LogPanel" type="Control" parent="."]
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Panel" type="Panel" parent="LogPanel"]
anchor_right = 1.0
anchor_bottom = 1.0

[node name="RichTextLabel" type="RichTextLabel" parent="LogPanel"]
anchor_left = 0.02
anchor_top = 0.05
anchor_right = 0.98
anchor_bottom = 0.95
text = "Coucou je suis un text de test, ou bien l'inverse"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="TextButton" type="Button" parent="LogPanel"]
modulate = Color( 1, 1, 1, 0.235294 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -20.0
flat = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LogPanel" parent="." instance=ExtResource( 2 )]

Laden…
Annuleren
Opslaan