From 2c7a69682160f7fdcaf11e7026277f58abbe2de9 Mon Sep 17 00:00:00 2001 From: cmod31 Date: Fri, 24 Feb 2023 12:53:44 +0100 Subject: [PATCH] added dialogue close command --- src/essential.cs | 5 ++- src/scene-scripts/console/commands.json | 17 +++---- src/scene-scripts/console/console.cs | 44 +++++++++++-------- .../dialogue-system/dialog_bubble.cs | 10 +++-- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/essential.cs b/src/essential.cs index e007640..aed312a 100644 --- a/src/essential.cs +++ b/src/essential.cs @@ -10,8 +10,11 @@ public partial class essential : Node //Checks if using Keyboard or controller and giving out current controller if (@event is InputEventKey || @event is InputEventMouseButton || currentController == "") currentController = "PC"; - if (@event is InputEventJoypadButton) + if (@event is InputEventJoypadButton && currentController != Input.GetJoyName(0)) + { currentController = Input.GetJoyName(0); + console.Print("Current controller device: " + currentController); + } } public override void _Process(double delta) { diff --git a/src/scene-scripts/console/commands.json b/src/scene-scripts/console/commands.json index e20bbe5..ec7677d 100644 --- a/src/scene-scripts/console/commands.json +++ b/src/scene-scripts/console/commands.json @@ -1,10 +1,11 @@ { - "help": " [command] - Shows help or help for a specific command\n", - "consoleclear": " - Clears the console\n", - "speed": " - Multiplies the player speed by the given value\n", - "noclip": " - Toggles the player collision and lets you walk through walls and world barriers\n", - "stickycamera": " - Toggles the camera mode. Stickycamera follows the player without limits and extra animation\n", - "playername": " - Renames the player\n", - "reload": " - Reloads the current level (for softlocks or other issues)\n", - "visiblecollision": " - Toggles if collision shapes hitboxes and hitmarkers are visible. Use 'reload' to see changes!\n" + "help": " [command] - Shows help or help for a specific command", + "consoleclear": " - Clears the console", + "speed": " - Multiplies the player speed by the given value", + "noclip": " - Toggles the player collision and lets you walk through walls and world barriers", + "stickycamera": " - Toggles the camera mode. Stickycamera follows the player without limits and extra animation", + "playername": " - Renames the player", + "closedialogue": "Closes the current dialogue box", + "reload": " - Reloads the current level (for softlocks or other issues)", + "visiblecollision": " - Toggles if collision shapes hitboxes and hitmarkers are visible. Use 'reload' to see changes!" } \ No newline at end of file diff --git a/src/scene-scripts/console/console.cs b/src/scene-scripts/console/console.cs index 937b569..dd75376 100644 --- a/src/scene-scripts/console/console.cs +++ b/src/scene-scripts/console/console.cs @@ -3,7 +3,7 @@ using Godot.Collections; public partial class console : PopupPanel { - private RichTextLabel textblock; + private static RichTextLabel textblock; private LineEdit line; private Dictionary commandDict; private string error = "Not found! :(\n"; @@ -31,7 +31,7 @@ public partial class console : PopupPanel private void OnLineEditTextSubmitted(string command) { line.Clear(); - if (command.Length != 0) textblock.AddText(player_variables.PlayerName + " > " + command + "\n"); + if (command.Length != 0) Print(player_variables.PlayerName + " > " + command + "\n"); Variant args; if (command.Split(' ').Length == 2 && commandDict.ContainsKey(command.Split(' ')[0].ToLower())) { @@ -51,18 +51,21 @@ public partial class console : PopupPanel { Call(command.ToLower()); } - else if (command.Length != 0) textblock.AddText(error); + else if (command.Length != 0) Print(error); + } + public static void Print(string text) + { + textblock.AddText(text + "\n"); } - private void help() { - textblock.AddText("==================================== Help ====================================\n"); + Print("==================================== Help ====================================\n"); for (int i = 0; i < commandDict.Count; i++) { - textblock.AddText((i + 1) + ". " + Json.ParseString(commandDict.Keys.ToString()).AsStringArray()[i]); - textblock.AddText(Json.ParseString(commandDict.Values.ToString()).AsStringArray()[i]); + Print((i + 1) + ". " + Json.ParseString(commandDict.Keys.ToString()).AsStringArray()[i]); + Print(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 @@ -70,12 +73,12 @@ public partial class console : PopupPanel key = key.ToLower(); if (key.Length != 0 && commandDict.ContainsKey(key)) { - textblock.AddText(key); - textblock.AddText(commandDict[key].ToString()); + Print(key); + Print(commandDict[key].ToString()); } else { - textblock.AddText(error); + Print(error); help("help"); }; } @@ -83,39 +86,44 @@ public partial class console : PopupPanel private void speed(float multiplier) { player.speed = Mathf.Clamp(multiplier, 0.01f, 15f); - textblock.AddText("Set player speed to " + Mathf.Clamp(multiplier, 0.01f, 15f) + "\n"); + Print("Set player speed to " + Mathf.Clamp(multiplier, 0.01f, 15f)); } private void noclip() { - try { textblock.AddText(player.CollisionToggle()); } + try { Print(player.CollisionToggle()); } catch { - textblock.AddText("Player is not accessable\n"); + Print("Player is not accessable"); help("noclip"); } } private void stickycamera() { - try { textblock.AddText(player.CheatCam()); } + try { Print(player.CheatCam()); } catch { - textblock.AddText("Player is not accessable\n"); + Print("Player is not accessable"); help("stickycamera"); } } private void playername(string name) { player_variables.PlayerName = name; - textblock.AddText("Your new name is now: " + player_variables.PlayerName + "\n"); + Print("Your new name is now: " + player_variables.PlayerName); + } + private void closedialogue() + { + dialog_bubble.forceClose = true; + Print("Dialogue got closed!"); } private void reload() { GetTree().ReloadCurrentScene(); - textblock.AddText("Level got reloaded!\n"); + Print("Level got reloaded!"); } private void visiblecollision() { GetTree().DebugCollisionsHint = !GetTree().DebugCollisionsHint; - textblock.AddText("Visible collision shapes and hitmarker now set to: " + GetTree().DebugCollisionsHint + "\nUse 'reload' to see changes!\n"); + Print("Visible collision shapes and hitmarker now set to: " + GetTree().DebugCollisionsHint + "\nUse 'reload' to see changes!"); } } \ No newline at end of file diff --git a/src/scene-scripts/dialogue-system/dialog_bubble.cs b/src/scene-scripts/dialogue-system/dialog_bubble.cs index 045e9fd..9425c86 100644 --- a/src/scene-scripts/dialogue-system/dialog_bubble.cs +++ b/src/scene-scripts/dialogue-system/dialog_bubble.cs @@ -10,6 +10,7 @@ public partial class dialog_bubble : CanvasLayer public Timer typewriterTimer; public string title; public Area2D triggerArea; + public static bool forceClose; /*TODO: - Dont repeat the same randomized dialogue after you get asked do you need something "else" - add tree support (example: "story" key) @@ -24,6 +25,7 @@ public partial class dialog_bubble : CanvasLayer } public void GetDialog(string file, Area2D actor) { + console.Print("Loaded dialogue from: " + file + "\nClose dialogue with 'closedialogue'"); triggerArea = actor; title = actor.Get("title").AsString(); bool introducedVillager = actor.Get("introducedVillager").AsBool(); @@ -69,7 +71,7 @@ public partial class dialog_bubble : CanvasLayer { if (Input.IsActionJustPressed("ui_cancel")) richText.VisibleCharacters = richText.Text.Length; - if (Input.IsActionJustPressed("ui_accept") && GetNode("box/panel_container").Visible == false + if (Input.IsActionJustPressed("ui_accept") && GetNode("/root/Console").Visible == false && GetNode("box/panel_container").Visible == false && richText.VisibleCharacters == -1 | Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length <= richText.VisibleCharacters) { if (dlgPointer < dlgLines.AsGodotArray().Count) @@ -89,7 +91,7 @@ public partial class dialog_bubble : CanvasLayer } dlgPointer++; } - if (dlgPointer > dlgLines.AsGodotArray().Count) + if (dlgPointer > dlgLines.AsGodotArray().Count || forceClose) CloseDialog(); } public void UpdateDialog() @@ -127,7 +129,7 @@ public partial class dialog_bubble : CanvasLayer if (GetNode("box/panel_container").Visible == true && GetNode("box/panel_container/margin_container").GetChild(0).GetChild