Highlight and paths are now updated after moves/deaths. (bug #7028)

Additionally enemy moves do no longer unhighlight the player's
selection. I'm not sure if this is a bug or a feature.  There is a
small glitch that you have to move the mouse 1px to get the update
during enemy turns. (it should call mouse_update() somewhere)
This commit is contained in:
Martin Renold 2008-01-27 19:05:36 +00:00
parent d2dd39ef7a
commit 94c680127b
5 changed files with 45 additions and 2 deletions

View file

@ -555,7 +555,8 @@ gamemap::location ai_interface::move_unit_partial(location from, location to,
game_events::fire("sighted",to);
}
info_.disp.unhighlight_reach();
// would have to go via mousehandler to make this work:
//info_.disp.unhighlight_reach();
raise_unit_moved();
return to;

View file

@ -690,6 +690,7 @@ mouse_handler::mouse_handler(game_display* gui, std::vector<team>& teams, unit_m
gui_(gui), teams_(teams), units_(units), map_(map), status_(status), gameinfo_(gameinfo),
undo_stack_(undo_stack), redo_stack_(redo_stack)
{
singleton_ = this;
minimap_scrolling_ = false;
dragging_ = false;
dragging_started_ = false;
@ -702,6 +703,11 @@ undo_stack_(undo_stack), redo_stack_(redo_stack)
over_route_ = false;
team_num_ = 1;
attackmove_ = false;
reachmap_invalid_ = false;
}
mouse_handler::~mouse_handler()
{
singleton_ = NULL;
}
void mouse_handler::set_team(const int team_number)
@ -773,7 +779,23 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update)
last_hex_ = new_hex;
}
if (reachmap_invalid_) update = true;
if (update) {
if (reachmap_invalid_) {
reachmap_invalid_ = false;
if (!current_paths_.routes.empty()) {
unit_map::iterator u = find_unit(selected_hex_);
if(selected_hex_.valid() && u != units_.end() ) {
// reselect the unit without firing events (updates current_paths_)
select_hex(selected_hex_, true);
}
// we do never deselect here, mainly because of canceled attack-move
}
}
if(new_hex.valid() == false) {
current_route_.steps.clear();
(*gui_).set_route(NULL);
@ -1506,4 +1528,5 @@ void mouse_handler::set_current_paths(paths new_paths) {
gui_->set_route(NULL);
}
mouse_handler *mouse_handler::singleton_ = NULL;
}

View file

@ -39,6 +39,8 @@ class mouse_handler{
public:
mouse_handler(game_display* gui, std::vector<team>& teams, unit_map& units, gamemap& map,
gamestatus& status, const game_data& gameinfo, undo_list& undo_stack, undo_list& redo_stack);
~mouse_handler();
static mouse_handler* get_singleton() { return singleton_ ;}
void set_team(const int team_number);
void mouse_motion(const SDL_MouseMotionEvent& event, const bool browse);
// update the mouse with a fake mouse motion
@ -57,6 +59,8 @@ public:
void set_current_paths(paths new_paths);
void set_selected_hex(gamemap::location hex) { selected_hex_ = hex; }
void deselect_hex();
void invalidate_reachmap() { reachmap_invalid_ = true; }
void set_gui(game_display* gui) { gui_ = gui; }
void set_undo(const bool undo) { undo_ = undo; }
@ -122,6 +126,9 @@ private:
bool show_menu_;
bool over_route_;
bool attackmove_;
bool reachmap_invalid_;
static mouse_handler * singleton_;
};
extern int commands_disabled;

View file

@ -1074,7 +1074,9 @@ bool do_replay_handle(game_display& disp, const gamemap& map, const game_data& g
}
fix_shroud = !get_replay_source().is_skipping();
disp.unhighlight_reach();
// would have to go via mousehandler to make this work:
//disp.unhighlight_reach();
}
else if((child = cfg->child("attack")) != NULL) {

View file

@ -30,6 +30,7 @@
#include "sound.hpp"
#include "unit_display.hpp"
#include "util.hpp"
#include "mouse_events.hpp"
#include <cassert>
#include <climits>
@ -142,6 +143,11 @@ void move_unit(const std::vector<gamemap::location>& path, unit& u, const std::v
u.set_hidden(was_hidden);
disp->invalidate_unit_after_move(path[0], path[path.size()-1]);
events::mouse_handler* mousehandler = events::mouse_handler::get_singleton();
if (mousehandler) {
mousehandler->invalidate_reachmap();
}
}
void unit_die(const gamemap::location& loc, unit& loser,
@ -158,6 +164,10 @@ void unit_die(const gamemap::location& loc, unit& loser,
animator.start_animations();
animator.wait_for_end();
events::mouse_handler* mousehandler = events::mouse_handler::get_singleton();
if (mousehandler) {
mousehandler->invalidate_reachmap();
}
}