remove browse_ member from controller_base.

This commit is contained in:
gfgtdf 2015-02-25 21:30:58 +01:00
parent 1a008e4de7
commit 3b16f13a18
6 changed files with 25 additions and 27 deletions

View File

@ -35,7 +35,6 @@ controller_base::controller_base(
const config& game_config, CVideo& /*video*/)
: game_config_(game_config)
, key_()
, browse_(false)
, scrolling_(false)
, joystick_manager_()
{
@ -81,21 +80,21 @@ void controller_base::handle_event(const SDL_Event& event)
SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) {
while(SDL_PeepEvents(&new_event,1,SDL_GETEVENT,
SDL_EVENTMASK(SDL_MOUSEMOTION)) > 0) {};
get_mouse_handler_base().mouse_motion_event(new_event.motion, browse_);
get_mouse_handler_base().mouse_motion_event(new_event.motion, is_browsing());
} else {
get_mouse_handler_base().mouse_motion_event(event.motion, browse_);
get_mouse_handler_base().mouse_motion_event(event.motion, is_browsing());
}
break;
case SDL_MOUSEBUTTONDOWN:
process_keydown_event(event);
get_mouse_handler_base().mouse_press(event.button, browse_);
get_mouse_handler_base().mouse_press(event.button, is_browsing());
if (get_mouse_handler_base().get_show_menu()){
show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display());
}
hotkey::mbutton_event(get_display(), event.button, get_hotkey_command_executor());
break;
case SDL_MOUSEBUTTONUP:
get_mouse_handler_base().mouse_press(event.button, browse_);
get_mouse_handler_base().mouse_press(event.button, is_browsing());
if (get_mouse_handler_base().get_show_menu()){
show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display());
}
@ -110,7 +109,7 @@ void controller_base::handle_event(const SDL_Event& event)
int x, y;
Uint8 mouse_flags = SDL_GetMouseState(&x, &y);
if ((mouse_flags & SDL_BUTTON_LEFT) == 0) {
get_mouse_handler_base().mouse_press(event.button, browse_);
get_mouse_handler_base().mouse_press(event.button, is_browsing());
}
}
}
@ -118,7 +117,7 @@ void controller_base::handle_event(const SDL_Event& event)
#endif
#if SDL_VERSION_ATLEAST(2,0,0)
case SDL_MOUSEWHEEL:
get_mouse_handler_base().mouse_wheel(event.wheel.x, event.wheel.y, browse_);
get_mouse_handler_base().mouse_wheel(event.wheel.x, event.wheel.y, is_browsing());
break;
#endif
default:
@ -285,7 +284,7 @@ void controller_base::play_slice(bool is_delay_enabled)
if (!scrolling_ && was_scrolling) {
// scrolling ended, update the cursor and the brightened hex
get_mouse_handler_base().mouse_update(browse_, highlighted_hex);
get_mouse_handler_base().mouse_update(is_browsing(), highlighted_hex);
}
}

View File

@ -62,6 +62,8 @@ public:
void play_slice(bool is_delay_enabled = true);
protected:
virtual bool is_browsing() const
{ return false; }
/**
* Get a reference to a mouse handler member a derived class uses
*/
@ -134,7 +136,6 @@ protected:
static const config &get_theme(const config& game_config, std::string theme_name);
const config& game_config_;
CKey key_;
bool browse_;
bool scrolling_;
joystick_manager joystick_manager_;
};

View File

@ -260,8 +260,6 @@ void play_controller::init(CVideo& video){
}
}
browse_ = true;
init_managers();
loadscreen::global_loadscreen->start_stage("start game");
loadscreen_manager->reset();
@ -813,11 +811,11 @@ void play_controller::redo(){
}
bool play_controller::can_undo() const {
return !linger_ && !browse_ && !events::commands_disabled && undo_stack_->can_undo();
return !linger_ && !is_browsing() && !events::commands_disabled && undo_stack_->can_undo();
}
bool play_controller::can_redo() const {
return !linger_ && !browse_ && !events::commands_disabled && undo_stack_->can_redo();
return !linger_ && !is_browsing() && !events::commands_disabled && undo_stack_->can_redo();
}
namespace {
@ -967,3 +965,13 @@ plugins_context * play_controller::get_plugins_context() {
hotkey::command_executor * play_controller::get_hotkey_command_executor() {
return hotkey_handler_.get();
}
bool play_controller::is_browsing() const
{
const team& t = current_team();
return !t.is_local_human()
|| !t.is_proxy_human()
|| linger_
|| !init_side_done_
|| this->gamestate_.gamedata_.phase() != game_data::PLAY;
}

View File

@ -193,7 +193,7 @@ public:
actions::undo_list & get_undo_stack() { return *undo_stack_; }
bool is_browsing() { return browse_; }
bool is_browsing() const OVERRIDE;
bool is_lingering() { return linger_; }
class hotkey_handler;

View File

@ -323,7 +323,6 @@ void playmp_controller::reset_end_scenario_button()
void playmp_controller::linger()
{
LOG_NG << "beginning end-of-scenario linger\n";
browse_ = true;
linger_ = true;
// If we need to set the status depending on the completion state
// we're needed here.

View File

@ -91,7 +91,7 @@ playsingle_controller::playsingle_controller(const config& level,
if (state_of_game.classification().completion == "victory" || state_of_game.classification().completion == "defeat")
{
LOG_NG << "Setting linger mode.\n";
browse_ = linger_ = true;
linger_ = true;
}
ai::game_info ai_info;
@ -615,7 +615,6 @@ possible_end_play_signal playsingle_controller::play_side()
// If new controller is not human,
// reset gui to prev human one
if (!gamestate_.board_.teams()[player_number_-1].is_local_human()) {
browse_ = true;
int s = find_human_team_before_current_player();
if (s <= 0)
s = gui_->playing_side();
@ -657,7 +656,6 @@ possible_end_play_signal playsingle_controller::play_side()
do_idle_notification();
possible_end_play_signal signal = before_human_turn();
browse_ = true;
if (!signal) {
signal = play_idle_loop();
@ -674,7 +672,6 @@ possible_end_play_signal playsingle_controller::play_side()
// If new controller is not human,
// reset gui to prev human one
if (!gamestate_.board_.teams()[player_number_-1].is_local_human()) {
browse_ = true;
int s = find_human_team_before_current_player();
if (s <= 0)
s = gui_->playing_side();
@ -702,7 +699,6 @@ possible_end_play_signal playsingle_controller::play_side()
possible_end_play_signal playsingle_controller::before_human_turn()
{
log_scope("player turn");
browse_ = false;
linger_ = false;
HANDLE_END_PLAY_SIGNAL( ai::manager::raise_turn_started() ); //This line throws exception from here: https://github.com/wesnoth/wesnoth/blob/ac96a2b91b3276e20b682210617cf87d1e0d366a/src/playsingle_controller.cpp#L954
@ -756,7 +752,6 @@ possible_end_play_signal playsingle_controller::play_human_turn() {
void playsingle_controller::linger()
{
LOG_NG << "beginning end-of-scenario linger\n";
browse_ = true;
linger_ = true;
// If we need to set the status depending on the completion state
@ -813,7 +808,6 @@ void playsingle_controller::end_turn_enable(bool enable)
void playsingle_controller::after_human_turn()
{
// Mark the turn as done.
browse_ = true;
if (!linger_)
{
recorder.end_turn();
@ -829,7 +823,6 @@ void playsingle_controller::play_ai_turn()
LOG_NG << "is ai...\n";
end_turn_enable(false);
browse_ = true;
gui_->recalculate_minimap();
const cursor::setter cursor_setter(cursor::WAIT);
@ -928,10 +921,8 @@ possible_end_play_signal playsingle_controller::check_time_over(){
void playsingle_controller::end_turn(){
if (linger_)
end_turn_ = true;
else if (!browse_){
browse_ = true;
else if (!is_browsing()){
end_turn_ = menu_handler_.end_turn(player_number_);
browse_ = end_turn_;
}
}
@ -945,7 +936,7 @@ void playsingle_controller::check_end_level()
if (level_result_ == NONE || linger_)
{
const team &t = gamestate_.board_.teams()[gui_->viewing_team()];
if (!browse_ && t.objectives_changed()) {
if (!is_browsing() && t.objectives_changed()) {
dialogs::show_objectives(get_scenario_name().str(), t.objectives());
t.reset_objectives_changed();
}