added FullCheckBox

This commit is contained in:
MihailRis 2024-01-11 04:08:36 +03:00
parent b2b961552b
commit 290fec379e
4 changed files with 69 additions and 65 deletions

View File

@ -333,7 +333,6 @@ void TrackBar::mouseMove(GUI*, int x, int y) {
// ================================ CheckBox ================================== // ================================ CheckBox ==================================
CheckBox::CheckBox(bool checked) : UINode(vec2(), vec2(32.0f)), checked_(checked) { CheckBox::CheckBox(bool checked) : UINode(vec2(), vec2(32.0f)), checked_(checked) {
color(vec4(0.0f, 0.0f, 0.0f, 0.5f)); color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
margin(vec4(0.0f, 0.0f, 5.0f, 0.0f));
} }
void CheckBox::draw(Batch2D* batch, Assets* assets) { void CheckBox::draw(Batch2D* batch, Assets* assets) {
@ -365,3 +364,16 @@ CheckBox* CheckBox::checked(bool flag) {
checked_ = flag; checked_ = flag;
return this; return this;
} }
FullCheckBox::FullCheckBox(std::wstring text, glm::vec2 size, bool checked)
: Panel(size),
checkbox(std::make_shared<CheckBox>(checked)){
color(vec4(0.0f));
orientation(Orientation::horizontal);
add(checkbox);
auto label = std::make_shared<Label>(text);
label->margin(vec4(5.0f, 5.0f, 0.0f, 0.0f));
add(label);
}

View File

@ -166,6 +166,29 @@ namespace gui {
return checked_; return checked_;
} }
}; };
class FullCheckBox : public Panel {
protected:
std::shared_ptr<CheckBox> checkbox;
public:
FullCheckBox(std::wstring text, glm::vec2 size, bool checked=false);
virtual void supplier(boolsupplier supplier) {
checkbox->supplier(supplier);
}
virtual void consumer(boolconsumer consumer) {
checkbox->consumer(consumer);
}
virtual void checked(bool flag) {
checkbox->checked(flag);
}
virtual bool checked() const {
return checkbox->checked();
}
};
} }
#endif // FRONTEND_GUI_CONTROLS_H_ #endif // FRONTEND_GUI_CONTROLS_H_

View File

@ -146,21 +146,14 @@ void HudRenderer::createDebugPanel(Engine* engine) {
panel->add(bar); panel->add(bar);
} }
{ {
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f); auto checkbox = new FullCheckBox(L"Show Chunk Borders", vec2(400, 32));
checkpanel->color(vec4(0.0f));
checkpanel->orientation(Orientation::horizontal);
CheckBox* checkbox = new CheckBox();
checkbox->supplier([=]() { checkbox->supplier([=]() {
return engine->getSettings().debug.showChunkBorders; return engine->getSettings().debug.showChunkBorders;
}); });
checkbox->consumer([=](bool checked) { checkbox->consumer([=](bool checked) {
engine->getSettings().debug.showChunkBorders = checked; engine->getSettings().debug.showChunkBorders = checked;
}); });
checkpanel->add(checkbox); panel->add(checkbox);
checkpanel->add(new Label(L"Show Chunk Borders"));
panel->add(checkpanel);
} }
panel->refresh(); panel->refresh();
} }

View File

@ -139,7 +139,6 @@ void create_languages_panel(Engine* engine, PagesControl* menu) {
Button* button = new Button(util::str2wstr_utf8(fullName), vec4(10.f)); Button* button = new Button(util::str2wstr_utf8(fullName), vec4(10.f));
button->listenAction([=](GUI*) { button->listenAction([=](GUI*) {
auto resdir = engine->getPaths()->getResources();
engine->setLanguage(name); engine->setLanguage(name);
menu->back(); menu->back();
}); });
@ -252,33 +251,27 @@ inline uint64_t str2seed(std::wstring seedstr) {
void create_new_world_panel(Engine* engine, PagesControl* menu) { void create_new_world_panel(Engine* engine, PagesControl* menu) {
auto panel = create_page(engine, "new-world", 400, 0.0f, 1); auto panel = create_page(engine, "new-world", 400, 0.0f, 1);
TextBox* worldNameInput; { panel->add(std::make_shared<Label>(langs::get(L"Name", L"world")));
Label* label = new Label(langs::get(L"Name", L"world")); auto nameInput = std::make_shared<TextBox>(L"New World", vec4(6.0f));
panel->add(label); nameInput->textValidator([=](const std::wstring& text) {
TextBox* input = new TextBox(L"New World", vec4(6.0f));
input->textValidator([=](const std::wstring& text) {
EnginePaths* paths = engine->getPaths(); EnginePaths* paths = engine->getPaths();
std::string textutf8 = util::wstr2str_utf8(text); std::string textutf8 = util::wstr2str_utf8(text);
return util::is_valid_filename(text) && return util::is_valid_filename(text) &&
!paths->isWorldNameUsed(textutf8); !paths->isWorldNameUsed(textutf8);
}); });
panel->add(input); panel->add(nameInput);
worldNameInput = input;
}
TextBox* seedInput; {
panel->add(std::make_shared<Label>(langs::get(L"Seed", L"world"))); panel->add(std::make_shared<Label>(langs::get(L"Seed", L"world")));
seedInput = new TextBox(std::to_wstring(randU64()), vec4(6.0f)); auto seedstr = std::to_wstring(randU64());
auto seedInput = std::make_shared<TextBox>(seedstr, vec4(6.0f));
panel->add(seedInput); panel->add(seedInput);
}
panel->add(create_button( L"Create World", vec4(10), vec4(1, 20, 1, 1), panel->add(create_button( L"Create World", vec4(10), vec4(1, 20, 1, 1),
[=](GUI*) { [=](GUI*) {
if (!worldNameInput->validate()) if (!nameInput->validate())
return; return;
std::wstring name = worldNameInput->text(); std::wstring name = nameInput->text();
std::string nameutf8 = util::wstr2str_utf8(name); std::string nameutf8 = util::wstr2str_utf8(name);
EnginePaths* paths = engine->getPaths(); EnginePaths* paths = engine->getPaths();
@ -291,9 +284,8 @@ void create_new_world_panel(Engine* engine, PagesControl* menu) {
engine->loadAllPacks(); engine->loadAllPacks();
engine->loadContent(); engine->loadContent();
Level* level = World::create(nameutf8, Level* level = World::create(
folder, nameutf8, folder, seed,
seed,
engine->getSettings(), engine->getSettings(),
engine->getContent(), engine->getContent(),
engine->getContentPacks()); engine->getContentPacks());
@ -307,10 +299,9 @@ void create_controls_panel(Engine* engine, PagesControl* menu) {
/* Camera sensitivity setting track bar */{ /* Camera sensitivity setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() { panel->add((new Label(L""))->textSupplier([=]() {
std::wstringstream ss; float s = engine->getSettings().camera.sensitivity;
ss << std::fixed << std::setprecision(1); return langs::get(L"Mouse Sensitivity", L"settings")+L": "+
ss << engine->getSettings().camera.sensitivity; util::to_wstring(s, 1);
return langs::get(L"Mouse Sensitivity", L"settings")+L": "+ss.str();
})); }));
TrackBar* trackbar = new TrackBar(0.1, 10.0, 2.0, 0.1, 4); TrackBar* trackbar = new TrackBar(0.1, 10.0, 2.0, 0.1, 4);
@ -381,10 +372,9 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
/* Fog Curve setting track bar */{ /* Fog Curve setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() { panel->add((new Label(L""))->textSupplier([=]() {
std::wstringstream ss; float value = engine->getSettings().graphics.fogCurve;
ss << std::fixed << std::setprecision(1); return langs::get(L"Fog Curve", L"settings")+L": " +
ss << engine->getSettings().graphics.fogCurve; util::to_wstring(value, 1);
return langs::get(L"Fog Curve", L"settings")+L": " + ss.str();
})); }));
TrackBar* trackbar = new TrackBar(1.0, 6.0, 1.0, 0.1, 2); TrackBar* trackbar = new TrackBar(1.0, 6.0, 1.0, 0.1, 2);
@ -414,39 +404,25 @@ void create_settings_panel(Engine* engine, PagesControl* menu) {
} }
/* V-Sync checkbox */{ /* V-Sync checkbox */{
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f); auto checkbox = new FullCheckBox(langs::get(L"V-Sync", L"settings"), vec2(400, 32));
checkpanel->color(vec4(0.0f));
checkpanel->orientation(Orientation::horizontal);
CheckBox* checkbox = new CheckBox();
checkbox->supplier([=]() { checkbox->supplier([=]() {
return engine->getSettings().display.swapInterval != 0; return engine->getSettings().display.swapInterval != 0;
}); });
checkbox->consumer([=](bool checked) { checkbox->consumer([=](bool checked) {
engine->getSettings().display.swapInterval = checked; engine->getSettings().display.swapInterval = checked;
}); });
checkpanel->add(checkbox); panel->add(checkbox);
checkpanel->add(new Label(langs::get(L"V-Sync", L"settings")));
panel->add(checkpanel);
} }
/* Backlight checkbox */{ /* Backlight checkbox */{
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f); auto checkbox = new FullCheckBox(langs::get(L"Backlight", L"settings"), vec2(400, 32));
checkpanel->color(vec4(0.0f));
checkpanel->orientation(Orientation::horizontal);
CheckBox* checkbox = new CheckBox();
checkbox->supplier([=]() { checkbox->supplier([=]() {
return engine->getSettings().graphics.backlight != 0; return engine->getSettings().graphics.backlight != 0;
}); });
checkbox->consumer([=](bool checked) { checkbox->consumer([=](bool checked) {
engine->getSettings().graphics.backlight = checked; engine->getSettings().graphics.backlight = checked;
}); });
checkpanel->add(checkbox); panel->add(checkbox);
checkpanel->add(new Label(langs::get(L"Backlight", L"settings")));
panel->add(checkpanel);
} }
std::string langName = langs::locales_info.at(langs::current->getId()).name; std::string langName = langs::locales_info.at(langs::current->getId()).name;