void ttroop_detail::refresh_tooltip(twindow& window) { std::stringstream text; int index; tbutton* button = find_widget<tbutton>(&window, "merit", false, true); button->set_dirty(); button->set_active(partial_troops_.empty()? false: true); if (partial_troops_.empty()) { // It is necessary set all relative tips to empty. tlabel* label = find_widget<tlabel>(&window, "tip_name", false, true); label->set_label(""); // tip_loyalty label = find_widget<tlabel>(&window, "tip_loyalty", false, true); label->set_label(""); // tip_activity label = find_widget<tlabel>(&window, "tip_activity", false, true); label->set_label(""); // leadership label = find_widget<tlabel>(&window, "tip_leadership", false, true); label->set_label(""); // force label = find_widget<tlabel>(&window, "tip_force", false, true); label->set_label(""); // intellect label = find_widget<tlabel>(&window, "tip_intellect", false, true); label->set_label(""); // politics label = find_widget<tlabel>(&window, "tip_politics", false, true); label->set_label(""); // charm label = find_widget<tlabel>(&window, "tip_charm", false, true); label->set_label(""); /* // hp label = find_widget<tlabel>(&window, "tip_hp", false, true); label->set_label(""); // xp label = find_widget<tlabel>(&window, "tip_xp", false, true); label->set_label(""); // movement label = find_widget<tlabel>(&window, "tip_movement", false, true); label->set_label(""); // arm label = find_widget<tlabel>(&window, "tip_arm", false, true); label->set_label(""); */ // traits label = find_widget<tlabel>(&window, "tip_traits", false, true); label->set_label(""); // adaptability label = find_widget<tlabel>(&window, "tip_adaptability", false, true); label->set_label(""); // skill label = find_widget<tlabel>(&window, "tip_skill", false, true); label->set_label(""); // abilities label = find_widget<tlabel>(&window, "tip_abilities", false, true); label->set_label(""); // feature label = find_widget<tlabel>(&window, "tip_feature", false, true); label->set_label(""); // attack label = find_widget<tlabel>(&window, "tip_attack", false, true); label->set_label(""); // resistance label = find_widget<tlabel>(&window, "tip_resistance", false, true); label->set_label(""); return; } const unit& temp = *(partial_troops_[troop_index_]); std::stringstream str, activity_str; int loyalty, activity, hero_count = 1; // refresh to gui tlabel* label = find_widget<tlabel>(&window, "tip_name", false, true); str << dgettext("wesnoth", "hero") << ": " << temp.master().name(); text << temp.master().loyalty(*teams_[temp.master().side_].leader()); loyalty = temp.master().loyalty(*teams_[temp.master().side_].leader()); activity = temp.master().activity_; activity_str << (int)temp.master().activity_; if (temp.second().valid()) { str << " " << temp.second().name(); text << ", " << temp.second().loyalty(*teams_[temp.second().side_].leader()); loyalty += temp.second().loyalty(*teams_[temp.second().side_].leader()); activity += temp.second().activity_; activity_str << ", " << (int)temp.second().activity_; hero_count ++; } if (temp.third().valid()) { str << " " << temp.third().name(); text << ", " << temp.third().loyalty(*teams_[temp.third().side_].leader()); loyalty += temp.third().loyalty(*teams_[temp.third().side_].leader()); activity += temp.third().activity_; activity_str << ", " << (int)temp.third().activity_; hero_count ++; } label->set_label(str.str()); str.str(""); label = find_widget<tlabel>(&window, "tip_loyalty", false, true); str << dgettext("wesnoth", "loyalty") << ": " << loyalty / hero_count << "/(" << text.str() << ")"; label->set_label(str.str()); // activity str.str(""); label = find_widget<tlabel>(&window, "tip_activity", false, true); str << _("Activity") << ": " << activity / hero_count << "/(" << activity_str.str() << ")"; label->set_label(str.str()); // leadership label = find_widget<tlabel>(&window, "tip_leadership", false, true); label->set_label(lexical_cast<std::string>(temp.leadership_)); // force label = find_widget<tlabel>(&window, "tip_force", false, true); label->set_label(lexical_cast<std::string>(temp.force_)); // intellect label = find_widget<tlabel>(&window, "tip_intellect", false, true); label->set_label(lexical_cast<std::string>(temp.intellect_)); // politics label = find_widget<tlabel>(&window, "tip_politics", false, true); label->set_label(lexical_cast<std::string>(temp.politics_)); // charm label = find_widget<tlabel>(&window, "tip_charm", false, true); label->set_label(lexical_cast<std::string>(temp.charm_)); /* // hp label = find_widget<tlabel>(&window, "tip_hp", false, true); label->set_label(lexical_cast<std::string>(temp.max_hitpoints())); // xp label = find_widget<tlabel>(&window, "tip_xp", false, true); label->set_label(lexical_cast<std::string>(temp.max_experience())); // movement label = find_widget<tlabel>(&window, "tip_movement", false, true); label->set_label(lexical_cast<std::string>(temp.total_movement())); // arm label = find_widget<tlabel>(&window, "tip_arm", false, true); str << temp.type_name() << "(Lv" << temp.level() << ")"; label->set_label(str.str()); */ // traits str.str(""); str << dgettext("wesnoth", "Traits") << ": " << utils::join(temp.trait_names(), ", "); label = find_widget<tlabel>(&window, "tip_traits", false, true); label->set_label(str.str()); // abilities str.str(""); std::vector<std::string> abilities_tt; abilities_tt = temp.ability_tooltips(true); str << dgettext("wesnoth", "Abilities") << ": "; if (!abilities_tt.empty()) { std::vector<t_string> abilities; for (std::vector<std::string>::const_iterator a = abilities_tt.begin(); a != abilities_tt.end(); a += 2) { abilities.push_back(*a); } for (std::vector<t_string>::const_iterator a = abilities.begin(); a != abilities.end(); a++) { if (a != abilities.begin()) { str << ", "; } str << (*a); } } label = find_widget<tlabel>(&window, "tip_abilities", false, true); label->set_label(str.str()); // feature str.str(""); index = 0; str << dgettext("wesnoth", "feature") << ": "; for (int i = 0; i < HEROS_MAX_FEATURE; i ++) { if (unit_feature_val2(temp, i) == hero_feature_single_result) { if (index > 0) { str << ", "; } index ++; str << temp.master().feature_str(i); } } label = find_widget<tlabel>(&window, "tip_feature", false, true); label->set_label(str.str()); // adaptability str.str(""); str << dgettext("wesnoth", "adaptability") << ": "; str << hero::arms_str(temp.arms()) << "(" << hero::adaptability_str2(ftofxp12(temp.adaptability_[temp.arms()])) << ")"; label = find_widget<tlabel>(&window, "tip_adaptability", false, true); label->set_label(str.str()); // skill str.str(""); str << dgettext("wesnoth-lib", "Skill") << ": "; str << hero::skill_str(hero_skill_demolish) << "(" << hero::adaptability_str2(ftofxp12(temp.skill_[hero_skill_demolish])) << ")"; label = find_widget<tlabel>(&window, "tip_skill", false, true); label->set_label(str.str()); // attack str.str(""); std::vector<attack_type>* attacks_ptr = const_cast<std::vector<attack_type>*>(&temp.attacks()); for (std::vector<attack_type>::const_iterator at_it = attacks_ptr->begin(); at_it != attacks_ptr->end(); ++at_it) { // see generate_report() in generate_report.cpp str << at_it->name() << " (" << dgettext("wesnoth", at_it->type().c_str()) << ")\n"; std::string accuracy = at_it->accuracy_parry_description(); if(accuracy.empty() == false) { accuracy += " "; } str << " " << at_it->damage() << "-" << at_it->num_attacks() << " " << accuracy << "- " << dgettext("wesnoth", at_it->range().c_str()); std::string special = at_it->weapon_specials(true); if (!special.empty()) { str << "(" << special << ")"; } str << "\n"; } label = find_widget<tlabel>(&window, "tip_attack", false, true); label->set_label(str.str()); // resistance int idx_in_resistances; std::set<std::string> resistances_table; utils::string_map resistances = temp.get_base_resistances(); bool att_def_diff = false; const map_location& loc = temp.get_location(); idx_in_resistances = 0; str.str(""); for (utils::string_map::iterator resist = resistances.begin(); resist != resistances.end(); ++resist, idx_in_resistances ++) { str << dgettext("wesnoth", resist->first.c_str()) << ": "; const map_location& loc = temp.get_location(); if (loc.valid()) { // Some units have different resistances when // attacking or defending. int res_att = 100 - temp.resistance_against(resist->first, true, loc); int res_def = 100 - temp.resistance_against(resist->first, false, loc); if (res_att == res_def) { str << res_def; } else { str << res_att << "% / " << res_def; // (Att / Def) att_def_diff = true; } } else { str << 100 - lexical_cast_default<int>(resist->second.c_str()); } if (idx_in_resistances % 2) { str << "%\n"; } else { str << "% "; } } label = find_widget<tlabel>(&window, "tip_resistance", false, true); label->set_label(str.str()); }
void trecruit::refresh_tooltip(twindow& window) { int idx_in_resistances; std::stringstream text; tstacked_widget* stacked = find_widget<tstacked_widget>(&window, "middle_top_part", false, true); stacked->set_dirty(true); stacked = find_widget<tstacked_widget>(&window, "right_part", false, true); stacked->set_dirty(true); if (checked_heros_.empty()) { // It is necessary set all relative tips to empty. tcontrol* control = find_widget<tcontrol>(&window, "master_png", false, true); control->set_label(""); tlabel* label = find_widget<tlabel>(&window, "master_name", false, true); label->set_label(""); // leadership label = find_widget<tlabel>(&window, "tip_leadership", false, true); label->set_label(""); // force label = find_widget<tlabel>(&window, "tip_force", false, true); label->set_label(""); // intellect label = find_widget<tlabel>(&window, "tip_intellect", false, true); label->set_label(""); // politics label = find_widget<tlabel>(&window, "tip_politics", false, true); label->set_label(""); // charm label = find_widget<tlabel>(&window, "tip_charm", false, true); label->set_label(""); // hp label = find_widget<tlabel>(&window, "tip_hp", false, true); label->set_label(""); // xp label = find_widget<tlabel>(&window, "tip_xp", false, true); label->set_label(""); // movement label = find_widget<tlabel>(&window, "tip_movement", false, true); label->set_label(""); // arm label = find_widget<tlabel>(&window, "tip_arm", false, true); label->set_label(""); // adaptability label = find_widget<tlabel>(&window, "tip_adaptability", false, true); label->set_label(""); // abilities label = find_widget<tlabel>(&window, "tip_abilities", false, true); label->set_label(""); // feature label = find_widget<tlabel>(&window, "tip_feature", false, true); label->set_label(""); // attack label = find_widget<tlabel>(&window, "tip_attack", false, true); label->set_label(""); // resistance for (idx_in_resistances = 0; idx_in_resistances < 7; idx_in_resistances ++) { text.str(""); text << "tip_resistance" << idx_in_resistances; label = find_widget<tlabel>(&window, text.str(), false, true); label->set_label(""); } return; } const unit_type* t = unit_types_[type_index_]; std::vector<const hero*> v; int index = 0; for (std::set<int>::const_iterator itor = checked_heros_.begin(); itor != checked_heros_.end(); ++ itor, index ++) { if (index == 0) { v.push_back(fresh_heros_[*itor]); } else if (index == 1) { v.push_back(fresh_heros_[*itor]); } else if (index == 2) { v.push_back(fresh_heros_[*itor]); } } type_heros_pair pair(t, v); unit temp(units_, heros_, pair, city_.cityno(), false); std::stringstream str; // refresh to gui tcontrol* control = find_widget<tcontrol>(&window, "master_png", false, true); control->set_label(temp.master().image()); tlabel* label = find_widget<tlabel>(&window, "master_name", false, true); label->set_label(temp.master().name()); control = find_widget<tcontrol>(&window, "second_png", false, true); label = find_widget<tlabel>(&window, "second_name", false, true); if (temp.second().valid()) { control->set_label(temp.second().image()); label->set_label(temp.second().name()); } else { control->set_label(""); label->set_label(""); } control = find_widget<tcontrol>(&window, "third_png", false, true); label = find_widget<tlabel>(&window, "third_name", false, true); if (temp.third().valid()) { control->set_label(temp.third().image()); label->set_label(temp.third().name()); } else { control->set_label(""); label->set_label(""); } // leadership label = find_widget<tlabel>(&window, "tip_leadership", false, true); label->set_label(lexical_cast<std::string>(temp.leadership_)); // force label = find_widget<tlabel>(&window, "tip_force", false, true); label->set_label(lexical_cast<std::string>(temp.force_)); // intellect label = find_widget<tlabel>(&window, "tip_intellect", false, true); label->set_label(lexical_cast<std::string>(temp.intellect_)); // politics label = find_widget<tlabel>(&window, "tip_politics", false, true); label->set_label(lexical_cast<std::string>(temp.politics_)); // charm label = find_widget<tlabel>(&window, "tip_charm", false, true); label->set_label(lexical_cast<std::string>(temp.charm_)); // hp label = find_widget<tlabel>(&window, "tip_hp", false, true); label->set_label(lexical_cast<std::string>(temp.max_hitpoints())); // xp label = find_widget<tlabel>(&window, "tip_xp", false, true); label->set_label(lexical_cast<std::string>(temp.max_experience())); // movement label = find_widget<tlabel>(&window, "tip_movement", false, true); label->set_label(lexical_cast<std::string>(temp.total_movement())); // arm label = find_widget<tlabel>(&window, "tip_arm", false, true); str << temp.type_name() << "(Lv" << temp.level() << ")"; label->set_label(str.str()); // adaptability str.str(""); label = find_widget<tlabel>(&window, "tip_adaptability", false, true); str << hero::arms_str(temp.arms()) << "(" << hero::adaptability_str2(ftofxp12(temp.adaptability_[temp.arms()])) << ")"; label->set_label(str.str()); // abilities str.str(""); std::vector<std::string> abilities_tt; abilities_tt = temp.ability_tooltips(true); if (!abilities_tt.empty()) { std::vector<t_string> abilities; for (std::vector<std::string>::const_iterator a = abilities_tt.begin(); a != abilities_tt.end(); a += 2) { abilities.push_back(*a); } for (std::vector<t_string>::const_iterator a = abilities.begin(); a != abilities.end(); a++) { if (a != abilities.begin()) { if (a - abilities.begin() != 2) { str << ", "; } else { str << "\n"; } } str << (*a); } } label = find_widget<tlabel>(&window, "tip_abilities", false, true); label->set_label(str.str()); // feature str.str(""); index = 0; for (int i = 0; i < HEROS_MAX_FEATURE; i ++) { if (unit_feature_val2(temp, i) == hero_feature_single_result) { if (index > 0) { if (index != 2) { str << ", "; } else { str << "\n"; } } index ++; str << temp.master().feature_str(i); } } label = find_widget<tlabel>(&window, "tip_feature", false, true); label->set_label(str.str()); // attack str.str(""); std::vector<attack_type>* attacks_ptr = const_cast<std::vector<attack_type>*>(&temp.attacks()); for (std::vector<attack_type>::const_iterator at_it = attacks_ptr->begin(); at_it != attacks_ptr->end(); ++at_it) { // see generate_report() in generate_report.cpp str << at_it->name() << " (" << dgettext("wesnoth", at_it->type().c_str()) << ")\n"; std::string accuracy = at_it->accuracy_parry_description(); if(accuracy.empty() == false) { accuracy += " "; } str << " " << at_it->damage() << "-" << at_it->num_attacks() << " " << accuracy << "- " << dgettext("wesnoth", at_it->range().c_str()); std::string special = at_it->weapon_specials(true); if (!special.empty()) { str << "(" << special << ")"; } str << "\n"; } label = find_widget<tlabel>(&window, "tip_attack", false, true); label->set_label(str.str()); // resistance std::set<std::string> resistances_table; utils::string_map resistances = temp.get_base_resistances(); bool att_def_diff = false; const map_location& loc = temp.get_location(); idx_in_resistances = 0; for (utils::string_map::iterator resist = resistances.begin(); resist != resistances.end(); ++resist, idx_in_resistances ++) { // str << gettext(resist->first.c_str()) << ": "; str.str(""); if (loc.valid()) { // Some units have different resistances when // attacking or defending. int res_att = 100 - temp.resistance_against(resist->first, true, loc); int res_def = 100 - temp.resistance_against(resist->first, false, loc); if (res_att == res_def) { str << res_def; } else { str << res_att << "% / " << res_def; // (Att / Def) att_def_diff = true; } } else { str << 100 - lexical_cast_default<int>(resist->second.c_str()); } str << "%"; text.str(""); text << "tip_resistance" << idx_in_resistances; label = find_widget<tlabel>(&window, text.str(), false, true); label->set_label(str.str()); } // gui_.show_unit_tooltip(temp, window.get_x() + window.get_width(), window.get_y()); }
bool get_hero(hero& h, int default_image) { const config& cfg = prefs.child("hero"); if (cfg) { h.set_name(cfg["name"].str()); h.set_surname(cfg["surname"].str()); h.set_biography(cfg["biography"].str()); h.gender_ = cfg["gender"].to_int(hero_gender_male); h.image_ = cfg["image"].to_int(default_image); h.leadership_ = ftofxp9(cfg["leadership"].to_int(1)); h.force_ = ftofxp9(cfg["force"].to_int(1)); h.intellect_ = ftofxp9(cfg["intellect"].to_int(1)); h.spirit_ = ftofxp9(cfg["spirit"].to_int(1)); h.charm_ = ftofxp9(cfg["charm"].to_int(1)); std::stringstream str; for (int i = 0; i < HEROS_MAX_ARMS; i ++) { str.str(""); str << "arms" << i; h.arms_[i] = ftofxp12(cfg[str.str()].to_int(0)); } for (int i = 0; i < HEROS_MAX_SKILL; i ++) { str.str(""); str << "skill" << i; h.skill_[i] = ftofxp12(cfg[str.str()].to_int(0)); } h.side_feature_ = cfg["side_feature"].to_int(HEROS_NO_FEATURE); if (h.side_feature_ < 0 || h.side_feature_ > HEROS_MAX_FEATURE) { h.side_feature_ = HEROS_NO_FEATURE; } h.feature_ = cfg["feature"].to_int(HEROS_NO_FEATURE); if (h.feature_ < 0 || h.feature_ > HEROS_MAX_FEATURE) { h.feature_ = HEROS_NO_FEATURE; } h.tactic_ = cfg["tactic"].to_int(HEROS_NO_TACTIC); h.utype_ = cfg["utype"].to_int(HEROS_NO_UTYPE); h.character_ = cfg["character"].to_int(HEROS_NO_CHARACTER); h.base_catalog_ = cfg["base_catalog"].to_int(); h.float_catalog_ = ftofxp8(h.base_catalog_); return true; } else { // h.set_name(_("Press left button to create hero")); h.set_name(public_account); h.set_surname("Mr."); h.gender_ = hero_gender_male; h.image_ = default_image; h.leadership_ = ftofxp9(1); h.force_ = ftofxp9(1); h.intellect_ = ftofxp9(1); h.spirit_ = ftofxp9(1); h.charm_ = ftofxp9(1); for (int i = 0; i < HEROS_MAX_ARMS; i ++) { h.arms_[i] = 0; } for (int i = 0; i < HEROS_MAX_SKILL; i ++) { h.skill_[i] = 0; } return false; } }