Merge 1.9.0-beta3

This commit is contained in:
Pavel Stupnikov
2019-02-25 18:47:08 +03:00
145 changed files with 2701 additions and 1536 deletions
+370 -281
View File
@@ -533,64 +533,10 @@ public:
return INVALID_DATAPOINT;
}
void UpdateExcludedData()
{
this->excluded_data = 0;
int i = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
i++;
}
}
void UpdateLoweredWidgets()
{
for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
this->SetWidgetLoweredState(WID_CPR_CARGO_FIRST + i, !HasBit(this->excluded_data, i));
}
}
virtual void OnClick(Point pt, int widget, int click_count)
{
switch (widget) {
/* Clicked on legend? */
case WID_CV_KEY_BUTTON:
ShowGraphLegend();
break;
case WID_CPR_ENABLE_CARGOES:
/* Remove all cargoes from the excluded lists. */
_legend_excluded_cargo = 0;
this->excluded_data = 0;
this->UpdateLoweredWidgets();
this->SetDirty();
break;
case WID_CPR_DISABLE_CARGOES: {
/* Add all cargoes to the excluded lists. */
int i = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
SetBit(_legend_excluded_cargo, cs->Index());
SetBit(this->excluded_data, i);
i++;
}
this->UpdateLoweredWidgets();
this->SetDirty();
break;
}
default:
if (widget >= WID_CPR_CARGO_FIRST) {
int i = widget - WID_CPR_CARGO_FIRST;
ToggleBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index());
this->ToggleWidgetLoweredState(widget);
this->UpdateExcludedData();
this->SetDirty();
}
break;
}
if (widget == WID_CV_KEY_BUTTON) ShowGraphLegend();
}
virtual void OnGameTick()
@@ -664,6 +610,149 @@ public:
};
struct ExcludingCargoBaseGraphWindow : BaseGraphWindow {
ExcludingCargoBaseGraphWindow(WindowDesc *desc, int widget, StringID format_str_y_axis):
BaseGraphWindow(desc, widget, format_str_y_axis)
{
}
uint line_height; ///< Pixel height of each cargo type row.
Scrollbar *vscroll; ///< Cargo list scrollbar.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
return;
}
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
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);
}
this->line_height = size->height;
size->height = this->line_height * 11; /* Default number of cargo types in most climates. */
resize->width = 0;
resize->height = this->line_height;
}
virtual void DrawWidget(const Rect &r, int widget) const
{
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::DrawWidget(r, widget);
return;
}
bool rtl = _current_text_dir == TD_RTL;
int x = r.left + WD_FRAMERECT_LEFT;
int y = r.top;
int pos = this->vscroll->GetPosition();
int max = pos + this->vscroll->GetCapacity();
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (pos-- > 0) continue;
if (--max < 0) break;
bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
/* Redraw box if lowered */
if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_ORANGE, lowered ? FR_LOWERED : FR_NONE);
byte clk_dif = lowered ? 1 : 0;
int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
SetDParam(0, cs->name);
DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
y += this->line_height;
}
}
void UpdateExcludedData()
{
this->excluded_data = 0;
int i = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
i++;
}
}
virtual void OnClick(Point pt, int widget, int click_count)
{
switch (widget) {
case WID_CPR_KEY_BUTTON:
ShowGraphLegend();
break;
case WID_CPR_ENABLE_CARGOES:
/* Remove all cargoes from the excluded lists. */
_legend_excluded_cargo = 0;
this->excluded_data = 0;
this->SetDirty();
break;
case WID_CPR_DISABLE_CARGOES: {
/* Add all cargoes to the excluded lists. */
int i = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
SetBit(_legend_excluded_cargo, cs->Index());
SetBit(this->excluded_data, i);
i++;
}
this->SetDirty();
break;
}
case WID_CPR_MATRIX: {
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX, 0, this->line_height);
if (row >= this->vscroll->GetCount()) return;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (row-- > 0) continue;
ToggleBit(_legend_excluded_cargo, cs->Index());
this->UpdateExcludedData();
this->SetDirty();
break;
}
break;
}
}
}
virtual void OnResize()
{
this->vscroll->SetCapacityFromWidget(this, WID_CPR_MATRIX);
}
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
if (!gui_scope) return;
this->UpdateExcludedData();
}
};
/********************/
/* OPERATING PROFIT */
/********************/
@@ -719,11 +808,15 @@ void ShowOperatingProfitGraph()
/* INCOME GRAPH */
/****************/
struct IncomeGraphWindow : BaseGraphWindow {
struct IncomeGraphWindow : ExcludingCargoBaseGraphWindow {
IncomeGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
ExcludingCargoBaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT)
{
this->InitializeWindow(window_number);
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
this->vscroll->SetCount(_sorted_standard_cargo_specs_size);
this->UpdateExcludedData();
this->FinishInitNested(window_number);
}
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
@@ -743,73 +836,136 @@ struct IncomeGraphWindow : BaseGraphWindow {
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget < WID_CPR_CARGO_FIRST) {
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
return;
}
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_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);
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
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);
}
this->line_height = size->height;
size->height = this->line_height * 11; /* Default number of cargo types in most climates. */
resize->width = 0;
resize->height = this->line_height;
}
virtual void DrawWidget(const Rect &r, int widget) const
{
if (widget < WID_CPR_CARGO_FIRST) {
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::DrawWidget(r, widget);
return;
}
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_CARGO_FIRST];
bool rtl = _current_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 */
byte clk_dif = this->IsWidgetLowered(widget) ? 1 : 0;
int x = r.left + WD_FRAMERECT_LEFT;
int y = r.top;
int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
int pos = this->vscroll->GetPosition();
int max = pos + this->vscroll->GetCapacity();
GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
SetDParam(0, cs->name);
DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (pos-- > 0) continue;
if (--max < 0) break;
bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
/* Redraw box if lowered */
if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_ORANGE, lowered ? FR_LOWERED : FR_NONE);
byte clk_dif = lowered ? 1 : 0;
int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
SetDParam(0, cs->name);
DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
y += this->line_height;
}
}
};
// virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
// {
// if (widget != WID_CPR_MATRIX) {
// BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
// return;
// }
static NWidgetBase *MakeCargoButtons(int *biggest_index);
// const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_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);
// }
// virtual void DrawWidget(const Rect &r, int widget) const
// {
// if (widget < WID_CPR_CARGO_FIRST) {
// BaseGraphWindow::DrawWidget(r, widget);
// return;
// }
// const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_CARGO_FIRST];
// bool rtl = _current_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 */
// byte clk_dif = this->IsWidgetLowered(widget) ? 1 : 0;
// int x = r.left + WD_FRAMERECT_LEFT;
// int y = r.top;
// int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
// GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
// GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
// SetDParam(0, cs->name);
// DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
// }
};
static const NWidgetPart _nested_income_graph_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_INCOME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CPR_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_BACKGROUND),
NWidget(WWT_PANEL, COLOUR_GREY, WID_CPR_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),//add
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 0), SetResize(0, 1),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CPR_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
NWidgetFunction(MakeCargoButtons),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1), SetResize(0, 1),
EndContainer(),//add
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CV_RESIZE),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_MATRIX, COLOUR_ORANGE, WID_CPR_MATRIX), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_ORANGE, WID_CPR_MATRIX_SCROLLBAR),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(WD_RESIZEBOX_WIDTH, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_GREY, WID_CPR_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CPR_RESIZE),
EndContainer(),
EndContainer(),
};
@@ -830,11 +986,15 @@ void ShowIncomeGraph()
/* DELIVERED CARGO */
/*******************/
struct DeliveredCargoGraphWindow : BaseGraphWindow {
struct DeliveredCargoGraphWindow : ExcludingCargoBaseGraphWindow {
DeliveredCargoGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_COMMA)
ExcludingCargoBaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT)
{
this->InitializeWindow(window_number);
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
this->vscroll->SetCount(_sorted_standard_cargo_specs_size);
this->OnHundredthTick();
this->FinishInitNested(window_number);
}
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
@@ -852,74 +1012,79 @@ struct DeliveredCargoGraphWindow : BaseGraphWindow {
return total_delivered;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget < WID_CPR_CARGO_FIRST) {
BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
return;
}
// virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
// {
// if (widget < WID_CPR_CARGO_FIRST) {
// BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
// return;
// }
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_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);
}
// const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_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);
// }
virtual void DrawWidget(const Rect &r, int widget) const
{
if (widget < WID_CPR_CARGO_FIRST) {
BaseGraphWindow::DrawWidget(r, widget);
return;
}
// virtual void DrawWidget(const Rect &r, int widget) const
// {
// if (widget < WID_CPR_CARGO_FIRST) {
// BaseGraphWindow::DrawWidget(r, widget);
// return;
// }
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_CARGO_FIRST];
bool rtl = _current_text_dir == TD_RTL;
// const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_CARGO_FIRST];
// bool rtl = _current_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 */
byte clk_dif = this->IsWidgetLowered(widget) ? 1 : 0;
int x = r.left + WD_FRAMERECT_LEFT;
int y = r.top;
// /* 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(widget) ? 1 : 0;
// int x = r.left + WD_FRAMERECT_LEFT;
// int y = r.top;
int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
// int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
SetDParam(0, cs->name);
DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
}
// GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
// GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
// SetDParam(0, cs->name);
// DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
// }
};
static const NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CPR_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_BACKGROUND),
NWidget(WWT_PANEL, COLOUR_GREY, WID_CPR_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),//add
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 0), SetResize(0, 1),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CPR_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
NWidgetFunction(MakeCargoButtons),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1), SetResize(0, 1),
EndContainer(),//add
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CV_RESIZE),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_MATRIX, COLOUR_ORANGE, WID_CPR_MATRIX), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_ORANGE, WID_CPR_MATRIX_SCROLLBAR),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(WD_RESIZEBOX_WIDTH, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_GREY, WID_CPR_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY, WID_CPR_RESIZE),
EndContainer(),
EndContainer(),
};
@@ -1045,152 +1210,91 @@ void ShowCompanyValueGraph()
/* PAYMENT RATES */
/*****************/
struct PaymentRatesGraphWindow : BaseGraphWindow {
bool first_init; ///< This value is true until the first initialization of the window has finished.
struct PaymentRatesGraphWindow : ExcludingCargoBaseGraphWindow {
PaymentRatesGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT)
ExcludingCargoBaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT)
{
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;
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
this->vscroll->SetCount(_sorted_standard_cargo_specs_size);
/* Initialise the dataset */
this->OnHundredthTick();
this->InitNested(window_number);
this->UpdateLoweredWidgets();
this->FinishInitNested(window_number);
}
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;
// virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
// {
// if (widget != WID_CPR_MATRIX) {
// BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
// return;
// }
int i = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
i++;
}
}
// const CargoSpec *cs;
// FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
// 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);
// }
void UpdateLoweredWidgets()
{
for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
this->SetWidgetLoweredState(WID_CPR_CARGO_FIRST + i, !HasBit(this->excluded_data, i));
}
}
*/
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget < WID_CPR_CARGO_FIRST) {
BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
return;
}
// this->line_height = size->height;
// size->height = this->line_height * 11; /* Default number of cargo types in most climates. */
// resize->width = 0;
// resize->height = this->line_height;
// }
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_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);
}
// virtual void DrawWidget(const Rect &r, int widget) const
// {
// if (widget != WID_CPR_MATRIX) {
// BaseGraphWindow::DrawWidget(r, widget);
// return;
// }
virtual void DrawWidget(const Rect &r, int widget) const
{
if (widget < WID_CPR_CARGO_FIRST) {
BaseGraphWindow::DrawWidget(r, widget);
return;
}
// bool rtl = _current_text_dir == TD_RTL;
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_CPR_CARGO_FIRST];
bool rtl = _current_text_dir == TD_RTL;
// int x = r.left + WD_FRAMERECT_LEFT;
// int y = r.top;
/* 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(widget) ? 1 : 0;
int x = r.left + WD_FRAMERECT_LEFT;
int y = r.top;
// int pos = this->vscroll->GetPosition();
// int max = pos + this->vscroll->GetCapacity();
int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
// const CargoSpec *cs;
// FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
// if (pos-- > 0) continue;
// if (--max < 0) break;
GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
SetDParam(0, cs->name);
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)
{
switch (widget) {
case WID_CPR_ENABLE_CARGOES:
/* Remove all cargoes from the excluded lists. * /
_legend_excluded_cargo = 0;
this->excluded_data = 0;
this->UpdateLoweredWidgets();
this->SetDirty();
break;
// bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
case WID_CPR_DISABLE_CARGOES: {
/* Add all cargoes to the excluded lists. * /
int i = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
SetBit(_legend_excluded_cargo, cs->Index());
SetBit(this->excluded_data, i);
i++;
}
this->UpdateLoweredWidgets();
this->SetDirty();
break;
}
// /* Redraw box if lowered */
// if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_ORANGE, lowered ? FR_LOWERED : FR_NONE);
// byte clk_dif = lowered ? 1 : 0;
// int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
// GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
// GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
// SetDParam(0, cs->name);
// DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
// y += this->line_height;
// }
// }
default:
if (widget >= WID_CPR_CARGO_FIRST) {
int i = widget - WID_CPR_CARGO_FIRST;
ToggleBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index());
this->ToggleWidgetLoweredState(widget);
this->UpdateExcludedData();
this->SetDirty();
}
break;
}
}
*/
virtual void OnGameTick()
{
/* Override default OnGameTick */
}
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
if (!gui_scope) return;
this->OnHundredthTick();
}
virtual void OnHundredthTick()
{
this->UpdateExcludedData();
@@ -1205,25 +1309,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
i++;
}
this->num_dataset = i;
}
};
/** Construct the row containing the digit keys. */
static NWidgetBase *MakeCargoButtons(int *biggest_index)
{
NWidgetVertical *ver = new NWidgetVertical;
for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, WID_CPR_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 = WID_CPR_CARGO_FIRST + _sorted_standard_cargo_specs_size - 1;
return ver;
}
}};
static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
NWidget(NWID_HORIZONTAL),
@@ -1242,12 +1328,15 @@ static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_EMPTY, COLOUR_GREY, WID_CPR_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 0), SetResize(0, 1),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
NWidgetFunction(MakeCargoButtons),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1), SetResize(0, 1),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_MATRIX, COLOUR_ORANGE, WID_CPR_MATRIX), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_ORANGE, WID_CPR_MATRIX_SCROLLBAR),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
EndContainer(),