fixes undo and redo

This commit is contained in:
Jörg Hinrichs 2006-04-04 20:03:04 +00:00
parent c9882f7085
commit f8ac313625
6 changed files with 33 additions and 34 deletions

View File

@ -81,7 +81,7 @@ namespace events{
{
}
const undo_list menu_handler::get_undo_list() const{
const undo_list& menu_handler::get_undo_list() const{
return undo_stack_;
}
@ -491,7 +491,7 @@ namespace events{
return false;
}
void menu_handler::recruit(const bool browse, const int team_num, mouse_handler& mousehandler)
void menu_handler::recruit(const bool browse, const int team_num, const gamemap::location& last_hex)
{
if(browse)
return;
@ -548,17 +548,17 @@ namespace events{
}
if(recruit_res != -1) {
do_recruit(item_keys[recruit_res], team_num, mousehandler);
do_recruit(item_keys[recruit_res], team_num, last_hex);
}
}
void menu_handler::repeat_recruit(const int team_num, mouse_handler& mousehandler)
void menu_handler::repeat_recruit(const int team_num, const gamemap::location& last_hex)
{
if(last_recruit_.empty() == false)
do_recruit(last_recruit_, team_num, mousehandler);
do_recruit(last_recruit_, team_num, last_hex);
}
void menu_handler::do_recruit(const std::string& name, const int team_num, mouse_handler& mousehandler)
void menu_handler::do_recruit(const std::string& name, const int team_num, const gamemap::location& last_hex)
{
team& current_team = teams_[team_num-1];
@ -587,9 +587,9 @@ namespace events{
last_recruit_ = name;
//create a unit with traits
recorder.add_recruit(recruit_num, mousehandler.get_last_hex());
recorder.add_recruit(recruit_num, last_hex);
unit new_unit(&(u_type->second),team_num,true);
gamemap::location loc = mousehandler.get_last_hex();
gamemap::location loc = last_hex;
const std::string& msg = recruit_unit(map_,team_num,units_,new_unit,loc,gui_);
if(msg.empty()) {
current_team.spend_gold(u_type->second.cost());
@ -610,7 +610,7 @@ namespace events{
}
}
void menu_handler::recall(const int team_num, mouse_handler& mousehandler)
void menu_handler::recall(const int team_num, const gamemap::location& last_hex)
{
player_info *player = gamestate_.get_player(teams_[team_num-1].save_id());
if(!player) {
@ -694,7 +694,7 @@ namespace events{
gui::show_dialog(*gui_,NULL,"",msg.str());
} else {
unit& un = recall_list[res];
gamemap::location loc = mousehandler.get_last_hex();
gamemap::location loc = last_hex;
recorder.add_recall(res,loc);
const std::string err = recruit_unit(map_,team_num,units_,un,loc,gui_);
if(!err.empty()) {
@ -784,11 +784,8 @@ namespace events{
redo_stack_.push_back(action);
undo_stack_.pop_back();
gui_->unhighlight_reach();
mousehandler.set_current_paths(paths());
mousehandler.set_selected_hex(gamemap::location());
mousehandler.get_current_route().steps.clear();
gui_->set_route(NULL);
mousehandler.set_current_paths(paths());
recorder.undo();
@ -809,11 +806,8 @@ namespace events{
const events::command_disabler disable_commands;
//clear routes, selected hex, etc
gui_->unhighlight_reach();
mousehandler.set_current_paths(paths());
mousehandler.set_selected_hex(gamemap::location());
mousehandler.get_current_route().steps.clear();
gui_->set_route(NULL);
mousehandler.set_current_paths(paths());
undo_action& action = redo_stack_.back();
if(action.is_recall()) {
@ -1163,8 +1157,6 @@ namespace events{
un->second.set_hold_position(!un->second.hold_position());
gui_->draw_tile(mousehandler.get_selected_hex().x, mousehandler.get_selected_hex().y);
gui_->set_route(NULL);
gui_->unhighlight_reach();
mousehandler.set_current_paths(paths());
gui_->draw();
@ -1185,8 +1177,6 @@ namespace events{
}
gui_->draw_tile(mousehandler.get_selected_hex().x, mousehandler.get_selected_hex().y);
gui_->set_route(NULL);
gui_->unhighlight_reach();
mousehandler.set_current_paths(paths());
gui_->draw();

View File

@ -35,7 +35,7 @@ public:
const config& game_config, const gamestatus& status, game_state& gamestate,
undo_list& undo_stack, undo_list& redo_stack);
const undo_list get_undo_list() const;
const undo_list& get_undo_list() const;
gui::floating_textbox& get_textbox();
void set_gui(display* gui) { gui_ = gui; }
@ -49,9 +49,9 @@ public:
void show_chat_log();
void show_help();
void speak();
void recruit(const bool browse, const int team_num, mouse_handler& mousehandler);
void repeat_recruit(const int team_num, mouse_handler& mousehandler);
void recall(const int team_num, mouse_handler& mousehandler);
void recruit(const bool browse, const int team_num, const gamemap::location& last_hex);
void repeat_recruit(const int team_num, const gamemap::location& last_hex);
void recall(const int team_num, const gamemap::location& last_hex);
void undo(const int team_num, mouse_handler& mousehandler);
void redo(const int team_num, mouse_handler& mousehandler);
void show_enemy_moves(bool ignore_units, const int team_num);
@ -82,7 +82,7 @@ public:
void clear_undo_stack(const int team_num);
private:
void do_speak(const std::string& message, bool allies_only);
void do_recruit(const std::string& name, const int team_num, mouse_handler& mousehandler);
void do_recruit(const std::string& name, const int team_num, const gamemap::location& last_hex);
std::vector<std::string> create_unit_table(const statistics::stats::str_int_map& m);
void write_game_snapshot(config& start) const;
bool has_friends() const;

View File

@ -885,4 +885,11 @@ void mouse_handler::cycle_back_units()
}
}
void mouse_handler::set_current_paths(paths new_paths) {
gui_->unhighlight_reach();
current_paths_ = new_paths;
current_route_.steps.clear();
gui_->set_route(NULL);
}
}

View File

@ -31,12 +31,12 @@ public:
int get_path_turns() const { return path_turns_; }
paths get_current_paths() { return current_paths_; }
paths::route get_current_route() const { return current_route_; }
gamemap::location get_last_hex() const { return last_hex_; }
const gamemap::location& get_last_hex() const { return last_hex_; }
gamemap::location get_selected_hex() const { return selected_hex_; }
const bool get_undo() const { return undo_; }
const bool get_show_menu() const { return show_menu_; }
void set_path_turns(const int path_turns) { path_turns_ = path_turns; }
void set_current_paths(paths new_paths) { current_paths_ = new_paths; }
void set_current_paths(paths new_paths);
void set_selected_hex(gamemap::location hex) { selected_hex_ = hex; }
void set_gui(display* gui) { gui_ = gui; }

View File

@ -464,8 +464,10 @@ bool play_controller::can_execute_command(hotkey::HOTKEY_COMMAND command) const
case hotkey::HOTKEY_CHAT_LOG:
return network::nconnections() > 0;
case hotkey::HOTKEY_REDO:
return !browse_ && !redo_stack_.empty() && !events::commands_disabled;
case hotkey::HOTKEY_UNDO:
return !browse_ && !menu_handler_.get_undo_list().empty() && !events::commands_disabled;
return !browse_ && !undo_stack_.empty() && !events::commands_disabled;
case hotkey::HOTKEY_UNIT_DESCRIPTION:
return menu_handler_.current_unit(mouse_handler_) != units_.end();

View File

@ -67,17 +67,17 @@ void playsingle_controller::init_gui(){
void playsingle_controller::recruit(){
if (!browse_)
menu_handler_.recruit(browse_, player_number_, mouse_handler_);
menu_handler_.recruit(browse_, player_number_, mouse_handler_.get_last_hex());
}
void playsingle_controller::repeat_recruit(){
if (!browse_)
menu_handler_.repeat_recruit(player_number_, mouse_handler_);
menu_handler_.repeat_recruit(player_number_, mouse_handler_.get_last_hex());
}
void playsingle_controller::recall(){
if (!browse_)
menu_handler_.recall(player_number_, mouse_handler_);
menu_handler_.recall(player_number_, mouse_handler_.get_last_hex());
}
void playsingle_controller::toggle_shroud_updates(){
@ -420,13 +420,13 @@ void playsingle_controller::play_human_turn(){
while(!end_turn_) {
play_slice();
menu_handler_.clear_undo_stack(player_number_);
gui_->invalidate_animations();
gui_->draw();
}
}
void playsingle_controller::after_human_turn(){
menu_handler_.clear_undo_stack(player_number_);
gui_->unhighlight_reach();
}