Does not build: Revert "Refactored display-class theme initialization"

This reverts commit 4551e28166. That commit
broke the Ubuntu builds, but the Windows builds were already broken by
commit 4551e28166. I need a working CI to
check that my next commit fixes the earlier problem.
This commit is contained in:
Steve Cotton 2022-03-30 08:09:47 +02:00
parent 4551e28166
commit c52c784522
15 changed files with 84 additions and 81 deletions

View file

@ -453,3 +453,25 @@ bool controller_base::in_context_menu(hotkey::HOTKEY_COMMAND /*command*/) const
{
return true;
}
const config& controller_base::get_theme(const game_config_view& game_config, std::string theme_name)
{
if(theme_name.empty()) {
theme_name = preferences::theme();
}
if(const config& c = game_config.find_child("theme", "id", theme_name)) {
return c;
}
ERR_DP << "Theme '" << theme_name << "' not found. Trying the default theme." << std::endl;
if(const config& c = game_config.find_child("theme", "id", "Default")) {
return c;
}
ERR_DP << "Default theme not found." << std::endl;
static config empty;
return empty;
}

View file

@ -69,6 +69,8 @@ public:
virtual void play_slice(bool is_delay_enabled = true);
static const config& get_theme(const game_config_view& game_config, std::string theme_name);
void apply_keyboard_scroll(int x, int y);
void set_scroll_up(bool on)

View file

@ -169,7 +169,7 @@ void display::remove_single_overlay(const map_location& loc, const std::string&
display::display(const display_context* dc,
std::weak_ptr<wb::manager> wb,
reports& reports_object,
const std::string& theme_id,
const config& theme_cfg,
const config& level,
bool auto_join)
: video2::draw_layering(auto_join)
@ -183,7 +183,7 @@ display::display(const display_context* dc,
, xpos_(0)
, ypos_(0)
, view_locked_(false)
, theme_(theme::get_theme_config(theme_id.empty() ? preferences::theme() : theme_id), screen_.screen_area())
, theme_(theme_cfg, screen_.screen_area())
, zoom_index_(0)
, fake_unit_man_(new fake_unit_manager(*this))
, builder_(new terrain_builder(level, (dc_ ? &dc_->map() : nullptr), theme_.border().tile_image, theme_.border().show_border))
@ -288,9 +288,8 @@ display::~display()
resources::fake_units = nullptr;
}
void display::set_theme(const std::string& new_theme)
{
theme_ = theme{theme::get_theme_config(new_theme), screen_.screen_area()};
void display::set_theme(config theme_cfg) {
theme_ = theme(theme_cfg, screen_.screen_area());
builder_->set_draw_border(theme_.border().show_border);
menu_buttons_.clear();
action_buttons_.clear();

View file

@ -80,13 +80,9 @@ class gamemap;
class display : public video2::draw_layering
{
public:
display(const display_context* dc,
std::weak_ptr<wb::manager> wb,
reports& reports_object,
const std::string& theme_id,
const config& level,
bool auto_join = true);
display(const display_context * dc, std::weak_ptr<wb::manager> wb,
reports & reports_object,
const config& theme_cfg, const config& level, bool auto_join=true);
virtual ~display();
/**
* Returns the display object if a display object exists. Otherwise it returns nullptr.
@ -380,7 +376,7 @@ public:
void clear_redraw_observers();
theme& get_theme() { return theme_; }
void set_theme(const std::string& new_theme);
void set_theme(config theme_cfg);
/**
* Retrieves a pointer to a theme UI button.

View file

@ -69,7 +69,7 @@ editor_controller::editor_controller()
, quit_confirmation(std::bind(&editor_controller::quit_confirm, this))
, active_menu_(editor::MAP)
, reports_(new reports())
, gui_(new editor_display(*this, *reports_))
, gui_(new editor_display(*this, *reports_, controller_base::get_theme(game_config_, "editor")))
, tods_()
, context_manager_(new context_manager(*gui_.get(), game_config_))
, toolkit_(nullptr)

View file

@ -30,8 +30,8 @@ namespace wb {
namespace editor {
editor_display::editor_display(editor_controller& controller, reports& reports_object)
: display(nullptr, std::shared_ptr<wb::manager>(), reports_object, "editor", config())
editor_display::editor_display(editor_controller& controller, reports& reports_object, const config& theme_cfg)
: display(nullptr, std::shared_ptr<wb::manager>(), reports_object, theme_cfg, config())
, brush_locations_()
, controller_(controller)
{

View file

@ -23,7 +23,7 @@ namespace editor {
class editor_display : public display
{
public:
editor_display(editor_controller& controller, reports& reports_object);
editor_display(editor_controller& controller, reports& reports_object, const config& theme_cfg);
bool in_editor() const override { return true; }

View file

@ -65,9 +65,9 @@ std::vector<surface> footsteps_images(const map_location& loc, const pathfind::m
game_display::game_display(game_board& board,
std::weak_ptr<wb::manager> wb,
reports& reports_object,
const std::string& theme_id,
const config& theme_cfg,
const config& level)
: display(&board, wb, reports_object, theme_id, level, false)
: display(&board, wb, reports_object, theme_cfg, level, false)
, overlay_map_()
, attack_indicator_src_()
, attack_indicator_dst_()

View file

@ -36,7 +36,7 @@ public:
game_display(game_board& board,
std::weak_ptr<wb::manager> wb,
reports & reports_object,
const std::string& theme_id,
const config& theme_cfg,
const config& level);
~game_display();

View file

@ -236,10 +236,11 @@ void play_controller::init(const config& level)
LOG_NG << "initializing theme... " << (SDL_GetTicks() - ticks()) << std::endl;
gui2::dialogs::loading_screen::progress(loading_stage::init_theme);
const config& theme_cfg = controller_base::get_theme(game_config_, theme());
LOG_NG << "building terrain rules... " << (SDL_GetTicks() - ticks()) << std::endl;
gui2::dialogs::loading_screen::progress(loading_stage::build_terrain);
gui_.reset(new game_display(gamestate().board_, whiteboard_manager_, *gamestate().reports_, theme(), level));
gui_.reset(new game_display(gamestate().board_, whiteboard_manager_, *gamestate().reports_, theme_cfg, level));
map_start_ = map_location(level.child_or_empty("display").child_or_empty("location"));
if(!gui_->video().faked()) {

View file

@ -37,6 +37,7 @@
#include "log.hpp"
#include "play_controller.hpp"
#include "game_data.hpp"
#include "game_config_manager.hpp"
#include "resources.hpp"
namespace preferences {
@ -64,7 +65,7 @@ void set_show_standing_animations(bool value)
bool show_theme_dialog()
{
std::vector<theme_info> themes = theme::get_basic_theme_info();
std::vector<theme_info> themes = theme::get_known_themes();
if (themes.empty()) {
gui2::show_transient_message("",
@ -86,8 +87,8 @@ bool show_theme_dialog()
if (action >= 0) {
preferences::set_theme(themes[action].id);
if(display::get_singleton() && resources::gamedata && resources::gamedata->get_theme().empty()) {
display::get_singleton()->set_theme(themes[action].id);
if(display::get_singleton() && resources::controller && resources::gamedata && resources::gamedata->get_theme().empty()) {
display::get_singleton()->set_theme(resources::controller->get_theme(game_config_manager::get()->game_config(), themes[action].id));
}
return true;

View file

@ -91,7 +91,7 @@ replay_controller::~replay_controller()
}
void replay_controller::add_replay_theme()
{
const config& theme_cfg = theme::get_theme_config(controller_.theme());
const config &theme_cfg = controller_.get_theme(game_config_manager::get()->game_config(), controller_.theme());
if (const auto res = theme_cfg.optional_child("resolution"))
{
if (const auto replay_theme_cfg = res->optional_child("replay")) {

View file

@ -1326,7 +1326,8 @@ int game_lua_kernel::impl_game_config_set(lua_State *L)
modify_string_attrib_deprecated("next_scenario", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.next instead", gamedata().set_next_scenario(value));
modify_string_attrib("theme",
gamedata().set_theme(value);
game_display_->set_theme(value);
const game_config_view& game_config = game_config_manager::get()->game_config();
game_display_->set_theme(play_controller_.get_theme(game_config, value));
);
modify_vector_string_attrib_deprecated("defeat_music", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.defeat_music instead", gamedata().set_defeat_music(std::move(value)));
modify_vector_string_attrib_deprecated("victory_music", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.victory_music instead", gamedata().set_victory_music(std::move(value)));

View file

@ -914,6 +914,38 @@ const theme::status_item* theme::get_status_item(const std::string& key) const
return nullptr;
}
typedef std::map<std::string, config> known_themes_map;
known_themes_map theme::known_themes;
void theme::set_known_themes(const game_config_view* cfg)
{
known_themes.clear();
if(!cfg)
return;
for(const config& thm : cfg->child_range("theme")) {
std::string thm_id = thm["id"];
if(!thm["hidden"].to_bool(false)) {
known_themes[thm_id] = thm;
}
}
}
std::vector<theme_info> theme::get_known_themes()
{
std::vector<theme_info> res;
for(known_themes_map::const_iterator i = known_themes.begin(); i != known_themes.end(); ++i) {
res.push_back(theme_info());
res.back().id = i->first;
res.back().name = i->second["name"].t_str();
res.back().description = i->second["description"].t_str();
}
return res;
}
const theme::menu* theme::get_menu_item(const std::string& key) const
{
for(const theme::menu& m : menus_) {
@ -973,49 +1005,3 @@ void theme::modify_label(const std::string& id, const std::string& text)
}
label->set_text(text);
}
void theme::set_known_themes(const game_config_view* cfg)
{
if(cfg) {
known_themes.clear();
for(const config& thm : cfg->child_range("theme")) {
known_themes[thm["id"]] = thm;
}
}
}
std::vector<theme_info> theme::get_basic_theme_info(bool include_hidden)
{
std::vector<theme_info> res;
for(const auto& [id, cfg] : known_themes) {
if(!cfg["hidden"].to_bool(false) || include_hidden) {
auto& info = res.emplace_back();
info.id = id;
info.name = cfg["name"].t_str();
info.description = cfg["description"].t_str();
}
}
return res;
}
const config& theme::get_theme_config(const std::string& id)
{
auto iter = known_themes.find(id);
if(iter != known_themes.end()) {
return iter->second;
}
ERR_DP << "Theme '" << id << "' not found. Falling back to default theme." << std::endl;
iter = known_themes.find("Default");
if(iter != known_themes.end()) {
return iter->second;
}
ERR_DP << "Default theme not found." << std::endl;
static config empty;
return empty;
}

View file

@ -278,6 +278,9 @@ public:
const SDL_Rect& palette_location(const SDL_Rect& screen) const
{ return palette_.location(screen); }
static void set_known_themes(const game_config_view* cfg);
static std::vector<theme_info> get_known_themes();
const border_t& border() const { return border_; }
events::generic_event& theme_reset_event() { return theme_reset_event_; }
@ -292,6 +295,7 @@ private:
//atm this is used for replay_controller to add replay controls to the standard theme
events::generic_event theme_reset_event_;
static std::map<std::string, config> known_themes;
std::string cur_theme;
config cfg_;
std::vector<panel> panels_;
@ -311,13 +315,4 @@ private:
SDL_Rect screen_dimensions_;
std::size_t cur_spec_width_, cur_spec_height_;
static inline std::map<std::string, config> known_themes{};
public:
static void set_known_themes(const game_config_view* cfg);
static const config& get_theme_config(const std::string& id);
static std::vector<theme_info> get_basic_theme_info(bool include_hidden = false);
};