mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-09-02 00:38:46 -04:00
Begin scaffolding keyboard nav
This commit is contained in:
+107
-58
@@ -6,13 +6,73 @@
|
||||
#include "dusk/audio/DuskAudioSystem.h"
|
||||
#include "dusk/config.hpp"
|
||||
#include "pane.hpp"
|
||||
#include "ui.hpp"
|
||||
|
||||
namespace dusk::ui {
|
||||
|
||||
template <typename T>
|
||||
struct ConfigProps {
|
||||
Rml::String key;
|
||||
ConfigVar<T>* value;
|
||||
std::function<void(T)> onChange;
|
||||
Rml::String helpText;
|
||||
Pane* rightPane = nullptr;
|
||||
bool selected = false;
|
||||
};
|
||||
|
||||
class ConfigBoolSelect : public SelectButton {
|
||||
public:
|
||||
using Props = ConfigProps<bool>;
|
||||
|
||||
ConfigBoolSelect(Rml::Element* parent, Props props)
|
||||
: SelectButton(
|
||||
parent, {
|
||||
.key = std::move(props.key),
|
||||
.getValue = [this] { return mValue->getValue() ? "On" : "Off"; },
|
||||
.onPressed = [this](SelectButton&, Rml::Event&) { toggle_value(); },
|
||||
.selected = props.selected,
|
||||
}),
|
||||
mValue(props.value), onChange(std::move(props.onChange)),
|
||||
mHelpText(std::move(props.helpText)), mRightPane(props.rightPane) {
|
||||
if (!mHelpText.empty() && mRightPane != nullptr) {
|
||||
listen(nullptr, Rml::EventId::Focus, [this](Rml::Event&) {
|
||||
mRightPane->clear();
|
||||
mRightPane->add_text(mHelpText);
|
||||
});
|
||||
listen(nullptr, Rml::EventId::Mouseover, [this](Rml::Event&) {
|
||||
mRightPane->clear();
|
||||
mRightPane->add_text(mHelpText);
|
||||
});
|
||||
}
|
||||
listen(nullptr, Rml::EventId::Keydown, [this](Rml::Event& event) {
|
||||
const auto cmd = map_nav_event(event);
|
||||
if (cmd == NavCommand::Left || cmd == NavCommand::Right || cmd == NavCommand::Confirm) {
|
||||
toggle_value();
|
||||
event.StopPropagation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
void toggle_value() {
|
||||
const bool newValue = !mValue->getValue();
|
||||
mValue->setValue(newValue);
|
||||
if (onChange) {
|
||||
onChange(newValue);
|
||||
}
|
||||
config::Save();
|
||||
}
|
||||
|
||||
ConfigVar<bool>* mValue;
|
||||
std::function<void(bool)> onChange;
|
||||
Rml::String mHelpText;
|
||||
Pane* mRightPane;
|
||||
};
|
||||
|
||||
SettingsWindow::SettingsWindow() {
|
||||
add_tab("Audio", [this](Rml::Element* content) {
|
||||
auto& leftPane = add_child<Pane>(content);
|
||||
auto& rightPane = add_child<Pane>(content);
|
||||
auto& leftPane = add_child<Pane>(content, Pane::Direction::Vertical);
|
||||
auto& rightPane = add_child<Pane>(content, Pane::Direction::Vertical);
|
||||
|
||||
leftPane.add_section("Volume");
|
||||
{
|
||||
@@ -32,37 +92,30 @@ SettingsWindow::SettingsWindow() {
|
||||
}
|
||||
|
||||
leftPane.add_section("Effects");
|
||||
{
|
||||
auto& btn = leftPane.add_select_button({
|
||||
.key = "Enable Reverb",
|
||||
.getValue = [] { return getSettings().audio.enableReverb ? "On" : "Off"; },
|
||||
.onPressed =
|
||||
[](SelectButton& self, Rml::Event& event) {
|
||||
getSettings().audio.enableReverb.setValue(
|
||||
!getSettings().audio.enableReverb);
|
||||
dusk::audio::SetEnableReverb(getSettings().audio.enableReverb);
|
||||
config::Save();
|
||||
},
|
||||
});
|
||||
btn.listen(nullptr, Rml::EventId::Focus, [&](Rml::Event&) {
|
||||
rightPane.clear();
|
||||
rightPane.add_text("Enables the reverb effect in game audio.");
|
||||
});
|
||||
btn.listen(nullptr, Rml::EventId::Mouseover, [&](Rml::Event&) {
|
||||
rightPane.clear();
|
||||
rightPane.add_text("Enables the reverb effect in game audio.");
|
||||
});
|
||||
}
|
||||
leftPane.add_child<ConfigBoolSelect>(
|
||||
leftPane.root(), ConfigBoolSelect::Props{
|
||||
.key = "Enable Reverb",
|
||||
.value = &getSettings().audio.enableReverb,
|
||||
.onChange = [](bool value) { audio::SetEnableReverb(value); },
|
||||
.helpText = "Enables the reverb effect in game audio.",
|
||||
.rightPane = &rightPane,
|
||||
});
|
||||
|
||||
leftPane.add_section("Tweaks");
|
||||
leftPane.add_select_button({
|
||||
.key = "No Low HP Sound",
|
||||
.value = "Off",
|
||||
});
|
||||
leftPane.add_select_button({
|
||||
.key = "Non-Stop Midna's Lament",
|
||||
.value = "On",
|
||||
});
|
||||
leftPane.add_child<ConfigBoolSelect>(
|
||||
leftPane.root(), ConfigBoolSelect::Props{
|
||||
.key = "No Low HP Sound",
|
||||
.value = &getSettings().game.noLowHpSound,
|
||||
.helpText = "Disable the beeping sound when having low health.",
|
||||
.rightPane = &rightPane,
|
||||
});
|
||||
leftPane.add_child<ConfigBoolSelect>(leftPane.root(),
|
||||
ConfigBoolSelect::Props{
|
||||
.key = "Non-Stop Midna's Lament",
|
||||
.value = &getSettings().game.midnasLamentNonStop,
|
||||
.helpText = "Prevents enemy music while Midna's Lament is playing.",
|
||||
.rightPane = &rightPane,
|
||||
});
|
||||
});
|
||||
|
||||
add_tab("Cheats", [this](Rml::Element* content) {
|
||||
@@ -74,10 +127,11 @@ SettingsWindow::SettingsWindow() {
|
||||
});
|
||||
|
||||
add_tab("Graphics", [this](Rml::Element* content) {
|
||||
auto& leftPane = add_child<Pane>(content);
|
||||
auto& rightPane = add_child<Pane>(content);
|
||||
auto& leftPane = add_child<Pane>(content, Pane::Direction::Vertical);
|
||||
auto& rightPane = add_child<Pane>(content, Pane::Direction::Vertical);
|
||||
|
||||
leftPane.add_section("Display");
|
||||
|
||||
leftPane.add_button({
|
||||
.text = "Toggle Fullscreen",
|
||||
.onPressed =
|
||||
@@ -98,31 +152,26 @@ SettingsWindow::SettingsWindow() {
|
||||
VICenterWindow();
|
||||
},
|
||||
});
|
||||
leftPane.add_select_button({
|
||||
.key = "Enable VSync",
|
||||
.getValue = [] { return getSettings().video.enableVsync ? "On" : "Off"; },
|
||||
.onPressed =
|
||||
[](SelectButton&, Rml::Event&) {
|
||||
getSettings().video.enableVsync.setValue(!getSettings().video.enableVsync);
|
||||
aurora_enable_vsync(getSettings().video.enableVsync);
|
||||
config::Save();
|
||||
},
|
||||
});
|
||||
leftPane.add_select_button({
|
||||
.key = "Force 4:3 Aspect Ratio",
|
||||
.getValue = [] { return getSettings().video.lockAspectRatio ? "On" : "Off"; },
|
||||
.onPressed =
|
||||
[](SelectButton&, Rml::Event&) {
|
||||
getSettings().video.lockAspectRatio.setValue(
|
||||
!getSettings().video.lockAspectRatio);
|
||||
if (getSettings().video.lockAspectRatio) {
|
||||
AuroraSetViewportPolicy(AURORA_VIEWPORT_FIT);
|
||||
} else {
|
||||
AuroraSetViewportPolicy(AURORA_VIEWPORT_STRETCH);
|
||||
}
|
||||
config::Save();
|
||||
},
|
||||
});
|
||||
leftPane.add_child<ConfigBoolSelect>(leftPane.root(),
|
||||
ConfigBoolSelect::Props{
|
||||
.key = "Enable VSync",
|
||||
.value = &getSettings().video.enableVsync,
|
||||
.onChange = [](bool value) { aurora_enable_vsync(value); },
|
||||
.helpText = "Synchronizes the frame rate to your monitor's refresh rate.",
|
||||
.rightPane = &rightPane,
|
||||
});
|
||||
leftPane.add_child<ConfigBoolSelect>(
|
||||
leftPane.root(), ConfigBoolSelect::Props{
|
||||
.key = "Lock 4:3 Aspect Ratio",
|
||||
.value = &getSettings().video.lockAspectRatio,
|
||||
.onChange =
|
||||
[](bool value) {
|
||||
AuroraSetViewportPolicy(
|
||||
value ? AURORA_VIEWPORT_FIT : AURORA_VIEWPORT_STRETCH);
|
||||
},
|
||||
.helpText = "Lock the game's aspect ratio to the original.",
|
||||
.rightPane = &rightPane,
|
||||
});
|
||||
|
||||
leftPane.add_section("Resolution");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user