src/graph_gui.cpp
author rubidium
Mon, 03 Dec 2007 23:39:38 +0000
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
permissions -rw-r--r--
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
     3
/** @file graph_gui.cpp */
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1575
diff changeset
     6
#include "openttd.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 410
diff changeset
     7
#include "table/strings.h"
6725
23339968083f (svn r10595) [NewGRF_ports] -Sync: with trunk r10559-10593
richk
parents: 6720
diff changeset
     8
#include "strings.h"
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
     9
#include "table/sprites.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    10
#include "functions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "player.h"
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
    15
#include "economy.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2135
diff changeset
    16
#include "variables.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 3801
diff changeset
    17
#include "date.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    18
#include "helpers.hpp"
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6197
diff changeset
    19
#include "cargotype.h"
5291
5e4d9ab3cc0f (svn r7444) -Codechange: Use one (global) cargo-colours array for drawing cargo-colours. Change Food
Darkvater
parents: 5247
diff changeset
    20
6057
8f1388f239b3 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 6056
diff changeset
    21
/* Bitmasks of player and cargo indices that shouldn't be drawn. */
8f1388f239b3 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 6056
diff changeset
    22
static uint _legend_excluded_players;
8f1388f239b3 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 6056
diff changeset
    23
static uint _legend_excluded_cargo;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
/************************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
/* GENERIC GRAPH DRAWER */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
/************************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
    29
enum {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6698
diff changeset
    30
	GRAPH_MAX_DATASETS = 32,
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    31
	GRAPH_AXIS_LABEL_COLOUR = TC_BLACK,
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
    32
	GRAPH_AXIS_LINE_COLOUR  = 215,
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    33
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    34
	GRAPH_X_POSITION_BEGINNING  = 44,  ///< Start the graph 44 pixels from gw->left
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    35
	GRAPH_X_POSITION_SEPARATION = 22,  ///< There are 22 pixels between each X value
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    36
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    37
	GRAPH_NUM_LINES_Y = 9, ///< How many horizontal lines to draw.
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    38
	/* 9 is convenient as that means the distance between them is the height of the graph / 8,
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    39
	 * which is the same
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    40
	 * as height >> 3. */
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
    41
};
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
    42
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
    43
/* Apparently these don't play well with enums. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    44
static const OverflowSafeInt64 INVALID_DATAPOINT = INT64_MAX; // Value used for a datapoint that shouldn't be drawn.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    45
static const uint INVALID_DATAPOINT_POS = UINT_MAX;  // Used to determine if the previous point was drawn.
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
    46
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    47
struct GraphDrawer {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    48
	uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	byte num_dataset;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	byte num_on_x_axis;
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
    51
	bool has_negative_values;
6022
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    52
	byte num_vert_lines;
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    53
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    54
	/* The starting month and year that values are plotted against. If month is
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    55
	 * 0xFF, use x_values_start and x_values_increment below instead. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	byte month;
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4286
diff changeset
    57
	Year year;
6022
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    58
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    59
	/* These values are used if the graph is being plotted against values
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    60
	 * rather than the dates specified by month and year. */
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    61
	uint16 x_values_start;
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    62
	uint16 x_values_increment;
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
    63
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    64
	int left, top;  ///< Where to start drawing the graph, in pixels.
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
    65
	uint height;    ///< The height of the graph in pixels.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	StringID format_str_y_axis;
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
    67
	byte colors[GRAPH_MAX_DATASETS];
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    68
	OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    69
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2261
diff changeset
    71
static void DrawGraph(const GraphDrawer *gw)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    73
	uint x, y;                       ///< Reused whenever x and y coordinates are needed.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    74
	OverflowSafeInt64 highest_value; ///< Highest value to be drawn.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    75
	int x_axis_offset;               ///< Distance from the top of the graph to the x axis.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
240
f1efbac04112 (svn r241) -Fix: Trailing spaces :O
darkvater
parents: 236
diff changeset
    77
	/* the colors and cost array of GraphDrawer must accomodate
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
    78
	 * both values for cargo and players. So if any are higher, quit */
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
    79
	assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS);
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    80
	assert(gw->num_vert_lines > 0);
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    81
6017
2b6446e2deff (svn r8317) -Codechange: Remove GraphDrawer::bg_line_color since it was the same everywhere it was set.
maedhros
parents: 6012
diff changeset
    82
	byte grid_colour = _colour_gradient[14][4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
    84
	/* The coordinates of the opposite edges of the graph. */
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    85
	int bottom = gw->top + gw->height - 1;
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
    86
	int right  = gw->left + GRAPH_X_POSITION_BEGINNING + gw->num_vert_lines * GRAPH_X_POSITION_SEPARATION - 1;
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    87
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
    88
	/* Draw the vertical grid lines. */
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    89
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    90
	/* Don't draw the first line, as that's where the axis will be. */
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    91
	x = gw->left + GRAPH_X_POSITION_BEGINNING + GRAPH_X_POSITION_SEPARATION;
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    92
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    93
	for (int i = 0; i < gw->num_vert_lines; i++) {
6017
2b6446e2deff (svn r8317) -Codechange: Remove GraphDrawer::bg_line_color since it was the same everywhere it was set.
maedhros
parents: 6012
diff changeset
    94
		GfxFillRect(x, gw->top, x, bottom, grid_colour);
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    95
		x += GRAPH_X_POSITION_SEPARATION;
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    96
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    97
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
    98
	/* Draw the horizontal grid lines. */
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
    99
	x = gw->left + GRAPH_X_POSITION_BEGINNING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
	y = gw->height + gw->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   102
	for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) {
6017
2b6446e2deff (svn r8317) -Codechange: Remove GraphDrawer::bg_line_color since it was the same everywhere it was set.
maedhros
parents: 6012
diff changeset
   103
		GfxFillRect(x, y, right, y, grid_colour);
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   104
		y -= (gw->height / (GRAPH_NUM_LINES_Y - 1));
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   105
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   107
	/* Draw the y axis. */
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
   108
	GfxFillRect(x, gw->top, x, bottom, GRAPH_AXIS_LINE_COLOUR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   110
	/* Find the distance from the top of the graph to the x axis. */
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   111
	x_axis_offset = gw->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   113
	/* The graph is currently symmetrical about the x axis. */
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   114
	if (gw->has_negative_values) x_axis_offset /= 2;
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   115
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   116
	/* Draw the x axis. */
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   117
	y = x_axis_offset + gw->top;
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
   118
	GfxFillRect(x, y, right, y, GRAPH_AXIS_LINE_COLOUR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   120
	/* Find the largest value that will be drawn. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	if (gw->num_on_x_axis == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   124
	assert(gw->num_on_x_axis > 0);
6029
3db5cfc1ee92 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 6028
diff changeset
   125
	assert(gw->num_dataset > 0);
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
   126
6055
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   127
	/* Start of with a value of twice the height of the graph in pixels. It's a
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   128
	 * bit arbitrary, but it makes the cargo payment graph look a little nicer,
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   129
	 * and prevents division by zero when calculating where the datapoint
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   130
	 * should be drawn. */
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   131
	highest_value = x_axis_offset * 2;
6047
a69bc9a0b6ec (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 6044
diff changeset
   132
6029
3db5cfc1ee92 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 6028
diff changeset
   133
	for (int i = 0; i < gw->num_dataset; i++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   134
		if (!HasBit(gw->excluded_data, i)) {
6042
1a7b67e2afd2 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 6029
diff changeset
   135
			for (int j = 0; j < gw->num_on_x_axis; j++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   136
				OverflowSafeInt64 datapoint = gw->cost[i][j];
6042
1a7b67e2afd2 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 6029
diff changeset
   137
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   138
				if (datapoint != INVALID_DATAPOINT) {
6047
a69bc9a0b6ec (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 6044
diff changeset
   139
					/* For now, if the graph has negative values the scaling is
a69bc9a0b6ec (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 6044
diff changeset
   140
					 * symmetrical about the x axis, so take the absolute value
a69bc9a0b6ec (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 6044
diff changeset
   141
					 * of each data point. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   142
					highest_value = max(highest_value, abs(datapoint));
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
   143
				}
6029
3db5cfc1ee92 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 6028
diff changeset
   144
			}
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
   145
		}
6029
3db5cfc1ee92 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 6028
diff changeset
   146
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   147
6055
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   148
	/* Round up highest_value so that it will divide cleanly into the number of
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   149
	 * axis labels used. */
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   150
	int round_val = highest_value % (GRAPH_NUM_LINES_Y - 1);
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   151
	if (round_val != 0) highest_value += (GRAPH_NUM_LINES_Y - 1 - round_val);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	/* draw text strings on the y axis */
6055
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   154
	int64 y_label = highest_value;
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   155
	int64 y_label_separation = highest_value / (GRAPH_NUM_LINES_Y - 1);
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   156
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   157
	/* If there are negative values, the graph goes from highest_value to
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   158
	 * -highest_value, not highest_value to 0. */
6058
3ee339c612d1 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 6057
diff changeset
   159
	if (gw->has_negative_values) y_label_separation *= 2;
6055
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   160
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   161
	x = gw->left + GRAPH_X_POSITION_BEGINNING + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	y = gw->top - 3;
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   163
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   164
	for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 519
diff changeset
   165
		SetDParam(0, gw->format_str_y_axis);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   166
		SetDParam(1, y_label);
6019
e244cd8e301a (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 6017
diff changeset
   167
		DrawStringRightAligned(x, y, STR_0170, GRAPH_AXIS_LABEL_COLOUR);
6055
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   168
4ac2b6bfc16b (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 6047
diff changeset
   169
		y_label -= y_label_separation;
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   170
		y += (gw->height / (GRAPH_NUM_LINES_Y - 1));
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   171
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	/* draw strings on the x axis */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	if (gw->month != 0xFF) {
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   175
		x = gw->left + GRAPH_X_POSITION_BEGINNING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
		y = gw->top + gw->height + 1;
6028
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   177
		byte month = gw->month;
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   178
		Year year  = gw->year;
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   179
		for (int i = 0; i < gw->num_on_x_axis; i++) {
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   180
			SetDParam(0, month + STR_0162_JAN);
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   181
			SetDParam(1, month + STR_0162_JAN + 2);
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   182
			SetDParam(2, year);
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   183
			DrawString(x, y, month == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
6028
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   185
			month += 3;
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   186
			if (month >= 12) {
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   187
				month = 0;
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   188
				year++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
			}
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   190
			x += GRAPH_X_POSITION_SEPARATION;
6028
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   191
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	} else {
6044
6f03f8cab2ec (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 6042
diff changeset
   193
		/* Draw the label under the data point rather than on the grid line. */
6f03f8cab2ec (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 6042
diff changeset
   194
		x = gw->left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
		y = gw->top + gw->height + 1;
6022
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
   196
		uint16 label = gw->x_values_start;
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
   197
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
   198
		for (int i = 0; i < gw->num_on_x_axis; i++) {
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
   199
			SetDParam(0, label);
6044
6f03f8cab2ec (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 6042
diff changeset
   200
			DrawStringCentered(x, y, STR_01CB, GRAPH_AXIS_LABEL_COLOUR);
6f03f8cab2ec (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 6042
diff changeset
   201
6022
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
   202
			label += gw->x_values_increment;
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   203
			x += GRAPH_X_POSITION_SEPARATION;
6022
69bdaeb96df0 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 6019
diff changeset
   204
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	/* draw lines and dots */
6028
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   208
	for (int i = 0; i < gw->num_dataset; i++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   209
		if (!HasBit(gw->excluded_data, i)) {
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   210
			/* Centre the dot between the grid lines. */
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   211
			x = gw->left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2);
6042
1a7b67e2afd2 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 6029
diff changeset
   212
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   213
			byte color  = gw->colors[i];
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   214
			uint prev_x = INVALID_DATAPOINT_POS;
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   215
			uint prev_y = INVALID_DATAPOINT_POS;
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   216
6042
1a7b67e2afd2 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 6029
diff changeset
   217
			for (int j = 0; j < gw->num_on_x_axis; j++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   218
				OverflowSafeInt64 datapoint = gw->cost[i][j];
6042
1a7b67e2afd2 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 6029
diff changeset
   219
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   220
				if (datapoint != INVALID_DATAPOINT) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   221
					/*
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   222
					 * Check whether we need to reduce the 'accuracy' of the
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   223
					 * datapoint value and the highest value to splut overflows.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   224
					 * And when 'drawing' 'one million' or 'one million and one'
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   225
					 * there is no significant difference, so the least
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   226
					 * significant bits can just be removed.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   227
					 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   228
					 * If there are more bits needed than would fit in a 32 bits
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   229
					 * integer, so at about 31 bits because of the sign bit, the
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   230
					 * least significant bits are removed.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   231
					 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   232
					int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint));
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   233
					int reduce_range = max(mult_range - 31, 0);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   234
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   235
					/* Handle negative values differently (don't shift sign) */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   236
					if (datapoint < 0) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   237
						datapoint = -(abs(datapoint) >> reduce_range);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   238
					} else {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   239
						datapoint >>= reduce_range;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   240
					}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   241
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   242
					y = gw->top + x_axis_offset - (x_axis_offset * datapoint) / (highest_value >> reduce_range);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   244
					/* Draw the point. */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6698
diff changeset
   245
					GfxFillRect(x - 1, y - 1, x + 1, y + 1, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   247
					/* Draw the line connected to the previous point. */
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   248
					if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, color);
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   249
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   250
					prev_x = x;
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   251
					prev_y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
				} else {
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   253
					prev_x = INVALID_DATAPOINT_POS;
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   254
					prev_y = INVALID_DATAPOINT_POS;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
				}
6056
879b00467368 (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros
parents: 6055
diff changeset
   256
6027
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   257
				x += GRAPH_X_POSITION_SEPARATION;
6897590574c0 (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 6022
diff changeset
   258
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		}
6028
5638dde4a5f6 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 6027
diff changeset
   260
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
/* GRAPH LEGEND */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
static void GraphLegendWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   269
	switch (e->event) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   270
		case WE_CREATE:
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   271
			for (uint i = 3; i < w->widget_count; i++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   272
				if (!HasBit(_legend_excluded_players, i - 3)) w->LowerWidget(i);
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   273
			}
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   274
			break;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   275
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   276
		case WE_PAINT: {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   277
			const Player *p;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   278
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   279
			FOR_ALL_PLAYERS(p) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   280
				if (p->is_active) continue;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   281
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   282
				SetBit(_legend_excluded_players, p->index);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   283
				w->RaiseWidget(p->index + 3);
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   284
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   286
			DrawWindowWidgets(w);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   287
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   288
			FOR_ALL_PLAYERS(p) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   289
				if (!p->is_active) continue;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   290
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6698
diff changeset
   291
				DrawPlayerIcon(p->index, 4, 18 + p->index * 12);
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   292
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   293
				SetDParam(0, p->index);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   294
				SetDParam(1, p->index);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   295
				DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE);
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   296
			}
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   297
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   300
		case WE_CLICK:
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   301
			if (!IsInsideMM(e->we.click.widget, 3, 11)) return;
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   302
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   303
			ToggleBit(_legend_excluded_players, e->we.click.widget - 3);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   304
			w->ToggleWidgetLoweredState(e->we.click.widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
			InvalidateWindow(WC_INCOME_GRAPH, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
			InvalidateWindow(WC_OPERATING_PROFIT, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
			InvalidateWindow(WC_DELIVERED_CARGO, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
140
b00ce8503044 (svn r141) -Fix: Company-value was not updated immediatly if legend was changed
truelight
parents: 116
diff changeset
   310
			InvalidateWindow(WC_COMPANY_VALUE, 0);
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   311
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
static const Widget _graph_legend_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   316
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   317
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   249,     0,    13, STR_704E_KEY_TO_COMPANY_GRAPHS, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   318
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,   113, 0x0,                            STR_NULL},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   319
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    16,    27, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   320
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    28,    39, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   321
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    40,    51, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   322
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    52,    63, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   323
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    64,    75, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   324
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    76,    87, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   325
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    88,    99, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   326
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,   100,   111, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   327
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
static const WindowDesc _graph_legend_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   331
	WDP_AUTO, WDP_AUTO, 250, 114, 250, 114,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   332
	WC_GRAPH_LEGEND, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
	_graph_legend_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	GraphLegendWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   338
static void ShowGraphLegend()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	AllocateWindowDescFront(&_graph_legend_desc, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
/********************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
/* OPERATING PROFIT */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
/********************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
static void SetupGraphDrawerForPlayers(GraphDrawer *gd)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
{
2475
8443e1eefe1b (svn r3001) s/Player*/const Player*/
tron
parents: 2458
diff changeset
   349
	const Player* p;
6057
8f1388f239b3 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 6056
diff changeset
   350
	uint excluded_players = _legend_excluded_players;
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5838
diff changeset
   351
	byte nums;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6698
diff changeset
   352
	int mo, yr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   354
	/* Exclude the players which aren't valid */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	FOR_ALL_PLAYERS(p) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   356
		if (!p->is_active) SetBit(excluded_players, p->index);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   357
	}
6057
8f1388f239b3 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 6056
diff changeset
   358
	gd->excluded_data = excluded_players;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	gd->num_vert_lines = 24;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	nums = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	FOR_ALL_PLAYERS(p) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   363
		if (p->is_active) nums = max(nums, p->num_valid_stat_ent);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   365
	gd->num_on_x_axis = min(nums, 24);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   367
	mo = (_cur_month / 3 - nums) * 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	yr = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	while (mo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		yr--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
		mo += 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	gd->year = yr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	gd->month = mo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
static void OperatingProfitWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   380
	switch (e->event) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   381
		case WE_PAINT: {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   382
			GraphDrawer gd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   383
			const Player* p;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   384
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   385
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   387
			gd.left = 2;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   388
			gd.top = 18;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   389
			gd.height = 136;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   390
			gd.has_negative_values = true;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   391
			gd.format_str_y_axis = STR_CURRCOMPACT;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   392
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   393
			SetupGraphDrawerForPlayers(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   394
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   395
			int numd = 0;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   396
			FOR_ALL_PLAYERS(p) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   397
				if (p->is_active) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   398
					gd.colors[numd] = _colour_gradient[p->player_color][6];
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   399
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   400
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (p->old_economy[j].income + p->old_economy[j].expenses);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   401
						i++;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   402
					}
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   403
				}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   404
				numd++;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   405
			}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   406
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   407
			gd.num_dataset = numd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   408
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   409
			DrawGraph(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   410
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
		}
1085
408f95e1b70a (svn r1586) Fix: [ 1107340 ] Graphs don't show comapany info for company #8
dominik
parents: 1079
diff changeset
   412
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   413
		case WE_CLICK:
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   414
			/* Clicked on legend? */
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   415
			if (e->we.click.widget == 2) ShowGraphLegend();
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   416
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
static const Widget _operating_profit_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   421
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   422
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7025_OPERATING_PROFIT_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   423
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,                    STR_704D_SHOW_KEY_TO_GRAPHS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   424
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   173, 0x0,                             STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   425
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
static const WindowDesc _operating_profit_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   429
	WDP_AUTO, WDP_AUTO, 576, 174, 576, 174,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   430
	WC_OPERATING_PROFIT, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	_operating_profit_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	OperatingProfitWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   437
void ShowOperatingProfitGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	if (AllocateWindowDescFront(&_operating_profit_desc, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
/* INCOME GRAPH */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
static void IncomeGraphWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   451
	switch (e->event) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   452
		case WE_PAINT: {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   453
			GraphDrawer gd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   454
			const Player* p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   456
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   458
			gd.left = 2;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   459
			gd.top = 18;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   460
			gd.height = 104;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   461
			gd.has_negative_values = false;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   462
			gd.format_str_y_axis = STR_CURRCOMPACT;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   463
			SetupGraphDrawerForPlayers(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   464
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   465
			int numd = 0;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   466
			FOR_ALL_PLAYERS(p) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   467
				if (p->is_active) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   468
					gd.colors[numd] = _colour_gradient[p->player_color][6];
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   469
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   470
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].income;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   471
						i++;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   472
					}
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   473
				}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   474
				numd++;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   475
			}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   476
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   477
			gd.num_dataset = numd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   478
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   479
			DrawGraph(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   480
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   483
		case WE_CLICK:
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   484
			if (e->we.click.widget == 2) ShowGraphLegend();
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   485
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
static const Widget _income_graph_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   490
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   491
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7022_INCOME_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   492
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,          STR_704D_SHOW_KEY_TO_GRAPHS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   493
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   141, 0x0,                   STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   494
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
static const WindowDesc _income_graph_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   498
	WDP_AUTO, WDP_AUTO, 576, 142, 576, 142,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   499
	WC_INCOME_GRAPH, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	_income_graph_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
	IncomeGraphWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   505
void ShowIncomeGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	if (AllocateWindowDescFront(&_income_graph_desc, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
/*******************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
/* DELIVERED CARGO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
/*******************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   518
	switch (e->event) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   519
		case WE_PAINT: {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   520
			GraphDrawer gd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   521
			const Player* p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   523
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   525
			gd.left = 2;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   526
			gd.top = 18;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   527
			gd.height = 104;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   528
			gd.has_negative_values = false;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   529
			gd.format_str_y_axis = STR_7024;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   530
			SetupGraphDrawerForPlayers(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   531
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   532
			int numd = 0;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   533
			FOR_ALL_PLAYERS(p) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   534
				if (p->is_active) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   535
					gd.colors[numd] = _colour_gradient[p->player_color][6];
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   536
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   537
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (OverflowSafeInt64)p->old_economy[j].delivered_cargo;
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   538
						i++;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   539
					}
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   540
				}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   541
				numd++;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   542
			}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   543
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   544
			gd.num_dataset = numd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   545
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   546
			DrawGraph(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   547
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   550
		case WE_CLICK:
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   551
			if (e->we.click.widget == 2) ShowGraphLegend();
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   552
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
static const Widget _delivered_cargo_graph_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   557
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   558
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7050_UNITS_OF_CARGO_DELIVERED, STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   559
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,                      STR_704D_SHOW_KEY_TO_GRAPHS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   560
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   141, 0x0,                               STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   561
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
static const WindowDesc _delivered_cargo_graph_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   565
	WDP_AUTO, WDP_AUTO, 576, 142, 576, 142,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   566
	WC_DELIVERED_CARGO, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	_delivered_cargo_graph_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	DeliveredCargoGraphWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   572
void ShowDeliveredCargoGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	if (AllocateWindowDescFront(&_delivered_cargo_graph_desc, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   577
}
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   578
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   579
/***********************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   580
/* PERFORMANCE HISTORY */
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   581
/***********************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   582
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   583
static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   584
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   585
	switch (e->event) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   586
		case WE_PAINT: {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   587
			GraphDrawer gd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   588
			const Player* p;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   589
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   590
			DrawWindowWidgets(w);
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   591
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   592
			gd.left = 2;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   593
			gd.top = 18;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   594
			gd.height = 200;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   595
			gd.has_negative_values = false;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   596
			gd.format_str_y_axis = STR_7024;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   597
			SetupGraphDrawerForPlayers(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   598
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   599
			int numd = 0;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   600
			FOR_ALL_PLAYERS(p) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   601
				if (p->is_active) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   602
					gd.colors[numd] = _colour_gradient[p->player_color][6];
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   603
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   604
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (OverflowSafeInt64)p->old_economy[j].performance_history;
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   605
						i++;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   606
					}
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   607
				}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   608
				numd++;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   609
			}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   610
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   611
			gd.num_dataset = numd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   612
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   613
			DrawGraph(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   614
			break;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   615
		}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   616
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   617
		case WE_CLICK:
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   618
			if (e->we.click.widget == 2) ShowGraphLegend();
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   619
			if (e->we.click.widget == 3) ShowPerformanceRatingDetail();
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   620
			break;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   621
	}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   622
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   623
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   624
static const Widget _performance_history_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   625
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                             STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   626
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   475,     0,    13, STR_7051_COMPANY_PERFORMANCE_RATINGS, STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   627
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,                         STR_704D_SHOW_KEY_TO_GRAPHS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   628
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   476,   525,     0,    13, STR_PERFORMANCE_DETAIL_KEY,           STR_704D_SHOW_KEY_TO_GRAPHS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   629
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   237, 0x0,                                  STR_NULL},
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   630
{   WIDGETS_END},
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   631
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   632
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   633
static const WindowDesc _performance_history_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   634
	WDP_AUTO, WDP_AUTO, 576, 238, 576, 238,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   635
	WC_PERFORMANCE_HISTORY, WC_NONE,
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   636
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   637
	_performance_history_widgets,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   638
	PerformanceHistoryWndProc
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   639
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   640
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   641
void ShowPerformanceHistoryGraph()
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   642
{
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   643
	if (AllocateWindowDescFront(&_performance_history_desc, 0)) {
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   644
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   645
	}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   646
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   647
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   648
/*****************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   649
/* COMPANY VALUE */
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   650
/*****************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   651
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   652
static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   653
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   654
	switch (e->event) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   655
		case WE_PAINT: {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   656
			GraphDrawer gd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   657
			const Player* p;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   658
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   659
			DrawWindowWidgets(w);
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   660
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   661
			gd.left = 2;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   662
			gd.top = 18;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   663
			gd.height = 200;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   664
			gd.has_negative_values = false;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   665
			gd.format_str_y_axis = STR_CURRCOMPACT;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   666
			SetupGraphDrawerForPlayers(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   667
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   668
			int numd = 0;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   669
			FOR_ALL_PLAYERS(p) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   670
				if (p->is_active) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   671
					gd.colors[numd] = _colour_gradient[p->player_color][6];
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   672
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   673
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].company_value;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   674
						i++;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   675
					}
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   676
				}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   677
				numd++;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   678
			}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   679
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   680
			gd.num_dataset = numd;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   681
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   682
			DrawGraph(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   683
			break;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   684
		}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   685
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   686
		case WE_CLICK:
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   687
			if (e->we.click.widget == 2) ShowGraphLegend();
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   688
			break;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   689
	}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   690
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   691
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   692
static const Widget _company_value_graph_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   693
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   694
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7052_COMPANY_VALUES, STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   695
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,            STR_704D_SHOW_KEY_TO_GRAPHS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   696
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   237, 0x0,                     STR_NULL},
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   697
{   WIDGETS_END},
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   698
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   699
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   700
static const WindowDesc _company_value_graph_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   701
	WDP_AUTO, WDP_AUTO, 576, 238, 576, 238,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   702
	WC_COMPANY_VALUE, WC_NONE,
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   703
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   704
	_company_value_graph_widgets,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   705
	CompanyValueGraphWndProc
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   706
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   707
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   708
void ShowCompanyValueGraph()
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   709
{
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   710
	if (AllocateWindowDescFront(&_company_value_graph_desc, 0)) {
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   711
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   712
	}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   713
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   714
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   715
/*****************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   716
/* PAYMENT RATES */
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   717
/*****************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   718
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   719
static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   720
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   721
	switch (e->event) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   722
		case WE_PAINT: {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   723
			GraphDrawer gd;
4851
15d60e1f41a2 (svn r6777) -GuiChange: When painting a lowered button on CargoPaymentsRates, displace the content of one pixel to the right and to the bottom. This will make it look like a normal button
belugas
parents: 4760
diff changeset
   724
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   725
			DrawWindowWidgets(w);
6518
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   726
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   727
			int x = 495;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   728
			int y = 24;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   729
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   730
			gd.excluded_data = _legend_excluded_cargo;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   731
			gd.left = 2;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   732
			gd.top = 24;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   733
			gd.height = w->height - 38;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   734
			gd.has_negative_values = false;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   735
			gd.format_str_y_axis = STR_CURRCOMPACT;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   736
			gd.num_on_x_axis = 20;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   737
			gd.num_vert_lines = 20;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   738
			gd.month = 0xFF;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   739
			gd.x_values_start     = 10;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   740
			gd.x_values_increment = 10;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   741
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   742
			uint i = 0;
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6596
diff changeset
   743
			for (CargoID c = 0; c < NUM_CARGO; c++) {
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   744
				const CargoSpec *cs = GetCargo(c);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   745
				if (!cs->IsValid()) continue;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   746
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   747
				/* Only draw labels for widgets that exist. If the widget doesn't
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   748
				 * exist then the local player has used the climate cheat or
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   749
				 * changed the NewGRF configuration with this window open. */
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   750
				if (i + 3 < w->widget_count) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   751
					/* Since the buttons have no text, no images,
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   752
					 * both the text and the colored box have to be manually painted.
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   753
					 * clk_dif will move one pixel down and one pixel to the right
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   754
					 * when the button is clicked */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   755
					byte clk_dif = w->IsWidgetLowered(i + 3) ? 1 : 0;
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   756
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   757
					GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   758
					GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   759
					SetDParam(0, cs->name);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   760
					DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, TC_FROMSTRING);
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   761
					y += 8;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   762
				}
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   763
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   764
				gd.colors[i] = cs->legend_colour;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   765
				for (uint j = 0; j != 20; j++) {
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   766
					gd.cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, c);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   767
				}
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   768
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   769
				i++;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   770
			}
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   771
			gd.num_dataset = i;
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   772
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   773
			DrawGraph(&gd);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   774
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   775
			DrawString(2 + 46, 24 + gd.height + 7, STR_7062_DAYS_IN_TRANSIT, TC_FROMSTRING);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   776
			DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, TC_FROMSTRING);
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   777
			break;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   778
		}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   779
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   780
		case WE_CLICK:
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   781
			if (e->we.click.widget >= 3) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   782
				ToggleBit(_legend_excluded_cargo, e->we.click.widget - 3);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   783
				w->ToggleWidgetLoweredState(e->we.click.widget);
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   784
				SetWindowDirty(w);
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   785
			}
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   786
			break;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   787
	}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   788
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   789
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   790
static const Widget _cargo_payment_rates_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   791
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                     STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   792
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   567,     0,    13, STR_7061_CARGO_PAYMENT_RATES, STR_018C_WINDOW_TITLE_DRAG_THIS},
6518
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   793
{      WWT_PANEL, RESIZE_BOTTOM,    14,     0,   567,    14,    45, 0x0,                          STR_NULL},
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   794
{   WIDGETS_END},
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   795
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   796
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   797
static const WindowDesc _cargo_payment_rates_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   798
	WDP_AUTO, WDP_AUTO, 568, 46, 568, 46,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   799
	WC_PAYMENT_RATES, WC_NONE,
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   800
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   801
	_cargo_payment_rates_widgets,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   802
	CargoPaymentRatesWndProc
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   803
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   804
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   805
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   806
void ShowCargoPaymentRates()
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   807
{
6518
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   808
	Window *w = AllocateWindowDescFront(&_cargo_payment_rates_desc, 0);
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   809
	if (w == NULL) return;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   810
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   811
	/* Count the number of active cargo types */
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   812
	uint num_active = 0;
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6596
diff changeset
   813
	for (CargoID c = 0; c < NUM_CARGO; c++) {
6518
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   814
		if (GetCargo(c)->IsValid()) num_active++;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   815
	}
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   816
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   817
	/* Resize the window to fit the cargo types */
6698
4d04ee4613aa (svn r9435) -Fix (r8972): ensure the cargo payment graph is at least 12 "items" high
peter1138
parents: 6676
diff changeset
   818
	ResizeWindow(w, 0, max(num_active, 12U) * 8);
6518
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   819
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   820
	/* Add widgets for each cargo type */
6596
0c6bff37a6e8 (svn r9079) -Codechange: add WWT_LAST widget when dynamically building cargo payment graph
peter1138
parents: 6574
diff changeset
   821
	w->widget_count += num_active;
0c6bff37a6e8 (svn r9079) -Codechange: add WWT_LAST widget when dynamically building cargo payment graph
peter1138
parents: 6574
diff changeset
   822
	w->widget = ReallocT(w->widget, w->widget_count + 1);
0c6bff37a6e8 (svn r9079) -Codechange: add WWT_LAST widget when dynamically building cargo payment graph
peter1138
parents: 6574
diff changeset
   823
	w->widget[w->widget_count].type = WWT_LAST;
6518
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   824
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   825
	/* Set the properties of each widget */
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   826
	for (uint i = 0; i != num_active; i++) {
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   827
		Widget *wi = &w->widget[3 + i];
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   828
		wi->type     = WWT_PANEL;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   829
		wi->display_flags = RESIZE_NONE;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   830
		wi->color    = 12;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   831
		wi->left     = 493;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   832
		wi->right    = 562;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   833
		wi->top      = 24 + i * 8;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   834
		wi->bottom   = wi->top + 7;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   835
		wi->data     = 0;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   836
		wi->tooltips = STR_7064_TOGGLE_GRAPH_FOR_CARGO;
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   837
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   838
		if (!HasBit(_legend_excluded_cargo, i)) w->LowerWidget(i + 3);
6518
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   839
	}
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   840
c7ac357020e3 (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6505
diff changeset
   841
	SetWindowDirty(w);
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   842
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   843
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   844
/************************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   845
/* COMPANY LEAGUE TABLE */
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   846
/************************/
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   847
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   848
static const StringID _performance_titles[] = {
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   849
	STR_7066_ENGINEER,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   850
	STR_7066_ENGINEER,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   851
	STR_7067_TRAFFIC_MANAGER,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   852
	STR_7067_TRAFFIC_MANAGER,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   853
	STR_7068_TRANSPORT_COORDINATOR,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   854
	STR_7068_TRANSPORT_COORDINATOR,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   855
	STR_7069_ROUTE_SUPERVISOR,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   856
	STR_7069_ROUTE_SUPERVISOR,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   857
	STR_706A_DIRECTOR,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   858
	STR_706A_DIRECTOR,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   859
	STR_706B_CHIEF_EXECUTIVE,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   860
	STR_706B_CHIEF_EXECUTIVE,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   861
	STR_706C_CHAIRMAN,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   862
	STR_706C_CHAIRMAN,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   863
	STR_706D_PRESIDENT,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   864
	STR_706E_TYCOON,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   865
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   866
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   867
static inline StringID GetPerformanceTitleFromValue(uint value)
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   868
{
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   869
	return _performance_titles[minu(value, 1000) >> 6];
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   870
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   871
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   872
static int CDECL PerfHistComp(const void* elem1, const void* elem2)
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   873
{
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   874
	const Player* p1 = *(const Player* const*)elem1;
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   875
	const Player* p2 = *(const Player* const*)elem2;
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   876
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   877
	return p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   878
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   879
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   880
static void CompanyLeagueWndProc(Window *w, WindowEvent *e)
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   881
{
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2475
diff changeset
   882
	switch (e->event) {
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   883
		case WE_PAINT: {
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   884
			const Player* plist[MAX_PLAYERS];
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   885
			const Player* p;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   886
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   887
			DrawWindowWidgets(w);
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   888
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   889
			uint pl_num = 0;
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   890
			FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p;
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   891
2673
1c1e8cb73c67 (svn r3215) - Fix: warning on VS.NET 2003 complaining about constness reintroduced by revision 3192
Darkvater
parents: 2656
diff changeset
   892
			qsort((void*)plist, pl_num, sizeof(*plist), PerfHistComp);
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   893
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   894
			for (uint i = 0; i != pl_num; i++) {
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   895
				p = plist[i];
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   896
				SetDParam(0, i + STR_01AC_1ST);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   897
				SetDParam(1, p->index);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   898
				SetDParam(2, p->index);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   899
				SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   900
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   901
				DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING);
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   902
				DrawPlayerIcon(p->index, 27, 16 + i * 10);
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   903
			}
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   904
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   905
			break;
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   906
		}
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   907
	}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   908
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   909
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   910
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   911
static const Widget _company_league_widgets[] = {
2869
5cf9acd29edd (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   912
{   WWT_CLOSEBOX, RESIZE_NONE, 14,   0,  10,  0, 13, STR_00C5,                      STR_018B_CLOSE_WINDOW},
5cf9acd29edd (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   913
{    WWT_CAPTION, RESIZE_NONE, 14,  11, 387,  0, 13, STR_7053_COMPANY_LEAGUE_TABLE, STR_018C_WINDOW_TITLE_DRAG_THIS},
5cf9acd29edd (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   914
{  WWT_STICKYBOX, RESIZE_NONE, 14, 388, 399,  0, 13, STR_NULL,                      STR_STICKY_BUTTON},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   915
{      WWT_PANEL, RESIZE_NONE, 14,   0, 399, 14, 96, 0x0,                           STR_NULL},
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   916
{   WIDGETS_END},
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   917
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   918
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   919
static const WindowDesc _company_league_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   920
	WDP_AUTO, WDP_AUTO, 400, 97, 400, 97,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   921
	WC_COMPANY_LEAGUE, WC_NONE,
2869
5cf9acd29edd (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   922
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   923
	_company_league_widgets,
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   924
	CompanyLeagueWndProc
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   925
};
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   926
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   927
void ShowCompanyLeagueTable()
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   928
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6698
diff changeset
   929
	AllocateWindowDescFront(&_company_league_desc, 0);
1086
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   930
}
9d00ef71146e (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   931
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   932
/*****************************/
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   933
/* PERFORMANCE RATING DETAIL */
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   934
/*****************************/
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   935
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   936
static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   937
{
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   938
	static PlayerID _performance_rating_detail_player = INVALID_PLAYER;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   939
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   940
	switch (e->event) {
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   941
		case WE_PAINT: {
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   942
			byte x;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
   943
			uint16 y = 14;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   944
			int total_score = 0;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   945
			int color_done, color_notdone;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   946
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   947
			/* Draw standard stuff */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   948
			DrawWindowWidgets(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   949
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   950
			/* Check if the currently selected player is still active. */
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   951
			if (_performance_rating_detail_player == INVALID_PLAYER || !GetPlayer(_performance_rating_detail_player)->is_active) {
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   952
				if (_performance_rating_detail_player != INVALID_PLAYER) {
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   953
					/* Raise and disable the widget for the previous selection. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   954
					w->RaiseWidget(_performance_rating_detail_player + 13);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   955
					w->DisableWidget(_performance_rating_detail_player + 13);
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   956
					SetWindowDirty(w);
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   957
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   958
					_performance_rating_detail_player = INVALID_PLAYER;
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   959
				}
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   960
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   961
				for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   962
					if (GetPlayer(i)->is_active) {
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   963
						/* Lower the widget corresponding to this player. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   964
						w->LowerWidget(i + 13);
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   965
						SetWindowDirty(w);
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   966
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   967
						_performance_rating_detail_player = i;
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   968
						break;
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   969
					}
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   970
				}
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   971
			}
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   972
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   973
			/* If there are no active players, don't display anything else. */
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   974
			if (_performance_rating_detail_player == INVALID_PLAYER) break;
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   975
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   976
			/* Paint the player icons */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   977
			for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   978
				if (!GetPlayer(i)->is_active) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   979
					/* Check if we have the player as an active player */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   980
					if (!w->IsWidgetDisabled(i + 13)) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   981
						/* Bah, player gone :( */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   982
						w->DisableWidget(i + 13);
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   983
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   984
						/* We need a repaint */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   985
						SetWindowDirty(w);
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   986
					}
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   987
					continue;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   988
				}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   989
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   990
				/* Check if we have the player marked as inactive */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   991
				if (w->IsWidgetDisabled(i + 13)) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   992
					/* New player! Yippie :p */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   993
					w->EnableWidget(i + 13);
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
   994
					/* We need a repaint */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   995
					SetWindowDirty(w);
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   996
				}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   997
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   998
				x = (i == _performance_rating_detail_player) ? 1 : 0;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   999
				DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1000
			}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1001
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1002
			/* The colors used to show how the progress is going */
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4365
diff changeset
  1003
			color_done = _colour_gradient[COLOUR_GREEN][4];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4365
diff changeset
  1004
			color_notdone = _colour_gradient[COLOUR_RED][4];
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1005
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1006
			/* Draw all the score parts */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1007
			for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
  1008
				int val    = _score_part[_performance_rating_detail_player][i];
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1009
				int needed = _score_info[i].needed;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1010
				int score  = _score_info[i].score;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1011
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1012
				y += 20;
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1013
				/* SCORE_TOTAL has his own rulez ;) */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1014
				if (i == SCORE_TOTAL) {
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1015
					needed = total_score;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1016
					score = SCORE_MAX;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1017
				} else {
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1018
					total_score += score;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1019
				}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1020
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1021
				DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, TC_FROMSTRING);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1022
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1023
				/* Draw the score */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1024
				SetDParam(0, score);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1025
				DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, TC_FROMSTRING);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1026
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1027
				/* Calculate the %-bar */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1028
				x = Clamp(val, 0, needed) * 50 / needed;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1029
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1030
				/* SCORE_LOAN is inversed */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1031
				if (val < 0 && i == SCORE_LOAN) x = 0;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1032
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1033
				/* Draw the bar */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1034
				if (x !=  0) GfxFillRect(112,     y - 2, 112 + x,  y + 10, color_done);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1035
				if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1036
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1037
				/* Calculate the % */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1038
				x = Clamp(val, 0, needed) * 100 / needed;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1039
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1040
				/* SCORE_LOAN is inversed */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1041
				if (val < 0 && i == SCORE_LOAN) x = 0;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1042
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1043
				/* Draw it */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1044
				SetDParam(0, x);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1045
				DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1046
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1047
				/* SCORE_LOAN is inversed */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1048
				if (i == SCORE_LOAN) val = needed - val;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1049
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1050
				/* Draw the amount we have against what is needed
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1051
				 * For some of them it is in currency format */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1052
				SetDParam(0, val);
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1053
				SetDParam(1, needed);
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1054
				switch (i) {
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1055
					case SCORE_MIN_PROFIT:
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1056
					case SCORE_MIN_INCOME:
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1057
					case SCORE_MAX_INCOME:
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1058
					case SCORE_MONEY:
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1059
					case SCORE_LOAN:
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1060
						DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, TC_FROMSTRING);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1061
						break;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1062
					default:
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1063
						DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_INT, TC_FROMSTRING);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1064
				}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1065
			}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1066
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1067
			break;
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1068
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1069
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1070
		case WE_CLICK:
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1071
			/* Check which button is clicked */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1072
			if (IsInsideMM(e->we.click.widget, 13, 21)) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1073
				/* Is it no on disable? */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1074
				if (!w->IsWidgetDisabled(e->we.click.widget)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1075
					w->RaiseWidget(_performance_rating_detail_player + 13);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1076
					_performance_rating_detail_player = (PlayerID)(e->we.click.widget - 13);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1077
					w->LowerWidget(_performance_rating_detail_player + 13);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1078
					SetWindowDirty(w);
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1079
				}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1080
			}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1081
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1082
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1083
		case WE_CREATE: {
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1084
			Player *p2;
4702
5179f9adc5b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4634
diff changeset
  1085
4709
eff35edfb653 (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1086
			/* Disable the players who are not active */
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
  1087
			for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1088
				w->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1089
			}
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
  1090
			/* Update all player stats with the current data
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
  1091
			 * (this is because _score_info is not saved to a savegame) */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1092
			FOR_ALL_PLAYERS(p2) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1093
				if (p2->is_active) UpdateCompanyRatingAndValue(p2, false);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1094
			}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1095
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1096
			w->custom[0] = DAY_TICKS;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1097
			w->custom[1] = 5;
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1098
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1099
			if (_performance_rating_detail_player != INVALID_PLAYER) w->LowerWidget(_performance_rating_detail_player + 13);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1100
			SetWindowDirty(w);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1101
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1102
			break;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1103
		}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1104
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
  1105
		case WE_TICK:
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1106
			/* Update the player score every 5 days */
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1107
			if (--w->custom[0] == 0) {
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1108
				w->custom[0] = DAY_TICKS;
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1109
				if (--w->custom[1] == 0) {
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1110
					Player *p2;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1111
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1112
					w->custom[1] = 5;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1113
					FOR_ALL_PLAYERS(p2) {
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6417
diff changeset
  1114
						/* Skip if player is not active */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1115
						if (p2->is_active) UpdateCompanyRatingAndValue(p2, false);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1116
					}
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1117
					SetWindowDirty(w);
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1118
				}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1119
			}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1120
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1121
			break;
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1122
	}
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1123
}
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1124
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1125
static const Widget _performance_rating_detail_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
  1126
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
  1127
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   298,     0,    13, STR_PERFORMANCE_DETAIL, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1128
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    14,    27, 0x0,                    STR_NULL},
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1129
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1130
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    28,    47, 0x0,                    STR_PERFORMANCE_DETAIL_VEHICLES_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1131
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    48,    67, 0x0,                    STR_PERFORMANCE_DETAIL_STATIONS_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1132
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    68,    87, 0x0,                    STR_PERFORMANCE_DETAIL_MIN_PROFIT_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1133
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    88,   107, 0x0,                    STR_PERFORMANCE_DETAIL_MIN_INCOME_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1134
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   108,   127, 0x0,                    STR_PERFORMANCE_DETAIL_MAX_INCOME_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1135
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   128,   147, 0x0,                    STR_PERFORMANCE_DETAIL_DELIVERED_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1136
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   148,   167, 0x0,                    STR_PERFORMANCE_DETAIL_CARGO_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1137
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   168,   187, 0x0,                    STR_PERFORMANCE_DETAIL_MONEY_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1138
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   188,   207, 0x0,                    STR_PERFORMANCE_DETAIL_LOAN_TIP},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1139
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   208,   227, 0x0,                    STR_PERFORMANCE_DETAIL_TOTAL_TIP},
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1140
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1141
{      WWT_PANEL,   RESIZE_NONE,    14,     2,    38,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1142
{      WWT_PANEL,   RESIZE_NONE,    14,    39,    75,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1143
{      WWT_PANEL,   RESIZE_NONE,    14,    76,   112,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1144
{      WWT_PANEL,   RESIZE_NONE,    14,   113,   149,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1145
{      WWT_PANEL,   RESIZE_NONE,    14,   150,   186,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1146
{      WWT_PANEL,   RESIZE_NONE,    14,   187,   223,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1147
{      WWT_PANEL,   RESIZE_NONE,    14,   224,   260,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1148
{      WWT_PANEL,   RESIZE_NONE,    14,   261,   297,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
  1149
{   WIDGETS_END},
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1150
};
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1151
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1152
static const WindowDesc _performance_rating_detail_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
  1153
	WDP_AUTO, WDP_AUTO, 299, 228, 299, 228,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
  1154
	WC_PERFORMANCE_DETAIL, WC_NONE,
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1155
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1156
	_performance_rating_detail_widgets,
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1157
	PerformanceRatingDetailWndProc
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1158
};
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1159
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
  1160
void ShowPerformanceRatingDetail()
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1161
{
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1162
	AllocateWindowDescFront(&_performance_rating_detail_desc, 0);
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1163
}