diff -r 45d0233e7d79 -r 187e3ef04cc9 src/graph_gui.cpp --- a/src/graph_gui.cpp Sat Mar 03 20:33:32 2007 +0000 +++ b/src/graph_gui.cpp Sun Mar 04 04:25:36 2007 +0000 @@ -1,5 +1,7 @@ /* $Id$ */ +/** @file graph_gui.cpp */ + #include "stdafx.h" #include "openttd.h" #include "table/strings.h" @@ -28,13 +30,13 @@ GRAPH_AXIS_LABEL_COLOUR = 16, GRAPH_AXIS_LINE_COLOUR = 215, - GRAPH_X_POSITION_BEGINNING = 44, // Start the graph 44 pixels from gw->left - GRAPH_X_POSITION_SEPARATION = 22, // There are 22 pixels between each X value + GRAPH_X_POSITION_BEGINNING = 44, ///< Start the graph 44 pixels from gw->left + GRAPH_X_POSITION_SEPARATION = 22, ///< There are 22 pixels between each X value - /* How many horizontal lines to draw. 9 is convenient as that means the - * distance between them is the height of the graph / 8, which is the same + GRAPH_NUM_LINES_Y = 9, ///< How many horizontal lines to draw. + /* 9 is convenient as that means the distance between them is the height of the graph / 8, + * which is the same * as height >> 3. */ - GRAPH_NUM_LINES_Y = 9, }; /* Apparently these don't play well with enums. */ @@ -42,7 +44,7 @@ static const uint INVALID_DATAPOINT_POS = UINT_MAX; // Used to determine if the previous point was drawn. typedef struct GraphDrawer { - uint excluded_data; // bitmask of the datasets that shouldn't be displayed. + uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed. byte num_dataset; byte num_on_x_axis; bool has_negative_values; @@ -58,18 +60,18 @@ uint16 x_values_start; uint16 x_values_increment; - int left, top; // Where to start drawing the graph, in pixels. - uint height; // The height of the graph in pixels. + int left, top; ///< Where to start drawing the graph, in pixels. + uint height; ///< The height of the graph in pixels. StringID format_str_y_axis; byte colors[GRAPH_MAX_DATASETS]; - int64 cost[GRAPH_MAX_DATASETS][24]; // last 2 years + int64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years } GraphDrawer; static void DrawGraph(const GraphDrawer *gw) { - uint x, y; // Reused whenever x and y coordinates are needed. - int64 highest_value; // Highest value to be drawn. - int x_axis_offset; // Distance from the top of the graph to the x axis. + uint x, y; ///< Reused whenever x and y coordinates are needed. + int64 highest_value; ///< Highest value to be drawn. + int x_axis_offset; ///< Distance from the top of the graph to the x axis. /* the colors and cost array of GraphDrawer must accomodate * both values for cargo and players. So if any are higher, quit */ @@ -244,40 +246,42 @@ static void GraphLegendWndProc(BaseWindow *w, WindowEvent *e) { - const Player* p; - switch (e->event) { - case WE_CREATE: { - uint i; - for (i = 3; i < w->widget_count; i++) { - if (!HASBIT(_legend_excluded_players, i - 3)) w->LowerWidget(i); + case WE_CREATE: { + for (uint i = 3; i < w->widget_count; i++) { + if (!HASBIT(_legend_excluded_players, i - 3)) w->LowerWidget(i); + } + break; } - break; - } - case WE_PAINT: - FOR_ALL_PLAYERS(p) { - if (!p->is_active) { + case WE_PAINT: { + const Player *p; + + FOR_ALL_PLAYERS(p) { + if (p->is_active) continue; + SETBIT(_legend_excluded_players, p->index); w->RaiseWidget(p->index + 3); } - } - w->DrawWidgets(); - - FOR_ALL_PLAYERS(p) { - if (!p->is_active) continue; - - DrawPlayerIcon(p->index, 4, 18+p->index*12); - SetDParam(0, p->name_1); - SetDParam(1, p->name_2); - SetDParam(2, GetPlayerNameString(p->index, 3)); - DrawString(21, 17 + p->index * 12, STR_7021, HASBIT(_legend_excluded_players, p->index) ? 0x10 : 0xC); + w->DrawWidgets(); + + FOR_ALL_PLAYERS(p) { + if (!p->is_active) continue; + + DrawPlayerIcon(p->index, 4, 18+p->index*12); + + SetDParam(0, p->name_1); + SetDParam(1, p->name_2); + SetDParam(2, GetPlayerNameString(p->index, 3)); + DrawString(21, 17 + p->index * 12, STR_7021, HASBIT(_legend_excluded_players, p->index) ? 0x10 : 0xC); + } + break; } - break; - case WE_CLICK: - if (IS_INT_INSIDE(e->we.click.widget, 3, 11)) { + case WE_CLICK: + if (!IS_INT_INSIDE(e->we.click.widget, 3, 11)) return; + TOGGLEBIT(_legend_excluded_players, e->we.click.widget - 3); w->ToggleWidgetLoweredState(e->we.click.widget); w->SetDirty(); @@ -286,8 +290,7 @@ InvalidateWindow(WC_DELIVERED_CARGO, 0); InvalidateWindow(WC_PERFORMANCE_HISTORY, 0); InvalidateWindow(WC_COMPANY_VALUE, 0); - } - break; + break; } } @@ -330,7 +333,7 @@ byte nums; int mo,yr; - // Exclude the players which aren't valid + /* Exclude the players which aren't valid */ FOR_ALL_PLAYERS(p) { if (!p->is_active) SETBIT(excluded_players, p->index); } @@ -339,11 +342,11 @@ nums = 0; FOR_ALL_PLAYERS(p) { - if (p->is_active) nums = max(nums,p->num_valid_stat_ent); + if (p->is_active) nums = max(nums, p->num_valid_stat_ent); } - gd->num_on_x_axis = min(nums,24); + gd->num_on_x_axis = min(nums, 24); - mo = (_cur_month/3-nums)*3; + mo = (_cur_month / 3 - nums) * 3; yr = _cur_year; while (mo < 0) { yr--; @@ -357,42 +360,42 @@ static void OperatingProfitWndProc(BaseWindow *w, WindowEvent *e) { switch (e->event) { - case WE_PAINT: { - GraphDrawer gd; - const Player* p; - int i,j; - int numd; - - w->DrawWidgets(); + case WE_PAINT: { + GraphDrawer gd; + const Player* p; - gd.left = 2; - gd.top = 18; - gd.height = 136; - gd.has_negative_values = true; - gd.format_str_y_axis = STR_CURRCOMPACT; - - SetupGraphDrawerForPlayers(&gd); + w->DrawWidgets(); - numd = 0; - FOR_ALL_PLAYERS(p) { - if (p->is_active) { - gd.colors[numd] = _colour_gradient[p->player_color][6]; - for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { - gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (p->old_economy[j].income + p->old_economy[j].expenses); - i++; + gd.left = 2; + gd.top = 18; + gd.height = 136; + gd.has_negative_values = true; + gd.format_str_y_axis = STR_CURRCOMPACT; + + SetupGraphDrawerForPlayers(&gd); + + int numd = 0; + FOR_ALL_PLAYERS(p) { + if (p->is_active) { + gd.colors[numd] = _colour_gradient[p->player_color][6]; + for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) { + gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (p->old_economy[j].income + p->old_economy[j].expenses); + i++; + } } + numd++; } - numd++; + + gd.num_dataset = numd; + + DrawGraph(&gd); + break; } - gd.num_dataset = numd; - - DrawGraph(&gd); - } break; - case WE_CLICK: - if (e->we.click.widget == 2) /* Clicked on Legend */ - ShowGraphLegend(); - break; + case WE_CLICK: + /* Clicked on legend? */ + if (e->we.click.widget == 2) ShowGraphLegend(); + break; } } @@ -428,43 +431,40 @@ static void IncomeGraphWndProc(BaseWindow *w, WindowEvent *e) { switch (e->event) { - case WE_PAINT: { - GraphDrawer gd; - const Player* p; - int i,j; - int numd; - - w->DrawWidgets(); + case WE_PAINT: { + GraphDrawer gd; + const Player* p; - gd.left = 2; - gd.top = 18; - gd.height = 104; - gd.has_negative_values = false; - gd.format_str_y_axis = STR_CURRCOMPACT; - SetupGraphDrawerForPlayers(&gd); + w->DrawWidgets(); - numd = 0; - FOR_ALL_PLAYERS(p) { - if (p->is_active) { - gd.colors[numd] = _colour_gradient[p->player_color][6]; - for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { - gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].income; - i++; + gd.left = 2; + gd.top = 18; + gd.height = 104; + gd.has_negative_values = false; + gd.format_str_y_axis = STR_CURRCOMPACT; + SetupGraphDrawerForPlayers(&gd); + + int numd = 0; + FOR_ALL_PLAYERS(p) { + if (p->is_active) { + gd.colors[numd] = _colour_gradient[p->player_color][6]; + for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) { + gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].income; + i++; + } } + numd++; } - numd++; + + gd.num_dataset = numd; + + DrawGraph(&gd); + break; } - gd.num_dataset = numd; - - DrawGraph(&gd); - break; - } - - case WE_CLICK: - if (e->we.click.widget == 2) - ShowGraphLegend(); - break; + case WE_CLICK: + if (e->we.click.widget == 2) ShowGraphLegend(); + break; } } @@ -498,43 +498,40 @@ static void DeliveredCargoGraphWndProc(BaseWindow *w, WindowEvent *e) { switch (e->event) { - case WE_PAINT: { - GraphDrawer gd; - const Player* p; - int i,j; - int numd; - - w->DrawWidgets(); + case WE_PAINT: { + GraphDrawer gd; + const Player* p; - gd.left = 2; - gd.top = 18; - gd.height = 104; - gd.has_negative_values = false; - gd.format_str_y_axis = STR_7024; - SetupGraphDrawerForPlayers(&gd); + w->DrawWidgets(); - numd = 0; - FOR_ALL_PLAYERS(p) { - if (p->is_active) { - gd.colors[numd] = _colour_gradient[p->player_color][6]; - for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { - gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].delivered_cargo; - i++; + gd.left = 2; + gd.top = 18; + gd.height = 104; + gd.has_negative_values = false; + gd.format_str_y_axis = STR_7024; + SetupGraphDrawerForPlayers(&gd); + + int numd = 0; + FOR_ALL_PLAYERS(p) { + if (p->is_active) { + gd.colors[numd] = _colour_gradient[p->player_color][6]; + for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) { + gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].delivered_cargo; + i++; + } } + numd++; } - numd++; + + gd.num_dataset = numd; + + DrawGraph(&gd); + break; } - gd.num_dataset = numd; - - DrawGraph(&gd); - break; - } - - case WE_CLICK: - if (e->we.click.widget == 2) - ShowGraphLegend(); - break; + case WE_CLICK: + if (e->we.click.widget == 2) ShowGraphLegend(); + break; } } @@ -568,45 +565,41 @@ static void PerformanceHistoryWndProc(BaseWindow *w, WindowEvent *e) { switch (e->event) { - case WE_PAINT: { - GraphDrawer gd; - const Player* p; - int i,j; - int numd; - - w->DrawWidgets(); + case WE_PAINT: { + GraphDrawer gd; + const Player* p; - gd.left = 2; - gd.top = 18; - gd.height = 200; - gd.has_negative_values = false; - gd.format_str_y_axis = STR_7024; - SetupGraphDrawerForPlayers(&gd); + w->DrawWidgets(); - numd = 0; - FOR_ALL_PLAYERS(p) { - if (p->is_active) { - gd.colors[numd] = _colour_gradient[p->player_color][6]; - for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { - gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].performance_history; - i++; + gd.left = 2; + gd.top = 18; + gd.height = 200; + gd.has_negative_values = false; + gd.format_str_y_axis = STR_7024; + SetupGraphDrawerForPlayers(&gd); + + int numd = 0; + FOR_ALL_PLAYERS(p) { + if (p->is_active) { + gd.colors[numd] = _colour_gradient[p->player_color][6]; + for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) { + gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].performance_history; + i++; + } } + numd++; } - numd++; + + gd.num_dataset = numd; + + DrawGraph(&gd); + break; } - gd.num_dataset = numd; - - DrawGraph(&gd); - break; - } - - case WE_CLICK: - if (e->we.click.widget == 2) - ShowGraphLegend(); - if (e->we.click.widget == 3) - ShowPerformanceRatingDetail(); - break; + case WE_CLICK: + if (e->we.click.widget == 2) ShowGraphLegend(); + if (e->we.click.widget == 3) ShowPerformanceRatingDetail(); + break; } } @@ -641,43 +634,40 @@ static void CompanyValueGraphWndProc(BaseWindow *w, WindowEvent *e) { switch (e->event) { - case WE_PAINT: { - GraphDrawer gd; - const Player* p; - int i,j; - int numd; - - w->DrawWidgets(); + case WE_PAINT: { + GraphDrawer gd; + const Player* p; - gd.left = 2; - gd.top = 18; - gd.height = 200; - gd.has_negative_values = false; - gd.format_str_y_axis = STR_CURRCOMPACT; - SetupGraphDrawerForPlayers(&gd); + w->DrawWidgets(); - numd = 0; - FOR_ALL_PLAYERS(p) { - if (p->is_active) { - gd.colors[numd] = _colour_gradient[p->player_color][6]; - for (j = gd.num_on_x_axis, i = 0; --j >= 0;) { - gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].company_value; - i++; + gd.left = 2; + gd.top = 18; + gd.height = 200; + gd.has_negative_values = false; + gd.format_str_y_axis = STR_CURRCOMPACT; + SetupGraphDrawerForPlayers(&gd); + + int numd = 0; + FOR_ALL_PLAYERS(p) { + if (p->is_active) { + gd.colors[numd] = _colour_gradient[p->player_color][6]; + for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) { + gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].company_value; + i++; + } } + numd++; } - numd++; + + gd.num_dataset = numd; + + DrawGraph(&gd); + break; } - gd.num_dataset = numd; - - DrawGraph(&gd); - break; - } - - case WE_CLICK: - if (e->we.click.widget == 2) - ShowGraphLegend(); - break; + case WE_CLICK: + if (e->we.click.widget == 2) ShowGraphLegend(); + break; } } @@ -711,97 +701,83 @@ static void CargoPaymentRatesWndProc(BaseWindow *w, WindowEvent *e) { switch (e->event) { - case WE_CREATE: { - uint i; - for (i = 3; i < w->widget_count; i++) { - if (!HASBIT(_legend_excluded_cargo, i - 3)) w->LowerWidget(i); - } - break; - } - - case WE_PAINT: { - int j, x, y; - CargoID i; - GraphDrawer gd; - - w->DrawWidgets(); - - x = 495; - y = 24; + case WE_PAINT: { + GraphDrawer gd; - gd.excluded_data = _legend_excluded_cargo; - gd.left = 2; - gd.top = 24; - gd.height = 104; - gd.has_negative_values = false; - gd.format_str_y_axis = STR_CURRCOMPACT; - gd.num_dataset = NUM_CARGO; - gd.num_on_x_axis = 20; - gd.num_vert_lines = 20; - gd.month = 0xFF; - gd.x_values_start = 10; - gd.x_values_increment = 10; + w->DrawWidgets(); - for (i = 0; i != NUM_CARGO; i++) { - /* Since the buttons have no text, no images, - * both the text and the colored box have to be manually painted. - * clk_dif will move one pixel down and one pixel to the right - * when the button is clicked */ - byte clk_dif = w->IsWidgetLowered(i + 3) ? 1 : 0; - const CargoSpec *cs = GetCargo(i); + int x = 495; + int y = 24; - GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0); - GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour); - SetDParam(0, cs->name != 0 ? cs->name : (StringID)STR_EMPTY); - DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, 0); - y += 8; - gd.colors[i] = cs->legend_colour; - for (j = 0; j != 20; j++) { - gd.cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, i); + gd.excluded_data = _legend_excluded_cargo; + gd.left = 2; + gd.top = 24; + gd.height = w->Height() - 38; + gd.has_negative_values = false; + gd.format_str_y_axis = STR_CURRCOMPACT; + gd.num_on_x_axis = 20; + gd.num_vert_lines = 20; + gd.month = 0xFF; + gd.x_values_start = 10; + gd.x_values_increment = 10; + + uint i = 0; + for (CargoID c = 0; c != NUM_CARGO; c++) { + const CargoSpec *cs = GetCargo(c); + if (!cs->IsValid()) continue; + + /* Only draw labels for widgets that exist. If the widget doesn't + * exist then the local player has used the climate cheat or + * changed the NewGRF configuration with this window open. */ + if (i + 3 < w->widget_count) { + /* Since the buttons have no text, no images, + * both the text and the colored box have to be manually painted. + * clk_dif will move one pixel down and one pixel to the right + * when the button is clicked */ + byte clk_dif = w->IsWidgetLowered(i + 3) ? 1 : 0; + + GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0); + GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour); + SetDParam(0, cs->name); + DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, 0); + y += 8; + } + + gd.colors[i] = cs->legend_colour; + for (uint j = 0; j != 20; j++) { + gd.cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, c); + } + + i++; } + gd.num_dataset = i; + + DrawGraph(&gd); + + DrawString(2 + 46, 24 + gd.height + 7, STR_7062_DAYS_IN_TRANSIT, 0); + DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, 0); + break; } - DrawGraph(&gd); - - DrawString(2 + 46, 24 + gd.height + 7, STR_7062_DAYS_IN_TRANSIT, 0); - DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, 0); - } break; - - case WE_CLICK: { - switch (e->we.click.widget) { - case 3: case 4: case 5: case 6: - case 7: case 8: case 9: case 10: - case 11: case 12: case 13: case 14: - TOGGLEBIT(_legend_excluded_cargo, e->we.click.widget - 3); - w->ToggleWidgetLoweredState(e->we.click.widget); - w->SetDirty(); + case WE_CLICK: + if (e->we.click.widget >= 3) { + TOGGLEBIT(_legend_excluded_cargo, e->we.click.widget - 3); + w->ToggleWidgetLoweredState(e->we.click.widget); + w->SetDirty(); + } break; - } - } break; } } static const OldWidget _cargo_payment_rates_widgets[] = { { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CAPTION, RESIZE_NONE, 14, 11, 567, 0, 13, STR_7061_CARGO_PAYMENT_RATES, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_PANEL, RESIZE_NONE, 14, 0, 567, 14, 141, 0x0, STR_NULL}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 24, 31, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 32, 39, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 40, 47, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 48, 55, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 56, 63, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 64, 71, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 72, 79, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 80, 87, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 88, 95, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 96, 103, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 104, 111, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, -{ WWT_PANEL, RESIZE_NONE, 12, 493, 562, 112, 119, 0x0, STR_7064_TOGGLE_GRAPH_FOR_CARGO}, +{ WWT_PANEL, RESIZE_BOTTOM, 14, 0, 567, 14, 45, 0x0, STR_NULL}, { WIDGETS_END}, }; static const WindowDesc _cargo_payment_rates_desc = { - WDP_AUTO, WDP_AUTO, 568, 142, + WDP_AUTO, WDP_AUTO, 568, 46, WC_PAYMENT_RATES, WC_NONE, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, _cargo_payment_rates_widgets, @@ -811,7 +787,39 @@ void ShowCargoPaymentRates(void) { - BaseWindow::AllocateFront(&_cargo_payment_rates_desc, 0); + BaseWindow *w = BaseWindow::AllocateFront(&_cargo_payment_rates_desc, 0); + if (w == NULL) return; + + /* Count the number of active cargo types */ + uint num_active = 0; + for (CargoID c = 0; c != NUM_CARGO; c++) { + if (GetCargo(c)->IsValid()) num_active++; + } + + /* Resize the window to fit the cargo types */ + w->Resize(0, num_active * 8); + + /* Add widgets for each cargo type */ + w->widget_count = 3 + num_active; + w->widget = ReallocT(w->widget, w->widget_count); + + /* Set the properties of each widget */ + for (uint i = 0; i != num_active; i++) { + OldWidget *wi = &w->widget[3 + i]; + wi->type = WWT_PANEL; + wi->m_display_flags = RESIZE_NONE; + wi->color = 12; + wi->left = 493; + wi->right = 562; + wi->top = 24 + i * 8; + wi->bottom = wi->top + 7; + wi->data = 0; + wi->tooltips = STR_7064_TOGGLE_GRAPH_FOR_CARGO; + + if (!HASBIT(_legend_excluded_cargo, i)) w->LowerWidget(i + 3); + } + + w->SetDirty(); } /************************/ @@ -856,17 +864,15 @@ case WE_PAINT: { const Player* plist[MAX_PLAYERS]; const Player* p; - uint pl_num; - uint i; w->DrawWidgets(); - pl_num = 0; + uint pl_num = 0; FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p; qsort((void*)plist, pl_num, sizeof(*plist), PerfHistComp); - for (i = 0; i != pl_num; i++) { + for (uint i = 0; i != pl_num; i++) { p = plist[i]; SetDParam(0, i + STR_01AC_1ST); SetDParam(1, p->name_1); @@ -920,7 +926,7 @@ int total_score = 0; int color_done, color_notdone; - // Draw standard stuff + /* Draw standard stuff */ w->DrawWidgets(); /* Check if the currently selected player is still active. */ @@ -949,25 +955,25 @@ /* If there are no active players, don't display anything else. */ if (_performance_rating_detail_player == INVALID_PLAYER) break; - // Paint the player icons + /* Paint the player icons */ for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { if (!GetPlayer(i)->is_active) { - // Check if we have the player as an active player + /* Check if we have the player as an active player */ if (!w->IsWidgetDisabled(i + 13)) { - // Bah, player gone :( + /* Bah, player gone :( */ w->DisableWidget(i + 13); - // We need a repaint + /* We need a repaint */ w->SetDirty(); } continue; } - // Check if we have the player marked as inactive + /* Check if we have the player marked as inactive */ if (w->IsWidgetDisabled(i + 13)) { - // New player! Yippie :p + /* New player! Yippie :p */ w->EnableWidget(i + 13); - // We need a repaint + /* We need a repaint */ w->SetDirty(); } @@ -975,18 +981,18 @@ DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x); } - // The colors used to show how the progress is going + /* The colors used to show how the progress is going */ color_done = _colour_gradient[COLOUR_GREEN][4]; color_notdone = _colour_gradient[COLOUR_RED][4]; - // Draw all the score parts + /* Draw all the score parts */ for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) { int val = _score_part[_performance_rating_detail_player][i]; int needed = _score_info[i].needed; int score = _score_info[i].score; y += 20; - // SCORE_TOTAL has his own rulez ;) + /* SCORE_TOTAL has his own rulez ;) */ if (i == SCORE_TOTAL) { needed = total_score; score = SCORE_MAX; @@ -996,11 +1002,11 @@ DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, 0); - // Draw the score + /* Draw the score */ SetDParam(0, score); DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0); - // Calculate the %-bar + /* Calculate the %-bar */ if (val > needed) { x = 50; } else if (val == 0) { @@ -1009,28 +1015,28 @@ x = val * 50 / needed; } - // SCORE_LOAN is inversed + /* SCORE_LOAN is inversed */ if (val < 0 && i == SCORE_LOAN) x = 0; - // Draw the bar + /* Draw the bar */ if (x != 0) GfxFillRect(112, y - 2, 112 + x, y + 10, color_done); if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone); - // Calculate the % + /* Calculate the % */ x = (val <= needed) ? val * 100 / needed : 100; - // SCORE_LOAN is inversed + /* SCORE_LOAN is inversed */ if (val < 0 && i == SCORE_LOAN) x = 0; - // Draw it + /* Draw it */ SetDParam(0, x); DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, 0); - // SCORE_LOAN is inversed + /* SCORE_LOAN is inversed */ if (i == SCORE_LOAN) val = needed - val; - // Draw the amount we have against what is needed - // For some of them it is in currency format + /* 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 (i) { @@ -1050,9 +1056,9 @@ } case WE_CLICK: - // Check which button is clicked + /* Check which button is clicked */ if (IS_INT_INSIDE(e->we.click.widget, 13, 21)) { - // Is it no on disable? + /* Is it no on disable? */ if (!w->IsWidgetDisabled(e->we.click.widget)) { w->RaiseWidget(_performance_rating_detail_player + 13); _performance_rating_detail_player = (PlayerID)(e->we.click.widget - 13); @@ -1063,11 +1069,10 @@ break; case WE_CREATE: { - PlayerID i; Player *p2; /* Disable the players who are not active */ - for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { + for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) { w->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active); } /* Update all player stats with the current data @@ -1085,8 +1090,8 @@ break; } - case WE_TICK: { - // Update the player score every 5 days + case WE_TICK: + /* Update the player score every 5 days */ if (--w->custom[0] == 0) { w->custom[0] = DAY_TICKS; if (--w->custom[1] == 0) { @@ -1094,7 +1099,7 @@ w->custom[1] = 5; FOR_ALL_PLAYERS(p2) { - // Skip if player is not active + /* Skip if player is not active */ if (p2->is_active) UpdateCompanyRatingAndValue(p2, false); } w->SetDirty(); @@ -1102,7 +1107,6 @@ } break; - } } }