settings panel moved to xml (WIP)
This commit is contained in:
parent
7cb5b2eb70
commit
9cdf3ff016
@ -1,4 +1,4 @@
|
||||
<panel size='400' padding='8' interval='8' color='0'>
|
||||
<label context='menu'>@Page does not exists</label>
|
||||
<button padding='10' onclick='menu:back()'>@Back</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
<panel id='packs_panel' size='540,10' color='0,0,0,50' max-length='400'>
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
<button onclick='menu:back()' padding='10'>@Back</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
<panel id='packs_panel' size='540,10' color='0,0,0,50' max-length='400'>
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
<button onclick='menu.page = "add_packs"' padding='10'>@Add</button>
|
||||
<button onclick='menu:back()' padding='10'>@Back</button>
|
||||
<button onclick='menu.page = "add_packs"'>@Add</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
|
||||
@ -7,5 +7,5 @@
|
||||
<panel id='bindings_panel' size='380,200' padding='2' interval='1' max-length='400' color='#0000004C'>
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
<button padding='10' onclick='menu:back()'>@Back</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<panel size='400' color='0' interval='1' context='menu'>
|
||||
<button onclick='menu.page="new_world"' padding='10'>@New World</button>
|
||||
<button onclick='menu.page="new_world"'>@New World</button>
|
||||
<panel id='worlds' size='390,1' padding='5' color='#FFFFFF11' max-length='400'>
|
||||
</panel>
|
||||
<button onclick='menu.page="settings"' padding='10'>@Settings</button>
|
||||
<button onclick='core.quit()' padding='10'>@Quit</button>
|
||||
<button onclick='menu.page="settings"'>@Settings</button>
|
||||
<button onclick='core.quit()'>@Quit</button>
|
||||
</panel>
|
||||
|
||||
@ -1,21 +1,6 @@
|
||||
function on_open()
|
||||
local worlds = core.get_worlds_list()
|
||||
for _, name in ipairs(worlds) do
|
||||
document.worlds:add(
|
||||
"<container "..
|
||||
"size='380,46' "..
|
||||
"color='#0F1E2DB2' "..
|
||||
"hover-color='#162B3399' "..
|
||||
"onclick='core.open_world(\""..name.."\")'"..
|
||||
">"..
|
||||
"<label pos='8,8'>"..name.."</label>"..
|
||||
"<button pos='350,5' "..
|
||||
"color='#00000000' "..
|
||||
"hover-color='#FFFFFF2B' "..
|
||||
"onclick='core.delete_world(\""..name.."\")'>"..
|
||||
"<image src='gui/delete_icon' size='32,32' color='#FFFFFF80'/>"..
|
||||
"</button>"..
|
||||
"</container>"
|
||||
)
|
||||
document.worlds:add(gui.template("world", {name=name}))
|
||||
end
|
||||
end
|
||||
|
||||
@ -7,11 +7,11 @@
|
||||
</textbox>
|
||||
<label>@Seed</label>
|
||||
<textbox id='seed_box' placeholder='-' padding='4'></textbox>
|
||||
<button onclick='menu.page="generators"' id='generator_btn' padding='10'>
|
||||
<button onclick='menu.page="generators"' id='generator_btn'>
|
||||
@World generator
|
||||
</button>
|
||||
<button onclick='create_world()' padding='10' margin='1,20,1,1'>
|
||||
<button onclick='create_world()' margin='1,20,1,1'>
|
||||
@Create World
|
||||
</button>
|
||||
<button onclick='menu:back()' padding='10'>@Back</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<panel size='400' color='0' interval='1' context='menu'>
|
||||
<button onclick='menu:reset()' padding='10'>@Continue</button>
|
||||
<button onclick='menu.page="content"' padding='10'>@Content</button>
|
||||
<button onclick='menu.page="settings"' padding='10'>@Settings</button>
|
||||
<button onclick='core.close_world(true)' padding='10'>
|
||||
<button onclick='menu:reset()'>@Continue</button>
|
||||
<button onclick='menu.page="content"'>@Content</button>
|
||||
<button onclick='menu.page="settings"'>@Settings</button>
|
||||
<button onclick='core.close_world(true)'>
|
||||
@Save and Quit to Menu
|
||||
</button>
|
||||
</panel>
|
||||
|
||||
7
res/layouts/pages/settings.xml
Normal file
7
res/layouts/pages/settings.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<panel size='400' color='0' interval='1' context='menu'>
|
||||
<panel id='settings_panel' color='0'>
|
||||
</panel>
|
||||
<button onclick='menu.page="settings_audio"'>@Audio</button>
|
||||
<button onclick='menu.page="controls"'>@Controls</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
31
res/layouts/pages/settings.xml.lua
Normal file
31
res/layouts/pages/settings.xml.lua
Normal file
@ -0,0 +1,31 @@
|
||||
function create_setting(id, name, step, track_width, postfix)
|
||||
local info = core.get_setting_info(id)
|
||||
if postfix == nil then
|
||||
postfix = ""
|
||||
end
|
||||
document.settings_panel:add(gui.template("track_setting", {
|
||||
id=id,
|
||||
name=gui.str(name, "settings"),
|
||||
value=core.get_setting(id),
|
||||
min=info.min,
|
||||
max=info.max,
|
||||
step=step,
|
||||
track_width=track_width,
|
||||
postfix=postfix
|
||||
}))
|
||||
end
|
||||
|
||||
function update_setting(x, id, name, postfix)
|
||||
core.set_setting(id, x)
|
||||
-- updating label
|
||||
document[id..".L"].text = string.format(
|
||||
"%s: %s%s", name, core.str_setting(id), postfix
|
||||
)
|
||||
end
|
||||
|
||||
function on_open()
|
||||
create_setting("chunks.load-distance", "Load Distance", 1, 3)
|
||||
create_setting("chunks.load-speed", "Load Speed", 1, 1)
|
||||
create_setting("graphics.fog-curve", "Fog Curve", 0.1, 2)
|
||||
create_setting("camera.fov", "FOV", 1, 4, "°")
|
||||
end
|
||||
@ -2,5 +2,5 @@
|
||||
<panel id='tracks_panel' size='400' color='0' interval='1'>
|
||||
<!-- content is generated in script -->
|
||||
</panel>
|
||||
<button padding='10' onclick='menu:back()'>@Back</button>
|
||||
<button onclick='menu:back()'>@Back</button>
|
||||
</panel>
|
||||
@ -11,7 +11,7 @@
|
||||
%{description}
|
||||
</label>
|
||||
<button if='%{remover}' onclick='%{remover}' color='0' hover-color='#FFFFFF2B'
|
||||
gravity='center-right' margin='10'>
|
||||
gravity='center-right' margin='10' padding='0'>
|
||||
<image src='gui/cross' size='32,32' color='#FFFFFF80'/>
|
||||
</button>
|
||||
<image pos='8,8' src='%{icon}' size='64'></image>
|
||||
|
||||
7
res/layouts/templates/track_setting.xml
Normal file
7
res/layouts/templates/track_setting.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<panel color='0' context='settings'>
|
||||
<label id='%{id}.L'>%{name}: %{value}%{postfix}</label>
|
||||
<trackbar
|
||||
value='%{value}' min='%{min}' max='%{max}'
|
||||
step='%{step}' track-width="%{track_width}"
|
||||
consumer='function(x) update_setting(x, "%{id}", "%{name}", "%{postfix}") end'/>
|
||||
</panel>
|
||||
15
res/layouts/templates/world.xml
Normal file
15
res/layouts/templates/world.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<container
|
||||
size='380,46'
|
||||
color='#0F1E2DB2'
|
||||
hover-color='#162B3399'
|
||||
onclick='core.open_world("%{name}")'
|
||||
>
|
||||
<label pos='8,8'>%{name}</label>
|
||||
<button pos='350,5'
|
||||
color='#00000000'
|
||||
hover-color='#FFFFFF2B'
|
||||
padding='0'
|
||||
onclick='core.delete_world("{%{name}}")'>
|
||||
<image src='gui/delete_icon' size='32,32' color='#FFFFFF80'/>
|
||||
</button>
|
||||
</container>
|
||||
@ -33,6 +33,10 @@ void Section::add(std::string name, uint* ptr) {
|
||||
add(name, {fieldtype::ftuint, ptr});
|
||||
}
|
||||
|
||||
void Section::add(std::string name, int64_t* ptr) {
|
||||
add(name, {fieldtype::ftint64, ptr});
|
||||
}
|
||||
|
||||
void Section::add(std::string name, float* ptr) {
|
||||
add(name, {fieldtype::ftfloat, ptr});
|
||||
}
|
||||
@ -100,6 +104,7 @@ std::string Wrapper::write() const {
|
||||
break;
|
||||
case fieldtype::ftint: ss << *((int*)field->ptr); break;
|
||||
case fieldtype::ftuint: ss << *((uint*)field->ptr); break;
|
||||
case fieldtype::ftint64: ss << *((int64_t*)field->ptr); break;
|
||||
case fieldtype::ftfloat: ss << *((float*)field->ptr); break;
|
||||
case fieldtype::ftdouble: ss << *((double*)field->ptr); break;
|
||||
case fieldtype::ftstring:
|
||||
@ -144,6 +149,7 @@ void Section::set(const std::string& name, double value) {
|
||||
case fieldtype::ftbool: *(bool*)(field->ptr) = fabs(value) > 0.0; break;
|
||||
case fieldtype::ftint: *(int*)(field->ptr) = value; break;
|
||||
case fieldtype::ftuint: *(uint*)(field->ptr) = value; break;
|
||||
case fieldtype::ftint64: *(int64_t*)(field->ptr) = value; break;
|
||||
case fieldtype::ftfloat: *(float*)(field->ptr) = value; break;
|
||||
case fieldtype::ftdouble: *(double*)(field->ptr) = value; break;
|
||||
case fieldtype::ftstring: *(std::string*)(field->ptr) = std::to_string(value); break;
|
||||
@ -162,6 +168,7 @@ void Section::set(const std::string& name, bool value) {
|
||||
case fieldtype::ftbool: *(bool*)(field->ptr) = value; break;
|
||||
case fieldtype::ftint: *(int*)(field->ptr) = (int)value; break;
|
||||
case fieldtype::ftuint: *(uint*)(field->ptr) = (uint)value; break;
|
||||
case fieldtype::ftint64: *(int64_t*)(field->ptr) = (int64_t)value; break;
|
||||
case fieldtype::ftfloat: *(float*)(field->ptr) = (float)value; break;
|
||||
case fieldtype::ftdouble: *(double*)(field->ptr) = (double)value; break;
|
||||
case fieldtype::ftstring: *(std::string*)(field->ptr) = value ? "true" : "false"; break;
|
||||
|
||||
@ -12,6 +12,7 @@ namespace toml {
|
||||
ftbool,
|
||||
ftint,
|
||||
ftuint,
|
||||
ftint64,
|
||||
ftfloat,
|
||||
ftdouble,
|
||||
ftstring,
|
||||
@ -31,6 +32,7 @@ namespace toml {
|
||||
Section(std::string name);
|
||||
void add(std::string name, bool* ptr);
|
||||
void add(std::string name, int* ptr);
|
||||
void add(std::string name, int64_t* ptr);
|
||||
void add(std::string name, uint* ptr);
|
||||
void add(std::string name, float* ptr);
|
||||
void add(std::string name, double* ptr);
|
||||
|
||||
@ -12,3 +12,14 @@ std::string NumberSetting::toString() const {
|
||||
return "invalid format";
|
||||
}
|
||||
}
|
||||
|
||||
std::string IntegerSetting::toString() const {
|
||||
switch (getFormat()) {
|
||||
case setting_format::simple:
|
||||
return util::to_string(value);
|
||||
case setting_format::percent:
|
||||
return std::to_string(value) + "%";
|
||||
default:
|
||||
return "invalid format";
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,4 +95,65 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class IntegerSetting : public Setting {
|
||||
protected:
|
||||
integer_t initial;
|
||||
integer_t value;
|
||||
integer_t min;
|
||||
integer_t max;
|
||||
std::vector<consumer<integer_t>> consumers;
|
||||
public:
|
||||
IntegerSetting(
|
||||
integer_t value,
|
||||
integer_t min=std::numeric_limits<integer_t>::min(),
|
||||
integer_t max=std::numeric_limits<integer_t>::max(),
|
||||
setting_format format=setting_format::simple
|
||||
) : Setting(format),
|
||||
initial(value),
|
||||
value(value),
|
||||
min(min),
|
||||
max(max)
|
||||
{}
|
||||
|
||||
integer_t& operator*() {
|
||||
return value;
|
||||
}
|
||||
|
||||
integer_t get() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
void set(integer_t value) {
|
||||
if (value == this->value) {
|
||||
return;
|
||||
}
|
||||
this->value = value;
|
||||
for (auto& callback : consumers) {
|
||||
callback(value);
|
||||
}
|
||||
}
|
||||
|
||||
integer_t getMin() const {
|
||||
return min;
|
||||
}
|
||||
|
||||
integer_t getMax() const {
|
||||
return max;
|
||||
}
|
||||
|
||||
integer_t getT() const {
|
||||
return (value - min) / (max - min);
|
||||
}
|
||||
|
||||
void observe(consumer<integer_t> callback) {
|
||||
consumers.push_back(callback);
|
||||
}
|
||||
|
||||
virtual void resetToDefault() override {
|
||||
value = initial;
|
||||
}
|
||||
|
||||
virtual std::string toString() const override;
|
||||
};
|
||||
|
||||
#endif // DATA_SETTING_H_
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "../coders/json.h"
|
||||
|
||||
SettingsHandler::SettingsHandler(EngineSettings& settings) {
|
||||
// public settings
|
||||
map.emplace("audio.volume-master", &settings.audio.volumeMaster);
|
||||
map.emplace("audio.volume-regular", &settings.audio.volumeRegular);
|
||||
map.emplace("audio.volume-ui", &settings.audio.volumeUI);
|
||||
@ -17,6 +18,12 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) {
|
||||
map.emplace("audio.volume-music", &settings.audio.volumeMusic);
|
||||
|
||||
map.emplace("camera.sensitivity", &settings.camera.sensitivity);
|
||||
map.emplace("camera.fov", &settings.camera.fov);
|
||||
|
||||
map.emplace("chunks.load-distance", &settings.chunks.loadDistance);
|
||||
map.emplace("chunks.load-speed", &settings.chunks.loadSpeed);
|
||||
|
||||
map.emplace("graphics.fog-curve", &settings.graphics.fogCurve);
|
||||
}
|
||||
|
||||
dynamic::Value SettingsHandler::getValue(const std::string& name) const {
|
||||
@ -27,6 +34,8 @@ dynamic::Value SettingsHandler::getValue(const std::string& name) const {
|
||||
auto setting = found->second;
|
||||
if (auto number = dynamic_cast<NumberSetting*>(setting)) {
|
||||
return dynamic::Value::of((number_t)number->get());
|
||||
} else if (auto integer = dynamic_cast<IntegerSetting*>(setting)) {
|
||||
return dynamic::Value::of((integer_t)integer->get());
|
||||
} else {
|
||||
throw std::runtime_error("type is not implemented for '"+name+"'");
|
||||
}
|
||||
@ -41,6 +50,14 @@ std::string SettingsHandler::toString(const std::string& name) const {
|
||||
return setting->toString();
|
||||
}
|
||||
|
||||
Setting* SettingsHandler::getSetting(const std::string& name) const {
|
||||
auto found = map.find(name);
|
||||
if (found == map.end()) {
|
||||
throw std::runtime_error("setting '"+name+"' does not exist");
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
|
||||
void SettingsHandler::setValue(const std::string& name, dynamic::Value value) {
|
||||
auto found = map.find(name);
|
||||
if (found == map.end()) {
|
||||
@ -58,6 +75,17 @@ void SettingsHandler::setValue(const std::string& name, dynamic::Value value) {
|
||||
default:
|
||||
throw std::runtime_error("type error, numeric value expected");
|
||||
}
|
||||
} else if (auto integer = dynamic_cast<IntegerSetting*>(setting)) {
|
||||
switch (value.type) {
|
||||
case dynamic::valtype::integer:
|
||||
integer->set(std::get<integer_t>(value.value));
|
||||
break;
|
||||
case dynamic::valtype::number:
|
||||
integer->set(std::get<number_t>(value.value));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("type error, numeric value expected");
|
||||
}
|
||||
} else {
|
||||
throw std::runtime_error("type is not implement - setting '"+name+"'");
|
||||
}
|
||||
@ -82,19 +110,19 @@ toml::Wrapper* create_wrapper(EngineSettings& settings) {
|
||||
display.add("swap-interval", &settings.display.swapInterval);
|
||||
|
||||
toml::Section& chunks = wrapper->add("chunks");
|
||||
chunks.add("load-distance", &settings.chunks.loadDistance);
|
||||
chunks.add("load-speed", &settings.chunks.loadSpeed);
|
||||
chunks.add("padding", &settings.chunks.padding);
|
||||
chunks.add("load-distance", &*settings.chunks.loadDistance);
|
||||
chunks.add("load-speed", &*settings.chunks.loadSpeed);
|
||||
chunks.add("padding", &*settings.chunks.padding);
|
||||
|
||||
toml::Section& camera = wrapper->add("camera");
|
||||
camera.add("fov-effects", &settings.camera.fovEvents);
|
||||
camera.add("fov", &settings.camera.fov);
|
||||
camera.add("fov", &*settings.camera.fov);
|
||||
camera.add("shaking", &settings.camera.shaking);
|
||||
camera.add("sensitivity", &*settings.camera.sensitivity);
|
||||
|
||||
toml::Section& graphics = wrapper->add("graphics");
|
||||
graphics.add("gamma", &settings.graphics.gamma);
|
||||
graphics.add("fog-curve", &settings.graphics.fogCurve);
|
||||
graphics.add("fog-curve", &*settings.graphics.fogCurve);
|
||||
graphics.add("backlight", &settings.graphics.backlight);
|
||||
graphics.add("frustum-culling", &settings.graphics.frustumCulling);
|
||||
graphics.add("skybox-resolution", &settings.graphics.skyboxResolution);
|
||||
|
||||
@ -18,6 +18,7 @@ public:
|
||||
dynamic::Value getValue(const std::string& name) const;
|
||||
void setValue(const std::string& name, dynamic::Value value);
|
||||
std::string toString(const std::string& name) const;
|
||||
Setting* getSetting(const std::string& name) const;
|
||||
};
|
||||
|
||||
extern std::string write_controls();
|
||||
|
||||
@ -211,12 +211,11 @@ void menus::delete_world(std::string name, Engine* engine) {
|
||||
L" ("+util::str2wstr_utf8(folder.u8string())+L")", [=]() {
|
||||
std::cout << "deleting " << folder.u8string() << std::endl;
|
||||
fs::remove_all(folder);
|
||||
menus::refresh_menus(engine);
|
||||
});
|
||||
}
|
||||
|
||||
void menus::create_menus(Engine* engine) {
|
||||
create_settings_panel(engine);
|
||||
// create_settings_panel(engine);
|
||||
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
menu->setPageLoader([=](auto name) {
|
||||
@ -229,6 +228,3 @@ void menus::create_menus(Engine* engine) {
|
||||
return document->getRoot();
|
||||
});
|
||||
}
|
||||
|
||||
void menus::refresh_menus(Engine* engine) {
|
||||
}
|
||||
|
||||
@ -61,7 +61,6 @@ namespace menus {
|
||||
/// @brief Create development version label at the top-right screen corner
|
||||
void create_version_label(Engine* engine);
|
||||
void create_menus(Engine* engine);
|
||||
void refresh_menus(Engine* engine);
|
||||
}
|
||||
|
||||
#endif // FRONTEND_MENU_MENU_H_
|
||||
|
||||
@ -19,15 +19,6 @@
|
||||
|
||||
using namespace gui;
|
||||
|
||||
inline uint64_t randU64() {
|
||||
srand(time(NULL));
|
||||
return rand() ^ (rand() << 8) ^
|
||||
(rand() << 16) ^ (rand() << 24) ^
|
||||
((uint64_t)rand() << 32) ^
|
||||
((uint64_t)rand() << 40) ^
|
||||
((uint64_t)rand() << 56);
|
||||
}
|
||||
|
||||
inline uint64_t str2seed(const std::string& seedstr) {
|
||||
if (util::is_integer(seedstr)) {
|
||||
try {
|
||||
|
||||
@ -13,76 +13,9 @@
|
||||
using namespace gui;
|
||||
|
||||
void menus::create_settings_panel(Engine* engine) {
|
||||
//create_controls_panel(engine);
|
||||
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
auto panel = menus::create_page(engine, "settings", 400, 0.0f, 1);
|
||||
|
||||
/* Load Distance setting track bar */{
|
||||
panel->add(menus::create_label([=]() {
|
||||
return langs::get(L"Load Distance", L"settings")+L": " +
|
||||
std::to_wstring(engine->getSettings().chunks.loadDistance);
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(3, 66, 10, 1, 3);
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().chunks.loadDistance;
|
||||
});
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().chunks.loadDistance = static_cast<uint>(value);
|
||||
});
|
||||
panel->add(trackbar);
|
||||
}
|
||||
|
||||
/* Load Speed setting track bar */{
|
||||
panel->add(menus::create_label([=]() {
|
||||
return langs::get(L"Load Speed", L"settings")+L": " +
|
||||
std::to_wstring(engine->getSettings().chunks.loadSpeed);
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(1, 32, 10, 1, 1);
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().chunks.loadSpeed;
|
||||
});
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().chunks.loadSpeed = static_cast<uint>(value);
|
||||
});
|
||||
panel->add(trackbar);
|
||||
}
|
||||
|
||||
/* Fog Curve setting track bar */{
|
||||
panel->add(menus::create_label([=]() {
|
||||
float value = engine->getSettings().graphics.fogCurve;
|
||||
return langs::get(L"Fog Curve", L"settings")+L": " +
|
||||
util::to_wstring(value, 1);
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(1.0, 6.0, 1.0, 0.1, 2);
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().graphics.fogCurve;
|
||||
});
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().graphics.fogCurve = value;
|
||||
});
|
||||
panel->add(trackbar);
|
||||
}
|
||||
|
||||
/* Fov setting track bar */{
|
||||
panel->add(menus::create_label([=]() {
|
||||
int fov = (int)engine->getSettings().camera.fov;
|
||||
return langs::get(L"FOV", L"settings")+L": "+std::to_wstring(fov)+L"°";
|
||||
}));
|
||||
|
||||
auto trackbar = std::make_shared<TrackBar>(30.0, 120.0, 90, 1, 4);
|
||||
trackbar->setSupplier([=]() {
|
||||
return engine->getSettings().camera.fov;
|
||||
});
|
||||
trackbar->setConsumer([=](double value) {
|
||||
engine->getSettings().camera.fov = value;
|
||||
});
|
||||
panel->add(trackbar);
|
||||
}
|
||||
|
||||
/* V-Sync checkbox */{
|
||||
auto checkbox = std::make_shared<FullCheckBox>(
|
||||
langs::get(L"V-Sync", L"settings"), glm::vec2(400, 32)
|
||||
@ -128,7 +61,7 @@ void menus::create_settings_panel(Engine* engine) {
|
||||
util::str2wstr_utf8(langName),
|
||||
"languages", menu));
|
||||
|
||||
panel->add(guiutil::gotoButton(L"Audio", "settings-audio", menu));
|
||||
panel->add(guiutil::gotoButton(L"Audio", "settings_audio", menu));
|
||||
panel->add(guiutil::gotoButton(L"Controls", "controls", menu));
|
||||
panel->add(guiutil::backButton(menu));
|
||||
}
|
||||
|
||||
@ -51,7 +51,6 @@ Screen::~Screen() {
|
||||
MenuScreen::MenuScreen(Engine* engine_) : Screen(engine_) {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
menu->reset();
|
||||
menus::refresh_menus(engine);
|
||||
menu->setPage("main");
|
||||
|
||||
uicamera.reset(new Camera(glm::vec3(), Window::height));
|
||||
@ -167,7 +166,7 @@ void LevelScreen::update(float delta) {
|
||||
|
||||
// TODO: subscribe for setting change
|
||||
EngineSettings& settings = engine->getSettings();
|
||||
controller->getPlayer()->camera->setFov(glm::radians(settings.camera.fov));
|
||||
controller->getPlayer()->camera->setFov(glm::radians(settings.camera.fov.get()));
|
||||
if (settings.graphics.backlight != backlight) {
|
||||
controller->getLevel()->chunks->saveAndClear();
|
||||
backlight = settings.graphics.backlight;
|
||||
|
||||
@ -150,7 +150,7 @@ void WorldRenderer::renderLevel(
|
||||
Shader* shader = assets->getShader("main");
|
||||
auto indices = level->content->getIndices();
|
||||
|
||||
float fogFactor = 15.0f / ((float)settings.chunks.loadDistance-2);
|
||||
float fogFactor = 15.0f / ((float)settings.chunks.loadDistance.get()-2);
|
||||
|
||||
// Setting up main shader
|
||||
shader->use();
|
||||
@ -158,7 +158,7 @@ void WorldRenderer::renderLevel(
|
||||
shader->uniformMatrix("u_view", camera->getView());
|
||||
shader->uniform1f("u_gamma", settings.graphics.gamma);
|
||||
shader->uniform1f("u_fogFactor", fogFactor);
|
||||
shader->uniform1f("u_fogCurve", settings.graphics.fogCurve);
|
||||
shader->uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
|
||||
shader->uniform1f("u_dayTime", level->getWorld()->daytime);
|
||||
shader->uniform3f("u_cameraPos", camera->position);
|
||||
shader->uniform1i("u_cubemap", 1);
|
||||
|
||||
@ -912,7 +912,8 @@ void TrackBar::mouseMove(GUI*, int x, int y) {
|
||||
value += min;
|
||||
value = (value > max) ? max : value;
|
||||
value = (value < min) ? min : value;
|
||||
value = (int)(value / step) * step;
|
||||
value = (int64_t)round(value / step) * step;
|
||||
|
||||
if (consumer) {
|
||||
consumer(value);
|
||||
}
|
||||
|
||||
@ -228,20 +228,21 @@ static std::shared_ptr<UINode> readPanel(UiXmlReader& reader, xml::xmlelement el
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement element) {
|
||||
glm::vec4 padding = element->attr("padding", "10").asVec4();
|
||||
|
||||
std::shared_ptr<Button> button;
|
||||
auto& elements = element->getElements();
|
||||
if (!elements.empty() && elements.at(0)->getTag() != "#") {
|
||||
glm::vec4 padding = element->attr("padding", "0,0,0,0").asVec4();
|
||||
auto inner = reader.readUINode(element->getElements().at(0));
|
||||
if (inner != nullptr) {
|
||||
button = std::make_shared<Button>(inner, padding);
|
||||
} else {
|
||||
button = std::make_shared<Button>(L"", glm::vec4(0.0f), nullptr);
|
||||
button = std::make_shared<Button>(L"", padding, nullptr);
|
||||
}
|
||||
_readPanel(reader, element, *button, false);
|
||||
} else {
|
||||
std::wstring text = readAndProcessInnerText(element, reader.getContext());
|
||||
button = std::make_shared<Button>(text, glm::vec4(0.0f), nullptr);
|
||||
button = std::make_shared<Button>(text, padding, nullptr);
|
||||
_readPanel(reader, element, *button, true);
|
||||
}
|
||||
if (element->has("text-align")) {
|
||||
|
||||
@ -11,8 +11,8 @@ static debug::Logger logger("level-control");
|
||||
|
||||
LevelController::LevelController(EngineSettings& settings, Level* level)
|
||||
: settings(settings), level(level),
|
||||
blocks(std::make_unique<BlocksController>(level, settings.chunks.padding)),
|
||||
chunks(std::make_unique<ChunksController>(level, settings.chunks.padding)),
|
||||
blocks(std::make_unique<BlocksController>(level, settings.chunks.padding.get())),
|
||||
chunks(std::make_unique<ChunksController>(level, settings.chunks.padding.get())),
|
||||
player(std::make_unique<PlayerController>(level, settings, blocks.get())) {
|
||||
|
||||
scripting::on_world_load(this);
|
||||
@ -21,8 +21,10 @@ LevelController::LevelController(EngineSettings& settings, Level* level)
|
||||
void LevelController::update(float delta, bool input, bool pause) {
|
||||
player->update(delta, input, pause);
|
||||
glm::vec3 position = player->getPlayer()->hitbox->position;
|
||||
level->loadMatrix(position.x, position.z, settings.chunks.loadDistance + settings.chunks.padding * 2);
|
||||
chunks->update(settings.chunks.loadSpeed);
|
||||
level->loadMatrix(position.x, position.z,
|
||||
settings.chunks.loadDistance.get() +
|
||||
settings.chunks.padding.get() * 2);
|
||||
chunks->update(settings.chunks.loadSpeed.get());
|
||||
|
||||
// erease null pointers
|
||||
level->objects.erase(
|
||||
|
||||
@ -130,6 +130,29 @@ static int l_str_setting(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_get_setting_info(lua_State* L) {
|
||||
auto name = lua_tostring(L, 1);
|
||||
auto setting = scripting::engine->getSettingsHandler().getSetting(name);
|
||||
if (auto number = dynamic_cast<NumberSetting*>(setting)) {
|
||||
lua_createtable(L, 0, 1);
|
||||
lua_pushnumber(L, number->getMin());
|
||||
lua_setfield(L, -2, "min");
|
||||
lua_pushnumber(L, number->getMax());
|
||||
lua_setfield(L, -2, "max");
|
||||
return 1;
|
||||
}
|
||||
if (auto integer = dynamic_cast<IntegerSetting*>(setting)) {
|
||||
lua_createtable(L, 0, 1);
|
||||
lua_pushinteger(L, integer->getMin());
|
||||
lua_setfield(L, -2, "min");
|
||||
lua_pushinteger(L, integer->getMax());
|
||||
lua_setfield(L, -2, "max");
|
||||
return 1;
|
||||
}
|
||||
luaL_error(L, "unsupported setting type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_quit(lua_State* L) {
|
||||
Window::setShouldClose(true);
|
||||
return 0;
|
||||
@ -165,6 +188,7 @@ const luaL_Reg corelib [] = {
|
||||
{"get_setting", lua_wrap_errors<l_get_setting>},
|
||||
{"set_setting", lua_wrap_errors<l_set_setting>},
|
||||
{"str_setting", lua_wrap_errors<l_str_setting>},
|
||||
{"get_setting_info", lua_wrap_errors<l_get_setting_info>},
|
||||
{"quit", lua_wrap_errors<l_quit>},
|
||||
{"get_default_generator", lua_wrap_errors<l_get_default_generator>},
|
||||
{"get_generators", lua_wrap_errors<l_get_generators>},
|
||||
|
||||
@ -38,11 +38,11 @@ struct DisplaySettings {
|
||||
|
||||
struct ChunksSettings {
|
||||
/// @brief Max milliseconds that engine uses for chunks loading only
|
||||
uint loadSpeed = 4;
|
||||
IntegerSetting loadSpeed = {4, 1, 32};
|
||||
/// @brief Radius of chunks loading zone (chunk is unit)
|
||||
uint loadDistance = 22;
|
||||
IntegerSetting loadDistance = {22, 3, 66};
|
||||
/// @brief Buffer zone where chunks are not unloading (chunk is unit)
|
||||
uint padding = 2;
|
||||
IntegerSetting padding = {2, 1, 8};
|
||||
};
|
||||
|
||||
struct CameraSettings {
|
||||
@ -51,15 +51,15 @@ struct CameraSettings {
|
||||
/// @brief Camera movement shake
|
||||
bool shaking = true;
|
||||
/// @brief Camera field of view
|
||||
float fov = 90.0f;
|
||||
NumberSetting fov {90.0f, 10, 120};
|
||||
/// @brief Camera sensitivity
|
||||
NumberSetting sensitivity {2.0f, 0.1f, 10.0f};
|
||||
};
|
||||
|
||||
struct GraphicsSettings {
|
||||
/// @brief Fog opacity is calculated as `pow(depth*k, fogCurve)` where k depends on chunksLoadDistance.
|
||||
/// Use values in range [1.0 - 2.0] where 1.0 is linear, 2.0 is quadratic
|
||||
float fogCurve = 1.6f;
|
||||
/// 1.0 is linear, 2.0 is quadratic
|
||||
NumberSetting fogCurve {1.6f, 1.0f, 6.0f};
|
||||
float gamma = 1.0f;
|
||||
/// @brief Enable blocks backlight to prevent complete darkness
|
||||
bool backlight = true;
|
||||
|
||||
@ -20,10 +20,17 @@ Level::Level(World* world, const Content* content, EngineSettings& settings)
|
||||
events(std::make_unique<LevelEvents>()),
|
||||
settings(settings)
|
||||
{
|
||||
auto inv = std::make_shared<Inventory>(world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE);
|
||||
auto player = spawnObject<Player>(glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv);
|
||||
auto inv = std::make_shared<Inventory>(
|
||||
world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE
|
||||
);
|
||||
auto player = spawnObject<Player>(
|
||||
glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv
|
||||
);
|
||||
|
||||
uint matrixSize = (settings.chunks.loadDistance + settings.chunks.padding) * 2;
|
||||
uint matrixSize = (
|
||||
settings.chunks.loadDistance.get() +
|
||||
settings.chunks.padding.get()
|
||||
) * 2;
|
||||
chunks = std::make_unique<Chunks>(
|
||||
matrixSize, matrixSize, 0, 0, world->wfile.get(), events.get(), content
|
||||
);
|
||||
@ -45,7 +52,10 @@ Level::~Level(){
|
||||
|
||||
void Level::loadMatrix(int32_t x, int32_t z, uint32_t radius) {
|
||||
chunks->setCenter(x, z);
|
||||
uint32_t diameter = std::min(radius*2, (settings.chunks.loadDistance + settings.chunks.padding) * 2);
|
||||
uint32_t diameter = std::min(
|
||||
radius*2L,
|
||||
(settings.chunks.loadDistance.get() + settings.chunks.padding.get()) * 2
|
||||
);
|
||||
if (chunks->w != diameter) {
|
||||
chunks->resize(diameter, diameter);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user