diff options
-rw-r--r-- | src/industry_gui.cpp | 47 | ||||
-rw-r--r-- | src/lang/english.txt | 2 | ||||
-rw-r--r-- | src/smallmap_gui.cpp | 15 |
3 files changed, 63 insertions, 1 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index c3837160b..97b7cf983 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -12,6 +12,8 @@ #include "stdafx.h" #include "openttd.h" #include "gui.h" +#include "sound_func.h" +#include "window_func.h" #include "textbuf_gui.h" #include "command_func.h" #include "viewport_func.h" @@ -34,11 +36,15 @@ #include "core/random_func.hpp" #include "core/backup_type.hpp" #include "genworld.h" +#include "smallmap_gui.h" #include "table/strings.h" #include "table/sprites.h" bool _ignore_restrictions; +uint64 _displayed_industries; ///< Communication from the industry chain window to the smallmap window about what industries to display. + +assert_compile(NUM_INDUSTRYTYPES <= 64); // Make sure all industry types fit in _displayed_industries. /** Cargo suffix type (for which window is it requested) */ enum CargoSuffixType { @@ -1289,6 +1295,7 @@ void ShowIndustryDirectory() /** Widget numbers of the industry cargoes window, */ enum IndustryCargoesWidgets { ICW_CAPTION, + ICW_NOTIFY, ICW_PANEL, ICW_SCROLLBAR, }; @@ -1302,7 +1309,14 @@ static const NWidgetPart _nested_industry_cargoes_widgets[] = { NWidget(WWT_STICKYBOX, COLOUR_BROWN), EndContainer(), NWidget(NWID_HORIZONTAL), - NWidget(WWT_PANEL, COLOUR_BROWN, ICW_PANEL), SetResize(1, 10), SetMinimalSize(200, 90), EndContainer(), + NWidget(NWID_VERTICAL), + NWidget(WWT_PANEL, COLOUR_BROWN, ICW_PANEL), SetResize(1, 10), SetMinimalSize(200, 90), EndContainer(), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_TEXTBTN, COLOUR_BROWN, ICW_NOTIFY), + SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP), + NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(1, 0), EndContainer(), + EndContainer(), + EndContainer(), NWidget(NWID_VERTICAL), NWidget(WWT_SCROLLBAR, COLOUR_BROWN, ICW_SCROLLBAR), NWidget(WWT_RESIZEBOX, COLOUR_BROWN), @@ -2109,6 +2123,18 @@ struct IndustryCargoesWindow : public Window { } /** + * Notify smallmap that new displayed industries have been selected (in #_displayed_industries). + */ + void NotifySmallmap() + { + if (!this->IsWidgetLowered(ICW_NOTIFY)) return; + + /* Only notify the smallmap window if it exists. In particular, do not + * bring it to the front to prevent messing up any nice layout of the user. */ + InvalidateWindowClassesData(WC_SMALLMAP, 0); + } + + /** * Compute what and where to display for industry type \a it. * @param it Industry type to display. */ @@ -2116,6 +2142,7 @@ struct IndustryCargoesWindow : public Window { { this->GetWidget<NWidgetCore>(ICW_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION; this->ind_cargo = it; + _displayed_industries = 1 << it; this->fields.Clear(); CargoesRow *row = this->fields.Append(); @@ -2159,10 +2186,12 @@ struct IndustryCargoesWindow : public Window { if (HasCommonValidCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo), indsp->produced_cargo, lengthof(indsp->produced_cargo))) { this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it); + SetBit(_displayed_industries, it); supp_count++; } if (HasCommonValidCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo), indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) { this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it); + SetBit(_displayed_industries, it); cust_count++; } } @@ -2180,6 +2209,7 @@ struct IndustryCargoesWindow : public Window { const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(ICW_PANEL); this->vscroll.SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y)); this->SetDirty(); + this->NotifySmallmap(); } /** @@ -2190,6 +2220,7 @@ struct IndustryCargoesWindow : public Window { { this->GetWidget<NWidgetCore>(ICW_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION; this->ind_cargo = cid + NUM_INDUSTRYTYPES; + _displayed_industries = 0; this->fields.Clear(); CargoesRow *row = this->fields.Append(); @@ -2224,10 +2255,12 @@ struct IndustryCargoesWindow : public Window { if (HasCommonValidCargo(&cid, 1, indsp->produced_cargo, lengthof(indsp->produced_cargo))) { this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it); + SetBit(_displayed_industries, it); supp_count++; } if (HasCommonValidCargo(&cid, 1, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) { this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it); + SetBit(_displayed_industries, it); cust_count++; } } @@ -2244,6 +2277,7 @@ struct IndustryCargoesWindow : public Window { const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(ICW_PANEL); this->vscroll.SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y)); this->SetDirty(); + this->NotifySmallmap(); } /** @@ -2376,6 +2410,17 @@ struct IndustryCargoesWindow : public Window { } break; } + + case ICW_NOTIFY: + this->ToggleWidgetLoweredState(ICW_NOTIFY); + this->SetWidgetDirty(ICW_NOTIFY); + SndPlayFx(SND_15_BEEP); + + if (this->IsWidgetLowered(ICW_NOTIFY)) { + if (FindWindowByClass(WC_SMALLMAP) == NULL) ShowSmallMap(); + this->NotifySmallmap(); + } + break; } } diff --git a/src/lang/english.txt b/src/lang/english.txt index f5e8c91db..41b57a139 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2131,6 +2131,8 @@ STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP :{BLACK}Click at STR_INDUSTRY_CARGOES_CARGO_TOOLTIP :{BLACK}{STRING}{}Click at the cargo to see its suppliers and customers STR_INDUSTRY_DISPLAY_CHAIN :{BLACK}Display chain STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP :{BLACK}Display cargo supplying and accepting industries +STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP :{BLACK}Link to smallmap +STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP :{BLACK}Select the displayed industries at the smallmap as well # Land area window STR_LAND_AREA_INFORMATION_CAPTION :{WHITE}Land Area Information diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index af2cc1e6a..e73401c32 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1278,6 +1278,21 @@ public: } } + /** + * Notifications for the smallmap window. + * - data = 0: Displayed industries at the industry chain window have changed. + */ + virtual void OnInvalidateData(int data) + { + extern uint64 _displayed_industries; + if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY); + + for (int i = 0; i != _smallmap_industry_count; i++) { + _legend_from_industries[i].show_on_map = HasBit(_displayed_industries, _legend_from_industries[i].u.type); + } + this->SetDirty(); + } + virtual bool OnRightClick(Point pt, int widget) { if (widget != SM_WIDGET_MAP || _scrolling_viewport) return false; |