Skip to content

Commit

Permalink
Feature: Industry production graph (#10541)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolyeltsov authored Oct 31, 2024
1 parent db1a1c5 commit 3fca0cf
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 32 deletions.
326 changes: 300 additions & 26 deletions src/graph_gui.cpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/graph_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
#ifndef GRAPH_GUI_H
#define GRAPH_GUI_H

#include "window_type.h"

void ShowOperatingProfitGraph();
void ShowIncomeGraph();
void ShowDeliveredCargoGraph();
void ShowPerformanceHistoryGraph();
void ShowCompanyValueGraph();
void ShowCargoPaymentRates();
void ShowPerformanceRatingDetail();
void ShowIndustryProductionGraph(WindowNumber window_number);

#endif /* GRAPH_GUI_H */
2 changes: 1 addition & 1 deletion src/industry.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
CargoID cargo; ///< Cargo type
uint16_t waiting; ///< Amount of cargo produced
uint8_t rate; ///< Production rate
std::array<ProducedHistory, 2> history; ///< History of cargo produced and transported
std::array<ProducedHistory, 25> history; ///< History of cargo produced and transported for this month and 24 previous months
};

struct AcceptedCargo {
Expand Down
14 changes: 14 additions & 0 deletions src/industry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "clear_map.h"
#include "zoom_func.h"
#include "industry_cmd.h"
#include "graph_gui.h"
#include "querystring_gui.h"
#include "stringfilter_type.h"
#include "timer/timer.h"
Expand Down Expand Up @@ -824,9 +825,17 @@ class IndustryViewWindow : public Window
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_INDUSTRY));

const Industry *i = Industry::Get(window_number);
if (!i->IsCargoProduced()) this->DisableWidget(WID_IV_GRAPH);

this->InvalidateData();
}

~IndustryViewWindow()
{
CloseWindowById(WC_INDUSTRY_PRODUCTION, this->window_number, false);
}

void OnInit() override
{
/* This only used when the cheat to alter industry production is enabled */
Expand Down Expand Up @@ -1111,6 +1120,10 @@ class IndustryViewWindow : public Window
ShowIndustryCargoesWindow(i->type);
break;
}

case WID_IV_GRAPH:
ShowIndustryProductionGraph(this->window_number);
break;
}
}

Expand Down Expand Up @@ -1219,6 +1232,7 @@ static constexpr NWidgetPart _nested_industry_view_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_DISPLAY), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_GRAPH), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INDUSTRY_VIEW_PRODUCTION_GRAPH, STR_INDUSTRY_VIEW_PRODUCTION_GRAPH_TOOLTIP),
NWidget(WWT_RESIZEBOX, COLOUR_CREAM),
EndContainer(),
};
Expand Down
5 changes: 5 additions & 0 deletions src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ STR_GRAPH_CARGO_DELIVERED_CAPTION :{WHITE}Units of
STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION :{WHITE}Company performance ratings (maximum rating=1000)
STR_GRAPH_COMPANY_VALUES_CAPTION :{WHITE}Company Value Graph

STR_GRAPH_LAST_24_MINUTES_TIME_LABEL :{TINY_FONT}{BLACK}Last 24 minutes
STR_GRAPH_LAST_72_MINUTES_TIME_LABEL :{TINY_FONT}{BLACK}Last 72 minutes

STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION :{WHITE}Cargo Payment Rates
Expand All @@ -626,6 +627,8 @@ STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL :{BLACK}Display
STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO :{BLACK}Toggle graph of this cargo type
STR_GRAPH_CARGO_PAYMENT_CARGO :{TINY_FONT}{BLACK}{STRING}

STR_GRAPH_INDUSTRY_PRODUCTION_CAPTION :{WHITE}{INDUSTRY} - Production History

STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP :{BLACK}Show detailed performance ratings

# Graph key window
Expand Down Expand Up @@ -3987,6 +3990,8 @@ STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE :{BLACK}Producti
STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE :{BLACK}Production last minute:
STR_INDUSTRY_VIEW_TRANSPORTED :{YELLOW}{CARGO_LONG}{RAW_STRING}{BLACK} ({COMMA}% transported)
STR_INDUSTRY_VIEW_LOCATION_TOOLTIP :{BLACK}Centre the main view on industry location. Ctrl+Click to open a new viewport on industry location
STR_INDUSTRY_VIEW_PRODUCTION_GRAPH :{BLACK}Production Graph
STR_INDUSTRY_VIEW_PRODUCTION_GRAPH_TOOLTIP :{BLACK}Shows the graph of industry production history
STR_INDUSTRY_VIEW_PRODUCTION_LEVEL :{BLACK}Production level: {YELLOW}{COMMA}%
STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE :{YELLOW}The industry has announced imminent closure!

Expand Down
1 change: 1 addition & 0 deletions src/saveload/saveload.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ enum SaveLoadVersion : uint16_t {
SLV_ROAD_STOP_TILE_DATA, ///< 340 PR#12883 Move storage of road stop tile data, also save for road waypoints.
SLV_COMPANY_ALLOW_LIST_V2, ///< 341 PR#12908 Fixed savegame format for saving of list of client keys that are allowed to join this company.
SLV_WATER_TILE_TYPE, ///< 342 PR#13030 Simplify water tile type.
SLV_PRODUCTION_HISTORY, ///< 343 PR#10541 Industry production history.

SL_MAX_VERSION, ///< Highest possible saveload version
};
Expand Down
11 changes: 6 additions & 5 deletions src/widgets/graph_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ enum GraphLegendWidgets : WidgetID {
enum GraphWidgets : WidgetID {
WID_GRAPH_KEY_BUTTON, ///< Key button.
WID_GRAPH_BACKGROUND, ///< Background of the window.
WID_GRAPH_CAPTION, ///< Caption.
WID_GRAPH_GRAPH, ///< Graph itself.
WID_GRAPH_RESIZE, ///< Resize button.
WID_GRAPH_HEADER, ///< Header.
WID_GRAPH_FOOTER, ///< Footer.

WID_PHG_DETAILED_PERFORMANCE, ///< Detailed performance.
WID_GRAPH_ENABLE_CARGOES, ///< Enable cargoes button.
WID_GRAPH_DISABLE_CARGOES, ///< Disable cargoes button.
WID_GRAPH_MATRIX, ///< Cargo list.
WID_GRAPH_MATRIX_SCROLLBAR,///< Cargo list scrollbar.

WID_CPR_ENABLE_CARGOES, ///< Enable cargoes button.
WID_CPR_DISABLE_CARGOES, ///< Disable cargoes button.
WID_CPR_MATRIX, ///< Cargo list.
WID_CPR_MATRIX_SCROLLBAR,///< Cargo list scrollbar.
WID_PHG_DETAILED_PERFORMANCE, ///< Detailed performance.
};

/** Widget of the #PerformanceRatingDetailWindow class. */
Expand Down
1 change: 1 addition & 0 deletions src/widgets/industry_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum IndustryViewWidgets : WidgetID {
WID_IV_INFO, ///< Info of the industry.
WID_IV_GOTO, ///< Goto button.
WID_IV_DISPLAY, ///< Display chain button.
WID_IV_GRAPH, ///< Production history button.
};

/** Widgets of the #IndustryDirectoryWindow class. */
Expand Down
6 changes: 6 additions & 0 deletions src/window_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ enum WindowClass {
*/
WC_PERFORMANCE_DETAIL,

/**
* Industry production history graph; %Window numbers:
* - #IndustryID = #IndustryProductionGraphWidgets
*/
WC_INDUSTRY_PRODUCTION,

/**
* Company infrastructure overview; %Window numbers:
* - #CompanyID = #CompanyInfrastructureWidgets
Expand Down

0 comments on commit 3fca0cf

Please sign in to comment.