diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index dfad22c413..dad83e081b 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -196,6 +196,12 @@ protected: const HistoryRange *history_range = nullptr; }; + /** Label and tooltip for a graph range. */ + struct GraphRange { + StringID label; ///< Label for this range. + StringID tooltip; ///< Tooltip for this range. + }; + static inline constexpr GraphScale MONTHLY_SCALE_WALLCLOCK[] = { {STR_GRAPH_LAST_24_MINUTES_TIME_LABEL, HISTORY_MONTH.total_division, ECONOMY_MONTH_MINUTES, &HISTORY_MONTH}, {STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, HISTORY_QUARTER.total_division, ECONOMY_QUARTER_MINUTES, &HISTORY_QUARTER}, @@ -240,7 +246,7 @@ protected: }; std::vector data{}; - std::span ranges{}; + std::span ranges{}; std::span scales{}; uint8_t selected_scale = 0; @@ -670,7 +676,7 @@ public: { switch (widget) { case WID_GRAPH_RANGE_MATRIX: - this->UpdateMatrixSize(widget, size, resize, this->ranges); + this->UpdateMatrixSize(widget, size, resize, this->ranges | std::views::transform(&GraphRange::label)); break; case WID_GRAPH_SCALE_MATRIX: @@ -704,6 +710,17 @@ public: } } + bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override + { + if (widget != WID_GRAPH_RANGE_MATRIX) return false; + + int row = GetRowFromWidget(pt.y, widget, 0, GetCharacterHeight(FontSize::Small) + WidgetDimensions::scaled.framerect.Vertical()); + if (row == INT_MAX) return false; + + GuiShowTooltips(this, GetEncodedString(this->ranges[row].tooltip), close_cond); + return true; + } + void DrawWidget(const Rect &r, WidgetID widget) const override { switch (widget) { @@ -715,14 +732,14 @@ public: uint line_height = GetCharacterHeight(FontSize::Small) + WidgetDimensions::scaled.framerect.Vertical(); uint index = 0; Rect line = r.WithHeight(line_height); - for (const auto &str : this->ranges) { + for (const auto &[label, tooltip] : this->ranges) { bool lowered = !HasBit(this->excluded_range, index) && !HasBit(this->masked_range, index); /* Redraw frame if lowered */ if (lowered) DrawFrameRect(line, Colours::Brown, FrameFlag::Lowered); const Rect text = line.Shrink(WidgetDimensions::scaled.framerect); - DrawString(text, str, (this->highlight_state && this->highlight_range == index) ? TextColour::White : TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}, false, FontSize::Small); + DrawString(text, label, (this->highlight_state && this->highlight_range == index) ? TextColour::White : TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle}, false, FontSize::Small); if (HasBit(this->masked_range, index)) { GfxFillRect(line.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(Colours::Brown, Shade::Darker), FillRectMode::Checker); @@ -1710,11 +1727,11 @@ CompanyID PerformanceRatingDetailWindow::company = CompanyID::Invalid(); /*******************************/ struct IndustryProductionGraphWindow : BaseCargoGraphWindow { - static inline constexpr StringID RANGE_LABELS[] = { - STR_GRAPH_INDUSTRY_RANGE_PRODUCED, - STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED, - STR_GRAPH_INDUSTRY_RANGE_DELIVERED, - STR_GRAPH_INDUSTRY_RANGE_WAITING, + static inline constexpr GraphRange RANGE_LABELS[] = { + {STR_GRAPH_INDUSTRY_RANGE_PRODUCED, STR_GRAPH_INDUSTRY_RANGE_PRODUCED_TOOLTIP}, + {STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED, STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED_TOOLTIP}, + {STR_GRAPH_INDUSTRY_RANGE_DELIVERED, STR_GRAPH_INDUSTRY_RANGE_DELIVERED_TOOLTIP}, + {STR_GRAPH_INDUSTRY_RANGE_WAITING, STR_GRAPH_INDUSTRY_RANGE_WAITING_TOOLTIP}, }; static inline CargoTypes excluded_cargo_types{}; @@ -1851,7 +1868,7 @@ static constexpr std::initializer_list _nested_industry_production_ NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_VERTICAL), NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1), - NWidget(WWT_MATRIX, Colours::Brown, WID_GRAPH_RANGE_MATRIX), SetFill(1, 0), SetResize(0, 0), SetMatrixDataTip(1, 0, STR_GRAPH_TOGGLE_RANGE), + NWidget(WWT_MATRIX, Colours::Brown, WID_GRAPH_RANGE_MATRIX), SetFill(1, 0), SetResize(0, 0), SetMatrixDataTip(1, 0), NWidget(NWID_SPACER), SetMinimalSize(0, 4), NWidget(WWT_PUSHTXTBTN, Colours::Brown, WID_GRAPH_ENABLE_CARGOES), SetStringTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0), NWidget(WWT_PUSHTXTBTN, Colours::Brown, WID_GRAPH_DISABLE_CARGOES), SetStringTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0), @@ -1887,10 +1904,10 @@ void ShowIndustryProductionGraph(WindowNumber window_number) } struct TownCargoGraphWindow : BaseCargoGraphWindow { - static inline constexpr StringID RANGE_LABELS[] = { - STR_GRAPH_TOWN_RANGE_PRODUCED, - STR_GRAPH_TOWN_RANGE_TRANSPORTED, - STR_GRAPH_TOWN_RANGE_DELIVERED, + static inline constexpr GraphRange RANGE_LABELS[] = { + {STR_GRAPH_TOWN_RANGE_PRODUCED, STR_GRAPH_TOWN_RANGE_PRODUCED_TOOLTIP}, + {STR_GRAPH_TOWN_RANGE_TRANSPORTED, STR_GRAPH_TOWN_RANGE_TRANSPORTED_TOOLTIP}, + {STR_GRAPH_TOWN_RANGE_DELIVERED, STR_GRAPH_TOWN_RANGE_DELIVERED_TOOLTIP}, }; static inline CargoTypes excluded_cargo_types{}; @@ -2015,7 +2032,7 @@ static constexpr std::initializer_list _nested_town_cargo_graph_wid NWidget(WWT_EMPTY, Colours::Invalid, WID_GRAPH_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_VERTICAL), NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1), - NWidget(WWT_MATRIX, Colours::Brown, WID_GRAPH_RANGE_MATRIX), SetFill(1, 0), SetResize(0, 0), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), + NWidget(WWT_MATRIX, Colours::Brown, WID_GRAPH_RANGE_MATRIX), SetFill(1, 0), SetResize(0, 0), SetMatrixDataTip(1, 0), NWidget(NWID_SPACER), SetMinimalSize(0, 4), NWidget(WWT_PUSHTXTBTN, Colours::Brown, WID_GRAPH_ENABLE_CARGOES), SetStringTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0), NWidget(WWT_PUSHTXTBTN, Colours::Brown, WID_GRAPH_DISABLE_CARGOES), SetStringTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0), diff --git a/src/lang/english.txt b/src/lang/english.txt index 1ef056c01c..53492df8b4 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -631,7 +631,6 @@ STR_GRAPH_LAST_24_MONTHS :{TINY_FONT}{BLA STR_GRAPH_LAST_24_QUARTERS :{TINY_FONT}{BLACK}6 years (quarterly) STR_GRAPH_LAST_24_YEARS :{TINY_FONT}{BLACK}24 years (yearly) -STR_GRAPH_TOGGLE_RANGE :Toggle graph for this data range STR_GRAPH_SELECT_SCALE :Change horizontal scale of graph STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION :{WHITE}Cargo Payment Rates @@ -647,14 +646,21 @@ STR_GRAPH_CARGO_PAYMENT_CARGO :{TINY_FONT}{BLA STR_GRAPH_INDUSTRY_CAPTION :{WHITE}{INDUSTRY} - Cargo History STR_GRAPH_INDUSTRY_RANGE_PRODUCED :Produced +STR_GRAPH_INDUSTRY_RANGE_PRODUCED_TOOLTIP :Toggle graph of cargo produced by this industry STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED :Transported +STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED_TOOLTIP :Toggle graph of cargo transported from this industry STR_GRAPH_INDUSTRY_RANGE_DELIVERED :Delivered +STR_GRAPH_INDUSTRY_RANGE_DELIVERED_TOOLTIP :Toggle graph of cargo delivered to this industry STR_GRAPH_INDUSTRY_RANGE_WAITING :Waiting +STR_GRAPH_INDUSTRY_RANGE_WAITING_TOOLTIP :Toggle graph of cargo waiting at this industry STR_GRAPH_TOWN_CARGO_CAPTION :{WHITE}{TOWN} - Cargo History STR_GRAPH_TOWN_RANGE_PRODUCED :Produced +STR_GRAPH_TOWN_RANGE_PRODUCED_TOOLTIP :Toggle graph of cargo produced by this town STR_GRAPH_TOWN_RANGE_TRANSPORTED :Transported +STR_GRAPH_TOWN_RANGE_TRANSPORTED_TOOLTIP :Toggle graph of cargo transported from this town STR_GRAPH_TOWN_RANGE_DELIVERED :Delivered +STR_GRAPH_TOWN_RANGE_DELIVERED_TOOLTIP :Toggle graph of cargo delivered to this town STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP :{BLACK}Show detailed performance ratings