16 #define GETTEXT_DOMAIN "wesnoth-lib"
35 config read_and_validate(
const std::string&
path)
39 defines.try_emplace(
"ANDROID");
44 }
catch(
const utils::bad_optional_access&) {
45 FAIL(
"GUI2: schema/gui.cfg not found.");
48 FAIL(
"GUI2: could not read schema file: " +
e.message);
65 auto register_theme(
const config& def) -> utils::optional<gui_theme_map_t::iterator>
67 auto [iter, is_unique] =
guis.try_emplace(def[
"id"], def);
68 if(is_unique)
return iter;
70 ERR_GUI_P <<
"UI Theme '" << def[
"id"] <<
"' already exists.";
71 return utils::nullopt;
74 ERR_GUI_P <<
"Invalid UI theme: " << def[
"id"];
76 return utils::nullopt;
85 void parse(
const std::string& full_path,
bool is_core)
87 config cfg = read_and_validate(full_path);
89 const bool is_default = def[
"id"] ==
"default";
91 if(is_default && !is_core) {
92 ERR_GUI_P <<
"UI theme id 'default' is reserved for core themes.";
96 const auto iter = register_theme(def);
99 if(is_default && is_core) {
110 LOG_GUI_G <<
"Initializing UI subststem.";
124 }
catch(
const utils::bad_optional_access&) {
125 FAIL(
"GUI2: gui/_main.cfg not found.");
135 std::vector<std::string> addon_dirs;
140 for(
const std::string& umc : addon_dirs) {
141 const std::string gui_file = umc +
"/gui-theme.cfg";
144 parse(gui_file,
false);
151 if(theme_id.empty() || theme_id ==
"default") {
155 [&](
const auto&
theme) {
return theme.first; });
158 ERR_GUI_P <<
"Missing [gui] definition for '" << theme_id <<
"'";
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(std::string_view key)
Realization of serialization/validator.hpp abstract validator.
Declarations for File-IO.
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, name_mode mode, filter_mode filter, reorder_mode reorder, file_tree_checksum *checksum)
Get a list of all files and/or directories in a given directory.
static bool file_exists(const bfs::path &fpath)
utils::optional< std::string > get_wml_location(const std::string &path, const utils::optional< std::string > ¤t_dir)
Returns a translated path to the actual file or directory, if it exists.
std::string get_addons_dir()
void update_screen_size_variables()
Update the size of the screen variables in settings.
void init()
Initializes the GUI subsystems.
gui_theme_map_t guis
Map of all known GUIs.
void switch_theme(const std::string &theme_id)
Set and activate the given gui2 theme.
gui_theme_map_t::iterator current_gui
Iterator pointing to the current GUI.
gui_theme_map_t::iterator default_gui
Iterator pointing to the default GUI.
config read(std::istream &in, abstract_validator *validator)
auto find(Container &container, const Value &value, const Projection &projection={})
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map &defines)
Function to use the WML preprocessor on a file.
std::map< std::string, struct preproc_define > preproc_map
One of the realizations of serialization/validator.hpp abstract validator.
This file contains the settings handling of the widget library.
std::unique_ptr< MIX_Audio, decltype(&MIX_DestroyAudio)> value
Used to manage with not initialized validators Supposed to be thrown from the constructor.
Helper class, don't construct this directly.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.