add setting camera.inertia & add display settings menu page

This commit is contained in:
MihailRis 2024-07-15 14:23:31 +03:00
parent af1b32d91d
commit 7c6d620560
9 changed files with 55 additions and 5 deletions

View File

@ -1,6 +1,7 @@
<container size='668,418' color='#0F1E2DB2' context='menu'>
<panel pos='6' size='250' color='0' interval='1'>
<button id='s_aud' onclick='set_page("s_aud", "settings_audio")'>@Audio</button>
<button id='s_dsp' onclick='set_page("s_dsp", "settings_display")'>@Display</button>
<button id='s_gfx' onclick='set_page("s_gfx", "settings_graphics")'>@Graphics</button>
<button id='s_ctl' onclick='set_page("s_ctl", "settings_controls")'>@Controls</button>
</panel>

View File

@ -8,6 +8,7 @@ end
function set_page(btn, page)
document.s_aud.enabled = true
document.s_dsp.enabled = true
document.s_gfx.enabled = true
document.s_ctl.enabled = true
document[btn].enabled = false

View File

@ -0,0 +1,2 @@
<panel size='400' color='0' interval='1' context='menu'>
</panel>

View File

@ -0,0 +1,43 @@
function create_setting(id, name, step, postfix, tooltip)
local info = core.get_setting_info(id)
postfix = postfix or ""
tooltip = tooltip or ""
document.root: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,
postfix=postfix,
tooltip=tooltip
}))
update_setting(core.get_setting(id), id, name, 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",
gui.str(name, "settings"),
core.str_setting(id),
postfix
)
end
function create_checkbox(id, name, tooltip)
tooltip = tooltip or ''
document.root:add(string.format(
"<checkbox consumer='function(x) core.set_setting(\"%s\", x) end' checked='%s' tooltip='%s'>%s</checkbox>",
id, core.str_setting(id), gui.str(tooltip, "settings"), gui.str(name, "settings")
))
end
function on_open()
create_setting("camera.fov", "FOV", 1, "°")
create_checkbox("display.fullscreen", "Fullscreen")
create_checkbox("display.vsync", "V-Sync")
create_checkbox("camera.shaking", "Camera Shaking")
create_checkbox("camera.inertia", "Camera Inertia")
end

View File

@ -39,9 +39,5 @@ function on_open()
create_setting("chunks.load-speed", "Load Speed", 1)
create_setting("graphics.fog-curve", "Fog Curve", 0.1)
create_setting("graphics.gamma", "Gamma", 0.05, "", "graphics.gamma.tooltip")
create_setting("camera.fov", "FOV", 1, "°")
create_checkbox("display.fullscreen", "Fullscreen")
create_checkbox("display.vsync", "V-Sync")
create_checkbox("graphics.backlight", "Backlight", "graphics.backlight.tooltip")
create_checkbox("camera.shaking", "Camera Shaking")
end

View File

@ -28,6 +28,7 @@ menu.Content Error=Ошибка Контента
menu.Content=Контент
menu.Continue=Продолжить
menu.Controls=Управление
menu.Display=Дисплей
menu.Graphics=Графика
menu.missing-content=Отсутствует Контент!
menu.New World=Новый Мир
@ -50,6 +51,7 @@ world.delete-confirm=Удалить мир безвозвратно?
settings.Ambient=Фон
settings.Backlight=Подсветка
settings.Camera Shaking=Тряска Камеры
settings.Camera Inertia=Инерция Камеры
settings.Fog Curve=Кривая Тумана
settings.FOV=Поле Зрения
settings.Fullscreen=Полный экран

View File

@ -56,6 +56,7 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) {
builder.add("fov", &settings.camera.fov);
builder.add("fov-effects", &settings.camera.fovEffects);
builder.add("shaking", &settings.camera.shaking);
builder.add("inertia", &settings.camera.inertia);
builder.section("chunks");
builder.add("load-distance", &settings.chunks.loadDistance);

View File

@ -98,7 +98,9 @@ glm::vec3 CameraControl::updateCameraShaking(const Hitbox& hitbox, float delta)
offset += camera->right * glm::sin(shakeTimer) * oh * shake;
offset += camera->up * glm::abs(glm::cos(shakeTimer)) * ov * shake;
if (settings.inertia.get()) {
offset -= glm::min(interpVel * 0.05f, 1.0f);
}
return offset;
}

View File

@ -46,6 +46,8 @@ struct CameraSettings {
FlagSetting fovEffects {true};
/// @brief Camera movement shake
FlagSetting shaking {true};
/// @brief Camera movement inertia effect
FlagSetting inertia {true};
/// @brief Camera field of view
NumberSetting fov {90.0f, 10, 120};
/// @brief Camera sensitivity