From f5be4cffb7b34fdd2ac875cf0f76fc8db7e23cef Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sat, 6 May 2023 19:54:28 -0400 Subject: [PATCH] Don't use optional_child for widget state definitions when it's mandatory (#7600) --- src/gui/core/widget_definition.cpp | 8 +++----- src/gui/core/widget_definition.hpp | 2 +- src/gui/widgets/button.cpp | 10 ++++++---- src/gui/widgets/chatbox.cpp | 11 +++++------ src/gui/widgets/horizontal_scrollbar.cpp | 9 +++++---- src/gui/widgets/image.cpp | 4 +++- src/gui/widgets/label.cpp | 5 +++-- src/gui/widgets/listbox.cpp | 6 +++--- src/gui/widgets/matrix.cpp | 4 ++-- src/gui/widgets/menu_button.cpp | 10 ++++++---- src/gui/widgets/minimap.cpp | 4 +++- src/gui/widgets/multimenu_button.cpp | 9 +++++---- src/gui/widgets/panel.cpp | 4 ++-- src/gui/widgets/progress_bar.cpp | 4 +++- src/gui/widgets/repeating_button.cpp | 10 ++++++---- src/gui/widgets/scroll_label.cpp | 11 +++++------ src/gui/widgets/scrollbar_panel.cpp | 10 ++++------ src/gui/widgets/slider.cpp | 8 ++++---- src/gui/widgets/text_box.cpp | 10 ++++++---- src/gui/widgets/toggle_button.cpp | 8 +++++--- src/gui/widgets/toggle_panel.cpp | 6 +++--- src/gui/widgets/tree_view.cpp | 9 ++++----- src/gui/widgets/unit_preview_pane.cpp | 10 ++++------ src/gui/widgets/vertical_scrollbar.cpp | 9 +++++---- 24 files changed, 96 insertions(+), 85 deletions(-) diff --git a/src/gui/core/widget_definition.cpp b/src/gui/core/widget_definition.cpp index 750da64445a..6fa7d126e52 100644 --- a/src/gui/core/widget_definition.cpp +++ b/src/gui/core/widget_definition.cpp @@ -25,11 +25,9 @@ namespace gui2 { -state_definition::state_definition(optional_const_config cfg) - : canvas_cfg_(cfg ? cfg->child_or_empty("draw") : config()) -{ - VALIDATE(cfg && cfg->has_child("draw"), _("No state or draw section defined.")); -} +state_definition::state_definition(const config& cfg) + : canvas_cfg_(VALIDATE_WML_CHILD(cfg, "draw", _("No draw section defined for state."))) +{} resolution_definition::resolution_definition(const config& cfg) : window_width(cfg["window_width"]) diff --git a/src/gui/core/widget_definition.hpp b/src/gui/core/widget_definition.hpp index c0d12177073..a35466a6c4d 100644 --- a/src/gui/core/widget_definition.hpp +++ b/src/gui/core/widget_definition.hpp @@ -35,7 +35,7 @@ namespace gui2 */ struct state_definition { - explicit state_definition(optional_const_config cfg); + explicit state_definition(const config& cfg); config canvas_cfg_; }; diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index f6b032a06f0..a7ee64fa49f 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -26,6 +26,8 @@ #include "gui/core/register_widget.hpp" #include "gui/widgets/settings.hpp" #include "gui/widgets/window.hpp" +#include "wml_exception.hpp" +#include "gettext.hpp" #include "sound.hpp" @@ -159,10 +161,10 @@ button_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg) { // Note the order should be the same as the enum state_t in button.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_pressed")); - state.emplace_back(cfg.optional_child("state_focused")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for button"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/chatbox.cpp b/src/gui/widgets/chatbox.cpp index 22ead50e784..c7f54a1b2d8 100644 --- a/src/gui/widgets/chatbox.cpp +++ b/src/gui/widgets/chatbox.cpp @@ -38,6 +38,7 @@ #include "preferences/game.hpp" #include "preferences/lobby.hpp" #include "scripting/plugins/manager.hpp" +#include "wml_exception.hpp" static lg::log_domain log_lobby("lobby"); #define DBG_LB LOG_STREAM(debug, log_lobby) @@ -653,13 +654,11 @@ chatbox_definition::chatbox_definition(const config& cfg) chatbox_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg), grid() { - state.emplace_back(cfg.optional_child("background")); - state.emplace_back(cfg.optional_child("foreground")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for chatbox"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for chatbox"))); - auto child = cfg.optional_child("grid"); - VALIDATE(child, _("No grid defined.")); - - grid = std::make_shared(*child); + auto child = VALIDATE_WML_CHILD(cfg, "grid", _("Missing required grid for chatbox")); + grid = std::make_shared(child); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/horizontal_scrollbar.cpp b/src/gui/widgets/horizontal_scrollbar.cpp index 34923b52ad6..b89bd5b5e58 100644 --- a/src/gui/widgets/horizontal_scrollbar.cpp +++ b/src/gui/widgets/horizontal_scrollbar.cpp @@ -24,6 +24,7 @@ #include "gui/widgets/settings.hpp" #include "wml_exception.hpp" +#include "gettext.hpp" #include @@ -129,10 +130,10 @@ horizontal_scrollbar_definition::resolution::resolution(const config& cfg) "minimum_positioner_length")); // Note the order should be the same as the enum state_t is scrollbar.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_pressed")); - state.emplace_back(cfg.optional_child("state_focused")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for horizontal scrollbar"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for horizontal scrollbar"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for horizontal scrollbar"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for horizontal scrollbar"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/image.cpp b/src/gui/widgets/image.cpp index 83123d26374..09f4ecf0991 100644 --- a/src/gui/widgets/image.cpp +++ b/src/gui/widgets/image.cpp @@ -24,6 +24,8 @@ #include "gui/core/log.hpp" #include "gui/core/register_widget.hpp" #include "gui/widgets/settings.hpp" +#include "wml_exception.hpp" +#include "gettext.hpp" #include @@ -110,7 +112,7 @@ image_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg) { // Note the order should be the same as the enum state_t in image.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for image control"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 047b3a67416..df8687b2f65 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -30,6 +30,7 @@ #include "desktop/clipboard.hpp" #include "desktop/open.hpp" #include "gettext.hpp" +#include "wml_exception.hpp" #include #include @@ -237,8 +238,8 @@ label_definition::resolution::resolution(const config& cfg) , link_color(cfg["link_color"].empty() ? color_t::from_hex_string("ffff00") : color_t::from_rgba_string(cfg["link_color"].str())) { // Note the order should be the same as the enum state_t is label.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for text label control"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for text label control"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index d8f429e42be..4575b2e2471 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -32,6 +32,7 @@ #include "gui/widgets/widget_helpers.hpp" #include "gui/widgets/window.hpp" #include "sdl/rect.hpp" +#include "wml_exception.hpp" #include #include @@ -706,11 +707,10 @@ listbox_definition::resolution::resolution(const config& cfg) , grid(nullptr) { // Note the order should be the same as the enum state_t in listbox.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for listbox"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for listbox"))); auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined.")); - grid = std::make_shared(child); } diff --git a/src/gui/widgets/matrix.cpp b/src/gui/widgets/matrix.cpp index 0b2ad370729..de4b40ab318 100644 --- a/src/gui/widgets/matrix.cpp +++ b/src/gui/widgets/matrix.cpp @@ -188,8 +188,8 @@ matrix_definition::resolution::resolution(const config& cfg) , content(new builder_grid(VALIDATE_WML_CHILD(cfg, "content", _("Missing [content] in [matrix_definition]")))) { // Note the order should be the same as the enum state_t in matrix.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for matrix definition"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for matrix definition"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/menu_button.cpp b/src/gui/widgets/menu_button.cpp index 7fbea22efd2..097b93cb3d5 100644 --- a/src/gui/widgets/menu_button.cpp +++ b/src/gui/widgets/menu_button.cpp @@ -25,6 +25,8 @@ #include "gui/widgets/settings.hpp" #include "gui/widgets/window.hpp" #include "sound.hpp" +#include "wml_exception.hpp" +#include "gettext.hpp" #include @@ -229,10 +231,10 @@ menu_button_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg) { // Note the order should be the same as the enum state_t in menu_button.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_pressed")); - state.emplace_back(cfg.optional_child("state_focused")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for menu button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for menu button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for menu button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for menu button"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/minimap.cpp b/src/gui/widgets/minimap.cpp index c379cfb87ae..efa9ae8b044 100644 --- a/src/gui/widgets/minimap.cpp +++ b/src/gui/widgets/minimap.cpp @@ -26,6 +26,8 @@ #include "map/map.hpp" #include "map/exception.hpp" #include "sdl/rect.hpp" +#include "wml_exception.hpp" +#include "gettext.hpp" #include "../../minimap.hpp" // We want the file in src/ #include @@ -112,7 +114,7 @@ minimap_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg) { // Note the order should be the same as the enum state_t in minimap.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for minimap control"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/multimenu_button.cpp b/src/gui/widgets/multimenu_button.cpp index 988ed844ae8..b2f1ab8080c 100644 --- a/src/gui/widgets/multimenu_button.cpp +++ b/src/gui/widgets/multimenu_button.cpp @@ -29,6 +29,7 @@ #include "formula/string_utils.hpp" #include #include "gettext.hpp" +#include "wml_exception.hpp" #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__ #define LOG_HEADER LOG_SCOPE_HEADER + ':' @@ -252,10 +253,10 @@ multimenu_button_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg) { // Note the order should be the same as the enum state_t in multimenu_button.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_pressed")); - state.emplace_back(cfg.optional_child("state_focused")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for multimenu button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for multimenu button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for multimenu button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for multimenu button"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/panel.cpp b/src/gui/widgets/panel.cpp index 8293881d4e3..cbea5f363ad 100644 --- a/src/gui/widgets/panel.cpp +++ b/src/gui/widgets/panel.cpp @@ -108,8 +108,8 @@ panel_definition::resolution::resolution(const config& cfg) , right_border(cfg["right_border"]) { // The panel needs to know the order. - state.emplace_back(cfg.optional_child("background")); - state.emplace_back(cfg.optional_child("foreground")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for panel definition"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for panel definition"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/progress_bar.cpp b/src/gui/widgets/progress_bar.cpp index ad146d962c9..940def38fe7 100644 --- a/src/gui/widgets/progress_bar.cpp +++ b/src/gui/widgets/progress_bar.cpp @@ -20,6 +20,8 @@ #include "gui/core/log.hpp" #include "gui/core/register_widget.hpp" #include "gui/widgets/settings.hpp" +#include "wml_exception.hpp" +#include "gettext.hpp" #include @@ -91,7 +93,7 @@ progress_bar_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg) { // Note the order should be the same as the enum state_t in progress_bar.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for progress bar"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/repeating_button.cpp b/src/gui/widgets/repeating_button.cpp index 868e9296135..b1361b374df 100644 --- a/src/gui/widgets/repeating_button.cpp +++ b/src/gui/widgets/repeating_button.cpp @@ -23,6 +23,8 @@ #include "gui/widgets/settings.hpp" #include "gui/widgets/window.hpp" #include "sound.hpp" +#include "wml_exception.hpp" +#include "gettext.hpp" #include @@ -179,10 +181,10 @@ repeating_button_definition::resolution::resolution(const config& cfg) { // Note the order should be the same as the enum state_t in // repeating_button.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_pressed")); - state.emplace_back(cfg.optional_child("state_focused")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for repeating button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for repeating button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for repeating button"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for repeating button"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/scroll_label.cpp b/src/gui/widgets/scroll_label.cpp index 3a9977f35fe..a52057d338c 100644 --- a/src/gui/widgets/scroll_label.cpp +++ b/src/gui/widgets/scroll_label.cpp @@ -27,6 +27,7 @@ #include "gui/widgets/spacer.hpp" #include "gui/widgets/window.hpp" #include "gettext.hpp" +#include "wml_exception.hpp" #include @@ -176,13 +177,11 @@ scroll_label_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg), grid(nullptr) { // Note the order should be the same as the enum state_t is scroll_label.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for scroll label control"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for scroll label control"))); - auto child = cfg.optional_child("grid"); - VALIDATE(child, _("No grid defined.")); - - grid = std::make_shared(*child); + auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for scroll label control")); + grid = std::make_shared(child); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/scrollbar_panel.cpp b/src/gui/widgets/scrollbar_panel.cpp index f5d66e07008..8d6ad293e2f 100644 --- a/src/gui/widgets/scrollbar_panel.cpp +++ b/src/gui/widgets/scrollbar_panel.cpp @@ -67,13 +67,11 @@ scrollbar_panel_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg), grid() { // The panel needs to know the order. - state.emplace_back(cfg.optional_child("background")); - state.emplace_back(cfg.optional_child("foreground")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for scrollbar panel"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for scrollbar panel"))); - auto child = cfg.optional_child("grid"); - VALIDATE(child, _("No grid defined.")); - - grid = std::make_shared(*child); + auto child = VALIDATE_WML_CHILD(cfg, "grid", _("Missing required grid for scrollbar panel")); + grid = std::make_shared(child); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 572cc7d724e..445cbc96320 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -310,10 +310,10 @@ slider_definition::resolution::resolution(const config& cfg) VALIDATE(positioner_length, missing_mandatory_wml_key("resolution", "minimum_positioner_length")); // Note the order should be the same as the enum state_t is slider.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_pressed")); - state.emplace_back(cfg.optional_child("state_focused")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for slider"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for slider"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for slider"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for slider"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/text_box.cpp b/src/gui/widgets/text_box.cpp index 64d444fc82d..0f959d40460 100644 --- a/src/gui/widgets/text_box.cpp +++ b/src/gui/widgets/text_box.cpp @@ -24,6 +24,8 @@ #include "preferences/game.hpp" #include "serialization/unicode.hpp" #include +#include "wml_exception.hpp" +#include "gettext.hpp" #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__ #define LOG_HEADER LOG_SCOPE_HEADER + ':' @@ -406,10 +408,10 @@ text_box_definition::resolution::resolution(const config& cfg) , text_y_offset(cfg["text_y_offset"]) { // Note the order should be the same as the enum state_t in text_box.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_focused")); - state.emplace_back(cfg.optional_child("state_hovered")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for editable text box"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for editable text box"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for editable text box"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_hovered", _("Missing required state for editable text box"))); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/toggle_button.cpp b/src/gui/widgets/toggle_button.cpp index 4d4381d4d77..c136bf5a130 100644 --- a/src/gui/widgets/toggle_button.cpp +++ b/src/gui/widgets/toggle_button.cpp @@ -23,6 +23,8 @@ #include "gui/core/log.hpp" #include "gui/core/window_builder/helper.hpp" #include "sound.hpp" +#include "wml_exception.hpp" +#include "gettext.hpp" #include @@ -209,9 +211,9 @@ toggle_button_definition::resolution::resolution(const config& cfg) // toggle_button.hpp. for(const auto& c : cfg.child_range("state")) { - state.emplace_back(c.optional_child("enabled")); - state.emplace_back(c.optional_child("disabled")); - state.emplace_back(c.optional_child("focused")); + state.emplace_back(VALIDATE_WML_CHILD(c, "enabled", _("Missing required state for toggle button"))); + state.emplace_back(VALIDATE_WML_CHILD(c, "disabled", _("Missing required state for toggle button"))); + state.emplace_back(VALIDATE_WML_CHILD(c, "focused", _("Missing required state for toggle button"))); } } diff --git a/src/gui/widgets/toggle_panel.cpp b/src/gui/widgets/toggle_panel.cpp index 2488b8b5422..910216bc7fb 100644 --- a/src/gui/widgets/toggle_panel.cpp +++ b/src/gui/widgets/toggle_panel.cpp @@ -299,9 +299,9 @@ toggle_panel_definition::resolution::resolution(const config& cfg) // Note the order should be the same as the enum state_t in toggle_panel.hpp. for(const auto& c : cfg.child_range("state")) { - state.emplace_back(c.optional_child("enabled")); - state.emplace_back(c.optional_child("disabled")); - state.emplace_back(c.optional_child("focused")); + state.emplace_back(VALIDATE_WML_CHILD(c, "enabled", _("Missing required state for toggle panel"))); + state.emplace_back(VALIDATE_WML_CHILD(c, "disabled", _("Missing required state for toggle panel"))); + state.emplace_back(VALIDATE_WML_CHILD(c, "focused", _("Missing required state for toggle panel"))); } } diff --git a/src/gui/widgets/tree_view.cpp b/src/gui/widgets/tree_view.cpp index cf566f6ecb7..76b593278ac 100644 --- a/src/gui/widgets/tree_view.cpp +++ b/src/gui/widgets/tree_view.cpp @@ -265,13 +265,12 @@ tree_view_definition::resolution::resolution(const config& cfg) , grid(nullptr) { // Note the order should be the same as the enum state_t is listbox.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for tree view"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for tree view"))); - auto child = cfg.optional_child("grid"); - VALIDATE(child, _("No grid defined.")); + auto child = VALIDATE_WML_CHILD(cfg, "grid", _("No grid defined for tree view")); - grid = std::make_shared(*child); + grid = std::make_shared(child); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/unit_preview_pane.cpp b/src/gui/widgets/unit_preview_pane.cpp index 43484313e1f..09970bdcbb7 100644 --- a/src/gui/widgets/unit_preview_pane.cpp +++ b/src/gui/widgets/unit_preview_pane.cpp @@ -608,13 +608,11 @@ unit_preview_pane_definition::unit_preview_pane_definition(const config& cfg) unit_preview_pane_definition::resolution::resolution(const config& cfg) : resolution_definition(cfg), grid() { - state.emplace_back(cfg.optional_child("background")); - state.emplace_back(cfg.optional_child("foreground")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "background", _("Missing required background for unit preview pane"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "foreground", _("Missing required foreground for unit preview pane"))); - auto child = cfg.optional_child("grid"); - VALIDATE(child, _("No grid defined.")); - - grid = std::make_shared(*child); + auto child = VALIDATE_WML_CHILD(cfg, "grid", _("Missing required grid for unit preview pane")); + grid = std::make_shared(child); } // }---------- BUILDER -----------{ diff --git a/src/gui/widgets/vertical_scrollbar.cpp b/src/gui/widgets/vertical_scrollbar.cpp index 2566b43510e..663fc80415c 100644 --- a/src/gui/widgets/vertical_scrollbar.cpp +++ b/src/gui/widgets/vertical_scrollbar.cpp @@ -19,6 +19,7 @@ #include "gui/core/register_widget.hpp" #include "gui/widgets/settings.hpp" #include "wml_exception.hpp" +#include "gettext.hpp" #include @@ -119,10 +120,10 @@ vertical_scrollbar_definition::resolution::resolution(const config& cfg) "minimum_positioner_length")); // Note the order should be the same as the enum state_t in scrollbar.hpp. - state.emplace_back(cfg.optional_child("state_enabled")); - state.emplace_back(cfg.optional_child("state_disabled")); - state.emplace_back(cfg.optional_child("state_pressed")); - state.emplace_back(cfg.optional_child("state_focused")); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", _("Missing required state for vertical scrollbar"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_disabled", _("Missing required state for vertical scrollbar"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_pressed", _("Missing required state for vertical scrollbar"))); + state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_focused", _("Missing required state for vertical scrollbar"))); } // }---------- BUILDER -----------{