24 Commits

Author SHA1 Message Date
63312425e9 i guess regex and replacement is finished 2023-04-17 11:36:33 +02:00
fbacee48f0 improved playername regex 2023-04-16 18:55:09 +02:00
35d61c4169 updated godot to 4.0.2 2023-04-16 13:52:21 +02:00
Yannik
6e3cebb653 added a basic anticheat 2023-04-12 21:18:27 +02:00
Yannik
1b1c72e86a curseword bbcode censor effect 2023-04-12 14:15:54 +02:00
Yannik
20d1ade391 even better playername regex 2023-04-11 20:47:28 +02:00
Yannik
f985225515 edited debug message 2023-04-11 20:47:11 +02:00
Yannik
9c45bd7f69 Merge branch 'main' of https://github.com/vaporvee/RPG-Test 2023-04-11 17:38:41 +02:00
Yannik
e279f80793 improved playername regex 2023-04-11 17:38:17 +02:00
Yannik
4bdd594045 renamed player 2023-04-11 17:36:27 +02:00
Yannik
9140220ef1 improved playername regex 2023-04-11 17:35:52 +02:00
Yannik
4c58781fb6 even more dialogue system improvements 2023-04-11 16:32:16 +02:00
Yannik
15b938e0a0 small collision bug fixes 2023-04-11 16:31:54 +02:00
f149fa7c53 changed comments 2023-03-31 12:48:15 +02:00
7bff319b39 better one line dialogue string support 2023-03-28 20:49:39 +02:00
86ffc9682b removed more dumb c# code 2023-03-21 20:09:32 +01:00
d05cbb2260 fixed some returns 2023-03-21 20:01:52 +01:00
8208919dd2 removed some dumb c# coding 2023-03-21 20:00:55 +01:00
6fedaad0b3 capped fps and reset some settings 2023-03-21 19:53:29 +01:00
57f1bd959e updated to godot 4.0.1 2023-03-21 19:53:03 +01:00
6c71aa302c removed useless function 2023-03-17 10:01:06 +01:00
ca77ad3fc1 Merge branch 'main' of https://github.com/vaporvee/RPG-Test 2023-03-17 07:39:50 +01:00
33c8c127e7 added functionality for non random dialogue 2023-03-17 07:38:37 +01:00
e9241eff46 better slime collision shape 2023-03-12 12:47:47 +01:00
17 changed files with 236 additions and 142 deletions

View File

@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.0.0">
<Project Sdk="Godot.NET.Sdk/4.0.2">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>

10
RPG Test gd4.csproj.old Normal file
View File

@@ -0,0 +1,10 @@
<Project Sdk="Godot.NET.Sdk/4.0.1">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>RPGTestgd4</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="villager_normal.json" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,3 @@
{
"<message>": "[cuss]FUCKING HELL[/cuss]"
}

View File

@@ -1,58 +1,60 @@
{
"dialogType": "villager",
"intro": [
"<dialogType>": "villager",
"<intro>": [
[
"Hello i'm {title}. Your name must be {player}!",
0
]
],
"welcome": [
"<welcome>": [
[
"Oh hello, {player}... You look great!",
"<goto:>begindialog"
"<goto:0:begindialog>"
],
[
"Hey, {player}! Hope you have fun today!",
"<goto:>begindialog"
"<goto:0:begindialog>"
],
[
"Hi! What's up {player}?",
"<goto:>begindialog"
"<goto:0:begindialog>"
]
],
"begindialog": [
"<begindialog>": [
[
"What can I do for you?",
{
"I just wanna talk": "<goto:>tipp",
"Nevermind!": "<goto:>goodbye"
"<eventBeginAnswers>": true,
"I just wanna talk": "<goto:0:tipp>",
"Nevermind!": "<goto:0:goodbye>"
}
],
[
"So what do you want?",
{
"What's up": "<goto:>tipp",
"Nothing": "<goto:>goodbye"
"<eventBeginAnswers>": true,
"What's up": "<goto:0:tipp>",
"Nothing": "<goto:0:goodbye>"
}
]
],
"else": [
"<else>": [
[
"Do you need something else?",
{
"Can you tell me more?": "<goto:>tipp",
"No, thanks!": "<goto:>goodbye"
"Can you tell me more?": "<goto:0:tipp>",
"No, thanks!": "<goto:0:goodbye>"
}
],
[
"So can i help you with something else?",
{
"Tell me a bit more": "<goto:>tipp",
"I'm good, thank you!": "<goto:>goodbye"
"Tell me a bit more": "<goto:0:tipp>",
"I'm good, thank you!": "<goto:0:goodbye>"
}
]
],
"goodbye": [
"<goodbye>": [
[
"Was nice talking to you goodbye!"
],
@@ -60,20 +62,20 @@
"Have a great day, {player}!"
]
],
"tipp": [
"<tipp>": [
[
"[font s=6]░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░░\n░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░\n░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░\n░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░\n░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░\n█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█\n█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█\n░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░\n░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░\n░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░\n░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░\n░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░\n░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░\n░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░\n░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░[/font]",
"<goto:>else"
"<goto:0:else>"
],
[
"[center][font s=80][wave amp=50 freq=15][rainbow]This is cool test text[/rainbow][/wave][/font][/center]",
"sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,",
"sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.",
"Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
"<goto:>else"
"<goto:0:else>"
]
],
"story": [
"<story>": [
[
"test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1",
"test2test2test2test2test2test2test2test2test2test2test2test2test2test2test2",

View File

@@ -0,0 +1,4 @@
{
"cheatalert_message": "This game closed any suspicious software automatically. If this causes problems, please exit the game and contact support for help immediately.",
"cheatalert_title": "Cheat process detected in your operating system! D:<"
}

View File

@@ -13,6 +13,7 @@ config_version=5
config/name="RPG Test"
run/main_scene="res://scenes/overworld.tscn"
config/features=PackedStringArray("4.0", "Forward Plus")
run/max_fps=60
boot_splash/show_image=false
config/icon="res://assets/textures/debug/dummy-player-normal.png"
@@ -21,6 +22,7 @@ config/icon="res://assets/textures/debug/dummy-player-normal.png"
Essential="res://src/essential.cs"
PlayerVariables="*res://src/player_variables.cs"
Console="*res://scenes/gui/console.tscn"
Anticheat="*res://src/anticheat.cs"
[display]
@@ -28,8 +30,8 @@ window/size/viewport_width=1844
window/size/viewport_height=1037
window/size/window_width_override=1537
window/size/window_height_override=864
mouse_cursor/custom_image="res://assets/textures/cursor.png"
window/stretch/mode="canvas_items"
mouse_cursor/custom_image="res://assets/textures/cursor.png"
[dotnet]
@@ -37,17 +39,12 @@ project/assembly_name="RPG Test gd4"
[editor]
naming/default_signal_callback_name="On{NodeName}{SignalName}"
naming/default_signal_callback_to_self_name="On{SignalName}"
naming/node_name_num_separator=2
naming/node_name_casing=2
naming/default_signal_callback_name="On{NodeName}{SignalName}"
naming/default_signal_callback_to_self_name="On{SignalName}"
node_naming/name_casing=2
[filesystem]
import/blender/enabled=false
import/fbx/enabled=false
[input]
ui_accept={
@@ -138,20 +135,12 @@ cheat_start={
[internationalization]
locale/translation_remaps={}
locale/translations_pot_files=PackedStringArray()
[layer_names]
2d_physics/layer_1="World"
2d_physics/layer_2="Interactable"
[physics]
2d/run_on_separate_thread=true
[rendering]
global_illumination/gi/use_half_resolution=true
shading/overrides/force_vertex_shading=true
occlusion_culling/use_occlusion_culling=true
shading/use_occlusion_culling=true
camera/depth_of_field/depth_of_field_bokeh_quality=2

View File

@@ -1,8 +1,9 @@
[gd_scene load_steps=7 format=3 uid="uid://bkm7365u1mm3o"]
[gd_scene load_steps=8 format=3 uid="uid://di368n7hi66po"]
[ext_resource type="Script" path="res://src/scene-scripts/dialogue-system/dialog_bubble.cs" id="1_xtj1q"]
[ext_resource type="Script" path="res://src/scene-scripts/dialog_bubble.cs" id="1_xtj1q"]
[ext_resource type="FontFile" uid="uid://cx6bvqk0ghmjv" path="res://assets/fonts/urbane-rounded-medium.otf" id="2_qrihj"]
[ext_resource type="AudioStream" uid="uid://cg6grs5k5m33n" path="res://assets/audios/typewrite/default_tw.wav" id="2_wg62u"]
[ext_resource type="RichTextEffect" uid="uid://0o1lbwcdjg28" path="res://src/gdscript/tool/bbcodeeffects/cuss.tres" id="3_lmnhk"]
[ext_resource type="Texture2D" uid="uid://04pdpdvkg2s" path="res://assets/textures/dialogue/dialogue_answer_ninepatch.png" id="3_n3y1v"]
[ext_resource type="AudioStream" uid="uid://7si4jccoofsf" path="res://assets/audios/ui/small_btn.wav" id="5_w6jq7"]
@@ -11,6 +12,7 @@
[node name="dialog_bubble" type="CanvasLayer"]
process_mode = 4
script = ExtResource("1_xtj1q")
eventBeginAnswers = {}
metadata/_edit_use_anchors_ = true
[node name="typewriter_audio_stream" type="AudioStreamPlayer" parent="."]
@@ -54,6 +56,7 @@ theme_override_fonts/normal_font = ExtResource("2_qrihj")
theme_override_font_sizes/normal_font_size = 42
bbcode_enabled = true
scroll_active = false
custom_effects = [ExtResource("3_lmnhk")]
visible_characters_behavior = 1
metadata/_edit_lock_ = true

View File

@@ -55,6 +55,9 @@ editor_draw_limits = true
position = Vector2(-224, 206)
metadata/_edit_lock_ = true
[node name="dialog_trigger_area" parent="base_npc" index="2"]
file = "res://assets/lang/en/dialogue/npcs/message_one.json"
[node name="base_npc_2" parent="." instance=ExtResource("3_dxdug")]
position = Vector2(-319, 178)
metadata/_edit_lock_ = true
@@ -85,3 +88,5 @@ shape = SubResource("SegmentShape2D_f7wta")
metadata/_edit_lock_ = true
[editable path="player"]
[editable path="base_npc"]
[editable path="base_npc/dialog_trigger_area"]

View File

@@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
[ext_resource type="Texture2D" uid="uid://olceowuycu8c" path="res://assets/textures/debug/dummy-player-atlas.png" id="2_yu1q5"]
[ext_resource type="PackedScene" uid="uid://bkm7365u1mm3o" path="res://scenes/gui/dialog_bubble.tscn" id="3_8f573"]
[ext_resource type="PackedScene" uid="uid://di368n7hi66po" path="res://scenes/gui/dialog_bubble.tscn" id="3_8f573"]
[sub_resource type="AtlasTexture" id="AtlasTexture_068kt"]
atlas = ExtResource("2_yu1q5")
@@ -128,7 +128,7 @@ metadata/_edit_lock_ = true
visible = false
[node name="collision_shape" type="CollisionShape2D" parent="."]
position = Vector2(0, 35)
position = Vector2(0, 34)
rotation = 1.5708
shape = SubResource("CapsuleShape2D_38v5o")

View File

@@ -36,8 +36,8 @@ animations = [{
}]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_e6mi3"]
radius = 9.0
height = 46.0
radius = 6.0
height = 40.0
[node name="slime" type="CharacterBody2D" groups=["enemies"]]
collision_layer = 8
@@ -48,14 +48,15 @@ floor_constant_speed = true
script = ExtResource("1_l1742")
[node name="animated_sprite_2d" type="AnimatedSprite2D" parent="."]
position = Vector2(0, 19)
position = Vector2(0, 24)
sprite_frames = SubResource("SpriteFrames_bwr2v")
frame_progress = 0.348187
[node name="collision_shape_2d" type="CollisionShape2D" parent="."]
position = Vector2(0, 28)
position = Vector2(0, 33)
rotation = 1.5708
shape = SubResource("CapsuleShape2D_e6mi3")
[node name="visible_notifier_2d" type="VisibleOnScreenNotifier2D" parent="."]
rect = Rect2(-25, 0, 50, 40)
position = Vector2(0, 9)
rect = Rect2(-25, 0, 50, 30)

29
src/anticheat.cs Normal file
View File

@@ -0,0 +1,29 @@
using System.Diagnostics;
using Godot;
public partial class anticheat : Node
{
string[] suspiciousProcesses = { "cheat", "wemod" };
string alertMessage;
string alertTitle;
public override void _Ready()
{
var lang = Json.ParseString(FileAccess.Open("res://assets/lang/en/warnings.json", FileAccess.ModeFlags.Read).GetAsText()).AsGodotDictionary();
alertMessage = lang["cheatalert_message"].ToString();
alertTitle = lang["cheatalert_title"].ToString();
}
public override void _Process(double delta)
{
foreach (Process p in Process.GetProcesses())
foreach (string s in suspiciousProcesses)
{
if (p.ProcessName.Find(s) >= 0) //cheat gets detected
{
GetTree().Paused = true;
OS.Kill(p.Id);
OS.Alert(alertMessage, alertTitle);
GetTree().Paused = false;
}
}
}
}

View File

@@ -0,0 +1,33 @@
@tool
extends RichTextEffect
# Syntax: [cuss][/cuss]
var bbcode = "cuss"
var VOWELS : PackedInt32Array = [97,101,105,111,117,65,69,73,79,85]#a,e,i,o,u,A,E,I,O,U
var CHARS : PackedInt32Array = [38,36,33,64,42,35,37]#&,$,!,@,*,#,%
var SPACE : int = 32
var _was_space = false
func get_text_server():
return TextServerManager.get_primary_interface()
func _process_custom_fx(char_fx):
var c = char_fx.glyph_index
var vowelBool : bool = false
for x in VOWELS:
if char_fx.glyph_index == get_text_server().font_get_glyph_index(char_fx.font, 1, x, 0):
vowelBool = true
if not _was_space and not char_fx.relative_index == 0 and not c == get_text_server().font_get_glyph_index(char_fx.font, 1, SPACE, 0):
var t = char_fx.elapsed_time + char_fx.glyph_index * 10.2 + char_fx.relative_index * 2
t *= 4.3
if vowelBool or sin(t) > 0.0:
char_fx.glyph_index = get_text_server().font_get_glyph_index(char_fx.font, 1, CHARS[int(t) % len(CHARS)], 0)
_was_space = c == get_text_server().font_get_glyph_index(char_fx.font, 1, SPACE, 0)
return true

View File

@@ -0,0 +1,7 @@
[gd_resource type="RichTextEffect" load_steps=2 format=3 uid="uid://0o1lbwcdjg28"]
[ext_resource type="Script" path="res://src/gdscript/tool/bbcodeeffects/cuss.gd" id="1_ctc4u"]
[resource]
resource_name = "cuss"
script = ExtResource("1_ctc4u")

View File

@@ -7,13 +7,13 @@ public partial class player_variables : Node
private static string _playername = "Yannik";
public static string PlayerName
{
get { return _playername; }
set
get
{
_playername = Regex.Replace(value, @"\[[^]]+\]", "");
_playername = Regex.Replace(_playername, @"<[^>]*>", "");
if (PlayerName.Length > 12)
_playername = PlayerName.Substring(0, 12);
_playername = Regex.Replace(_playername, @"[<卐卍࿕࿖࿗࿘ꖦ‍⃠\uD83C-\uDBFF\uDC00-\uDFFF]", "").StripEdges(); //todo swearword censoring with bbcode effect
if (_playername.Length > 12)
_playername = _playername.Substring(0, 12);
return _playername.Replace(@"\s+", " ").Replace(@"\", @"\\").Replace("\"", "\\\"").Replace("'", "\\'");
}
set { _playername = value; }
}
}

View File

@@ -3,13 +3,13 @@ using Godot.Collections;
public partial class console : PopupPanel
{
private string[] gamepadCheatcode = { "ui_up", "ui_up", "ui_down", "ui_down", "ui_left", "ui_right", "ui_left", "ui_right", "ui_cancel", "ui_accept", "cheat_start" };
private int gpCcIndexer = 0;
private InputEvent inputEvent;
string[] gamepadCheatcode = { "ui_up", "ui_up", "ui_down", "ui_down", "ui_left", "ui_right", "ui_left", "ui_right", "ui_cancel", "ui_accept", "cheat_start" };
int gpCcIndexer = 0;
InputEvent inputEvent;
private static RichTextLabel textblock;
private LineEdit line;
private Dictionary commandDict;
private string error = "Not found! :(";
LineEdit line;
Dictionary commandDict;
string error = "Not found! :(";
//functions with capital letters can't be used inside the console
public override void _Ready()
@@ -39,14 +39,14 @@ public partial class console : PopupPanel
if (Input.IsActionJustPressed("console"))
ToggleVisible();
}
private void ToggleVisible()
void ToggleVisible()
{
Visible = !Visible;
player.allowMovement = !Visible;
line.GrabFocus();
}
private void OnPopupHide() { if (dialog_bubble.isTalking == false) player.allowMovement = true; }
private void OnLineEditTextSubmitted(string command)
void OnPopupHide() { if (dialog_bubble.isTalking == false) player.allowMovement = true; }
void OnLineEditTextSubmitted(string command)
{
line.Clear();
//repeat user input to console
@@ -80,7 +80,7 @@ public partial class console : PopupPanel
}
private void help()
void help()
{
Print("==================================== Help ====================================");
for (int i = 0; i < commandDict.Count; i++)
@@ -89,7 +89,7 @@ public partial class console : PopupPanel
+ Json.ParseString(commandDict.Values.ToString()).AsStringArray()[i]);
}
}
private void help(string key) //Optional parameters aren't optional in Call()/Callv() so i use overloads instead
void help(string key) //Optional parameters aren't optional in Call()/Callv() so i use overloads instead
{
key = key.ToLower();
if (key.Length != 0 && commandDict.ContainsKey(key))
@@ -103,13 +103,13 @@ public partial class console : PopupPanel
help("help");
};
}
private void consoleclear() => textblock.Clear();
private void speed(float multiplier)
void consoleclear() => textblock.Clear();
void speed(float multiplier)
{
player.speed = Mathf.Clamp(multiplier, 0.01f, 15f);
Print("Set player speed to " + Mathf.Clamp(multiplier, 0.01f, 15f));
}
private void noclip()
void noclip()
{
try { Print(player.CollisionToggle()); }
catch
@@ -118,7 +118,7 @@ public partial class console : PopupPanel
help("noclip");
}
}
private void stickycamera()
void stickycamera()
{
try { Print(player.CheatCam()); }
catch
@@ -127,22 +127,29 @@ public partial class console : PopupPanel
help("stickycamera");
}
}
private void playername(string name)
void playername(string name)
{
string tmpPlayerName = player_variables.PlayerName;
player_variables.PlayerName = name;
Print("Your new name is now: " + player_variables.PlayerName);
if (player_variables.PlayerName == "")
{
player_variables.PlayerName = tmpPlayerName;
Print("The name had too much incorrect symbols and would be empty when changed.");
}
else
Print("Your new name is now: " + player_variables.PlayerName);
}
private void closedialogue()
void closedialogue()
{
dialog_bubble.forceClose = true;
Print("Dialogue got closed!");
}
private void reload()
void reload()
{
GetTree().ReloadCurrentScene();
Print("Level got reloaded!");
}
private void visiblecollision()
void visiblecollision()
{
GetTree().DebugCollisionsHint = !GetTree().DebugCollisionsHint;
Print("Visible collision shapes and hitmarker now set to: " + GetTree().DebugCollisionsHint + "Use 'reload' to see changes!");

View File

@@ -1,15 +1,18 @@
using Godot;
using Godot.Collections;
using System.Text.RegularExpressions;
public partial class dialog_bubble : CanvasLayer
{
public Variant parsedDlg;
public Variant dlgLines;
public int dlgPointer = 0;
public RichTextLabel richText;
public Timer typewriterTimer;
public string title;
public Area2D triggerArea;
[Export] Dictionary eventBeginAnswers;
Variant parsedDlg;
Variant dlgLines;
int dlgPointer = 0;
int parsedDlgPointer = 0;
RichTextLabel richText;
Timer typewriterTimer;
string title;
Area2D triggerArea;
public static bool forceClose;
public static bool isTalking;
/*TODO:
@@ -17,8 +20,8 @@ public partial class dialog_bubble : CanvasLayer
- add tree support (example: "story" key)
- 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
-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*/
-answers should work more like gatherdialogue for tree support
- the int in <goto:0 <- should represent the parsedDlgPointer*/
public override void _Ready()
{
richText = GetNode<RichTextLabel>("box/rich_text_label");
@@ -26,51 +29,66 @@ public partial class dialog_bubble : CanvasLayer
}
public void GetDialog(string file, Area2D actor)
{
console.Print("Loaded dialogue from: " + file + "\nClose dialogue with 'closedialogue'");
console.Print("Loaded dialogue from: " + file + "\nClose dialogue with \"closedialogue\"");
triggerArea = actor;
title = actor.Get("title").AsString();
bool introducedVillager = actor.Get("introducedVillager").AsBool();
parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText()
.Replace("{player}", "[color=cyan]" + player_variables.PlayerName + "[/color]").Replace("{title}", "[color=purple]" + title + "[/color]"));
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() != "villager" || introducedVillager)
if (introducedVillager)
GetNode<Label>("box/name_label").Text = title;
player.allowMovement = false;
//Get first key
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
if (introducedVillager)
GatherDialog("welcome");
else
GatherDialog("intro");
else if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "message")
GatherDialog("message");
if (introducedVillager && parsedDlg.AsGodotDictionary().ContainsKey("<welcome>"))
GatherDialog("<welcome>");
else if (parsedDlg.AsGodotDictionary().ContainsKey("<intro>"))
GatherDialog("<intro>");
else if (parsedDlg.AsGodotDictionary().ContainsKey("<message>"))
{
GetNode<Label>("box/name_label").Text = title;
GatherDialog("<message>");
}
Visible = true;
isTalking = true;
}
public void GatherDialog(string key)
void GatherDialog(string key)
{
dlgPointer = 0;
dlgLines = parsedDlg.AsGodotDictionary()[key].AsGodotArray();
dlgLines = dlgLines.AsGodotArray()[GD.RandRange(0, dlgLines.AsGodotArray().Count - 1)];
if (parsedDlg.AsGodotDictionary()[key].VariantType == Variant.Type.String)
{
string[] oneline = { parsedDlg.AsGodotDictionary()[key].AsString() };
dlgLines = oneline;
}
if (parsedDlg.AsGodotDictionary()[key].VariantType == Variant.Type.Array)
dlgLines = parsedDlg.AsGodotDictionary()[key].AsGodotArray();
if (dlgLines.AsGodotArray()[0].VariantType == Variant.Type.Array)
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
}
public void OnVisibilityChanged()
void OnVisibilityChanged()
{
if (Visible)
ProcessMode = ProcessModeEnum.Inherit;
else ProcessMode = ProcessModeEnum.Disabled;
else if (richText != null)
{
dlgPointer = 0;
richText.VisibleCharacters = -1;
GetNode<Label>("box/name_label").Text = "???";
richText.Text = "";
if (GetParent().Name == "player") player.allowMovement = true;
isTalking = false;
forceClose = false;
ProcessMode = ProcessModeEnum.Disabled;
}
}
public override void _Process(double delta)
{
DialogControlls();
AnswerBoxControlls();
}
public void DialogControlls()
void DialogControlls()
{
if (Input.IsActionJustPressed("ui_cancel")) richText.VisibleCharacters = richText.Text.Length;
@@ -82,11 +100,11 @@ public partial class dialog_bubble : CanvasLayer
//read and write the dialogue
if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Float)
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();
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:0:", ""));
UpdateDialog();
}
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Dictionary)
@@ -94,10 +112,9 @@ public partial class dialog_bubble : CanvasLayer
}
dlgPointer++;
}
if (dlgPointer > dlgLines.AsGodotArray().Count || forceClose)
CloseDialog();
Visible = !(dlgPointer > dlgLines.AsGodotArray().Count || forceClose);
}
public void UpdateDialog()
void UpdateDialog()
{
richText.Text = dlgLines.AsGodotArray()[dlgPointer].ToString();
richText.VisibleCharacters = 0;
@@ -112,7 +129,7 @@ public partial class dialog_bubble : CanvasLayer
}
else typewriterTimer.Stop();
}
public void MakeAnswerBox(string[] dialogOptions)
void MakeAnswerBox(string[] dialogOptions)
{
var parent = GetNode("box/panel_container/margin_container");
if (parent.GetChildCount() == 1) parent.GetChild(0).Free();
@@ -127,45 +144,33 @@ public partial class dialog_bubble : CanvasLayer
GetNode<PanelContainer>("box/panel_container").Visible = true;
parent.GetChild<Button>(0).GrabFocus();
}
public void AnswerBoxControlls()
void AnswerBoxControlls()
{
if (GetNode<PanelContainer>("box/panel_container").Visible == true
&& GetNode("box/panel_container/margin_container").GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton() != null)
{
GetNode<AudioStreamPlayer>("answerbtn_audio_stream").Play(); //BUG: dialogue box breaks while game console is open.
GetNode<AudioStreamPlayer>("answerbtn_audio_stream").Play();
var answer = dlgLines.AsGodotArray()[dlgPointer - 1].AsGodotDictionary()[GetNode<Button>(GetNode("box/panel_container/margin_container")
.GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton().GetPath()).Text];
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:0:", ""));
UpdateDialog();
}
dlgPointer++;
}
}
public void InDialogEvents(int eventID)
void InDialogEvents(int eventID)
{
switch (eventID)
{
case 0:
GetNode<Label>("box/name_label").Text = title;
triggerArea.Set("introducedVillager", true);
GatherDialog("begindialog");
GatherDialog("<begindialog>");
UpdateDialog();
break;
}
}
public void CloseDialog()
{
Visible = false;
dlgPointer = 0;
richText.VisibleCharacters = -1;
GetNode<Label>("box/name_label").Text = "???";
richText.Text = "";
if (GetParent().Name == "player") player.allowMovement = true;
isTalking = false;
forceClose = false;
}
}

View File

@@ -6,15 +6,15 @@ public partial class player : CharacterBody2D
{
[Export] public static float speed = 1;
public static bool allowMovement = true;
public Vector2 movement;
public AnimatedSprite2D animatedSprite;
public Marker2D rotCenter;
public RayCast2D dialogRayCast;
Vector2 movement;
AnimatedSprite2D animatedSprite;
Marker2D rotCenter;
RayCast2D dialogRayCast;
public static Vector2 globalPlayerPosition;
//console cheats:
private static Camera2D cheatCam;
private static Camera2D mainCam;
private static CollisionShape2D collision;
static Camera2D cheatCam;
static Camera2D mainCam;
static CollisionShape2D collision;
public override void _Ready()
{
@@ -67,11 +67,7 @@ public partial class player : CharacterBody2D
animatedSprite.SpeedScale = Math.Abs(movement.Y * speed * 1.3f);
}
}
public int BeginDialogue(int i)
{
return 0;
}
public void OnAnimationChanged()
void OnAnimationChanged()
{
if (animatedSprite.Animation == "move_side")
{
@@ -91,18 +87,18 @@ public partial class player : CharacterBody2D
{
cheatCam.Enabled = true;
mainCam.Enabled = false;
return "cheat_cam has been enabled\n";
return "cheat_cam has been enabled";
}
else
{
cheatCam.Enabled = false;
mainCam.Enabled = true;
return "cheat_cam has been disabled\n";
return "cheat_cam has been disabled";
}
}
public static string CollisionToggle()
{
collision.Disabled = !collision.Disabled;
return ("Noclip is now set to: " + collision.Disabled + "\n");
return ("Noclip is now set to: " + collision.Disabled);
}
}