Initial refactor of game_config::red_to_green and blue_to_white to use color_t
This commit is contained in:
parent
860e03c697
commit
3e0797d3a6
5 changed files with 41 additions and 51 deletions
|
@ -121,11 +121,11 @@ namespace game_config
|
|||
std::string shroud_prefix, fog_prefix;
|
||||
|
||||
std::string flag_rgb, unit_rgb;
|
||||
std::vector<uint32_t> red_green_scale;
|
||||
std::vector<uint32_t> red_green_scale_text;
|
||||
std::vector<color_t> red_green_scale;
|
||||
std::vector<color_t> red_green_scale_text;
|
||||
|
||||
static std::vector<uint32_t> blue_white_scale;
|
||||
static std::vector<uint32_t> blue_white_scale_text;
|
||||
static std::vector<color_t> blue_white_scale;
|
||||
static std::vector<color_t> blue_white_scale_text;
|
||||
|
||||
double hp_bar_scaling = 0.666;
|
||||
double xp_bar_scaling = 0.5;
|
||||
|
@ -277,37 +277,28 @@ namespace game_config
|
|||
unit_rgb = a->str();
|
||||
}
|
||||
|
||||
std::string color_string = v["red_green_scale"].str();
|
||||
if(!string2rgb(color_string, red_green_scale)) {
|
||||
ERR_NG << "can't parse color string red_green_scale, ignoring: " << color_string << std::endl;
|
||||
}
|
||||
if (red_green_scale.empty()) {
|
||||
red_green_scale.push_back(0x00FFFF00);
|
||||
}
|
||||
const auto parse_config_color_list = [&](
|
||||
const std::string& key,
|
||||
std::vector<color_t>& color_vec,
|
||||
const color_t fallback)
|
||||
{
|
||||
std::vector<std::string> temp = utils::split(v[key].str());
|
||||
|
||||
color_string = v["red_green_scale_text"].str();
|
||||
if(!string2rgb(color_string, red_green_scale_text)) {
|
||||
ERR_NG << "can't parse color string red_green_scale_text, ignoring: " << color_string << std::endl;
|
||||
}
|
||||
if (red_green_scale_text.empty()) {
|
||||
red_green_scale_text.push_back(0x00FFFF00);
|
||||
}
|
||||
for(const auto& s : temp) {
|
||||
try {
|
||||
color_vec.push_back(color_t::from_hex_string(s));
|
||||
std::cerr << key << " :" << color_vec.back() << std::endl;
|
||||
} catch(std::invalid_argument& e) {
|
||||
ERR_NG << "Error parsing color list '" << key << "'.\n" << e.what() << std::endl;
|
||||
color_vec.push_back(fallback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
color_string = v["blue_white_scale"].str();
|
||||
if(!string2rgb(color_string, blue_white_scale)) {
|
||||
ERR_NG << "can't parse color string blue_white_scale, ignoring: " << color_string << std::endl;
|
||||
}
|
||||
if (blue_white_scale.empty()) {
|
||||
blue_white_scale.push_back(0x00FFFFFF);
|
||||
}
|
||||
|
||||
color_string = v["blue_white_scale_text"].str();
|
||||
if(!string2rgb(color_string, blue_white_scale_text)) {
|
||||
ERR_NG << "can't parse color string blue_white_scale_text, ignoring: " << color_string << std::endl;
|
||||
}
|
||||
if (blue_white_scale_text.empty()) {
|
||||
blue_white_scale_text.push_back(0x00FFFFFF);
|
||||
}
|
||||
parse_config_color_list("red_green_scale", red_green_scale, {255, 255, 255, 0});
|
||||
parse_config_color_list("red_green_scale_text", red_green_scale_text, {255, 255, 255, 0});
|
||||
parse_config_color_list("blue_white_scale", blue_white_scale, {0 , 0 , 255, 0});
|
||||
parse_config_color_list("blue_white_scale_text", blue_white_scale_text, {0 , 0 , 255, 0});
|
||||
|
||||
server_list.clear();
|
||||
for (const config &server : v.child_range("server"))
|
||||
|
@ -423,16 +414,16 @@ namespace game_config
|
|||
return i->second;
|
||||
}
|
||||
|
||||
uint32_t red_to_green(int val, bool for_text){
|
||||
const std::vector<uint32_t>& color_scale =
|
||||
color_t red_to_green(int val, bool for_text){
|
||||
const std::vector<color_t>& color_scale =
|
||||
for_text ? red_green_scale_text : red_green_scale;
|
||||
val = std::max<int>(0, std::min<int>(val, 100));
|
||||
int lvl = (color_scale.size()-1) * val / 100;
|
||||
return color_scale[lvl];
|
||||
}
|
||||
|
||||
uint32_t blue_to_white(int val, bool for_text){
|
||||
const std::vector<uint32_t>& color_scale =
|
||||
color_t blue_to_white(int val, bool for_text){
|
||||
const std::vector<color_t>& color_scale =
|
||||
for_text ? blue_white_scale_text : blue_white_scale;
|
||||
val = std::max<int>(0, std::min<int>(val, 100));
|
||||
int lvl = (color_scale.size()-1) * val / 100;
|
||||
|
|
|
@ -18,6 +18,7 @@ class config;
|
|||
class version_info;
|
||||
class color_range;
|
||||
|
||||
#include "sdl/color.hpp"
|
||||
#include "tstring.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
@ -127,8 +128,8 @@ namespace game_config
|
|||
extern double hex_semi_brightening;
|
||||
|
||||
extern std::string flag_rgb, unit_rgb;
|
||||
extern std::vector<uint32_t> red_green_scale;
|
||||
extern std::vector<uint32_t> red_green_scale_text;
|
||||
extern std::vector<color_t> red_green_scale;
|
||||
extern std::vector<color_t> red_green_scale_text;
|
||||
|
||||
extern std::vector<std::string> foot_speed_prefix;
|
||||
extern std::string foot_teleport_enter, foot_teleport_exit;
|
||||
|
@ -175,8 +176,8 @@ namespace game_config
|
|||
* red_green_scale and red_green_scale_text
|
||||
*/
|
||||
|
||||
uint32_t red_to_green(int val, bool for_text = true);
|
||||
uint32_t blue_to_white(int val, bool for_text = true);
|
||||
color_t red_to_green(int val, bool for_text = true);
|
||||
color_t blue_to_white(int val, bool for_text = true);
|
||||
|
||||
extern const version_info wesnoth_version;
|
||||
extern const version_info min_savegame_version;
|
||||
|
|
|
@ -436,7 +436,7 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
std::stringstream def_text;
|
||||
def_text << def << "%";
|
||||
|
||||
color_t color = color_t::from_argb_bytes(game_config::red_to_green(def, false));
|
||||
color_t color = game_config::red_to_green(def, false);
|
||||
|
||||
// simple mark (no turn point) use smaller font
|
||||
int def_font = w->second.turns > 0 ? 18 : 16;
|
||||
|
@ -481,7 +481,7 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
std::stringstream def_text;
|
||||
def_text << def << "%";
|
||||
|
||||
color_t color = color_t::from_argb_bytes(game_config::red_to_green(def, false));
|
||||
color_t color = game_config::red_to_green(def, false);
|
||||
|
||||
// use small font
|
||||
int def_font = 16;
|
||||
|
|
|
@ -134,10 +134,8 @@ void unit_attack::pre_show(window& window)
|
|||
continue;
|
||||
}
|
||||
|
||||
const color_t a_cth_color =
|
||||
color_t::from_argb_bytes(game_config::red_to_green(attacker.chance_to_hit));
|
||||
const color_t d_cth_color =
|
||||
color_t::from_argb_bytes(game_config::red_to_green(defender.chance_to_hit));
|
||||
const color_t a_cth_color = game_config::red_to_green(attacker.chance_to_hit);
|
||||
const color_t d_cth_color = game_config::red_to_green(defender.chance_to_hit);
|
||||
|
||||
const std::string attw_name = !attacker_weapon.name().empty() ? attacker_weapon.name() : " ";
|
||||
const std::string defw_name = !defender_weapon.name().empty() ? defender_weapon.name() : " ";
|
||||
|
|
|
@ -519,7 +519,7 @@ static config unit_defense(reports::context & rc, const unit* u, const map_locat
|
|||
|
||||
const t_translation::terrain_code &terrain = map[displayed_unit_hex];
|
||||
int def = 100 - u->defense_modifier(terrain);
|
||||
color_t color = color_t::from_argb_bytes(game_config::red_to_green(def));
|
||||
color_t color = game_config::red_to_green(def);
|
||||
str << span_color(color) << def << '%' << naps;
|
||||
tooltip << _("Terrain: ") << "<b>" << map.get_terrain_info(terrain).description() << "</b>\n";
|
||||
|
||||
|
@ -535,7 +535,7 @@ static config unit_defense(reports::context & rc, const unit* u, const map_locat
|
|||
revert = false;
|
||||
} else {
|
||||
int t_def = 100 - u->defense_modifier(t);
|
||||
color_t t_color = color_t::from_argb_bytes(game_config::red_to_green(t_def));
|
||||
color_t t_color = game_config::red_to_green(t_def);
|
||||
tooltip << '\t' << map.get_terrain_info(t).description() << ": "
|
||||
<< span_color(t_color) << t_def << '%' << naps
|
||||
<< (revert ? _("maximum^max.") : _("minimum^min.")) << '\n';
|
||||
|
@ -906,7 +906,7 @@ static config unit_weapons(reports::context & rc, const unit *attacker, const ma
|
|||
<< _("Damage: ") << "<b>" << "0" << "</b>\n";
|
||||
}
|
||||
|
||||
color_t chance_color = color_t::from_argb_bytes(game_config::red_to_green(chance_to_hit));
|
||||
color_t chance_color = game_config::red_to_green(chance_to_hit);
|
||||
|
||||
// Total damage.
|
||||
str << " " << span_color(dmg_color) << total_damage << naps << span_color(font::weapon_color)
|
||||
|
@ -965,7 +965,7 @@ static config unit_weapons(reports::context & rc, const unit *attacker, const ma
|
|||
char hp_buf[10];
|
||||
format_hp(hp_buf, hp);
|
||||
|
||||
color_t prob_color = color_t::from_argb_bytes(game_config::blue_to_white(prob * 100.0, true));
|
||||
color_t prob_color = game_config::blue_to_white(prob * 100.0, true);
|
||||
|
||||
str << span_color(font::weapon_details_color) << " " << " "
|
||||
<< span_color(u->hp_color(hp)) << hp_buf << naps
|
||||
|
|
Loading…
Add table
Reference in a new issue