2023-01-29 18:36:33 +02:00
|
|
|
/*
|
2023-02-12 18:49:41 +02:00
|
|
|
* GeneralOptionsTab.cpp, part of VCMI engine
|
2023-01-29 18:36:33 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
2023-02-12 18:49:41 +02:00
|
|
|
#include "GeneralOptionsTab.h"
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-02-12 18:29:23 +02:00
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "CPlayerInterface.h"
|
2023-01-29 18:36:33 +02:00
|
|
|
#include "CServerHandler.h"
|
2024-05-02 14:55:20 +02:00
|
|
|
#include "media/IMusicPlayer.h"
|
|
|
|
#include "media/ISoundPlayer.h"
|
2023-05-08 12:22:01 +02:00
|
|
|
#include "render/IScreenHandler.h"
|
2023-06-16 11:59:20 +02:00
|
|
|
#include "windows/GUIClasses.h"
|
|
|
|
|
|
|
|
#include "../../eventsSDL/InputHandler.h"
|
|
|
|
#include "../../gui/CGuiHandler.h"
|
|
|
|
#include "../../gui/WindowHandler.h"
|
|
|
|
#include "../../widgets/Buttons.h"
|
|
|
|
#include "../../widgets/Images.h"
|
|
|
|
#include "../../widgets/Slider.h"
|
|
|
|
#include "../../widgets/TextControls.h"
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../../lib/texts/CGeneralTextHandler.h"
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "../../../lib/filesystem/ResourcePath.h"
|
2023-01-29 18:36:33 +02:00
|
|
|
|
|
|
|
static void setIntSetting(std::string group, std::string field, int value)
|
|
|
|
{
|
|
|
|
Settings entry = settings.write[group][field];
|
|
|
|
entry->Float() = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setBoolSetting(std::string group, std::string field, bool value)
|
|
|
|
{
|
2023-03-05 15:47:16 +02:00
|
|
|
Settings entry = settings.write[group][field];
|
|
|
|
entry->Bool() = value;
|
2023-01-29 18:36:33 +02:00
|
|
|
}
|
|
|
|
|
2023-05-04 22:50:33 +02:00
|
|
|
static std::string scalingToEntryString( int scaling)
|
|
|
|
{
|
|
|
|
return std::to_string(scaling) + '%';
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string scalingToLabelString( int scaling)
|
|
|
|
{
|
|
|
|
std::string string = CGI->generaltexth->translate("vcmi.systemOptions.scalingButton.hover");
|
|
|
|
boost::replace_all(string, "%p", std::to_string(scaling));
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2023-06-16 11:59:20 +02:00
|
|
|
static std::string longTouchToEntryString( int duration)
|
|
|
|
{
|
|
|
|
std::string string = CGI->generaltexth->translate("vcmi.systemOptions.longTouchMenu.entry");
|
|
|
|
boost::replace_all(string, "%d", std::to_string(duration));
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string longTouchToLabelString( int duration)
|
|
|
|
{
|
|
|
|
std::string string = CGI->generaltexth->translate("vcmi.systemOptions.longTouchButton.hover");
|
|
|
|
boost::replace_all(string, "%d", std::to_string(duration));
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2023-03-07 15:27:54 +02:00
|
|
|
static std::string resolutionToEntryString( int w, int h)
|
2023-01-29 18:36:33 +02:00
|
|
|
{
|
2023-03-07 15:27:54 +02:00
|
|
|
std::string string = "%wx%h";
|
|
|
|
|
|
|
|
boost::replace_all(string, "%w", std::to_string(w));
|
|
|
|
boost::replace_all(string, "%h", std::to_string(h));
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string resolutionToLabelString( int w, int h)
|
|
|
|
{
|
|
|
|
std::string string = CGI->generaltexth->translate("vcmi.systemOptions.resolutionButton.hover");
|
2023-03-04 00:33:16 +02:00
|
|
|
|
|
|
|
boost::replace_all(string, "%w", std::to_string(w));
|
|
|
|
boost::replace_all(string, "%h", std::to_string(h));
|
|
|
|
|
|
|
|
return string;
|
2023-01-29 18:36:33 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
GeneralOptionsTab::GeneralOptionsTab()
|
2023-01-29 18:36:33 +02:00
|
|
|
: InterfaceObjectConfigurable(),
|
|
|
|
onFullscreenChanged(settings.listen["video"]["fullscreen"])
|
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2023-07-03 18:24:12 +02:00
|
|
|
setRedrawParent(true);
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2024-08-28 23:07:00 +02:00
|
|
|
addConditional("touchscreen", GH.input().getCurrentInputMode() == InputMode::TOUCH);
|
|
|
|
addConditional("keyboardMouse", GH.input().getCurrentInputMode() == InputMode::KEYBOARD_AND_MOUSE);
|
|
|
|
addConditional("controller", GH.input().getCurrentInputMode() == InputMode::CONTROLLER);
|
2023-05-19 22:19:43 +02:00
|
|
|
#ifdef VCMI_MOBILE
|
|
|
|
addConditional("mobile", true);
|
|
|
|
addConditional("desktop", false);
|
2023-05-30 19:08:27 +02:00
|
|
|
#else
|
|
|
|
addConditional("mobile", false);
|
|
|
|
addConditional("desktop", true);
|
2023-05-19 22:19:43 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-01 23:26:14 +02:00
|
|
|
const JsonNode config(JsonPath::builtin("config/widgets/settings/generalOptionsTab.json"));
|
2023-02-18 18:49:43 +02:00
|
|
|
addCallback("spellbookAnimationChanged", [](bool value)
|
|
|
|
{
|
2023-03-05 15:47:16 +02:00
|
|
|
setBoolSetting("video", "spellbookAnimation", value);
|
2023-02-18 18:49:43 +02:00
|
|
|
});
|
|
|
|
addCallback("setMusic", [this](int value)
|
|
|
|
{
|
|
|
|
setIntSetting("general", "music", value);
|
|
|
|
widget<CSlider>("musicSlider")->redraw();
|
2023-03-04 13:37:27 +02:00
|
|
|
|
|
|
|
auto targetLabel = widget<CLabel>("musicValueLabel");
|
|
|
|
if (targetLabel)
|
|
|
|
targetLabel->setText(std::to_string(value) + "%");
|
2023-02-18 18:49:43 +02:00
|
|
|
});
|
|
|
|
addCallback("setVolume", [this](int value)
|
|
|
|
{
|
|
|
|
setIntSetting("general", "sound", value);
|
|
|
|
widget<CSlider>("soundVolumeSlider")->redraw();
|
2023-03-04 13:37:27 +02:00
|
|
|
|
|
|
|
auto targetLabel = widget<CLabel>("soundValueLabel");
|
|
|
|
if (targetLabel)
|
|
|
|
targetLabel->setText(std::to_string(value) + "%");
|
2023-02-18 18:49:43 +02:00
|
|
|
});
|
2023-02-14 00:53:28 +02:00
|
|
|
//settings that do not belong to base game:
|
2023-05-15 18:44:02 +02:00
|
|
|
addCallback("fullscreenBorderlessChanged", [this](bool value)
|
2023-02-18 18:49:43 +02:00
|
|
|
{
|
2023-05-15 18:44:02 +02:00
|
|
|
setFullscreenMode(value, false);
|
|
|
|
});
|
|
|
|
addCallback("fullscreenExclusiveChanged", [this](bool value)
|
|
|
|
{
|
|
|
|
setFullscreenMode(value, true);
|
2023-02-18 18:49:43 +02:00
|
|
|
});
|
|
|
|
addCallback("setGameResolution", [this](int dummyValue)
|
|
|
|
{
|
|
|
|
selectGameResolution();
|
|
|
|
});
|
2023-05-04 22:50:33 +02:00
|
|
|
addCallback("setGameScaling", [this](int dummyValue)
|
|
|
|
{
|
|
|
|
selectGameScaling();
|
|
|
|
});
|
2023-06-16 11:59:20 +02:00
|
|
|
addCallback("setLongTouchDuration", [this](int dummyValue)
|
|
|
|
{
|
|
|
|
selectLongTouchDuration();
|
|
|
|
});
|
2023-02-18 18:49:43 +02:00
|
|
|
addCallback("framerateChanged", [](bool value)
|
|
|
|
{
|
2023-03-05 21:06:52 +02:00
|
|
|
setBoolSetting("video", "showfps", value);
|
2023-02-18 18:49:43 +02:00
|
|
|
});
|
2023-07-08 18:47:38 +02:00
|
|
|
addCallback("hapticFeedbackChanged", [](bool value)
|
|
|
|
{
|
|
|
|
setBoolSetting("general", "hapticFeedback", value);
|
|
|
|
});
|
2023-09-25 13:11:08 +02:00
|
|
|
addCallback("enableUiEnhancementsChanged", [](bool value)
|
|
|
|
{
|
|
|
|
setBoolSetting("general", "enableUiEnhancements", value);
|
|
|
|
});
|
2023-03-05 15:47:16 +02:00
|
|
|
|
2023-12-24 01:41:29 +02:00
|
|
|
addCallback("enableLargeSpellbookChanged", [this](bool value)
|
2023-11-26 20:16:53 +02:00
|
|
|
{
|
2023-11-28 23:30:50 +02:00
|
|
|
setBoolSetting("gameTweaks", "enableLargeSpellbook", value);
|
2023-12-24 01:41:29 +02:00
|
|
|
std::shared_ptr<CToggleButton> spellbookAnimationCheckbox = widget<CToggleButton>("spellbookAnimationCheckbox");
|
|
|
|
if(value)
|
|
|
|
spellbookAnimationCheckbox->disable();
|
|
|
|
else
|
|
|
|
spellbookAnimationCheckbox->enable();
|
|
|
|
redraw();
|
2023-11-26 20:16:53 +02:00
|
|
|
});
|
|
|
|
|
2023-12-10 15:49:27 +02:00
|
|
|
addCallback("audioMuteFocusChanged", [](bool value)
|
|
|
|
{
|
|
|
|
setBoolSetting("general", "audioMuteFocus", value);
|
|
|
|
});
|
|
|
|
|
2023-02-18 17:35:07 +02:00
|
|
|
//moved from "other" tab that is disabled for now to avoid excessible tabs with barely any content
|
2023-03-05 15:47:16 +02:00
|
|
|
addCallback("availableCreaturesAsDwellingChanged", [=](int value)
|
2023-02-18 18:49:43 +02:00
|
|
|
{
|
2023-03-05 15:47:16 +02:00
|
|
|
setBoolSetting("gameTweaks", "availableCreaturesAsDwellingLabel", value > 0);
|
2023-02-18 18:49:43 +02:00
|
|
|
});
|
2023-03-05 15:47:16 +02:00
|
|
|
|
2023-02-18 18:49:43 +02:00
|
|
|
addCallback("compactTownCreatureInfoChanged", [](bool value)
|
|
|
|
{
|
2023-03-05 15:47:16 +02:00
|
|
|
setBoolSetting("gameTweaks", "compactTownCreatureInfo", value);
|
2023-02-18 18:49:43 +02:00
|
|
|
});
|
2023-03-05 15:47:16 +02:00
|
|
|
|
2023-01-29 18:36:33 +02:00
|
|
|
build(config);
|
|
|
|
|
2023-04-30 18:20:40 +02:00
|
|
|
const auto & currentResolution = settings["video"]["resolution"];
|
2023-05-04 22:50:33 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CLabel> scalingLabel = widget<CLabel>("scalingLabel");
|
|
|
|
scalingLabel->setText(scalingToLabelString(currentResolution["scaling"].Integer()));
|
|
|
|
|
2023-06-16 11:59:20 +02:00
|
|
|
std::shared_ptr<CLabel> longTouchLabel = widget<CLabel>("longTouchLabel");
|
2023-06-16 12:21:42 +02:00
|
|
|
if (longTouchLabel)
|
|
|
|
longTouchLabel->setText(longTouchToLabelString(settings["general"]["longTouchTimeMilliseconds"].Integer()));
|
2023-06-16 11:59:20 +02:00
|
|
|
|
2023-01-29 18:36:33 +02:00
|
|
|
std::shared_ptr<CToggleButton> spellbookAnimationCheckbox = widget<CToggleButton>("spellbookAnimationCheckbox");
|
2023-02-18 18:49:43 +02:00
|
|
|
spellbookAnimationCheckbox->setSelected(settings["video"]["spellbookAnimation"].Bool());
|
2023-12-24 01:41:29 +02:00
|
|
|
if(settings["gameTweaks"]["enableLargeSpellbook"].Bool())
|
|
|
|
spellbookAnimationCheckbox->disable();
|
|
|
|
else
|
|
|
|
spellbookAnimationCheckbox->enable();
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-05-15 18:44:02 +02:00
|
|
|
std::shared_ptr<CToggleButton> fullscreenBorderlessCheckbox = widget<CToggleButton>("fullscreenBorderlessCheckbox");
|
|
|
|
if (fullscreenBorderlessCheckbox)
|
|
|
|
fullscreenBorderlessCheckbox->setSelected(settings["video"]["fullscreen"].Bool() && !settings["video"]["realFullscreen"].Bool());
|
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> fullscreenExclusiveCheckbox = widget<CToggleButton>("fullscreenExclusiveCheckbox");
|
|
|
|
if (fullscreenExclusiveCheckbox)
|
|
|
|
fullscreenExclusiveCheckbox->setSelected(settings["video"]["fullscreen"].Bool() && settings["video"]["realFullscreen"].Bool());
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-02-14 00:53:28 +02:00
|
|
|
std::shared_ptr<CToggleButton> framerateCheckbox = widget<CToggleButton>("framerateCheckbox");
|
2023-03-05 21:06:52 +02:00
|
|
|
framerateCheckbox->setSelected(settings["video"]["showfps"].Bool());
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-07-08 18:47:38 +02:00
|
|
|
std::shared_ptr<CToggleButton> hapticFeedbackCheckbox = widget<CToggleButton>("hapticFeedbackCheckbox");
|
2023-07-12 22:56:35 +02:00
|
|
|
if (hapticFeedbackCheckbox)
|
|
|
|
hapticFeedbackCheckbox->setSelected(settings["general"]["hapticFeedback"].Bool());
|
2023-07-08 18:47:38 +02:00
|
|
|
|
2023-09-25 13:11:08 +02:00
|
|
|
std::shared_ptr<CToggleButton> enableUiEnhancementsCheckbox = widget<CToggleButton>("enableUiEnhancementsCheckbox");
|
|
|
|
if (enableUiEnhancementsCheckbox)
|
|
|
|
enableUiEnhancementsCheckbox->setSelected(settings["general"]["enableUiEnhancements"].Bool());
|
|
|
|
|
2023-11-26 20:16:53 +02:00
|
|
|
std::shared_ptr<CToggleButton> enableLargeSpellbookCheckbox = widget<CToggleButton>("enableLargeSpellbookCheckbox");
|
|
|
|
if (enableLargeSpellbookCheckbox)
|
2023-11-28 23:30:50 +02:00
|
|
|
enableLargeSpellbookCheckbox->setSelected(settings["gameTweaks"]["enableLargeSpellbook"].Bool());
|
2023-11-26 20:16:53 +02:00
|
|
|
|
2023-12-10 15:49:27 +02:00
|
|
|
std::shared_ptr<CToggleButton> audioMuteFocusCheckbox = widget<CToggleButton>("audioMuteFocusCheckbox");
|
|
|
|
if (audioMuteFocusCheckbox)
|
|
|
|
audioMuteFocusCheckbox->setSelected(settings["general"]["audioMuteFocus"].Bool());
|
|
|
|
|
2023-01-29 18:36:33 +02:00
|
|
|
std::shared_ptr<CSlider> musicSlider = widget<CSlider>("musicSlider");
|
2023-05-30 17:10:22 +02:00
|
|
|
musicSlider->scrollTo(CCS->musich->getVolume());
|
2023-01-29 18:36:33 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CSlider> volumeSlider = widget<CSlider>("soundVolumeSlider");
|
2023-05-30 17:10:22 +02:00
|
|
|
volumeSlider->scrollTo(CCS->soundh->getVolume());
|
2023-02-18 17:35:07 +02:00
|
|
|
|
2023-03-05 15:47:16 +02:00
|
|
|
std::shared_ptr<CToggleGroup> creatureGrowthAsDwellingPicker = widget<CToggleGroup>("availableCreaturesAsDwellingPicker");
|
|
|
|
creatureGrowthAsDwellingPicker->setSelected(settings["gameTweaks"]["availableCreaturesAsDwellingLabel"].Bool());
|
2023-02-18 17:35:07 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> compactTownCreatureInfo = widget<CToggleButton>("compactTownCreatureInfoCheckbox");
|
2023-02-18 18:49:43 +02:00
|
|
|
compactTownCreatureInfo->setSelected(settings["gameTweaks"]["compactTownCreatureInfo"].Bool());
|
2023-03-30 11:23:47 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CLabel> musicVolumeLabel = widget<CLabel>("musicValueLabel");
|
|
|
|
musicVolumeLabel->setText(std::to_string(CCS->musich->getVolume()) + "%");
|
|
|
|
|
|
|
|
std::shared_ptr<CLabel> soundVolumeLabel = widget<CLabel>("soundValueLabel");
|
2023-04-02 21:24:07 +02:00
|
|
|
soundVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%");
|
2023-05-19 22:54:43 +02:00
|
|
|
|
|
|
|
updateResolutionSelector();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralOptionsTab::updateResolutionSelector()
|
|
|
|
{
|
|
|
|
std::shared_ptr<CButton> resolutionButton = widget<CButton>("resolutionButton");
|
|
|
|
std::shared_ptr<CLabel> resolutionLabel = widget<CLabel>("resolutionLabel");
|
|
|
|
|
2023-07-13 19:11:08 +02:00
|
|
|
if (resolutionButton)
|
2023-05-19 22:54:43 +02:00
|
|
|
{
|
2023-07-13 19:11:08 +02:00
|
|
|
if (settings["video"]["fullscreen"].Bool() && !settings["video"]["realFullscreen"].Bool())
|
2023-05-19 22:54:43 +02:00
|
|
|
resolutionButton->disable();
|
2023-07-13 19:11:08 +02:00
|
|
|
else
|
2023-05-19 22:54:43 +02:00
|
|
|
resolutionButton->enable();
|
|
|
|
}
|
|
|
|
|
2023-07-13 19:11:08 +02:00
|
|
|
if (resolutionLabel)
|
|
|
|
{
|
|
|
|
Point resolution = GH.screenHandler().getRenderResolution();
|
|
|
|
resolutionLabel->setText(resolutionToLabelString(resolution.x, resolution.y));
|
|
|
|
}
|
2023-02-12 16:03:33 +02:00
|
|
|
}
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
void GeneralOptionsTab::selectGameResolution()
|
2023-02-12 16:03:33 +02:00
|
|
|
{
|
2023-05-08 12:22:01 +02:00
|
|
|
supportedResolutions = GH.screenHandler().getSupportedResolutions();
|
2023-05-04 22:50:33 +02:00
|
|
|
|
2023-02-12 16:03:33 +02:00
|
|
|
std::vector<std::string> items;
|
2023-01-29 18:36:33 +02:00
|
|
|
size_t currentResolutionIndex = 0;
|
|
|
|
size_t i = 0;
|
2023-04-30 17:48:15 +02:00
|
|
|
for(const auto & it : supportedResolutions)
|
2023-01-29 18:36:33 +02:00
|
|
|
{
|
2023-03-07 15:27:54 +02:00
|
|
|
auto resolutionStr = resolutionToEntryString(it.x, it.y);
|
2023-03-07 15:35:04 +02:00
|
|
|
if(widget<CLabel>("resolutionLabel")->getText() == resolutionToLabelString(it.x, it.y))
|
2023-01-29 18:36:33 +02:00
|
|
|
currentResolutionIndex = i;
|
2023-02-12 16:03:33 +02:00
|
|
|
|
2023-01-29 18:36:33 +02:00
|
|
|
items.push_back(std::move(resolutionStr));
|
|
|
|
++i;
|
|
|
|
}
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CObjectListWindow>(items, nullptr,
|
2023-01-29 18:36:33 +02:00
|
|
|
CGI->generaltexth->translate("vcmi.systemOptions.resolutionMenu.hover"),
|
|
|
|
CGI->generaltexth->translate("vcmi.systemOptions.resolutionMenu.help"),
|
2023-02-18 18:49:43 +02:00
|
|
|
[this](int index)
|
|
|
|
{
|
|
|
|
setGameResolution(index);
|
|
|
|
},
|
2023-01-29 18:36:33 +02:00
|
|
|
currentResolutionIndex);
|
|
|
|
}
|
|
|
|
|
2023-02-12 18:49:41 +02:00
|
|
|
void GeneralOptionsTab::setGameResolution(int index)
|
2023-01-29 18:36:33 +02:00
|
|
|
{
|
2023-04-30 17:48:15 +02:00
|
|
|
assert(index >= 0 && index < supportedResolutions.size());
|
2023-02-12 16:03:33 +02:00
|
|
|
|
2023-04-30 17:48:15 +02:00
|
|
|
if ( index < 0 || index >= supportedResolutions.size() )
|
2023-02-12 16:03:33 +02:00
|
|
|
return;
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-04-30 17:48:15 +02:00
|
|
|
Point resolution = supportedResolutions[index];
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-04-30 18:20:40 +02:00
|
|
|
Settings gameRes = settings.write["video"]["resolution"];
|
2023-02-12 16:03:33 +02:00
|
|
|
gameRes["width"].Float() = resolution.x;
|
|
|
|
gameRes["height"].Float() = resolution.y;
|
2023-01-29 18:36:33 +02:00
|
|
|
|
2023-03-07 15:27:54 +02:00
|
|
|
widget<CLabel>("resolutionLabel")->setText(resolutionToLabelString(resolution.x, resolution.y));
|
2023-07-05 17:14:37 +02:00
|
|
|
|
|
|
|
GH.dispatchMainThread([](){
|
2024-02-03 16:14:59 +02:00
|
|
|
GH.onScreenResize(true);
|
2023-07-05 17:14:37 +02:00
|
|
|
});
|
2023-02-12 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
2023-05-15 18:44:02 +02:00
|
|
|
void GeneralOptionsTab::setFullscreenMode(bool on, bool exclusive)
|
2023-02-12 16:03:33 +02:00
|
|
|
{
|
2023-07-05 17:14:37 +02:00
|
|
|
if (on == settings["video"]["fullscreen"].Bool() && exclusive == settings["video"]["realFullscreen"].Bool())
|
|
|
|
return;
|
|
|
|
|
2023-05-15 18:44:02 +02:00
|
|
|
setBoolSetting("video", "realFullscreen", exclusive);
|
2023-02-12 16:03:33 +02:00
|
|
|
setBoolSetting("video", "fullscreen", on);
|
2023-05-15 18:44:02 +02:00
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> fullscreenExclusiveCheckbox = widget<CToggleButton>("fullscreenExclusiveCheckbox");
|
|
|
|
std::shared_ptr<CToggleButton> fullscreenBorderlessCheckbox = widget<CToggleButton>("fullscreenBorderlessCheckbox");
|
|
|
|
|
|
|
|
if (fullscreenBorderlessCheckbox)
|
2023-07-05 17:14:37 +02:00
|
|
|
fullscreenBorderlessCheckbox->setSelectedSilent(on && !exclusive);
|
2023-05-15 18:44:02 +02:00
|
|
|
|
|
|
|
if (fullscreenExclusiveCheckbox)
|
2023-07-05 17:14:37 +02:00
|
|
|
fullscreenExclusiveCheckbox->setSelectedSilent(on && exclusive);
|
2023-05-19 22:54:43 +02:00
|
|
|
|
|
|
|
updateResolutionSelector();
|
2023-07-05 17:14:37 +02:00
|
|
|
|
|
|
|
GH.dispatchMainThread([](){
|
2024-02-03 16:14:59 +02:00
|
|
|
GH.onScreenResize(true);
|
2023-07-05 17:14:37 +02:00
|
|
|
});
|
2023-02-12 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
2023-05-04 22:50:33 +02:00
|
|
|
void GeneralOptionsTab::selectGameScaling()
|
2023-02-12 16:03:33 +02:00
|
|
|
{
|
2023-05-04 22:50:33 +02:00
|
|
|
supportedScaling.clear();
|
2023-02-12 16:03:33 +02:00
|
|
|
|
2023-05-19 22:54:43 +02:00
|
|
|
// generate list of all possible scaling values, with 10% step
|
|
|
|
// also add one value over maximum, so if player can use scaling up to 123.456% he will be able to select 130%
|
|
|
|
// and let screen handler clamp that value to actual maximum
|
2023-05-08 12:22:01 +02:00
|
|
|
auto [minimalScaling, maximalScaling] = GH.screenHandler().getSupportedScalingRange();
|
2023-05-19 22:54:43 +02:00
|
|
|
for (int i = 0; i <= maximalScaling + 10 - 1; i += 10)
|
2023-02-12 16:03:33 +02:00
|
|
|
{
|
2023-05-08 12:22:01 +02:00
|
|
|
if (i >= minimalScaling)
|
2023-05-04 22:50:33 +02:00
|
|
|
supportedScaling.push_back(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> items;
|
|
|
|
size_t currentIndex = 0;
|
|
|
|
size_t i = 0;
|
|
|
|
for(const auto & it : supportedScaling)
|
|
|
|
{
|
|
|
|
auto resolutionStr = scalingToEntryString(it);
|
|
|
|
if(widget<CLabel>("scalingLabel")->getText() == scalingToLabelString(it))
|
|
|
|
currentIndex = i;
|
|
|
|
|
|
|
|
items.push_back(std::move(resolutionStr));
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CObjectListWindow>(
|
2023-05-04 22:50:33 +02:00
|
|
|
items,
|
|
|
|
nullptr,
|
|
|
|
CGI->generaltexth->translate("vcmi.systemOptions.scalingMenu.hover"),
|
|
|
|
CGI->generaltexth->translate("vcmi.systemOptions.scalingMenu.help"),
|
|
|
|
[this](int index)
|
|
|
|
{
|
|
|
|
setGameScaling(index);
|
|
|
|
},
|
|
|
|
currentIndex
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralOptionsTab::setGameScaling(int index)
|
|
|
|
{
|
|
|
|
assert(index >= 0 && index < supportedScaling.size());
|
|
|
|
|
|
|
|
if ( index < 0 || index >= supportedScaling.size() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int scaling = supportedScaling[index];
|
|
|
|
|
|
|
|
Settings gameRes = settings.write["video"]["resolution"];
|
|
|
|
gameRes["scaling"].Float() = scaling;
|
|
|
|
|
|
|
|
widget<CLabel>("scalingLabel")->setText(scalingToLabelString(scaling));
|
2023-07-13 19:10:10 +02:00
|
|
|
|
|
|
|
GH.dispatchMainThread([](){
|
2024-02-03 16:14:59 +02:00
|
|
|
GH.onScreenResize(true);
|
2023-07-13 19:10:10 +02:00
|
|
|
});
|
2023-03-04 00:33:16 +02:00
|
|
|
}
|
2023-06-16 11:59:20 +02:00
|
|
|
|
|
|
|
void GeneralOptionsTab::selectLongTouchDuration()
|
|
|
|
{
|
|
|
|
longTouchDurations = { 500, 750, 1000, 1250, 1500, 1750, 2000 };
|
|
|
|
|
|
|
|
std::vector<std::string> items;
|
|
|
|
size_t currentIndex = 0;
|
|
|
|
size_t i = 0;
|
|
|
|
for(const auto & it : longTouchDurations)
|
|
|
|
{
|
|
|
|
auto resolutionStr = longTouchToEntryString(it);
|
|
|
|
if(widget<CLabel>("longTouchLabel")->getText() == longTouchToLabelString(it))
|
|
|
|
currentIndex = i;
|
|
|
|
|
|
|
|
items.push_back(std::move(resolutionStr));
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
GH.windows().createAndPushWindow<CObjectListWindow>(
|
|
|
|
items,
|
|
|
|
nullptr,
|
|
|
|
CGI->generaltexth->translate("vcmi.systemOptions.longTouchMenu.hover"),
|
|
|
|
CGI->generaltexth->translate("vcmi.systemOptions.longTouchMenu.help"),
|
|
|
|
[this](int index)
|
|
|
|
{
|
|
|
|
setLongTouchDuration(index);
|
|
|
|
},
|
|
|
|
currentIndex
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeneralOptionsTab::setLongTouchDuration(int index)
|
|
|
|
{
|
|
|
|
assert(index >= 0 && index < longTouchDurations.size());
|
|
|
|
|
|
|
|
if ( index < 0 || index >= longTouchDurations.size() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int scaling = longTouchDurations[index];
|
|
|
|
|
|
|
|
Settings longTouchTime = settings.write["general"]["longTouchTimeMilliseconds"];
|
|
|
|
longTouchTime->Float() = scaling;
|
|
|
|
|
|
|
|
widget<CLabel>("longTouchLabel")->setText(longTouchToLabelString(scaling));
|
|
|
|
}
|