-
-
Notifications
You must be signed in to change notification settings - Fork 990
/
sp_options_configure.hpp
92 lines (70 loc) · 2.65 KB
/
sp_options_configure.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
Copyright (C) 2008 - 2016 by the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_DIALOGS_SP_CONFIGURE_OPTIONS_HPP_INCLUDED
#define GUI_DIALOGS_SP_CONFIGURE_OPTIONS_HPP_INCLUDED
#include "gui/dialogs/modal_dialog.hpp"
#include "gui/dialogs/multiplayer/plugin_executor.hpp"
#include "gui/dialogs/multiplayer/mp_options_helper.hpp"
#include "game_initialization/create_engine.hpp"
#include "game_initialization/configure_engine.hpp"
namespace gui2
{
namespace dialogs
{
class sp_options_configure : public modal_dialog, private plugin_executor
{
public:
sp_options_configure(ng::create_engine& create_engine, ng::configure_engine& config_engine);
/**
* Execute function. We only want to show the dialog if the campaign has options or if
* there are active mods and at least one of those mods has custom options.
*/
static bool execute(ng::create_engine& create_engine, ng::configure_engine& config_engine, CVideo& video)
{
// Check campaign options.
const auto& campaign_mods = create_engine.current_level().data().child_range("options");
const bool have_campaign_options = std::any_of(campaign_mods.begin(), campaign_mods.end(), [](config& mod) {
return !mod.empty();
});
// Check active mod options.
bool have_mod_options = false;
for(const auto& mod : create_engine.active_mods_data()) {
if(!(*mod->cfg).has_child("options")) {
continue;
}
const auto& opt_range = (*mod->cfg).child_range("options");
if(std::any_of(opt_range.begin(), opt_range.end(), [](const config& options) {
return !options.empty();
})) {
have_mod_options = true;
break;
}
}
// If we have no valid options whatsoever, just bypass this dialog.
if(!have_campaign_options && !have_mod_options) {
return true;
}
return sp_options_configure(create_engine, config_engine).show(video);
}
private:
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from modal_dialog. */
void pre_show(window& window);
/** Inherited from modal_dialog. */
void post_show(window& window);
ng::create_engine& create_engine_;
ng::configure_engine& config_engine_;
std::unique_ptr<mp_options_helper> options_manager_;
};
} // namespace dialogs
} // namespace gui2
#endif