|
@@ -1091,24 +1091,75 @@ struct PerformanceRatingDetailWindow : W
|
|
|
void UpdateCompanyStats()
|
|
|
{
|
|
|
/* Update all company stats with the current data
|
|
|
* (this is because _score_info is not saved to a savegame) */
|
|
|
Company *c;
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
UpdateCompanyRatingAndValue(c, false);
|
|
|
}
|
|
|
|
|
|
this->timeout = DAY_TICKS * 5;
|
|
|
}
|
|
|
|
|
|
uint score_info_left;
|
|
|
uint score_info_right;
|
|
|
uint bar_left;
|
|
|
uint bar_right;
|
|
|
uint bar_width;
|
|
|
uint bar_height;
|
|
|
uint score_detail_left;
|
|
|
uint score_detail_right;
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
case PRW_SCORE_FIRST:
|
|
|
this->bar_height = FONT_HEIGHT_NORMAL + 4;
|
|
|
size->height = this->bar_height + 2 * WD_MATRIX_TOP;
|
|
|
|
|
|
uint score_info_width = 0;
|
|
|
for (uint i = SCORE_BEGIN; i < SCORE_END; i++) {
|
|
|
score_info_width = max(score_info_width, GetStringBoundingBox(STR_PERFORMANCE_DETAIL_VEHICLES + i).width);
|
|
|
}
|
|
|
SetDParam(0, 1000);
|
|
|
score_info_width += GetStringBoundingBox(STR_BLACK_COMMA).width + WD_FRAMERECT_LEFT;
|
|
|
|
|
|
SetDParam(0, 100);
|
|
|
this->bar_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_PERCENT).width + 20; // Wide bars!
|
|
|
|
|
|
/* At this number we are roughly at the max; it can become wider,
|
|
|
* but then you need at 1000 times more money. At that time you're
|
|
|
* not that interested anymore in the last few digits anyway. */
|
|
|
uint max = 999999999; // nine 9s
|
|
|
SetDParam(0, max);
|
|
|
SetDParam(1, max);
|
|
|
uint score_detail_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY).width;
|
|
|
|
|
|
size->width = 7 + score_info_width + 5 + this->bar_width + 5 + score_detail_width + 7;
|
|
|
uint left = 7;
|
|
|
uint right = size->width - 7;
|
|
|
|
|
|
bool rtl = _dynlang.text_dir == TD_RTL;
|
|
|
this->score_info_left = rtl ? right - score_info_width : left;
|
|
|
this->score_info_right = rtl ? right : left + score_info_width;
|
|
|
|
|
|
this->score_detail_left = rtl ? left : right - score_detail_width;
|
|
|
this->score_detail_right = rtl ? left + score_detail_width : right;
|
|
|
|
|
|
this->bar_left = left + (rtl ? score_detail_width : score_info_width) + 5;
|
|
|
this->bar_right = this->bar_left + this->bar_width;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
/* Draw standard stuff */
|
|
|
this->DrawWidgets();
|
|
|
}
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
{
|
|
|
/* No need to draw when there's nothing to draw */
|
|
|
if (this->company == INVALID_COMPANY) return;
|
|
|
|
|
|
if (IsInsideMM(widget, PRW_COMPANY_FIRST, PRW_COMPANY_LAST + 1)) {
|
|
@@ -1130,58 +1181,67 @@ struct PerformanceRatingDetailWindow : W
|
|
|
|
|
|
/* Draw all the score parts */
|
|
|
int val = _score_part[company][score_type];
|
|
|
int needed = _score_info[score_type].needed;
|
|
|
int score = _score_info[score_type].score;
|
|
|
|
|
|
/* SCORE_TOTAL has his own rules ;) */
|
|
|
if (score_type == SCORE_TOTAL) {
|
|
|
for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) score += _score_info[i].score;
|
|
|
needed = SCORE_MAX;
|
|
|
}
|
|
|
|
|
|
DrawString(7, 107, r.top + 6, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
|
|
|
uint bar_top = r.top + WD_MATRIX_TOP;
|
|
|
uint text_top = bar_top + 2;
|
|
|
|
|
|
DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
|
|
|
|
|
|
/* Draw the score */
|
|
|
SetDParam(0, score);
|
|
|
DrawString(7, 107, r.top + 6, STR_BLACK_INT, TC_FROMSTRING, SA_RIGHT);
|
|
|
DrawString(this->score_info_left, this->score_info_right, text_top, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT);
|
|
|
|
|
|
/* Calculate the %-bar */
|
|
|
byte x = Clamp(val, 0, needed) * 50 / needed;
|
|
|
uint x = Clamp(val, 0, needed) * this->bar_width / needed;
|
|
|
bool rtl = _dynlang.text_dir == TD_RTL;
|
|
|
if (rtl) {
|
|
|
x = this->bar_right - x;
|
|
|
} else {
|
|
|
x = this->bar_left + x;
|
|
|
}
|
|
|
|
|
|
/* Draw the bar */
|
|
|
if (x != 0) GfxFillRect(112, r.top + 4, 112 + x, r.top + 16, colour_done);
|
|
|
if (x != 50) GfxFillRect(112 + x, r.top + 4, 112 + 50, r.top + 16, colour_notdone);
|
|
|
if (x != this->bar_left) GfxFillRect(this->bar_left, bar_top, x, bar_top + this->bar_height, rtl ? colour_notdone : colour_done);
|
|
|
if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height, rtl ? colour_done : colour_notdone);
|
|
|
|
|
|
/* Draw it */
|
|
|
SetDParam(0, Clamp(val, 0, needed) * 100 / needed);
|
|
|
DrawString(112, 162, r.top + 6, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING, SA_CENTER);
|
|
|
DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING, SA_CENTER);
|
|
|
|
|
|
/* SCORE_LOAN is inversed */
|
|
|
if (score_type == SCORE_LOAN) val = needed - val;
|
|
|
|
|
|
/* Draw the amount we have against what is needed
|
|
|
* For some of them it is in currency format */
|
|
|
SetDParam(0, val);
|
|
|
SetDParam(1, needed);
|
|
|
switch (score_type) {
|
|
|
case SCORE_MIN_PROFIT:
|
|
|
case SCORE_MIN_INCOME:
|
|
|
case SCORE_MAX_INCOME:
|
|
|
case SCORE_MONEY:
|
|
|
case SCORE_LOAN:
|
|
|
DrawString(167, this->width, r.top + 6, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY);
|
|
|
DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY);
|
|
|
break;
|
|
|
default:
|
|
|
DrawString(167, this->width, r.top + 6, STR_PERFORMANCE_DETAIL_AMOUNT_INT);
|
|
|
DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_INT);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
{
|
|
|
/* Check which button is clicked */
|
|
|
if (IsInsideMM(widget, PRW_COMPANY_FIRST, PRW_COMPANY_LAST + 1)) {
|
|
|
/* Is it no on disable? */
|
|
|
if (!this->IsWidgetDisabled(widget)) {
|
|
|
this->RaiseWidget(this->company + PRW_COMPANY_FIRST);
|
|
|
this->company = (CompanyID)(widget - PRW_COMPANY_FIRST);
|
|
|
this->LowerWidget(this->company + PRW_COMPANY_FIRST);
|
|
@@ -1247,29 +1307,28 @@ static NWidgetBase *MakePerformanceDetai
|
|
|
STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP,
|
|
|
STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
|
|
|
STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
|
|
|
STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
|
|
|
STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
|
|
|
STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
|
|
|
STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
|
|
|
STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
|
|
|
};
|
|
|
|
|
|
assert_compile(lengthof(performance_tips) == SCORE_END - SCORE_BEGIN);
|
|
|
|
|
|
NWidgetVertical *vert = new NWidgetVertical();
|
|
|
NWidgetVertical *vert = new NWidgetVertical(NC_EQUALSIZE);
|
|
|
for (int widnum = PRW_SCORE_FIRST; widnum <= PRW_SCORE_LAST; widnum++) {
|
|
|
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
|
|
|
panel->SetMinimalSize(299, 20);
|
|
|
panel->SetFill(false, false);
|
|
|
panel->SetFill(true, true);
|
|
|
panel->SetDataTip(0x0, performance_tips[widnum - PRW_SCORE_FIRST]);
|
|
|
vert->Add(panel);
|
|
|
}
|
|
|
*biggest_index = PRW_SCORE_LAST;
|
|
|
return vert;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Make a number of rows with button-like graphics, for enabling/disabling each company.
|
|
|
* @param biggest_index Storage for collecting the biggest index used in the returned tree.
|
|
|
* @return Panel with rows of company buttons.
|
|
|
* @postcond \c *biggest_index contains the largest used index in the tree.
|