← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-601398-map-location-markers into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-601398-map-location-markers into lp:widelands.

Commit message:
Persist map location markers ((Ctrl)+0-9).

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #601398 in widelands: "map location markers not stored in save game"
  https://bugs.launchpad.net/widelands/+bug/601398

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-601398-map-location-markers/+merge/293983
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-601398-map-location-markers into lp:widelands.
=== modified file 'src/game_io/game_interactive_player_packet.cc'
--- src/game_io/game_interactive_player_packet.cc	2016-01-10 11:36:05 +0000
+++ src/game_io/game_interactive_player_packet.cc	2016-05-06 08:35:13 +0000
@@ -30,7 +30,7 @@
 
 namespace Widelands {
 
-constexpr uint16_t kCurrentPacketVersion = 2;
+constexpr uint16_t kCurrentPacketVersion = 3;
 
 void GameInteractivePlayerPacket::read
 	(FileSystem & fs, Game & game, MapObjectLoader *)
@@ -39,7 +39,7 @@
 		FileRead fr;
 		fr.open(fs, "binary/interactive_player");
 		uint16_t const packet_version = fr.unsigned_16();
-		if (packet_version == kCurrentPacketVersion) {
+		if (packet_version >= 2 && packet_version <= kCurrentPacketVersion) {
 			PlayerNumber player_number = fr.unsigned_8();
 			if (!(0 < player_number && player_number <= game.map().get_nrplayers())) {
 				throw GameDataError("Invalid player number: %i.", player_number);
@@ -75,6 +75,20 @@
 			if (InteractivePlayer * const ipl = game.get_ipl()) {
 				ipl->set_player_number(player_number);
 			}
+
+			// Map landmarks
+			if (packet_version >= 3) {
+				if (InteractiveBase * const ibase = game.get_ibase()) {
+					size_t no_of_landmarks = fr.unsigned_8();
+					for (size_t i = 0; i < no_of_landmarks; ++i) {
+						uint8_t set = fr.unsigned_8();
+						Point landmark(fr.signed_32(), fr.signed_32());
+						if (set > 0) {
+							ibase->set_landmark(i, landmark);
+						}
+					}
+				}
+			}
 		} else {
 			throw UnhandledVersionError("GameInteractivePlayerPacket", packet_version, kCurrentPacketVersion);
 		}
@@ -110,6 +124,15 @@
 	// Display flags
 	fw.unsigned_32(ibase ? ibase->get_display_flags() : 0);
 
+	// Map landmarks
+	const std::vector<QuickNavigation::Landmark>& landmarks = ibase->landmarks();
+	fw.unsigned_8(landmarks.size());
+	for (const QuickNavigation::Landmark& landmark: landmarks) {
+		fw.unsigned_8(landmark.set ? 1 : 0);
+		fw.signed_32(landmark.point.x);
+		fw.signed_32(landmark.point.y);
+	}
+
 	fw.write(fs, "binary/interactive_player");
 }
 

=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc	2016-04-05 07:51:48 +0000
+++ src/wui/interactive_base.cc	2016-05-06 08:35:13 +0000
@@ -55,7 +55,6 @@
 #include "wui/mapviewpixelconstants.h"
 #include "wui/mapviewpixelfunctions.h"
 #include "wui/minimap.h"
-#include "wui/quicknavigation.h"
 #include "wui/unique_window_handler.h"
 
 using Widelands::Area;
@@ -483,6 +482,14 @@
 	}
 }
 
+const std::vector<QuickNavigation::Landmark>& InteractiveBase::landmarks() {
+	return m->quicknavigation->landmarks();
+}
+void InteractiveBase::set_landmark(size_t key, const Point& point) {
+	m->quicknavigation->set_landmark(key, point);
+}
+
+
 /**
  * Hide the minimap if it is currently shown; otherwise, do nothing.
  */

=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h	2016-04-04 08:32:37 +0000
+++ src/wui/interactive_base.h	2016-05-06 08:35:13 +0000
@@ -37,6 +37,7 @@
 #include "wui/edge_overlay_manager.h"
 #include "wui/field_overlay_manager.h"
 #include "wui/mapview.h"
+#include "wui/quicknavigation.h"
 
 namespace Widelands {struct CoordPath;}
 
@@ -144,6 +145,11 @@
 
 	void toggle_minimap();
 
+	// Returns the list of landmarks that have been mapped to the keys 0-9
+	const std::vector<QuickNavigation::Landmark>& landmarks();
+	// Sets the landmark for the keyboard 'key' to 'point'
+	void set_landmark(size_t key, const Point& point);
+
 protected:
 	// Will be called whenever the buildhelp is changed with the new 'value'.
 	virtual void on_buildhelp_changed(bool value);

=== modified file 'src/wui/quicknavigation.cc'
--- src/wui/quicknavigation.cc	2016-01-24 20:11:53 +0000
+++ src/wui/quicknavigation.cc	2016-05-06 08:35:13 +0000
@@ -28,7 +28,8 @@
 QuickNavigation::QuickNavigation
 	(const Widelands::EditorGameBase & egbase,
 	 uint32_t screenwidth, uint32_t screenheight)
-: egbase_(egbase)
+: egbase_(egbase),
+  landmarks_(10)
 {
 	screenwidth_ = screenwidth;
 	screenheight_ = screenheight;
@@ -86,6 +87,12 @@
 	havefirst_ = true;
 }
 
+void QuickNavigation::set_landmark(size_t index, const Point& point) {
+	assert(index < landmarks_.size());
+	landmarks_[index].point = point;
+	landmarks_[index].set = true;
+}
+
 bool QuickNavigation::handle_key(bool down, SDL_Keysym key)
 {
 	if (!havefirst_)
@@ -101,8 +108,7 @@
 			WLApplication::get()->get_key_state(SDL_SCANCODE_LCTRL) ||
 			WLApplication::get()->get_key_state(SDL_SCANCODE_RCTRL);
 		if (ctrl) {
-			landmarks_[which].point = current_;
-			landmarks_[which].set = true;
+			set_landmark(which, current_);
 		} else {
 			if (landmarks_[which].set)
 				setview_(landmarks_[which].point);

=== modified file 'src/wui/quicknavigation.h'
--- src/wui/quicknavigation.h	2016-01-24 20:11:53 +0000
+++ src/wui/quicknavigation.h	2016-05-06 08:35:13 +0000
@@ -39,6 +39,13 @@
  * but it is moved in its own structure to avoid overloading that class.
  */
 struct QuickNavigation {
+	struct Landmark {
+		Point point;
+		bool set;
+
+		Landmark() : set(false) {}
+	};
+
 	using SetViewFn = boost::function<void (Point)>;
 
 	QuickNavigation(const Widelands::EditorGameBase & egbase, uint32_t screenwidth, uint32_t screenheight);
@@ -47,6 +54,12 @@
 
 	void view_changed(Point point, bool jump);
 
+	// Set the landmark for 'index' to 'point'. 'index' must be < 10.
+	void set_landmark(size_t index, const Point& point);
+
+	// Returns a pointer to the first element in the landmarks array
+	const std::vector<Landmark>& landmarks() const {return landmarks_;}
+
 	bool handle_key(bool down, SDL_Keysym key);
 
 private:
@@ -75,17 +88,10 @@
 	std::vector<Point>::size_type history_index_;
 	/*@}*/
 
-	struct Landmark {
-		Point point;
-		bool set;
-
-		Landmark() : set(false) {}
-	};
-
 	/**
 	 * Landmarks that were set explicitly by the player, mapped on the 0-9 keys.
 	 */
-	Landmark landmarks_[10];
+	std::vector<Landmark> landmarks_;
 };
 
 #endif  // end of include guard: WL_WUI_QUICKNAVIGATION_H


Follow ups