Skip to content

Commit

Permalink
MP Staging: colorize color choice text
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Oct 8, 2016
1 parent a2b7972 commit 53a60f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/game_initialization/multiplayer_ui.cpp
Expand Up @@ -16,6 +16,7 @@

#include "construct_dialog.hpp"
#include "video.hpp"
#include "formatter.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "gui/dialogs/multiplayer/mp_cmd_wrapper.hpp"
Expand Down Expand Up @@ -100,6 +101,22 @@ std::string get_color_string(const std::string& id)
return rgb2highlight(has_color ? i_color->second.mid() : 0x00FF0000) + (has_name ? std::string(i_name->second) : _("Invalid Color"));
}

// TODO: should probably move this somewhere more general
std::string get_color_string_pango(const std::string& id)
{
const auto color = game_config::team_rgb_colors.find(id);
const auto name = game_config::team_rgb_name.find(id);

const bool has_color = color != game_config::team_rgb_colors.end();
const bool has_name = name != game_config::team_rgb_name.end();

if(has_color && has_name) {
return formatter() << "<span color='" << rgb2highlight_pango(color->second[0]) << "'>" << name->second << "</span>";
}

return _("Invalid Color");
}

chat::chat() :
message_history_(),
last_update_()
Expand Down
1 change: 1 addition & 0 deletions src/game_initialization/multiplayer_ui.hpp
Expand Up @@ -36,6 +36,7 @@ namespace mp {

std::string get_color_string(int id);
std::string get_color_string(const std::string& id);
std::string get_color_string_pango(const std::string& id);

/** this class memorizes a chat session. */
class chat
Expand Down
12 changes: 4 additions & 8 deletions src/gui/dialogs/multiplayer/mp_staging.cpp
Expand Up @@ -188,22 +188,18 @@ void tmp_staging::pre_show(twindow& window)
// Colors
//
std::vector<config> color_options;
for(const auto& color : side.get_colors()) {
// BIG FAT TODO: get rid of the hardcoded GUI1 formatting and do something about this hideous string manipulation
const std::string c = color.substr(color.find_first_of(">") + 1);
std::string cid = c;
cid[0] = std::tolower(cid[0]);

for(const auto& color : side.get_colors_pango()) {
color_options.push_back(config_of
("label", c)
("icon", (formatter() << "misc/status.png~RC(magenta>" << cid << ")").str())
("label", color.second)
("icon", (formatter() << "misc/status.png~RC(magenta>" << color.first << ")").str())
);
}

tmenu_button& color_selection = find_widget<tmenu_button>(&row_grid, "side_color", false);

color_selection.set_values(color_options, side.color());
color_selection.set_active(!saved_game);
color_selection.set_use_markup(true);
color_selection.connect_click_handler(std::bind(&tmp_staging::on_color_select, this, std::ref(side), std::ref(row_grid)));

//
Expand Down

0 comments on commit 53a60f1

Please sign in to comment.