latest novapolis client for 1.5

--HG--
branch : novattd150
This commit is contained in:
Pavel Stupnikov
2015-03-16 03:20:50 +03:00
parent d201932121
commit e48d2d58e0
69 changed files with 3756 additions and 486 deletions

View File

@@ -103,6 +103,23 @@ struct GraphLegendWindow : Window {
}
};
/** 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;
}
/**
* Construct a vertical list of buttons, one for each company.
* @param biggest_index Storage for collecting the biggest index used in the returned tree.
@@ -533,10 +550,64 @@ 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? */
if (widget == WID_CV_KEY_BUTTON) ShowGraphLegend();
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;
}
}
virtual void OnTick()
@@ -674,8 +745,60 @@ struct IncomeGraphWindow : BaseGraphWindow {
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
{
if(_legend_excluded_cargo == 0){
return c->old_economy[j].income;
}
uint total_income = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (!HasBit(_legend_excluded_cargo, cs->Index())){
total_income += c->old_economy[j].cargo_income[cs->Index()];
}
}
return total_income;
}
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);
}
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[] = {
@@ -690,6 +813,14 @@ static const NWidgetPart _nested_income_graph_widgets[] = {
NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_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_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),
@@ -723,8 +854,60 @@ struct DeliveredCargoGraphWindow : BaseGraphWindow {
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
{
if(_legend_excluded_cargo == 0){
return c->old_economy[j].delivered_cargo.GetSum<OverflowSafeInt64>();
}
uint total_delivered = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
if (!HasBit(_legend_excluded_cargo, cs->Index())){
total_delivered += c->old_economy[j].delivered_cargo[cs->Index()];
}
}
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;
}
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_delivered_cargo_graph_widgets[] = {
@@ -739,6 +922,15 @@ static const NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_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_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),
@@ -899,7 +1091,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
}
this->first_init = false;
}
/*
void UpdateExcludedData()
{
this->excluded_data = 0;
@@ -918,7 +1110,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
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) {
@@ -960,12 +1152,12 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
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. */
/* Remove all cargoes from the excluded lists. * /
_legend_excluded_cargo = 0;
this->excluded_data = 0;
this->UpdateLoweredWidgets();
@@ -973,7 +1165,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
break;
case WID_CPR_DISABLE_CARGOES: {
/* Add all cargoes to the excluded lists. */
/* Add all cargoes to the excluded lists. * /
int i = 0;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
@@ -997,7 +1189,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
break;
}
}
*/
virtual void OnTick()
{
/* Override default OnTick */
@@ -1031,23 +1223,6 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
}
};
/** 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),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
@@ -1582,3 +1757,4 @@ void ShowPerformanceRatingDetail()
{
AllocateWindowDescFront<PerformanceRatingDetailWindow>(&_performance_rating_detail_desc, 0);
}