added dialogue close command

This commit is contained in:
2023-02-24 12:53:44 +01:00
parent fef7db9b7a
commit 2c7a696821
4 changed files with 46 additions and 30 deletions

View File

@@ -10,8 +10,11 @@ public partial class essential : Node
//Checks if using Keyboard or controller and giving out current controller //Checks if using Keyboard or controller and giving out current controller
if (@event is InputEventKey || @event is InputEventMouseButton || currentController == "") if (@event is InputEventKey || @event is InputEventMouseButton || currentController == "")
currentController = "PC"; currentController = "PC";
if (@event is InputEventJoypadButton) if (@event is InputEventJoypadButton && currentController != Input.GetJoyName(0))
{
currentController = Input.GetJoyName(0); currentController = Input.GetJoyName(0);
console.Print("Current controller device: " + currentController);
}
} }
public override void _Process(double delta) public override void _Process(double delta)
{ {

View File

@@ -1,10 +1,11 @@
{ {
"help": " [command] - Shows help or help for a specific command\n", "help": " [command] - Shows help or help for a specific command",
"consoleclear": " - Clears the console\n", "consoleclear": " - Clears the console",
"speed": " <multiplier number> - Multiplies the player speed by the given value\n", "speed": " <multiplier number> - Multiplies the player speed by the given value",
"noclip": " - Toggles the player collision and lets you walk through walls and world barriers\n", "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\n", "stickycamera": " - Toggles the camera mode. Stickycamera follows the player without limits and extra animation",
"playername": " <new name> - Renames the player\n", "playername": " <new name> - Renames the player",
"reload": " - Reloads the current level (for softlocks or other issues)\n", "closedialogue": "Closes the current dialogue box",
"visiblecollision": " - Toggles if collision shapes hitboxes and hitmarkers are visible. Use 'reload' to see changes!\n" "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!"
} }

View File

@@ -3,7 +3,7 @@ using Godot.Collections;
public partial class console : PopupPanel public partial class console : PopupPanel
{ {
private RichTextLabel textblock; private static RichTextLabel textblock;
private LineEdit line; private LineEdit line;
private Dictionary commandDict; private Dictionary commandDict;
private string error = "Not found! :(\n"; private string error = "Not found! :(\n";
@@ -31,7 +31,7 @@ public partial class console : PopupPanel
private void OnLineEditTextSubmitted(string command) private void OnLineEditTextSubmitted(string command)
{ {
line.Clear(); 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; Variant args;
if (command.Split(' ').Length == 2 && commandDict.ContainsKey(command.Split(' ')[0].ToLower())) if (command.Split(' ').Length == 2 && commandDict.ContainsKey(command.Split(' ')[0].ToLower()))
{ {
@@ -51,18 +51,21 @@ public partial class console : PopupPanel
{ {
Call(command.ToLower()); 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() private void help()
{ {
textblock.AddText("==================================== Help ====================================\n"); Print("==================================== Help ====================================\n");
for (int i = 0; i < commandDict.Count; i++) for (int i = 0; i < commandDict.Count; i++)
{ {
textblock.AddText((i + 1) + ". " + Json.ParseString(commandDict.Keys.ToString()).AsStringArray()[i]); Print((i + 1) + ". " + Json.ParseString(commandDict.Keys.ToString()).AsStringArray()[i]);
textblock.AddText(Json.ParseString(commandDict.Values.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 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(); key = key.ToLower();
if (key.Length != 0 && commandDict.ContainsKey(key)) if (key.Length != 0 && commandDict.ContainsKey(key))
{ {
textblock.AddText(key); Print(key);
textblock.AddText(commandDict[key].ToString()); Print(commandDict[key].ToString());
} }
else else
{ {
textblock.AddText(error); Print(error);
help("help"); help("help");
}; };
} }
@@ -83,39 +86,44 @@ public partial class console : PopupPanel
private void speed(float multiplier) private void speed(float multiplier)
{ {
player.speed = Mathf.Clamp(multiplier, 0.01f, 15f); 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() private void noclip()
{ {
try { textblock.AddText(player.CollisionToggle()); } try { Print(player.CollisionToggle()); }
catch catch
{ {
textblock.AddText("Player is not accessable\n"); Print("Player is not accessable");
help("noclip"); help("noclip");
} }
} }
private void stickycamera() private void stickycamera()
{ {
try { textblock.AddText(player.CheatCam()); } try { Print(player.CheatCam()); }
catch catch
{ {
textblock.AddText("Player is not accessable\n"); Print("Player is not accessable");
help("stickycamera"); help("stickycamera");
} }
} }
private void playername(string name) private void playername(string name)
{ {
player_variables.PlayerName = 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() private void reload()
{ {
GetTree().ReloadCurrentScene(); GetTree().ReloadCurrentScene();
textblock.AddText("Level got reloaded!\n"); Print("Level got reloaded!");
} }
private void visiblecollision() private void visiblecollision()
{ {
GetTree().DebugCollisionsHint = !GetTree().DebugCollisionsHint; 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!");
} }
} }

View File

@@ -10,6 +10,7 @@ public partial class dialog_bubble : CanvasLayer
public Timer typewriterTimer; public Timer typewriterTimer;
public string title; public string title;
public Area2D triggerArea; public Area2D triggerArea;
public static bool forceClose;
/*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)
@@ -24,6 +25,7 @@ public partial class dialog_bubble : CanvasLayer
} }
public void GetDialog(string file, Area2D actor) public void GetDialog(string file, Area2D actor)
{ {
console.Print("Loaded dialogue from: " + file + "\nClose dialogue with 'closedialogue'");
triggerArea = actor; triggerArea = actor;
title = actor.Get("title").AsString(); title = actor.Get("title").AsString();
bool introducedVillager = actor.Get("introducedVillager").AsBool(); 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_cancel")) richText.VisibleCharacters = richText.Text.Length;
if (Input.IsActionJustPressed("ui_accept") && GetNode<PanelContainer>("box/panel_container").Visible == false if (Input.IsActionJustPressed("ui_accept") && GetNode<console>("/root/Console").Visible == false && 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)
@@ -89,7 +91,7 @@ public partial class dialog_bubble : CanvasLayer
} }
dlgPointer++; dlgPointer++;
} }
if (dlgPointer > dlgLines.AsGodotArray().Count) if (dlgPointer > dlgLines.AsGodotArray().Count || forceClose)
CloseDialog(); CloseDialog();
} }
public void UpdateDialog() public void UpdateDialog()
@@ -127,7 +129,7 @@ public partial class dialog_bubble : CanvasLayer
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(); //BUG: dialogue box breaks while game console is open.
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;
@@ -151,6 +153,7 @@ public partial class dialog_bubble : CanvasLayer
break; break;
} }
} }
public void CloseDialog() public void CloseDialog()
{ {
Visible = false; Visible = false;
@@ -159,5 +162,6 @@ public partial class dialog_bubble : CanvasLayer
GetNode<Label>("box/name_label").Text = "???"; GetNode<Label>("box/name_label").Text = "???";
richText.Text = ""; richText.Text = "";
if (GetParent().Name == "player") player.allowMovement = true; if (GetParent().Name == "player") player.allowMovement = true;
forceClose = false;
} }
} }