diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index ace88536..a5f69883 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -73,3 +73,66 @@ function dofile(path) end return _dofile(path) end + +toml = {} + +-- Convert table to TOML +function toml.from_table(tb, isinner) + local text = "" + for k, v in pairs(tb) do + local tp = type(v) + if tp ~= "table" then + text = text..k.." = " + if tp == "string" then + text = text..string.format("%q", v) + else + text = text..tostring(v) + end + text = text.."\n" + end + end + for k, v in pairs(tb) do + local tp = type(v) + if tp == "table" then + if isinner then + error("only one level of subtables supported") + end + text = text.."["..k.."]\n"..toml.from_table(v).."\n" + end + end + return text +end + +-- Parse TOML to new table +function toml.parse(s) + local output = {} + local current = output + local lines = {} + for line in string.gmatch(s, "[^\r\n]+") do + line = string.gsub(line, "%s+", "") + table.insert(lines, line) + end + for i = 1,#lines do + local s = lines[i] + if string.sub(s, 1, 1) == "[" then + local section = s.sub(s, 2, #s-1) + current = {} + output[section] = current + else + for k, v in string.gmatch(s, "(%w+)=(.+)" ) do + v = string.gsub(v, "%s+", "") + if v.sub(v, 1, 1) == "\"" then + current[k] = v.sub(v, 2, #v-1) + elseif v == "true" or v == "false" then + current[k] = v == "true" + end + + local num = tonumber(v) + if num ~= nil then + current[k] = num + end + end + end + end + return output +end diff --git a/src/frontend/menu.cpp b/src/frontend/menu.cpp index 3838e23a..6a0dba3a 100644 --- a/src/frontend/menu.cpp +++ b/src/frontend/menu.cpp @@ -37,8 +37,6 @@ using glm::vec4; namespace fs = std::filesystem; using namespace gui; -const int PACKS_PANEL_WIDTH = 550; - inline uint64_t randU64() { srand(time(NULL)); return rand() ^ (rand() << 8) ^ @@ -224,8 +222,8 @@ std::shared_ptr create_worlds_panel(Engine* engine) { auto namews = util::str2wstr_utf8(name); auto btn = std::make_shared(vec2(390, 46)); - btn->setColor(vec4(1.0f, 1.0f, 1.0f, 0.1f)); - btn->setHoverColor(vec4(1.0f, 1.0f, 1.0f, 0.17f)); + btn->setColor(vec4(0.06f, 0.12f, 0.18f, 0.7f)); + btn->setHoverColor(vec4(0.09f, 0.17f, 0.2f, 0.6f)); btn->listenAction([=](GUI*) { open_world(name, engine); }); @@ -277,13 +275,14 @@ std::shared_ptr create_packs_panel( packconsumer callback ){ auto assets = engine->getAssets(); - auto panel = std::make_shared(vec2(PACKS_PANEL_WIDTH, 200), vec4(5.0f)); + auto panel = std::make_shared(vec2(550, 200), vec4(5.0f)); panel->setColor(vec4(1.0f, 1.0f, 1.0f, 0.07f)); panel->setMaxLength(400); panel->setScrollable(true); for (auto& pack : packs) { - auto packpanel = std::make_shared(vec2(390, 80)); + auto packpanel = std::make_shared(vec2(540, 80)); + packpanel->setColor(vec4(0.06f, 0.12f, 0.18f, 0.7f)); if (callback) { packpanel->listenAction([=](GUI*) { callback(pack); @@ -291,7 +290,9 @@ std::shared_ptr create_packs_panel( } auto idlabel = std::make_shared