Move certain text constants into the constants file

This commit is contained in:
Charles Dang 2016-10-16 22:04:07 +11:00
parent b5d6186ea2
commit ebc8ddfb78
26 changed files with 76 additions and 66 deletions

View file

@ -186,7 +186,7 @@ addon_op_result do_resolve_addon_dependencies(CVideo& v, addons_client& client,
broken_deps_report += "\n";
for(const std::string& broken_dep_id : broken_deps) {
broken_deps_report += "\n " + utils::unicode_bullet + " " + make_addon_title(broken_dep_id);
broken_deps_report += "\n " + font::unicode_bullet + " " + make_addon_title(broken_dep_id);
}
if(gui2::show_message(v, _("Broken Dependencies"), broken_deps_report, gui2::tmessage::yes_no_buttons) != gui2::twindow::OK) {

View file

@ -199,7 +199,7 @@ void terrain_palette::draw_item(const t_translation::t_terrain& terrain,
tooltip_text << map().get_terrain_editor_string(terrain);
if (gui_.get_draw_terrain_codes()) {
tooltip_text << " " + utils::unicode_em_dash + " " << terrain;
tooltip_text << " " + font::unicode_em_dash + " " << terrain;
}
}

View file

@ -49,4 +49,17 @@ CONSTEXPR int
CONSTEXPR size_t max_text_line_width = 4096;
const std::string
ellipsis = "...",
unicode_minus = "-",
unicode_en_dash = "",
unicode_em_dash = "",
unicode_figure_dash = "?",
unicode_multiplication_sign = "×",
unicode_bullet = "",
weapon_numbers_sep = "×",
weapon_details_sep = "";
} // end namespace font

View file

@ -14,9 +14,11 @@
#pragma once
#include <SDL.h>
#include "global.hpp"
#include <SDL.h>
#include <string>
namespace font {
//various standard colors
@ -40,4 +42,18 @@ CONSTEXPR inline int relative_size(int size)
// GUI1 built-in maximum
extern CONSTEXPR size_t max_text_line_width;
// String constants
extern const std::string
ellipsis,
unicode_minus,
unicode_en_dash,
unicode_em_dash,
unicode_figure_dash,
unicode_multiplication_sign,
unicode_bullet,
weapon_numbers_sep,
weapon_details_sep;
} // end namespace font

View file

@ -189,7 +189,7 @@ std::string scenario::map_size() const
if (map_.get() != nullptr) {
map_size << map_.get()->w();
map_size << utils::unicode_multiplication_sign;
map_size << font::unicode_multiplication_sign;
map_size << map_.get()->h();
} else {
map_size << _("not available.");

View file

@ -156,7 +156,7 @@ void flg_manager::reset_leader_combo(gui::combo& combo_leader, const std::string
leaders.push_back(IMAGE_PREFIX + random_enemy_picture +
COLUMN_SEPARATOR + _("Random"));
} else if (leader == "null") {
leaders.push_back(utils::unicode_em_dash);
leaders.push_back(font::unicode_em_dash);
} else {
leaders.push_back("?");
}
@ -189,7 +189,7 @@ void flg_manager::reset_gender_combo(gui::combo& combo_gender, const std::string
genders.push_back(IMAGE_PREFIX + random_enemy_picture +
COLUMN_SEPARATOR + _("Random"));
} else if (gender == "null") {
genders.push_back(utils::unicode_em_dash);
genders.push_back(font::unicode_em_dash);
} else {
genders.push_back("?");
}

View file

@ -618,7 +618,7 @@ void gamebrowser::populate_game_item_map_info(gamebrowser::game_item & item, con
// Parsing the map and generating the minimap are both cpu expensive
gamemap map(std::make_shared<terrain_type_data>(game_config), item.map_data);
item.mini_map = image::getMinimap(minimap_size_, minimap_size_, map, 0);
item.map_info_size = std::to_string(map.w()) + utils::unicode_multiplication_sign
item.map_info_size = std::to_string(map.w()) + font::unicode_multiplication_sign
+ std::to_string(map.h());
}
} catch (incorrect_map_format_error &e) {

View file

@ -50,7 +50,7 @@ std::string format_addon_time(time_t time)
}
}
return utils::unicode_em_dash;
return font::unicode_em_dash;
}
std::string langcode_to_string(const std::string& lcode)

View file

@ -468,7 +468,7 @@ static std::string format_addon_time(time_t time)
}
}
return utils::unicode_em_dash;
return font::unicode_em_dash;
}
void taddon_list::on_addon_select(twindow& window)

View file

@ -293,7 +293,7 @@ game_info::game_info(const config& game, const config& game_config, const std::v
// mini_map = image::getMinimap(minimap_size_, minimap_size_, map,
// 0);
std::ostringstream msi;
msi << map.w() << utils::unicode_multiplication_sign << map.h();
msi << map.w() << font::unicode_multiplication_sign << map.h();
map_size_info = msi.str();
info_stream << "" + map_size_info;
} catch(incorrect_map_format_error& e) {
@ -391,7 +391,7 @@ game_info::game_info(const config& game, const config& game_config, const std::v
}
// Remove any newlines that might have been in game titles
boost::replace_all(scenario, "\n", " " + utils::unicode_em_dash + " ");
boost::replace_all(scenario, "\n", " " + font::unicode_em_dash + " ");
if(reloaded) {
info_stream << "";

View file

@ -138,7 +138,7 @@ void tfaction_select::on_faction_select(twindow& window)
} else if(leader == "random") {
leaders.push_back(config_of("label", _("Random"))("icon", "units/random-dice.png"));
} else if(leader == "null") {
leaders.push_back(config_of("label", utils::unicode_em_dash));
leaders.push_back(config_of("label", font::unicode_em_dash));
} else {
leaders.push_back(config_of("label", "?"));
}

View file

@ -607,7 +607,7 @@ void tmp_create_game::update_details(twindow& window)
// Set the title, with newlines replaced. Newlines are sometimes found in SP Campaign names
std::string title = create_engine_.current_level().name();
boost::replace_all(title, "\n", " " + utils::unicode_em_dash + " ");
boost::replace_all(title, "\n", " " + font::unicode_em_dash + " ");
find_widget<tcontrol>(&window, "game_title", false).set_label(title);
show_description(window, create_engine_.current_level().description());
@ -652,7 +652,7 @@ void tmp_create_game::update_details(twindow& window)
}
players.set_label(players_str.str());
map_size.set_label(utils::unicode_em_dash);
map_size.set_label(font::unicode_em_dash);
break;
}

View file

@ -259,7 +259,7 @@ void tmp_join_game::pre_show(twindow& window)
// Set title
//
tlabel& title = find_widget<tlabel>(&window, "title", false);
title.set_label((formatter() << title.label() << " " << utils::unicode_em_dash << " " << get_scenario()["name"].t_str()).str());
title.set_label((formatter() << title.label() << " " << font::unicode_em_dash << " " << get_scenario()["name"].t_str()).str());
//
// Set up sides list

View file

@ -79,7 +79,7 @@ void tmp_staging::pre_show(twindow& window)
// Set title and status widget states
//
tlabel& title = find_widget<tlabel>(&window, "title", false);
title.set_label((formatter() << title.label() << " " << utils::unicode_em_dash << " " << connect_engine_.scenario()["name"].t_str()).str());
title.set_label((formatter() << title.label() << " " << font::unicode_em_dash << " " << connect_engine_.scenario()["name"].t_str()).str());
update_status_label_and_buttons(window);
@ -384,8 +384,8 @@ void tmp_staging::update_leader_display(ng::side_engine_ptr side, tgrid& row_gri
const std::string current_faction = (*side->flg().choosable_factions()[side->flg().current_faction_index()])["name"];
// BIG FAT TODO: get rid of this shitty "null" string value in the FLG manager
std::string current_leader = side->flg().current_leader() != "null" ? side->flg().current_leader() : utils::unicode_em_dash;
const std::string current_gender = side->flg().current_gender() != "null" ? side->flg().current_gender() : utils::unicode_em_dash;
std::string current_leader = side->flg().current_leader() != "null" ? side->flg().current_leader() : font::unicode_em_dash;
const std::string current_gender = side->flg().current_gender() != "null" ? side->flg().current_gender() : font::unicode_em_dash;
// Sprite
std::string new_image;
@ -414,7 +414,7 @@ void tmp_staging::update_leader_display(ng::side_engine_ptr side, tgrid& row_gri
find_widget<tlabel>(&row_grid, "leader_faction", false).set_label("<span color='#a69275'>" + current_faction + "</span>");
// Gender
if(current_gender != utils::unicode_em_dash) {
if(current_gender != font::unicode_em_dash) {
const std::string gender_icon = formatter() << "icons/icon-" << current_gender << ".png";
timage& icon = find_widget<timage>(&row_grid, "leader_gender", false);

View file

@ -100,7 +100,7 @@ void tpreferences::set_resolution_list(tmenu_button& res_list, CVideo& video)
for(const auto& res : resolutions_)
{
config option;
option["label"] = formatter() << res.first << utils::unicode_multiplication_sign << res.second;
option["label"] = formatter() << res.first << font::unicode_multiplication_sign << res.second;
const int div = boost::math::gcd(res.first, res.second);
const int ratio[2] = {res.first/div, res.second/div};

View file

@ -173,7 +173,7 @@ void tunit_attack::pre_show(twindow& window)
item["label"] = attacker_stats.str();
data.emplace("attacker_weapon", item);
item["label"] = "<span color='#a69275'>" + utils::unicode_em_dash + " " + range + " " + utils::unicode_em_dash + "</span>";
item["label"] = "<span color='#a69275'>" + font::unicode_em_dash + " " + range + " " + font::unicode_em_dash + "</span>";
data.emplace("range", item);
item["label"] = defender_stats.str();

View file

@ -120,7 +120,7 @@ void tunit_list::pre_show(twindow& window)
column["label"] = format_if_leader(unit, unit->type_name());
row_data.emplace("unit_type", column);
const std::string& name = !unit->name().empty() ? format_if_leader(unit, unit->name().str()) : utils::unicode_en_dash;
const std::string& name = !unit->name().empty() ? format_if_leader(unit, unit->name().str()) : font::unicode_en_dash;
column["label"] = name;
row_data.emplace("unit_name", column);
@ -138,7 +138,7 @@ void tunit_list::pre_show(twindow& window)
std::stringstream exp_str;
exp_str << font::span_color(unit->xp_color()) << unit->experience() << "/"
<< (unit->can_advance() ? std::to_string(unit->max_experience()) : utils::unicode_en_dash) << "</span>";
<< (unit->can_advance() ? std::to_string(unit->max_experience()) : font::unicode_en_dash) << "</span>";
column["label"] = exp_str.str();
row_data.emplace("unit_experience", column);

View file

@ -203,7 +203,7 @@ void tunit_recall::pre_show(twindow& window)
column["label"] = format_cost_string(unit->recall_cost(), team_.recall_cost());
row_data.emplace("unit_recall_cost", column);
const std::string& name = !unit->name().empty() ? unit->name().str() : utils::unicode_en_dash;
const std::string& name = !unit->name().empty() ? unit->name().str() : font::unicode_en_dash;
column["label"] = name;
row_data.emplace("unit_name", column);
@ -212,7 +212,7 @@ void tunit_recall::pre_show(twindow& window)
std::stringstream exp_str;
exp_str << font::span_color(unit->xp_color()) << unit->experience() << "/"
<< (unit->can_advance() ? std::to_string(unit->max_experience()) : utils::unicode_en_dash) << "</span>";
<< (unit->can_advance() ? std::to_string(unit->max_experience()) : font::unicode_en_dash) << "</span>";
column["label"] = exp_str.str();
row_data.emplace("unit_experience", column);
@ -227,7 +227,7 @@ void tunit_recall::pre_show(twindow& window)
filter_text += " " + trait;
}
column["label"] = !traits.empty() ? traits : utils::unicode_en_dash;
column["label"] = !traits.empty() ? traits : font::unicode_en_dash;
row_data.emplace("unit_traits", column);
list.add_row(row_data);

View file

@ -518,7 +518,7 @@ std::string unit_topic_generator::operator()() const {
push_tab_pair(row, lang_weapon);
push_tab_pair(row, lang_type);
attack_ss.str(clear_stringstream);
attack_ss << attack.damage() << utils::unicode_en_dash << attack.num_attacks()
attack_ss << attack.damage() << font::unicode_en_dash << attack.num_attacks()
<< " " << attack.accuracy_parry_description();
push_tab_pair(row, attack_ss.str());
attack_ss.str(clear_stringstream);
@ -585,7 +585,7 @@ std::string unit_topic_generator::operator()() const {
std::string resist = std::to_string(resistance) + '%';
const size_t pos = resist.find('-');
if (pos != std::string::npos) {
resist.replace(pos, 1, utils::unicode_minus);
resist.replace(pos, 1, font::unicode_minus);
}
std::string color = unit_helper::resistance_color(resistance);
std::string lang_weapon = string_table["type_" + dam_it.first];
@ -690,7 +690,7 @@ std::string unit_topic_generator::operator()() const {
// A 5 MP margin; if the movement costs go above
// the unit's max moves + 5, we replace it with dashes.
if(cannot_move && (moves > type_.movement() + 5)) {
str << utils::unicode_figure_dash;
str << font::unicode_figure_dash;
} else {
str << moves;
}
@ -708,14 +708,14 @@ std::string unit_topic_generator::operator()() const {
if (has_cap) {
str << "<format>color='"<< color <<"' text='" << defense << "%'</format>";
} else {
str << "<format>color=white text='" << utils::unicode_figure_dash << "'</format>";
str << "<format>color=white text='" << font::unicode_figure_dash << "'</format>";
}
markup = str.str();
str.str(clear_stringstream);
if (has_cap) {
str << defense << '%';
} else {
str << utils::unicode_figure_dash;
str << font::unicode_figure_dash;
}
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
@ -738,7 +738,7 @@ std::string unit_topic_generator::operator()() const {
// A 5 MP margin; if the vision costs go above
// the unit's vision + 5, we replace it with dashes.
if(cannot_view && (views > type_.vision() + 5)) {
str << utils::unicode_figure_dash;
str << font::unicode_figure_dash;
} else {
str << views;
}
@ -767,7 +767,7 @@ std::string unit_topic_generator::operator()() const {
// A 5 MP margin; if the jamming costs go above
// the unit's jamming + 5, we replace it with dashes.
if ( cannot_jam && jams > type_.jamming() + 5 ) {
str << utils::unicode_figure_dash;
str << font::unicode_figure_dash;
} else {
str << jams;
}

View file

@ -60,8 +60,6 @@ const SDL_Color
unit_type_color = { 245, 230, 193, SDL_ALPHA_OPAQUE },
race_color = { 166, 146, 117, SDL_ALPHA_OPAQUE };
const std::string weapon_numbers_sep = "×", weapon_details_sep = "";
std::string::const_iterator parse_markup(std::string::const_iterator i1,
std::string::const_iterator i2,
int* font_size,

View file

@ -43,9 +43,6 @@ extern const SDL_Color weapon_color,
unit_type_color,
race_color;
// separator between damage-hits and range--type
extern const std::string weapon_numbers_sep, weapon_details_sep;
/** Parses the markup-tags at the front of a string. */
std::string::const_iterator parse_markup(std::string::const_iterator i1,
std::string::const_iterator i2,

View file

@ -622,7 +622,7 @@ static config unit_moves(reports::context & rc, const unit* u)
// A 5 MP margin; if the movement costs go above
// the unit's max moves + 5, we replace it with dashes.
if(cannot_move && (moves > u->total_movement() + 5)) {
tooltip << utils::unicode_figure_dash;
tooltip << font::unicode_figure_dash;
} else {
tooltip << moves;
}
@ -909,7 +909,7 @@ static config unit_weapons(reports::context & rc, const unit *attacker, const ma
// Total damage.
str << " " << span_color(dmg_color) << total_damage << naps << span_color(font::weapon_color)
<< utils::unicode_en_dash << num_blows
<< font::unicode_en_dash << num_blows
<< " (" << span_color(chance_color) << chance_to_hit << "%" << naps << ")"
<< naps << "\n";
@ -1309,7 +1309,7 @@ REPORT_GENERATOR(income, rc)
if (td.net_income < 0) {
td.net_income = - td.net_income;
str << span_color(font::GRAY_COLOR);
str << utils::unicode_minus;
str << font::unicode_minus;
}
else {
str << span_color(font::GRAY_COLOR);
@ -1318,7 +1318,7 @@ REPORT_GENERATOR(income, rc)
else if (td.net_income < 0) {
td.net_income = - td.net_income;
str << span_color(font::BAD_COLOR);
str << utils::unicode_minus;
str << font::unicode_minus;
}
else {
end = "";

View file

@ -35,15 +35,6 @@ static lg::log_domain log_engine("engine");
namespace utils {
const std::string ellipsis = "...";
const std::string unicode_minus = "";
const std::string unicode_en_dash = "";
const std::string unicode_em_dash = "";
const std::string unicode_figure_dash = "";
const std::string unicode_multiplication_sign = "×";
const std::string unicode_bullet = "";
bool isnewline(const char c)
{
return c == '\r' || c == '\n';
@ -526,7 +517,7 @@ bool string_bool(const std::string& str, bool def) {
std::string signed_value(int val)
{
std::ostringstream oss;
oss << (val >= 0 ? "+" : unicode_minus) << abs(val);
oss << (val >= 0 ? "+" : font::unicode_minus) << abs(val);
return oss.str();
}
@ -534,7 +525,7 @@ std::string half_signed_value(int val)
{
std::ostringstream oss;
if (val < 0)
oss << unicode_minus;
oss << font::unicode_minus;
oss << abs(val);
return oss.str();
}
@ -859,7 +850,7 @@ void ellipsis_truncate(std::string& str, const size_t size)
utf8::truncate(str, size);
if(str.length() != prev_size) {
str += ellipsis;
str += font::ellipsis;
}
}

View file

@ -16,6 +16,8 @@
#ifndef SERIALIZATION_STRING_UTILS_HPP_INCLUDED
#define SERIALIZATION_STRING_UTILS_HPP_INCLUDED
#include "font/constants.hpp"
#include <algorithm>
#include <map>
#include <set>
@ -27,13 +29,6 @@ class t_string;
namespace utils {
extern const std::string unicode_minus;
extern const std::string unicode_en_dash;
extern const std::string unicode_em_dash;
extern const std::string unicode_figure_dash;
extern const std::string unicode_multiplication_sign;
extern const std::string unicode_bullet;
bool isnewline(const char c);
bool portable_isspace(const char c);
bool notspace(char c);
@ -165,7 +160,7 @@ std::string join_map(
* @param bullet The leading bullet string.
*/
template<typename T>
std::string bullet_list(const T& v, size_t indent = 4, const std::string& bullet = unicode_bullet)
std::string bullet_list(const T& v, size_t indent = 4, const std::string& bullet = font::unicode_bullet)
{
std::ostringstream str;
@ -210,7 +205,7 @@ int apply_modifier( const int number, const std::string &amount, const int minim
/* add a "+" or replace the "-" par Unicode minus */
inline std::string print_modifier(const std::string &mod)
{ return mod[0] == '-' ?
(unicode_minus + std::string(mod.begin()+1, mod.end())) : ("+" + mod);}
(font::unicode_minus + std::string(mod.begin()+1, mod.end())) : ("+" + mod);}
/** Prepends a configurable set of characters with a backslash */
std::string escape(const std::string &str, const char *special_chars);

View file

@ -184,10 +184,10 @@ void recall::draw_hex(map_location const& hex)
unit &it = *get_unit();
int cost = statistics::un_recall_unit_cost(it);
if (cost < 0) {
number_text << utils::unicode_minus << resources::gameboard->teams().at(team_index()).recall_cost();
number_text << font::unicode_minus << resources::gameboard->teams().at(team_index()).recall_cost();
}
else {
number_text << utils::unicode_minus << cost;
number_text << font::unicode_minus << cost;
}
size_t font_size = 16;
SDL_Color color; color.r = 255; color.g = 0; color.b = 0; //red

View file

@ -152,7 +152,7 @@ void recruit::draw_hex(map_location const& hex)
const double y_offset = 0.7;
//position 0,0 in the hex is the upper left corner
std::stringstream number_text;
number_text << utils::unicode_minus << cost_;
number_text << font::unicode_minus << cost_;
size_t font_size = 16;
SDL_Color color; color.r = 255; color.g = 0; color.b = 0; //red
resources::screen->draw_text_in_hex(hex, display::LAYER_ACTIONS_NUMBERING,