00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "editor_undo.hpp"
00019
00020 namespace {
00021 const unsigned int undo_limit = 100;
00022 map_editor::map_undo_list undo_stack;
00023 map_editor::map_undo_list redo_stack;
00024 }
00025
00026
00027 namespace map_editor {
00028
00029 map_undo_action::map_undo_action() {
00030 terrain_set_ = false;
00031 selection_set_ = false;
00032 map_data_set_ = false;
00033 starting_locations_set_ = false;
00034 }
00035
00036 const std::map<gamemap::location, t_translation::t_terrain>& map_undo_action::undo_terrains() const
00037 {
00038 return old_terrain_;
00039 }
00040
00041 const std::map<gamemap::location, t_translation::t_terrain>& map_undo_action::redo_terrains() const
00042 {
00043 return new_terrain_;
00044 }
00045
00046 const std::set<gamemap::location> map_undo_action::undo_selection() const {
00047 return old_selection_;
00048 }
00049
00050 const std::set<gamemap::location> map_undo_action::redo_selection() const {
00051 return new_selection_;
00052 }
00053
00054 std::string map_undo_action::old_map_data() const {
00055 return old_map_data_;
00056 }
00057
00058 std::string map_undo_action::new_map_data() const {
00059 return new_map_data_;
00060 }
00061
00062 const std::map<gamemap::location, int>& map_undo_action::undo_starting_locations() const {
00063 return old_starting_locations_;
00064 }
00065
00066 const std::map<gamemap::location, int>& map_undo_action::redo_starting_locations() const {
00067 return new_starting_locations_;
00068 }
00069
00070 void map_undo_action::add_terrain(const t_translation::t_terrain& old_tr,
00071 const t_translation::t_terrain& new_tr,
00072 const gamemap::location& lc)
00073 {
00074 old_terrain_[lc] = old_tr;
00075 new_terrain_[lc] = new_tr;
00076 terrain_set_ = true;
00077 }
00078
00079 bool map_undo_action::terrain_set() const {
00080 return terrain_set_;
00081 }
00082
00083 void map_undo_action::set_selection(const std::set<gamemap::location> &old_selection,
00084 const std::set<gamemap::location> &new_selection) {
00085 old_selection_ = old_selection;
00086 new_selection_ = new_selection;
00087 selection_set_ = true;
00088 }
00089
00090 bool map_undo_action::selection_set() const {
00091 return selection_set_;
00092 }
00093
00094 void map_undo_action::set_map_data(const std::string &old_data,
00095 const std::string &new_data) {
00096 old_map_data_ = old_data;
00097 new_map_data_ = new_data;
00098 map_data_set_ = true;
00099 }
00100
00101 bool map_undo_action::map_data_set() const {
00102 return map_data_set_;
00103 }
00104
00105 void map_undo_action::add_starting_location(const int old_side, const int new_side,
00106 const gamemap::location &old_loc,
00107 const gamemap::location &new_loc) {
00108 old_starting_locations_[old_loc] = old_side;
00109 new_starting_locations_[new_loc] = new_side;
00110 starting_locations_set_ = true;
00111 }
00112
00113 bool map_undo_action::starting_location_set() const {
00114 return starting_locations_set_;
00115 }
00116
00117 bool map_undo_action::something_set() const {
00118 return terrain_set_ || selection_set_ || map_data_set_ || starting_locations_set_;
00119 }
00120
00121 void add_undo_action(const map_undo_action &action) {
00122 undo_stack.push_back(action);
00123 if (undo_stack.size() > undo_limit) {
00124 undo_stack.pop_front();
00125 }
00126
00127
00128 redo_stack.clear();
00129 }
00130
00131 bool exist_undo_actions() {
00132 return !undo_stack.empty();
00133 }
00134
00135 bool exist_redo_actions() {
00136 return !redo_stack.empty();
00137 }
00138
00139 map_undo_action pop_undo_action() {
00140 map_undo_action action = undo_stack.back();
00141 undo_stack.pop_back();
00142 redo_stack.push_back(action);
00143 if (redo_stack.size() > undo_limit) {
00144 redo_stack.pop_front();
00145 }
00146 return action;
00147 }
00148
00149 map_undo_action pop_redo_action() {
00150 map_undo_action action = redo_stack.back();
00151 redo_stack.pop_back();
00152 undo_stack.push_back(action);
00153 if (undo_stack.size() > undo_limit) {
00154 undo_stack.pop_front();
00155 }
00156 return action;
00157 }
00158
00159 void clear_undo_actions() {
00160 undo_stack.clear();
00161 redo_stack.clear();
00162 }
00163
00164
00165 }