tunit_attack: simplify damage calc callback by calling gui::show_dialog directly

As opposed to manually "clicking" the button.
This commit is contained in:
Charles Dang 2016-08-10 22:28:43 +11:00
parent 34d6df9e43
commit c3f07f1f73
3 changed files with 10 additions and 41 deletions

View file

@ -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);
}
}
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;
}

View file

@ -109,22 +109,4 @@ private:
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

View file

@ -31,6 +31,7 @@
#include "gui/widgets/unit_preview_pane.hpp"
#include "gui/widgets/window.hpp"
#include "game_config.hpp"
#include "game_display.hpp"
#include "gettext.hpp"
#include "help/help.hpp"
#include "language.hpp"
@ -175,11 +176,13 @@ static void set_weapon_info(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();
attack_prediction_displayer predition_dialog(weapons_, (*attacker_itor_).get_location(), (*defender_itor_).get_location());
predition_dialog.button_pressed(selection);
battle_prediction_pane battle_pane(weapons_[index], (*attacker_itor_).get_location(), (*defender_itor_).get_location());
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)