tron@2186: /* $Id$ */ tron@2186: rubidium@9111: /** @file graph_gui.cpp GUI that shows performance graphs. */ belugas@6179: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" truelight@0: #include "gui.h" rubidium@8107: #include "window_gui.h" rubidium@8254: #include "player_base.h" rubidium@8254: #include "player_gui.h" rubidium@8116: #include "economy_func.h" tron@2159: #include "variables.h" peter1138@6091: #include "cargotype.h" rubidium@8114: #include "strings_func.h" rubidium@8130: #include "core/alloc_func.hpp" rubidium@8131: #include "window_func.h" rubidium@8140: #include "date_func.h" rubidium@8224: #include "gfx_func.h" Darkvater@5291: rubidium@8264: #include "table/strings.h" rubidium@8264: #include "table/sprites.h" rubidium@8264: maedhros@5806: /* Bitmasks of player and cargo indices that shouldn't be drawn. */ maedhros@5806: static uint _legend_excluded_players; maedhros@5806: static uint _legend_excluded_cargo; truelight@0: maedhros@5805: /* Apparently these don't play well with enums. */ rubidium@8409: static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn. rubidium@7763: static const uint INVALID_DATAPOINT_POS = UINT_MAX; // Used to determine if the previous point was drawn. maedhros@5805: truelight@0: /****************/ truelight@0: /* GRAPH LEGEND */ truelight@0: /****************/ truelight@0: rubidium@9289: struct GraphLegendWindow : Window { rubidium@9289: GraphLegendWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) rubidium@9289: { rubidium@9289: for (uint i = 3; i < this->widget_count; i++) { rubidium@9289: if (!HasBit(_legend_excluded_players, i - 3)) this->LowerWidget(i); rubidium@9289: } rubidium@9290: rubidium@9290: this->FindWindowPlacementAndResize(desc); rubidium@9289: } peter1138@6203: rubidium@9289: virtual void OnPaint() rubidium@9289: { rubidium@9289: const Player *p; peter1138@6203: rubidium@9289: FOR_ALL_PLAYERS(p) { rubidium@9289: if (p->is_active) continue; peter1138@6203: rubidium@9289: SetBit(_legend_excluded_players, p->index); rubidium@9289: this->RaiseWidget(p->index + 3); truelight@0: } truelight@0: rubidium@9289: this->DrawWidgets(); peter1138@6203: rubidium@9289: FOR_ALL_PLAYERS(p) { rubidium@9289: if (!p->is_active) continue; rubidium@9289: rubidium@9289: DrawPlayerIcon(p->index, 4, 18 + p->index * 12); rubidium@9289: rubidium@9289: SetDParam(0, p->index); rubidium@9289: SetDParam(1, p->index); rubidium@9289: DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE); rubidium@9289: } truelight@0: } rubidium@9289: rubidium@9289: virtual void OnClick(Point pt, int widget) rubidium@9289: { rubidium@9289: if (!IsInsideMM(widget, 3, 11)) return; rubidium@9289: rubidium@9289: ToggleBit(_legend_excluded_players, widget - 3); rubidium@9289: this->ToggleWidgetLoweredState(widget); rubidium@9289: this->SetDirty(); rubidium@9289: InvalidateWindow(WC_INCOME_GRAPH, 0); rubidium@9289: InvalidateWindow(WC_OPERATING_PROFIT, 0); rubidium@9289: InvalidateWindow(WC_DELIVERED_CARGO, 0); rubidium@9289: InvalidateWindow(WC_PERFORMANCE_HISTORY, 0); rubidium@9289: InvalidateWindow(WC_COMPANY_VALUE, 0); rubidium@9289: } rubidium@9289: }; 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@7341: WDP_AUTO, WDP_AUTO, 250, 114, 250, 114, rubidium@5893: 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@6247: static void ShowGraphLegend() truelight@0: { rubidium@9289: AllocateWindowDescFront(&_graph_legend_desc, 0); truelight@0: } truelight@0: rubidium@9290: /******************/ rubidium@9290: /* BASE OF GRAPHS */ rubidium@9290: /*****************/ rubidium@9290: rubidium@9290: struct BaseGraphWindow : Window { rubidium@9290: protected: rubidium@9290: enum { rubidium@9290: GRAPH_MAX_DATASETS = 32, rubidium@9290: GRAPH_AXIS_LABEL_COLOUR = TC_BLACK, rubidium@9290: GRAPH_AXIS_LINE_COLOUR = 215, rubidium@9290: rubidium@9290: GRAPH_X_POSITION_BEGINNING = 44, ///< Start the graph 44 pixels from gd_left rubidium@9290: GRAPH_X_POSITION_SEPARATION = 22, ///< There are 22 pixels between each X value rubidium@9290: rubidium@9290: GRAPH_NUM_LINES_Y = 9, ///< How many horizontal lines to draw. rubidium@9290: /* 9 is convenient as that means the distance between them is the gd_height of the graph / 8, rubidium@9290: * which is the same rubidium@9290: * as height >> 3. */ rubidium@9290: }; rubidium@9290: rubidium@9290: uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed. rubidium@9290: byte num_dataset; rubidium@9290: byte num_on_x_axis; rubidium@9290: bool has_negative_values; rubidium@9290: byte num_vert_lines; rubidium@9290: rubidium@9290: /* The starting month and year that values are plotted against. If month is rubidium@9290: * 0xFF, use x_values_start and x_values_increment below instead. */ rubidium@9290: byte month; rubidium@9290: Year year; rubidium@9290: rubidium@9290: /* These values are used if the graph is being plotted against values rubidium@9290: * rather than the dates specified by month and year. */ rubidium@9290: uint16 x_values_start; rubidium@9290: uint16 x_values_increment; rubidium@9290: rubidium@9290: int gd_left, gd_top; ///< Where to start drawing the graph, in pixels. rubidium@9290: uint gd_height; ///< The height of the graph in pixels. rubidium@9290: StringID format_str_y_axis; rubidium@9290: byte colors[GRAPH_MAX_DATASETS]; rubidium@9290: OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years rubidium@9290: rubidium@9290: void DrawGraph() const rubidium@9290: { rubidium@9290: uint x, y; ///< Reused whenever x and y coordinates are needed. rubidium@9290: OverflowSafeInt64 highest_value; ///< Highest value to be drawn. rubidium@9290: int x_axis_offset; ///< Distance from the top of the graph to the x axis. rubidium@9290: rubidium@9290: /* the colors and cost array of GraphDrawer must accomodate rubidium@9290: * both values for cargo and players. So if any are higher, quit */ rubidium@9290: assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS); rubidium@9290: assert(this->num_vert_lines > 0); rubidium@9290: rubidium@9290: byte grid_colour = _colour_gradient[14][4]; rubidium@9290: rubidium@9290: /* The coordinates of the opposite edges of the graph. */ rubidium@9290: int bottom = this->gd_top + this->gd_height - 1; rubidium@9290: int right = this->gd_left + GRAPH_X_POSITION_BEGINNING + this->num_vert_lines * GRAPH_X_POSITION_SEPARATION - 1; rubidium@9290: rubidium@9290: /* Draw the vertical grid lines. */ rubidium@9290: rubidium@9290: /* Don't draw the first line, as that's where the axis will be. */ rubidium@9290: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + GRAPH_X_POSITION_SEPARATION; rubidium@9290: rubidium@9290: for (int i = 0; i < this->num_vert_lines; i++) { rubidium@9290: GfxFillRect(x, this->gd_top, x, bottom, grid_colour); rubidium@9290: x += GRAPH_X_POSITION_SEPARATION; rubidium@9290: } rubidium@9290: rubidium@9290: /* Draw the horizontal grid lines. */ rubidium@9290: x = this->gd_left + GRAPH_X_POSITION_BEGINNING; rubidium@9290: y = this->gd_height + this->gd_top; rubidium@9290: rubidium@9290: for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) { rubidium@9290: GfxFillRect(x, y, right, y, grid_colour); rubidium@9290: y -= (this->gd_height / (GRAPH_NUM_LINES_Y - 1)); rubidium@9290: } rubidium@9290: rubidium@9290: /* Draw the y axis. */ rubidium@9290: GfxFillRect(x, this->gd_top, x, bottom, GRAPH_AXIS_LINE_COLOUR); rubidium@9290: rubidium@9290: /* Find the distance from the gd_top of the graph to the x axis. */ rubidium@9290: x_axis_offset = this->gd_height; rubidium@9290: rubidium@9290: /* The graph is currently symmetrical about the x axis. */ rubidium@9290: if (this->has_negative_values) x_axis_offset /= 2; rubidium@9290: rubidium@9290: /* Draw the x axis. */ rubidium@9290: y = x_axis_offset + this->gd_top; rubidium@9290: GfxFillRect(x, y, right, y, GRAPH_AXIS_LINE_COLOUR); rubidium@9290: rubidium@9290: /* Find the largest value that will be drawn. */ rubidium@9290: if (this->num_on_x_axis == 0) rubidium@9290: return; rubidium@9290: rubidium@9290: assert(this->num_on_x_axis > 0); rubidium@9290: assert(this->num_dataset > 0); rubidium@9290: rubidium@9290: /* Start of with a value of twice the gd_height of the graph in pixels. It's a rubidium@9290: * bit arbitrary, but it makes the cargo payment graph look a little nicer, rubidium@9290: * and prevents division by zero when calculating where the datapoint rubidium@9290: * should be drawn. */ rubidium@9290: highest_value = x_axis_offset * 2; rubidium@9290: rubidium@9290: for (int i = 0; i < this->num_dataset; i++) { rubidium@9290: if (!HasBit(this->excluded_data, i)) { rubidium@9290: for (int j = 0; j < this->num_on_x_axis; j++) { rubidium@9290: OverflowSafeInt64 datapoint = this->cost[i][j]; rubidium@9290: rubidium@9290: if (datapoint != INVALID_DATAPOINT) { rubidium@9290: /* For now, if the graph has negative values the scaling is rubidium@9290: * symmetrical about the x axis, so take the absolute value rubidium@9290: * of each data point. */ rubidium@9290: highest_value = max(highest_value, abs(datapoint)); rubidium@9290: } rubidium@9290: } rubidium@9290: } rubidium@9290: } rubidium@9290: rubidium@9290: /* Round up highest_value so that it will divide cleanly into the number of rubidium@9290: * axis labels used. */ rubidium@9290: int round_val = highest_value % (GRAPH_NUM_LINES_Y - 1); rubidium@9290: if (round_val != 0) highest_value += (GRAPH_NUM_LINES_Y - 1 - round_val); rubidium@9290: rubidium@9290: /* draw text strings on the y axis */ rubidium@9290: int64 y_label = highest_value; rubidium@9290: int64 y_label_separation = highest_value / (GRAPH_NUM_LINES_Y - 1); rubidium@9290: rubidium@9290: /* If there are negative values, the graph goes from highest_value to rubidium@9290: * -highest_value, not highest_value to 0. */ rubidium@9290: if (this->has_negative_values) y_label_separation *= 2; rubidium@9290: rubidium@9290: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + 1; rubidium@9290: y = this->gd_top - 3; rubidium@9290: rubidium@9290: for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) { rubidium@9290: SetDParam(0, this->format_str_y_axis); rubidium@9290: SetDParam(1, y_label); rubidium@9290: DrawStringRightAligned(x, y, STR_0170, GRAPH_AXIS_LABEL_COLOUR); rubidium@9290: rubidium@9290: y_label -= y_label_separation; rubidium@9290: y += (this->gd_height / (GRAPH_NUM_LINES_Y - 1)); rubidium@9290: } rubidium@9290: rubidium@9290: /* draw strings on the x axis */ rubidium@9290: if (this->month != 0xFF) { rubidium@9290: x = this->gd_left + GRAPH_X_POSITION_BEGINNING; rubidium@9290: y = this->gd_top + this->gd_height + 1; rubidium@9290: byte month = this->month; rubidium@9290: Year year = this->year; rubidium@9290: for (int i = 0; i < this->num_on_x_axis; i++) { rubidium@9290: SetDParam(0, month + STR_0162_JAN); rubidium@9290: SetDParam(1, month + STR_0162_JAN + 2); rubidium@9290: SetDParam(2, year); rubidium@9290: DrawString(x, y, month == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR); rubidium@9290: rubidium@9290: month += 3; rubidium@9290: if (month >= 12) { rubidium@9290: month = 0; rubidium@9290: year++; rubidium@9290: } rubidium@9290: x += GRAPH_X_POSITION_SEPARATION; rubidium@9290: } rubidium@9290: } else { rubidium@9290: /* Draw the label under the data point rather than on the grid line. */ rubidium@9290: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2) + 1; rubidium@9290: y = this->gd_top + this->gd_height + 1; rubidium@9290: uint16 label = this->x_values_start; rubidium@9290: rubidium@9290: for (int i = 0; i < this->num_on_x_axis; i++) { rubidium@9290: SetDParam(0, label); rubidium@9290: DrawStringCentered(x, y, STR_01CB, GRAPH_AXIS_LABEL_COLOUR); rubidium@9290: rubidium@9290: label += this->x_values_increment; rubidium@9290: x += GRAPH_X_POSITION_SEPARATION; rubidium@9290: } rubidium@9290: } rubidium@9290: rubidium@9290: /* draw lines and dots */ rubidium@9290: for (int i = 0; i < this->num_dataset; i++) { rubidium@9290: if (!HasBit(this->excluded_data, i)) { rubidium@9290: /* Centre the dot between the grid lines. */ rubidium@9290: x = this->gd_left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2); rubidium@9290: rubidium@9290: byte color = this->colors[i]; rubidium@9290: uint prev_x = INVALID_DATAPOINT_POS; rubidium@9290: uint prev_y = INVALID_DATAPOINT_POS; rubidium@9290: rubidium@9290: for (int j = 0; j < this->num_on_x_axis; j++) { rubidium@9290: OverflowSafeInt64 datapoint = this->cost[i][j]; rubidium@9290: rubidium@9290: if (datapoint != INVALID_DATAPOINT) { rubidium@9290: /* rubidium@9290: * Check whether we need to reduce the 'accuracy' of the rubidium@9290: * datapoint value and the highest value to splut overflows. rubidium@9290: * And when 'drawing' 'one million' or 'one million and one' rubidium@9290: * there is no significant difference, so the least rubidium@9290: * significant bits can just be removed. rubidium@9290: * rubidium@9290: * If there are more bits needed than would fit in a 32 bits rubidium@9290: * integer, so at about 31 bits because of the sign bit, the rubidium@9290: * least significant bits are removed. rubidium@9290: */ rubidium@9290: int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint)); rubidium@9290: int reduce_range = max(mult_range - 31, 0); rubidium@9290: rubidium@9290: /* Handle negative values differently (don't shift sign) */ rubidium@9290: if (datapoint < 0) { rubidium@9290: datapoint = -(abs(datapoint) >> reduce_range); rubidium@9290: } else { rubidium@9290: datapoint >>= reduce_range; rubidium@9290: } rubidium@9290: rubidium@9290: y = this->gd_top + x_axis_offset - (x_axis_offset * datapoint) / (highest_value >> reduce_range); rubidium@9290: rubidium@9290: /* Draw the point. */ rubidium@9290: GfxFillRect(x - 1, y - 1, x + 1, y + 1, color); rubidium@9290: rubidium@9290: /* Draw the line connected to the previous point. */ rubidium@9290: if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, color); rubidium@9290: rubidium@9290: prev_x = x; rubidium@9290: prev_y = y; rubidium@9290: } else { rubidium@9290: prev_x = INVALID_DATAPOINT_POS; rubidium@9290: prev_y = INVALID_DATAPOINT_POS; rubidium@9290: } rubidium@9290: rubidium@9290: x += GRAPH_X_POSITION_SEPARATION; rubidium@9290: } rubidium@9290: } rubidium@9290: } rubidium@9290: } rubidium@9290: rubidium@9290: rubidium@9290: BaseGraphWindow(const WindowDesc *desc, WindowNumber window_number, int left, rubidium@9290: int top, int height, bool has_negative_values, StringID format_str_y_axis) : rubidium@9290: Window(desc, window_number), has_negative_values(has_negative_values), rubidium@9290: gd_left(left), gd_top(top), gd_height(height), format_str_y_axis(format_str_y_axis) rubidium@9290: { rubidium@9290: InvalidateWindow(WC_GRAPH_LEGEND, 0); rubidium@9290: } rubidium@9290: rubidium@9290: public: rubidium@9290: virtual void OnPaint() rubidium@9290: { rubidium@9290: this->DrawWidgets(); rubidium@9290: rubidium@9290: uint excluded_players = _legend_excluded_players; rubidium@9290: rubidium@9290: /* Exclude the players which aren't valid */ rubidium@9290: const Player* p; rubidium@9290: FOR_ALL_PLAYERS(p) { rubidium@9290: if (!p->is_active) SetBit(excluded_players, p->index); rubidium@9290: } rubidium@9290: this->excluded_data = excluded_players; rubidium@9290: this->num_vert_lines = 24; rubidium@9290: rubidium@9290: byte nums = 0; rubidium@9290: FOR_ALL_PLAYERS(p) { rubidium@9290: if (p->is_active) nums = max(nums, p->num_valid_stat_ent); rubidium@9290: } rubidium@9290: this->num_on_x_axis = min(nums, 24); rubidium@9290: rubidium@9290: int mo = (_cur_month / 3 - nums) * 3; rubidium@9290: int yr = _cur_year; rubidium@9290: while (mo < 0) { rubidium@9290: yr--; rubidium@9290: mo += 12; rubidium@9290: } rubidium@9290: rubidium@9290: this->year = yr; rubidium@9290: this->month = mo; rubidium@9290: rubidium@9290: int numd = 0; rubidium@9290: FOR_ALL_PLAYERS(p) { rubidium@9290: if (p->is_active) { rubidium@9290: this->colors[numd] = _colour_gradient[p->player_color][6]; rubidium@9290: for (int j = this->num_on_x_axis, i = 0; --j >= 0;) { rubidium@9290: this->cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(p, j); rubidium@9290: i++; rubidium@9290: } rubidium@9290: } rubidium@9290: numd++; rubidium@9290: } rubidium@9290: rubidium@9290: this->num_dataset = numd; rubidium@9290: rubidium@9290: this->DrawGraph(); rubidium@9290: } rubidium@9290: rubidium@9290: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) rubidium@9290: { rubidium@9290: return INVALID_DATAPOINT; rubidium@9290: } rubidium@9290: rubidium@9290: virtual void OnClick(Point pt, int widget) rubidium@9290: { rubidium@9290: /* Clicked on legend? */ rubidium@9290: if (widget == 2) ShowGraphLegend(); rubidium@9290: } rubidium@9290: }; rubidium@9290: truelight@0: /********************/ truelight@0: /* OPERATING PROFIT */ truelight@0: /********************/ truelight@0: rubidium@9290: struct OperatingProfitGraphWindow : BaseGraphWindow { rubidium@9290: OperatingProfitGraphWindow(const WindowDesc *desc, WindowNumber window_number) : rubidium@9290: BaseGraphWindow(desc, window_number, 2, 18, 136, true, STR_CURRCOMPACT) rubidium@9290: { rubidium@9290: this->FindWindowPlacementAndResize(desc); truelight@0: } truelight@0: rubidium@9290: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) rubidium@9290: { rubidium@9290: return p->old_economy[j].income + p->old_economy[j].expenses; truelight@0: } rubidium@9290: }; 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@7341: WDP_AUTO, WDP_AUTO, 576, 174, 576, 174, rubidium@5893: 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@6247: void ShowOperatingProfitGraph() truelight@0: { rubidium@9290: AllocateWindowDescFront(&_operating_profit_desc, 0); truelight@0: } truelight@0: truelight@0: truelight@0: /****************/ truelight@0: /* INCOME GRAPH */ truelight@0: /****************/ truelight@0: rubidium@9290: struct IncomeGraphWindow : BaseGraphWindow { rubidium@9290: IncomeGraphWindow(const WindowDesc *desc, WindowNumber window_number) : rubidium@9290: BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_CURRCOMPACT) rubidium@9290: { rubidium@9290: this->FindWindowPlacementAndResize(desc); rubidium@9290: } peter1138@6203: rubidium@9290: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) rubidium@9290: { rubidium@9290: return p->old_economy[j].income; truelight@0: } rubidium@9290: }; 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@7341: WDP_AUTO, WDP_AUTO, 576, 142, 576, 142, rubidium@5893: 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@6247: void ShowIncomeGraph() truelight@0: { rubidium@9290: AllocateWindowDescFront(&_income_graph_desc, 0); truelight@0: } truelight@0: truelight@0: /*******************/ truelight@0: /* DELIVERED CARGO */ truelight@0: /*******************/ truelight@0: rubidium@9290: struct DeliveredCargoGraphWindow : BaseGraphWindow { rubidium@9290: DeliveredCargoGraphWindow(const WindowDesc *desc, WindowNumber window_number) : rubidium@9290: BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_7024) rubidium@9290: { rubidium@9290: this->FindWindowPlacementAndResize(desc); rubidium@9290: } peter1138@6203: rubidium@9290: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) rubidium@9290: { rubidium@9290: return p->old_economy[j].delivered_cargo; truelight@0: } rubidium@9290: }; 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@7341: WDP_AUTO, WDP_AUTO, 576, 142, 576, 142, rubidium@5893: 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@6247: void ShowDeliveredCargoGraph() truelight@0: { rubidium@9290: AllocateWindowDescFront(&_delivered_cargo_graph_desc, 0); dominik@116: } dominik@116: darkvater@1086: /***********************/ darkvater@1086: /* PERFORMANCE HISTORY */ darkvater@1086: /***********************/ darkvater@1086: rubidium@9290: struct PerformanceHistoryGraphWindow : BaseGraphWindow { rubidium@9290: PerformanceHistoryGraphWindow(const WindowDesc *desc, WindowNumber window_number) : rubidium@9290: BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_7024) rubidium@9290: { rubidium@9290: this->FindWindowPlacementAndResize(desc); rubidium@9290: } peter1138@6203: rubidium@9290: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) rubidium@9290: { rubidium@9290: return p->old_economy[j].performance_history; rubidium@9290: } peter1138@6203: rubidium@9290: virtual void OnClick(Point pt, int widget) rubidium@9290: { rubidium@9290: if (widget == 3) ShowPerformanceRatingDetail(); rubidium@9290: this->BaseGraphWindow::OnClick(pt, widget); darkvater@1086: } rubidium@9290: }; 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@7341: WDP_AUTO, WDP_AUTO, 576, 238, 576, 238, rubidium@5893: 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@6247: void ShowPerformanceHistoryGraph() darkvater@1086: { rubidium@9290: AllocateWindowDescFront(&_performance_history_desc, 0); darkvater@1086: } darkvater@1086: darkvater@1086: /*****************/ darkvater@1086: /* COMPANY VALUE */ darkvater@1086: /*****************/ darkvater@1086: rubidium@9290: struct CompanyValueGraphWindow : BaseGraphWindow { rubidium@9290: CompanyValueGraphWindow(const WindowDesc *desc, WindowNumber window_number) : rubidium@9290: BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_CURRCOMPACT) rubidium@9290: { rubidium@9290: this->FindWindowPlacementAndResize(desc); rubidium@9290: } peter1138@6203: rubidium@9290: virtual OverflowSafeInt64 GetGraphData(const Player *p, int j) rubidium@9290: { rubidium@9290: return p->old_economy[j].company_value; darkvater@1086: } rubidium@9290: }; 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@7341: WDP_AUTO, WDP_AUTO, 576, 238, 576, 238, rubidium@5893: 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@6247: void ShowCompanyValueGraph() darkvater@1086: { rubidium@9290: AllocateWindowDescFront(&_company_value_graph_desc, 0); darkvater@1086: } darkvater@1086: darkvater@1086: /*****************/ darkvater@1086: /* PAYMENT RATES */ darkvater@1086: /*****************/ darkvater@1086: rubidium@9290: struct PaymentRatesGraphWindow : BaseGraphWindow { rubidium@9290: PaymentRatesGraphWindow(const WindowDesc *desc, WindowNumber window_number) : rubidium@9290: BaseGraphWindow(desc, window_number, 2, 24, 200, false, STR_CURRCOMPACT) rubidium@9290: { rubidium@9290: uint num_active = 0; rubidium@9290: for (CargoID c = 0; c < NUM_CARGO; c++) { rubidium@9290: if (GetCargo(c)->IsValid()) num_active++; darkvater@1086: } peter1138@6203: rubidium@9290: /* Resize the window to fit the cargo types */ rubidium@9290: ResizeWindow(this, 0, max(num_active, 12U) * 8); rubidium@9290: rubidium@9290: /* Add widgets for each cargo type */ rubidium@9290: this->widget_count += num_active; rubidium@9290: this->widget = ReallocT(this->widget, this->widget_count + 1); rubidium@9290: this->widget[this->widget_count].type = WWT_LAST; rubidium@9290: rubidium@9290: /* Set the properties of each widget */ rubidium@9290: for (uint i = 0; i != num_active; i++) { rubidium@9290: Widget *wi = &this->widget[3 + i]; rubidium@9290: wi->type = WWT_PANEL; rubidium@9290: wi->display_flags = RESIZE_NONE; rubidium@9290: wi->color = 12; rubidium@9290: wi->left = 493; rubidium@9290: wi->right = 562; rubidium@9290: wi->top = 24 + i * 8; rubidium@9290: wi->bottom = wi->top + 7; rubidium@9290: wi->data = 0; rubidium@9290: wi->tooltips = STR_7064_TOGGLE_GRAPH_FOR_CARGO; rubidium@9290: rubidium@9290: if (!HasBit(_legend_excluded_cargo, i)) this->LowerWidget(i + 3); rubidium@9290: } rubidium@9290: rubidium@9290: this->SetDirty(); rubidium@9290: rubidium@9290: this->gd_height = this->height - 38; rubidium@9290: this->num_on_x_axis = 20; rubidium@9290: this->num_vert_lines = 20; rubidium@9290: this->month = 0xFF; rubidium@9290: this->x_values_start = 10; rubidium@9290: this->x_values_increment = 10; rubidium@9290: rubidium@9290: this->FindWindowPlacementAndResize(desc); rubidium@9290: } rubidium@9290: rubidium@9290: virtual void OnPaint() rubidium@9290: { rubidium@9290: this->DrawWidgets(); rubidium@9290: rubidium@9290: this->excluded_data = _legend_excluded_cargo; rubidium@9290: rubidium@9290: int x = 495; rubidium@9290: int y = 24; rubidium@9290: rubidium@9290: uint i = 0; rubidium@9290: for (CargoID c = 0; c < NUM_CARGO; c++) { rubidium@9290: const CargoSpec *cs = GetCargo(c); rubidium@9290: if (!cs->IsValid()) continue; rubidium@9290: rubidium@9290: /* Only draw labels for widgets that exist. If the widget doesn't rubidium@9290: * exist then the local player has used the climate cheat or rubidium@9290: * changed the NewGRF configuration with this window open. */ rubidium@9290: if (i + 3 < this->widget_count) { rubidium@9290: /* Since the buttons have no text, no images, rubidium@9290: * both the text and the colored box have to be manually painted. rubidium@9290: * clk_dif will move one pixel down and one pixel to the right rubidium@9290: * when the button is clicked */ rubidium@9290: byte clk_dif = this->IsWidgetLowered(i + 3) ? 1 : 0; rubidium@9290: rubidium@9290: GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0); rubidium@9290: GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour); rubidium@9290: SetDParam(0, cs->name); rubidium@9290: DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, TC_FROMSTRING); rubidium@9290: y += 8; peter1138@6203: } rubidium@9290: rubidium@9290: this->colors[i] = cs->legend_colour; rubidium@9290: for (uint j = 0; j != 20; j++) { rubidium@9290: this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, c); rubidium@9290: } rubidium@9290: rubidium@9290: i++; rubidium@9290: } rubidium@9290: this->num_dataset = i; rubidium@9290: rubidium@9290: this->DrawGraph(); rubidium@9290: rubidium@9290: DrawString(2 + 46, 24 + this->gd_height + 7, STR_7062_DAYS_IN_TRANSIT, TC_FROMSTRING); rubidium@9290: DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, TC_FROMSTRING); darkvater@1086: } rubidium@9290: rubidium@9290: virtual void OnClick(Point pt, int widget) rubidium@9290: { rubidium@9290: if (widget >= 3) { rubidium@9290: ToggleBit(_legend_excluded_cargo, widget - 3); rubidium@9290: this->ToggleWidgetLoweredState(widget); rubidium@9290: this->SetDirty(); rubidium@9290: } rubidium@9290: } rubidium@9290: }; 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@6192: { 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@7341: WDP_AUTO, WDP_AUTO, 568, 46, 568, 46, rubidium@5893: 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@6247: void ShowCargoPaymentRates() darkvater@1086: { rubidium@9290: 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: tron@2656: static int CDECL PerfHistComp(const void* elem1, const void* elem2) tron@2656: { tron@2656: const Player* p1 = *(const Player* const*)elem1; tron@2656: const Player* p2 = *(const Player* const*)elem2; tron@2656: tron@2656: return p2->old_economy[1].performance_history - p1->old_economy[1].performance_history; darkvater@1086: } darkvater@1086: rubidium@9289: struct CompanyLeagueWindow : Window { rubidium@9289: CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) rubidium@9289: { peter1138@9333: this->FindWindowPlacementAndResize(desc); rubidium@9289: } darkvater@1086: rubidium@9289: virtual void OnPaint() rubidium@9289: { rubidium@9289: const Player *plist[MAX_PLAYERS]; rubidium@9289: const Player *p; darkvater@1086: rubidium@9289: this->DrawWidgets(); tron@2656: rubidium@9289: uint pl_num = 0; rubidium@9289: FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p; tron@2656: rubidium@9289: qsort((void*)plist, pl_num, sizeof(*plist), PerfHistComp); rubidium@9289: rubidium@9289: for (uint i = 0; i != pl_num; i++) { rubidium@9289: p = plist[i]; rubidium@9289: SetDParam(0, i + STR_01AC_1ST); rubidium@9289: SetDParam(1, p->index); rubidium@9289: SetDParam(2, p->index); rubidium@9289: SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history)); rubidium@9289: rubidium@9289: DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING); rubidium@9289: DrawPlayerIcon(p->index, 27, 16 + i * 10); tron@2656: } darkvater@1086: } rubidium@9289: }; 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@7341: WDP_AUTO, WDP_AUTO, 400, 97, 400, 97, rubidium@5893: 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@6247: void ShowCompanyLeagueTable() darkvater@1086: { rubidium@9289: AllocateWindowDescFront(&_company_league_desc, 0); darkvater@1086: } darkvater@1086: dominik@116: /*****************************/ dominik@116: /* PERFORMANCE RATING DETAIL */ dominik@116: /*****************************/ dominik@116: rubidium@9255: struct PerformanceRatingDetailWindow : Window { rubidium@9255: static PlayerID player; rubidium@9255: int timeout; maedhros@5946: rubidium@9255: PerformanceRatingDetailWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) rubidium@9255: { rubidium@9255: /* Disable the players who are not active */ rubidium@9255: for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { rubidium@9255: this->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active); rubidium@9255: } maedhros@5946: rubidium@9255: this->UpdatePlayerStats(); maedhros@5946: rubidium@9255: if (player != INVALID_PLAYER) this->LowerWidget(player + 13); rubidium@9290: rubidium@9290: this->FindWindowPlacementAndResize(desc); rubidium@9255: } peter1138@3027: rubidium@9255: void UpdatePlayerStats() rubidium@9255: { rubidium@9255: /* Update all player stats with the current data rubidium@9255: * (this is because _score_info is not saved to a savegame) */ rubidium@9255: Player *p; rubidium@9255: FOR_ALL_PLAYERS(p) { rubidium@9255: if (p->is_active) UpdateCompanyRatingAndValue(p, false); rubidium@9255: } peter1138@3027: rubidium@9255: this->timeout = DAY_TICKS * 5; rubidium@9255: rubidium@9255: } rubidium@9255: rubidium@9255: virtual void OnPaint() rubidium@9255: { rubidium@9255: byte x; rubidium@9255: uint16 y = 14; rubidium@9255: int total_score = 0; rubidium@9255: int color_done, color_notdone; rubidium@9255: rubidium@9255: /* Draw standard stuff */ rubidium@9273: this->DrawWidgets(); rubidium@9255: rubidium@9255: /* Check if the currently selected player is still active. */ rubidium@9255: if (player == INVALID_PLAYER || !GetPlayer(player)->is_active) { rubidium@9255: if (player != INVALID_PLAYER) { rubidium@9255: /* Raise and disable the widget for the previous selection. */ rubidium@9255: this->RaiseWidget(player + 13); rubidium@9255: this->DisableWidget(player + 13); rubidium@9255: this->SetDirty(); rubidium@9255: rubidium@9255: player = INVALID_PLAYER; peter1138@3027: } peter1138@3027: rubidium@9255: for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { rubidium@9255: if (GetPlayer(i)->is_active) { rubidium@9255: /* Lower the widget corresponding to this player. */ rubidium@9255: this->LowerWidget(i + 13); rubidium@9255: this->SetDirty(); peter1138@3027: rubidium@9255: player = i; rubidium@9255: break; peter1138@3027: } peter1138@3027: } dominik@116: } truelight@193: rubidium@9255: /* If there are no active players, don't display anything else. */ rubidium@9255: if (player == INVALID_PLAYER) return; rubidium@9255: rubidium@9255: /* Paint the player icons */ rubidium@9255: for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { rubidium@9255: if (!GetPlayer(i)->is_active) { rubidium@9255: /* Check if we have the player as an active player */ rubidium@9255: if (!this->IsWidgetDisabled(i + 13)) { rubidium@9255: /* Bah, player gone :( */ rubidium@9255: this->DisableWidget(i + 13); rubidium@9255: rubidium@9255: /* We need a repaint */ rubidium@9255: this->SetDirty(); peter1138@3027: } rubidium@9255: continue; tron@3033: } dominik@116: rubidium@9255: /* Check if we have the player marked as inactive */ rubidium@9255: if (this->IsWidgetDisabled(i + 13)) { rubidium@9255: /* New player! Yippie :p */ rubidium@9255: this->EnableWidget(i + 13); rubidium@9255: /* We need a repaint */ rubidium@9255: this->SetDirty(); rubidium@9255: } dominik@116: rubidium@9255: x = (i == player) ? 1 : 0; rubidium@9255: DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x); peter1138@3027: } peter1138@3027: rubidium@9255: /* The colors used to show how the progress is going */ rubidium@9255: color_done = _colour_gradient[COLOUR_GREEN][4]; rubidium@9255: color_notdone = _colour_gradient[COLOUR_RED][4]; peter1138@8179: rubidium@9255: /* Draw all the score parts */ rubidium@9255: for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) { rubidium@9255: int val = _score_part[player][i]; rubidium@9255: int needed = _score_info[i].needed; rubidium@9255: int score = _score_info[i].score; tron@3033: rubidium@9255: y += 20; rubidium@9255: /* SCORE_TOTAL has his own rulez ;) */ rubidium@9255: if (i == SCORE_TOTAL) { rubidium@9255: needed = total_score; rubidium@9255: score = SCORE_MAX; rubidium@9255: } else { rubidium@9255: total_score += score; peter1138@3027: } peter1138@3027: rubidium@9255: DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, TC_FROMSTRING); rubidium@9255: rubidium@9255: /* Draw the score */ rubidium@9255: SetDParam(0, score); rubidium@9255: DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, TC_FROMSTRING); rubidium@9255: rubidium@9255: /* Calculate the %-bar */ rubidium@9255: x = Clamp(val, 0, needed) * 50 / needed; rubidium@9255: rubidium@9255: /* SCORE_LOAN is inversed */ rubidium@9255: if (val < 0 && i == SCORE_LOAN) x = 0; rubidium@9255: rubidium@9255: /* Draw the bar */ rubidium@9255: if (x != 0) GfxFillRect(112, y - 2, 112 + x, y + 10, color_done); rubidium@9255: if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone); rubidium@9255: rubidium@9255: /* Calculate the % */ rubidium@9255: x = Clamp(val, 0, needed) * 100 / needed; rubidium@9255: rubidium@9255: /* SCORE_LOAN is inversed */ rubidium@9255: if (val < 0 && i == SCORE_LOAN) x = 0; rubidium@9255: rubidium@9255: /* Draw it */ rubidium@9255: SetDParam(0, x); rubidium@9255: DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING); rubidium@9255: rubidium@9255: /* SCORE_LOAN is inversed */ rubidium@9255: if (i == SCORE_LOAN) val = needed - val; rubidium@9255: rubidium@9255: /* Draw the amount we have against what is needed rubidium@9255: * For some of them it is in currency format */ rubidium@9255: SetDParam(0, val); rubidium@9255: SetDParam(1, needed); rubidium@9255: switch (i) { rubidium@9255: case SCORE_MIN_PROFIT: rubidium@9255: case SCORE_MIN_INCOME: rubidium@9255: case SCORE_MAX_INCOME: rubidium@9255: case SCORE_MONEY: rubidium@9255: case SCORE_LOAN: rubidium@9255: DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, TC_FROMSTRING); rubidium@9255: break; rubidium@9255: default: rubidium@9255: DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_INT, TC_FROMSTRING); rubidium@9255: } rubidium@9255: } dominik@116: } rubidium@9255: rubidium@9255: virtual void OnClick(Point pt, int widget) rubidium@9255: { rubidium@9255: /* Check which button is clicked */ rubidium@9255: if (IsInsideMM(widget, 13, 21)) { rubidium@9255: /* Is it no on disable? */ rubidium@9255: if (!this->IsWidgetDisabled(widget)) { rubidium@9255: this->RaiseWidget(player + 13); rubidium@9255: player = (PlayerID)(widget - 13); rubidium@9255: this->LowerWidget(player + 13); rubidium@9255: this->SetDirty(); rubidium@9255: } rubidium@9255: } rubidium@9255: } rubidium@9255: rubidium@9255: virtual void OnTick() rubidium@9255: { rubidium@9255: if (_pause_game != 0) return; rubidium@9255: rubidium@9255: /* Update the player score every 5 days */ rubidium@9255: if (--this->timeout == 0) { rubidium@9255: this->UpdatePlayerStats(); rubidium@9255: this->SetDirty(); rubidium@9255: } rubidium@9255: } rubidium@9255: }; rubidium@9255: rubidium@9255: PlayerID PerformanceRatingDetailWindow::player = INVALID_PLAYER; rubidium@9255: 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@7341: WDP_AUTO, WDP_AUTO, 299, 228, 299, 228, rubidium@5893: 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@6247: void ShowPerformanceRatingDetail() dominik@116: { rubidium@9255: AllocateWindowDescFront(&_performance_rating_detail_desc, 0); dominik@116: }