From 8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Fri, 18 Jun 2021 17:14:19 +0500 Subject: Implemented RmlFileInterface --- cwd/assets/altcraft/scripts/init.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'cwd/assets/altcraft/scripts/init.lua') diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua index 96b5ec3..b9b34a7 100644 --- a/cwd/assets/altcraft/scripts/init.lua +++ b/cwd/assets/altcraft/scripts/init.lua @@ -9,11 +9,14 @@ local plugin = { } function plugin.onLoad () - print("Loaded AltCraft plugin!") + rmlui:LoadFontFace("altcraft/fonts/OpenSans-Regular") end function plugin.onChangeState (newState) - AC.LogWarning("New state: "..newState) + if newState == "MainMenu" then + local con = rmlui.contexts["default"] + con:LoadDocument("altcraft/ui/main-menu"):Show() + end end function plugin.onUnload () -- cgit v1.2.3 From d8710c9c252f49bf442590d47e8b79a9c1231ead Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 20 Jun 2021 01:04:53 +0500 Subject: Added game menus --- cwd/assets/altcraft/scripts/init.lua | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'cwd/assets/altcraft/scripts/init.lua') 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 -- cgit v1.2.3 From 14939a87010ab17425d73b53829aa22c17c96d79 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Tue, 22 Jun 2021 03:38:08 +0500 Subject: Added Settings UI --- cwd/assets/altcraft/scripts/init.lua | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'cwd/assets/altcraft/scripts/init.lua') diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua index bf7739e..c626375 100644 --- a/cwd/assets/altcraft/scripts/init.lua +++ b/cwd/assets/altcraft/scripts/init.lua @@ -14,6 +14,7 @@ function plugin.onLoad () con:LoadDocument("altcraft/ui/main-menu"):Show() con:LoadDocument("altcraft/ui/hud") con:LoadDocument("altcraft/ui/pause") + con:LoadDocument("altcraft/ui/options") end function plugin.onChangeState (newState) @@ -41,33 +42,11 @@ 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 +require("altcraft/ui") function plugin.onTick (deltaTime) + UpdateUi() 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 -- cgit v1.2.3 From 0d2b4783824730ba2208f5caaef27c5c61a56fa5 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Tue, 22 Jun 2021 04:40:04 +0500 Subject: Minor changes to Ui scripts --- cwd/assets/altcraft/scripts/init.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cwd/assets/altcraft/scripts/init.lua') diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua index c626375..790bab0 100644 --- a/cwd/assets/altcraft/scripts/init.lua +++ b/cwd/assets/altcraft/scripts/init.lua @@ -11,10 +11,15 @@ local plugin = { function plugin.onLoad () rmlui:LoadFontFace("altcraft/fonts/OpenSans-Regular") local con = rmlui.contexts["default"] - con:LoadDocument("altcraft/ui/main-menu"):Show() + local uiMainMenu = con:LoadDocument("altcraft/ui/main-menu") con:LoadDocument("altcraft/ui/hud") con:LoadDocument("altcraft/ui/pause") con:LoadDocument("altcraft/ui/options") + + uiMainMenu:Show() + AC.Settings.Load() + uiMainMenu:GetElementById("username"):SetAttribute("value", AC.Settings.Read("username","Username"..tostring(math.random(10000)))) + uiMainMenu:GetElementById("hostname"):SetAttribute("value",AC.Settings.Read("hostname","127.0.0.1")) end function plugin.onChangeState (newState) -- cgit v1.2.3