|
@@ -807,42 +807,67 @@ enum CargoPaymentRatesWidgets {
|
|
|
CPW_GRAPH,
|
|
|
CPW_FOOTER,
|
|
|
CPW_CARGO_FIRST,
|
|
|
};
|
|
|
|
|
|
struct PaymentRatesGraphWindow : BaseGraphWindow {
|
|
|
bool first_init; ///< This value is true until the first initialization of the window has finished.
|
|
|
PaymentRatesGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
|
|
|
BaseGraphWindow(CPW_GRAPH, false, STR_JUST_CURRCOMPACT)
|
|
|
{
|
|
|
this->first_init = true;
|
|
|
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->InitNested(desc, window_number);
|
|
|
|
|
|
int i = 0;
|
|
|
const CargoSpec *cs;
|
|
|
FOR_ALL_CARGOSPECS(cs) {
|
|
|
this->SetWidgetLoweredState(CPW_CARGO_FIRST + cs->Index(), !HasBit(_legend_excluded_cargo, i));
|
|
|
i++;
|
|
|
this->UpdateLoweredWidgets();
|
|
|
}
|
|
|
|
|
|
virtual void OnInit()
|
|
|
{
|
|
|
/* UpdateLoweredWidgets needs to be called after a language or NewGRF change, but it can't be called before
|
|
|
* InitNested is done. On the first init these functions are called in the correct order by the constructor. */
|
|
|
if (!this->first_init) {
|
|
|
/* Initialise the dataset */
|
|
|
this->OnHundredthTick();
|
|
|
this->UpdateLoweredWidgets();
|
|
|
}
|
|
|
this->first_init = false;
|
|
|
}
|
|
|
|
|
|
void UpdateExcludedData()
|
|
|
{
|
|
|
this->excluded_data = 0;
|
|
|
|
|
|
for (int i = 0; i < _sorted_cargo_specs_size; i++) {
|
|
|
if (HasBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index())) SetBit(this->excluded_data, i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void UpdateLoweredWidgets()
|
|
|
{
|
|
|
for (int i = 0; i < _sorted_cargo_specs_size; i++) {
|
|
|
this->SetWidgetLoweredState(CPW_CARGO_FIRST + i, !HasBit(this->excluded_data, i));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
{
|
|
|
if (widget < CPW_CARGO_FIRST) {
|
|
|
BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const CargoSpec *cs = CargoSpec::Get(widget - CPW_CARGO_FIRST);
|
|
|
const CargoSpec *cs = _sorted_cargo_specs[widget - CPW_CARGO_FIRST];
|
|
|
SetDParam(0, cs->name);
|
|
|
Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
|
|
|
d.width += 14; // colour field
|
|
|
d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
|
d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
*size = maxdim(d, *size);
|
|
@@ -852,13 +877,13 @@ struct PaymentRatesGraphWindow : BaseGra
|
|
|
{
|
|
|
if (widget < CPW_CARGO_FIRST) {
|
|
|
BaseGraphWindow::DrawWidget(r, widget);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const CargoSpec *cs = CargoSpec::Get(widget - CPW_CARGO_FIRST);
|
|
|
const CargoSpec *cs = _sorted_cargo_specs[widget - CPW_CARGO_FIRST];
|
|
|
bool rtl = _dynlang.text_dir == TD_RTL;
|
|
|
|
|
|
/* 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 */
|
|
@@ -874,63 +899,53 @@ struct PaymentRatesGraphWindow : BaseGra
|
|
|
DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
{
|
|
|
if (widget >= CPW_CARGO_FIRST) {
|
|
|
int i = 0;
|
|
|
const CargoSpec *cs;
|
|
|
FOR_ALL_CARGOSPECS(cs) {
|
|
|
if (cs->Index() + CPW_CARGO_FIRST == widget) break;
|
|
|
i++;
|
|
|
}
|
|
|
|
|
|
ToggleBit(_legend_excluded_cargo, i);
|
|
|
int i = widget - CPW_CARGO_FIRST;
|
|
|
ToggleBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index());
|
|
|
this->ToggleWidgetLoweredState(widget);
|
|
|
this->excluded_data = _legend_excluded_cargo;
|
|
|
this->UpdateExcludedData();
|
|
|
this->SetDirty();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnTick()
|
|
|
{
|
|
|
/* Override default OnTick */
|
|
|
}
|
|
|
|
|
|
virtual void OnHundredthTick()
|
|
|
{
|
|
|
this->excluded_data = _legend_excluded_cargo;
|
|
|
this->UpdateExcludedData();
|
|
|
|
|
|
int i = 0;
|
|
|
const CargoSpec *cs;
|
|
|
FOR_ALL_CARGOSPECS(cs) {
|
|
|
this->colours[i] = cs->legend_colour;
|
|
|
int i;
|
|
|
for (i = 0; i < _sorted_cargo_specs_size; i++) {
|
|
|
this->colours[i] = _sorted_cargo_specs[i]->legend_colour;
|
|
|
for (uint j = 0; j != 20; j++) {
|
|
|
this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
|
|
|
this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, _sorted_cargo_specs[i]->Index());
|
|
|
}
|
|
|
|
|
|
i++;
|
|
|
}
|
|
|
this->num_dataset = i;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/** Construct the row containing the digit keys. */
|
|
|
static NWidgetBase *MakeCargoButtons(int *biggest_index)
|
|
|
{
|
|
|
NWidgetVertical *ver = new NWidgetVertical;
|
|
|
|
|
|
const CargoSpec *cs;
|
|
|
FOR_ALL_CARGOSPECS(cs) {
|
|
|
*biggest_index = CPW_CARGO_FIRST + cs->Index();
|
|
|
NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, *biggest_index, NULL);
|
|
|
for (int i = 0; i < _sorted_cargo_specs_size; i++) {
|
|
|
NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, CPW_CARGO_FIRST + i, NULL);
|
|
|
leaf->tool_tip = STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO;
|
|
|
leaf->SetFill(1, 0);
|
|
|
leaf->SetLowered(true);
|
|
|
ver->Add(leaf);
|
|
|
}
|
|
|
*biggest_index = CPW_CARGO_FIRST + _sorted_cargo_specs_size - 1;
|
|
|
return ver;
|
|
|
}
|
|
|
|
|
|
|
|
|
static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
|
|
|
NWidget(NWID_HORIZONTAL),
|