From 7cb225b0129f426025d3621e12ff9942e69e9532 Mon Sep 17 00:00:00 2001 From: SupSuper Date: Sun, 17 Mar 2019 20:37:44 +0000 Subject: [PATCH] Placeholder options screen --- data/forms/options.form | 83 ++++++++++++++------------------- framework/configfile.cpp | 78 ++++++++++++++++++------------- framework/configfile.h | 33 +++++++------ game/ui/general/optionsmenu.cpp | 65 +++++++++++++++++++------- game/ui/general/optionsmenu.h | 4 ++ 5 files changed, 153 insertions(+), 110 deletions(-) diff --git a/data/forms/options.form b/data/forms/options.form index 7b56912ea..8cf565137 100644 --- a/data/forms/options.form +++ b/data/forms/options.form @@ -3,60 +3,47 @@
diff --git a/framework/configfile.cpp b/framework/configfile.cpp index 5b91daedd..521aab88c 100644 --- a/framework/configfile.cpp +++ b/framework/configfile.cpp @@ -365,6 +365,27 @@ class ConfigFileImpl for (auto &optPair : this->optionSections) std::cout << optPair.second << "\n"; } + + std::map> getOptions() + { + std::map> options; + for (auto &optPair : this->optionSections) + { + std::vector vec; + for (auto &opt : optPair.second.options()) + { + std::string short_name = opt->long_name(); + size_t dot = short_name.find_last_of('.'); + if (dot != std::string::npos) + { + short_name = short_name.substr(dot + 1); + } + vec.emplace_back(ConfigOption(optPair.first, short_name, opt->description())); + } + options[optPair.first] = vec; + } + return options; + } }; ConfigFile::ConfigFile() { this->pimpl.reset(new ConfigFileImpl()); } @@ -432,66 +453,59 @@ bool ConfigFile::loaded() const { return this->pimpl->loaded(); } void ConfigFile::showHelp() { this->pimpl->showHelp(); } -ConfigOptionString::ConfigOptionString(const UString section, const UString name, - const UString description, const UString defaultValue) - : section(section), name(name), description(description), defaultValue(defaultValue) +std::map> ConfigFile::getOptions() { - config().addOptionString(section, name, "", description, defaultValue); + return this->pimpl->getOptions(); } -UString ConfigOptionString::get() const +ConfigOption::ConfigOption(const UString section, const UString name, const UString description) + : section(section), name(name), description(description) +{ +} + +UString ConfigOption::getKey() const { if (section.empty()) - return config().getString(name); + return name; else - return config().getString(section + "." + name); + return section + "." + name; } +ConfigOptionString::ConfigOptionString(const UString section, const UString name, + const UString description, const UString defaultValue) + : ConfigOption(section, name, description), defaultValue(defaultValue) +{ + config().addOptionString(section, name, "", description, defaultValue); +} + +UString ConfigOptionString::get() const { return config().getString(getKey()); } + ConfigOptionInt::ConfigOptionInt(const UString section, const UString name, const UString description, const int defaultValue) - : section(section), name(name), description(description), defaultValue(defaultValue) + : ConfigOption(section, name, description), defaultValue(defaultValue) { config().addOptionInt(section, name, "", description, defaultValue); } -int ConfigOptionInt::get() const -{ - - if (section.empty()) - return config().getInt(name); - else - return config().getInt(section + "." + name); -} +int ConfigOptionInt::get() const { return config().getInt(getKey()); } ConfigOptionBool::ConfigOptionBool(const UString section, const UString name, const UString description, const bool defaultValue) - : section(section), name(name), description(description), defaultValue(defaultValue) + : ConfigOption(section, name, description), defaultValue(defaultValue) { config().addOptionBool(section, name, "", description, defaultValue); } -bool ConfigOptionBool::get() const -{ - if (section.empty()) - return config().getBool(name); - else - - return config().getBool(section + "." + name); -} +bool ConfigOptionBool::get() const { return config().getBool(getKey()); } ConfigOptionFloat::ConfigOptionFloat(const UString section, const UString name, const UString description, const float defaultValue) + : ConfigOption(section, name, description), defaultValue(defaultValue) { config().addOptionFloat(section, name, "", description, defaultValue); } -bool ConfigOptionFloat::get() const -{ - if (section.empty()) - return config().getFloat(name); - else - return config().getFloat(section + "." + name); -} +bool ConfigOptionFloat::get() const { return config().getFloat(getKey()); } void validate(boost::any &v, const std::vector &values, UString *, int) { diff --git a/framework/configfile.h b/framework/configfile.h index 37c5a7d47..b7bf003e7 100644 --- a/framework/configfile.h +++ b/framework/configfile.h @@ -3,11 +3,14 @@ #include "library/sp.h" #include "library/strings.h" #include +#include +#include namespace OpenApoc { class ConfigFileImpl; +class ConfigOption; class ConfigFile { @@ -53,15 +56,28 @@ class ConfigFile // invalid void showHelp(); + std::map> getOptions(); + static ConfigFile &getInstance(); }; -class ConfigOptionString +class ConfigOption { private: UString section; UString name; UString description; + + public: + ConfigOption(const UString section, const UString name, const UString description); + UString getName() const { return name; } + UString getDescription() const { return description; } + UString getKey() const; +}; + +class ConfigOptionString : public ConfigOption +{ + private: UString defaultValue; public: @@ -70,12 +86,9 @@ class ConfigOptionString UString get() const; }; -class ConfigOptionInt +class ConfigOptionInt : public ConfigOption { private: - UString section; - UString name; - UString description; int defaultValue; public: @@ -84,12 +97,9 @@ class ConfigOptionInt int get() const; }; -class ConfigOptionBool +class ConfigOptionBool : public ConfigOption { private: - UString section; - UString name; - UString description; bool defaultValue; public: @@ -98,12 +108,9 @@ class ConfigOptionBool bool get() const; }; -class ConfigOptionFloat +class ConfigOptionFloat : public ConfigOption { private: - UString section; - UString name; - UString description; float defaultValue; public: diff --git a/game/ui/general/optionsmenu.cpp b/game/ui/general/optionsmenu.cpp index 07adbdb33..e8f837880 100644 --- a/game/ui/general/optionsmenu.cpp +++ b/game/ui/general/optionsmenu.cpp @@ -1,18 +1,62 @@ #include "game/ui/general/optionsmenu.h" #include "forms/form.h" +#include "forms/label.h" +#include "forms/listbox.h" +#include "forms/textbutton.h" +#include "forms/textedit.h" #include "forms/ui.h" +#include "framework/configfile.h" #include "framework/event.h" #include "framework/framework.h" #include "framework/keycodes.h" -#include "game/ui/debugtools/debugmenu.h" namespace OpenApoc { -OptionsMenu::OptionsMenu() : Stage(), menuform(ui().getForm("options")) {} +OptionsMenu::OptionsMenu() : Stage(), menuform(ui().getForm("options")) +{ + auto options = config().getOptions(); + auto listbox = menuform->findControlTyped("LISTBOX_OPTIONS"); + for (auto §ion : options) + { + if (!section.first.empty()) + { + listbox->addItem(mksp(section.first, ui().getFont("smalfont"))); + for (auto &opt : section.second) + { + listbox->addItem(createOptionRow(opt)); + } + } + } +} OptionsMenu::~OptionsMenu() = default; +sp OptionsMenu::createOptionRow(const ConfigOption &option) +{ + auto control = mksp(); + + const int HEIGHT = 21; + + auto label = control->createChild