summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2014-01-19 09:26:56 +0000
committerfonsinchen <fonsinchen@openttd.org>2014-01-19 09:26:56 +0000
commitb158c7d0fa0bec2ccf885d06a9f1855ca8b3c698 (patch)
tree501d2d77868709da599734aaa413e46f1d48c544 /src
parentbe62387e4412e15fe7238a1c90979fe119c0fdcf (diff)
downloadopenttd-b158c7d0fa0bec2ccf885d06a9f1855ca8b3c698.tar.xz
(svn r26266) -Fix [FS#5860]: Update smallmap overlay if player joins different company and make sure company masks are valid
Diffstat (limited to 'src')
-rw-r--r--src/linkgraph/linkgraph_gui.h3
-rw-r--r--src/smallmap_gui.cpp11
-rw-r--r--src/smallmap_gui.h11
3 files changed, 21 insertions, 4 deletions
diff --git a/src/linkgraph/linkgraph_gui.h b/src/linkgraph/linkgraph_gui.h
index b2d74baa6..fcf81817f 100644
--- a/src/linkgraph/linkgraph_gui.h
+++ b/src/linkgraph/linkgraph_gui.h
@@ -51,8 +51,7 @@ public:
* @param company_mask Bitmask of companies to be shown.
* @param scale Desired thickness of lines and size of station dots.
*/
- LinkGraphOverlay(const Window *w, uint wid, uint32 cargo_mask = 0xFFFFFFFF,
- uint32 company_mask = 1 << _local_company, uint scale = 1) :
+ LinkGraphOverlay(const Window *w, uint wid, uint32 cargo_mask, uint32 company_mask, uint scale) :
window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
{}
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index e144ddb0c..b4137038f 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -1049,7 +1049,7 @@ void SmallMapWindow::SetupWidgetData()
SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc), refresh(FORCE_REFRESH_PERIOD)
{
_smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
- this->overlay = new LinkGraphOverlay(this, WID_SM_MAP);
+ this->overlay = new LinkGraphOverlay(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1);
this->InitNested(window_number);
this->LowerWidget(this->map_type + WID_SM_CONTOUR);
@@ -1530,7 +1530,14 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
/* Update the window every now and then */
if (--this->refresh != 0) return;
- if (this->map_type == SMT_LINKSTATS) this->overlay->RebuildCache();
+ if (this->map_type == SMT_LINKSTATS) {
+ uint32 company_mask = this->GetOverlayCompanyMask();
+ if (this->overlay->GetCompanyMask() != company_mask) {
+ this->overlay->SetCompanyMask(company_mask);
+ } else {
+ this->overlay->RebuildCache();
+ }
+ }
_smallmap_industry_highlight_state = !_smallmap_industry_highlight_state;
this->refresh = _smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD;
diff --git a/src/smallmap_gui.h b/src/smallmap_gui.h
index 4b180f547..6652f83d8 100644
--- a/src/smallmap_gui.h
+++ b/src/smallmap_gui.h
@@ -13,6 +13,7 @@
#define SMALLMAP_GUI_H
#include "industry_type.h"
+#include "company_base.h"
#include "window_gui.h"
#include "strings_func.h"
#include "blitter/factory.hpp"
@@ -135,6 +136,16 @@ protected:
this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
}
+ /**
+ * Get a bitmask for company links to be displayed. Usually this will be
+ * the _local_company. Spectators get to see all companies' links.
+ * @return Company mask.
+ */
+ inline uint32 GetOverlayCompanyMask() const
+ {
+ return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
+ }
+
uint GetNumberRowsLegend(uint columns) const;
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
void SwitchMapType(SmallMapType map_type);