GunChleoc has proposed merging 
lp:~widelands-dev/widelands/bug-1623375-multiplayer-starting-view into 
lp:widelands.

Commit message:
In multiplayer games, scroll to starting position when a game is loaded.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1623375 in widelands: "Map viewpoint and location markers not read in 
multiplayer mode"
  https://bugs.launchpad.net/widelands/+bug/1623375

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1623375-multiplayer-starting-view/+merge/343287

Gets rid of starting loaded multiplayer games with the map view at position 
0,0, which is often unexplored.
-- 
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug-1623375-multiplayer-starting-view into 
lp:widelands.
=== modified file 'src/logic/game.cc'
--- src/logic/game.cc	2018-04-07 16:59:00 +0000
+++ src/logic/game.cc	2018-04-16 07:18:48 +0000
@@ -452,6 +452,8 @@
 		}
 
 		if (get_ipl()) {
+			// Scroll map to startng position for new games.
+			// Loaded games are handled in GameInteractivePlayerPacket for single player, and in InteractiveGameBase::start() for multiplayer.
 			get_ipl()->map_view()->scroll_to_field(
 			   map().get_starting_pos(get_ipl()->player_number()), MapView::Transition::Jump);
 		}

=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc	2018-04-07 16:59:00 +0000
+++ src/wui/interactive_gamebase.cc	2018-04-16 07:18:48 +0000
@@ -148,6 +148,27 @@
 	hide_minimap();
 }
 
+void InteractiveGameBase::start() {
+	InteractiveBase::start();
+	// Multiplayer games don't save the view position, so we go to the starting position instead
+	if (is_multiplayer()) {
+		Widelands::PlayerNumber pln = player_number();
+		const Widelands::PlayerNumber max = game().map().get_nrplayers();
+		if (pln == 0) {
+			// Spectator, use the view of the first viable player
+			for (pln = 1; pln <= max; ++pln) {
+				if (game().get_player(pln)) {
+					break;
+				}
+			}
+		}
+		// Adding a check, just in case there was no viable player found for spectator
+		if (game().get_player(pln)) {
+			map_view()->scroll_to_field(game().map().get_starting_pos(pln), MapView::Transition::Jump);
+		}
+	}
+}
+
 void InteractiveGameBase::on_buildhelp_changed(const bool value) {
 	toggle_buildhelp_->set_perm_pressed(value);
 }

=== modified file 'src/wui/interactive_gamebase.h'
--- src/wui/interactive_gamebase.h	2018-04-07 16:59:00 +0000
+++ src/wui/interactive_gamebase.h	2018-04-16 07:18:48 +0000
@@ -92,8 +92,7 @@
 
 	void show_game_summary();
 	void postload() override;
-	void start() override {
-	}
+	void start() override;
 
 protected:
 	void draw_overlay(RenderTarget&) override;

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to