From f2266b843959413277767a990bb9a9c5593f3489 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 13 Jun 2021 13:47:33 +0500 Subject: Implemented basic RmlUi integration --- cwd/assets/altcraft/shaders/frag/rml.fs | 12 ++++++++++++ cwd/assets/altcraft/shaders/frag/rmltex.fs | 14 ++++++++++++++ cwd/assets/altcraft/shaders/rml.json | 7 +++++++ cwd/assets/altcraft/shaders/rmltex.json | 8 ++++++++ cwd/assets/altcraft/shaders/vert/rml.vs | 21 +++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 cwd/assets/altcraft/shaders/frag/rml.fs create mode 100644 cwd/assets/altcraft/shaders/frag/rmltex.fs create mode 100644 cwd/assets/altcraft/shaders/rml.json create mode 100644 cwd/assets/altcraft/shaders/rmltex.json create mode 100644 cwd/assets/altcraft/shaders/vert/rml.vs (limited to 'cwd/assets/altcraft') diff --git a/cwd/assets/altcraft/shaders/frag/rml.fs b/cwd/assets/altcraft/shaders/frag/rml.fs new file mode 100644 index 0000000..54c3f36 --- /dev/null +++ b/cwd/assets/altcraft/shaders/frag/rml.fs @@ -0,0 +1,12 @@ +#version 330 core + +in VS_OUT { + vec4 color; + vec2 tex_coord; +} fs_in; + +out vec4 fragColor; + +void main() { + fragColor = fs_in.color; +} diff --git a/cwd/assets/altcraft/shaders/frag/rmltex.fs b/cwd/assets/altcraft/shaders/frag/rmltex.fs new file mode 100644 index 0000000..d885b3b --- /dev/null +++ b/cwd/assets/altcraft/shaders/frag/rmltex.fs @@ -0,0 +1,14 @@ +#version 330 core + +uniform sampler2D fontTexture; + +in VS_OUT { + vec4 color; + vec2 tex_coord; +} fs_in; + +out vec4 fragColor; + +void main() { + fragColor = fs_in.color * texture(fontTexture, fs_in.tex_coord); +} diff --git a/cwd/assets/altcraft/shaders/rml.json b/cwd/assets/altcraft/shaders/rml.json new file mode 100644 index 0000000..c62ff25 --- /dev/null +++ b/cwd/assets/altcraft/shaders/rml.json @@ -0,0 +1,7 @@ +{ + "vert": "/altcraft/shaders/vert/rml", + "frag": "/altcraft/shaders/frag/rml", + "uniforms": [ + "viewportSize" + ] +} \ No newline at end of file diff --git a/cwd/assets/altcraft/shaders/rmltex.json b/cwd/assets/altcraft/shaders/rmltex.json new file mode 100644 index 0000000..3fef969 --- /dev/null +++ b/cwd/assets/altcraft/shaders/rmltex.json @@ -0,0 +1,8 @@ +{ + "vert": "/altcraft/shaders/vert/rml", + "frag": "/altcraft/shaders/frag/rmltex", + "uniforms": [ + "viewportSize", + "fontTexture" + ] +} \ No newline at end of file diff --git a/cwd/assets/altcraft/shaders/vert/rml.vs b/cwd/assets/altcraft/shaders/vert/rml.vs new file mode 100644 index 0000000..bfc50fb --- /dev/null +++ b/cwd/assets/altcraft/shaders/vert/rml.vs @@ -0,0 +1,21 @@ +#version 330 core + +uniform uvec2 viewportSize; +uniform mat4 rotationMat; + +layout (location = 0) in vec2 pos; +layout (location = 1) in uvec4 color; +layout (location = 2) in vec2 tex_coord; + +out VS_OUT { + vec4 color; + vec2 tex_coord; +} vs_out; + +void main() { + float x = (pos.x - viewportSize.x) / viewportSize.x; + float y = ((pos.y - viewportSize.y) / viewportSize.y) * -1; + gl_Position = vec4(x, y, -1.0f, 1.0f); + vs_out.color = vec4(float(color.x) / 255.0f, float(color.y) / 255.0f, float(color.z) / 255.0f, float(color.w) / 255.0f); + vs_out.tex_coord = tex_coord; +} -- cgit v1.2.3 From cc937302964a04aa8e7cdc0e6796503559efaa69 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 13 Jun 2021 21:20:25 +0500 Subject: Improved RmlUi integration --- cwd/assets/altcraft/shaders/rml.json | 1 + cwd/assets/altcraft/shaders/rmltex.json | 1 + cwd/assets/altcraft/shaders/vert/rml.vs | 7 ++++--- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'cwd/assets/altcraft') diff --git a/cwd/assets/altcraft/shaders/rml.json b/cwd/assets/altcraft/shaders/rml.json index c62ff25..0cd85cc 100644 --- a/cwd/assets/altcraft/shaders/rml.json +++ b/cwd/assets/altcraft/shaders/rml.json @@ -2,6 +2,7 @@ "vert": "/altcraft/shaders/vert/rml", "frag": "/altcraft/shaders/frag/rml", "uniforms": [ + "translation", "viewportSize" ] } \ No newline at end of file diff --git a/cwd/assets/altcraft/shaders/rmltex.json b/cwd/assets/altcraft/shaders/rmltex.json index 3fef969..a8a1323 100644 --- a/cwd/assets/altcraft/shaders/rmltex.json +++ b/cwd/assets/altcraft/shaders/rmltex.json @@ -2,6 +2,7 @@ "vert": "/altcraft/shaders/vert/rml", "frag": "/altcraft/shaders/frag/rmltex", "uniforms": [ + "translation", "viewportSize", "fontTexture" ] diff --git a/cwd/assets/altcraft/shaders/vert/rml.vs b/cwd/assets/altcraft/shaders/vert/rml.vs index bfc50fb..bdd3b71 100644 --- a/cwd/assets/altcraft/shaders/vert/rml.vs +++ b/cwd/assets/altcraft/shaders/vert/rml.vs @@ -1,6 +1,7 @@ #version 330 core uniform uvec2 viewportSize; +uniform vec2 translation; uniform mat4 rotationMat; layout (location = 0) in vec2 pos; @@ -13,9 +14,9 @@ out VS_OUT { } vs_out; void main() { - float x = (pos.x - viewportSize.x) / viewportSize.x; - float y = ((pos.y - viewportSize.y) / viewportSize.y) * -1; - gl_Position = vec4(x, y, -1.0f, 1.0f); + float x = ((pos.x + translation.x) / viewportSize.x) * 2.0f - 1.0f; + float y = ((pos.y + translation.y) / viewportSize.y) * 2.0f - 1.0f; + gl_Position = vec4(x, -y, -1.0f, 1.0f); vs_out.color = vec4(float(color.x) / 255.0f, float(color.y) / 255.0f, float(color.z) / 255.0f, float(color.w) / 255.0f); vs_out.tex_coord = tex_coord; } -- cgit v1.2.3 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 +- cwd/assets/altcraft/ui/main-menu-styles.rcss | 105 +++++++++++++++++++++++++++ cwd/assets/altcraft/ui/main-menu.rml | 19 +++++ 3 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 cwd/assets/altcraft/ui/main-menu-styles.rcss create mode 100644 cwd/assets/altcraft/ui/main-menu.rml (limited to 'cwd/assets/altcraft') 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 () diff --git a/cwd/assets/altcraft/ui/main-menu-styles.rcss b/cwd/assets/altcraft/ui/main-menu-styles.rcss new file mode 100644 index 0000000..ee86894 --- /dev/null +++ b/cwd/assets/altcraft/ui/main-menu-styles.rcss @@ -0,0 +1,105 @@ +body { + 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 { + margin: 0% auto auto; + font-size: 20vh; +} + +#disclaimer { + width: 70%; + margin: 0 auto; +} + +#hostname-text { + width: 70%; + margin: 5% auto; +} + +#hostname { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 0% auto auto; +} + +#username { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 10% auto auto; +} + +#connect { + display: inline-block; + width: 45%; + height: 8%; + position: fixed; + margin: 20% auto auto; +} + +#options { + display: inline-block; + width: 22%; + height: 8%; + position: fixed; + margin: 33% auto auto 27.5%; +} + +#exit { + display: inline-block; + width: 22%; + height: 8%; + position: fixed; + margin: 33% 27.5% auto auto; +} diff --git a/cwd/assets/altcraft/ui/main-menu.rml b/cwd/assets/altcraft/ui/main-menu.rml new file mode 100644 index 0000000..9fd2898 --- /dev/null +++ b/cwd/assets/altcraft/ui/main-menu.rml @@ -0,0 +1,19 @@ + + + + + + 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:

+ + + + + + +
-- 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 ++++++++++++++++++++++-- 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/assets/altcraft') 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 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 +----- cwd/assets/altcraft/scripts/ui.lua | 138 +++++++++++++++++++++++++++++ cwd/assets/altcraft/ui/main-menu.rml | 3 +- cwd/assets/altcraft/ui/mc-styles.rcss | 6 +- cwd/assets/altcraft/ui/options-styles.rcss | 84 ++++++++++++++++++ cwd/assets/altcraft/ui/options.rml | 61 +++++++++++++ cwd/assets/altcraft/ui/pause.rml | 3 +- 7 files changed, 294 insertions(+), 28 deletions(-) create mode 100644 cwd/assets/altcraft/scripts/ui.lua create mode 100644 cwd/assets/altcraft/ui/options-styles.rcss create mode 100644 cwd/assets/altcraft/ui/options.rml (limited to 'cwd/assets/altcraft') 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 diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua new file mode 100644 index 0000000..c55436f --- /dev/null +++ b/cwd/assets/altcraft/scripts/ui.lua @@ -0,0 +1,138 @@ +local options = { + brightness = 0.2, + flight = false, + mouseSensetivity = 0.1, + renderDistance = 2, + resolutionScale = 1.0, + targetFps = 60, + vsync = false, + wireframe = false +} + +function OpenOptions(doc) + optionsReturnDocument = doc + local optionsDoc = {} + for i,d in ipairs(rmlui.contexts["default"].documents) do + if d.title == "Options" then + optionsDoc = d + end + end + doc:Hide() + optionsDoc:Show() + optionsDoc.style["background-color"] = doc.style["background-color"] +end + +function CloseOptions(doc) + for i, v in pairs(options) do + local input = doc:GetElementById(i) + if type(v) == "number" then + local val = input:GetAttribute("value") + if i == "targetFps" and val == 301 then + AC.Settings.WriteDouble(i, 10000) + else + AC.Settings.WriteDouble(i, tonumber(val)) + end + elseif type(v) == "boolean" then + local val = input:HasAttribute("checked") + AC.Settings.WriteBool(i, val) + end + end + AC.Settings.Save() + AC.SettingsUpdate() + + optionsReturnDocument:Show() + doc:Hide() +end + +function OptionsDefaultHandler(event) + local input = event.current_element.previous_sibling + local id = input:GetAttribute("id") + if input:GetAttribute("type") == "checkbox" then + if options[id] then + input:SetAttribute("checked", "") + else + input:RemoveAttribute("checked") + end + else + input:SetAttribute("value", options[id]) + end +end + +function UpdateUi() + local doc = {} + local uiDoc = {} + for i,d in ipairs(rmlui.contexts["default"].documents) do + if d.title == "Playing" then + doc = d + elseif d.title == "Options" then + uiDoc = d + end + end + + if AC.GetGameState() and AC.GetGameState():GetPlayer() and AC.GetGameState():GetTimeStatus().worldAge > 0 then + 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 + + + local uiInit = optionsListenersAdded == nil + if uiInit then + AC.Settings.Load() + end + + for i,v in pairs(options) do + local input = uiDoc:GetElementById(i) + local span = input.next_sibling + + if uiInit then + span:AddEventListener("click", OptionsDefaultHandler, true) + + if type(v) == "number" then + local val = AC.Settings.ReadDouble(i, v) + input:SetAttribute("value", tostring(val)) + elseif type(v) == "boolean" then + local val = AC.Settings.ReadBool(i, v) + if val then + input:SetAttribute("checked", "") + else + input:RemoveAttribute("checked") + end + end + end + + if type(v) == "number" then + local val = input:GetAttribute("value") + if v == math.floor(v) and i ~= "resolutionScale" then + span.inner_rml = string.format("%d (%d)", math.floor(val), v) + if i == "targetFps" and val == 301 then + span.inner_rml = string.format("∞ (%d)", v) + end + else + span.inner_rml = string.format("%.2f (%.2f)", val, v) + end + elseif type(v) == "boolean" then + if v then + span.inner_rml = "(on)" + else + span.inner_rml = "(off)" + end + end + end + + if uiInit == true then + optionsListenersAdded = true + AC.SettingsUpdate() + end +end diff --git a/cwd/assets/altcraft/ui/main-menu.rml b/cwd/assets/altcraft/ui/main-menu.rml index e796b67..0aaac89 100644 --- a/cwd/assets/altcraft/ui/main-menu.rml +++ b/cwd/assets/altcraft/ui/main-menu.rml @@ -3,6 +3,7 @@ MainMenu + AltCraft @@ -14,7 +15,7 @@ AC.ConnectToServer( document:GetElementById('hostname'):GetAttribute('value'), 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 index e6dba35..3549180 100644 --- a/cwd/assets/altcraft/ui/mc-styles.rcss +++ b/cwd/assets/altcraft/ui/mc-styles.rcss @@ -39,8 +39,10 @@ body { .mc-button:hover { background-color: #7e86bc; + color: #cfd69d; } .mc-button:disabled { - background-color: #393939; -} \ No newline at end of file + background-color: #2b2b2b; + color: #848484; +} diff --git a/cwd/assets/altcraft/ui/options-styles.rcss b/cwd/assets/altcraft/ui/options-styles.rcss new file mode 100644 index 0000000..fbfc685 --- /dev/null +++ b/cwd/assets/altcraft/ui/options-styles.rcss @@ -0,0 +1,84 @@ +.body-options { + background-color: transparent; +} + +form { + width: 70%; + display: block; + margin: 5% auto; + background-color: #211710; +} + +.option { + display: block; + background-color: #0f0b07; + margin: 1vh; + padding: 0.5vh; + font-size: 4vh; + text-align: center; +} + +label { + +} + +span { + +} + +span:hover { + color: #cfd69d; +} + +input { + background-color: #2c2c2c; + height: 4vh; + margin-right: 1vh; + margin-left: 1vh; +} + +input.checkbox { + border-width: 1vh; + border-color: #2c2c2c; +} + +input.checkbox:checked { + background-color: #dcdadc; +} + +input.checkbox:hover { + border-color: #6a6b70; +} + +input.range:hover { + background-color: #6a6b70; +} + +input.range sliderbar { + width: 3vh; + background-color: #9c9c9c; +} + +input.range:hover sliderbar { + background-color: #e9e7e8; +} + +input.range sliderbar:active { + background-color: #cfd69d; +} + +input.range sliderarrowdec { + display: none; +} + +input.range sliderarrowinc { + display: none; +} + +#done { + display: block; + width: 45%; + height: 8%; + position: fixed; + margin: 5% auto auto; +} diff --git a/cwd/assets/altcraft/ui/options.rml b/cwd/assets/altcraft/ui/options.rml new file mode 100644 index 0000000..485dcba --- /dev/null +++ b/cwd/assets/altcraft/ui/options.rml @@ -0,0 +1,61 @@ + + + + + + Options + + +
+
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + +
diff --git a/cwd/assets/altcraft/ui/pause.rml b/cwd/assets/altcraft/ui/pause.rml index 2e366f8..5d652f9 100644 --- a/cwd/assets/altcraft/ui/pause.rml +++ b/cwd/assets/altcraft/ui/pause.rml @@ -2,6 +2,7 @@ + Paused @@ -9,7 +10,7 @@ Advancements Statistics - Options... + -- 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 ++++++- cwd/assets/altcraft/scripts/ui.lua | 37 ++++++++++++++++++++++++++++++++++-- cwd/assets/altcraft/ui/hud.rml | 1 + cwd/assets/altcraft/ui/main-menu.rml | 7 ++----- 4 files changed, 44 insertions(+), 8 deletions(-) (limited to 'cwd/assets/altcraft') 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) diff --git a/cwd/assets/altcraft/scripts/ui.lua b/cwd/assets/altcraft/scripts/ui.lua index c55436f..392ad27 100644 --- a/cwd/assets/altcraft/scripts/ui.lua +++ b/cwd/assets/altcraft/scripts/ui.lua @@ -44,6 +44,15 @@ function CloseOptions(doc) doc:Hide() end +function ConnectToServer(doc) + AC.Settings.Write('hostname',doc:GetElementById('hostname'):GetAttribute('value')) + AC.Settings.Write('username',doc:GetElementById('username'):GetAttribute('value')) + AC.Settings.Save() + AC.ConnectToServer( + doc:GetElementById('hostname'):GetAttribute('value'), + doc:GetElementById('username'):GetAttribute('value')) +end + function OptionsDefaultHandler(event) local input = event.current_element.previous_sibling local id = input:GetAttribute("id") @@ -58,6 +67,21 @@ function OptionsDefaultHandler(event) end end +local lastFps = {} + +local function UpdateFps(newFps) + lastFps[#lastFps + 1] = newFps + if #lastFps >= 100 then + table.remove(lastFps, 1) + end + local smoothFps = 0 + for i,v in ipairs(lastFps) do + smoothFps = smoothFps + v + end + smoothFps = smoothFps / #lastFps + return smoothFps +end + function UpdateUi() local doc = {} local uiDoc = {} @@ -70,14 +94,23 @@ function UpdateUi() end if AC.GetGameState() and AC.GetGameState():GetPlayer() and AC.GetGameState():GetTimeStatus().worldAge > 0 then - local playerEnt = AC.GetGameState():GetPlayer() + local time = AC.GetTime() + local rawFps = 1.0 / time:GetRealDeltaS() + local smoothFps = UpdateFps(rawFps) + doc:GetElementById('dbg-fps').inner_rml = string.format("%.1f", smoothFps) + + 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 wrld = AC.GetGameState():GetWorld() local selection = AC.GetGameState():GetSelectionStatus() if selection.isBlockSelected then + bid = wrld:GetBlockId(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) else doc:GetElementById('dbg-select-pos').inner_rml = "" + doc:GetElementById('dbg-select-bid').inner_rml = "" end local player = AC.GetGameState():GetPlayerStatus() diff --git a/cwd/assets/altcraft/ui/hud.rml b/cwd/assets/altcraft/ui/hud.rml index 5a1d7ce..cbf5c86 100644 --- a/cwd/assets/altcraft/ui/hud.rml +++ b/cwd/assets/altcraft/ui/hud.rml @@ -9,6 +9,7 @@

FPS: ∞?

Pos: ∞?

Select pos: ∞?

+

Select block: ∞?

HP: ∞?

diff --git a/cwd/assets/altcraft/ui/main-menu.rml b/cwd/assets/altcraft/ui/main-menu.rml index 0aaac89..c5d405d 100644 --- a/cwd/assets/altcraft/ui/main-menu.rml +++ b/cwd/assets/altcraft/ui/main-menu.rml @@ -10,11 +10,8 @@

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:

- - + + -- cgit v1.2.3