Added new CampaignWML attribute "allow_era_choice".

If attribute is set to "no" and campaign with it is selected, eras menu will be
hidden and text to indicate this will be displayed.

Attribute defaults to "yes" and has been added to LoW.

N.B. since current MP code is tighly coupled with eras, the default era will
still be used by the engine to properly initialize stuff. Later on, code should be
improved by making it more modular and independant of eras.
This commit is contained in:
Andrius Silinskas 2013-12-19 21:30:05 +00:00
parent 473fc1d3f0
commit 597f5ad6a9
5 changed files with 43 additions and 4 deletions

View file

@ -52,6 +52,8 @@
min_players=2
max_players=4
allow_era_choice=no
icon="units/elves-wood/high-lord.png~RC(magenta>brown)"
image="data/campaigns/Legend_of_Wesmere/images/campaign_image.png"
first_scenario="01_The_Uprooting"

View file

@ -70,6 +70,8 @@ create::create(game_display& disp, const config& cfg, game_state& state,
filter_num_players_label_(disp.video(), _("Number of players: any"), font::SIZE_SMALL, font::LOBBY_COLOR),
map_generator_label_(disp.video(), _("Random map options:"), font::SIZE_SMALL, font::LOBBY_COLOR),
era_label_(disp.video(), _("Era:"), font::SIZE_SMALL, font::LOBBY_COLOR),
no_era_label_(disp.video(), _("No eras available\nfor this game."),
font::SIZE_SMALL, font::LOBBY_COLOR),
mod_label_(disp.video(), _("Modifications:"), font::SIZE_SMALL, font::LOBBY_COLOR),
map_size_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOR),
num_players_label_(disp.video(), "", font::SIZE_SMALL, font::LOBBY_COLOR),
@ -300,7 +302,7 @@ void create::process_event()
level_selection_ = levels_menu_.selection();
if (level_changed) {
engine_.set_current_level(levels_menu_.selection());
init_level_changed(levels_menu_.selection());
synchronize_selections();
}
@ -387,7 +389,7 @@ void create::init_level_type_changed(size_t index)
const std::vector<std::string>& menu_item_names =
engine_.levels_menu_item_names();
engine_.set_current_level((index < menu_item_names.size()) ? index : 0);
init_level_changed((index < menu_item_names.size()) ? index : 0);
levels_menu_.set_items(menu_item_names);
levels_menu_.move_selection(index);
@ -395,6 +397,21 @@ void create::init_level_type_changed(size_t index)
level_selection_ = -1;
}
void create::init_level_changed(size_t index)
{
engine_.set_current_level(index);
// N.B. the order of hide() calls here is important
// to avoid redrawing glitches.
if (engine_.current_level().allow_era_choice()) {
no_era_label_.hide(true);
eras_menu_.hide(false);
} else {
eras_menu_.hide(true);
no_era_label_.hide(false);
}
}
void create::synchronize_selections()
{
DBG_MP << "Synchronizing with the dependency manager" << std::endl;
@ -499,7 +516,8 @@ void create::hide_children(bool hide)
ui::hide_children(hide);
eras_menu_.hide(hide),
eras_menu_.hide(hide || !engine_.current_level().allow_era_choice());
no_era_label_.hide(hide || engine_.current_level().allow_era_choice());
levels_menu_.hide(hide);
mods_menu_.hide(hide);
@ -646,6 +664,7 @@ void create::layout_children(const SDL_Rect& rect)
xpos += menu_width + column_border_size;
era_label_.set_location(xpos, ypos);
ypos += era_label_.height() + border_size;
no_era_label_.set_location(xpos, ypos);
eras_menu_.set_max_width(menu_width);
eras_menu_.set_max_height(eras_menu_height);
eras_menu_.set_location(xpos, ypos);

View file

@ -43,6 +43,7 @@ protected:
private:
void init_level_type_changed(size_t index);
void init_level_changed(size_t index);
void synchronize_selections();
@ -67,6 +68,7 @@ private:
gui::label filter_num_players_label_;
gui::label map_generator_label_;
gui::label era_label_;
gui::label no_era_label_;
gui::label mod_label_;
gui::label map_size_label_;
gui::label num_players_label_;

View file

@ -80,6 +80,11 @@ std::string level::id() const
return data_["id"];
}
bool level::allow_era_choice() const
{
return data_["allow_era_choice"].to_bool(true);
}
void level::set_data(const config& data)
{
data_ = data;
@ -253,6 +258,7 @@ std::string random_map::id() const
campaign::campaign(const config& data) :
level(data),
id_(data["id"]),
allow_era_choice_(level::allow_era_choice()),
image_label_(),
min_players_(2),
max_players_(2)
@ -298,6 +304,11 @@ std::string campaign::id() const
return id_;
}
bool campaign::allow_era_choice() const
{
return allow_era_choice_;
}
int campaign::min_players() const
{
return min_players_;
@ -753,7 +764,8 @@ const mp_game_settings& create_engine::get_parameters()
{
DBG_MP << "getting parameter values" << std::endl;
parameters_.mp_era = eras_[current_era_index_]->id;
int era_index = current_level().allow_era_choice() ? current_era_index_ : 0;
parameters_.mp_era = eras_[era_index]->id;
return parameters_;
}

View file

@ -43,6 +43,7 @@ public:
virtual std::string name() const;
virtual std::string description() const;
virtual std::string id() const;
virtual bool allow_era_choice() const;
void set_data(const config& data);
const config& data() const;
@ -134,6 +135,8 @@ public:
std::string id() const;
bool allow_era_choice() const;
int min_players() const;
int max_players() const;
@ -142,6 +145,7 @@ private:
void operator=(const campaign&);
std::string id_;
bool allow_era_choice_;
std::string image_label_;
int min_players_;
int max_players_;