initial shit
This commit is contained in:
66
GameShit/PlayerController/ChatSystem/ChatBox.gd
Normal file
66
GameShit/PlayerController/ChatSystem/ChatBox.gd
Normal file
@@ -0,0 +1,66 @@
|
||||
extends Control
|
||||
|
||||
## This entire script is just for handling the ChatBox UI
|
||||
## if you are here looking for command handlers
|
||||
## they are in GameShit/ChatSystem/commands
|
||||
|
||||
## if you are looking for chat var storage
|
||||
## they are in GameShit/ChatSystem/ChatBox.gd
|
||||
|
||||
var Commands : Dictionary = {
|
||||
"give": CommandHandler.registerCommand("base:giveItem").new(),
|
||||
"say": CommandHandler.registerCommand("base:say").new()
|
||||
}
|
||||
|
||||
var language = LanguageManager.loadLanguage()
|
||||
|
||||
func _parseMessage():
|
||||
var messageContents : String = %Input.text
|
||||
|
||||
if messageContents.begins_with("/"):
|
||||
var command = messageContents.right(-1)
|
||||
runCommand(command)
|
||||
%Input.text = ""
|
||||
MainGame.hideChatbox.emit()
|
||||
else:
|
||||
sendMessage(messageContents)
|
||||
%Input.text = ""
|
||||
MainGame.hideChatbox.emit()
|
||||
|
||||
func sendMessage(message):
|
||||
%TextDisplay.newline()
|
||||
%TextDisplay.add_text("{a}: {b}".format({"a": MainGame.username, "b": message}))
|
||||
|
||||
func sendMessageAs(user, message):
|
||||
%TextDisplay.newline()
|
||||
%TextDisplay.add_text("{a}: {b}".format({"a": user, "b": message}))
|
||||
|
||||
func sendSystemErrorMessage(error:Dictionary):
|
||||
%TextDisplay.newline()
|
||||
%TextDisplay.add_text("Error: {Error} {Details}".format({"Error": language[error["type"]], "Details": error["caller"]}))
|
||||
func _ready() -> void:
|
||||
## here imma add callbacks to signals for chatbox
|
||||
CommandBus.sendChatMessage.connect(sendMessage)
|
||||
CommandBus.sendChatMessageAs.connect(sendMessageAs)
|
||||
CommandBus.castError.connect(sendSystemErrorMessage)
|
||||
|
||||
func runCommand(message: String):
|
||||
var regex = RegEx.new()
|
||||
regex.compile("(\"[^\"]*\"|'[^']*'|\\S+)")
|
||||
var matches = regex.search_all(message)
|
||||
var commandArgs = []
|
||||
for m in matches:
|
||||
var arg = m.get_string()
|
||||
if (arg.begins_with("\"") and arg.ends_with("\"")) or (arg.begins_with("'") and arg.ends_with("'")):
|
||||
arg = arg.substr(1, arg.length() - 2)
|
||||
commandArgs.append(arg)
|
||||
if commandArgs.size() > 0:
|
||||
var command_name = commandArgs[0]
|
||||
if Commands.has(command_name):
|
||||
Commands[command_name].runCommand(commandArgs.slice(1))
|
||||
else:
|
||||
CommandBus.castError.emit({"type": "base.command.commandNotFoundError", "caller": command_name})
|
||||
|
||||
|
||||
func _on_input_text_submitted(new_text: String) -> void:
|
||||
_parseMessage()
|
||||
1
GameShit/PlayerController/ChatSystem/ChatBox.gd.uid
Normal file
1
GameShit/PlayerController/ChatSystem/ChatBox.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bv7jebheo3yyf
|
||||
73
GameShit/PlayerController/ChatSystem/ChatBox.tscn
Normal file
73
GameShit/PlayerController/ChatSystem/ChatBox.tscn
Normal file
@@ -0,0 +1,73 @@
|
||||
[gd_scene format=3 uid="uid://bliihydr5ja7g"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bv7jebheo3yyf" path="res://GameShit/PlayerController/ChatSystem/ChatBox.gd" id="1_u837s"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bq26o"]
|
||||
bg_color = Color(0.043137256, 0.043137256, 0.043137256, 0.6509804)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_u837s"]
|
||||
bg_color = Color(0.14767182, 0.14767182, 0.14767176, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_aksbt"]
|
||||
bg_color = Color(0.24840015, 0.24840021, 0.24840006, 1)
|
||||
|
||||
[node name="ChatBox" type="Control" unique_id=756491211]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_u837s")
|
||||
|
||||
[node name="Panel" type="Panel" parent="." unique_id=1311922339]
|
||||
layout_mode = 0
|
||||
offset_right = 384.0
|
||||
offset_bottom = 264.0
|
||||
|
||||
[node name="Panel2" type="Panel" parent="Panel" unique_id=1474934579]
|
||||
layout_mode = 0
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = 376.0
|
||||
offset_bottom = 256.0
|
||||
|
||||
[node name="TextDisplay" type="RichTextLabel" parent="Panel/Panel2" unique_id=575967085]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 0
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = 360.0
|
||||
offset_bottom = 200.0
|
||||
theme_override_font_sizes/normal_font_size = 10
|
||||
theme_override_font_sizes/bold_font_size = 10
|
||||
theme_override_font_sizes/bold_italics_font_size = 10
|
||||
theme_override_font_sizes/italics_font_size = 10
|
||||
theme_override_font_sizes/mono_font_size = 10
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_bq26o")
|
||||
theme_override_styles/focus = SubResource("StyleBoxFlat_u837s")
|
||||
bbcode_enabled = true
|
||||
|
||||
[node name="Input" type="LineEdit" parent="Panel/Panel2" unique_id=484855696]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 0
|
||||
offset_left = 8.0
|
||||
offset_top = 208.0
|
||||
offset_right = 304.0
|
||||
offset_bottom = 239.0
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_aksbt")
|
||||
theme_override_styles/read_only = SubResource("StyleBoxFlat_aksbt")
|
||||
theme_override_styles/focus = SubResource("StyleBoxFlat_aksbt")
|
||||
placeholder_text = "Type a message or command!"
|
||||
|
||||
[node name="Send" type="Button" parent="Panel/Panel2" unique_id=1540729483]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 0
|
||||
offset_left = 312.0
|
||||
offset_top = 208.0
|
||||
offset_right = 360.0
|
||||
offset_bottom = 240.0
|
||||
text = "Send"
|
||||
|
||||
[connection signal="text_submitted" from="Panel/Panel2/Input" to="." method="_on_input_text_submitted"]
|
||||
[connection signal="pressed" from="Panel/Panel2/Send" to="." method="_parseMessage"]
|
||||
10
GameShit/PlayerController/ChatSystem/CommandHandler.gd
Normal file
10
GameShit/PlayerController/ChatSystem/CommandHandler.gd
Normal file
@@ -0,0 +1,10 @@
|
||||
extends Node
|
||||
|
||||
## all command variables are stuck in here, idk why i did this but its like 5am and im done with this shit atp
|
||||
|
||||
var lastMessage = ""
|
||||
|
||||
|
||||
func registerCommand(CommandID:String):
|
||||
var parts = CommandID.split(":")
|
||||
return load("res://GameShit/PlayerController/ChatSystem/commands/{namespace}/{id}.gd".format({"namespace": parts[0], "id": parts[1]}))
|
||||
@@ -0,0 +1 @@
|
||||
uid://jo7ml3jp3sd7
|
||||
@@ -0,0 +1,5 @@
|
||||
extends Node
|
||||
|
||||
func runCommand(args:Array):
|
||||
print("test")
|
||||
InventoryBus.givePlayerItem.emit(args[0])
|
||||
@@ -0,0 +1 @@
|
||||
uid://bvqkox22uye4s
|
||||
@@ -0,0 +1,4 @@
|
||||
extends Node
|
||||
|
||||
func runCommand(args:Array):
|
||||
CommandBus.sendChatMessageAs.emit(args[0], args[1])
|
||||
@@ -0,0 +1 @@
|
||||
uid://bxu4o5bts4nwf
|
||||
Reference in New Issue
Block a user