diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2021-07-04 14:47:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-04 14:47:44 +0200 |
commit | 8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a (patch) | |
tree | 1e9510a1c2ff7f6c0eaaba211c38e0a855b36ca9 /cwd/assets/altcraft/scripts | |
parent | Merge pull request #64 from LaG1924/ftr/render-optimization (diff) | |
parent | Added screenshot-mode (diff) | |
download | AltCraft-8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a.tar AltCraft-8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a.tar.gz AltCraft-8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a.tar.bz2 AltCraft-8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a.tar.lz AltCraft-8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a.tar.xz AltCraft-8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a.tar.zst AltCraft-8a4075c58b4a078cdbbe8b394eb5ae761fdaff6a.zip |
Diffstat (limited to 'cwd/assets/altcraft/scripts')
-rw-r--r-- | cwd/assets/altcraft/scripts/init.lua | 36 | ||||
-rw-r--r-- | cwd/assets/altcraft/scripts/ui.lua | 30 |
2 files changed, 65 insertions, 1 deletions
diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua index 790bab0..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 () @@ -15,6 +16,9 @@ function plugin.onLoad () con:LoadDocument("altcraft/ui/hud") con:LoadDocument("altcraft/ui/pause") 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() @@ -70,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,'&','&') + msg = string.gsub(msg,'<','<') + msg = string.gsub(msg,'>','>') + msg = string.gsub(msg,'""','"') + msg = string.gsub(msg,"''",''') + + 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 392ad27..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() @@ -106,13 +123,26 @@ function UpdateUi() local selection = AC.GetGameState():GetSelectionStatus() if selection.isBlockSelected then bid = wrld:GetBlockId(selection.selectedBlock) + binfo = AC.GetBlockInfo(bid) + light = wrld:GetBlockLight(selection.selectedBlock) + skyLight = wrld:GetBlockSkyLight(selection.selectedBlock) doc:GetElementById('dbg-select-pos').inner_rml = tostring(selection.selectedBlock) doc:GetElementById('dbg-select-bid').inner_rml = string.format("%d:%d", bid.id, bid.state) + doc:GetElementById('dbg-select-name').inner_rml = string.format("%s:%s", binfo.blockstate, binfo.variant) + doc:GetElementById('dbg-select-light').inner_rml = string.format("%d:%d", light, skyLight) else doc:GetElementById('dbg-select-pos').inner_rml = "" doc:GetElementById('dbg-select-bid').inner_rml = "" + doc:GetElementById('dbg-select-name').inner_rml = "" + doc:GetElementById('dbg-select-light').inner_rml = "" end + doc:GetElementById('dbg-sections-loaded').inner_rml = AC.GetDebugValue(0) + doc:GetElementById('dbg-sections-renderer').inner_rml = AC.GetDebugValue(1) + doc:GetElementById('dbg-sections-ready').inner_rml = AC.GetDebugValue(2) + doc:GetElementById('dbg-sections-culled').inner_rml = AC.GetDebugValue(0) - AC.GetDebugValue(5) + doc:GetElementById('dbg-rendered-faces').inner_rml = AC.GetDebugValue(4) + local player = AC.GetGameState():GetPlayerStatus() local playerHp = string.format("%.0f", player.health) doc:GetElementById('status-hp').inner_rml = playerHp |