This commit is contained in:
Ara
2023-12-09 18:43:58 +06:00
19 changed files with 383 additions and 141 deletions
+12 -1
View File
@@ -27,6 +27,7 @@ GUI::GUI() {
menu = new PagesControl();
container->add(menu);
container->scrollable(false);
}
GUI::~GUI() {
@@ -160,4 +161,14 @@ shared_ptr<UINode> GUI::get(string name) {
void GUI::remove(string name) {
storage.erase(name);
}
}
void GUI::setFocus(shared_ptr<UINode> node) {
if (focus) {
focus->defocus();
}
focus = node;
if (focus) {
focus->focus(this);
}
}
+1
View File
@@ -76,6 +76,7 @@ namespace gui {
void store(std::string name, std::shared_ptr<UINode> node);
std::shared_ptr<UINode> get(std::string name);
void remove(std::string name);
void setFocus(std::shared_ptr<UINode> node);
};
}
+6 -5
View File
@@ -37,19 +37,20 @@ void guiutil::alert(GUI* gui, wstring text, gui::runnable on_hidden) {
menu->set("<alert>");
}
void guiutil::confirm(GUI* gui, wstring text, gui::runnable on_confirm) {
void guiutil::confirm(GUI* gui, wstring text, gui::runnable on_confirm,
wstring yestext, wstring notext) {
PagesControl* menu = gui->getMenu();
Panel* panel = new Panel(vec2(500, 200), vec4(8.0f), 8.0f);
Panel* panel = new Panel(vec2(600, 200), vec4(8.0f), 8.0f);
panel->color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
panel->add(new Label(text));
Panel* subpanel = new Panel(vec2(500, 53));
Panel* subpanel = new Panel(vec2(600, 53));
subpanel->color(vec4(0));
subpanel->add((new Button(L"Yes", vec4(8.0f)))->listenAction([=](GUI*){
subpanel->add((new Button(yestext, vec4(8.0f)))->listenAction([=](GUI*){
if (on_confirm)
on_confirm();
menu->back();
}));
subpanel->add((new Button(L"No", vec4(8.0f)))->listenAction([=](GUI*){
subpanel->add((new Button(notext, vec4(8.0f)))->listenAction([=](GUI*){
menu->back();
}));
panel->add(subpanel);
+2 -1
View File
@@ -12,7 +12,8 @@ namespace guiutil {
gui::Button* backButton(gui::PagesControl* menu);
gui::Button* gotoButton(std::wstring text, std::string page, gui::PagesControl* menu);
void alert(gui::GUI* gui, std::wstring text, gui::runnable on_hidden=nullptr);
void confirm(gui::GUI* gui, std::wstring text, gui::runnable on_confirm=nullptr);
void confirm(gui::GUI* gui, std::wstring text, gui::runnable on_confirm=nullptr,
std::wstring yestext=L"Yes", std::wstring notext=L"No");
}
#endif // FRONTEND_GUI_GUI_UTIL_H_
+84 -13
View File
@@ -13,11 +13,14 @@
#include "screens.h"
#include "../util/stringutil.h"
#include "../files/engine_paths.h"
#include "../files/WorldConverter.h"
#include "../world/World.h"
#include "../window/Events.h"
#include "../window/Window.h"
#include "../engine.h"
#include "../settings.h"
#include "../content/Content.h"
#include "../content/ContentLUT.h"
#include "gui/gui_util.h"
@@ -25,12 +28,69 @@ using glm::vec2;
using glm::vec4;
using std::string;
using std::wstring;
using std::make_unique;
using std::unique_ptr;
using std::shared_ptr;
using std::filesystem::path;
using std::filesystem::u8path;
using std::filesystem::directory_iterator;
using namespace gui;
void show_content_missing(GUI* gui, const Content* content, ContentLUT* lut) {
PagesControl* menu = gui->getMenu();
Panel* panel = new Panel(vec2(500, 200), vec4(8.0f), 8.0f);
panel->color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
panel->add(new Label(L"Content missing!"));
Panel* subpanel = new Panel(vec2(500, 100));
subpanel->color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
for (size_t i = 0; i < lut->countBlocks(); i++) {
// missing block
if (lut->getBlockId(i) == BLOCK_VOID) {
auto name = lut->getBlockName(i);
Panel* hpanel = new Panel(vec2(500, 30));
hpanel->color(vec4(0.0f));
hpanel->orientation(Orientation::horizontal);
Label* namelabel = new Label(util::str2wstr_utf8(name));
namelabel->color(vec4(1.0f, 0.2f, 0.2f, 0.5f));
Label* typelabel = new Label(L"[block]");
typelabel->color(vec4(0.5f));
hpanel->add(typelabel);
hpanel->add(namelabel);
subpanel->add(hpanel);
}
}
subpanel->maxLength(400);
panel->add(subpanel);
panel->add((new Button(L"Back to Main Menu", vec4(8.0f)))->listenAction([=](GUI*){
menu->back();
}));
panel->refresh();
menu->add("missing-content", panel);
menu->set("missing-content");
}
void show_convert_request(GUI* gui, const Content* content, ContentLUT* lut,
path folder) {
guiutil::confirm(gui, L"Content indices have changed! Convert "
+util::str2wstr_utf8(folder.string())+L"?",
[=]() {
std::cout << "Convert the world: " << folder.string() << std::endl;
// TODO: add multithreading here
auto converter = make_unique<WorldConverter>(folder, content, lut);
while (converter->hasNext()) {
converter->convertNext();
}
converter->write();
delete lut;
}, L"Yes", L"Cancel");
}
Panel* create_main_menu_panel(Engine* engine, PagesControl* menu) {
EnginePaths* paths = engine->getPaths();
@@ -40,7 +100,7 @@ Panel* create_main_menu_panel(Engine* engine, PagesControl* menu) {
panel->add(guiutil::gotoButton(L"New World", "new-world", menu));
Panel* worldsPanel = new Panel(vec2(390, 200), vec4(5.0f));
worldsPanel->color(vec4(0.1f));
worldsPanel->color(vec4(1.0f, 1.0f, 1.0f, 0.07f));
worldsPanel->maxLength(400);
path worldsFolder = paths->getWorldsFolder();
if (std::filesystem::is_directory(worldsFolder)) {
@@ -51,14 +111,25 @@ Panel* create_main_menu_panel(Engine* engine, PagesControl* menu) {
string name = entry.path().filename().string();
Button* button = new Button(util::str2wstr_utf8(name),
vec4(10.0f, 8.0f, 10.0f, 8.0f));
button->color(vec4(0.5f));
button->listenAction([=](GUI*) {
EngineSettings& settings = engine->getSettings();
button->color(vec4(1.0f, 1.0f, 1.0f, 0.1f));
button->listenAction([=](GUI* gui) {
auto* content = engine->getContent();
auto& settings = engine->getSettings();
auto folder = paths->getWorldsFolder()/u8path(name);
Level* level = World::load(folder, settings, engine->getContent());
auto screen = new LevelScreen(engine, level);
engine->setScreen(shared_ptr<Screen>(screen));
std::filesystem::create_directories(folder);
ContentLUT* lut = World::checkIndices(folder, content);
if (lut) {
if (lut->hasMissingContent()) {
show_content_missing(gui, content, lut);
delete lut;
} else {
show_convert_request(gui, content, lut, folder);
}
} else {
Level* level = World::load(folder, settings, content);
auto screen = new LevelScreen(engine, level);
engine->setScreen(shared_ptr<Screen>(screen));
}
});
worldsPanel->add(button);
}
@@ -140,12 +211,13 @@ Panel* create_new_world_panel(Engine* engine, PagesControl* menu) {
seed = hash(seedstr);
}
std::cout << "world seed: " << seed << std::endl;
EngineSettings& settings = engine->getSettings();
auto folder = paths->getWorldsFolder()/u8path(nameutf8);
std::filesystem::create_directories(folder);
Level* level = World::create(nameutf8, folder, seed, settings, engine->getContent());
Level* level = World::create(nameutf8,
folder,
seed,
engine->getSettings(),
engine->getContent());
auto screen = new LevelScreen(engine, level);
engine->setScreen(shared_ptr<Screen>(screen));
});
@@ -207,7 +279,6 @@ Panel* create_settings_panel(Engine* engine, PagesControl* menu) {
Panel* panel = new Panel(vec2(400, 200), vec4(5.0f), 1.0f);
panel->color(vec4(0.0f));
// TODO: simplify repeating code for trackbars
/* Load Distance setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() {
return L"Load Distance: " +