summaryrefslogtreecommitdiffstats
path: root/cwd/assets/altcraft/scripts
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-07-04 14:21:50 +0200
committerLaG1924 <lag1924@gmail.com>2021-07-04 14:21:50 +0200
commitb37e52c9facd4c41183c016fd5c91f8829407766 (patch)
tree7672459f9480a7b4cb0d95cdf09823d5072746fa /cwd/assets/altcraft/scripts
parentAdded RmlDebugger (diff)
downloadAltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.gz
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.bz2
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.lz
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.xz
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.tar.zst
AltCraft-b37e52c9facd4c41183c016fd5c91f8829407766.zip
Diffstat (limited to 'cwd/assets/altcraft/scripts')
-rw-r--r--cwd/assets/altcraft/scripts/init.lua34
-rw-r--r--cwd/assets/altcraft/scripts/ui.lua17
2 files changed, 50 insertions, 1 deletions
diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua
index e13fc81..b60a988 100644
--- a/cwd/assets/altcraft/scripts/init.lua
+++ b/cwd/assets/altcraft/scripts/init.lua
@@ -6,6 +6,7 @@ local plugin = {
onChangeState = nil,
onTick = nil,
onRequestBlockInfo = nil,
+ onChatMessage = nil,
}
function plugin.onLoad ()
@@ -17,6 +18,7 @@ function plugin.onLoad ()
con:LoadDocument("altcraft/ui/options")
con:LoadDocument("altcraft/ui/loading")
con:LoadDocument("altcraft/ui/respawn")
+ con:LoadDocument("altcraft/ui/chat")
uiMainMenu:Show()
AC.Settings.Load()
@@ -72,9 +74,39 @@ function plugin.onRequestBlockInfo(blockPos)
return blocks.GetBlockInfo(blockPos)
end
+function plugin.onChatMessage(chat, pos)
+ local chatDoc = {}
+ for i,d in ipairs(rmlui.contexts["default"].documents) do
+ if d.title == "Chat" then
+ chatDoc = d
+ end
+ end
+
+ local msg = chat:ToPlainText()
+ msg = string.gsub(msg,'&','&amp;')
+ msg = string.gsub(msg,'<','&lt;')
+ msg = string.gsub(msg,'>','&gt;')
+ msg = string.gsub(msg,'""','&quot;')
+ msg = string.gsub(msg,"''",'&apos;')
+
+ local color = ""
+ if pos == 0 then
+ color = ""
+ elseif pos == 1 then
+ color = 'style="color: #BBBBBB"'
+ elseif pos == 2 then
+ color = 'style="color: maroon"'
+ else
+ color = 'style="color: navy"'
+ end
+
+ chatDoc:GetElementById('chat').inner_rml = chatDoc:GetElementById('chat').inner_rml .. string.format('<p class="chat-msg" %s>%s</p>', color, msg)
+ MoveChatToBottom = true
+end
+
AC.RegisterDimension(0, Dimension.new("overworld", true))
AC.RegisterDimension(-1, Dimension.new("the_nether", false))
AC.RegisterDimension(1, Dimension.new("the_end", false))
AC.RegisterPlugin(plugin)
-plugin = nil \ No newline at end of file
+plugin = nil
diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua
index 98f0fae..b938737 100644
--- a/cwd/assets/altcraft/scripts/ui.lua
+++ b/cwd/assets/altcraft/scripts/ui.lua
@@ -53,6 +53,16 @@ function ConnectToServer(doc)
doc:GetElementById('username'):GetAttribute('value'))
end
+function SendChatMessage(doc)
+ local msg = doc:GetElementById("chat-input"):GetAttribute("value")
+ if msg == nil then
+ return
+ end
+ doc:GetElementById("chat-input"):SetAttribute("value", "")
+
+ AC.SendChatMessage(msg)
+end
+
function OptionsDefaultHandler(event)
local input = event.current_element.previous_sibling
local id = input:GetAttribute("id")
@@ -85,14 +95,21 @@ end
function UpdateUi()
local doc = {}
local uiDoc = {}
+ local chatDoc = {}
for i,d in ipairs(rmlui.contexts["default"].documents) do
if d.title == "Playing" then
doc = d
elseif d.title == "Options" then
uiDoc = d
+ elseif d.title == "Chat" then
+ chatDoc = d
end
end
+ if MoveChatToBottom ~= nil and MoveChatToBottom == true then
+ chatDoc:GetElementById('chat').scroll_top = chatDoc:GetElementById('chat').scroll_height
+ end
+
if AC.GetGameState() and AC.GetGameState():GetPlayer() and AC.GetGameState():GetTimeStatus().worldAge > 0 then
local time = AC.GetTime()
local rawFps = 1.0 / time:GetRealDeltaS()