← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1663490-ship-windows into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1663490-ship-windows into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1663490 in widelands: "Ships can have multiple windows"
  https://bugs.launchpad.net/widelands/+bug/1663490

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1663490-ship-windows/+merge/317051

Restricts number of open windows per ship to 1.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1663490-ship-windows into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/ship.cc'
--- src/logic/map_objects/tribes/ship.cc	2017-01-30 14:40:12 +0000
+++ src/logic/map_objects/tribes/ship.cc	2017-02-12 19:55:42 +0000
@@ -129,7 +129,7 @@
 }
 
 Ship::Ship(const ShipDescr& gdescr)
-   : Bob(gdescr), fleet_(nullptr), economy_(nullptr), ship_state_(ShipStates::kTransport) {
+   : Bob(gdescr), fleet_(nullptr), economy_(nullptr), ship_state_(ShipStates::kTransport), optionswindow_(nullptr) {
 }
 
 Ship::~Ship() {

=== modified file 'src/logic/map_objects/tribes/ship.h'
--- src/logic/map_objects/tribes/ship.h	2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/ship.h	2017-02-12 19:55:42 +0000
@@ -28,6 +28,8 @@
 #include "graphic/diranimations.h"
 #include "logic/map_objects/bob.h"
 
+class ShipWindow;
+
 namespace Widelands {
 
 class Economy;
@@ -243,6 +245,8 @@
 	void exp_cancel(Game&);
 	void sink_ship(Game&);
 
+	void create_options_window(InteractiveGameBase&);
+
 protected:
 	void draw(const EditorGameBase&,
 	          const TextToDraw& draw_text,
@@ -252,6 +256,8 @@
 
 private:
 	friend struct Fleet;
+	// The destructor of the class has to set optionswindow_ to nullptr
+	friend class ::ShipWindow;
 
 	void wakeup_neighbours(Game&);
 
@@ -280,6 +286,7 @@
 	std::vector<ShippingItem> items_;
 	ShipStates ship_state_;
 	std::string shipname_;
+	UI::Window* optionswindow_;
 
 	struct Expedition {
 		std::vector<Coords> seen_port_buildspaces;

=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc	2017-02-10 15:20:46 +0000
+++ src/wui/interactive_gamebase.cc	2017-02-12 19:55:42 +0000
@@ -146,7 +146,7 @@
 	for (Widelands::Bob* temp_ship : ships) {
 		if (upcast(Widelands::Ship, ship, temp_ship)) {
 			if (can_see(ship->get_owner()->player_number())) {
-				new ShipWindow(*this, *ship);
+				ship->create_options_window(*this);
 				return true;
 			}
 		}

=== modified file 'src/wui/shipwindow.cc'
--- src/wui/shipwindow.cc	2017-01-25 18:55:59 +0000
+++ src/wui/shipwindow.cc	2017-02-12 19:55:42 +0000
@@ -74,6 +74,11 @@
 		});
 }
 
+ShipWindow::~ShipWindow() {
+	assert(ship_.optionswindow_ == this);
+	ship_.optionswindow_ = nullptr;
+}
+
 void ShipWindow::init(bool avoid_fastclick) {
 	assert(ship_.get_owner());
 
@@ -177,6 +182,19 @@
 	}
 }
 
+/**
+ * Create window.
+ */
+void Ship::create_options_window(InteractiveGameBase& parent) {
+	if (optionswindow_) {
+		if (optionswindow_->is_minimal())
+			optionswindow_->restore();
+		optionswindow_->move_to_top();
+	} else {
+		optionswindow_ = new ShipWindow(parent, *this);
+	}
+}
+
 void ShipWindow::think() {
 	UI::Window::think();
 	InteractiveBase* ib = ship_.get_owner()->egbase().get_ibase();

=== modified file 'src/wui/shipwindow.h'
--- src/wui/shipwindow.h	2017-01-25 18:55:59 +0000
+++ src/wui/shipwindow.h	2017-02-12 19:55:42 +0000
@@ -37,6 +37,7 @@
 class ShipWindow : public UI::Window {
 public:
 	ShipWindow(InteractiveGameBase& igb, Widelands::Ship& ship);
+	virtual ~ShipWindow();
 
 private:
 	// Resets the vbox_ and fills it with the currently needed buttons, then positions the window.


Follow ups