Author: jhinrichs
Date: Tue Apr 28 20:44:11 2009
New Revision: 35304
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35304&view=rev
Log:
Applies the patch for making dismissal of units undoable and partly fixes bug
#13268 (save corruption through undo/redo of recalls. The bug will still be
kept open as working with the index of the recall list always leaves room for
corruption. A final fix will have to involve working with unit id's instead if
indices.
Modified:
trunk/changelog
trunk/src/actions.hpp
trunk/src/menu_events.cpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=35304&r1=35303&r2=35304&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Tue Apr 28 20:44:11 2009
@@ -133,6 +133,7 @@
* The add-ons directory, <preferences>/data/campaigns, has been renamed
and it is now <preferences>/data/add-ons
* Enabled hinting for texts displayed by Pango/Cairo (bug #13399)
+ * Made dismissing of recallable units undoable
Version 1.6a:
* User interface:
Modified: trunk/src/actions.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.hpp?rev=35304&r1=35303&r2=35304&view=diff
==============================================================================
--- trunk/src/actions.hpp (original)
+++ trunk/src/actions.hpp Tue Apr 28 20:44:11 2009
@@ -333,14 +333,15 @@
countdown_time_bonus(timebonus)
{}
- undo_action(const unit& u, const map_location& loc, const int pos) :
+ undo_action(const unit& u, const map_location& loc, const int pos,
const bool dismiss=false) :
route(),
starting_moves(),
original_village_owner(),
recall_loc(loc),
recall_pos(pos),
affected_unit(u),
- countdown_time_bonus(1)
+ countdown_time_bonus(1),
+ is_dismiss(dismiss)
{}
std::vector<map_location> route;
@@ -350,6 +351,7 @@
int recall_pos; // set to RECRUIT_POS for an undo-able recruit
unit affected_unit;
int countdown_time_bonus;
+ bool is_dismiss; //set to true if the action is a dismissal of a
recallable unit
bool is_recall() const { return recall_pos >= 0; }
bool is_recruit() const { return recall_pos == RECRUIT_POS; }
};
Modified: trunk/src/menu_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=35304&r1=35303&r2=35304&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Tue Apr 28 20:44:11 2009
@@ -56,13 +56,15 @@
class delete_recall_unit : public gui::dialog_button_action
{
public:
- delete_recall_unit(game_display& disp, gui::filter_textbox&
filter, std::vector<unit>& units) : disp_(disp), filter_(filter), units_(units)
{}
+ delete_recall_unit(game_display& disp, gui::filter_textbox&
filter, std::vector<unit>& units, undo_list& undo_stack, undo_list& redo_stack)
: disp_(disp), filter_(filter), units_(units), undo_stack_(undo_stack),
redo_stack_(redo_stack) {}
private:
gui::dialog_button_action::RESULT button_pressed(int
menu_selection);
game_display& disp_;
gui::filter_textbox& filter_;
std::vector<unit>& units_;
+ undo_list& undo_stack_;
+ undo_list& redo_stack_;
};
gui::dialog_button_action::RESULT
delete_recall_unit::button_pressed(int menu_selection)
@@ -94,9 +96,12 @@
}
// Remove the item from filter_textbox memory
filter_.delete_item(menu_selection);
-
+ //add dismissal to the undo stack
+ undo_stack_.push_back(undo_action(u, map_location(),
static_cast<int>(index), true));
units_.erase(units_.begin() + index);
recorder.add_disband(index);
+ //clear the redo stack to avoid duplication of
dismissals
+ redo_stack_.clear();
return gui::DELETE_ITEM;
} else {
return gui::CONTINUE_DIALOG;
@@ -897,7 +902,7 @@
_("Filter: "), options, options_to_filter, 1,
rmenu, 200);
rmenu.set_textbox(filter);
- delete_recall_unit recall_deleter(*gui_,
*filter, recall_list);
+ delete_recall_unit recall_deleter(*gui_,
*filter, recall_list, undo_stack_, redo_stack_);
gui::dialog_button_info
delete_button(&recall_deleter,_("Dismiss Unit"));
rmenu.add_button(delete_button);
@@ -961,7 +966,18 @@
const events::command_disabler disable_commands;
undo_action& action = undo_stack_.back();
- if(action.is_recall()) {
+ if (action.is_dismiss) {
+ //undo a dismissal
+ player_info* const player =
gamestate_.get_player(teams_[team_num - 1].save_id());
+
+ if(player == NULL) {
+ ERR_NG << "trying to undo a dismissal for side
" << team_num
+ << ", which has no recall list!\n";
+ } else {
+ std::vector<unit>& recall_list =
player->available_units;
+
recall_list.insert(recall_list.begin()+action.recall_pos,action.affected_unit);
+ }
+ } else if(action.is_recall()) {
player_info* const player =
gamestate_.get_player(teams_[team_num - 1].save_id());
if(player == NULL) {
@@ -1069,7 +1085,18 @@
const events::command_disabler disable_commands;
undo_action& action = redo_stack_.back();
- if(action.is_recall()) {
+ if (action.is_dismiss) {
+ player_info
*player=gamestate_.get_player(teams_[team_num - 1].save_id());
+ if(!player) {
+ ERR_NG << "trying to redo a dismiss for side "
<< team_num
+ << ", which has no recall list!\n";
+ } else {
+ //redo a dismissal
+ std::vector<unit>& recall_list =
player->available_units;
+ recorder.add_disband(action.recall_pos);
+
recall_list.erase(recall_list.begin()+action.recall_pos);
+ }
+ } else if(action.is_recall()) {
player_info
*player=gamestate_.get_player(teams_[team_num - 1].save_id());
if(!player) {
ERR_NG << "trying to redo a recall for side "
<< team_num
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits