← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/expedition_portspace_indicator into lp:widelands

 

Benedikt Straub has proposed merging lp:~widelands-dev/widelands/expedition_portspace_indicator into lp:widelands.

Commit message:
Show a port icon on the field where an expedition ship can build a port

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1826655 in widelands: "Highlight where expedition ship will build port"
  https://bugs.launchpad.net/widelands/+bug/1826655

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/expedition_portspace_indicator/+merge/366640
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/expedition_portspace_indicator into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/ship.cc'
--- src/logic/map_objects/tribes/ship.cc	2019-04-26 20:38:39 +0000
+++ src/logic/map_objects/tribes/ship.cc	2019-04-29 10:21:04 +0000
@@ -48,6 +48,7 @@
 #include "logic/widelands_geometry_io.h"
 #include "map_io/map_object_loader.h"
 #include "map_io/map_object_saver.h"
+#include "wui/interactive_base.h"
 
 namespace Widelands {
 
@@ -435,6 +436,16 @@
 			             "images/wui/editor/fsel_editor_set_port_space.png");
 		}
 	}
+
+	if (InteractiveBase* ibase = game.get_ibase()) {
+		if (ibase->get_player() == get_owner()) {
+			if (ship_state_ == ShipStates::kExpeditionPortspaceFound) {
+				ibase->show_expedition_port_space(this, expedition_->seen_port_buildspaces.front());
+			} else {
+				ibase->hide_expedition_port_space(this);
+			}
+		}
+	}
 }
 
 void Ship::ship_update_idle(Game& game, Bob::State& state) {

=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc	2019-04-25 06:31:33 +0000
+++ src/wui/interactive_base.cc	2019-04-29 10:21:04 +0000
@@ -304,6 +304,28 @@
 void InteractiveBase::on_buildhelp_changed(bool /* value */) {
 }
 
+void InteractiveBase::show_expedition_port_space(Widelands::Ship* ship, const Widelands::Coords& coords) {
+	expedition_port_spaces_.emplace(std::make_pair(ship, coords));
+}
+
+void InteractiveBase::hide_expedition_port_space(Widelands::Ship* ship) {
+	for (auto it = expedition_port_spaces_.begin(); it != expedition_port_spaces_.end(); ++it) {
+		if (it->first == ship) {
+			expedition_port_spaces_.erase(it);
+			return;
+		}
+	}
+}
+
+bool InteractiveBase::has_expedition_port_space(const Widelands::Coords& coords) const {
+	for (const auto& pair : expedition_port_spaces_) {
+		if (pair.second == coords) {
+			return true;
+		}
+	}
+	return false;
+}
+
 // Show the given workareas at the given coords and returns the overlay job id associated
 void InteractiveBase::show_workarea(const WorkareaInfo& workarea_info, Widelands::Coords coords) {
 	workarea_previews_[coords] = &workarea_info;

=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h	2019-04-25 06:31:33 +0000
+++ src/wui/interactive_base.h	2019-04-29 10:21:04 +0000
@@ -86,6 +86,10 @@
 	void show_workarea(const WorkareaInfo& workarea_info, Widelands::Coords coords);
 	void hide_workarea(const Widelands::Coords& coords);
 
+	void show_expedition_port_space(Widelands::Ship*, const Widelands::Coords&);
+	void hide_expedition_port_space(Widelands::Ship*);
+	bool has_expedition_port_space(const Widelands::Coords&) const;
+
 	//  point of view for drawing
 	virtual Widelands::Player* get_player() const = 0;
 
@@ -291,6 +295,8 @@
 	// coordinate that the building that shows the work area is positioned.
 	std::map<Widelands::Coords, const WorkareaInfo*> workarea_previews_;
 
+	std::map<Widelands::Ship*, Widelands::Coords> expedition_port_spaces_;
+
 	RoadBuildingOverlays road_building_overlays_;
 
 	std::unique_ptr<Notifications::Subscriber<GraphicResolutionChanged>>

=== modified file 'src/wui/interactive_player.cc'
--- src/wui/interactive_player.cc	2019-04-25 06:31:33 +0000
+++ src/wui/interactive_player.cc	2019-04-29 10:21:04 +0000
@@ -339,8 +339,10 @@
 
 		if (f->vision > 0) {
 			// Draw build help.
-			if (buildhelp()) {
-				const auto* overlay = get_buildhelp_overlay(plr.get_buildcaps(f->fcoords));
+			bool show_port_space = has_expedition_port_space(f->fcoords);
+			if (show_port_space || buildhelp()) {
+				const auto* overlay = get_buildhelp_overlay(show_port_space ?
+						f->fcoords.field->maxcaps() : plr.get_buildcaps(f->fcoords));
 				if (overlay != nullptr) {
 					blit_field_overlay(dst, *f, overlay->pic, overlay->hotspot, scale);
 				}


Follow ups