added patch by John Messerley which shows attack stat tooltips
This commit is contained in:
parent
fb9feae9c2
commit
bec5fa14b3
5 changed files with 92 additions and 24 deletions
|
@ -475,6 +475,10 @@ see_also="See Also..."
|
|||
|
||||
attack_type="Attack Type"
|
||||
|
||||
attacks="attacks"
|
||||
damage="damage"
|
||||
hexes="hexes"
|
||||
|
||||
#Multiplayer lobby/dialogs
|
||||
game_lobby="Game Lobby"
|
||||
shroud="Shroud"
|
||||
|
|
|
@ -714,24 +714,52 @@ void display::draw_report(reports::TYPE report_num)
|
|||
|
||||
SDL_Rect area = rect;
|
||||
|
||||
if(report.text.empty() == false) {
|
||||
// Code for handling a report with multiple tooltips in different areas of the text
|
||||
// XXX figure out if prefix/postfix makes sense for these reports, and if so how
|
||||
// should we support it?
|
||||
if(report.text.size() > 1) {
|
||||
int x = rect.x, y = rect.y;
|
||||
for(size_t i = 0; i < report.text.size(); ++i) {
|
||||
std::string text = report.text[i];
|
||||
std::string tooltip = (i < report.tooltip.size() ? report.tooltip[i] : "");
|
||||
|
||||
area = font::draw_text(this,rect,item->font_size(),font::NORMAL_COLOUR,text,x,y);
|
||||
if(text != "" && *(text.end()-1) == '\n') {
|
||||
x = area.x;
|
||||
y = area.y + area.h;
|
||||
} else {
|
||||
x = area.x + area.w;
|
||||
y = area.y;
|
||||
}
|
||||
if(tooltip.empty() == false) {
|
||||
tooltips::add_tooltip(area,tooltip);
|
||||
}
|
||||
}
|
||||
// Skip single-tooltip report code and image drawing code
|
||||
return;
|
||||
}
|
||||
|
||||
std::string text = report.text.size() ? report.text[0] : "";
|
||||
std::string tooltip = report.tooltip.size() ? report.tooltip[0] : "";
|
||||
|
||||
if(text.empty() == false) {
|
||||
std::string str = item->prefix();
|
||||
|
||||
int nchop;
|
||||
|
||||
//if there are formatting directives on the front of the report,
|
||||
//move them to the front of the string
|
||||
for(nchop = 0; nchop != report.text.size() && font::is_format_char(report.text[nchop]); ++nchop) {
|
||||
str.insert(str.begin(),report.text[0]);
|
||||
for(nchop = 0; nchop != text.size() && font::is_format_char(text[nchop]); ++nchop) {
|
||||
str.insert(str.begin(),text[nchop]);
|
||||
}
|
||||
|
||||
str += report.text.substr(nchop) + item->postfix();
|
||||
str += text.substr(nchop) + item->postfix();
|
||||
|
||||
area = font::draw_text(this,rect,item->font_size(),font::NORMAL_COLOUR,str,rect.x,rect.y);
|
||||
}
|
||||
|
||||
if(report.tooltip.empty() == false) {
|
||||
tooltips::add_tooltip(area,report.tooltip);
|
||||
if(tooltip.empty() == false) {
|
||||
tooltips::add_tooltip(area,tooltip);
|
||||
}
|
||||
|
||||
if(report.image.empty() == false) {
|
||||
|
@ -756,7 +784,7 @@ void display::draw_report(reports::TYPE report_num)
|
|||
|
||||
int x = rect.x, y = rect.y;
|
||||
const std::vector<std::string> rows = config::split(report.image,';');
|
||||
const std::vector<std::string> tooltip_rows = config::split(report.tooltip,';');
|
||||
const std::vector<std::string> tooltip_rows = config::split(tooltip,';');
|
||||
std::vector<std::string>::const_iterator current_tooltip = tooltip_rows.begin();
|
||||
for(std::vector<std::string>::const_iterator row = rows.begin(); row != rows.end(); ++row) {
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ RESULT enter(display& disp, config& game_data, const config& terrain_data)
|
|||
|
||||
// Display Chats
|
||||
std::stringstream text;
|
||||
for(size_t n = messages.size() > 8 ? messages.size()-8 : 0;
|
||||
for(size_t n = messages.size() > 6 ? messages.size()-6 : 0;
|
||||
n != messages.size(); ++n) {
|
||||
text << messages[n] << "\n";
|
||||
}
|
||||
|
|
|
@ -25,6 +25,23 @@ const std::string& report_name(TYPE type)
|
|||
return report_names[type];
|
||||
}
|
||||
|
||||
void report::add_text(std::stringstream& text, std::stringstream& tooltip) {
|
||||
add_text(text.str(), tooltip.str());
|
||||
// Clear the streams
|
||||
text.str("");
|
||||
tooltip.str("");
|
||||
}
|
||||
|
||||
void report::add_text(const std::string& text, const std::string& tooltip) {
|
||||
this->text.push_back(text);
|
||||
this->tooltip.push_back(tooltip);
|
||||
}
|
||||
|
||||
void report::set_tooltip(const std::string& tooltip) {
|
||||
this->tooltip.clear();
|
||||
this->tooltip.push_back(tooltip);
|
||||
}
|
||||
|
||||
report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
||||
const std::vector<team>& teams,
|
||||
const team& current_team, int current_side, int playing_side,
|
||||
|
@ -64,7 +81,7 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
return report(u->second.description());
|
||||
case UNIT_TYPE: {
|
||||
report res(u->second.type().language_name());
|
||||
res.tooltip = u->second.type().unit_description();
|
||||
res.set_tooltip(u->second.type().unit_description());
|
||||
return res;
|
||||
}
|
||||
case UNIT_LEVEL:
|
||||
|
@ -72,7 +89,7 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
break;
|
||||
case UNIT_TRAITS: {
|
||||
report res(u->second.traits_description());
|
||||
res.tooltip = u->second.modification_description("trait");
|
||||
res.set_tooltip(u->second.modification_description("trait"));
|
||||
return res;
|
||||
}
|
||||
case UNIT_STATUS: {
|
||||
|
@ -101,13 +118,13 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
}
|
||||
|
||||
report res("",unit_status.str());
|
||||
res.tooltip = tooltip.str();
|
||||
res.set_tooltip(tooltip.str());
|
||||
return res;
|
||||
}
|
||||
case UNIT_ALIGNMENT: {
|
||||
const std::string& align = unit_type::alignment_description(u->second.type().alignment());
|
||||
report res(translate_string(align));
|
||||
res.tooltip = string_table[align + "_description"];
|
||||
res.set_tooltip(string_table[align + "_description"]);
|
||||
return res;
|
||||
}
|
||||
case UNIT_ABILITIES: {
|
||||
|
@ -122,7 +139,7 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
}
|
||||
|
||||
report res(str.str());
|
||||
res.tooltip = tooltip.str();
|
||||
res.set_tooltip(tooltip.str());
|
||||
return res;
|
||||
}
|
||||
case UNIT_HP:
|
||||
|
@ -152,28 +169,40 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
str << u->second.movement_left() << "/" << u->second.total_movement();
|
||||
break;
|
||||
case UNIT_WEAPONS: {
|
||||
report res;
|
||||
std::stringstream tooltip;
|
||||
|
||||
const std::vector<attack_type>& attacks = u->second.attacks();
|
||||
for(std::vector<attack_type>::const_iterator at_it = attacks.begin();
|
||||
at_it != attacks.end(); ++at_it) {
|
||||
const std::string& lang_weapon = string_table["weapon_name_" + at_it->name()];
|
||||
const std::string& lang_type = string_table["weapon_type_" + at_it->type()];
|
||||
const std::string& lang_special = string_table["weapon_special_" + at_it->special()];
|
||||
|
||||
str << (lang_weapon.empty() ? at_it->name():lang_weapon) << " ("
|
||||
<< (lang_type.empty() ? at_it->type():lang_type) << ")\n"
|
||||
<< (lang_special.empty() ? at_it->special():lang_special) << "\n"
|
||||
<< at_it->damage() << "-" << at_it->num_attacks() << " -- "
|
||||
<< (lang_type.empty() ? at_it->type():lang_type) << ")\n";
|
||||
res.add_text(str, tooltip);
|
||||
|
||||
str << (lang_special.empty() ? at_it->special():lang_special) << "\n";
|
||||
tooltip << string_table["weapon_special_" + at_it->special() + "_description"];
|
||||
res.add_text(str, tooltip);
|
||||
|
||||
str << at_it->damage() << "-" << at_it->num_attacks() << " -- "
|
||||
<< (at_it->range() == attack_type::SHORT_RANGE ?
|
||||
string_table["short_range"] :
|
||||
string_table["long_range"]);
|
||||
tooltip << at_it->damage() << " " << string_table["damage"] << ", "
|
||||
<< at_it->num_attacks() << " " << string_table["attacks"];
|
||||
|
||||
if(at_it->hexes() > 1) {
|
||||
str << " (" << at_it->hexes() << ")";
|
||||
tooltip << ", " << at_it->hexes() << " " << string_table["hexes"];
|
||||
}
|
||||
|
||||
str << "\n";
|
||||
res.add_text(str, tooltip);
|
||||
}
|
||||
|
||||
break;
|
||||
return res;
|
||||
}
|
||||
case UNIT_IMAGE:
|
||||
return report("",u->second.type().image());
|
||||
|
@ -190,7 +219,7 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
<< translate_string("neutral") << " " << string_table["units"] << ": " << "0%\n"
|
||||
<< translate_string("chaotic") << " " << string_table["units"] << ": "
|
||||
<< (tod.lawful_bonus < 0 ? "+" : "") << (tod.lawful_bonus*-1) << "%";
|
||||
res.tooltip = tooltip.str();
|
||||
res.set_tooltip(tooltip.str());
|
||||
return res;
|
||||
}
|
||||
case TURN:
|
||||
|
@ -271,7 +300,7 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
|
||||
case OBSERVERS: {
|
||||
if(observers.empty()) {
|
||||
return report("none");
|
||||
return report();
|
||||
}
|
||||
|
||||
for(std::set<std::string>::const_iterator i = observers.begin(); i != observers.end(); ++i) {
|
||||
|
@ -279,7 +308,7 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
}
|
||||
|
||||
report res("",game_config::observer_image);
|
||||
res.tooltip = str.str();
|
||||
res.set_tooltip(str.str());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,13 +26,20 @@ namespace reports {
|
|||
const std::string& report_name(TYPE type);
|
||||
|
||||
struct report {
|
||||
std::string image;
|
||||
std::vector<std::string> text, tooltip;
|
||||
|
||||
report() {}
|
||||
explicit report(const std::string& text) : text(text) {}
|
||||
report(const std::string& text, const std::string& image) : text(text), image(image) {}
|
||||
explicit report(const std::string& text) { this->text.push_back(text); }
|
||||
report(const std::string& text, const std::string& image) : image(image) { this->text.push_back(text); }
|
||||
bool empty() const { return text.empty() && image.empty(); }
|
||||
bool operator==(const report& o) const { return o.text == text && o.image == image && o.tooltip == tooltip; }
|
||||
bool operator!=(const report& o) const { return !(o == *this); }
|
||||
std::string text, image, tooltip;
|
||||
|
||||
// Convenience functions
|
||||
void add_text(std::stringstream& text, std::stringstream& tooltip);
|
||||
void add_text(const std::string& text, const std::string& tooltip);
|
||||
void set_tooltip(const std::string& tooltip);
|
||||
};
|
||||
|
||||
report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
||||
|
|
Loading…
Add table
Reference in a new issue