Advertisement
Vultraz

Untitled

Nov 19th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. void statistics_dialog::pre_show(window& window)
  2. {
  3.     const bool show_this_turn = use_campaign_ || scenario_index_ + 1 == scenarios_.size();
  4.  
  5.     std::vector<config> menu_items;
  6.     for(const auto& scenario : scenarios_) {
  7.         menu_items.push_back(config_of("label", *scenario.first));
  8.     }
  9.  
  10.     find_widget<menu_button>(&window, "scenario_list", false).set_values(menu_items, scenario_index_);
  11.  
  12.     const statistics::stats& stats = current_stats();
  13.  
  14.     listbox& stat_list = find_widget<listbox>(&window, "stats_list_main", false);
  15.  
  16.     std::map<std::string, string_map> data;
  17.     string_map item;
  18.  
  19.     const auto add_stat_row = [&](const std::string& type, const statistics::stats::str_int_map& value, const bool has_cost = true) {
  20.         item["label"] = type;
  21.         data.emplace("stat_type", item);
  22.  
  23.         item["label"] = std::to_string(statistics::sum_str_int_map(value));
  24.         data.emplace("stat_detail", item);
  25.  
  26.         item["label"] = has_cost ? std::to_string(statistics::sum_cost_str_int_map(value)) : font::unicode_em_dash;
  27.         data.emplace("stat_cost", item);
  28.  
  29.         stat_list.add_row(data);
  30.  
  31.         data.clear();
  32.         item.clear();
  33.     };
  34.  
  35.     add_stat_row(_("Recruits"),     stats.recruits);
  36.     add_stat_row(_("Recalls"),      stats.recalls);
  37.     add_stat_row(_("Advancements"), stats.advanced_to, false);
  38.     add_stat_row(_("Losses"),       stats.deaths);
  39.     add_stat_row(_("Kills"),        stats.killed);
  40.  
  41.     listbox& damage_list = find_widget<listbox>(&window, "stats_list_damage", false);
  42.  
  43.     const auto add_damage_row = [&](
  44.         const std::string& type,
  45.         const long long& damage,
  46.         const long long& expected,
  47.         const long long& turn_damage,
  48.         const long long& turn_expected)
  49.     {
  50.         item["label"] = type;
  51.         data.emplace("damage_type", item);
  52.  
  53.         const int shift = statistics::stats::decimal_shift;
  54.  
  55.         const long long dsa = shift * damage      - expected;
  56.         const long long dst = shift * turn_damage - turn_expected;
  57.  
  58.         std::ostringstream str;
  59.         str << damage << " / "
  60.             << (expected * 10 + shift / 2) / shift * 0.1
  61.             << "    " // TODO: should probably make this two columns
  62.             << ((dsa < 0) ^ (expected < 0) ? "" : "+")
  63.             << (expected == 0 ? 0 : 100 * dsa / expected) << '%';
  64.  
  65.         item["label"] = str.str();
  66.         data.emplace("damage_overall", item);
  67.  
  68.         str.clear();
  69.  
  70.         if(show_this_turn) {
  71.             str << turn_damage << " / "
  72.                 << (turn_expected * 10 + shift / 2) / shift * 0.1
  73.                 << "    " // TODO: should probably make this two columns
  74.                 << ((dst < 0) ^ (turn_expected < 0) ? "" : "+")
  75.                 << (turn_expected == 0 ? 0 : 100 * dst / turn_expected) << '%';
  76.  
  77.             item["label"] = str.str();
  78.             data.emplace("damage_this_turm", item);
  79.         }
  80.  
  81.         damage_list.add_row(data);
  82.  
  83.         data.clear();
  84.         item.clear();
  85.     };
  86.  
  87.     add_damage_row(_("Inflicted"),
  88.         stats.damage_inflicted,
  89.         stats.expected_damage_inflicted,
  90.         stats.turn_damage_inflicted,
  91.         stats.turn_expected_damage_inflicted);
  92.  
  93.     add_damage_row(_("Taken"),
  94.         stats.damage_taken,
  95.         stats.expected_damage_taken,
  96.         stats.turn_damage_taken,
  97.         stats.turn_expected_damage_taken);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement