Auto center the map on load.

Stops all PG campaigns from starting with their view pointed way up
north at the empty mountains.
This commit is contained in:
Dan Albert 2021-05-07 14:55:22 -07:00
parent 977845e2f4
commit 0ec5346574

View File

@ -202,11 +202,12 @@ class QLiberationMap(QGraphicsView):
self.setDragMode(QGraphicsView.ScrollHandDrag) self.setDragMode(QGraphicsView.ScrollHandDrag)
def setGame(self, game: Optional[Game]): def setGame(self, game: Optional[Game]):
should_recenter = self.game is None
self.game = game self.game = game
if self.game is not None: if self.game is not None:
logging.debug("Reloading Map Canvas") logging.debug("Reloading Map Canvas")
self.nm_to_pixel_ratio = self.distance_to_pixels(nautical_miles(1)) self.nm_to_pixel_ratio = self.distance_to_pixels(nautical_miles(1))
self.reload_scene() self.reload_scene(should_recenter)
""" """
@ -597,7 +598,13 @@ class QLiberationMap(QGraphicsView):
self.draw_threat_range(scene, group, ground_object, cp) self.draw_threat_range(scene, group, ground_object, cp)
added_objects.append(ground_object.obj_name) added_objects.append(ground_object.obj_name)
def reload_scene(self): def recenter(self) -> None:
center = self._transform_point(
self.game.theater.terrain.map_view_default.position
)
self.centerOn(QPointF(center[0], center[1]))
def reload_scene(self, recenter: bool = False) -> None:
scene = self.scene() scene = self.scene()
scene.clear() scene.clear()
@ -605,6 +612,8 @@ class QLiberationMap(QGraphicsView):
enemyColor = self.game.get_enemy_color() enemyColor = self.game.get_enemy_color()
self.addBackground() self.addBackground()
if recenter:
self.recenter()
# Display Culling # Display Culling
if DisplayOptions.culling and self.game.settings.perf_culling: if DisplayOptions.culling and self.game.settings.perf_culling: