tunit_attack: simplify damage calc callback by calling gui::show_dialog directly
As opposed to manually "clicking" the button.
This commit is contained in:
parent
34d6df9e43
commit
c3f07f1f73
3 changed files with 10 additions and 41 deletions
|
@ -523,19 +523,3 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
|
||||||
width - prob_width - 4, 2 + (fs + 2) * i, 0, TTF_STYLE_NORMAL);
|
width - prob_width - 4, 2 + (fs + 2) * i, 0, TTF_STYLE_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attack_prediction_displayer::RESULT attack_prediction_displayer::button_pressed(int selection)
|
|
||||||
{
|
|
||||||
// Get the selected weapon, if any.
|
|
||||||
const size_t index = size_t(selection);
|
|
||||||
|
|
||||||
if(index < bc_vector_.size()) {
|
|
||||||
battle_prediction_pane battle_pane(bc_vector_[index], attacker_loc_, defender_loc_);
|
|
||||||
std::vector<gui::preview_pane*> preview_panes;
|
|
||||||
preview_panes.push_back(&battle_pane);
|
|
||||||
|
|
||||||
gui::show_dialog(resources::screen->video(), nullptr, _("Damage Calculations"), "", gui::OK_ONLY, nullptr, &preview_panes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui::CONTINUE_DIALOG;
|
|
||||||
}
|
|
||||||
|
|
|
@ -109,22 +109,4 @@ private:
|
||||||
surface& surf, int& width, int& height);
|
surface& surf, int& width, int& height);
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class is used when the user clicks on the button
|
|
||||||
// to show the "Damage Calculations" dialog.
|
|
||||||
class attack_prediction_displayer : public gui::dialog_button_action
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
attack_prediction_displayer(const std::vector<battle_context>& bc_vector,
|
|
||||||
const map_location& attacker_loc, const map_location& defender_loc)
|
|
||||||
: bc_vector_(bc_vector),
|
|
||||||
attacker_loc_(attacker_loc), defender_loc_(defender_loc) {}
|
|
||||||
// This method is called when the button is pressed.
|
|
||||||
RESULT button_pressed(int selection);
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::vector<battle_context>& bc_vector_;
|
|
||||||
const map_location& attacker_loc_;
|
|
||||||
const map_location& defender_loc_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "gui/widgets/unit_preview_pane.hpp"
|
#include "gui/widgets/unit_preview_pane.hpp"
|
||||||
#include "gui/widgets/window.hpp"
|
#include "gui/widgets/window.hpp"
|
||||||
#include "game_config.hpp"
|
#include "game_config.hpp"
|
||||||
|
#include "game_display.hpp"
|
||||||
#include "gettext.hpp"
|
#include "gettext.hpp"
|
||||||
#include "help/help.hpp"
|
#include "help/help.hpp"
|
||||||
#include "language.hpp"
|
#include "language.hpp"
|
||||||
|
@ -111,9 +112,9 @@ static void set_weapon_info(twindow& window,
|
||||||
const battle_context_unit_stats& attacker = weapon.get_attacker_stats();
|
const battle_context_unit_stats& attacker = weapon.get_attacker_stats();
|
||||||
const battle_context_unit_stats& defender = weapon.get_defender_stats();
|
const battle_context_unit_stats& defender = weapon.get_defender_stats();
|
||||||
|
|
||||||
const attack_type& attacker_weapon =
|
const attack_type& attacker_weapon =
|
||||||
*attacker.weapon;
|
*attacker.weapon;
|
||||||
const attack_type& defender_weapon = defender.weapon ?
|
const attack_type& defender_weapon = defender.weapon ?
|
||||||
*defender.weapon : no_weapon;
|
*defender.weapon : no_weapon;
|
||||||
|
|
||||||
const SDL_Color a_cth_color =
|
const SDL_Color a_cth_color =
|
||||||
|
@ -129,9 +130,9 @@ static void set_weapon_info(twindow& window,
|
||||||
range = string_table["range_" + range];
|
range = string_table["range_" + range];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& attw_apecials =
|
const std::string& attw_apecials =
|
||||||
!attacker_weapon.weapon_specials().empty() ? " " + attacker_weapon.weapon_specials() : "";
|
!attacker_weapon.weapon_specials().empty() ? " " + attacker_weapon.weapon_specials() : "";
|
||||||
const std::string& defw_specials =
|
const std::string& defw_specials =
|
||||||
!defender_weapon.weapon_specials().empty() ? " " + defender_weapon.weapon_specials() : "";
|
!defender_weapon.weapon_specials().empty() ? " " + defender_weapon.weapon_specials() : "";
|
||||||
|
|
||||||
std::stringstream attacker_stats, defender_stats;
|
std::stringstream attacker_stats, defender_stats;
|
||||||
|
@ -175,11 +176,13 @@ static void set_weapon_info(twindow& window,
|
||||||
|
|
||||||
void tunit_attack::damage_calc_callback(twindow& window)
|
void tunit_attack::damage_calc_callback(twindow& window)
|
||||||
{
|
{
|
||||||
const int selection
|
const size_t index
|
||||||
= find_widget<tlistbox>(&window, "weapon_list", false).get_selected_row();
|
= find_widget<tlistbox>(&window, "weapon_list", false).get_selected_row();
|
||||||
|
|
||||||
attack_prediction_displayer predition_dialog(weapons_, (*attacker_itor_).get_location(), (*defender_itor_).get_location());
|
battle_prediction_pane battle_pane(weapons_[index], (*attacker_itor_).get_location(), (*defender_itor_).get_location());
|
||||||
predition_dialog.button_pressed(selection);
|
std::vector<gui::preview_pane*> preview_panes = {&battle_pane};
|
||||||
|
|
||||||
|
gui::show_dialog(resources::screen->video(), nullptr, _("Damage Calculations"), "", gui::OK_ONLY, nullptr, &preview_panes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tunit_attack::pre_show(twindow& window)
|
void tunit_attack::pre_show(twindow& window)
|
||||||
|
|
Loading…
Add table
Reference in a new issue