tron@2186: /* $Id$ */ tron@2186: rubidium@10455: /** @file graph_gui.cpp GUI that shows performance graphs. */ belugas@6505: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" truelight@0: #include "gui.h" rubidium@9723: #include "window_gui.h" rubidium@9724: #include "player_base.h" rubidium@9724: #include "player_gui.h" rubidium@9723: #include "economy_func.h" tron@2159: #include "variables.h" peter1138@6417: #include "cargotype.h" rubidium@9723: #include "strings_func.h" rubidium@9723: #include "core/alloc_func.hpp" rubidium@9723: #include "window_func.h" rubidium@9723: #include "date_func.h" rubidium@9723: #include "gfx_func.h" rubidium@11044: #include "sortlist_type.h" Darkvater@5291: rubidium@9724: #include "table/strings.h" rubidium@9724: #include "table/sprites.h" rubidium@9724: maedhros@6057: /* Bitmasks of player and cargo indices that shouldn't be drawn. */ maedhros@6057: static uint _legend_excluded_players; maedhros@6057: static uint _legend_excluded_cargo; truelight@0: maedhros@6056: /* Apparently these don't play well with enums. */ rubidium@9724: static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn. rubidium@9722: static const uint INVALID_DATAPOINT_POS = UINT_MAX; // Used to determine if the previous point was drawn. maedhros@6056: truelight@0: /****************/ truelight@0: /* GRAPH LEGEND */ truelight@0: /****************/ truelight@0: glx@10645: struct GraphLegendWindow : Window { glx@10645: GraphLegendWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) glx@10645: { glx@10645: for (uint i = 3; i < this->widget_count; i++) { glx@10645: if (!HasBit(_legend_excluded_players, i - 3)) this->LowerWidget(i); truelight@0: } truelight@0: glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } peter1138@6529: glx@10645: virtual void OnPaint() glx@10645: { glx@10645: const Player *p; glx@10645: glx@10645: FOR_ALL_PLAYERS(p) { glx@10645: if (p->is_active) continue; glx@10645: glx@10645: SetBit(_legend_excluded_players, p->index); glx@10645: this->RaiseWidget(p->index + 3); glx@10645: } glx@10645: glx@10645: this->DrawWidgets(); glx@10645: glx@10645: FOR_ALL_PLAYERS(p) { glx@10645: if (!p->is_active) continue; glx@10645: glx@10645: DrawPlayerIcon(p->index, 4, 18 + p->index * 12); glx@10645: glx@10645: SetDParam(0, p->index); glx@10645: SetDParam(1, p->index); glx@10645: DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE); glx@10645: } truelight@0: } glx@10645: glx@10645: virtual void OnClick(Point pt, int widget) glx@10645: { glx@10645: if (!IsInsideMM(widget, 3, 11)) return; glx@10645: glx@10645: ToggleBit(_legend_excluded_players, widget - 3); glx@10645: this->ToggleWidgetLoweredState(widget); glx@10645: this->SetDirty(); glx@10645: InvalidateWindow(WC_INCOME_GRAPH, 0); glx@10645: InvalidateWindow(WC_OPERATING_PROFIT, 0); glx@10645: InvalidateWindow(WC_DELIVERED_CARGO, 0); glx@10645: InvalidateWindow(WC_PERFORMANCE_HISTORY, 0); glx@10645: InvalidateWindow(WC_COMPANY_VALUE, 0); glx@10645: } glx@10645: }; truelight@0: truelight@0: static const Widget _graph_legend_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 14, 11, 249, 0, 13, STR_704E_KEY_TO_COMPANY_GRAPHS, STR_018C_WINDOW_TITLE_DRAG_THIS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 249, 14, 113, 0x0, STR_NULL}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 16, 27, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 28, 39, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 40, 51, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 52, 63, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 64, 75, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 76, 87, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 88, 99, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 247, 100, 111, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _graph_legend_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 250, 114, 250, 114, rubidium@6144: WC_GRAPH_LEGEND, WC_NONE, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _graph_legend_widgets, truelight@0: }; truelight@0: rubidium@6573: static void ShowGraphLegend() truelight@0: { glx@10645: AllocateWindowDescFront(&_graph_legend_desc, 0); truelight@0: } truelight@0: glx@10645: /******************/ glx@10645: /* BASE OF GRAPHS */ glx@10645: /*****************/ glx@10645: glx@10645: struct BaseGraphWindow : Window { glx@10645: protected: glx@10645: enum { glx@10645: GRAPH_MAX_DATASETS = 32, glx@10645: GRAPH_AXIS_LABEL_COLOUR = TC_BLACK, glx@10645: GRAPH_AXIS_LINE_COLOUR = 215, glx@10645: glx@10645: GRAPH_X_POSITION_BEGINNING = 44, ///< Start the graph 44 pixels from gd_left glx@10645: GRAPH_X_POSITION_SEPARATION = 22, ///< There are 22 pixels between each X value glx@10645: glx@10645: GRAPH_NUM_LINES_Y = 9, ///< How many horizontal lines to draw. glx@10645: /* 9 is convenient as that means the distance between them is the gd_height of the graph / 8, glx@10645: * which is the same glx@10645: * as height >> 3. */ glx@10645: }; glx@10645: glx@10645: uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed. glx@10645: byte num_dataset; glx@10645: byte num_on_x_axis; glx@10645: bool has_negative_values; glx@10645: byte num_vert_lines; glx@10645: glx@10645: /* The starting month and year that values are plotted against. If month is glx@10645: * 0xFF, use x_values_start and x_values_increment below instead. */ glx@10645: byte month; glx@10645: Year year; glx@10645: glx@10645: /* These values are used if the graph is being plotted against values glx@10645: * rather than the dates specified by month and year. */ glx@10645: uint16 x_values_start; glx@10645: uint16 x_values_increment; glx@10645: glx@10645: int gd_left, gd_top; ///< Where to start drawing the graph, in pixels. glx@10645: uint gd_height; ///< The height of the graph in pixels. glx@10645: StringID format_str_y_axis; glx@10645: byte colors[GRAPH_MAX_DATASETS]; glx@10645: OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years glx@10645: glx@10645: void DrawGraph() const glx@10645: { glx@10645: uint x, y; ///< Reused whenever x and y coordinates are needed. glx@10645: OverflowSafeInt64 highest_value; ///< Highest value to be drawn. glx@10645: int x_axis_offset; ///< Distance from the top of the graph to the x axis. glx@10645: glx@10645: /* the colors and cost array of GraphDrawer must accomodate glx@10645: * both values for cargo and players. So if any are higher, quit */ glx@10645: assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS); glx@10645: assert(this->num_vert_lines > 0); glx@10645: glx@10645: byte grid_colour = _colour_gradient[14][4]; glx@10645: glx@10645: /* The coordinates of the opposite edges of the graph. */ glx@10645: int bottom = this->gd_top + this->gd_height - 1; glx@10645: int right = this->gd_left + GRAPH_X_POSITION_BEGINNING + this->num_vert_lines * GRAPH_X_POSITION_SEPARATION - 1; glx@10645: glx@10645: /* Draw the vertical grid lines. */ glx@10645: glx@10645: /* Don't draw the first line, as that's where the axis will be. */ glx@10645: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + GRAPH_X_POSITION_SEPARATION; glx@10645: glx@10645: for (int i = 0; i < this->num_vert_lines; i++) { glx@10645: GfxFillRect(x, this->gd_top, x, bottom, grid_colour); glx@10645: x += GRAPH_X_POSITION_SEPARATION; glx@10645: } glx@10645: glx@10645: /* Draw the horizontal grid lines. */ glx@10645: x = this->gd_left + GRAPH_X_POSITION_BEGINNING; glx@10645: y = this->gd_height + this->gd_top; glx@10645: glx@10645: for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) { glx@10645: GfxFillRect(x, y, right, y, grid_colour); glx@10645: y -= (this->gd_height / (GRAPH_NUM_LINES_Y - 1)); glx@10645: } glx@10645: glx@10645: /* Draw the y axis. */ glx@10645: GfxFillRect(x, this->gd_top, x, bottom, GRAPH_AXIS_LINE_COLOUR); glx@10645: glx@10645: /* Find the distance from the gd_top of the graph to the x axis. */ glx@10645: x_axis_offset = this->gd_height; glx@10645: glx@10645: /* The graph is currently symmetrical about the x axis. */ glx@10645: if (this->has_negative_values) x_axis_offset /= 2; glx@10645: glx@10645: /* Draw the x axis. */ glx@10645: y = x_axis_offset + this->gd_top; glx@10645: GfxFillRect(x, y, right, y, GRAPH_AXIS_LINE_COLOUR); glx@10645: glx@10645: /* Find the largest value that will be drawn. */ glx@10645: if (this->num_on_x_axis == 0) glx@10645: return; glx@10645: glx@10645: assert(this->num_on_x_axis > 0); glx@10645: assert(this->num_dataset > 0); glx@10645: glx@10645: /* Start of with a value of twice the gd_height of the graph in pixels. It's a glx@10645: * bit arbitrary, but it makes the cargo payment graph look a little nicer, glx@10645: * and prevents division by zero when calculating where the datapoint glx@10645: * should be drawn. */ glx@10645: highest_value = x_axis_offset * 2; glx@10645: glx@10645: for (int i = 0; i < this->num_dataset; i++) { glx@10645: if (!HasBit(this->excluded_data, i)) { glx@10645: for (int j = 0; j < this->num_on_x_axis; j++) { glx@10645: OverflowSafeInt64 datapoint = this->cost[i][j]; glx@10645: glx@10645: if (datapoint != INVALID_DATAPOINT) { glx@10645: /* For now, if the graph has negative values the scaling is glx@10645: * symmetrical about the x axis, so take the absolute value glx@10645: * of each data point. */ glx@10645: highest_value = max(highest_value, abs(datapoint)); glx@10645: } glx@10645: } glx@10645: } glx@10645: } glx@10645: glx@10645: /* Round up highest_value so that it will divide cleanly into the number of glx@10645: * axis labels used. */ glx@10645: int round_val = highest_value % (GRAPH_NUM_LINES_Y - 1); glx@10645: if (round_val != 0) highest_value += (GRAPH_NUM_LINES_Y - 1 - round_val); glx@10645: glx@10645: /* draw text strings on the y axis */ glx@10645: int64 y_label = highest_value; glx@10645: int64 y_label_separation = highest_value / (GRAPH_NUM_LINES_Y - 1); glx@10645: glx@10645: /* If there are negative values, the graph goes from highest_value to glx@10645: * -highest_value, not highest_value to 0. */ glx@10645: if (this->has_negative_values) y_label_separation *= 2; glx@10645: glx@10645: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + 1; glx@10645: y = this->gd_top - 3; glx@10645: glx@10645: for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) { glx@10645: SetDParam(0, this->format_str_y_axis); glx@10645: SetDParam(1, y_label); glx@10645: DrawStringRightAligned(x, y, STR_0170, GRAPH_AXIS_LABEL_COLOUR); glx@10645: glx@10645: y_label -= y_label_separation; glx@10645: y += (this->gd_height / (GRAPH_NUM_LINES_Y - 1)); glx@10645: } glx@10645: glx@10645: /* draw strings on the x axis */ glx@10645: if (this->month != 0xFF) { glx@10645: x = this->gd_left + GRAPH_X_POSITION_BEGINNING; glx@10645: y = this->gd_top + this->gd_height + 1; glx@10645: byte month = this->month; glx@10645: Year year = this->year; glx@10645: for (int i = 0; i < this->num_on_x_axis; i++) { glx@10645: SetDParam(0, month + STR_0162_JAN); glx@10645: SetDParam(1, month + STR_0162_JAN + 2); glx@10645: SetDParam(2, year); glx@10645: DrawString(x, y, month == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR); glx@10645: glx@10645: month += 3; glx@10645: if (month >= 12) { glx@10645: month = 0; glx@10645: year++; glx@10645: } glx@10645: x += GRAPH_X_POSITION_SEPARATION; glx@10645: } glx@10645: } else { glx@10645: /* Draw the label under the data point rather than on the grid line. */ glx@10645: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2) + 1; glx@10645: y = this->gd_top + this->gd_height + 1; glx@10645: uint16 label = this->x_values_start; glx@10645: glx@10645: for (int i = 0; i < this->num_on_x_axis; i++) { glx@10645: SetDParam(0, label); glx@10645: DrawStringCentered(x, y, STR_01CB, GRAPH_AXIS_LABEL_COLOUR); glx@10645: glx@10645: label += this->x_values_increment; glx@10645: x += GRAPH_X_POSITION_SEPARATION; glx@10645: } glx@10645: } glx@10645: glx@10645: /* draw lines and dots */ glx@10645: for (int i = 0; i < this->num_dataset; i++) { glx@10645: if (!HasBit(this->excluded_data, i)) { glx@10645: /* Centre the dot between the grid lines. */ glx@10645: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2); glx@10645: glx@10645: byte color = this->colors[i]; glx@10645: uint prev_x = INVALID_DATAPOINT_POS; glx@10645: uint prev_y = INVALID_DATAPOINT_POS; glx@10645: glx@10645: for (int j = 0; j < this->num_on_x_axis; j++) { glx@10645: OverflowSafeInt64 datapoint = this->cost[i][j]; glx@10645: glx@10645: if (datapoint != INVALID_DATAPOINT) { glx@10645: /* glx@10645: * Check whether we need to reduce the 'accuracy' of the glx@10645: * datapoint value and the highest value to splut overflows. glx@10645: * And when 'drawing' 'one million' or 'one million and one' glx@10645: * there is no significant difference, so the least glx@10645: * significant bits can just be removed. glx@10645: * glx@10645: * If there are more bits needed than would fit in a 32 bits glx@10645: * integer, so at about 31 bits because of the sign bit, the glx@10645: * least significant bits are removed. glx@10645: */ glx@10645: int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint)); glx@10645: int reduce_range = max(mult_range - 31, 0); glx@10645: glx@10645: /* Handle negative values differently (don't shift sign) */ glx@10645: if (datapoint < 0) { glx@10645: datapoint = -(abs(datapoint) >> reduce_range); glx@10645: } else { glx@10645: datapoint >>= reduce_range; glx@10645: } glx@10645: glx@10645: y = this->gd_top + x_axis_offset - (x_axis_offset * datapoint) / (highest_value >> reduce_range); glx@10645: glx@10645: /* Draw the point. */ glx@10645: GfxFillRect(x - 1, y - 1, x + 1, y + 1, color); glx@10645: glx@10645: /* Draw the line connected to the previous point. */ glx@10645: if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, color); glx@10645: glx@10645: prev_x = x; glx@10645: prev_y = y; glx@10645: } else { glx@10645: prev_x = INVALID_DATAPOINT_POS; glx@10645: prev_y = INVALID_DATAPOINT_POS; glx@10645: } glx@10645: glx@10645: x += GRAPH_X_POSITION_SEPARATION; glx@10645: } glx@10645: } glx@10645: } glx@10645: } glx@10645: glx@10645: glx@10645: BaseGraphWindow(const WindowDesc *desc, WindowNumber window_number, int left, glx@10645: int top, int height, bool has_negative_values, StringID format_str_y_axis) : glx@10645: Window(desc, window_number), has_negative_values(has_negative_values), glx@10645: gd_left(left), gd_top(top), gd_height(height), format_str_y_axis(format_str_y_axis) glx@10645: { glx@10645: InvalidateWindow(WC_GRAPH_LEGEND, 0); glx@10645: } glx@10645: glx@10645: public: glx@10645: virtual void OnPaint() glx@10645: { glx@10645: this->DrawWidgets(); glx@10645: glx@10645: uint excluded_players = _legend_excluded_players; glx@10645: glx@10645: /* Exclude the players which aren't valid */ glx@10645: const Player* p; glx@10645: FOR_ALL_PLAYERS(p) { glx@10645: if (!p->is_active) SetBit(excluded_players, p->index); glx@10645: } glx@10645: this->excluded_data = excluded_players; glx@10645: this->num_vert_lines = 24; glx@10645: glx@10645: byte nums = 0; glx@10645: FOR_ALL_PLAYERS(p) { glx@10645: if (p->is_active) nums = max(nums, p->num_valid_stat_ent); glx@10645: } glx@10645: this->num_on_x_axis = min(nums, 24); glx@10645: glx@10645: int mo = (_cur_month / 3 - nums) * 3; glx@10645: int yr = _cur_year; glx@10645: while (mo < 0) { glx@10645: yr--; glx@10645: mo += 12; glx@10645: } glx@10645: glx@10645: this->year = yr; glx@10645: this->month = mo; glx@10645: glx@10645: int numd = 0; glx@10645: FOR_ALL_PLAYERS(p) { glx@10645: if (p->is_active) { glx@10645: this->colors[numd] = _colour_gradient[p->player_color][6]; glx@10645: for (int j = this->num_on_x_axis, i = 0; --j >= 0;) { glx@10645: this->cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(p, j); glx@10645: i++; glx@10645: } glx@10645: } glx@10645: numd++; glx@10645: } glx@10645: glx@10645: this->num_dataset = numd; glx@10645: glx@10645: this->DrawGraph(); glx@10645: } glx@10645: glx@10645: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) glx@10645: { glx@10645: return INVALID_DATAPOINT; glx@10645: } glx@10645: glx@10645: virtual void OnClick(Point pt, int widget) glx@10645: { glx@10645: /* Clicked on legend? */ glx@10645: if (widget == 2) ShowGraphLegend(); glx@10645: } glx@10645: }; glx@10645: truelight@0: /********************/ truelight@0: /* OPERATING PROFIT */ truelight@0: /********************/ truelight@0: glx@10645: struct OperatingProfitGraphWindow : BaseGraphWindow { glx@10645: OperatingProfitGraphWindow(const WindowDesc *desc, WindowNumber window_number) : glx@10645: BaseGraphWindow(desc, window_number, 2, 18, 136, true, STR_CURRCOMPACT) glx@10645: { glx@10645: this->FindWindowPlacementAndResize(desc); truelight@0: } truelight@0: glx@10645: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) glx@10645: { glx@10645: return p->old_economy[j].income + p->old_economy[j].expenses; truelight@0: } glx@10645: }; truelight@0: truelight@0: static const Widget _operating_profit_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7025_OPERATING_PROFIT_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 575, 14, 173, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _operating_profit_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 576, 174, 576, 174, rubidium@6144: WC_OPERATING_PROFIT, WC_NONE, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _operating_profit_widgets, truelight@0: }; truelight@0: truelight@0: rubidium@6573: void ShowOperatingProfitGraph() truelight@0: { glx@10645: AllocateWindowDescFront(&_operating_profit_desc, 0); truelight@0: } truelight@0: truelight@0: truelight@0: /****************/ truelight@0: /* INCOME GRAPH */ truelight@0: /****************/ truelight@0: glx@10645: struct IncomeGraphWindow : BaseGraphWindow { glx@10645: IncomeGraphWindow(const WindowDesc *desc, WindowNumber window_number) : glx@10645: BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_CURRCOMPACT) glx@10645: { glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } peter1138@6529: glx@10645: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) glx@10645: { glx@10645: return p->old_economy[j].income; truelight@0: } glx@10645: }; truelight@0: truelight@0: static const Widget _income_graph_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7022_INCOME_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 575, 14, 141, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _income_graph_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 576, 142, 576, 142, rubidium@6144: WC_INCOME_GRAPH, WC_NONE, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _income_graph_widgets, truelight@0: }; truelight@0: rubidium@6573: void ShowIncomeGraph() truelight@0: { glx@10645: AllocateWindowDescFront(&_income_graph_desc, 0); truelight@0: } truelight@0: truelight@0: /*******************/ truelight@0: /* DELIVERED CARGO */ truelight@0: /*******************/ truelight@0: glx@10645: struct DeliveredCargoGraphWindow : BaseGraphWindow { glx@10645: DeliveredCargoGraphWindow(const WindowDesc *desc, WindowNumber window_number) : glx@10645: BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_7024) glx@10645: { glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } peter1138@6529: glx@10645: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) glx@10645: { glx@10645: return p->old_economy[j].delivered_cargo; truelight@0: } glx@10645: }; truelight@0: truelight@0: static const Widget _delivered_cargo_graph_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7050_UNITS_OF_CARGO_DELIVERED, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 575, 14, 141, 0x0, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _delivered_cargo_graph_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 576, 142, 576, 142, rubidium@6144: WC_DELIVERED_CARGO, WC_NONE, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _delivered_cargo_graph_widgets, truelight@0: }; truelight@0: rubidium@6573: void ShowDeliveredCargoGraph() truelight@0: { glx@10645: AllocateWindowDescFront(&_delivered_cargo_graph_desc, 0); dominik@116: } dominik@116: darkvater@1086: /***********************/ darkvater@1086: /* PERFORMANCE HISTORY */ darkvater@1086: /***********************/ darkvater@1086: glx@10645: struct PerformanceHistoryGraphWindow : BaseGraphWindow { glx@10645: PerformanceHistoryGraphWindow(const WindowDesc *desc, WindowNumber window_number) : glx@10645: BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_7024) glx@10645: { glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } peter1138@6529: glx@10645: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) glx@10645: { glx@10645: return p->old_economy[j].performance_history; glx@10645: } peter1138@6529: glx@10645: virtual void OnClick(Point pt, int widget) glx@10645: { glx@10645: if (widget == 3) ShowPerformanceRatingDetail(); glx@10645: this->BaseGraphWindow::OnClick(pt, widget); darkvater@1086: } glx@10645: }; darkvater@1086: darkvater@1086: static const Widget _performance_history_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 14, 11, 475, 0, 13, STR_7051_COMPANY_PERFORMANCE_RATINGS, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 476, 525, 0, 13, STR_PERFORMANCE_DETAIL_KEY, STR_704D_SHOW_KEY_TO_GRAPHS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 575, 14, 237, 0x0, STR_NULL}, darkvater@1086: { WIDGETS_END}, darkvater@1086: }; darkvater@1086: darkvater@1086: static const WindowDesc _performance_history_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 576, 238, 576, 238, rubidium@6144: WC_PERFORMANCE_HISTORY, WC_NONE, darkvater@1086: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, darkvater@1086: _performance_history_widgets, darkvater@1086: }; darkvater@1086: rubidium@6573: void ShowPerformanceHistoryGraph() darkvater@1086: { glx@10645: AllocateWindowDescFront(&_performance_history_desc, 0); darkvater@1086: } darkvater@1086: darkvater@1086: /*****************/ darkvater@1086: /* COMPANY VALUE */ darkvater@1086: /*****************/ darkvater@1086: glx@10645: struct CompanyValueGraphWindow : BaseGraphWindow { glx@10645: CompanyValueGraphWindow(const WindowDesc *desc, WindowNumber window_number) : glx@10645: BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_CURRCOMPACT) glx@10645: { glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } peter1138@6529: glx@10645: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) glx@10645: { glx@10645: return p->old_economy[j].company_value; darkvater@1086: } glx@10645: }; darkvater@1086: darkvater@1086: static const Widget _company_value_graph_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7052_COMPANY_VALUES, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 575, 14, 237, 0x0, STR_NULL}, darkvater@1086: { WIDGETS_END}, darkvater@1086: }; darkvater@1086: darkvater@1086: static const WindowDesc _company_value_graph_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 576, 238, 576, 238, rubidium@6144: WC_COMPANY_VALUE, WC_NONE, darkvater@1086: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, darkvater@1086: _company_value_graph_widgets, darkvater@1086: }; darkvater@1086: rubidium@6573: void ShowCompanyValueGraph() darkvater@1086: { glx@10645: AllocateWindowDescFront(&_company_value_graph_desc, 0); darkvater@1086: } darkvater@1086: darkvater@1086: /*****************/ darkvater@1086: /* PAYMENT RATES */ darkvater@1086: /*****************/ darkvater@1086: glx@10645: struct PaymentRatesGraphWindow : BaseGraphWindow { glx@10645: PaymentRatesGraphWindow(const WindowDesc *desc, WindowNumber window_number) : glx@10645: BaseGraphWindow(desc, window_number, 2, 24, 200, false, STR_CURRCOMPACT) glx@10645: { glx@10645: uint num_active = 0; glx@10645: for (CargoID c = 0; c < NUM_CARGO; c++) { glx@10645: if (GetCargo(c)->IsValid()) num_active++; darkvater@1086: } peter1138@6529: glx@10645: /* Resize the window to fit the cargo types */ glx@10645: ResizeWindow(this, 0, max(num_active, 12U) * 8); glx@10645: glx@10645: /* Add widgets for each cargo type */ glx@10645: this->widget_count += num_active; glx@10645: this->widget = ReallocT(this->widget, this->widget_count + 1); glx@10645: this->widget[this->widget_count].type = WWT_LAST; glx@10645: glx@10645: /* Set the properties of each widget */ glx@10645: for (uint i = 0; i != num_active; i++) { glx@10645: Widget *wi = &this->widget[3 + i]; glx@10645: wi->type = WWT_PANEL; glx@10645: wi->display_flags = RESIZE_NONE; glx@10645: wi->color = 12; glx@10645: wi->left = 493; glx@10645: wi->right = 562; glx@10645: wi->top = 24 + i * 8; glx@10645: wi->bottom = wi->top + 7; glx@10645: wi->data = 0; glx@10645: wi->tooltips = STR_7064_TOGGLE_GRAPH_FOR_CARGO; glx@10645: glx@10645: if (!HasBit(_legend_excluded_cargo, i)) this->LowerWidget(i + 3); glx@10645: } glx@10645: glx@10645: this->SetDirty(); glx@10645: glx@10645: this->gd_height = this->height - 38; glx@10645: this->num_on_x_axis = 20; glx@10645: this->num_vert_lines = 20; glx@10645: this->month = 0xFF; glx@10645: this->x_values_start = 10; glx@10645: this->x_values_increment = 10; glx@10645: glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } glx@10645: glx@10645: virtual void OnPaint() glx@10645: { glx@10645: this->DrawWidgets(); glx@10645: glx@10645: this->excluded_data = _legend_excluded_cargo; glx@10645: glx@10645: int x = 495; glx@10645: int y = 24; glx@10645: glx@10645: uint i = 0; glx@10645: for (CargoID c = 0; c < NUM_CARGO; c++) { glx@10645: const CargoSpec *cs = GetCargo(c); glx@10645: if (!cs->IsValid()) continue; glx@10645: glx@10645: /* Only draw labels for widgets that exist. If the widget doesn't glx@10645: * exist then the local player has used the climate cheat or glx@10645: * changed the NewGRF configuration with this window open. */ glx@10645: if (i + 3 < this->widget_count) { glx@10645: /* Since the buttons have no text, no images, glx@10645: * both the text and the colored box have to be manually painted. glx@10645: * clk_dif will move one pixel down and one pixel to the right glx@10645: * when the button is clicked */ glx@10645: byte clk_dif = this->IsWidgetLowered(i + 3) ? 1 : 0; glx@10645: glx@10645: GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0); glx@10645: GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour); glx@10645: SetDParam(0, cs->name); glx@10645: DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, TC_FROMSTRING); glx@10645: y += 8; peter1138@6529: } glx@10645: glx@10645: this->colors[i] = cs->legend_colour; glx@10645: for (uint j = 0; j != 20; j++) { glx@10645: this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, c); glx@10645: } glx@10645: glx@10645: i++; glx@10645: } glx@10645: this->num_dataset = i; glx@10645: glx@10645: this->DrawGraph(); glx@10645: glx@10645: DrawString(2 + 46, 24 + this->gd_height + 7, STR_7062_DAYS_IN_TRANSIT, TC_FROMSTRING); glx@10645: DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, TC_FROMSTRING); darkvater@1086: } glx@10645: glx@10645: virtual void OnClick(Point pt, int widget) glx@10645: { glx@10645: if (widget >= 3) { glx@10645: ToggleBit(_legend_excluded_cargo, widget - 3); glx@10645: this->ToggleWidgetLoweredState(widget); glx@10645: this->SetDirty(); glx@10645: } glx@10645: } glx@10645: }; darkvater@1086: darkvater@1086: static const Widget _cargo_payment_rates_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 14, 11, 567, 0, 13, STR_7061_CARGO_PAYMENT_RATES, STR_018C_WINDOW_TITLE_DRAG_THIS}, peter1138@6518: { WWT_PANEL, RESIZE_BOTTOM, 14, 0, 567, 14, 45, 0x0, STR_NULL}, darkvater@1086: { WIDGETS_END}, darkvater@1086: }; darkvater@1086: darkvater@1086: static const WindowDesc _cargo_payment_rates_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 568, 46, 568, 46, rubidium@6144: WC_PAYMENT_RATES, WC_NONE, darkvater@1086: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, darkvater@1086: _cargo_payment_rates_widgets, darkvater@1086: }; darkvater@1086: darkvater@1086: rubidium@6573: void ShowCargoPaymentRates() darkvater@1086: { glx@10645: AllocateWindowDescFront(&_cargo_payment_rates_desc, 0); darkvater@1086: } darkvater@1086: darkvater@1086: /************************/ darkvater@1086: /* COMPANY LEAGUE TABLE */ darkvater@1086: /************************/ darkvater@1086: darkvater@1086: static const StringID _performance_titles[] = { darkvater@1086: STR_7066_ENGINEER, darkvater@1086: STR_7066_ENGINEER, darkvater@1086: STR_7067_TRAFFIC_MANAGER, darkvater@1086: STR_7067_TRAFFIC_MANAGER, darkvater@1086: STR_7068_TRANSPORT_COORDINATOR, darkvater@1086: STR_7068_TRANSPORT_COORDINATOR, darkvater@1086: STR_7069_ROUTE_SUPERVISOR, darkvater@1086: STR_7069_ROUTE_SUPERVISOR, darkvater@1086: STR_706A_DIRECTOR, darkvater@1086: STR_706A_DIRECTOR, darkvater@1086: STR_706B_CHIEF_EXECUTIVE, darkvater@1086: STR_706B_CHIEF_EXECUTIVE, darkvater@1086: STR_706C_CHAIRMAN, darkvater@1086: STR_706C_CHAIRMAN, darkvater@1086: STR_706D_PRESIDENT, darkvater@1086: STR_706E_TYCOON, darkvater@1086: }; darkvater@1086: darkvater@1086: static inline StringID GetPerformanceTitleFromValue(uint value) darkvater@1086: { darkvater@1086: return _performance_titles[minu(value, 1000) >> 6]; darkvater@1086: } darkvater@1086: rubidium@11044: class CompanyLeagueWindow : public Window { rubidium@11044: private: rubidium@11044: GUIList players; tron@2656: rubidium@11044: /** rubidium@11044: * (Re)Build the company league list rubidium@11044: */ rubidium@11044: void BuildPlayerList() rubidium@11044: { rubidium@11044: if (!this->players.NeedRebuild()) return; darkvater@1086: rubidium@11044: this->players.Clear(); rubidium@11044: rubidium@11044: const Player *p; rubidium@11044: FOR_ALL_PLAYERS(p) { rubidium@11044: if (p->is_active) { rubidium@11044: *this->players.Append() = p; rubidium@11044: } rubidium@11044: } rubidium@11044: rubidium@11044: this->players.Compact(); rubidium@11044: this->players.RebuildDone(); rubidium@11044: } rubidium@11044: rubidium@11044: /** Sort the company league by performance history */ rubidium@11044: static int CDECL PerformanceSorter(const Player* const *p1, const Player* const *p2) rubidium@11044: { rubidium@11044: return (*p2)->old_economy[1].performance_history - (*p1)->old_economy[1].performance_history; rubidium@11044: } rubidium@11044: rubidium@11044: public: glx@10645: CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) glx@10645: { rubidium@11044: this->players.ForceRebuild(); rubidium@11044: this->players.NeedResort(); rubidium@11044: rubidium@10715: this->FindWindowPlacementAndResize(desc); glx@10645: } darkvater@1086: glx@10645: virtual void OnPaint() glx@10645: { rubidium@11044: this->BuildPlayerList(); rubidium@11044: this->players.Sort(&PerformanceSorter); darkvater@1086: glx@10645: this->DrawWidgets(); tron@2656: rubidium@11044: for (uint i = 0; i != this->players.Length(); i++) { rubidium@11044: const Player *p = this->players[i]; glx@10645: SetDParam(0, i + STR_01AC_1ST); glx@10645: SetDParam(1, p->index); glx@10645: SetDParam(2, p->index); glx@10645: SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history)); glx@10645: glx@10645: DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING); glx@10645: DrawPlayerIcon(p->index, 27, 16 + i * 10); tron@2656: } darkvater@1086: } rubidium@11044: rubidium@11044: virtual void OnTick() rubidium@11044: { rubidium@11044: if (this->players.NeedResort()) { rubidium@11044: this->SetDirty(); rubidium@11044: } rubidium@11044: } rubidium@11044: rubidium@11044: virtual void OnInvalidateData(int data) rubidium@11044: { rubidium@11044: if (data == 0) { rubidium@11044: this->players.ForceRebuild(); rubidium@11044: } else { rubidium@11044: this->players.ForceResort(); rubidium@11044: } rubidium@11044: } glx@10645: }; darkvater@1086: darkvater@1086: darkvater@1086: static const Widget _company_league_widgets[] = { peter1138@2869: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, peter1138@2869: { WWT_CAPTION, RESIZE_NONE, 14, 11, 387, 0, 13, STR_7053_COMPANY_LEAGUE_TABLE, STR_018C_WINDOW_TITLE_DRAG_THIS}, peter1138@2869: { WWT_STICKYBOX, RESIZE_NONE, 14, 388, 399, 0, 13, STR_NULL, STR_STICKY_BUTTON}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 96, 0x0, STR_NULL}, darkvater@1086: { WIDGETS_END}, darkvater@1086: }; darkvater@1086: darkvater@1086: static const WindowDesc _company_league_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 400, 97, 400, 97, rubidium@6144: WC_COMPANY_LEAGUE, WC_NONE, peter1138@2869: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, darkvater@1086: _company_league_widgets, darkvater@1086: }; darkvater@1086: rubidium@6573: void ShowCompanyLeagueTable() darkvater@1086: { glx@10645: AllocateWindowDescFront(&_company_league_desc, 0); darkvater@1086: } darkvater@1086: dominik@116: /*****************************/ dominik@116: /* PERFORMANCE RATING DETAIL */ dominik@116: /*****************************/ dominik@116: glx@10645: struct PerformanceRatingDetailWindow : Window { glx@10645: static PlayerID player; glx@10645: int timeout; maedhros@6197: glx@10645: PerformanceRatingDetailWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) glx@10645: { glx@10645: /* Disable the players who are not active */ glx@10645: for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { glx@10645: this->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active); glx@10645: } maedhros@6197: glx@10645: this->UpdatePlayerStats(); maedhros@6197: glx@10645: if (player != INVALID_PLAYER) this->LowerWidget(player + 13); peter1138@3027: glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } peter1138@3027: glx@10645: void UpdatePlayerStats() glx@10645: { glx@10645: /* Update all player stats with the current data glx@10645: * (this is because _score_info is not saved to a savegame) */ glx@10645: Player *p; glx@10645: FOR_ALL_PLAYERS(p) { glx@10645: if (p->is_active) UpdateCompanyRatingAndValue(p, false); glx@10645: } glx@10645: glx@10645: this->timeout = DAY_TICKS * 5; glx@10645: glx@10645: } glx@10645: glx@10645: virtual void OnPaint() glx@10645: { glx@10645: byte x; glx@10645: uint16 y = 14; glx@10645: int total_score = 0; glx@10645: int color_done, color_notdone; glx@10645: glx@10645: /* Draw standard stuff */ glx@10645: this->DrawWidgets(); glx@10645: glx@10645: /* Check if the currently selected player is still active. */ glx@10645: if (player == INVALID_PLAYER || !GetPlayer(player)->is_active) { glx@10645: if (player != INVALID_PLAYER) { glx@10645: /* Raise and disable the widget for the previous selection. */ glx@10645: this->RaiseWidget(player + 13); glx@10645: this->DisableWidget(player + 13); glx@10645: this->SetDirty(); glx@10645: glx@10645: player = INVALID_PLAYER; peter1138@3027: } peter1138@3027: glx@10645: for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { glx@10645: if (GetPlayer(i)->is_active) { glx@10645: /* Lower the widget corresponding to this player. */ glx@10645: this->LowerWidget(i + 13); glx@10645: this->SetDirty(); peter1138@3027: glx@10645: player = i; glx@10645: break; peter1138@3027: } peter1138@3027: } dominik@116: } truelight@193: glx@10645: /* If there are no active players, don't display anything else. */ glx@10645: if (player == INVALID_PLAYER) return; glx@10645: glx@10645: /* Paint the player icons */ glx@10645: for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { glx@10645: if (!GetPlayer(i)->is_active) { glx@10645: /* Check if we have the player as an active player */ glx@10645: if (!this->IsWidgetDisabled(i + 13)) { glx@10645: /* Bah, player gone :( */ glx@10645: this->DisableWidget(i + 13); glx@10645: glx@10645: /* We need a repaint */ glx@10645: this->SetDirty(); peter1138@3027: } glx@10645: continue; tron@3033: } dominik@116: glx@10645: /* Check if we have the player marked as inactive */ glx@10645: if (this->IsWidgetDisabled(i + 13)) { glx@10645: /* New player! Yippie :p */ glx@10645: this->EnableWidget(i + 13); glx@10645: /* We need a repaint */ glx@10645: this->SetDirty(); glx@10645: } dominik@116: glx@10645: x = (i == player) ? 1 : 0; glx@10645: DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x); peter1138@3027: } peter1138@3027: glx@10645: /* The colors used to show how the progress is going */ glx@10645: color_done = _colour_gradient[COLOUR_GREEN][4]; glx@10645: color_notdone = _colour_gradient[COLOUR_RED][4]; rubidium@9723: glx@10645: /* Draw all the score parts */ glx@10645: for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) { glx@10645: int val = _score_part[player][i]; glx@10645: int needed = _score_info[i].needed; glx@10645: int score = _score_info[i].score; tron@3033: glx@10645: y += 20; glx@10645: /* SCORE_TOTAL has his own rulez ;) */ glx@10645: if (i == SCORE_TOTAL) { glx@10645: needed = total_score; glx@10645: score = SCORE_MAX; glx@10645: } else { glx@10645: total_score += score; peter1138@3027: } peter1138@3027: glx@10645: DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, TC_FROMSTRING); glx@10645: glx@10645: /* Draw the score */ glx@10645: SetDParam(0, score); glx@10645: DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, TC_FROMSTRING); glx@10645: glx@10645: /* Calculate the %-bar */ glx@10645: x = Clamp(val, 0, needed) * 50 / needed; glx@10645: glx@10645: /* SCORE_LOAN is inversed */ glx@10645: if (val < 0 && i == SCORE_LOAN) x = 0; glx@10645: glx@10645: /* Draw the bar */ glx@10645: if (x != 0) GfxFillRect(112, y - 2, 112 + x, y + 10, color_done); glx@10645: if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone); glx@10645: glx@10645: /* Calculate the % */ glx@10645: x = Clamp(val, 0, needed) * 100 / needed; glx@10645: glx@10645: /* SCORE_LOAN is inversed */ glx@10645: if (val < 0 && i == SCORE_LOAN) x = 0; glx@10645: glx@10645: /* Draw it */ glx@10645: SetDParam(0, x); glx@10645: DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING); glx@10645: glx@10645: /* SCORE_LOAN is inversed */ glx@10645: if (i == SCORE_LOAN) val = needed - val; glx@10645: glx@10645: /* Draw the amount we have against what is needed glx@10645: * For some of them it is in currency format */ glx@10645: SetDParam(0, val); glx@10645: SetDParam(1, needed); glx@10645: switch (i) { glx@10645: case SCORE_MIN_PROFIT: glx@10645: case SCORE_MIN_INCOME: glx@10645: case SCORE_MAX_INCOME: glx@10645: case SCORE_MONEY: glx@10645: case SCORE_LOAN: glx@10645: DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, TC_FROMSTRING); glx@10645: break; glx@10645: default: glx@10645: DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_INT, TC_FROMSTRING); glx@10645: } glx@10645: } dominik@116: } glx@10645: glx@10645: virtual void OnClick(Point pt, int widget) glx@10645: { glx@10645: /* Check which button is clicked */ glx@10645: if (IsInsideMM(widget, 13, 21)) { glx@10645: /* Is it no on disable? */ glx@10645: if (!this->IsWidgetDisabled(widget)) { glx@10645: this->RaiseWidget(player + 13); glx@10645: player = (PlayerID)(widget - 13); glx@10645: this->LowerWidget(player + 13); glx@10645: this->SetDirty(); glx@10645: } glx@10645: } glx@10645: } glx@10645: glx@10645: virtual void OnTick() glx@10645: { glx@10645: if (_pause_game != 0) return; glx@10645: glx@10645: /* Update the player score every 5 days */ glx@10645: if (--this->timeout == 0) { glx@10645: this->UpdatePlayerStats(); glx@10645: this->SetDirty(); glx@10645: } glx@10645: } glx@10645: }; glx@10645: glx@10645: PlayerID PerformanceRatingDetailWindow::player = INVALID_PLAYER; glx@10645: dominik@116: dominik@116: static const Widget _performance_rating_detail_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 14, 11, 298, 0, 13, STR_PERFORMANCE_DETAIL, STR_018C_WINDOW_TITLE_DRAG_THIS}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 14, 27, 0x0, STR_NULL}, dominik@116: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 28, 47, 0x0, STR_PERFORMANCE_DETAIL_VEHICLES_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 48, 67, 0x0, STR_PERFORMANCE_DETAIL_STATIONS_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 68, 87, 0x0, STR_PERFORMANCE_DETAIL_MIN_PROFIT_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 88, 107, 0x0, STR_PERFORMANCE_DETAIL_MIN_INCOME_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 108, 127, 0x0, STR_PERFORMANCE_DETAIL_MAX_INCOME_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 128, 147, 0x0, STR_PERFORMANCE_DETAIL_DELIVERED_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 148, 167, 0x0, STR_PERFORMANCE_DETAIL_CARGO_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 168, 187, 0x0, STR_PERFORMANCE_DETAIL_MONEY_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 188, 207, 0x0, STR_PERFORMANCE_DETAIL_LOAN_TIP}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 0, 298, 208, 227, 0x0, STR_PERFORMANCE_DETAIL_TOTAL_TIP}, dominik@116: Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 2, 38, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 39, 75, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 76, 112, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 113, 149, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 150, 186, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 187, 223, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 224, 260, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, Darkvater@4938: { WWT_PANEL, RESIZE_NONE, 14, 261, 297, 14, 26, 0x0, STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY}, darkvater@176: { WIDGETS_END}, dominik@116: }; dominik@116: dominik@116: static const WindowDesc _performance_rating_detail_desc = { rubidium@9694: WDP_AUTO, WDP_AUTO, 299, 228, 299, 228, rubidium@6144: WC_PERFORMANCE_DETAIL, WC_NONE, dominik@116: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, dominik@116: _performance_rating_detail_widgets, dominik@116: }; dominik@116: rubidium@6573: void ShowPerformanceRatingDetail() dominik@116: { glx@10645: AllocateWindowDescFront(&_performance_rating_detail_desc, 0); dominik@116: }