Unify leaders and genders set up between mp::connect and mp::wait.
The relevant functions from mp::connect were moved to mp::ui to enable them to use by mp::wait as well. This is not the most elegant solution, but in the future mp::connect and mp::wait should be merged into one, and those functions could be moved back to where they were. leader_list.?pp has been removed since it is no longer used.
This commit is contained in:
parent
b28a1fb6ab
commit
0509d0c188
13 changed files with 252 additions and 487 deletions
|
@ -18790,14 +18790,6 @@
|
|||
RelativePath="..\..\src\language.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\leader_list.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\leader_list.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\leader_scroll_dialog.cpp"
|
||||
>
|
||||
|
|
|
@ -758,7 +758,6 @@ set(wesnoth-main_SRC
|
|||
help.cpp
|
||||
hotkey_preferences_display.cpp
|
||||
intro.cpp
|
||||
leader_list.cpp
|
||||
leader_scroll_dialog.cpp
|
||||
map.cpp
|
||||
map_location.cpp
|
||||
|
|
|
@ -427,7 +427,6 @@ wesnoth_sources = Split("""
|
|||
halo.cpp
|
||||
help.cpp
|
||||
intro.cpp
|
||||
leader_list.cpp
|
||||
leader_scroll_dialog.cpp
|
||||
lobby_preferences.cpp
|
||||
menu_events.cpp
|
||||
|
|
|
@ -1,277 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2007 - 2013
|
||||
Part of 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 2
|
||||
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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Manage the selection of a leader, and select his/her gender.
|
||||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "leader_list.hpp"
|
||||
#include "wml_separators.hpp"
|
||||
#include "widgets/combo.hpp"
|
||||
|
||||
const std::string leader_list_manager::random_enemy_picture("units/random-dice.png");
|
||||
|
||||
leader_list_manager::leader_list_manager(gui::combo* leader_combo,
|
||||
gui::combo* gender_combo):
|
||||
leaders_(),
|
||||
genders_(),
|
||||
gender_ids_(),
|
||||
leader_combo_(leader_combo),
|
||||
gender_combo_(gender_combo),
|
||||
color_(0)
|
||||
{
|
||||
}
|
||||
|
||||
void leader_list_manager::init_combos(gui::combo* leader_combo,
|
||||
gui::combo* gender_combo)
|
||||
{
|
||||
leader_combo_ = leader_combo;
|
||||
gender_combo_ = gender_combo;
|
||||
}
|
||||
|
||||
void leader_list_manager::set_side_list(
|
||||
const std::vector<const config *> &side_list)
|
||||
{
|
||||
side_list_ = side_list;
|
||||
}
|
||||
|
||||
void leader_list_manager::set_leader_combo(gui::combo* combo)
|
||||
{
|
||||
int selected = leader_combo_ != NULL ? leader_combo_->selected() : 0;
|
||||
leader_combo_ = combo;
|
||||
|
||||
if(leader_combo_ != NULL) {
|
||||
if(leaders_.empty()) {
|
||||
update_leader_list(0);
|
||||
} else {
|
||||
populate_leader_combo(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void leader_list_manager::set_gender_combo(gui::combo* combo)
|
||||
{
|
||||
gender_combo_ = combo;
|
||||
|
||||
if(gender_combo_ != NULL) {
|
||||
if(!leaders_.empty()) {
|
||||
update_gender_list(get_leader());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void leader_list_manager::update_leader_list(int side_index)
|
||||
{
|
||||
const config& side = *side_list_[side_index];
|
||||
|
||||
leaders_.clear();
|
||||
|
||||
if (side["random_faction"].to_bool() || side["id"] == "Custom") {
|
||||
if(leader_combo_ != NULL) {
|
||||
std::vector<std::string> dummy;
|
||||
dummy.push_back(utils::unicode_em_dash);
|
||||
leader_combo_->enable(false);
|
||||
leader_combo_->set_items(dummy);
|
||||
leader_combo_->set_selected(0);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if(leader_combo_ != NULL)
|
||||
leader_combo_->enable(true);
|
||||
if(gender_combo_ != NULL)
|
||||
gender_combo_->enable(true);
|
||||
}
|
||||
|
||||
if(!side["leader"].empty()) {
|
||||
leaders_ = utils::split(side["leader"]);
|
||||
}
|
||||
|
||||
const std::string default_leader = side["type"];
|
||||
const std::string random_leader = "random";
|
||||
size_t default_index = 0;
|
||||
|
||||
std::vector<std::string>::const_iterator itor;
|
||||
|
||||
for (itor = leaders_.begin(); itor != leaders_.end(); ++itor) {
|
||||
if (*itor == default_leader) {
|
||||
break;
|
||||
}
|
||||
default_index++;
|
||||
}
|
||||
|
||||
if (default_index == leaders_.size()) {
|
||||
leaders_.push_back(default_leader);
|
||||
}
|
||||
|
||||
if (default_leader != random_leader) {
|
||||
leaders_.push_back(random_leader);
|
||||
}
|
||||
|
||||
populate_leader_combo(default_index);
|
||||
}
|
||||
|
||||
void leader_list_manager::update_gender_list(const std::string& leader)
|
||||
{
|
||||
int gender_index = gender_combo_ != NULL ? gender_combo_->selected() : 0;
|
||||
genders_.clear();
|
||||
gender_ids_.clear();
|
||||
if (leader == "random" || leader == "-" || leader == "?") {
|
||||
// Assume random/unknown leader/faction == unknown gender
|
||||
gender_ids_.push_back("null");
|
||||
genders_.push_back(utils::unicode_em_dash);
|
||||
if (gender_combo_ != NULL) {
|
||||
gender_combo_->enable(false);
|
||||
gender_combo_->set_items(genders_);
|
||||
gender_combo_->set_selected(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const unit_type *utp = unit_types.find(leader);
|
||||
if (utp) {
|
||||
const unit_type &ut = *utp;
|
||||
const std::vector<unit_race::GENDER> genders = ut.genders();
|
||||
if ( (genders.size() < 2) && (gender_combo_ != NULL) ) {
|
||||
gender_combo_->enable(false);
|
||||
} else {
|
||||
gender_ids_.push_back("random");
|
||||
genders_.push_back(IMAGE_PREFIX + random_enemy_picture + COLUMN_SEPARATOR + _("gender^Random"));
|
||||
if (gender_combo_ != NULL) gender_combo_->enable(true);
|
||||
}
|
||||
for (std::vector<unit_race::GENDER>::const_iterator i=genders.begin(); i != genders.end(); ++i) {
|
||||
const unit_type& utg = ut.get_gender_unit_type(*i);
|
||||
|
||||
// Make the internationalized titles for each gender, along with the WML ids
|
||||
if (*i == unit_race::FEMALE) {
|
||||
gender_ids_.push_back(unit_race::s_female);
|
||||
genders_.push_back(IMAGE_PREFIX + utg.image() + get_RC_suffix(utg.flag_rgb()) +
|
||||
COLUMN_SEPARATOR + _("Female ♀"));
|
||||
} else {
|
||||
gender_ids_.push_back(unit_race::s_male);
|
||||
genders_.push_back(IMAGE_PREFIX + utg.image() + get_RC_suffix(utg.flag_rgb()) +
|
||||
COLUMN_SEPARATOR + _("Male ♂"));
|
||||
}
|
||||
}
|
||||
if (gender_combo_ != NULL) {
|
||||
gender_combo_->set_items(genders_);
|
||||
assert(!genders_.empty());
|
||||
gender_index %= genders_.size();
|
||||
gender_combo_->set_selected(gender_index);
|
||||
}
|
||||
} else {
|
||||
gender_ids_.push_back("random");
|
||||
genders_.push_back(IMAGE_PREFIX + random_enemy_picture + COLUMN_SEPARATOR + _("Random"));
|
||||
if (gender_combo_ != NULL) {
|
||||
gender_combo_->enable(false);
|
||||
gender_combo_->set_items(genders_);
|
||||
gender_combo_->set_selected(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void leader_list_manager::populate_leader_combo(int selected_index) {
|
||||
std::vector<std::string>::const_iterator itor;
|
||||
std::vector<std::string> leader_strings;
|
||||
for(itor = leaders_.begin(); itor != leaders_.end(); ++itor) {
|
||||
|
||||
const unit_type *utp = unit_types.find(*itor);
|
||||
if (utp) {
|
||||
std::string gender;
|
||||
if (gender_combo_ != NULL && !genders_.empty() && size_t(gender_combo_->selected()) < genders_.size()) {
|
||||
gender = gender_ids_[gender_combo_->selected()];
|
||||
}
|
||||
const unit_type& ut = utp->get_gender_unit_type(gender);
|
||||
leader_strings.push_back(IMAGE_PREFIX + ut.image() + get_RC_suffix(ut.flag_rgb()) + COLUMN_SEPARATOR + ut.type_name());
|
||||
|
||||
} else {
|
||||
if(*itor == "random") {
|
||||
leader_strings.push_back(IMAGE_PREFIX + random_enemy_picture + COLUMN_SEPARATOR + _("Random"));
|
||||
} else {
|
||||
leader_strings.push_back("?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(leader_combo_ != NULL) {
|
||||
leader_combo_->set_items(leader_strings);
|
||||
leader_combo_->set_selected(selected_index);
|
||||
}
|
||||
}
|
||||
|
||||
void leader_list_manager::set_leader(const std::string& leader)
|
||||
{
|
||||
if(leader_combo_ == NULL)
|
||||
return;
|
||||
|
||||
int leader_index = 0;
|
||||
for(std::vector<std::string>::const_iterator itor = leaders_.begin();
|
||||
itor != leaders_.end(); ++itor) {
|
||||
if(leader == *itor) {
|
||||
leader_combo_->set_selected(leader_index);
|
||||
return;
|
||||
}
|
||||
++leader_index;
|
||||
}
|
||||
}
|
||||
|
||||
void leader_list_manager::set_gender(const std::string& gender)
|
||||
{
|
||||
if(gender_combo_ == NULL)
|
||||
return;
|
||||
|
||||
int gender_index = 0;
|
||||
for(std::vector<std::string>::const_iterator itor = gender_ids_.begin();
|
||||
itor != gender_ids_.end(); ++itor) {
|
||||
if(gender == *itor) {
|
||||
gender_combo_->set_selected(gender_index);
|
||||
return;
|
||||
}
|
||||
++gender_index;
|
||||
}
|
||||
}
|
||||
|
||||
std::string leader_list_manager::get_leader() const
|
||||
{
|
||||
if(leader_combo_ == NULL)
|
||||
return _("?");
|
||||
|
||||
if(leaders_.empty())
|
||||
return "random";
|
||||
|
||||
if(size_t(leader_combo_->selected()) >= leaders_.size())
|
||||
return _("?");
|
||||
|
||||
return leaders_[leader_combo_->selected()];
|
||||
}
|
||||
|
||||
std::string leader_list_manager::get_gender() const
|
||||
{
|
||||
if(gender_combo_ == NULL || genders_.empty() || size_t(gender_combo_->selected()) >= genders_.size())
|
||||
return "null";
|
||||
return gender_ids_[gender_combo_->selected()];
|
||||
}
|
||||
|
||||
#ifdef LOW_MEM
|
||||
std::string leader_list_manager::get_RC_suffix(const std::string& /*unit_color*/) const {
|
||||
return "";
|
||||
}
|
||||
#else
|
||||
std::string leader_list_manager::get_RC_suffix(const std::string& unit_color) const {
|
||||
return "~RC("+unit_color+">"+lexical_cast<std::string>(color_+1) +")";
|
||||
}
|
||||
#endif
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2007 - 2013
|
||||
Part of 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 2
|
||||
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.
|
||||
*/
|
||||
|
||||
/** @file */
|
||||
|
||||
#ifndef LEADER_LIST_HPP_INCLUDED
|
||||
#define LEADER_LIST_HPP_INCLUDED
|
||||
|
||||
namespace gui { class combo; }
|
||||
|
||||
#include "unit_types.hpp"
|
||||
|
||||
class leader_list_manager
|
||||
{
|
||||
public:
|
||||
static const std::string random_enemy_picture;
|
||||
|
||||
leader_list_manager(gui::combo* leader_combo = NULL,
|
||||
gui::combo* gender_combo = NULL);
|
||||
|
||||
void init_combos(gui::combo* leader_combo, gui::combo* gender_combo);
|
||||
void set_side_list(const std::vector<const config *> &side_list);
|
||||
void set_leader_combo(gui::combo* combo);
|
||||
void set_gender_combo(gui::combo* combo);
|
||||
void update_leader_list(int side);
|
||||
void update_gender_list(const std::string& leader);
|
||||
std::string get_leader() const;
|
||||
std::string get_gender() const;
|
||||
void set_leader(const std::string& leader);
|
||||
void set_gender(const std::string& gender);
|
||||
void set_color(int color) {color_ = color;};
|
||||
std::string get_RC_suffix(const std::string& unit_color) const;
|
||||
|
||||
private:
|
||||
void populate_leader_combo(int selected_index);
|
||||
std::vector<std::string> leaders_;
|
||||
std::vector<std::string> genders_;
|
||||
std::vector<std::string> gender_ids_;
|
||||
std::vector<const config *> side_list_;
|
||||
gui::combo* leader_combo_;
|
||||
gui::combo* gender_combo_;
|
||||
int color_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -382,60 +382,16 @@ void connect::side::update_faction_combo()
|
|||
|
||||
void connect::side::update_leader_combo()
|
||||
{
|
||||
std::vector<std::string> leaders;
|
||||
BOOST_FOREACH(const std::string& leader, engine_->choosable_leaders()) {
|
||||
const unit_type* unit = unit_types.find(leader);
|
||||
if (unit) {
|
||||
leaders.push_back(IMAGE_PREFIX + unit->image() +
|
||||
get_RC_suffix(unit->flag_rgb()) + COLUMN_SEPARATOR +
|
||||
unit->type_name());
|
||||
} else if (leader == "random") {
|
||||
leaders.push_back(IMAGE_PREFIX + random_enemy_picture +
|
||||
COLUMN_SEPARATOR + _("Random"));
|
||||
} else if (leader == "null") {
|
||||
leaders.push_back(utils::unicode_em_dash);
|
||||
} else {
|
||||
leaders.push_back("?");
|
||||
}
|
||||
}
|
||||
|
||||
combo_leader_.enable(leaders.size() > 1 && !parent_->params_.saved_game);
|
||||
|
||||
combo_leader_.set_items(leaders);
|
||||
combo_leader_.set_selected(engine_->current_leader_index());
|
||||
reset_leader_combo(&combo_leader_, engine_->choosable_leaders(),
|
||||
engine_->current_leader(), engine_->color(),
|
||||
parent_->params_.saved_game);
|
||||
}
|
||||
|
||||
void connect::side::update_gender_combo()
|
||||
{
|
||||
const unit_type* unit = unit_types.find(engine_->current_leader());
|
||||
|
||||
std::vector<std::string> genders;
|
||||
BOOST_FOREACH(const std::string& gender, engine_->choosable_genders()) {
|
||||
if (gender == unit_race::s_female || gender == unit_race::s_male) {
|
||||
if (unit) {
|
||||
const unit_type& gender_unit =
|
||||
unit->get_gender_unit_type(gender);
|
||||
|
||||
std::string gender_name = (gender == unit_race::s_female) ?
|
||||
_("Female ♀") : _("Male ♂");
|
||||
genders.push_back(IMAGE_PREFIX + gender_unit.image() +
|
||||
get_RC_suffix(gender_unit.flag_rgb()) + COLUMN_SEPARATOR +
|
||||
gender_name);
|
||||
}
|
||||
} else if (gender == "random") {
|
||||
genders.push_back(IMAGE_PREFIX + random_enemy_picture +
|
||||
COLUMN_SEPARATOR + _("Random"));
|
||||
} else if (gender == "null") {
|
||||
genders.push_back(utils::unicode_em_dash);
|
||||
} else {
|
||||
genders.push_back("?");
|
||||
}
|
||||
}
|
||||
|
||||
combo_gender_.enable(genders.size() > 1 && !parent_->params_.saved_game);
|
||||
|
||||
combo_gender_.set_items(genders);
|
||||
combo_gender_.set_selected(engine_->current_gender_index());
|
||||
reset_gender_combo(&combo_gender_, engine_->choosable_genders(),
|
||||
engine_->current_leader(), engine_->current_gender(),
|
||||
engine_->color(), parent_->params_.saved_game);
|
||||
}
|
||||
|
||||
void connect::side::update_controller_ui()
|
||||
|
@ -462,21 +418,6 @@ void connect::side::update_controller_ui()
|
|||
hide_ai_algorithm_combo(parent_->hidden());
|
||||
}
|
||||
|
||||
#ifdef LOW_MEM
|
||||
std::string connect::side::get_RC_suffix(
|
||||
const std::string& /*unit_color*/) const {
|
||||
|
||||
return "";
|
||||
}
|
||||
#else
|
||||
std::string connect::side::get_RC_suffix(
|
||||
const std::string& unit_color) const {
|
||||
|
||||
return "~RC(" + unit_color + ">" +
|
||||
lexical_cast<std::string>(engine_->color() + 1) + ")";
|
||||
}
|
||||
#endif
|
||||
|
||||
connect::connect(game_display& disp, const config& game_config,
|
||||
chat& c, config& gamelist, const mp_game_settings& params,
|
||||
bool local_players_only, bool first_scenario) :
|
||||
|
|
|
@ -67,7 +67,6 @@ public:
|
|||
void update_leader_combo();
|
||||
void update_gender_combo();
|
||||
void update_controller_ui();
|
||||
std::string get_RC_suffix(const std::string& unit_color) const;
|
||||
|
||||
// The mp::connect widget owning this mp::connect::side.
|
||||
connect* parent_;
|
||||
|
|
|
@ -1182,34 +1182,6 @@ int side_engine::current_faction_index() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
int side_engine::current_leader_index() const
|
||||
{
|
||||
int index = 0;
|
||||
BOOST_FOREACH(const std::string& leader, choosable_leaders_) {
|
||||
if (current_leader_ == leader) {
|
||||
return index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int side_engine::current_gender_index() const
|
||||
{
|
||||
int index = 0;
|
||||
BOOST_FOREACH(const std::string& gender, choosable_genders_) {
|
||||
if (current_gender_ == gender) {
|
||||
return index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void side_engine::set_faction_commandline(const std::string& faction_name)
|
||||
{
|
||||
BOOST_FOREACH(const config* faction, choosable_factions_) {
|
||||
|
|
|
@ -154,8 +154,6 @@ public:
|
|||
void set_current_gender(const std::string& current_gender);
|
||||
|
||||
int current_faction_index() const;
|
||||
int current_leader_index() const;
|
||||
int current_gender_index() const;
|
||||
|
||||
// Game set up from command line helpers.
|
||||
void set_faction_commandline(const std::string& faction_name);
|
||||
|
@ -173,6 +171,7 @@ public:
|
|||
{ return choosable_genders_; }
|
||||
const config& cfg() const { return cfg_; }
|
||||
const std::string& current_leader() const { return current_leader_; }
|
||||
const std::string& current_gender() const { return current_gender_; }
|
||||
controller mp_controller() const { return mp_controller_; }
|
||||
void set_mp_controller(controller mp_controller)
|
||||
{ mp_controller_ = mp_controller; }
|
||||
|
|
|
@ -46,7 +46,6 @@ static lg::log_domain log_network("network");
|
|||
#define ERR_NW LOG_STREAM(err, log_network)
|
||||
|
||||
namespace {
|
||||
|
||||
/** The maximum number of messages in the chat history. */
|
||||
const size_t max_messages = 256;
|
||||
|
||||
|
@ -834,7 +833,8 @@ const gui::label& ui::title() const
|
|||
return title_;
|
||||
}
|
||||
|
||||
int find_suitable_faction(faction_list const &fl, const config &cfg)
|
||||
int find_suitable_faction(const std::vector<const config*> &fl,
|
||||
const config &cfg)
|
||||
{
|
||||
std::vector<std::string> find;
|
||||
std::string search_field;
|
||||
|
@ -935,7 +935,7 @@ std::vector<std::string> init_choosable_leaders(const config& side,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (map_settings && side.has_attribute("type")) {
|
||||
if (map_settings && !side["type"].empty() && side["type"] != "null") {
|
||||
// Leader was explicitly assigned.
|
||||
const unit_type *unit = unit_types.find(side["type"]);
|
||||
if (unit) {
|
||||
|
@ -1025,6 +1025,102 @@ std::vector<std::string> init_choosable_genders(const config& side,
|
|||
return choosable_genders;
|
||||
}
|
||||
|
||||
void reset_leader_combo(gui::combo* combo_leader,
|
||||
const std::vector<std::string>& choosable_leaders,
|
||||
const std::string& current_leader, const int color, const bool saved_game)
|
||||
{
|
||||
std::vector<std::string> leaders;
|
||||
BOOST_FOREACH(const std::string& leader, choosable_leaders) {
|
||||
const unit_type* unit = unit_types.find(leader);
|
||||
if (unit) {
|
||||
leaders.push_back(IMAGE_PREFIX + unit->image() +
|
||||
get_RC_suffix(unit->flag_rgb(), color) +
|
||||
COLUMN_SEPARATOR + unit->type_name());
|
||||
} else if (leader == "random") {
|
||||
leaders.push_back(IMAGE_PREFIX + random_enemy_picture +
|
||||
COLUMN_SEPARATOR + _("Random"));
|
||||
} else if (leader == "null") {
|
||||
leaders.push_back(utils::unicode_em_dash);
|
||||
} else {
|
||||
leaders.push_back("?");
|
||||
}
|
||||
}
|
||||
|
||||
combo_leader->enable(leaders.size() > 1 && !saved_game);
|
||||
|
||||
combo_leader->set_items(leaders);
|
||||
combo_leader->set_selected(current_leader_index(current_leader,
|
||||
choosable_leaders));
|
||||
}
|
||||
|
||||
void reset_gender_combo(gui::combo* combo_gender,
|
||||
const std::vector<std::string>& choosable_genders,
|
||||
const std::string& current_leader, const std::string& current_gender,
|
||||
const int color, const bool saved_game)
|
||||
{
|
||||
const unit_type* unit = unit_types.find(current_leader);
|
||||
|
||||
std::vector<std::string> genders;
|
||||
BOOST_FOREACH(const std::string& gender, choosable_genders) {
|
||||
if (gender == unit_race::s_female || gender == unit_race::s_male) {
|
||||
if (unit) {
|
||||
const unit_type& gender_unit =
|
||||
unit->get_gender_unit_type(gender);
|
||||
|
||||
std::string gender_name = (gender == unit_race::s_female) ?
|
||||
_("Female ♀") : _("Male ♂");
|
||||
genders.push_back(IMAGE_PREFIX + gender_unit.image() +
|
||||
get_RC_suffix(gender_unit.flag_rgb(), color) +
|
||||
COLUMN_SEPARATOR + gender_name);
|
||||
}
|
||||
} else if (gender == "random") {
|
||||
genders.push_back(IMAGE_PREFIX + random_enemy_picture +
|
||||
COLUMN_SEPARATOR + _("Random"));
|
||||
} else if (gender == "null") {
|
||||
genders.push_back(utils::unicode_em_dash);
|
||||
} else {
|
||||
genders.push_back("?");
|
||||
}
|
||||
}
|
||||
|
||||
combo_gender->enable(genders.size() > 1 && !saved_game);
|
||||
|
||||
combo_gender->set_items(genders);
|
||||
combo_gender->set_selected(current_gender_index(current_gender,
|
||||
choosable_genders));
|
||||
}
|
||||
|
||||
|
||||
int current_leader_index(const std::string& current_leader,
|
||||
const std::vector<std::string>& choosable_leaders)
|
||||
{
|
||||
int index = 0;
|
||||
BOOST_FOREACH(const std::string& leader, choosable_leaders) {
|
||||
if (current_leader == leader) {
|
||||
return index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int current_gender_index(const std::string& current_gender,
|
||||
const std::vector<std::string>& choosable_genders)
|
||||
{
|
||||
int index = 0;
|
||||
BOOST_FOREACH(const std::string& gender, choosable_genders) {
|
||||
if (current_gender == gender) {
|
||||
return index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void append_leaders_from_faction(const config* faction,
|
||||
std::vector<std::string>& leaders)
|
||||
{
|
||||
|
@ -1035,4 +1131,17 @@ void append_leaders_from_faction(const config* faction,
|
|||
}
|
||||
|
||||
|
||||
#ifdef LOW_MEM
|
||||
std::string get_RC_suffix(const std::string&, const int)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
#else
|
||||
std::string get_RC_suffix(const std::string& unit_color, const int color)
|
||||
{
|
||||
return "~RC(" + unit_color + ">" + lexical_cast<std::string>(color + 1) +
|
||||
")";
|
||||
}
|
||||
#endif
|
||||
|
||||
}// namespace mp
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "hotkeys.hpp"
|
||||
#include "network.hpp"
|
||||
#include "preferences_display.hpp"
|
||||
#include "widgets/combo.hpp"
|
||||
#include "widgets/label.hpp"
|
||||
#include "widgets/menu.hpp"
|
||||
#include "widgets/textbox.hpp"
|
||||
|
@ -33,6 +34,8 @@ namespace mp {
|
|||
|
||||
enum controller { CNTR_NETWORK = 0, CNTR_LOCAL, CNTR_COMPUTER, CNTR_EMPTY, CNTR_RESERVED, CNTR_LAST };
|
||||
|
||||
const std::string random_enemy_picture("units/random-dice.png");
|
||||
|
||||
void check_response(network::connection res, const config& data);
|
||||
|
||||
void level_to_gamestate(config& level, game_state& state);
|
||||
|
@ -270,27 +273,48 @@ private:
|
|||
};
|
||||
};
|
||||
|
||||
typedef std::vector<const config *> faction_list;
|
||||
/** Picks the first faction with the greater amount of data matching the criteria. */
|
||||
int find_suitable_faction(faction_list const &fl, const config &side);
|
||||
/**
|
||||
* Picks the first faction with the greater amount of data
|
||||
* matching the criteria.
|
||||
*/
|
||||
int find_suitable_faction(const std::vector<const config*> &fl,
|
||||
const config &side);
|
||||
|
||||
/**
|
||||
* Returns the lists for factions, leaders and genders.
|
||||
*/
|
||||
std::vector<const config*> init_available_factions(
|
||||
std::vector<const config*> era_sides, const config& side);
|
||||
|
||||
std::vector<const config*> init_choosable_factions(
|
||||
std::vector<const config*> available_factions, const config& side,
|
||||
const bool map_settings);
|
||||
|
||||
std::vector<std::string> init_choosable_leaders(const config& side,
|
||||
const config* faction, const std::vector<const config*> available_factions,
|
||||
const bool map_settings, const bool saved_game);
|
||||
|
||||
std::vector<std::string> init_choosable_genders(const config& side,
|
||||
const std::string& leader, const bool map_settings, const bool saved_game);
|
||||
|
||||
/**
|
||||
* Updates combos for leaders and genders.
|
||||
*/
|
||||
void reset_leader_combo(gui::combo* combo_leader,
|
||||
const std::vector<std::string>& choosable_leaders,
|
||||
const std::string& current_leader, const int color, const bool saved_game);
|
||||
void reset_gender_combo(gui::combo* combo_gender,
|
||||
const std::vector<std::string>& choosable_genders,
|
||||
const std::string& current_leader, const std::string& current_gender,
|
||||
const int color, const bool saved_game);
|
||||
|
||||
int current_leader_index(const std::string& current_leader,
|
||||
const std::vector<std::string>& choosable_leaders);
|
||||
int current_gender_index(const std::string& current_gender,
|
||||
const std::vector<std::string>& choosable_genders);
|
||||
|
||||
void append_leaders_from_faction(const config* faction,
|
||||
std::vector<std::string>& leaders);
|
||||
|
||||
std::string get_RC_suffix(const std::string& unit_color, const int color);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "game_preferences.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "game_display.hpp"
|
||||
#include "leader_list.hpp"
|
||||
#include "log.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "multiplayer_wait.hpp"
|
||||
|
@ -42,28 +41,68 @@ const int leader_pane_border = 10;
|
|||
namespace mp {
|
||||
|
||||
wait::leader_preview_pane::leader_preview_pane(game_display& disp,
|
||||
const std::vector<const config *> &side_list, int color) :
|
||||
const std::vector<const config*>& available_factions,
|
||||
const std::vector<const config*>& choosable_factions, int color,
|
||||
const bool map_settings, const bool saved_game,
|
||||
const config& side_cfg) :
|
||||
gui::preview_pane(disp.video()),
|
||||
side_list_(side_list),
|
||||
color_(color),
|
||||
leader_combo_(disp, std::vector<std::string>()),
|
||||
gender_combo_(disp, std::vector<std::string>()),
|
||||
leaders_(&leader_combo_, &gender_combo_),
|
||||
selection_(0)
|
||||
selection_(0),
|
||||
available_factions_(available_factions),
|
||||
choosable_factions_(choosable_factions),
|
||||
choosable_leaders_(),
|
||||
choosable_genders_(),
|
||||
current_faction_(choosable_factions[0]),
|
||||
current_leader_("null"),
|
||||
current_gender_("null"),
|
||||
map_settings_(map_settings),
|
||||
saved_game_(saved_game),
|
||||
side_cfg_(side_cfg)
|
||||
{
|
||||
leaders_.set_side_list(side_list);
|
||||
leaders_.set_color(color_);
|
||||
init_leaders_and_genders();
|
||||
|
||||
set_location(leader_pane_position);
|
||||
}
|
||||
|
||||
void wait::leader_preview_pane::process_event()
|
||||
{
|
||||
if (leader_combo_.changed()) {
|
||||
current_leader_ = choosable_leaders_[leader_combo_.selected()];
|
||||
|
||||
choosable_genders_ = init_choosable_genders(side_cfg_, current_leader_,
|
||||
map_settings_, saved_game_);
|
||||
|
||||
current_gender_ = choosable_genders_[0];
|
||||
|
||||
reset_gender_combo(&gender_combo_, choosable_genders_,
|
||||
current_leader_, current_gender_, color_, saved_game_);
|
||||
|
||||
if (leader_combo_.changed() || gender_combo_.changed()) {
|
||||
leaders_.set_leader_combo(&leader_combo_);
|
||||
leaders_.update_gender_list(leaders_.get_leader());
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
if (gender_combo_.changed()) {
|
||||
current_gender_ = choosable_genders_[gender_combo_.selected()];
|
||||
|
||||
set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void wait::leader_preview_pane::init_leaders_and_genders()
|
||||
{
|
||||
choosable_leaders_ = init_choosable_leaders(side_cfg_, current_faction_,
|
||||
available_factions_, map_settings_, saved_game_);
|
||||
choosable_genders_ = init_choosable_genders(side_cfg_, current_leader_,
|
||||
map_settings_, saved_game_);
|
||||
|
||||
current_leader_ = choosable_leaders_[0];
|
||||
current_gender_ = choosable_genders_[0];
|
||||
|
||||
reset_leader_combo(&leader_combo_, choosable_leaders_,
|
||||
current_leader_, color_, saved_game_);
|
||||
reset_gender_combo(&gender_combo_, choosable_genders_,
|
||||
current_leader_, current_gender_, color_, saved_game_);
|
||||
}
|
||||
|
||||
void wait::leader_preview_pane::draw_contents()
|
||||
|
@ -79,8 +118,8 @@ void wait::leader_preview_pane::draw_contents()
|
|||
, loc.h - leader_pane_border * 2);
|
||||
const clip_rect_setter clipper(screen, &area);
|
||||
|
||||
if(selection_ < side_list_.size()) {
|
||||
const config& side = *side_list_[selection_];
|
||||
if(selection_ < choosable_factions_.size()) {
|
||||
const config& side = *choosable_factions_[selection_];
|
||||
std::string faction = side["faction"];
|
||||
|
||||
const std::string recruits = side["recruit"];
|
||||
|
@ -92,17 +131,15 @@ void wait::leader_preview_pane::draw_contents()
|
|||
if(p != std::string::npos && p < faction.size())
|
||||
faction = faction.substr(p+1);
|
||||
}
|
||||
std::string leader = leaders_.get_leader();
|
||||
std::string gender = leaders_.get_gender();
|
||||
|
||||
std::string image;
|
||||
|
||||
const unit_type *ut = unit_types.find(leader);
|
||||
const unit_type *ut = unit_types.find(current_leader_);
|
||||
|
||||
if (ut) {
|
||||
const unit_type &utg = ut->get_gender_unit_type(gender);
|
||||
const unit_type &utg = ut->get_gender_unit_type(current_gender_);
|
||||
|
||||
image = utg.image() + leaders_.get_RC_suffix(utg.flag_rgb());
|
||||
image = utg.image() + get_RC_suffix(utg.flag_rgb(), color_);
|
||||
}
|
||||
|
||||
for(std::vector<std::string>::const_iterator itor = recruit_list.begin();
|
||||
|
@ -151,19 +188,24 @@ bool wait::leader_preview_pane::left_side() const
|
|||
void wait::leader_preview_pane::set_selection(int selection)
|
||||
{
|
||||
selection_ = selection;
|
||||
leaders_.update_leader_list(selection_);
|
||||
leaders_.update_gender_list(leaders_.get_leader());
|
||||
set_dirty();
|
||||
|
||||
if ((size_t)selection < choosable_factions_.size()) {
|
||||
current_faction_ = choosable_factions_[selection];
|
||||
|
||||
init_leaders_and_genders();
|
||||
|
||||
set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
std::string wait::leader_preview_pane::get_selected_leader()
|
||||
{
|
||||
return leaders_.get_leader();
|
||||
return current_leader_;
|
||||
}
|
||||
|
||||
std::string wait::leader_preview_pane::get_selected_gender()
|
||||
{
|
||||
return leaders_.get_gender();
|
||||
return current_gender_;
|
||||
}
|
||||
|
||||
handler_vector wait::leader_preview_pane::handler_members() {
|
||||
|
@ -269,20 +311,23 @@ void wait::join_game(bool observe)
|
|||
if (!color_str.empty())
|
||||
color = game_config::color_info(color_str).index() - 1;
|
||||
|
||||
std::vector<const config *> leader_sides;
|
||||
std::vector<const config*> choosable_factions;
|
||||
BOOST_FOREACH(const config &side, possible_sides) {
|
||||
leader_sides.push_back(&side);
|
||||
choosable_factions.push_back(&side);
|
||||
}
|
||||
|
||||
const bool use_map_settings =
|
||||
const bool map_settings =
|
||||
level_.child("multiplayer")["mp_use_map_settings"].to_bool();
|
||||
const bool saved_game =
|
||||
level_.child("multiplayer")["savegame"].to_bool();
|
||||
|
||||
leader_sides = init_choosable_factions(
|
||||
init_available_factions(leader_sides, *side_choice),
|
||||
*side_choice, use_map_settings);
|
||||
std::vector<const config*> available_factions =
|
||||
init_available_factions(choosable_factions, *side_choice);
|
||||
choosable_factions = init_choosable_factions(available_factions,
|
||||
*side_choice, map_settings);
|
||||
|
||||
std::vector<std::string> choices;
|
||||
BOOST_FOREACH(const config *s, leader_sides)
|
||||
BOOST_FOREACH(const config *s, choosable_factions)
|
||||
{
|
||||
const config &side = *s;
|
||||
const std::string &name = side["name"];
|
||||
|
@ -301,7 +346,9 @@ void wait::join_game(bool observe)
|
|||
}
|
||||
|
||||
std::vector<gui::preview_pane* > preview_panes;
|
||||
leader_preview_pane leader_selector(disp(), leader_sides, color);
|
||||
leader_preview_pane leader_selector(disp(), available_factions,
|
||||
choosable_factions, color, map_settings, saved_game,
|
||||
*side_choice);
|
||||
preview_panes.push_back(&leader_selector);
|
||||
|
||||
const int faction_choice = gui::show_dialog(disp(), NULL,
|
||||
|
@ -318,7 +365,7 @@ void wait::join_game(bool observe)
|
|||
config faction;
|
||||
config& change = faction.add_child("change_faction");
|
||||
change["name"] = preferences::login();
|
||||
change["faction"] = (*leader_sides[faction_choice])["id"];
|
||||
change["faction"] = (*choosable_factions[faction_choice])["id"];
|
||||
change["leader"] = leader_choice;
|
||||
change["gender"] = gender_choice;
|
||||
network::send_data(faction, 0);
|
||||
|
@ -485,7 +532,7 @@ void wait::generate_menu()
|
|||
leader_image = utg.image() + std::string("~RC(") + utg.flag_rgb() + ">" + RCcolor + ")";
|
||||
#endif
|
||||
} else {
|
||||
leader_image = leader_list_manager::random_enemy_picture;
|
||||
leader_image = random_enemy_picture;
|
||||
}
|
||||
if (!leader_image.empty()) {
|
||||
// Dumps the "image" part of the faction name, if any,
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include "widgets/combo.hpp"
|
||||
|
||||
#include "leader_list.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
#include "multiplayer_ui.hpp"
|
||||
#include "show_dialog.hpp"
|
||||
|
@ -46,7 +45,10 @@ private:
|
|||
{
|
||||
public:
|
||||
leader_preview_pane(game_display& disp,
|
||||
const std::vector<const config *> &side_list, int color);
|
||||
const std::vector<const config*>& available_factions,
|
||||
const std::vector<const config*>& choosable_factions, int color,
|
||||
const bool map_settings, const bool saved_game,
|
||||
const config& side_cfg);
|
||||
|
||||
bool show_above() const;
|
||||
bool left_side() const;
|
||||
|
@ -59,12 +61,28 @@ private:
|
|||
virtual void draw_contents();
|
||||
virtual void process_event();
|
||||
|
||||
std::vector<const config *> side_list_;
|
||||
void init_leaders_and_genders();
|
||||
|
||||
const int color_;
|
||||
gui::combo leader_combo_; // Must appear before the leader_list_manager
|
||||
gui::combo gender_combo_; // Must appear before the leader_list_manager
|
||||
leader_list_manager leaders_;
|
||||
gui::combo leader_combo_;
|
||||
gui::combo gender_combo_;
|
||||
size_t selection_;
|
||||
|
||||
// All factions which could be played by a side (including Random).
|
||||
const std::vector<const config*>& available_factions_;
|
||||
|
||||
const std::vector<const config*>& choosable_factions_;
|
||||
std::vector<std::string> choosable_leaders_;
|
||||
std::vector<std::string> choosable_genders_;
|
||||
|
||||
const config* current_faction_;
|
||||
std::string current_leader_;
|
||||
std::string current_gender_;
|
||||
|
||||
const bool map_settings_;
|
||||
const bool saved_game_;
|
||||
|
||||
const config& side_cfg_;
|
||||
};
|
||||
|
||||
void generate_menu();
|
||||
|
|
Loading…
Add table
Reference in a new issue