osb/source/frontend/StarOptionsMenu.cpp

209 lines
7.3 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#include "StarOptionsMenu.hpp"
#include "StarRoot.hpp"
#include "StarGuiReader.hpp"
#include "StarLexicalCast.hpp"
#include "StarJsonExtra.hpp"
#include "StarSliderBar.hpp"
#include "StarLabelWidget.hpp"
#include "StarAssets.hpp"
#include "StarKeybindingsMenu.hpp"
2023-07-19 13:16:59 +00:00
#include "StarVoiceSettingsMenu.hpp"
2023-07-02 07:19:54 +00:00
#include "StarBindingsMenu.hpp"
2023-06-20 04:33:09 +00:00
#include "StarGraphicsMenu.hpp"
namespace Star {
OptionsMenu::OptionsMenu(PaneManager* manager)
: m_sfxRange(0, 100), m_musicRange(0, 100), m_paneManager(manager) {
auto root = Root::singletonPtr();
auto assets = root->assets();
GuiReader reader;
2024-01-03 09:08:57 +00:00
reader.registerCallback("instrumentSlider", [=](Widget*) {
updateInstrumentVol();
});
2023-06-20 04:33:09 +00:00
reader.registerCallback("sfxSlider", [=](Widget*) {
updateSFXVol();
});
reader.registerCallback("musicSlider", [=](Widget*) {
updateMusicVol();
});
reader.registerCallback("acceptButton", [=](Widget*) {
for (auto k : ConfigKeys)
root->configuration()->set(k, m_localChanges.get(k));
dismiss();
});
reader.registerCallback("tutorialMessagesCheckbox", [=](Widget*) {
updateTutorialMessages();
});
reader.registerCallback("clientIPJoinableCheckbox", [=](Widget*) {
updateClientIPJoinable();
});
reader.registerCallback("clientP2PJoinableCheckbox", [=](Widget*) {
updateClientP2PJoinable();
});
reader.registerCallback("allowAssetsMismatchCheckbox", [=](Widget*) {
updateAllowAssetsMismatch();
});
reader.registerCallback("backButton", [=](Widget*) {
dismiss();
});
reader.registerCallback("showKeybindings", [=](Widget*) {
displayControls();
});
2023-07-19 13:16:59 +00:00
reader.registerCallback("showVoiceSettings", [=](Widget*) {
displayVoiceSettings();
});
reader.registerCallback("showVoicePlayers", [=](Widget*) {
});
2023-07-02 07:19:54 +00:00
reader.registerCallback("showModBindings", [=](Widget*) {
2023-07-19 13:16:59 +00:00
displayModBindings();
2023-07-02 07:19:54 +00:00
});
2023-06-20 04:33:09 +00:00
reader.registerCallback("showGraphics", [=](Widget*) {
displayGraphics();
});
2023-07-02 07:19:54 +00:00
Json config = assets->json("/interface/optionsmenu/optionsmenu.config");
reader.construct(config.get("paneLayout"), this);
2023-06-20 04:33:09 +00:00
2024-01-03 09:08:57 +00:00
m_instrumentSlider = fetchChild<SliderBarWidget>("instrumentSlider");
2023-06-20 04:33:09 +00:00
m_sfxSlider = fetchChild<SliderBarWidget>("sfxSlider");
m_musicSlider = fetchChild<SliderBarWidget>("musicSlider");
m_tutorialMessagesButton = fetchChild<ButtonWidget>("tutorialMessagesCheckbox");
m_clientIPJoinableButton = fetchChild<ButtonWidget>("clientIPJoinableCheckbox");
m_clientP2PJoinableButton = fetchChild<ButtonWidget>("clientP2PJoinableCheckbox");
m_allowAssetsMismatchButton = fetchChild<ButtonWidget>("allowAssetsMismatchCheckbox");
2024-01-03 09:08:57 +00:00
m_instrumentLabel = fetchChild<LabelWidget>("instrumentValueLabel");
2023-06-20 04:33:09 +00:00
m_sfxLabel = fetchChild<LabelWidget>("sfxValueLabel");
m_musicLabel = fetchChild<LabelWidget>("musicValueLabel");
m_p2pJoinableLabel = fetchChild<LabelWidget>("clientP2PJoinableLabel");
2024-01-03 09:08:57 +00:00
m_instrumentSlider->setRange(m_sfxRange, assets->json("/interface/optionsmenu/optionsmenu.config:sfxDelta").toInt());
2023-06-20 04:33:09 +00:00
m_sfxSlider->setRange(m_sfxRange, assets->json("/interface/optionsmenu/optionsmenu.config:sfxDelta").toInt());
m_musicSlider->setRange(m_musicRange, assets->json("/interface/optionsmenu/optionsmenu.config:musicDelta").toInt());
2023-07-19 13:16:59 +00:00
m_voiceSettingsMenu = make_shared<VoiceSettingsMenu>(assets->json(config.getString("voiceSettingsPanePath", "/interface/opensb/voicechat/voicechat.config")));
2023-07-02 07:19:54 +00:00
m_modBindingsMenu = make_shared<BindingsMenu>(assets->json(config.getString("bindingsPanePath", "/interface/opensb/bindings/bindings.config")));
2023-06-20 04:33:09 +00:00
m_keybindingsMenu = make_shared<KeybindingsMenu>();
m_graphicsMenu = make_shared<GraphicsMenu>();
initConfig();
}
void OptionsMenu::show() {
initConfig();
syncGuiToConf();
Pane::show();
}
void OptionsMenu::toggleFullscreen() {
m_graphicsMenu->toggleFullscreen();
syncGuiToConf();
}
StringList const OptionsMenu::ConfigKeys = {
2024-01-03 09:08:57 +00:00
"instrumentVol",
2023-06-20 04:33:09 +00:00
"sfxVol",
"musicVol",
"tutorialMessages",
"clientIPJoinable",
"clientP2PJoinable",
"allowAssetsMismatch"
};
void OptionsMenu::initConfig() {
auto configuration = Root::singleton().configuration();
for (auto k : ConfigKeys) {
m_origConfig[k] = configuration->get(k);
m_localChanges[k] = configuration->get(k);
}
}
2024-01-03 09:08:57 +00:00
void OptionsMenu::updateInstrumentVol() {
m_localChanges.set("instrumentVol", m_instrumentSlider->val());
Root::singleton().configuration()->set("instrumentVol", m_instrumentSlider->val());
m_instrumentLabel->setText(toString(m_instrumentSlider->val()));
}
2023-06-20 04:33:09 +00:00
void OptionsMenu::updateSFXVol() {
m_localChanges.set("sfxVol", m_sfxSlider->val());
Root::singleton().configuration()->set("sfxVol", m_sfxSlider->val());
m_sfxLabel->setText(toString(m_sfxSlider->val()));
}
void OptionsMenu::updateMusicVol() {
m_localChanges.set("musicVol", {m_musicSlider->val()});
Root::singleton().configuration()->set("musicVol", m_musicSlider->val());
m_musicLabel->setText(toString(m_musicSlider->val()));
}
void OptionsMenu::updateTutorialMessages() {
m_localChanges.set("tutorialMessages", m_tutorialMessagesButton->isChecked());
Root::singleton().configuration()->set("tutorialMessages", m_tutorialMessagesButton->isChecked());
}
void OptionsMenu::updateClientIPJoinable() {
m_localChanges.set("clientIPJoinable", m_clientIPJoinableButton->isChecked());
Root::singleton().configuration()->set("clientIPJoinable", m_clientIPJoinableButton->isChecked());
}
void OptionsMenu::updateClientP2PJoinable() {
m_localChanges.set("clientP2PJoinable", m_clientP2PJoinableButton->isChecked());
Root::singleton().configuration()->set("clientP2PJoinable", m_clientP2PJoinableButton->isChecked());
}
void OptionsMenu::updateAllowAssetsMismatch() {
m_localChanges.set("allowAssetsMismatch", m_allowAssetsMismatchButton->isChecked());
Root::singleton().configuration()->set("allowAssetsMismatch", m_allowAssetsMismatchButton->isChecked());
}
void OptionsMenu::syncGuiToConf() {
2024-01-03 09:08:57 +00:00
m_instrumentSlider->setVal(m_localChanges.get("instrumentVol").toInt(), false);
m_instrumentLabel->setText(toString(m_instrumentSlider->val()));
2023-06-20 04:33:09 +00:00
m_sfxSlider->setVal(m_localChanges.get("sfxVol").toInt(), false);
m_sfxLabel->setText(toString(m_sfxSlider->val()));
m_musicSlider->setVal(m_localChanges.get("musicVol").toInt(), false);
m_musicLabel->setText(toString(m_musicSlider->val()));
m_tutorialMessagesButton->setChecked(m_localChanges.get("tutorialMessages").toBool());
m_clientIPJoinableButton->setChecked(m_localChanges.get("clientIPJoinable").toBool());
m_clientP2PJoinableButton->setChecked(m_localChanges.get("clientP2PJoinable").toBool());
m_allowAssetsMismatchButton->setChecked(m_localChanges.get("allowAssetsMismatch").toBool());
auto appController = GuiContext::singleton().applicationController();
if (!appController->p2pNetworkingService()) {
m_p2pJoinableLabel->setColor(Color::DarkGray);
m_clientP2PJoinableButton->setEnabled(false);
m_clientP2PJoinableButton->setChecked(false);
}
}
void OptionsMenu::displayControls() {
m_paneManager->displayPane(PaneLayer::ModalWindow, m_keybindingsMenu);
}
2023-07-19 13:16:59 +00:00
void OptionsMenu::displayVoiceSettings() {
m_paneManager->displayPane(PaneLayer::ModalWindow, m_voiceSettingsMenu);
}
2023-07-02 07:19:54 +00:00
void OptionsMenu::displayModBindings() {
m_paneManager->displayPane(PaneLayer::ModalWindow, m_modBindingsMenu);
}
2023-06-20 04:33:09 +00:00
void OptionsMenu::displayGraphics() {
m_paneManager->displayPane(PaneLayer::ModalWindow, m_graphicsMenu);
}
}