new content menu (WIP)
This commit is contained in:
@@ -184,6 +184,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/warning", "gui/warning");
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/error", "gui/error");
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/cross", "gui/cross");
|
||||
loader.add(AssetType::texture, TEXTURES_FOLDER+"/gui/refresh", "gui/refresh");
|
||||
if (content) {
|
||||
loader.processPreloadConfigs(content);
|
||||
|
||||
|
||||
@@ -203,6 +203,9 @@ void Hud::processInput(bool visible) {
|
||||
setPause(true);
|
||||
}
|
||||
}
|
||||
if (!Window::isFocused() && !pause && !isInventoryOpen()) {
|
||||
setPause(true);
|
||||
}
|
||||
|
||||
if (!pause && visible && Events::jactive(BIND_HUD_INVENTORY)) {
|
||||
if (inventoryOpen) {
|
||||
|
||||
@@ -125,6 +125,14 @@ void Container::remove(std::shared_ptr<UINode> selected) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::clear() {
|
||||
for (auto node : nodes) {
|
||||
node->setParent(nullptr);
|
||||
}
|
||||
nodes.clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::listenInterval(float interval, ontimeout callback, int repeat) {
|
||||
intervalEvents.push_back({callback, interval, 0.0f, repeat});
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace gui {
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void add(std::shared_ptr<UINode> node);
|
||||
virtual void add(std::shared_ptr<UINode> node, glm::vec2 pos);
|
||||
virtual void clear();
|
||||
virtual void remove(std::shared_ptr<UINode> node);
|
||||
virtual void scrolled(int value) override;
|
||||
virtual void setScrollable(bool flag);
|
||||
|
||||
@@ -22,9 +22,13 @@ void Image::draw(const DrawContext* pctx, Assets* assets) {
|
||||
setSize(glm::vec2(texture->getWidth(), texture->getHeight()));
|
||||
}
|
||||
batch->texture(texture);
|
||||
batch->setColor(color);
|
||||
if (enabled) {
|
||||
batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color));
|
||||
} else {
|
||||
batch->setColor({color.r, color.g, color.b, color.a * 0.5f});
|
||||
}
|
||||
batch->rect(pos.x, pos.y, size.x, size.y,
|
||||
0, 0, 0, UVRegion(), false, true, color);
|
||||
0, 0, 0, UVRegion(), false, true, batch->getColor());
|
||||
}
|
||||
|
||||
void Image::setAutoResize(bool flag) {
|
||||
|
||||
@@ -52,6 +52,10 @@ void Panel::add(std::shared_ptr<UINode> node) {
|
||||
|
||||
void Panel::refresh() {
|
||||
UINode::refresh();
|
||||
std::stable_sort(nodes.begin(), nodes.end(), [](auto a, auto b) {
|
||||
return a->getZIndex() < b->getZIndex();
|
||||
});
|
||||
|
||||
float x = padding.x;
|
||||
float y = padding.y;
|
||||
glm::vec2 size = getSize();
|
||||
|
||||
@@ -198,7 +198,18 @@ int UINode::getZIndex() const {
|
||||
return zindex;
|
||||
}
|
||||
|
||||
void UINode::lock() {
|
||||
void UINode::moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
) {
|
||||
auto parent = node->getParent();
|
||||
if (auto container = dynamic_cast<Container*>(parent)) {
|
||||
container->remove(node);
|
||||
}
|
||||
if (parent) {
|
||||
parent->scrolled(0);
|
||||
}
|
||||
dest->add(node);
|
||||
}
|
||||
|
||||
vec2supplier UINode::getPositionFunc() const {
|
||||
|
||||
@@ -17,6 +17,7 @@ class Assets;
|
||||
namespace gui {
|
||||
class UINode;
|
||||
class GUI;
|
||||
class Container;
|
||||
|
||||
using onaction = std::function<void(GUI*)>;
|
||||
using onnumberchange = std::function<void(GUI*, double)>;
|
||||
@@ -188,7 +189,10 @@ namespace gui {
|
||||
parent->fullRefresh();
|
||||
}
|
||||
};
|
||||
virtual void lock();
|
||||
static void moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
);
|
||||
|
||||
virtual vec2supplier getPositionFunc() const;
|
||||
virtual void setPositionFunc(vec2supplier);
|
||||
|
||||
@@ -217,8 +217,9 @@ void EngineController::reopenWorld(World* world) {
|
||||
openWorld(wname, true);
|
||||
}
|
||||
|
||||
void EngineController::removePacks(
|
||||
void EngineController::reconfigPacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packsToAdd,
|
||||
std::vector<std::string> packsToRemove
|
||||
) {
|
||||
auto content = engine->getContent();
|
||||
@@ -242,6 +243,9 @@ void EngineController::removePacks(
|
||||
manager.scan();
|
||||
|
||||
auto names = PacksManager::getNames(world->getPacks());
|
||||
for (const auto& id : packsToAdd) {
|
||||
names.push_back(id);
|
||||
}
|
||||
for (const auto& id : packsToRemove) {
|
||||
manager.exclude(id);
|
||||
names.erase(std::find(names.begin(), names.end(), id));
|
||||
@@ -262,31 +266,3 @@ void EngineController::removePacks(
|
||||
removeFunc();
|
||||
}
|
||||
}
|
||||
|
||||
void EngineController::addPacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packs
|
||||
) {
|
||||
auto level = controller->getLevel();
|
||||
auto gui = engine->getGUI();
|
||||
auto world = level->getWorld();
|
||||
auto new_packs = PacksManager::getNames(world->getPacks());
|
||||
for (auto& id : packs) {
|
||||
new_packs.push_back(id);
|
||||
}
|
||||
|
||||
auto manager = engine->createPacksManager(world->wfile->getFolder());
|
||||
manager.scan();
|
||||
try {
|
||||
new_packs = manager.assembly(new_packs);
|
||||
} catch (const contentpack_error& err) {
|
||||
guiutil::alert(
|
||||
gui, langs::get(L"error.dependency-not-found")+
|
||||
L": "+util::str2wstr_utf8(err.getPackId())
|
||||
);
|
||||
return;
|
||||
}
|
||||
world->wfile->writePacks(manager.getAll(new_packs));
|
||||
controller->saveWorld();
|
||||
reopenWorld(world);
|
||||
}
|
||||
|
||||
@@ -22,14 +22,10 @@ public:
|
||||
/// @param name world name
|
||||
void deleteWorld(std::string name);
|
||||
|
||||
void removePacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packs
|
||||
);
|
||||
|
||||
void addPacks(
|
||||
void reconfigPacks(
|
||||
LevelController* controller,
|
||||
std::vector<std::string> packs
|
||||
std::vector<std::string> packsToAdd,
|
||||
std::vector<std::string> packsToRemove
|
||||
);
|
||||
|
||||
void createWorld(
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../../../frontend/screens/MenuScreen.hpp"
|
||||
#include "../../../logic/LevelController.h"
|
||||
#include "../../../logic/EngineController.hpp"
|
||||
#include "../../../world/Level.h"
|
||||
#include "../../../window/Events.h"
|
||||
#include "../../../window/Window.h"
|
||||
#include "../../../world/WorldGenerators.h"
|
||||
@@ -37,6 +38,12 @@ static int l_open_world(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_reopen_world(lua_State* L) {
|
||||
auto controller = scripting::engine->getController();
|
||||
controller->reopenWorld(scripting::level->getWorld());
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_close_world(lua_State* L) {
|
||||
if (scripting::controller == nullptr) {
|
||||
luaL_error(L, "no world open");
|
||||
@@ -59,35 +66,30 @@ static int l_delete_world(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_remove_packs(lua_State* L) {
|
||||
static int l_reconfig_packs(lua_State* L) {
|
||||
if (!lua_istable(L, 1)) {
|
||||
luaL_error(L, "strings array expected as an argument");
|
||||
luaL_error(L, "strings array expected as the first argument");
|
||||
}
|
||||
std::vector<std::string> packs;
|
||||
int len = lua_objlen(L, 1);
|
||||
for (int i = 0; i < len; i++) {
|
||||
lua_rawgeti(L, -1, i+1);
|
||||
packs.push_back(lua_tostring(L, -1));
|
||||
if (!lua_istable(L, 2)) {
|
||||
luaL_error(L, "strings array expected as the second argument");
|
||||
}
|
||||
std::vector<std::string> addPacks;
|
||||
int addLen = lua_objlen(L, 1);
|
||||
for (int i = 0; i < addLen; i++) {
|
||||
lua_rawgeti(L, 1, i+1);
|
||||
addPacks.push_back(lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
auto controller = scripting::engine->getController();
|
||||
controller->removePacks(scripting::controller, packs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_add_packs(lua_State* L) {
|
||||
if (!lua_istable(L, 1)) {
|
||||
luaL_error(L, "strings array expected as an argument");
|
||||
}
|
||||
std::vector<std::string> packs;
|
||||
int len = lua_objlen(L, 1);
|
||||
for (int i = 0; i < len; i++) {
|
||||
lua_rawgeti(L, -1, i+1);
|
||||
packs.push_back(lua_tostring(L, -1));
|
||||
std::vector<std::string> remPacks;
|
||||
int remLen = lua_objlen(L, 2);
|
||||
for (int i = 0; i < remLen; i++) {
|
||||
lua_rawgeti(L, 2, i+1);
|
||||
remPacks.push_back(lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
auto controller = scripting::engine->getController();
|
||||
controller->addPacks(scripting::controller, packs);
|
||||
controller->reconfigPacks(scripting::controller, addPacks, remPacks);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -174,10 +176,10 @@ static int l_get_generators(lua_State* L) {
|
||||
const luaL_Reg corelib [] = {
|
||||
{"new_world", lua_wrap_errors<l_new_world>},
|
||||
{"open_world", lua_wrap_errors<l_open_world>},
|
||||
{"reopen_world", lua_wrap_errors<l_reopen_world>},
|
||||
{"close_world", lua_wrap_errors<l_close_world>},
|
||||
{"delete_world", lua_wrap_errors<l_delete_world>},
|
||||
{"add_packs", lua_wrap_errors<l_add_packs>},
|
||||
{"remove_packs", lua_wrap_errors<l_remove_packs>},
|
||||
{"reconfig_packs", lua_wrap_errors<l_reconfig_packs>},
|
||||
{"get_bindings", lua_wrap_errors<l_get_bindings>},
|
||||
{"get_setting", lua_wrap_errors<l_get_setting>},
|
||||
{"set_setting", lua_wrap_errors<l_set_setting>},
|
||||
|
||||
@@ -27,7 +27,7 @@ using namespace gui;
|
||||
|
||||
struct DocumentNode {
|
||||
UiDocument* document;
|
||||
UINode* node;
|
||||
std::shared_ptr<UINode> node;
|
||||
};
|
||||
|
||||
static DocumentNode getDocumentNode(lua_State* L, const std::string& name, const std::string& nodeName) {
|
||||
@@ -39,7 +39,7 @@ static DocumentNode getDocumentNode(lua_State* L, const std::string& name, const
|
||||
if (node == nullptr) {
|
||||
luaL_error(L, "document '%s' has no element with id '%s'", name.c_str(), nodeName.c_str());
|
||||
}
|
||||
return {doc, node.get()};
|
||||
return {doc, node};
|
||||
}
|
||||
|
||||
static bool getattr(lua_State* L, TrackBar* bar, const std::string& attr) {
|
||||
@@ -137,9 +137,9 @@ static bool getattr(lua_State* L, TextBox* box, const std::string& attr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static DocumentNode getDocumentNode(lua_State* L) {
|
||||
lua_getfield(L, 1, "docname");
|
||||
lua_getfield(L, 1, "name");
|
||||
static DocumentNode getDocumentNode(lua_State* L, int idx=1) {
|
||||
lua_getfield(L, idx, "docname");
|
||||
lua_getfield(L, idx, "name");
|
||||
auto docname = lua_tostring(L, -2);
|
||||
auto name = lua_tostring(L, -1);
|
||||
auto node = getDocumentNode(L, docname, name);
|
||||
@@ -149,14 +149,14 @@ static DocumentNode getDocumentNode(lua_State* L) {
|
||||
|
||||
static int menu_back(lua_State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto menu = dynamic_cast<Menu*>(node.node);
|
||||
auto menu = dynamic_cast<Menu*>(node.node.get());
|
||||
menu->back();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int menu_reset(lua_State* L) {
|
||||
auto node = getDocumentNode(L);
|
||||
auto menu = dynamic_cast<Menu*>(node.node);
|
||||
auto menu = dynamic_cast<Menu*>(node.node.get());
|
||||
menu->reset();
|
||||
return 0;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ static bool setattr(lua_State* L, InventoryView* view, const std::string& attr)
|
||||
|
||||
static int container_add(lua_State* L) {
|
||||
auto docnode = getDocumentNode(L);
|
||||
auto node = dynamic_cast<Container*>(docnode.node);
|
||||
auto node = dynamic_cast<Container*>(docnode.node.get());
|
||||
auto xmlsrc = lua_tostring(L, 2);
|
||||
try {
|
||||
auto subnode = guiutil::create(xmlsrc, docnode.document->getEnvironment());
|
||||
@@ -261,6 +261,14 @@ static int container_add(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int container_clear(lua_State* L) {
|
||||
auto node = getDocumentNode(L, 1);
|
||||
if (auto container = std::dynamic_pointer_cast<Container>(node.node)) {
|
||||
container->clear();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool getattr(lua_State* L, Container* container, const std::string& attr) {
|
||||
if (container == nullptr)
|
||||
return false;
|
||||
@@ -268,6 +276,9 @@ static bool getattr(lua_State* L, Container* container, const std::string& attr)
|
||||
if (attr == "add") {
|
||||
lua_pushcfunction(L, container_add);
|
||||
return true;
|
||||
} else if (attr == "clear") {
|
||||
lua_pushcfunction(L, container_clear);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -283,6 +294,13 @@ static bool getattr(lua_State* L, InventoryView* inventory, const std::string& a
|
||||
return false;
|
||||
}
|
||||
|
||||
static int uinode_move_into(lua_State* L) {
|
||||
auto node = getDocumentNode(L, 1);
|
||||
auto dest = getDocumentNode(L, 2);
|
||||
UINode::moveInto(node.node, std::dynamic_pointer_cast<Container>(dest.node));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_gui_getattr(lua_State* L) {
|
||||
auto docname = lua_tostring(L, 1);
|
||||
auto element = lua_tostring(L, 2);
|
||||
@@ -307,23 +325,26 @@ static int l_gui_getattr(lua_State* L) {
|
||||
} else if (attr == "enabled") {
|
||||
lua_pushboolean(L, node->isEnabled());
|
||||
return 1;
|
||||
} else if (attr == "move_into") {
|
||||
lua_pushcfunction(L, uinode_move_into);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (getattr(L, dynamic_cast<Container*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Container*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<Button*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Button*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<Label*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Label*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<TextBox*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<TextBox*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<TrackBar*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<TrackBar*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<FullCheckBox*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<FullCheckBox*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<Menu*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<Menu*>(node.get()), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<InventoryView*>(node), attr))
|
||||
if (getattr(L, dynamic_cast<InventoryView*>(node.get()), attr))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@@ -356,19 +377,19 @@ static int l_gui_setattr(lua_State* L) {
|
||||
} else if (attr == "enabled") {
|
||||
node->setEnabled(lua_toboolean(L, 4));
|
||||
} else {
|
||||
if (setattr(L, dynamic_cast<Button*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<Button*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<Label*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<Label*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<TextBox*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<TextBox*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<TrackBar*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<TrackBar*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<FullCheckBox*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<FullCheckBox*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<Menu*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<Menu*>(node.get()), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<InventoryView*>(node), attr))
|
||||
if (setattr(L, dynamic_cast<InventoryView*>(node.get()), attr))
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ struct GraphicsSettings {
|
||||
/// @brief Enable blocks backlight to prevent complete darkness
|
||||
FlagSetting backlight {true};
|
||||
/// @brief Enable chunks frustum culling
|
||||
FlagSetting frustumCulling {true}; // redutant?
|
||||
FlagSetting frustumCulling {true};
|
||||
IntegerSetting skyboxResolution {64 + 32, 64, 128};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user