Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent the autocenter option from autochanging #1609

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,23 @@ static struct tile *find_a_focus_unit_tile_to_center_on()
}
}

namespace {
bool auto_center_enabled = true;
}

/**
* Allows disabling automatic map recentering
*/
void set_auto_center_enabled(bool enabled) { auto_center_enabled = enabled; }

/**
Center on the focus unit, if off-screen and auto_center_on_unit is true.
*/
void auto_center_on_focus_unit()
{
struct tile *ptile = find_a_focus_unit_tile_to_center_on();

if (ptile && gui_options->auto_center_on_unit
if (ptile && gui_options->auto_center_on_unit && auto_center_enabled
&& !tile_visible_and_not_on_border_mapcanvas(ptile)) {
queen()->mapview_wdg->center_on_tile(ptile);
}
Expand Down
2 changes: 2 additions & 0 deletions client/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ void unit_focus_urgent(struct unit *punit);
void unit_focus_advance();
void unit_focus_update();

void set_auto_center_enabled(bool enabled);
void auto_center_on_focus_unit();

void update_unit_pix_label(const std::vector<unit *> &units);

unit *find_visible_unit(const ::tile *ptile);
Expand Down
5 changes: 2 additions & 3 deletions client/mapctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ void map_view::shortcut_pressed(shortcut_id id)
}

if (!goto_is_active()) {
stored_autocenter = gui_options->auto_center_on_unit;
gui_options->auto_center_on_unit = false;
set_auto_center_enabled(false);
action_button_pressed(pos.x(), pos.y(), SELECT_FOCUS);
return;
}
Expand Down Expand Up @@ -393,8 +392,8 @@ void map_view::shortcut_released(Qt::MouseButton bt)
}
if (!keyboardless_goto_active || goto_is_active()) {
action_button_pressed(pos.x(), pos.y(), SELECT_POPUP);
gui_options->auto_center_on_unit = stored_autocenter;
}
set_auto_center_enabled(true);
release_goto_button(pos.x(), pos.y());
return;
}
Expand Down
1 change: 0 additions & 1 deletion client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ map_view::map_view()
timer->start(200);
resize(0, 0);
setMouseTracking(true);
stored_autocenter = gui_options->auto_center_on_unit;
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
}

Expand Down
1 change: 0 additions & 1 deletion client/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private slots:
void timer_event();

private:
bool stored_autocenter;
int cursor_frame{0};
int cursor;
freeciv::renderer *m_renderer;
Expand Down