summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-06-22 01:40:04 +0200
committerLaG1924 <lag1924@gmail.com>2021-06-22 02:20:33 +0200
commit0d2b4783824730ba2208f5caaef27c5c61a56fa5 (patch)
tree3c2e085706f3824aa34d2dce5747c9c86a79723a
parentAdded Settings UI (diff)
downloadAltCraft-0d2b4783824730ba2208f5caaef27c5c61a56fa5.tar
AltCraft-0d2b4783824730ba2208f5caaef27c5c61a56fa5.tar.gz
AltCraft-0d2b4783824730ba2208f5caaef27c5c61a56fa5.tar.bz2
AltCraft-0d2b4783824730ba2208f5caaef27c5c61a56fa5.tar.lz
AltCraft-0d2b4783824730ba2208f5caaef27c5c61a56fa5.tar.xz
AltCraft-0d2b4783824730ba2208f5caaef27c5c61a56fa5.tar.zst
AltCraft-0d2b4783824730ba2208f5caaef27c5c61a56fa5.zip
-rw-r--r--cwd/assets/altcraft/scripts/init.lua7
-rw-r--r--cwd/assets/altcraft/scripts/ui.lua37
-rw-r--r--cwd/assets/altcraft/ui/hud.rml1
-rw-r--r--cwd/assets/altcraft/ui/main-menu.rml7
-rw-r--r--src/Plugin.cpp6
-rw-r--r--src/Rml.cpp2
6 files changed, 51 insertions, 9 deletions
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 @@
<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>
+ <p>Select block: <span id="dbg-select-bid">∞?</span></p>
</div>
<div class="status-hud">
<p>HP: <span id="status-hp">∞?</span> <progress value="15" max="20" id="status-hp-bar" /> </p>
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 @@
<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>
<input class="mc-text" id="hostname" value="127.0.0.1:25565"/>
- <input class="mc-text" id="username" value="HelloOne"/>
- <button class="mc-button" id="connect" onclick="
- AC.ConnectToServer(
- document:GetElementById('hostname'):GetAttribute('value'),
- document:GetElementById('username'):GetAttribute('value'))">Connect</button>
+ <input class="mc-text" id="username"/>
+ <button class="mc-button" id="connect" onclick="ConnectToServer(document)">Connect</button>
<button type="button" class="mc-button" id="options" onclick="OpenOptions(document)">Options...</button>
<button class="mc-button" id="exit" onclick="AC.Exit()">Quit game</button>
</body>
diff --git a/src/Plugin.cpp b/src/Plugin.cpp
index e3188e6..5134aa6 100644
--- a/src/Plugin.cpp
+++ b/src/Plugin.cpp
@@ -237,6 +237,11 @@ void PluginSystem::Init() {
"name", &Dimension::name,
"skylight", &Dimension::skylight);
+ lua.new_usertype<LoopExecutionTimeController>("LoopExecutionTimeController",
+ "GetIterations", &LoopExecutionTimeController::GetIterations,
+ "GetDeltaS", &LoopExecutionTimeController::GetDeltaS,
+ "GetRealDeltaS", &LoopExecutionTimeController::GetRealDeltaS);
+
sol::table apiTable = lua["AC"].get_or_create<sol::table>();
sol::table apiSettings = lua["AC"]["Settings"].get_or_create<sol::table>();
@@ -262,6 +267,7 @@ void PluginSystem::Init() {
apiSettings["ReadDouble"] = Settings::ReadDouble;
apiSettings["WriteDouble"] = Settings::WriteDouble;
apiTable["SettingsUpdate"] = PluginApi::SettingsUpdate;
+ apiTable["GetTime"] = GetTime;
}
lua_State* PluginSystem::GetLuaState() {
diff --git a/src/Rml.cpp b/src/Rml.cpp
index cbc795f..6ed83c1 100644
--- a/src/Rml.cpp
+++ b/src/Rml.cpp
@@ -189,7 +189,7 @@ void RmlFileInterface::Close(Rml::FileHandle file) {
size_t RmlFileInterface::Read(void* buffer, size_t size, Rml::FileHandle file) {
size_t readed = 0;
- readed = _min(handles[file].assetPtr->data.size() - handles[file].filePos, size);
+ readed = _min((size_t)(handles[file].assetPtr->data.size() - handles[file].filePos), size);
std::memcpy(buffer, handles[file].assetPtr->data.data() + handles[file].filePos, readed);
handles[file].filePos += readed;
return readed;