MP Staging: improvements to team change behavior

* Selecting the same team a side is already on now has no effect (bug #25560).
* Side nodes will always be sorted by index in each team group.
* Also fixes a few comment typos.
This commit is contained in:
Charles Dang 2017-03-08 01:08:47 +11:00
parent fc3757f3f6
commit b5113f48f1

View file

@ -143,7 +143,7 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
item["label"] = std::to_string(side->index() + 1);
data.emplace("side_number", item);
// TODO: don't hardcode meganta?
// TODO: don't hardcode magenta?
item["label"] = "units/unknown-unit.png~RC(magenta>" + std::to_string(side->color() + 1) + ")";
data.emplace("leader_image", item);
@ -164,8 +164,17 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
team_tree_map_[side->team_name()] = &team_node;
}
// Find an appropriate position to insert this node. This ensures the side nodes are always
// arranged by descending index order in each team group.
int position = 0;
for(const auto& side_engine : connect_engine_.side_engines()) {
if(side->team() == side_engine->team() && side->index() > side_engine->index()) {
++position;
}
}
// Must be *after* the above if block, or the node ptr could be invalid
tree_view_node& node = team_tree_map_[side->team_name()]->add_child("side_panel", data);
tree_view_node& node = team_tree_map_[side->team_name()]->add_child("side_panel", data, position);
side_tree_map_[side] = &node;
@ -348,6 +357,10 @@ void mp_staging::on_color_select(ng::side_engine_ptr side, grid& row_grid)
void mp_staging::on_team_select(window& window, ng::side_engine_ptr side, menu_button& team_menu, bool& handled, bool& halt)
{
if(static_cast<int>(team_menu.get_value()) == side->team()) {
return;
}
side->set_team(team_menu.get_value());
// First, remove the node from the tree
@ -457,10 +470,10 @@ void mp_staging::network_handler(window& window)
// TODO: why is this needed...
const bool was_able_to_start = connect_engine_.can_start_game();
bool quit_signal_recieved;
std::tie(quit_signal_recieved, std::ignore) = connect_engine_.process_network_data(data);
bool quit_signal_received;
std::tie(quit_signal_received, std::ignore) = connect_engine_.process_network_data(data);
if(quit_signal_recieved) {
if(quit_signal_received) {
window.set_retval(window::CANCEL);
}