fix bug #6311, bug #7132 and partially bug #5720; make bug #7028 more visible

* deselect units before moving, not after moving

* allow to prepare next move during move/fight

* fine-tuned mouse code
This commit is contained in:
Martin Renold 2008-01-20 13:12:13 +00:00
parent 10947e68d6
commit c42ed823d7
7 changed files with 46 additions and 49 deletions

View file

@ -15,6 +15,11 @@ Version 1.3.14+svn:
* Made ESC clear hotkey when changing hotkeys
* Made quick replay skip messages
* linger mode overlay is also drawn over fog and shroud (bug #10811)
* Units are deselected before they move.
* The next move can be prepared before the current attack/move
animation finishes (bug #7132).
* If a move is interrupted, footsteps are drawn again.
* Tuned some details of the mouse handling.
* miscellaneous and bug fixes:
* Fixed boost test compile with 1.34.1
* Make wesnoth work properly again if the datadir contains ../

View file

@ -11,6 +11,10 @@ Version 1.3.14+svn:
* Made ESC clear hotkey when changing hotkeys.
* Made quick replay skip messages
* Linger mode overlay is also drawn over fog and shroud.
* Units are deselected before they move.
* The next move can be prepared before the current attack/move
animation finishes (bug #7132).
* If a move is interrupted, footsteps are drawn again.
* Miscellaneous and bug fixes
* Added a more graceful handling of maps without a header.

View file

@ -2156,10 +2156,6 @@ size_t move_unit(game_display* disp, const game_data& gamedata,
// Show the final move animation step
disp->draw();
// Clear display helpers before firing events
disp->unhighlight_reach();
disp->set_route(NULL);
// Do not show it yet to avoid flickering before the attack dialog
disp->draw(false);
}
if(game_events::fire("moveto",steps.back())) {
event_mutated = true;
@ -2352,8 +2348,6 @@ void apply_shroud_changes(undo_list& undos, game_display* disp, const gamestatus
disp->invalidate_game_status();
clear_shroud(*disp,status,map,gamedata,units,teams,team);
disp->recalculate_minimap();
disp->unhighlight_reach();
disp->set_route(NULL);
disp->invalidate_all();
} else {
recalculate_fog(map,status,gamedata,units,teams,team);

View file

@ -1313,8 +1313,8 @@ private:
redo_stack_.push_back(action);
undo_stack_.pop_back();
mousehandler.set_selected_hex(gamemap::location());
mousehandler.set_current_paths(paths());
//mousehandler.set_selected_hex(gamemap::location());
//mousehandler.set_current_paths(paths());
recorder.undo();
@ -1335,8 +1335,8 @@ private:
const events::command_disabler disable_commands;
//clear routes, selected hex, etc
mousehandler.set_selected_hex(gamemap::location());
mousehandler.set_current_paths(paths());
//mousehandler.set_selected_hex(gamemap::location());
//mousehandler.set_current_paths(paths());
undo_action& action = redo_stack_.back();
if(action.is_recall()) {

View file

@ -701,6 +701,7 @@ undo_stack_(undo_stack), redo_stack_(redo_stack), game_state_(game_state)
show_menu_ = false;
over_route_ = false;
team_num_ = 1;
attackmove_ = false;
}
void mouse_handler::set_team(const int team_number)
@ -722,6 +723,8 @@ void mouse_handler::mouse_update(const bool browse)
void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update)
{
if(attackmove_) return;
if(minimap_scrolling_) {
//if the game is run in a window, we could miss a LMB/MMB up event
// if it occurs outside our window.
@ -980,6 +983,7 @@ paths::route mouse_handler::get_route(unit_map::const_iterator un, gamemap::loca
void mouse_handler::mouse_press(const SDL_MouseButtonEvent& event, const bool browse)
{
if(attackmove_) return;
show_menu_ = false;
mouse_update(browse);
int scrollx = 0;
@ -1113,7 +1117,7 @@ void mouse_handler::left_click(const SDL_MouseButtonEvent& event, const bool bro
return;
}
}
else if (move_unit_along_current_route(false)) {//move the unit without updating shroud
else if (move_unit_along_current_route(false, true)) {//move the unit without updating shroud
// a WML event could have invalidated both attacker and defender
// so make sure they're valid before attacking
u = find_unit(attack_from);
@ -1131,6 +1135,10 @@ void mouse_handler::left_click(const SDL_MouseButtonEvent& event, const bool bro
}
}
}
// reselect the unit to make the attacker's stats appear during the attack dialog
gui_->select_hex(attack_from);
if(!commands_disabled && attack_enemy(u,enemy) == false) {
undo_ = true;
selected_hex_ = src;
@ -1179,6 +1187,8 @@ void mouse_handler::left_click(const SDL_MouseButtonEvent& event, const bool bro
u != units_.end() && u->second.side() == team_num_ &&
clicked_u == units_.end() && !current_route_.steps.empty() &&
current_route_.steps.front() == selected_hex_) {
gui_->unhighlight_reach();
move_unit_along_current_route(check_shroud);
} else {
// we select a (maybe empty) hex
@ -1230,27 +1240,33 @@ void mouse_handler::clear_undo_stack()
undo_stack_.clear();
}
bool mouse_handler::move_unit_along_current_route(bool check_shroud)
bool mouse_handler::move_unit_along_current_route(bool check_shroud, bool attackmove)
{
const std::vector<gamemap::location> steps = current_route_.steps;
if(steps.empty()) {
return false;
}
// do not show footsteps during movement
gui_->set_route(NULL);
// do not keep the hex highlighted that we started from
selected_hex_ = gamemap::location();
gui_->select_hex(gamemap::location());
// will be invalid after the move
current_paths_ = paths();
current_route_.steps.clear();
attackmove_ = attackmove;
const size_t moves = ::move_unit(gui_,gameinfo_,status_,map_,units_,teams_,
steps,&recorder,&undo_stack_,&next_unit_,false,check_shroud);
attackmove_ = false;
cursor::set(cursor::NORMAL);
gui_->invalidate_game_status();
selected_hex_ = gamemap::location();
gui_->select_hex(gamemap::location());
gui_->set_route(NULL);
gui_->unhighlight_reach();
current_paths_ = paths();
if(moves == 0)
return false;
@ -1262,29 +1278,13 @@ bool mouse_handler::move_unit_along_current_route(bool check_shroud)
//u may be equal to units_.end() in the case of e.g. a [teleport]
if(u != units_.end()) {
//Reselect the unit if the move was interrupted
if(dst != steps.back()) {
selected_hex_ = dst;
gui_->select_hex(dst);
}
current_route_.steps.clear();
//check if we are now adjacent to an enemy,
//we reselect the unit (old 1.2.x behavior)
gamemap::location adj[6];
get_adjacent_tiles(dst,adj);
for(int i = 0; i != 6; i++) {
unit_map::iterator adj_unit = find_unit(adj[i]);
if (adj_unit != units_.end() && current_team().is_enemy(adj_unit->second.side())) {
selected_hex_ = dst;
gui_->select_hex(dst);
const bool teleport = u->second.get_ability_bool("teleport",u->first);
current_paths_ = paths(map_,status_,gameinfo_,units_,dst,teams_,
false,teleport,viewing_team(),path_turns_);
show_attack_options(u);
gui_->highlight_reach(current_paths_);
break;
// the move was interrupted (or never started)
if (u->second.movement_left() > 0) {
// reselect the unit (for "press t to continue")
select_hex(dst, false);
// the new discovery is more important than the new movement range
gui_->unhighlight_reach();
}
}
}
@ -1424,10 +1424,6 @@ bool mouse_handler::attack_enemy_(unit_map::iterator attacker, unit_map::iterato
dialogs::advance_unit(gameinfo_,map_,units_,attacker_loc,*gui_);
dialogs::advance_unit(gameinfo_,map_,units_,defender_loc,*gui_,!defender_human);
selected_hex_ = gamemap::location();
current_route_.steps.clear();
gui_->set_route(NULL);
check_victory(units_, teams_, *gui_);
gui_->draw();

View file

@ -74,7 +74,7 @@ private:
void left_click(const SDL_MouseButtonEvent& event, const bool browse);
void select_hex(const gamemap::location& hex, const bool browse);
void clear_undo_stack();
bool move_unit_along_current_route(bool check_shroud=true);
bool move_unit_along_current_route(bool check_shroud, bool attackmove=false);
// wrapper to catch bad_alloc so this should be called
bool attack_enemy(unit_map::iterator attacker, unit_map::iterator defender);
// the real function but can throw bad_alloc
@ -121,6 +121,7 @@ private:
bool undo_;
bool show_menu_;
bool over_route_;
bool attackmove_;
};
extern int commands_disabled;

View file

@ -140,9 +140,6 @@ void move_unit(const std::vector<gamemap::location>& path, unit& u, const std::v
u.set_facing(path[path.size()-2].get_relative_dir(path[path.size()-1]));
u.set_standing(path[path.size()-1]);
// Clean the footsteps path, its hexes will be invalidated if needed
disp->set_route(NULL);
u.set_hidden(was_hidden);
disp->invalidate_unit();
}