summaryrefslogtreecommitdiffstats
path: root/cwd/assets/altcraft/scripts/init.lua
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-06-19 22:04:53 +0200
committerLaG1924 <lag1924@gmail.com>2021-06-19 22:13:09 +0200
commitd8710c9c252f49bf442590d47e8b79a9c1231ead (patch)
treec8225953444ead9e4be5a7c586bc21e3c870ab6b /cwd/assets/altcraft/scripts/init.lua
parentImplemented RmlFileInterface (diff)
downloadAltCraft-d8710c9c252f49bf442590d47e8b79a9c1231ead.tar
AltCraft-d8710c9c252f49bf442590d47e8b79a9c1231ead.tar.gz
AltCraft-d8710c9c252f49bf442590d47e8b79a9c1231ead.tar.bz2
AltCraft-d8710c9c252f49bf442590d47e8b79a9c1231ead.tar.lz
AltCraft-d8710c9c252f49bf442590d47e8b79a9c1231ead.tar.xz
AltCraft-d8710c9c252f49bf442590d47e8b79a9c1231ead.tar.zst
AltCraft-d8710c9c252f49bf442590d47e8b79a9c1231ead.zip
Diffstat (limited to 'cwd/assets/altcraft/scripts/init.lua')
-rw-r--r--cwd/assets/altcraft/scripts/init.lua49
1 files changed, 46 insertions, 3 deletions
diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua
index b9b34a7..bf7739e 100644
--- a/cwd/assets/altcraft/scripts/init.lua
+++ b/cwd/assets/altcraft/scripts/init.lua
@@ -10,12 +10,30 @@ local plugin = {
function plugin.onLoad ()
rmlui:LoadFontFace("altcraft/fonts/OpenSans-Regular")
+ local con = rmlui.contexts["default"]
+ con:LoadDocument("altcraft/ui/main-menu"):Show()
+ con:LoadDocument("altcraft/ui/hud")
+ con:LoadDocument("altcraft/ui/pause")
end
function plugin.onChangeState (newState)
- if newState == "MainMenu" then
- local con = rmlui.contexts["default"]
- con:LoadDocument("altcraft/ui/main-menu"):Show()
+ local toHide = {}
+ local toShow = {}
+
+ for i,doc in ipairs(rmlui.contexts["default"].documents) do
+ if doc.title == newState then
+ toShow[#toShow+1]=doc
+ else
+ toHide[#toHide+1]=doc
+ end
+ end
+
+ for i,doc in ipairs(toHide) do
+ doc:Hide()
+ end
+
+ for i,doc in ipairs(toShow) do
+ doc:Show()
end
end
@@ -23,8 +41,33 @@ function plugin.onUnload ()
AC.LogInfo("AC Core unloaded")
end
+local function UpdateHud()
+ local doc = {}
+ for i,d in ipairs(rmlui.contexts["default"].documents) do
+ if d.title == "Playing" then
+ doc = d
+ end
+ end
+
+ local playerEnt = AC.GetGameState():GetPlayer()
+ doc:GetElementById('dbg-pos').inner_rml = string.format("%.1f %.1f %.1f", playerEnt.pos.x, playerEnt.pos.y, playerEnt.pos.z)
+
+ local selection = AC.GetGameState():GetSelectionStatus()
+ if selection.isBlockSelected then
+ doc:GetElementById('dbg-select-pos').inner_rml = tostring(selection.selectedBlock)
+ else
+ doc:GetElementById('dbg-select-pos').inner_rml = ""
+ end
+
+ local player = AC.GetGameState():GetPlayerStatus()
+ local playerHp = string.format("%.0f", player.health)
+ doc:GetElementById('status-hp').inner_rml = playerHp
+ doc:GetElementById('status-hp-bar'):SetAttribute("value", playerHp)
+end
+
function plugin.onTick (deltaTime)
if AC.GetGameState() and AC.GetGameState():GetPlayer() and AC.GetGameState():GetTimeStatus().worldAge > 0 then
+ UpdateHud()
-- local player = AC.GetGameState():GetPlayer()
-- player.pos.x = player.pos.x + deltaTime * 0.5