frontend/gui refactor
This commit is contained in:
parent
8c722b146e
commit
1ba563d42a
@ -214,7 +214,7 @@ void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
||||
void Engine::setLanguage(std::string locale) {
|
||||
settings.ui.language = locale;
|
||||
langs::setup(paths->getResources(), locale, contentPacks);
|
||||
menus::create_menus(this, gui->getMenu());
|
||||
menus::create_menus(this);
|
||||
}
|
||||
|
||||
gui::GUI* Engine::getGUI() {
|
||||
|
||||
@ -26,7 +26,7 @@ GUI::GUI() {
|
||||
uicamera->perspective = false;
|
||||
uicamera->flipped = true;
|
||||
|
||||
menu = new PagesControl();
|
||||
menu = std::make_shared<PagesControl>();
|
||||
container->add(menu);
|
||||
container->scrollable(false);
|
||||
}
|
||||
@ -36,7 +36,7 @@ GUI::~GUI() {
|
||||
delete container;
|
||||
}
|
||||
|
||||
PagesControl* GUI::getMenu() {
|
||||
std::shared_ptr<PagesControl> GUI::getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
||||
|
||||
@ -59,13 +59,13 @@ namespace gui {
|
||||
std::unordered_map<std::string, std::shared_ptr<UINode>> storage;
|
||||
|
||||
Camera* uicamera;
|
||||
PagesControl* menu;
|
||||
std::shared_ptr<PagesControl> menu;
|
||||
void actMouse(float delta);
|
||||
public:
|
||||
GUI();
|
||||
~GUI();
|
||||
|
||||
PagesControl* getMenu();
|
||||
std::shared_ptr<PagesControl> getMenu();
|
||||
|
||||
std::shared_ptr<UINode> getFocused() const;
|
||||
bool isFocusCaught() const;
|
||||
|
||||
@ -20,6 +20,7 @@ Label::Label(std::string text, std::string fontName)
|
||||
: UINode(vec2(), vec2(text.length() * 8, 15)),
|
||||
text(util::str2wstr_utf8(text)),
|
||||
fontName_(fontName) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +28,7 @@ Label::Label(std::wstring text, std::string fontName)
|
||||
: UINode(vec2(), vec2(text.length() * 8, 15)),
|
||||
text(text),
|
||||
fontName_(fontName) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
void Label::setText(std::wstring text) {
|
||||
@ -314,7 +316,7 @@ void TextBox::text(std::wstring value) {
|
||||
InputBindBox::InputBindBox(Binding& binding, vec4 padding)
|
||||
: Panel(vec2(100,32), padding, 0, false),
|
||||
binding(binding) {
|
||||
label = new Label(L"");
|
||||
label = std::make_shared<Label>(L"");
|
||||
add(label);
|
||||
scrollable(false);
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ namespace gui {
|
||||
protected:
|
||||
glm::vec4 hoverColor {0.05f, 0.1f, 0.2f, 0.75f};
|
||||
glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
Label* label;
|
||||
std::shared_ptr<Label> label;
|
||||
Binding& binding;
|
||||
public:
|
||||
InputBindBox(Binding& binding, glm::vec4 padding=glm::vec4(6.0f));
|
||||
|
||||
@ -10,24 +10,31 @@ using namespace gui;
|
||||
using glm::vec2;
|
||||
using glm::vec4;
|
||||
|
||||
Button* guiutil::backButton(PagesControl* menu) {
|
||||
return (new Button(langs::get(L"Back"), vec4(10.f)))->listenAction([=](GUI* gui) {
|
||||
std::shared_ptr<Button> guiutil::backButton(std::shared_ptr<PagesControl> menu) {
|
||||
auto button = std::make_shared<Button>(
|
||||
langs::get(L"Back"), vec4(10.f)
|
||||
);
|
||||
button->listenAction([=](GUI* gui) {
|
||||
menu->back();
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
Button* guiutil::gotoButton(
|
||||
std::wstring text,
|
||||
const std::string& page,
|
||||
PagesControl* menu) {
|
||||
std::shared_ptr<Button> guiutil::gotoButton(
|
||||
std::wstring text,
|
||||
const std::string& page,
|
||||
std::shared_ptr<PagesControl> menu
|
||||
) {
|
||||
text = langs::get(text, L"menu");
|
||||
return (new Button(text, vec4(10.f)))->listenAction([=](GUI* gui) {
|
||||
auto button = std::make_shared<Button>(text, vec4(10.f));
|
||||
button->listenAction([=](GUI* gui) {
|
||||
menu->set(page);
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
void guiutil::alert(GUI* gui, const std::wstring& text, gui::runnable on_hidden) {
|
||||
PagesControl* menu = gui->getMenu();
|
||||
auto menu = gui->getMenu();
|
||||
Panel* panel = new Panel(vec2(500, 200), vec4(8.0f), 8.0f);
|
||||
panel->setColor(vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
|
||||
@ -43,17 +50,19 @@ void guiutil::alert(GUI* gui, const std::wstring& text, gui::runnable on_hidden)
|
||||
}
|
||||
extra = std::min(extra, wrap_length);
|
||||
std::wstring part = text.substr(offset, extra);
|
||||
panel->add(new Label(part));
|
||||
panel->add(std::make_shared<Label>(part));
|
||||
offset += extra;
|
||||
}
|
||||
} else {
|
||||
panel->add(new Label(text));
|
||||
panel->add(std::make_shared<Label>(text));
|
||||
}
|
||||
panel->add((new Button(langs::get(L"Ok"), vec4(10.f)))->listenAction([=](GUI* gui) {
|
||||
auto button = std::make_shared<Button>(langs::get(L"Ok"), vec4(10.f));
|
||||
button->listenAction([=](GUI* gui) {
|
||||
if (on_hidden)
|
||||
on_hidden();
|
||||
menu->back();
|
||||
}));
|
||||
});
|
||||
panel->add(button);
|
||||
panel->refresh();
|
||||
menu->add("<alert>", panel);
|
||||
menu->set("<alert>");
|
||||
@ -68,20 +77,27 @@ void guiutil::confirm(
|
||||
if (yestext.empty()) yestext = langs::get(L"Yes");
|
||||
if (notext.empty()) notext = langs::get(L"No");
|
||||
|
||||
PagesControl* menu = gui->getMenu();
|
||||
Panel* panel = new Panel(vec2(600, 200), vec4(8.0f), 8.0f);
|
||||
auto menu = gui->getMenu();
|
||||
auto panel = std::make_shared<Panel>(vec2(600, 200), vec4(8.0f), 8.0f);
|
||||
panel->setColor(vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
panel->add(new Label(text));
|
||||
Panel* subpanel = new Panel(vec2(600, 53));
|
||||
panel->add(std::make_shared<Label>(text));
|
||||
auto subpanel = std::make_shared<Panel>(vec2(600, 53));
|
||||
subpanel->setColor(vec4(0));
|
||||
subpanel->add((new Button(yestext, vec4(8.0f)))->listenAction([=](GUI*){
|
||||
|
||||
auto yesbtn = std::make_shared<Button>(yestext, vec4(8.f));
|
||||
yesbtn->listenAction([=](GUI*){
|
||||
if (on_confirm)
|
||||
on_confirm();
|
||||
menu->back();
|
||||
}));
|
||||
subpanel->add((new Button(notext, vec4(8.0f)))->listenAction([=](GUI*){
|
||||
});
|
||||
subpanel->add(yesbtn);
|
||||
|
||||
auto nobtn = std::make_shared<Button>(notext, vec4(8.f));
|
||||
nobtn->listenAction([=](GUI*){
|
||||
menu->back();
|
||||
}));
|
||||
});
|
||||
subpanel->add(nobtn);
|
||||
|
||||
panel->add(subpanel);
|
||||
|
||||
panel->refresh();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#ifndef FRONTEND_GUI_GUI_UTIL_H_
|
||||
#define FRONTEND_GUI_GUI_UTIL_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "GUI.h"
|
||||
|
||||
@ -9,11 +10,28 @@ namespace gui {
|
||||
}
|
||||
|
||||
namespace guiutil {
|
||||
gui::Button* backButton(gui::PagesControl* menu);
|
||||
gui::Button* gotoButton(std::wstring text, const std::string& page, gui::PagesControl* menu);
|
||||
void alert(gui::GUI* gui, const std::wstring& text, gui::runnable on_hidden=nullptr);
|
||||
void confirm(gui::GUI* gui, const std::wstring& text, gui::runnable on_confirm=nullptr,
|
||||
std::wstring yestext=L"", std::wstring notext=L"");
|
||||
std::shared_ptr<gui::Button> backButton(
|
||||
std::shared_ptr<gui::PagesControl> menu
|
||||
);
|
||||
|
||||
std::shared_ptr<gui::Button> gotoButton(
|
||||
std::wstring text,
|
||||
const std::string& page,
|
||||
std::shared_ptr<gui::PagesControl> menu
|
||||
);
|
||||
|
||||
void alert(
|
||||
gui::GUI* gui,
|
||||
const std::wstring& text,
|
||||
gui::runnable on_hidden=nullptr
|
||||
);
|
||||
|
||||
void confirm(
|
||||
gui::GUI* gui,
|
||||
const std::wstring& text,
|
||||
gui::runnable on_confirm=nullptr,
|
||||
std::wstring yestext=L"",
|
||||
std::wstring notext=L"");
|
||||
}
|
||||
|
||||
#endif // FRONTEND_GUI_GUI_UTIL_H_
|
||||
|
||||
@ -108,10 +108,6 @@ void Container::add(std::shared_ptr<UINode> node) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::add(UINode* node) {
|
||||
add(std::shared_ptr<UINode>(node));
|
||||
}
|
||||
|
||||
void Container::add(std::shared_ptr<UINode> node, glm::vec2 coord) {
|
||||
node->setCoord(coord);
|
||||
add(node);
|
||||
|
||||
@ -39,7 +39,6 @@ namespace gui {
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void addBack(std::shared_ptr<UINode> node);
|
||||
virtual void add(std::shared_ptr<UINode> node);
|
||||
virtual void add(UINode* node);
|
||||
virtual void add(std::shared_ptr<UINode> node, glm::vec2 coord);
|
||||
virtual void remove(std::shared_ptr<UINode> node);
|
||||
virtual void scrolled(int value) override;
|
||||
|
||||
@ -97,18 +97,18 @@ std::shared_ptr<UINode> HudRenderer::createDebugPanel(Engine* engine) {
|
||||
}));
|
||||
|
||||
for (int ax = 0; ax < 3; ax++){
|
||||
Panel* sub = new Panel(vec2(10, 27), vec4(0.0f));
|
||||
auto sub = std::make_shared<Panel>(vec2(10, 27), vec4(0.0f));
|
||||
sub->orientation(Orientation::horizontal);
|
||||
|
||||
std::wstring str = L"x: ";
|
||||
str[0] += ax;
|
||||
Label* label = new Label(str);
|
||||
auto label = std::make_shared<Label>(str);
|
||||
label->setMargin(vec4(2, 3, 2, 3));
|
||||
sub->add(label);
|
||||
sub->setColor(vec4(0.0f));
|
||||
|
||||
// Coord input
|
||||
TextBox* box = new TextBox(L"");
|
||||
auto box = std::make_shared<TextBox>(L"");
|
||||
box->textSupplier([=]() {
|
||||
Hitbox* hitbox = level->player->hitbox.get();
|
||||
return util::to_wstring(hitbox->position[ax], 2);
|
||||
@ -139,19 +139,21 @@ std::shared_ptr<UINode> HudRenderer::createDebugPanel(Engine* engine) {
|
||||
return L"time: "+timeString;
|
||||
}));
|
||||
{
|
||||
TrackBar* bar = new TrackBar(0.0f, 1.0f, 1.0f, 0.005f, 8);
|
||||
auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 1.0f, 0.005f, 8);
|
||||
bar->supplier([=]() {return level->world->daytime;});
|
||||
bar->consumer([=](double val) {level->world->daytime = val;});
|
||||
panel->add(bar);
|
||||
}
|
||||
{
|
||||
TrackBar* bar = new TrackBar(0.0f, 1.0f, 0.0f, 0.005f, 8);
|
||||
auto bar = std::make_shared<TrackBar>(0.0f, 1.0f, 0.0f, 0.005f, 8);
|
||||
bar->supplier([=]() {return WorldRenderer::fog;});
|
||||
bar->consumer([=](double val) {WorldRenderer::fog = val;});
|
||||
panel->add(bar);
|
||||
}
|
||||
{
|
||||
auto checkbox = new FullCheckBox(L"Show Chunk Borders", vec2(400, 32));
|
||||
auto checkbox = std::make_shared<FullCheckBox>(
|
||||
L"Show Chunk Borders", vec2(400, 32)
|
||||
);
|
||||
checkbox->supplier([=]() {
|
||||
return engine->getSettings().debug.showChunkBorders;
|
||||
});
|
||||
|
||||
@ -37,6 +37,8 @@ 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) ^
|
||||
@ -46,13 +48,20 @@ inline uint64_t randU64() {
|
||||
((uint64_t)rand() << 56);
|
||||
}
|
||||
|
||||
std::shared_ptr<Panel> create_page(
|
||||
Engine* engine,
|
||||
std::string name,
|
||||
int width,
|
||||
float opacity,
|
||||
int interval) {
|
||||
PagesControl* menu = engine->getGUI()->getMenu();
|
||||
static std::shared_ptr<Label> create_label(gui::wstringsupplier supplier) {
|
||||
auto label = std::make_shared<Label>(L"-");
|
||||
label->textSupplier(supplier);
|
||||
return label;
|
||||
}
|
||||
|
||||
static std::shared_ptr<Panel> create_page(
|
||||
Engine* engine,
|
||||
std::string name,
|
||||
int width,
|
||||
float opacity,
|
||||
int interval
|
||||
) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto panel = std::make_shared<Panel>(
|
||||
vec2(width, 200), vec4(8.0f), interval
|
||||
);
|
||||
@ -61,38 +70,43 @@ std::shared_ptr<Panel> create_page(
|
||||
return panel;
|
||||
}
|
||||
|
||||
Button* create_button(std::wstring text,
|
||||
glm::vec4 padding,
|
||||
glm::vec4 margin,
|
||||
gui::onaction action) {
|
||||
|
||||
auto btn = new Button(langs::get(text, L"menu"),
|
||||
padding, margin);
|
||||
static std::shared_ptr<Button> create_button(
|
||||
std::wstring text,
|
||||
glm::vec4 padding,
|
||||
glm::vec4 margin,
|
||||
gui::onaction action
|
||||
) {
|
||||
auto btn = std::make_shared<Button>(
|
||||
langs::get(text, L"menu"), padding, margin
|
||||
);
|
||||
btn->listenAction(action);
|
||||
return btn;
|
||||
}
|
||||
|
||||
void show_content_missing(Engine* engine, const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut) {
|
||||
static void show_content_missing(
|
||||
Engine* engine,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut
|
||||
) {
|
||||
auto* gui = engine->getGUI();
|
||||
auto* menu = gui->getMenu();
|
||||
auto menu = gui->getMenu();
|
||||
auto panel = create_page(engine, "missing-content", 500, 0.5f, 8);
|
||||
|
||||
panel->add(new Label(langs::get(L"menu.missing-content")));
|
||||
panel->add(std::make_shared<Label>(langs::get(L"menu.missing-content")));
|
||||
|
||||
Panel* subpanel = new Panel(vec2(500, 100));
|
||||
auto subpanel = std::make_shared<Panel>(vec2(500, 100));
|
||||
subpanel->setColor(vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
|
||||
for (auto& entry : lut->getMissingContent()) {
|
||||
Panel* hpanel = new Panel(vec2(500, 30));
|
||||
auto hpanel = std::make_shared<Panel>(vec2(500, 30));
|
||||
hpanel->setColor(vec4(0.0f));
|
||||
hpanel->orientation(Orientation::horizontal);
|
||||
|
||||
Label* namelabel = new Label(util::str2wstr_utf8(entry.name));
|
||||
auto namelabel = std::make_shared<Label>(util::str2wstr_utf8(entry.name));
|
||||
namelabel->setColor(vec4(1.0f, 0.2f, 0.2f, 0.5f));
|
||||
|
||||
auto contentname = util::str2wstr_utf8(contenttype_name(entry.type));
|
||||
Label* typelabel = new Label(L"["+contentname+L"]");
|
||||
auto typelabel = std::make_shared<Label>(L"["+contentname+L"]");
|
||||
typelabel->setColor(vec4(0.5f));
|
||||
hpanel->add(typelabel);
|
||||
hpanel->add(namelabel);
|
||||
@ -101,11 +115,13 @@ void show_content_missing(Engine* engine, const Content* content,
|
||||
subpanel->maxLength(400);
|
||||
panel->add(subpanel);
|
||||
|
||||
panel->add((new Button(langs::get(L"Back to Main Menu", L"menu"),
|
||||
vec4(8.0f)))
|
||||
->listenAction([=](GUI*){
|
||||
auto button = std::make_shared<Button>(
|
||||
langs::get(L"Back to Main Menu", L"menu"), vec4(8.0f)
|
||||
);
|
||||
button->listenAction([=](GUI*){
|
||||
menu->back();
|
||||
}));
|
||||
});
|
||||
panel->add(button);
|
||||
menu->set("missing-content");
|
||||
}
|
||||
|
||||
@ -113,7 +129,8 @@ void show_convert_request(
|
||||
Engine* engine,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut,
|
||||
fs::path folder) {
|
||||
fs::path folder
|
||||
) {
|
||||
guiutil::confirm(engine->getGUI(), langs::get(L"world.convert-request"),
|
||||
[=]() {
|
||||
// TODO: add multithreading here
|
||||
@ -125,7 +142,8 @@ void show_convert_request(
|
||||
}, L"", langs::get(L"Cancel"));
|
||||
}
|
||||
|
||||
void create_languages_panel(Engine* engine, PagesControl* menu) {
|
||||
void create_languages_panel(Engine* engine) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto panel = create_page(engine, "languages", 400, 0.5f, 1);
|
||||
panel->scrollable(true);
|
||||
|
||||
@ -138,7 +156,9 @@ void create_languages_panel(Engine* engine, PagesControl* menu) {
|
||||
auto& locale = langs::locales_info.at(name);
|
||||
std::string& fullName = locale.name;
|
||||
|
||||
Button* button = new Button(util::str2wstr_utf8(fullName), vec4(10.f));
|
||||
auto button = std::make_shared<Button>(
|
||||
util::str2wstr_utf8(fullName), vec4(10.f)
|
||||
);
|
||||
button->listenAction([=](GUI*) {
|
||||
engine->setLanguage(name);
|
||||
menu->back();
|
||||
@ -191,8 +211,8 @@ void open_world(std::string name, Engine* engine) {
|
||||
}
|
||||
}
|
||||
|
||||
Panel* create_worlds_panel(Engine* engine) {
|
||||
auto panel = new Panel(vec2(390, 200), vec4(5.0f));
|
||||
std::shared_ptr<Panel> create_worlds_panel(Engine* engine) {
|
||||
auto panel = std::make_shared<Panel>(vec2(390, 200), vec4(5.0f));
|
||||
panel->setColor(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
||||
panel->maxLength(400);
|
||||
|
||||
@ -205,13 +225,10 @@ Panel* create_worlds_panel(Engine* engine) {
|
||||
auto btn = std::make_shared<RichButton>(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));
|
||||
|
||||
auto label = std::make_shared<Label>(namews);
|
||||
label->setInteractive(false);
|
||||
btn->add(label, vec2(8, 8));
|
||||
btn->listenAction([=](GUI*) {
|
||||
open_world(name, engine);
|
||||
});
|
||||
btn->add(std::make_shared<Label>(namews), vec2(8, 8));
|
||||
|
||||
auto image = std::make_shared<Image>("gui/delete_icon", vec2(32, 32));
|
||||
image->setColor(vec4(1, 1, 1, 0.5f));
|
||||
@ -219,45 +236,47 @@ Panel* create_worlds_panel(Engine* engine) {
|
||||
auto delbtn = std::make_shared<Button>(image, vec4(2));
|
||||
delbtn->setColor(vec4(0.0f));
|
||||
delbtn->setHoverColor(vec4(1.0f, 1.0f, 1.0f, 0.17f));
|
||||
|
||||
btn->add(delbtn, vec2(330, 3));
|
||||
|
||||
delbtn->listenAction([=](GUI* gui) {
|
||||
guiutil::confirm(gui, langs::get(L"delete-confirm", L"world")+
|
||||
L" ("+util::str2wstr_utf8(folder.u8string())+L")", [=]()
|
||||
{
|
||||
std::cout << "deleting " << folder.u8string() << std::endl;
|
||||
fs::remove_all(folder);
|
||||
menus::refresh_menus(engine, gui->getMenu());
|
||||
menus::refresh_menus(engine);
|
||||
});
|
||||
});
|
||||
btn->add(delbtn, vec2(330, 3));
|
||||
|
||||
panel->add(btn);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
void create_main_menu_panel(Engine* engine, PagesControl* menu) {
|
||||
void create_main_menu_panel(Engine* engine) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
|
||||
auto panel = create_page(engine, "main", 400, 0.0f, 1);
|
||||
panel->add(guiutil::gotoButton(L"New World", "new-world", menu));
|
||||
panel->add(create_worlds_panel(engine));
|
||||
panel->add(guiutil::gotoButton(L"Settings", "settings", menu));
|
||||
panel->add((new Button(langs::get(L"Quit", L"menu"), vec4(10.f)))
|
||||
->listenAction([](GUI* gui) {
|
||||
|
||||
auto quitbtn = std::make_shared<Button>(
|
||||
langs::get(L"Quit", L"menu"), vec4(10.f)
|
||||
);
|
||||
quitbtn->listenAction([](GUI* gui) {
|
||||
Window::setShouldClose(true);
|
||||
}));
|
||||
});
|
||||
panel->add(quitbtn);
|
||||
}
|
||||
|
||||
typedef std::function<void(const ContentPack& pack)> packconsumer;
|
||||
|
||||
const int PACKS_PANEL_WIDTH = 550;
|
||||
|
||||
std::shared_ptr<Panel> create_packs_panel(
|
||||
const std::vector<ContentPack>& packs,
|
||||
Engine* engine,
|
||||
bool backbutton,
|
||||
packconsumer callback)
|
||||
{
|
||||
packconsumer callback
|
||||
){
|
||||
auto assets = engine->getAssets();
|
||||
auto panel = std::make_shared<Panel>(vec2(PACKS_PANEL_WIDTH, 200), vec4(5.0f));
|
||||
panel->setColor(vec4(1.0f, 1.0f, 1.0f, 0.07f));
|
||||
@ -310,7 +329,8 @@ std::shared_ptr<Panel> create_packs_panel(
|
||||
}
|
||||
|
||||
// TODO: refactor
|
||||
void create_content_panel(Engine* engine, PagesControl* menu) {
|
||||
void create_content_panel(Engine* engine) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto paths = engine->getPaths();
|
||||
auto mainPanel = create_page(engine, "content", PACKS_PANEL_WIDTH, 0.0f, 5);
|
||||
|
||||
@ -375,7 +395,7 @@ inline uint64_t str2seed(std::wstring seedstr) {
|
||||
}
|
||||
}
|
||||
|
||||
void create_new_world_panel(Engine* engine, PagesControl* menu) {
|
||||
void create_new_world_panel(Engine* engine) {
|
||||
auto panel = create_page(engine, "new-world", 400, 0.0f, 1);
|
||||
|
||||
panel->add(std::make_shared<Label>(langs::get(L"Name", L"world")));
|
||||
@ -398,54 +418,59 @@ void create_new_world_panel(Engine* engine, PagesControl* menu) {
|
||||
if (!nameInput->validate())
|
||||
return;
|
||||
|
||||
std::wstring name = nameInput->text();
|
||||
std::string nameutf8 = util::wstr2str_utf8(name);
|
||||
EnginePaths* paths = engine->getPaths();
|
||||
|
||||
std::wstring seedstr = seedInput->text();
|
||||
uint64_t seed = str2seed(seedstr);
|
||||
std::string name = util::wstr2str_utf8(nameInput->text());
|
||||
uint64_t seed = str2seed(seedInput->text());
|
||||
std::cout << "world seed: " << seed << std::endl;
|
||||
|
||||
auto folder = paths->getWorldsFolder()/fs::u8path(nameutf8);
|
||||
EnginePaths* paths = engine->getPaths();
|
||||
auto folder = paths->getWorldsFolder()/fs::u8path(name);
|
||||
try {
|
||||
engine->loadAllPacks();
|
||||
engine->loadContent();
|
||||
paths->setWorldFolder(folder);
|
||||
} catch (const contentpack_error& error) {
|
||||
guiutil::alert(engine->getGUI(),
|
||||
langs::get(L"Content Error", L"menu")+
|
||||
L":\n"+util::str2wstr_utf8(std::string(error.what())+
|
||||
"\npack '"+error.getPackId()+"' from "+
|
||||
error.getFolder().u8string()));
|
||||
guiutil::alert(
|
||||
engine->getGUI(),
|
||||
langs::get(L"Content Error", L"menu")+L":\n"+
|
||||
util::str2wstr_utf8(
|
||||
std::string(error.what())+
|
||||
"\npack '"+error.getPackId()+"' from "+
|
||||
error.getFolder().u8string()
|
||||
)
|
||||
);
|
||||
return;
|
||||
} catch (const std::runtime_error& error) {
|
||||
guiutil::alert(engine->getGUI(),
|
||||
langs::get(L"Content Error", L"menu")+
|
||||
L": "+util::str2wstr_utf8(error.what()));
|
||||
guiutil::alert(
|
||||
engine->getGUI(),
|
||||
langs::get(L"Content Error", L"menu")+
|
||||
L": "+util::str2wstr_utf8(error.what())
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Level* level = World::create(
|
||||
nameutf8, folder, seed,
|
||||
name, folder, seed,
|
||||
engine->getSettings(),
|
||||
engine->getContent(),
|
||||
engine->getContentPacks());
|
||||
engine->getContentPacks()
|
||||
);
|
||||
engine->setScreen(std::make_shared<LevelScreen>(engine, level));
|
||||
}));
|
||||
panel->add(guiutil::backButton(menu));
|
||||
panel->add(guiutil::backButton(engine->getGUI()->getMenu()));
|
||||
}
|
||||
|
||||
void create_controls_panel(Engine* engine, PagesControl* menu) {
|
||||
void create_controls_panel(Engine* engine) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto panel = create_page(engine, "controls", 400, 0.0f, 1);
|
||||
|
||||
/* Camera sensitivity setting track bar */{
|
||||
panel->add((new Label(L""))->textSupplier([=]() {
|
||||
panel->add(create_label([=]() {
|
||||
float s = engine->getSettings().camera.sensitivity;
|
||||
return langs::get(L"Mouse Sensitivity", L"settings")+L": "+
|
||||
util::to_wstring(s, 1);
|
||||
}));
|
||||
|
||||
TrackBar* trackbar = new TrackBar(0.1, 10.0, 2.0, 0.1, 4);
|
||||
auto trackbar = std::make_shared<TrackBar>(0.1, 10.0, 2.0, 0.1, 4);
|
||||
trackbar->supplier([=]() {
|
||||
return engine->getSettings().camera.sensitivity;
|
||||
});
|
||||
@ -455,19 +480,18 @@ void create_controls_panel(Engine* engine, PagesControl* menu) {
|
||||
panel->add(trackbar);
|
||||
}
|
||||
|
||||
Panel* scrollPanel = new Panel(vec2(400, 200), vec4(2.0f), 1.0f);
|
||||
auto scrollPanel = std::make_shared<Panel>(vec2(400, 200), vec4(2.0f), 1.0f);
|
||||
scrollPanel->setColor(vec4(0.0f, 0.0f, 0.0f, 0.3f));
|
||||
scrollPanel->maxLength(400);
|
||||
for (auto& entry : Events::bindings){
|
||||
std::string bindname = entry.first;
|
||||
|
||||
Panel* subpanel = new Panel(vec2(400, 40), vec4(5.0f), 1.0f);
|
||||
auto subpanel = std::make_shared<Panel>(vec2(400, 40), vec4(5.0f), 1.0f);
|
||||
subpanel->setColor(vec4(0.0f));
|
||||
subpanel->orientation(Orientation::horizontal);
|
||||
subpanel->add(std::make_shared<InputBindBox>(entry.second));
|
||||
|
||||
InputBindBox* bindbox = new InputBindBox(entry.second);
|
||||
subpanel->add(bindbox);
|
||||
Label* label = new Label(langs::get(util::str2wstr_utf8(bindname)));
|
||||
auto label = std::make_shared<Label>(langs::get(util::str2wstr_utf8(bindname)));
|
||||
label->setMargin(vec4(6.0f));
|
||||
subpanel->add(label);
|
||||
scrollPanel->add(subpanel);
|
||||
@ -476,16 +500,17 @@ void create_controls_panel(Engine* engine, PagesControl* menu) {
|
||||
panel->add(guiutil::backButton(menu));
|
||||
}
|
||||
|
||||
void create_settings_panel(Engine* engine, PagesControl* menu) {
|
||||
void create_settings_panel(Engine* engine) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto panel = create_page(engine, "settings", 400, 0.0f, 1);
|
||||
|
||||
/* Load Distance setting track bar */{
|
||||
panel->add((new Label(L""))->textSupplier([=]() {
|
||||
panel->add(create_label([=]() {
|
||||
return langs::get(L"Load Distance", L"settings")+L": " +
|
||||
std::to_wstring(engine->getSettings().chunks.loadDistance);
|
||||
}));
|
||||
|
||||
TrackBar* trackbar = new TrackBar(3, 66, 10, 1, 3);
|
||||
auto trackbar = std::make_shared<TrackBar>(3, 66, 10, 1, 3);
|
||||
trackbar->supplier([=]() {
|
||||
return engine->getSettings().chunks.loadDistance;
|
||||
});
|
||||
@ -496,12 +521,12 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
|
||||
}
|
||||
|
||||
/* Load Speed setting track bar */{
|
||||
panel->add((new Label(L""))->textSupplier([=]() {
|
||||
panel->add(create_label([=]() {
|
||||
return langs::get(L"Load Speed", L"settings")+L": " +
|
||||
std::to_wstring(engine->getSettings().chunks.loadSpeed);
|
||||
}));
|
||||
|
||||
TrackBar* trackbar = new TrackBar(1, 32, 10, 1, 1);
|
||||
auto trackbar = std::make_shared<TrackBar>(1, 32, 10, 1, 1);
|
||||
trackbar->supplier([=]() {
|
||||
return engine->getSettings().chunks.loadSpeed;
|
||||
});
|
||||
@ -512,13 +537,13 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
|
||||
}
|
||||
|
||||
/* Fog Curve setting track bar */{
|
||||
panel->add((new Label(L""))->textSupplier([=]() {
|
||||
panel->add(create_label([=]() {
|
||||
float value = engine->getSettings().graphics.fogCurve;
|
||||
return langs::get(L"Fog Curve", L"settings")+L": " +
|
||||
util::to_wstring(value, 1);
|
||||
}));
|
||||
|
||||
TrackBar* trackbar = new TrackBar(1.0, 6.0, 1.0, 0.1, 2);
|
||||
auto trackbar = std::make_shared<TrackBar>(1.0, 6.0, 1.0, 0.1, 2);
|
||||
trackbar->supplier([=]() {
|
||||
return engine->getSettings().graphics.fogCurve;
|
||||
});
|
||||
@ -529,12 +554,12 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
|
||||
}
|
||||
|
||||
/* Fov setting track bar */{
|
||||
panel->add((new Label(L""))->textSupplier([=]() {
|
||||
panel->add(create_label([=]() {
|
||||
int fov = (int)engine->getSettings().camera.fov;
|
||||
return langs::get(L"FOV", L"settings")+L": "+std::to_wstring(fov)+L"°";
|
||||
}));
|
||||
|
||||
TrackBar* trackbar = new TrackBar(30.0, 120.0, 90, 1, 4);
|
||||
auto trackbar = std::make_shared<TrackBar>(30.0, 120.0, 90, 1, 4);
|
||||
trackbar->supplier([=]() {
|
||||
return engine->getSettings().camera.fov;
|
||||
});
|
||||
@ -545,7 +570,9 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
|
||||
}
|
||||
|
||||
/* V-Sync checkbox */{
|
||||
auto checkbox = new FullCheckBox(langs::get(L"V-Sync", L"settings"), vec2(400, 32));
|
||||
auto checkbox = std::make_shared<FullCheckBox>(
|
||||
langs::get(L"V-Sync", L"settings"), vec2(400, 32)
|
||||
);
|
||||
checkbox->supplier([=]() {
|
||||
return engine->getSettings().display.swapInterval != 0;
|
||||
});
|
||||
@ -556,7 +583,9 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
|
||||
}
|
||||
|
||||
/* Backlight checkbox */{
|
||||
auto checkbox = new FullCheckBox(langs::get(L"Backlight", L"settings"), vec2(400, 32));
|
||||
auto checkbox = std::make_shared<FullCheckBox>(
|
||||
langs::get(L"Backlight", L"settings"), vec2(400, 32)
|
||||
);
|
||||
checkbox->supplier([=]() {
|
||||
return engine->getSettings().graphics.backlight != 0;
|
||||
});
|
||||
@ -576,14 +605,15 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
|
||||
panel->add(guiutil::backButton(menu));
|
||||
}
|
||||
|
||||
void create_pause_panel(Engine* engine, PagesControl* menu) {
|
||||
void create_pause_panel(Engine* engine) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto panel = create_page(engine, "pause", 400, 0.0f, 1);
|
||||
|
||||
panel->add(create_button(L"Continue", vec4(10.0f), vec4(1), [=](GUI*){
|
||||
menu->reset();
|
||||
}));
|
||||
panel->add(create_button(L"Content", vec4(10.0f), vec4(1), [=](GUI*) {
|
||||
create_content_panel(engine, menu);
|
||||
create_content_panel(engine);
|
||||
menu->set("content");
|
||||
}));
|
||||
panel->add(guiutil::gotoButton(L"Settings", "settings", menu));
|
||||
@ -596,16 +626,16 @@ void create_pause_panel(Engine* engine, PagesControl* menu) {
|
||||
}));
|
||||
}
|
||||
|
||||
void menus::create_menus(Engine* engine, PagesControl* menu) {
|
||||
create_new_world_panel(engine, menu);
|
||||
create_settings_panel(engine, menu);
|
||||
create_controls_panel(engine, menu);
|
||||
create_pause_panel(engine, menu);
|
||||
create_languages_panel(engine, menu);
|
||||
create_main_menu_panel(engine, menu);
|
||||
void menus::create_menus(Engine* engine) {
|
||||
create_new_world_panel(engine);
|
||||
create_settings_panel(engine);
|
||||
create_controls_panel(engine);
|
||||
create_pause_panel(engine);
|
||||
create_languages_panel(engine);
|
||||
create_main_menu_panel(engine);
|
||||
}
|
||||
|
||||
void menus::refresh_menus(Engine* engine, PagesControl* menu) {
|
||||
create_main_menu_panel(engine, menu);
|
||||
create_new_world_panel(engine, menu);
|
||||
void menus::refresh_menus(Engine* engine) {
|
||||
create_main_menu_panel(engine);
|
||||
create_new_world_panel(engine);
|
||||
}
|
||||
|
||||
@ -3,13 +3,9 @@
|
||||
|
||||
class Engine;
|
||||
|
||||
namespace gui {
|
||||
class PagesControl;
|
||||
}
|
||||
|
||||
namespace menus {
|
||||
void create_menus(Engine* engine, gui::PagesControl* menu);
|
||||
void refresh_menus(Engine* engine, gui::PagesControl* menu);
|
||||
void create_menus(Engine* engine);
|
||||
void refresh_menus(Engine* engine);
|
||||
}
|
||||
|
||||
#endif // FRONTEND_MENU_H_
|
||||
@ -45,7 +45,7 @@ Screen::~Screen() {
|
||||
|
||||
MenuScreen::MenuScreen(Engine* engine_) : Screen(engine_) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
menus::refresh_menus(engine, menu);
|
||||
menus::refresh_menus(engine);
|
||||
menu->reset();
|
||||
menu->set("main");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user