Merge branch 'main' of https://github.com/MihailRis/VoxelEngine-Cpp
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "UiDocument.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../files/files.hpp"
|
||||
#include "../graphics/ui/elements/UINode.hpp"
|
||||
#include "../graphics/ui/elements/InventoryView.hpp"
|
||||
@@ -9,9 +11,9 @@
|
||||
UiDocument::UiDocument(
|
||||
std::string id,
|
||||
uidocscript script,
|
||||
std::shared_ptr<gui::UINode> root,
|
||||
const std::shared_ptr<gui::UINode>& root,
|
||||
scriptenv env
|
||||
) : id(id), script(script), root(root), env(env) {
|
||||
) : id(std::move(id)), script(script), root(root), env(std::move(env)) {
|
||||
gui::UINode::getIndices(root, map);
|
||||
}
|
||||
|
||||
@@ -31,11 +33,11 @@ const std::string& UiDocument::getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
const std::shared_ptr<gui::UINode> UiDocument::getRoot() const {
|
||||
std::shared_ptr<gui::UINode> UiDocument::getRoot() const {
|
||||
return root;
|
||||
}
|
||||
|
||||
const std::shared_ptr<gui::UINode> UiDocument::get(const std::string& id) const {
|
||||
std::shared_ptr<gui::UINode> UiDocument::get(const std::string& id) const {
|
||||
auto found = map.find(id);
|
||||
if (found == map.end()) {
|
||||
return nullptr;
|
||||
@@ -51,7 +53,7 @@ scriptenv UiDocument::getEnvironment() const {
|
||||
return env;
|
||||
}
|
||||
|
||||
std::unique_ptr<UiDocument> UiDocument::read(scriptenv penv, std::string name, fs::path file) {
|
||||
std::unique_ptr<UiDocument> UiDocument::read(const scriptenv& penv, const std::string& name, const fs::path& file) {
|
||||
const std::string text = files::read_string(file);
|
||||
auto xmldoc = xml::parse(file.u8string(), text);
|
||||
|
||||
@@ -72,7 +74,7 @@ std::unique_ptr<UiDocument> UiDocument::read(scriptenv penv, std::string name, f
|
||||
return std::make_unique<UiDocument>(name, script, view, env);
|
||||
}
|
||||
|
||||
std::shared_ptr<gui::UINode> UiDocument::readElement(fs::path file) {
|
||||
std::shared_ptr<gui::UINode> UiDocument::readElement(const fs::path& file) {
|
||||
auto document = read(nullptr, file.filename().u8string(), file);
|
||||
return document->getRoot();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
UiDocument(
|
||||
std::string id,
|
||||
uidocscript script,
|
||||
std::shared_ptr<gui::UINode> root,
|
||||
const std::shared_ptr<gui::UINode> &root,
|
||||
scriptenv env
|
||||
);
|
||||
|
||||
@@ -41,13 +41,13 @@ public:
|
||||
const std::string& getId() const;
|
||||
const uinodes_map& getMap() const;
|
||||
uinodes_map& getMapWriteable();
|
||||
const std::shared_ptr<gui::UINode> getRoot() const;
|
||||
const std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||
std::shared_ptr<gui::UINode> getRoot() const;
|
||||
std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||
const uidocscript& getScript() const;
|
||||
scriptenv getEnvironment() const;
|
||||
|
||||
static std::unique_ptr<UiDocument> read(scriptenv parent_env, std::string name, fs::path file);
|
||||
static std::shared_ptr<gui::UINode> readElement(fs::path file);
|
||||
static std::unique_ptr<UiDocument> read(const scriptenv& parent_env, const std::string& name, const fs::path& file);
|
||||
static std::shared_ptr<gui::UINode> readElement(const fs::path& file);
|
||||
};
|
||||
|
||||
#endif // FRONTEND_UI_DOCUMENT_HPP_
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../graphics/ui/elements/TrackBar.hpp"
|
||||
#include "../graphics/ui/elements/InputBindBox.hpp"
|
||||
#include "../graphics/render/WorldRenderer.hpp"
|
||||
#include "../logic/scripting/scripting.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
#include "../physics/Hitbox.hpp"
|
||||
#include "../util/stringutil.hpp"
|
||||
@@ -21,12 +22,13 @@
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <bitset>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
static std::shared_ptr<Label> create_label(wstringsupplier supplier) {
|
||||
auto label = std::make_shared<Label>(L"-");
|
||||
label->textSupplier(supplier);
|
||||
label->textSupplier(std::move(supplier));
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -36,6 +38,7 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
Player* player
|
||||
) {
|
||||
auto panel = std::make_shared<Panel>(glm::vec2(250, 200), glm::vec4(5.0f), 2.0f);
|
||||
panel->setId("hud.debug-panel");
|
||||
panel->setPos(glm::vec2(10, 10));
|
||||
|
||||
static int fps = 0;
|
||||
@@ -63,6 +66,9 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
return L"speakers: " + std::to_wstring(audio::count_speakers())+
|
||||
L" streams: " + std::to_wstring(audio::count_streams());
|
||||
}));
|
||||
panel->add(create_label([](){
|
||||
return L"lua-stack: " + std::to_wstring(scripting::get_values_on_stack());
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
auto& settings = engine->getSettings();
|
||||
bool culling = settings.graphics.frustumCulling.get();
|
||||
@@ -73,20 +79,21 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
L" visible: "+std::to_wstring(level->chunks->visible);
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
const auto& vox = player->selection.vox;
|
||||
std::wstringstream stream;
|
||||
stream << "r:" << player->selectedVoxel.state.rotation << " s:"
|
||||
<< player->selectedVoxel.state.segment << " u:"
|
||||
<< std::bitset<8>(player->selectedVoxel.state.userbits);
|
||||
if (player->selectedVoxel.id == BLOCK_VOID) {
|
||||
stream << "r:" << vox.state.rotation << " s:"
|
||||
<< std::bitset<3>(vox.state.segment) << " u:"
|
||||
<< std::bitset<8>(vox.state.userbits);
|
||||
if (vox.id == BLOCK_VOID) {
|
||||
return std::wstring {L"block: -"};
|
||||
} else {
|
||||
return L"block: "+std::to_wstring(player->selectedVoxel.id)+
|
||||
L" "+stream.str();
|
||||
return L"block: "+std::to_wstring(vox.id)+
|
||||
L" "+stream.str();
|
||||
}
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
auto* indices = level->content->getIndices();
|
||||
if (auto def = indices->getBlockDef(player->selectedVoxel.id)) {
|
||||
if (auto def = indices->getBlockDef(player->selection.vox.id)) {
|
||||
return L"name: " + util::str2wstr_utf8(def->name);
|
||||
} else {
|
||||
return std::wstring {L"name: void"};
|
||||
@@ -114,7 +121,7 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
Hitbox* hitbox = player->hitbox.get();
|
||||
return util::to_wstring(hitbox->position[ax], 2);
|
||||
});
|
||||
box->setTextConsumer([=](std::wstring text) {
|
||||
box->setTextConsumer([=](const std::wstring& text) {
|
||||
try {
|
||||
glm::vec3 position = player->hitbox->position;
|
||||
position[ax] = std::stoi(text);
|
||||
@@ -136,8 +143,8 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
timeutil::from_value(level->getWorld()->daytime, hour, minute, second);
|
||||
|
||||
std::wstring timeString =
|
||||
util::lfill(std::to_wstring(hour), 2, L'0') + L":" +
|
||||
util::lfill(std::to_wstring(minute), 2, L'0');
|
||||
util::lfill(std::to_wstring(hour), 2, L'0') + L":" +
|
||||
util::lfill(std::to_wstring(minute), 2, L'0');
|
||||
return L"time: "+timeString;
|
||||
}));
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -63,7 +64,7 @@ HudElement::HudElement(
|
||||
UiDocument* document,
|
||||
std::shared_ptr<UINode> node,
|
||||
bool debug
|
||||
) : mode(mode), document(document), node(node), debug(debug) {
|
||||
) : mode(mode), document(document), node(std::move(node)), debug(debug) {
|
||||
}
|
||||
|
||||
void HudElement::update(bool pause, bool inventoryOpen, bool debugMode) {
|
||||
@@ -132,7 +133,7 @@ std::shared_ptr<InventoryView> Hud::createHotbar() {
|
||||
InventoryBuilder builder;
|
||||
builder.addGrid(10, 10, glm::vec2(), 4, true, slotLayout);
|
||||
auto view = builder.build();
|
||||
|
||||
view->setId("hud.hotbar");
|
||||
view->setOrigin(glm::vec2(view->getSize().x/2, 0));
|
||||
view->bind(inventory, content);
|
||||
view->setInteractive(false);
|
||||
@@ -146,12 +147,14 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
|
||||
player(player)
|
||||
{
|
||||
contentAccess = createContentAccess();
|
||||
contentAccess->setId("hud.content-access");
|
||||
contentAccessPanel = std::make_shared<Panel>(
|
||||
contentAccess->getSize(), glm::vec4(0.0f), 0.0f
|
||||
);
|
||||
contentAccessPanel->setColor(glm::vec4());
|
||||
contentAccessPanel->add(contentAccess);
|
||||
contentAccessPanel->setScrollable(true);
|
||||
contentAccessPanel->setId("hud.content-access-panel");
|
||||
|
||||
hotbarView = createHotbar();
|
||||
darkOverlay = guiutil::create(
|
||||
@@ -398,7 +401,7 @@ void Hud::closeInventory() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void Hud::add(HudElement element) {
|
||||
void Hud::add(const HudElement& element) {
|
||||
using namespace dynamic;
|
||||
|
||||
gui->add(element.getNode());
|
||||
@@ -407,9 +410,9 @@ void Hud::add(HudElement element) {
|
||||
if (document) {
|
||||
auto inventory = invview ? invview->getInventory() : nullptr;
|
||||
std::vector<Value> args;
|
||||
args.push_back(inventory ? inventory.get()->getId() : 0);
|
||||
args.emplace_back(inventory ? inventory.get()->getId() : 0);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
args.push_back(static_cast<integer_t>(blockPos[i]));
|
||||
args.emplace_back(static_cast<integer_t>(blockPos[i]));
|
||||
}
|
||||
scripting::on_ui_open(
|
||||
element.getDocument(),
|
||||
@@ -435,7 +438,7 @@ void Hud::onRemove(const HudElement& element) {
|
||||
gui->remove(element.getNode());
|
||||
}
|
||||
|
||||
void Hud::remove(std::shared_ptr<UINode> node) {
|
||||
void Hud::remove(const std::shared_ptr<UINode>& node) {
|
||||
for (auto& element : elements) {
|
||||
if (element.getNode() == node) {
|
||||
element.setRemoved();
|
||||
|
||||
@@ -161,9 +161,9 @@ public:
|
||||
/// @param doc element layout
|
||||
void openPermanent(UiDocument* doc);
|
||||
|
||||
void add(HudElement element);
|
||||
void add(const HudElement& element);
|
||||
void onRemove(const HudElement& element);
|
||||
void remove(std::shared_ptr<gui::UINode> node);
|
||||
void remove(const std::shared_ptr<gui::UINode>& node);
|
||||
|
||||
Player* getPlayer() const;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "locale.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../coders/json.hpp"
|
||||
#include "../coders/commons.hpp"
|
||||
#include "../content/ContentPack.hpp"
|
||||
@@ -16,7 +18,7 @@ using namespace std::literals;
|
||||
std::unique_ptr<langs::Lang> langs::current;
|
||||
std::unordered_map<std::string, langs::LocaleInfo> langs::locales_info;
|
||||
|
||||
langs::Lang::Lang(std::string locale) : locale(locale) {
|
||||
langs::Lang::Lang(std::string locale) : locale(std::move(locale)) {
|
||||
}
|
||||
|
||||
const std::wstring& langs::Lang::get(const std::wstring& key) const {
|
||||
@@ -50,7 +52,7 @@ public:
|
||||
Reader(std::string_view file, std::string_view source) : BasicParser(file, source) {
|
||||
}
|
||||
|
||||
void read(langs::Lang& lang, std::string prefix) {
|
||||
void read(langs::Lang& lang, const std::string &prefix) {
|
||||
skipWhitespace();
|
||||
while (hasNext()) {
|
||||
std::string key = parseString('=', true);
|
||||
|
||||
@@ -54,7 +54,7 @@ gui::page_loader_func menus::create_page_loader(Engine* engine) {
|
||||
auto value = std::string(parser.readUntil('&'));
|
||||
map->put(key, value);
|
||||
}
|
||||
args.push_back(map);
|
||||
args.emplace_back(map);
|
||||
} else {
|
||||
name = query;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ UiDocument* menus::show(Engine* engine, const std::string& name, std::vector<dyn
|
||||
return document;
|
||||
}
|
||||
|
||||
void menus::show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text) {
|
||||
void menus::show_process_panel(Engine* engine, const std::shared_ptr<Task>& task, const std::wstring& text) {
|
||||
using namespace dynamic;
|
||||
|
||||
uint initialWork = task->getWorkTotal();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace menus {
|
||||
std::vector<dynamic::Value> args
|
||||
);
|
||||
|
||||
void show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text=L"");
|
||||
void show_process_panel(Engine* engine, const std::shared_ptr<Task>& task, const std::wstring& text=L"");
|
||||
}
|
||||
|
||||
#endif // FRONTEND_MENU_MENU_HPP_
|
||||
|
||||
Reference in New Issue
Block a user