added a 3d spinning cube 2d tile
This commit is contained in:
@@ -133,4 +133,4 @@ locale/translations_pot_files=PackedStringArray()
|
|||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
2d/snap/snap_2d_transforms_to_pixel=true
|
global_illumination/gi/use_half_resolution=true
|
||||||
|
30
scenes/3D/3d_cube.tscn
Normal file
30
scenes/3D/3d_cube.tscn
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
[gd_scene load_steps=4 format=3 uid="uid://boxvq5qowh8nn"]
|
||||||
|
|
||||||
|
[sub_resource type="Environment" id="Environment_t32a1"]
|
||||||
|
|
||||||
|
[sub_resource type="BoxMesh" id="BoxMesh_5dg07"]
|
||||||
|
|
||||||
|
[sub_resource type="GDScript" id="GDScript_a7mr5"]
|
||||||
|
resource_name = "spinning"
|
||||||
|
script/source = "extends MeshInstance3D
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
func _process(_delta):
|
||||||
|
rotate_y(0.01)
|
||||||
|
rotate_z(0.01)
|
||||||
|
"
|
||||||
|
|
||||||
|
[node name="Node3D" type="WorldEnvironment"]
|
||||||
|
environment = SubResource("Environment_t32a1")
|
||||||
|
|
||||||
|
[node name="mesh_instance_3d" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(0.5, -0.5, 0.707107, 0.707107, 0.707107, 0, -0.5, 0.5, 0.707107, 0, 0, 0)
|
||||||
|
mesh = SubResource("BoxMesh_5dg07")
|
||||||
|
script = SubResource("GDScript_a7mr5")
|
||||||
|
|
||||||
|
[node name="camera_3d" type="Camera3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 0.982906, 0.184106, 0, -0.184106, 0.982906, 0, 0.303103, 2.61621)
|
||||||
|
fov = 99.1704
|
||||||
|
|
||||||
|
[node name="directional_light_3d" type="DirectionalLight3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 0.856547, 0.51607, 0, -0.51607, 0.856547, 0, 0, 5.56892)
|
File diff suppressed because one or more lines are too long
30
scenes/tiles/3d_cube_tile.tscn
Normal file
30
scenes/tiles/3d_cube_tile.tscn
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
[gd_scene load_steps=3 format=3 uid="uid://dxfg62cl12ppw"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://boxvq5qowh8nn" path="res://scenes/3D/3d_cube.tscn" id="1_643fx"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lxe27"]
|
||||||
|
size = Vector2(64, 64)
|
||||||
|
|
||||||
|
[node name="3d_cube_tile" type="Node2D"]
|
||||||
|
|
||||||
|
[node name="static_body_2d" type="StaticBody2D" parent="."]
|
||||||
|
position = Vector2(0, 1)
|
||||||
|
|
||||||
|
[node name="collision_shape_2d" type="CollisionShape2D" parent="static_body_2d"]
|
||||||
|
position = Vector2(1, -2)
|
||||||
|
shape = SubResource("RectangleShape2D_lxe27")
|
||||||
|
|
||||||
|
[node name="sub_viewport_container" type="SubViewportContainer" parent="."]
|
||||||
|
offset_left = -115.0
|
||||||
|
offset_top = -112.0
|
||||||
|
offset_right = 141.0
|
||||||
|
offset_bottom = 144.0
|
||||||
|
|
||||||
|
[node name="sub_viewport" type="SubViewport" parent="sub_viewport_container"]
|
||||||
|
own_world_3d = true
|
||||||
|
transparent_bg = true
|
||||||
|
handle_input_locally = false
|
||||||
|
size = Vector2i(230, 230)
|
||||||
|
render_target_update_mode = 4
|
||||||
|
|
||||||
|
[node name="Node3D" parent="sub_viewport_container/sub_viewport" instance=ExtResource("1_643fx")]
|
@@ -3,152 +3,154 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
public partial class dialog_bubble : CanvasLayer
|
public partial class dialog_bubble : CanvasLayer
|
||||||
{
|
{
|
||||||
public Variant parsedDlg;
|
public Variant parsedDlg;
|
||||||
public Variant dlgLines;
|
public Variant dlgLines;
|
||||||
public int dlgPointer = 0;
|
public int dlgPointer = 0;
|
||||||
public RichTextLabel richText;
|
public RichTextLabel richText;
|
||||||
public Timer typewriterTimer;
|
public Timer typewriterTimer;
|
||||||
public string name;
|
public string name;
|
||||||
public Area2D triggerArea;
|
public Area2D triggerArea;
|
||||||
/*TODO:
|
/*TODO:
|
||||||
- Dont repeat the same randomized dialogue after you get asked do you need something "else"
|
- Dont repeat the same randomized dialogue after you get asked do you need something "else"
|
||||||
- add tree support (example: "story" key)
|
- add tree support (example: "story" key)
|
||||||
- ability to add dialogue begin answers on the fly (special ones are colored)
|
- ability to add dialogue begin answers on the fly (special ones are colored)
|
||||||
they will be in a dictionary with event IDs or Dictionary keys it also needs an array wich ones are active*/
|
they will be in a dictionary with event IDs or Dictionary keys it also needs an array wich ones are active
|
||||||
public override void _Ready()
|
-strings like in the "goodbye" key should be randomized without the array brackets so they are only needed for multiline texts
|
||||||
{
|
-answers should work more like dialogue for tree support*/
|
||||||
richText = GetNode<RichTextLabel>("box/rich_text_label");
|
public override void _Ready()
|
||||||
typewriterTimer = GetNode<Timer>("typewriter_timer");
|
{
|
||||||
}
|
richText = GetNode<RichTextLabel>("box/rich_text_label");
|
||||||
public void GetDialog(string file, string title, Area2D actor, string playerName, bool introducedVillager)
|
typewriterTimer = GetNode<Timer>("typewriter_timer");
|
||||||
{
|
}
|
||||||
triggerArea = actor;
|
public void GetDialog(string file, string title, Area2D actor, string playerName, bool introducedVillager)
|
||||||
name = title;
|
{
|
||||||
|
triggerArea = actor;
|
||||||
|
name = title;
|
||||||
|
|
||||||
parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText()
|
parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText()
|
||||||
.Replace("{player}", "[color=cyan]" + playerName + "[/color]").Replace("{title}", "[color=purple]" + title + "[/color]"));
|
.Replace("{player}", "[color=cyan]" + playerName + "[/color]").Replace("{title}", "[color=purple]" + title + "[/color]"));
|
||||||
|
|
||||||
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() != "villager" || introducedVillager)
|
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() != "villager" || introducedVillager)
|
||||||
GetNode<Label>("box/name_label").Text = title;
|
GetNode<Label>("box/name_label").Text = title;
|
||||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = false;
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = false;
|
||||||
|
|
||||||
//Get first key
|
//Get first key
|
||||||
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
|
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
|
||||||
if (introducedVillager)
|
if (introducedVillager)
|
||||||
GatherDialog("welcome");
|
GatherDialog("welcome");
|
||||||
else
|
else
|
||||||
GatherDialog("intro");
|
GatherDialog("intro");
|
||||||
|
|
||||||
else if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "message")
|
else if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "message")
|
||||||
GatherDialog("message");
|
GatherDialog("message");
|
||||||
|
|
||||||
Visible = true;
|
Visible = true;
|
||||||
}
|
}
|
||||||
public void GatherDialog(string key)
|
public void GatherDialog(string key)
|
||||||
{
|
{
|
||||||
dlgPointer = 0;
|
dlgPointer = 0;
|
||||||
dlgLines = parsedDlg.AsGodotDictionary()[key].AsGodotArray();
|
dlgLines = parsedDlg.AsGodotDictionary()[key].AsGodotArray();
|
||||||
dlgLines = dlgLines.AsGodotArray()[GD.RandRange(0, dlgLines.AsGodotArray().Count - 1)];
|
dlgLines = dlgLines.AsGodotArray()[GD.RandRange(0, dlgLines.AsGodotArray().Count - 1)];
|
||||||
//TODO:copy a clean default array and remove already used indexes and copy from clean array when its empty
|
//TODO:copy a clean default array and remove already used indexes and copy from clean array when its empty
|
||||||
}
|
}
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
DialogControlls();
|
DialogControlls();
|
||||||
AnswerBoxControlls();
|
AnswerBoxControlls();
|
||||||
}
|
}
|
||||||
public void DialogControlls()
|
public void DialogControlls()
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("ui_cancel") && Visible) richText.VisibleCharacters = richText.Text.Length;
|
if (Input.IsActionJustPressed("ui_cancel") && Visible) richText.VisibleCharacters = richText.Text.Length;
|
||||||
|
|
||||||
if (Input.IsActionJustPressed("ui_accept") && Visible && GetNode<PanelContainer>("box/panel_container").Visible == false
|
if (Input.IsActionJustPressed("ui_accept") && Visible && GetNode<PanelContainer>("box/panel_container").Visible == false
|
||||||
&& richText.VisibleCharacters == -1 | Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length <= richText.VisibleCharacters)
|
&& richText.VisibleCharacters == -1 | Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length <= richText.VisibleCharacters)
|
||||||
{
|
{
|
||||||
if (dlgPointer < dlgLines.AsGodotArray().Count)
|
if (dlgPointer < dlgLines.AsGodotArray().Count)
|
||||||
{
|
{
|
||||||
//read and write the dialogue
|
//read and write the dialogue
|
||||||
if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Float)
|
if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Float)
|
||||||
InDialogEvents((int)dlgLines.AsGodotArray()[dlgPointer]);
|
InDialogEvents((int)dlgLines.AsGodotArray()[dlgPointer]);
|
||||||
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.String && !dlgLines.AsGodotArray()[dlgPointer].AsString().StartsWith("<goto:>"))
|
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.String && !dlgLines.AsGodotArray()[dlgPointer].AsString().StartsWith("<goto:>"))
|
||||||
UpdateDialog();
|
UpdateDialog();
|
||||||
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.String && dlgLines.AsGodotArray()[dlgPointer].AsString().StartsWith("<goto:>"))
|
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.String && dlgLines.AsGodotArray()[dlgPointer].AsString().StartsWith("<goto:>"))
|
||||||
{
|
{
|
||||||
GatherDialog(dlgLines.AsGodotArray()[dlgPointer].AsString().Replace("<goto:>", ""));
|
GatherDialog(dlgLines.AsGodotArray()[dlgPointer].AsString().Replace("<goto:>", ""));
|
||||||
UpdateDialog();
|
UpdateDialog();
|
||||||
}
|
}
|
||||||
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Dictionary)
|
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Dictionary)
|
||||||
MakeAnswerBox(Json.ParseString(dlgLines.AsGodotArray()[dlgPointer].AsGodotDictionary().Keys.ToString()).AsStringArray());
|
MakeAnswerBox(Json.ParseString(dlgLines.AsGodotArray()[dlgPointer].AsGodotDictionary().Keys.ToString()).AsStringArray());
|
||||||
}
|
}
|
||||||
dlgPointer++;
|
dlgPointer++;
|
||||||
}
|
}
|
||||||
if (dlgPointer > dlgLines.AsGodotArray().Count)
|
if (dlgPointer > dlgLines.AsGodotArray().Count)
|
||||||
CloseDialog();
|
CloseDialog();
|
||||||
}
|
}
|
||||||
public void UpdateDialog()
|
public void UpdateDialog()
|
||||||
{
|
{
|
||||||
richText.Text = dlgLines.AsGodotArray()[dlgPointer].ToString();
|
richText.Text = dlgLines.AsGodotArray()[dlgPointer].ToString();
|
||||||
richText.VisibleCharacters = 0;
|
richText.VisibleCharacters = 0;
|
||||||
typewriterTimer.Start();
|
typewriterTimer.Start();
|
||||||
}
|
}
|
||||||
public void OnTypewriterTimerTimeout()
|
public void OnTypewriterTimerTimeout()
|
||||||
{
|
{
|
||||||
if (richText.VisibleCharacters < Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length)
|
if (richText.VisibleCharacters < Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length)
|
||||||
{
|
{
|
||||||
richText.VisibleCharacters++;
|
richText.VisibleCharacters++;
|
||||||
GetNode<AudioStreamPlayer>("typewriter_audio_stream").Play();
|
GetNode<AudioStreamPlayer>("typewriter_audio_stream").Play();
|
||||||
}
|
}
|
||||||
else typewriterTimer.Stop();
|
else typewriterTimer.Stop();
|
||||||
}
|
}
|
||||||
public void MakeAnswerBox(string[] dialogOptions)
|
public void MakeAnswerBox(string[] dialogOptions)
|
||||||
{
|
{
|
||||||
var parent = GetNode("box/panel_container/margin_container");
|
var parent = GetNode("box/panel_container/margin_container");
|
||||||
if (parent.GetChildCount() == 1) parent.GetChild(0).Free();
|
if (parent.GetChildCount() == 1) parent.GetChild(0).Free();
|
||||||
parent.AddChild(new VBoxContainer());
|
parent.AddChild(new VBoxContainer());
|
||||||
parent = parent.GetChild(0);
|
parent = parent.GetChild(0);
|
||||||
for (int i = 0; parent.GetChildCount() < dialogOptions.Length; i++)
|
for (int i = 0; parent.GetChildCount() < dialogOptions.Length; i++)
|
||||||
{
|
{
|
||||||
parent.AddChild(GD.Load<PackedScene>("res://scenes/gui/dlg_answer_button.tscn").Instantiate());
|
parent.AddChild(GD.Load<PackedScene>("res://scenes/gui/dlg_answer_button.tscn").Instantiate());
|
||||||
if (dialogOptions[i].StartsWith("<!>")) parent.GetChild<Button>(i).Disabled = true;
|
if (dialogOptions[i].StartsWith("<!>")) parent.GetChild<Button>(i).Disabled = true;
|
||||||
parent.GetChild<Button>(i).Text = dialogOptions[i].Replace("<!>", "");
|
parent.GetChild<Button>(i).Text = dialogOptions[i].Replace("<!>", "");
|
||||||
}
|
}
|
||||||
GetNode<PanelContainer>("box/panel_container").Visible = true;
|
GetNode<PanelContainer>("box/panel_container").Visible = true;
|
||||||
parent.GetChild<Button>(0).GrabFocus();
|
parent.GetChild<Button>(0).GrabFocus();
|
||||||
}
|
}
|
||||||
public void AnswerBoxControlls()
|
public void AnswerBoxControlls()
|
||||||
{
|
{
|
||||||
if (GetNode<PanelContainer>("box/panel_container").Visible == true
|
if (GetNode<PanelContainer>("box/panel_container").Visible == true
|
||||||
&& GetNode("box/panel_container/margin_container").GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton() != null)
|
&& GetNode("box/panel_container/margin_container").GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton() != null)
|
||||||
{
|
{
|
||||||
GetNode<AudioStreamPlayer>("answerbtn_audio_stream").Play();
|
GetNode<AudioStreamPlayer>("answerbtn_audio_stream").Play();
|
||||||
var answer = dlgLines.AsGodotArray()[dlgPointer - 1].AsGodotDictionary()[GetNode<Button>(GetNode("box/panel_container/margin_container")
|
var answer = dlgLines.AsGodotArray()[dlgPointer - 1].AsGodotDictionary()[GetNode<Button>(GetNode("box/panel_container/margin_container")
|
||||||
.GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton().GetPath()).Text];
|
.GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton().GetPath()).Text];
|
||||||
GetNode<PanelContainer>("box/panel_container").Visible = false;
|
GetNode<PanelContainer>("box/panel_container").Visible = false;
|
||||||
if (answer.VariantType == Variant.Type.String && answer.AsString().StartsWith("<goto:>"))
|
if (answer.VariantType == Variant.Type.String && answer.AsString().StartsWith("<goto:>"))
|
||||||
{
|
{
|
||||||
GatherDialog(answer.AsString().Replace("<goto:>", ""));
|
GatherDialog(answer.AsString().Replace("<goto:>", ""));
|
||||||
UpdateDialog();
|
UpdateDialog();
|
||||||
}
|
}
|
||||||
dlgPointer++;
|
dlgPointer++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void InDialogEvents(int eventID) //maybe replaceable with jsonrpc?
|
public void InDialogEvents(int eventID)
|
||||||
{
|
{
|
||||||
switch (eventID)
|
switch (eventID)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
GetNode<Label>("box/name_label").Text = name;
|
GetNode<Label>("box/name_label").Text = name;
|
||||||
triggerArea.Set("introducedVillager", true);
|
triggerArea.Set("introducedVillager", true);
|
||||||
GatherDialog("begindialog");
|
GatherDialog("begindialog");
|
||||||
UpdateDialog();
|
UpdateDialog();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void CloseDialog()
|
public void CloseDialog()
|
||||||
{
|
{
|
||||||
Visible = false;
|
Visible = false;
|
||||||
dlgPointer = 0;
|
dlgPointer = 0;
|
||||||
richText.VisibleCharacters = -1;
|
richText.VisibleCharacters = -1;
|
||||||
GetNode<Label>("box/name_label").Text = "???";
|
GetNode<Label>("box/name_label").Text = "???";
|
||||||
richText.Text = "";
|
richText.Text = "";
|
||||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,9 +1,10 @@
|
|||||||
[gd_resource type="TileSet" load_steps=9 format=3 uid="uid://txl24cadn8t4"]
|
[gd_resource type="TileSet" load_steps=11 format=3 uid="uid://txl24cadn8t4"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dk7fqaw2b3w1k" path="res://scenes/tiles/first_debug_tile.tscn" id="1_uxmn6"]
|
[ext_resource type="PackedScene" uid="uid://dk7fqaw2b3w1k" path="res://scenes/tiles/first_debug_tile.tscn" id="1_uxmn6"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dckxciecwjfgf" path="res://scenes/tiles/dialogdebug_cupcake.tscn" id="2_0cov5"]
|
[ext_resource type="PackedScene" uid="uid://dckxciecwjfgf" path="res://scenes/tiles/dialogdebug_cupcake.tscn" id="2_0cov5"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c4dkrtswpv8cv" path="res://scenes/tiles/sound_debug_tile.tscn" id="3_lf2fs"]
|
[ext_resource type="PackedScene" uid="uid://c4dkrtswpv8cv" path="res://scenes/tiles/sound_debug_tile.tscn" id="3_lf2fs"]
|
||||||
[ext_resource type="Texture2D" uid="uid://d3l4uomk1gw8c" path="res://assets/textures/debug/grass_tile.png" id="4_k7c1q"]
|
[ext_resource type="Texture2D" uid="uid://d3l4uomk1gw8c" path="res://assets/textures/debug/grass_tile.png" id="4_k7c1q"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dxfg62cl12ppw" path="res://scenes/tiles/3d_cube_tile.tscn" id="5_x3uol"]
|
||||||
|
|
||||||
[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_lcrun"]
|
[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_lcrun"]
|
||||||
resource_name = "test"
|
resource_name = "test"
|
||||||
@@ -22,9 +23,14 @@ texture = ExtResource("4_k7c1q")
|
|||||||
texture_region_size = Vector2i(64, 64)
|
texture_region_size = Vector2i(64, 64)
|
||||||
0:0/0 = 0
|
0:0/0 = 0
|
||||||
|
|
||||||
|
[sub_resource type="TileSetScenesCollectionSource" id="TileSetScenesCollectionSource_loadc"]
|
||||||
|
resource_name = "3d cube"
|
||||||
|
scenes/1/scene = ExtResource("5_x3uol")
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
tile_size = Vector2i(64, 64)
|
tile_size = Vector2i(64, 64)
|
||||||
sources/0 = SubResource("TileSetScenesCollectionSource_lcrun")
|
sources/0 = SubResource("TileSetScenesCollectionSource_lcrun")
|
||||||
sources/1 = SubResource("TileSetScenesCollectionSource_eskkr")
|
sources/1 = SubResource("TileSetScenesCollectionSource_eskkr")
|
||||||
sources/2 = SubResource("TileSetScenesCollectionSource_xtxu0")
|
sources/2 = SubResource("TileSetScenesCollectionSource_xtxu0")
|
||||||
sources/3 = SubResource("TileSetAtlasSource_na45g")
|
sources/3 = SubResource("TileSetAtlasSource_na45g")
|
||||||
|
sources/4 = SubResource("TileSetScenesCollectionSource_loadc")
|
||||||
|
Reference in New Issue
Block a user