|
@@ -383,84 +383,96 @@ protected:
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
BaseGraphWindow(const WindowDesc *desc, WindowNumber window_number, int left,
|
|
|
int top, int height, bool has_negative_values, StringID format_str_y_axis) :
|
|
|
Window(desc, window_number), has_negative_values(has_negative_values),
|
|
|
gd_left(left), gd_top(top), gd_height(height), format_str_y_axis(format_str_y_axis)
|
|
|
{
|
|
|
InvalidateWindow(WC_GRAPH_LEGEND, 0);
|
|
|
this->num_vert_lines = 24;
|
|
|
|
|
|
/* Initialise the dataset */
|
|
|
this->OnTick();
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
this->DrawWidgets();
|
|
|
|
|
|
this->DrawGraph();
|
|
|
}
|
|
|
|
|
|
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
|
|
{
|
|
|
return INVALID_DATAPOINT;
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
{
|
|
|
/* Clicked on legend? */
|
|
|
if (widget == BGW_KEY_BUTTON) ShowGraphLegend();
|
|
|
}
|
|
|
|
|
|
virtual void OnTick()
|
|
|
{
|
|
|
uint excluded_companies = _legend_excluded_companies;
|
|
|
|
|
|
/* Exclude the companies which aren't valid */
|
|
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
|
|
if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
|
|
|
}
|
|
|
this->excluded_data = excluded_companies;
|
|
|
this->num_vert_lines = 24;
|
|
|
|
|
|
byte nums = 0;
|
|
|
const Company *c;
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
nums = max(nums, c->num_valid_stat_ent);
|
|
|
nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent));
|
|
|
}
|
|
|
this->num_on_x_axis = min(nums, 24);
|
|
|
|
|
|
int mo = (_cur_month / 3 - nums) * 3;
|
|
|
int yr = _cur_year;
|
|
|
while (mo < 0) {
|
|
|
yr--;
|
|
|
mo += 12;
|
|
|
}
|
|
|
|
|
|
if (this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
|
|
|
this->year == yr && this->month == mo) {
|
|
|
/* There's no reason to get new stats */
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this->excluded_data = excluded_companies;
|
|
|
this->num_on_x_axis = nums;
|
|
|
this->year = yr;
|
|
|
this->month = mo;
|
|
|
|
|
|
int numd = 0;
|
|
|
for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
|
|
|
c = Company::GetIfValid(k);
|
|
|
if (c != NULL) {
|
|
|
this->colours[numd] = _colour_gradient[c->colour][6];
|
|
|
for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
|
|
|
this->cost[numd][i] = (j >= c->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(c, j);
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
numd++;
|
|
|
}
|
|
|
|
|
|
this->num_dataset = numd;
|
|
|
|
|
|
this->DrawGraph();
|
|
|
}
|
|
|
|
|
|
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
|
|
{
|
|
|
return INVALID_DATAPOINT;
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
{
|
|
|
/* Clicked on legend? */
|
|
|
if (widget == BGW_KEY_BUTTON) ShowGraphLegend();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
/********************/
|
|
|
/* OPERATING PROFIT */
|
|
|
/********************/
|
|
|
|
|
|
struct OperatingProfitGraphWindow : BaseGraphWindow {
|
|
|
OperatingProfitGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
BaseGraphWindow(desc, window_number, 2, 18, 136, true, STR_CURRCOMPACT)
|
|
|
{
|
|
@@ -752,80 +764,97 @@ struct PaymentRatesGraphWindow : BaseGra
|
|
|
if (!HasBit(_legend_excluded_cargo, i)) this->LowerWidget(i + CPW_CARGO_FIRST);
|
|
|
}
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
|
|
this->gd_height = this->height - 38;
|
|
|
this->num_on_x_axis = 20;
|
|
|
this->num_vert_lines = 20;
|
|
|
this->month = 0xFF;
|
|
|
this->x_values_start = 10;
|
|
|
this->x_values_increment = 10;
|
|
|
|
|
|
/* Initialise the dataset */
|
|
|
this->OnHundredthTick();
|
|
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
}
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
this->DrawWidgets();
|
|
|
|
|
|
this->excluded_data = _legend_excluded_cargo;
|
|
|
|
|
|
int x = 495;
|
|
|
int y = 24;
|
|
|
|
|
|
uint i = 0;
|
|
|
|
|
|
const CargoSpec *cs;
|
|
|
FOR_ALL_CARGOSPECS(cs) {
|
|
|
/* Only draw labels for widgets that exist. If the widget doesn't
|
|
|
* exist then the local company has used the climate cheat or
|
|
|
* changed the NewGRF configuration with this window open. */
|
|
|
if (i + CPW_CARGO_FIRST < this->widget_count) {
|
|
|
/* Since the buttons have no text, no images,
|
|
|
* both the text and the coloured box have to be manually painted.
|
|
|
* clk_dif will move one pixel down and one pixel to the right
|
|
|
* when the button is clicked */
|
|
|
byte clk_dif = this->IsWidgetLowered(i + CPW_CARGO_FIRST) ? 1 : 0;
|
|
|
|
|
|
GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0);
|
|
|
GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour);
|
|
|
SetDParam(0, cs->name);
|
|
|
DrawString(x + 14 + clk_dif, this->width, y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
|
|
|
y += 8;
|
|
|
}
|
|
|
|
|
|
this->colours[i] = cs->legend_colour;
|
|
|
for (uint j = 0; j != 20; j++) {
|
|
|
this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
|
|
|
}
|
|
|
|
|
|
i++;
|
|
|
}
|
|
|
this->num_dataset = i;
|
|
|
|
|
|
this->DrawGraph();
|
|
|
|
|
|
DrawString(2 + 46, this->width, 24 + this->gd_height + 7, STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL);
|
|
|
DrawString(2 + 84, this->width, 24 - 9, STR_GRAPH_CARGO_PAYMENT_RATES_TITLE);
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
{
|
|
|
if (widget >= CPW_CARGO_FIRST) {
|
|
|
ToggleBit(_legend_excluded_cargo, widget - CPW_CARGO_FIRST);
|
|
|
this->ToggleWidgetLoweredState(widget);
|
|
|
this->excluded_data = _legend_excluded_cargo;
|
|
|
this->SetDirty();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnTick()
|
|
|
{
|
|
|
/* Override default OnTick */
|
|
|
}
|
|
|
|
|
|
virtual void OnHundredthTick()
|
|
|
{
|
|
|
this->excluded_data = _legend_excluded_cargo;
|
|
|
|
|
|
int i = 0;
|
|
|
const CargoSpec *cs;
|
|
|
FOR_ALL_CARGOSPECS(cs) {
|
|
|
this->colours[i] = cs->legend_colour;
|
|
|
for (uint j = 0; j != 20; j++) {
|
|
|
this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
|
|
|
}
|
|
|
|
|
|
i++;
|
|
|
}
|
|
|
this->num_dataset = i;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
static const Widget _cargo_payment_rates_widgets[] = {
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW},
|
|
|
{ WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 567, 0, 13, STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS},
|
|
|
{ WWT_PANEL, RESIZE_BOTTOM, COLOUR_GREY, 0, 567, 14, 45, 0x0, STR_NULL},
|
|
|
{ WIDGETS_END},
|
|
|
};
|
|
|
|
|
|
static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY, CPW_CLOSEBOX),
|