00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "../window_gui.h"
00014 #include "../window_func.h"
00015 #include "../company_base.h"
00016 #include "../company_gui.h"
00017 #include "../date_func.h"
00018 #include "../viewport_func.h"
00019 #include "../smallmap_gui.h"
00020 #include "../core/geometry_func.hpp"
00021 #include "../widgets/link_graph_legend_widget.h"
00022
00023 #include "table/strings.h"
00024
00029 const uint8 LinkGraphOverlay::LINK_COLOURS[] = {
00030 0x0f, 0xd1, 0xd0, 0x57,
00031 0x55, 0x53, 0xbf, 0xbd,
00032 0xba, 0xb9, 0xb7, 0xb5
00033 };
00034
00039 void LinkGraphOverlay::GetWidgetDpi(DrawPixelInfo *dpi) const
00040 {
00041 const NWidgetBase *wi = this->window->GetWidget<NWidgetBase>(this->widget_id);
00042 dpi->left = dpi->top = 0;
00043 dpi->width = wi->current_x;
00044 dpi->height = wi->current_y;
00045 }
00046
00050 void LinkGraphOverlay::RebuildCache()
00051 {
00052 this->cached_links.clear();
00053 this->cached_stations.clear();
00054 if (this->company_mask == 0) return;
00055
00056 DrawPixelInfo dpi;
00057 this->GetWidgetDpi(&dpi);
00058
00059 const Station *sta;
00060 FOR_ALL_STATIONS(sta) {
00061 if (sta->rect.IsEmpty()) continue;
00062
00063 Point pta = this->GetStationMiddle(sta);
00064
00065 StationID from = sta->index;
00066 StationLinkMap &seen_links = this->cached_links[from];
00067
00068 uint supply = 0;
00069 CargoID c;
00070 FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) {
00071 if (!CargoSpec::Get(c)->IsValid()) continue;
00072 if (!LinkGraph::IsValidID(sta->goods[c].link_graph)) continue;
00073 const LinkGraph &lg = *LinkGraph::Get(sta->goods[c].link_graph);
00074
00075 ConstNode from_node = lg[sta->goods[c].node];
00076 supply += lg.Monthly(from_node.Supply());
00077 for (ConstEdgeIterator i = from_node.Begin(); i != from_node.End(); ++i) {
00078 StationID to = lg[i->first].Station();
00079 assert(from != to);
00080 if (!Station::IsValidID(to) || seen_links.find(to) != seen_links.end()) {
00081 continue;
00082 }
00083 const Station *stb = Station::Get(to);
00084 assert(sta != stb);
00085
00086
00087 if (stb->owner != OWNER_NONE && sta->owner != OWNER_NONE && !HasBit(this->company_mask, stb->owner)) continue;
00088 if (stb->rect.IsEmpty()) continue;
00089
00090 if (!this->IsLinkVisible(pta, this->GetStationMiddle(stb), &dpi)) continue;
00091
00092 this->AddLinks(sta, stb);
00093 seen_links[to];
00094 }
00095 }
00096 if (this->IsPointVisible(pta, &dpi)) {
00097 this->cached_stations.push_back(std::make_pair(from, supply));
00098 }
00099 }
00100 }
00101
00109 inline bool LinkGraphOverlay::IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding) const
00110 {
00111 return pt.x > dpi->left - padding && pt.y > dpi->top - padding &&
00112 pt.x < dpi->left + dpi->width + padding &&
00113 pt.y < dpi->top + dpi->height + padding;
00114 }
00115
00124 inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding) const
00125 {
00126 return !((pta.x < dpi->left - padding && ptb.x < dpi->left - padding) ||
00127 (pta.y < dpi->top - padding && ptb.y < dpi->top - padding) ||
00128 (pta.x > dpi->left + dpi->width + padding &&
00129 ptb.x > dpi->left + dpi->width + padding) ||
00130 (pta.y > dpi->top + dpi->height + padding &&
00131 ptb.y > dpi->top + dpi->height + padding));
00132 }
00133
00139 void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
00140 {
00141 CargoID c;
00142 FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) {
00143 if (!CargoSpec::Get(c)->IsValid()) continue;
00144 const GoodsEntry &ge = from->goods[c];
00145 if (!LinkGraph::IsValidID(ge.link_graph) ||
00146 ge.link_graph != to->goods[c].link_graph) {
00147 continue;
00148 }
00149 const LinkGraph &lg = *LinkGraph::Get(ge.link_graph);
00150 ConstEdge edge = lg[ge.node][to->goods[c].node];
00151 if (edge.Capacity() > 0) {
00152 this->AddStats(lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()),
00153 ge.GetSumFlowVia(to->index), from->owner == OWNER_NONE || to->owner == OWNER_NONE,
00154 this->cached_links[from->index][to->index]);
00155 }
00156 }
00157 }
00158
00169 void LinkGraphOverlay::AddStats(uint new_cap, uint new_usg, uint new_plan, bool new_shared, LinkProperties &cargo)
00170 {
00171
00172 if (cargo.capacity == 0 ||
00173 max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < max(new_usg, new_plan) * 32 / (new_cap + 1)) {
00174 cargo.capacity = new_cap;
00175 cargo.usage = new_usg;
00176 cargo.planned = new_plan;
00177 }
00178 if (new_shared) cargo.shared = true;
00179 }
00180
00185 void LinkGraphOverlay::Draw(const DrawPixelInfo *dpi) const
00186 {
00187 this->DrawLinks(dpi);
00188 this->DrawStationDots(dpi);
00189 }
00190
00195 void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const
00196 {
00197 for (LinkMap::const_iterator i(this->cached_links.begin()); i != this->cached_links.end(); ++i) {
00198 if (!Station::IsValidID(i->first)) continue;
00199 Point pta = this->GetStationMiddle(Station::Get(i->first));
00200 for (StationLinkMap::const_iterator j(i->second.begin()); j != i->second.end(); ++j) {
00201 if (!Station::IsValidID(j->first)) continue;
00202 Point ptb = this->GetStationMiddle(Station::Get(j->first));
00203 if (!this->IsLinkVisible(pta, ptb, dpi, this->scale + 2)) continue;
00204 this->DrawContent(pta, ptb, j->second);
00205 }
00206 }
00207 }
00208
00215 void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const
00216 {
00217 uint usage_or_plan = min(cargo.capacity * 2 + 1, max(cargo.usage, cargo.planned));
00218 int colour = LinkGraphOverlay::LINK_COLOURS[usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS) / (cargo.capacity * 2 + 2)];
00219 int dash = cargo.shared ? this->scale * 4 : 0;
00220
00221
00222
00223 int side = _settings_game.vehicle.road_side ? 1 : -1;
00224 if (abs(pta.x - ptb.x) < abs(pta.y - ptb.y)) {
00225 int offset_x = (pta.y > ptb.y ? 1 : -1) * side * this->scale;
00226 GfxDrawLine(pta.x + offset_x, pta.y, ptb.x + offset_x, ptb.y, colour, this->scale, dash);
00227 } else {
00228 int offset_y = (pta.x < ptb.x ? 1 : -1) * side * this->scale;
00229 GfxDrawLine(pta.x, pta.y + offset_y, ptb.x, ptb.y + offset_y, colour, this->scale, dash);
00230 }
00231
00232 GfxDrawLine(pta.x, pta.y, ptb.x, ptb.y, _colour_gradient[COLOUR_GREY][1], this->scale);
00233 }
00234
00239 void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
00240 {
00241 for (StationSupplyList::const_iterator i(this->cached_stations.begin()); i != this->cached_stations.end(); ++i) {
00242 const Station *st = Station::GetIfValid(i->first);
00243 if (st == NULL) continue;
00244 Point pt = this->GetStationMiddle(st);
00245 if (!this->IsPointVisible(pt, dpi, 3 * this->scale)) continue;
00246
00247 uint r = this->scale * 2 + this->scale * 2 * min(200, i->second) / 200;
00248
00249 LinkGraphOverlay::DrawVertex(pt.x, pt.y, r,
00250 _colour_gradient[st->owner != OWNER_NONE ?
00251 (Colours)Company::Get(st->owner)->colour : COLOUR_GREY][5],
00252 _colour_gradient[COLOUR_GREY][1]);
00253 }
00254 }
00255
00264 void LinkGraphOverlay::DrawVertex(int x, int y, int size, int colour, int border_colour)
00265 {
00266 size--;
00267 int w1 = size / 2;
00268 int w2 = size / 2 + size % 2;
00269
00270 GfxFillRect(x - w1, y - w1, x + w2, y + w2, colour);
00271
00272 w1++;
00273 w2++;
00274 GfxDrawLine(x - w1, y - w1, x + w2, y - w1, border_colour);
00275 GfxDrawLine(x - w1, y + w2, x + w2, y + w2, border_colour);
00276 GfxDrawLine(x - w1, y - w1, x - w1, y + w2, border_colour);
00277 GfxDrawLine(x + w2, y - w1, x + w2, y + w2, border_colour);
00278 }
00279
00285 Point LinkGraphOverlay::GetStationMiddle(const Station *st) const
00286 {
00287 if (this->window->viewport != NULL) {
00288 return GetViewportStationMiddle(this->window->viewport, st);
00289 } else {
00290
00291 return static_cast<const SmallMapWindow *>(this->window)->GetStationMiddle(st);
00292 }
00293 }
00294
00299 void LinkGraphOverlay::SetCargoMask(uint32 cargo_mask)
00300 {
00301 this->cargo_mask = cargo_mask;
00302 this->RebuildCache();
00303 this->window->GetWidget<NWidgetBase>(this->widget_id)->SetDirty(this->window);
00304 }
00305
00310 void LinkGraphOverlay::SetCompanyMask(uint32 company_mask)
00311 {
00312 this->company_mask = company_mask;
00313 this->RebuildCache();
00314 this->window->GetWidget<NWidgetBase>(this->widget_id)->SetDirty(this->window);
00315 }
00316
00318 NWidgetBase *MakeCompanyButtonRowsLinkGraphGUI(int *biggest_index)
00319 {
00320 return MakeCompanyButtonRows(biggest_index, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST, 3, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES);
00321 }
00322
00323 NWidgetBase *MakeSaturationLegendLinkGraphGUI(int *biggest_index)
00324 {
00325 NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
00326 for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS); ++i) {
00327 NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST);
00328 wid->SetMinimalSize(50, FONT_HEIGHT_SMALL);
00329 wid->SetFill(1, 1);
00330 wid->SetResize(0, 0);
00331 panel->Add(wid);
00332 }
00333 *biggest_index = WID_LGL_SATURATION_LAST;
00334 return panel;
00335 }
00336
00337 NWidgetBase *MakeCargoesLegendLinkGraphGUI(int *biggest_index)
00338 {
00339 static const uint ENTRIES_PER_ROW = CeilDiv(NUM_CARGO, 5);
00340 NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
00341 NWidgetHorizontal *row = NULL;
00342 for (uint i = 0; i < NUM_CARGO; ++i) {
00343 if (i % ENTRIES_PER_ROW == 0) {
00344 if (row) panel->Add(row);
00345 row = new NWidgetHorizontal(NC_EQUALSIZE);
00346 }
00347 NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST);
00348 wid->SetMinimalSize(25, FONT_HEIGHT_SMALL);
00349 wid->SetFill(1, 1);
00350 wid->SetResize(0, 0);
00351 row->Add(wid);
00352 }
00353
00354 for (uint i = 0; i < 4 - (NUM_CARGO - 1) % 5; ++i) {
00355 NWidgetSpacer *spc = new NWidgetSpacer(25, FONT_HEIGHT_SMALL);
00356 spc->SetFill(1, 1);
00357 spc->SetResize(0, 0);
00358 row->Add(spc);
00359 }
00360 panel->Add(row);
00361 *biggest_index = WID_LGL_CARGO_LAST;
00362 return panel;
00363 }
00364
00365
00366 static const NWidgetPart _nested_linkgraph_legend_widgets[] = {
00367 NWidget(NWID_HORIZONTAL),
00368 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
00369 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_LGL_CAPTION), SetDataTip(STR_LINKGRAPH_LEGEND_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00370 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
00371 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
00372 EndContainer(),
00373 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
00374 NWidget(NWID_HORIZONTAL),
00375 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_LGL_SATURATION),
00376 SetPadding(WD_FRAMERECT_TOP, 0, WD_FRAMERECT_BOTTOM, WD_CAPTIONTEXT_LEFT),
00377 NWidgetFunction(MakeSaturationLegendLinkGraphGUI),
00378 EndContainer(),
00379 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_LGL_COMPANIES),
00380 SetPadding(WD_FRAMERECT_TOP, 0, WD_FRAMERECT_BOTTOM, WD_CAPTIONTEXT_LEFT),
00381 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
00382 NWidgetFunction(MakeCompanyButtonRowsLinkGraphGUI),
00383 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_COMPANIES_ALL), SetDataTip(STR_LINKGRAPH_LEGEND_ALL, STR_NULL),
00384 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_COMPANIES_NONE), SetDataTip(STR_LINKGRAPH_LEGEND_NONE, STR_NULL),
00385 EndContainer(),
00386 EndContainer(),
00387 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_LGL_CARGOES),
00388 SetPadding(WD_FRAMERECT_TOP, WD_FRAMERECT_RIGHT, WD_FRAMERECT_BOTTOM, WD_CAPTIONTEXT_LEFT),
00389 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
00390 NWidgetFunction(MakeCargoesLegendLinkGraphGUI),
00391 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_CARGOES_ALL), SetDataTip(STR_LINKGRAPH_LEGEND_ALL, STR_NULL),
00392 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_LGL_CARGOES_NONE), SetDataTip(STR_LINKGRAPH_LEGEND_NONE, STR_NULL),
00393 EndContainer(),
00394 EndContainer(),
00395 EndContainer(),
00396 EndContainer()
00397 };
00398
00399 assert_compile(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST ==
00400 lengthof(LinkGraphOverlay::LINK_COLOURS) - 1);
00401
00402 static WindowDesc _linkgraph_legend_desc(
00403 WDP_AUTO, "toolbar_linkgraph", 0, 0,
00404 WC_LINKGRAPH_LEGEND, WC_NONE,
00405 0,
00406 _nested_linkgraph_legend_widgets, lengthof(_nested_linkgraph_legend_widgets)
00407 );
00408
00412 void ShowLinkGraphLegend()
00413 {
00414 AllocateWindowDescFront<LinkGraphLegendWindow>(&_linkgraph_legend_desc, 0);
00415 }
00416
00417 LinkGraphLegendWindow::LinkGraphLegendWindow(WindowDesc *desc, int window_number) : Window(desc)
00418 {
00419 this->InitNested(window_number);
00420 this->InvalidateData(0);
00421 this->SetOverlay(FindWindowById(WC_MAIN_WINDOW, 0)->viewport->overlay);
00422 }
00423
00428 void LinkGraphLegendWindow::SetOverlay(LinkGraphOverlay *overlay) {
00429 this->overlay = overlay;
00430 uint32 companies = this->overlay->GetCompanyMask();
00431 for (uint c = 0; c < MAX_COMPANIES; c++) {
00432 if (!this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) {
00433 this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, HasBit(companies, c));
00434 }
00435 }
00436 uint32 cargoes = this->overlay->GetCargoMask();
00437 for (uint c = 0; c < NUM_CARGO; c++) {
00438 if (!this->IsWidgetDisabled(WID_LGL_CARGO_FIRST + c)) {
00439 this->SetWidgetLoweredState(WID_LGL_CARGO_FIRST + c, HasBit(cargoes, c));
00440 }
00441 }
00442 }
00443
00444 void LinkGraphLegendWindow::UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00445 {
00446 if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
00447 StringID str = STR_NULL;
00448 if (widget == WID_LGL_SATURATION_FIRST) {
00449 str = STR_LINKGRAPH_LEGEND_UNUSED;
00450 } else if (widget == WID_LGL_SATURATION_LAST) {
00451 str = STR_LINKGRAPH_LEGEND_OVERLOADED;
00452 } else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) {
00453 str = STR_LINKGRAPH_LEGEND_SATURATED;
00454 }
00455 if (str != STR_NULL) {
00456 Dimension dim = GetStringBoundingBox(str);
00457 dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
00458 dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
00459 *size = maxdim(*size, dim);
00460 }
00461 }
00462 if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
00463 CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST);
00464 if (cargo->IsValid()) {
00465 Dimension dim = GetStringBoundingBox(cargo->abbrev);
00466 dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
00467 dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
00468 *size = maxdim(*size, dim);
00469 }
00470 }
00471 }
00472
00473 void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
00474 {
00475 if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
00476 if (this->IsWidgetDisabled(widget)) return;
00477 CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
00478 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
00479 DrawCompanyIcon(cid, (r.left + r.right + 1 - sprite_size.width) / 2, (r.top + r.bottom + 1 - sprite_size.height) / 2);
00480 }
00481 if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
00482 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, LinkGraphOverlay::LINK_COLOURS[widget - WID_LGL_SATURATION_FIRST]);
00483 StringID str = STR_NULL;
00484 if (widget == WID_LGL_SATURATION_FIRST) {
00485 str = STR_LINKGRAPH_LEGEND_UNUSED;
00486 } else if (widget == WID_LGL_SATURATION_LAST) {
00487 str = STR_LINKGRAPH_LEGEND_OVERLOADED;
00488 } else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) {
00489 str = STR_LINKGRAPH_LEGEND_SATURATED;
00490 }
00491 if (str != STR_NULL) DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, str, TC_FROMSTRING, SA_HOR_CENTER);
00492 }
00493 if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
00494 if (this->IsWidgetDisabled(widget)) return;
00495 CargoSpec *cargo = CargoSpec::Get(widget - WID_LGL_CARGO_FIRST);
00496 GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, cargo->legend_colour);
00497 DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, cargo->abbrev, TC_BLACK, SA_HOR_CENTER);
00498 }
00499 }
00500
00504 void LinkGraphLegendWindow::UpdateOverlayCompanies()
00505 {
00506 uint32 mask = 0;
00507 for (uint c = 0; c < MAX_COMPANIES; c++) {
00508 if (this->IsWidgetDisabled(c + WID_LGL_COMPANY_FIRST)) continue;
00509 if (!this->IsWidgetLowered(c + WID_LGL_COMPANY_FIRST)) continue;
00510 SetBit(mask, c);
00511 }
00512 this->overlay->SetCompanyMask(mask);
00513 }
00514
00518 void LinkGraphLegendWindow::UpdateOverlayCargoes()
00519 {
00520 uint32 mask = 0;
00521 for (uint c = 0; c < NUM_CARGO; c++) {
00522 if (this->IsWidgetDisabled(c + WID_LGL_CARGO_FIRST)) continue;
00523 if (!this->IsWidgetLowered(c + WID_LGL_CARGO_FIRST)) continue;
00524 SetBit(mask, c);
00525 }
00526 this->overlay->SetCargoMask(mask);
00527 }
00528
00529 void LinkGraphLegendWindow::OnClick(Point pt, int widget, int click_count)
00530 {
00531
00532 if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
00533 if (!this->IsWidgetDisabled(widget)) {
00534 this->ToggleWidgetLoweredState(widget);
00535 this->UpdateOverlayCompanies();
00536 }
00537 } else if (widget == WID_LGL_COMPANIES_ALL || widget == WID_LGL_COMPANIES_NONE) {
00538 for (uint c = 0; c < MAX_COMPANIES; c++) {
00539 if (this->IsWidgetDisabled(c + WID_LGL_COMPANY_FIRST)) continue;
00540 this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, widget == WID_LGL_COMPANIES_ALL);
00541 }
00542 this->UpdateOverlayCompanies();
00543 this->SetDirty();
00544 } else if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
00545 if (!this->IsWidgetDisabled(widget)) {
00546 this->ToggleWidgetLoweredState(widget);
00547 this->UpdateOverlayCargoes();
00548 }
00549 } else if (widget == WID_LGL_CARGOES_ALL || widget == WID_LGL_CARGOES_NONE) {
00550 for (uint c = 0; c < NUM_CARGO; c++) {
00551 if (this->IsWidgetDisabled(c + WID_LGL_CARGO_FIRST)) continue;
00552 this->SetWidgetLoweredState(WID_LGL_CARGO_FIRST + c, widget == WID_LGL_CARGOES_ALL);
00553 }
00554 this->UpdateOverlayCargoes();
00555 }
00556 this->SetDirty();
00557 }
00558
00564 void LinkGraphLegendWindow::OnInvalidateData(int data, bool gui_scope)
00565 {
00566
00567 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
00568 this->SetWidgetDisabledState(i + WID_LGL_COMPANY_FIRST, !Company::IsValidID(i));
00569 }
00570 for (CargoID i = 0; i < NUM_CARGO; i++) {
00571 this->SetWidgetDisabledState(i + WID_LGL_CARGO_FIRST, !CargoSpec::Get(i)->IsValid());
00572 }
00573 }