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 ++++++++++++++++++++++-- cwd/assets/altcraft/ui/hud-styles.rcss | 56 ++++++++++++++++++++++++++++ cwd/assets/altcraft/ui/hud.rml | 20 ++++++++++ cwd/assets/altcraft/ui/main-menu-styles.rcss | 48 +----------------------- cwd/assets/altcraft/ui/main-menu.rml | 9 +++-- cwd/assets/altcraft/ui/mc-styles.rcss | 46 +++++++++++++++++++++++ cwd/assets/altcraft/ui/pause-styles.rcss | 43 +++++++++++++++++++++ cwd/assets/altcraft/ui/pause.rml | 15 ++++++++ 8 files changed, 232 insertions(+), 54 deletions(-) create mode 100644 cwd/assets/altcraft/ui/hud-styles.rcss create mode 100644 cwd/assets/altcraft/ui/hud.rml create mode 100644 cwd/assets/altcraft/ui/mc-styles.rcss create mode 100644 cwd/assets/altcraft/ui/pause-styles.rcss create mode 100644 cwd/assets/altcraft/ui/pause.rml (limited to 'cwd') 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 diff --git a/cwd/assets/altcraft/ui/hud-styles.rcss b/cwd/assets/altcraft/ui/hud-styles.rcss new file mode 100644 index 0000000..61f4147 --- /dev/null +++ b/cwd/assets/altcraft/ui/hud-styles.rcss @@ -0,0 +1,56 @@ +.body-hud { + +} + +.dbg-hud { + background-color: #00000055; + border-color: black; + border-width: 2dp; + font-size: 20dp; + color: white; + padding: 3dp; + text-align: left; + margin: 3dp auto auto 3dp; + position: fixed; +} + +p { + display: block; +} + +span { + display: inline-block; +} + +.status-hud { + background-color: #00000055; + border-color: black; + border-width: 2dp; + font-size: 20dp; + color: white; + padding: 2dp; + margin: 10dp; + text-align: center; + bottom: 0; + position: fixed; +} + +#status-hp-bar { + background-color: maroon; + border-color: black; + margin-left: 5dp; + width: 200dp; + height: 10dp; +} + +#status-hp-bar fill { + background-color: red; +} + +.crosshair-hud { + display: table-cell; + color: white; + font-size: 50dp; + text-align: center; + vertical-align: middle; +} \ No newline at end of file diff --git a/cwd/assets/altcraft/ui/hud.rml b/cwd/assets/altcraft/ui/hud.rml new file mode 100644 index 0000000..5a1d7ce --- /dev/null +++ b/cwd/assets/altcraft/ui/hud.rml @@ -0,0 +1,20 @@ + + + + + Playing + + +
+

FPS: ∞?

+

Pos: ∞?

+

Select pos: ∞?

+
+
+

HP: ∞?

+
+
+
+
+
+ +
diff --git a/cwd/assets/altcraft/ui/main-menu-styles.rcss b/cwd/assets/altcraft/ui/main-menu-styles.rcss index ee86894..8b8b9fb 100644 --- a/cwd/assets/altcraft/ui/main-menu-styles.rcss +++ b/cwd/assets/altcraft/ui/main-menu-styles.rcss @@ -1,52 +1,6 @@ -body { +#body-main-menu { background-color: #160f08; color: white; - font-family: "open sans"; - width: 100%; - height: 100%; - text-align: center; -} - -.menu { - width: 50%; - margin: auto; - background-color: #a79f9c; -} - -.mc-title { - color: #8e8e8e; - display: block; -} - -.mc-p { - color: #d6d4d6; - display: block; - text-align: left; - font-size: 4vh; -} - -.mc-text { - border-width: 2dp; - border-color: #9f9793; - background-color: #010001; - color: #d6d4d6; - text-align: center; - vertical-align: middle; - font-size: 5vh; -} - -.mc-button { - border-width: 2dp; - border-color: #14110c; - background-color: #6e6f70; - color: #c5c6c7; - text-align: center; - vertical-align: middle; - font-size: 5vh; -} - -.mc-button:hover { - background-color: #7e86bc; } #title { diff --git a/cwd/assets/altcraft/ui/main-menu.rml b/cwd/assets/altcraft/ui/main-menu.rml index 9fd2898..e796b67 100644 --- a/cwd/assets/altcraft/ui/main-menu.rml +++ b/cwd/assets/altcraft/ui/main-menu.rml @@ -1,8 +1,10 @@ + + MainMenu - + AltCraft

AltCraft is currently not finished, but there is some buggy early testing going on.

Enter the hostname of a server and your username to connect to it:

@@ -11,9 +13,8 @@ - + document:GetElementById('username'):GetAttribute('value'))">Connect + Options...
diff --git a/cwd/assets/altcraft/ui/mc-styles.rcss b/cwd/assets/altcraft/ui/mc-styles.rcss new file mode 100644 index 0000000..e6dba35 --- /dev/null +++ b/cwd/assets/altcraft/ui/mc-styles.rcss @@ -0,0 +1,46 @@ +body { + font-family: "open sans"; + width: 100%; + height: 100%; + text-align: center; +} + +.mc-title { + color: #8e8e8e; + display: block; +} + +.mc-p { + color: #d6d4d6; + display: block; + text-align: left; + font-size: 4vh; +} + +.mc-text { + border-width: 2dp; + border-color: #9f9793; + background-color: #010001; + color: #d6d4d6; + text-align: center; + vertical-align: middle; + font-size: 5vh; +} + +.mc-button { + border-width: 2dp; + border-color: #14110c; + background-color: #6e6f70; + color: #c5c6c7; + text-align: center; + vertical-align: middle; + font-size: 5vh; +} + +.mc-button:hover { + background-color: #7e86bc; +} + +.mc-button:disabled { + background-color: #393939; +} \ No newline at end of file diff --git a/cwd/assets/altcraft/ui/pause-styles.rcss b/cwd/assets/altcraft/ui/pause-styles.rcss new file mode 100644 index 0000000..e8e5a08 --- /dev/null +++ b/cwd/assets/altcraft/ui/pause-styles.rcss @@ -0,0 +1,43 @@ +.body-pause { + background-color: #000000AA; +} + +#continue { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 20% auto auto; +} + +#advancements { + display: inline-block; + width: 22%; + height: 8%; + position: fixed; + margin: 30% auto auto 27.5%; +} + +#statistics { + display: inline-block; + width: 22%; + height: 8%; + position: fixed; + margin: 30% 27.5% auto auto; +} + +#options { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 43% auto auto; +} + +#disconnect { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 53% auto auto; +} diff --git a/cwd/assets/altcraft/ui/pause.rml b/cwd/assets/altcraft/ui/pause.rml new file mode 100644 index 0000000..2e366f8 --- /dev/null +++ b/cwd/assets/altcraft/ui/pause.rml @@ -0,0 +1,15 @@ + + + + + Paused + + + Press ESC to unpause + + Advancements + Statistics + Options... + + + -- cgit v1.2.3