diff options
Diffstat (limited to '')
-rw-r--r-- | cwd/assets/altcraft/scripts/init.lua | 49 | ||||
-rw-r--r-- | cwd/assets/altcraft/ui/hud-styles.rcss | 56 | ||||
-rw-r--r-- | cwd/assets/altcraft/ui/hud.rml | 20 | ||||
-rw-r--r-- | cwd/assets/altcraft/ui/main-menu-styles.rcss | 48 | ||||
-rw-r--r-- | cwd/assets/altcraft/ui/main-menu.rml | 9 | ||||
-rw-r--r-- | cwd/assets/altcraft/ui/mc-styles.rcss | 46 | ||||
-rw-r--r-- | cwd/assets/altcraft/ui/pause-styles.rcss | 43 | ||||
-rw-r--r-- | cwd/assets/altcraft/ui/pause.rml | 15 | ||||
-rw-r--r-- | src/Plugin.cpp | 10 |
9 files changed, 242 insertions, 54 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 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 @@ +<rml> + <head> + <link type="text/rcss" href="mc-styles" /> + <link type="text/rcss" href="hud-styles" /> + <title>Playing</title> + </head> + <body class="body-hud"> + <div class="dbg-hud"> + <p>FPS: <span id="dbg-fps">∞?</span></p> + <p>Pos: <span id="dbg-pos">∞?</span></p> + <p>Select pos: <span id="dbg-select-pos">∞?</span></p> + </div> + <div class="status-hud"> + <p>HP: <span id="status-hp">∞?</span> <progress value="15" max="20" id="status-hp-bar" /> </p> + </div> + <div style="display: table; width:100%; height: 100%;"> + <div class="crosshair-hud">+</div> + </div> + </body> +</rml> 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 @@ <rml> <head> + <link type="text/rcss" href="mc-styles" /> <link type="text/rcss" href="main-menu-styles" /> + <title>MainMenu</title> </head> - <body> + <body id="body-main-menu"> <strong class="mc-title" id="title">AltCraft</strong> <p class="mc-p" id="disclaimer">AltCraft is currently not finished, but there is some buggy early testing going on.</p> <p class="mc-p" id="hostname-text">Enter the hostname of a server and your username to connect to it:</p> @@ -11,9 +13,8 @@ <button class="mc-button" id="connect" onclick=" AC.ConnectToServer( document:GetElementById('hostname'):GetAttribute('value'), - document:GetElementById('username'):GetAttribute('value')); - document:Close()">Connect</button> - <button class="mc-button" id="options">Options...</button> + document:GetElementById('username'):GetAttribute('value'))">Connect</button> + <input type="button" disabled class="mc-button" id="options">Options...</input> <button class="mc-button" id="exit" onclick="AC.Exit()">Quit game</button> </body> </rmL> 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 @@ +<rml> + <head> + <link type="text/rcss" href="mc-styles" /> + <link type="text/rcss" href="pause-styles" /> + <title>Paused</title> + </head> + <body class="body-pause"> + Press ESC to unpause + <button class="mc-button" onclick="AC.SetStatePlaying()" id="continue">Back to Game</button> + <input disabled type="button" class="mc-button" onclick="" id="advancements">Advancements</input> + <input disabled type="button" class="mc-button" onclick="" id="statistics">Statistics</input> + <input disabled type="button" class="mc-button" onclick="" id="options">Options...</input> + <button class="mc-button" onclick="AC.Disconnect()" id="disconnect">Disconnect</button> + </body> +</rml> diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 776ba8d..f518957 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -95,6 +95,14 @@ namespace PluginApi { void Exit() { PUSH_EVENT("Exit", 0); } + + void Disconnect() { + PUSH_EVENT("Disconnect", std::string("Disconnected by user")); + } + + void SetStatePlaying() { + SetState(State::Playing); + } } int LoadFileRequire(lua_State* L) { @@ -235,6 +243,8 @@ void PluginSystem::Init() { apiTable["RegisterDimension"] = PluginApi::RegisterDimension; apiTable["ConnectToServer"] = PluginApi::ConnectToServer; apiTable["Exit"] = PluginApi::Exit; + apiTable["Disconnect"] = PluginApi::Disconnect; + apiTable["SetStatePlaying"] = PluginApi::SetStatePlaying; } lua_State* PluginSystem::GetLuaState() { |