src/graph_gui.cpp
author richk
Tue, 17 Jun 2008 13:22:13 +0000
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10731 67db0d431d5e
permissions -rw-r--r--
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
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
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
     3
/** @file graph_gui.cpp GUI that shows performance graphs. */
6505
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"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "gui.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
     8
#include "window_gui.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
     9
#include "player_base.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    10
#include "player_gui.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    11
#include "economy_func.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2135
diff changeset
    12
#include "variables.h"
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
    13
#include "cargotype.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    14
#include "strings_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    15
#include "core/alloc_func.hpp"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    16
#include "window_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    17
#include "date_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    18
#include "gfx_func.h"
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
    19
#include "sortlist_type.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    20
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    21
#include "table/strings.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    22
#include "table/sprites.h"
5291
5e4d9ab3cc0f (svn r7444) -Codechange: Use one (global) cargo-colours array for drawing cargo-colours. Change Food
Darkvater
parents: 5247
diff changeset
    23
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
    24
/* 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
    25
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
    26
static uint _legend_excluded_cargo;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
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
    28
/* Apparently these don't play well with enums. */
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
    29
static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn.
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    30
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
    31
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
/* GRAPH LEGEND */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    36
struct GraphLegendWindow : Window {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    37
	GraphLegendWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    38
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    39
		for (uint i = 3; i < this->widget_count; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    40
			if (!HasBit(_legend_excluded_players, i - 3)) this->LowerWidget(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    43
		this->FindWindowPlacementAndResize(desc);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    44
	}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
    45
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    46
	virtual void OnPaint()
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    47
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    48
		const Player *p;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    49
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    50
		FOR_ALL_PLAYERS(p) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    51
			if (p->is_active) continue;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    52
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    53
			SetBit(_legend_excluded_players, p->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    54
			this->RaiseWidget(p->index + 3);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    55
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    56
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    57
		this->DrawWidgets();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    58
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    59
		FOR_ALL_PLAYERS(p) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    60
			if (!p->is_active) continue;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    61
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    62
			DrawPlayerIcon(p->index, 4, 18 + p->index * 12);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    63
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    64
			SetDParam(0, p->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    65
			SetDParam(1, p->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    66
			DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    67
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    69
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    70
	virtual void OnClick(Point pt, int widget)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    71
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    72
		if (!IsInsideMM(widget, 3, 11)) return;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    73
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    74
		ToggleBit(_legend_excluded_players, widget - 3);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    75
		this->ToggleWidgetLoweredState(widget);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    76
		this->SetDirty();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    77
		InvalidateWindow(WC_INCOME_GRAPH, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    78
		InvalidateWindow(WC_OPERATING_PROFIT, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    79
		InvalidateWindow(WC_DELIVERED_CARGO, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    80
		InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    81
		InvalidateWindow(WC_COMPANY_VALUE, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    82
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    83
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
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
    86
{   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
    87
{    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
    88
{      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
    89
{      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
    90
{      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
    91
{      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
    92
{      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
    93
{      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
    94
{      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
    95
{      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
    96
{      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
    97
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
static const WindowDesc _graph_legend_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   101
	WDP_AUTO, WDP_AUTO, 250, 114, 250, 114,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   102
	WC_GRAPH_LEGEND, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	_graph_legend_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   107
static void ShowGraphLegend()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   109
	AllocateWindowDescFront<GraphLegendWindow>(&_graph_legend_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   112
/******************/
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   113
/* BASE OF GRAPHS */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   114
/*****************/
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   115
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   116
struct BaseGraphWindow : Window {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   117
protected:
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   118
	enum {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   119
		GRAPH_MAX_DATASETS = 32,
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   120
		GRAPH_AXIS_LABEL_COLOUR = TC_BLACK,
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   121
		GRAPH_AXIS_LINE_COLOUR  = 215,
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   122
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   123
		GRAPH_X_POSITION_BEGINNING  = 44,  ///< Start the graph 44 pixels from gd_left
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   124
		GRAPH_X_POSITION_SEPARATION = 22,  ///< There are 22 pixels between each X value
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   125
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   126
		GRAPH_NUM_LINES_Y = 9, ///< How many horizontal lines to draw.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   127
		/* 9 is convenient as that means the distance between them is the gd_height of the graph / 8,
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   128
		* which is the same
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   129
		* as height >> 3. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   130
	};
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   131
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   132
	uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   133
	byte num_dataset;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   134
	byte num_on_x_axis;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   135
	bool has_negative_values;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   136
	byte num_vert_lines;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   137
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   138
	/* The starting month and year that values are plotted against. If month is
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   139
	 * 0xFF, use x_values_start and x_values_increment below instead. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   140
	byte month;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   141
	Year year;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   142
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   143
	/* These values are used if the graph is being plotted against values
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   144
	 * rather than the dates specified by month and year. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   145
	uint16 x_values_start;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   146
	uint16 x_values_increment;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   147
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   148
	int gd_left, gd_top;  ///< Where to start drawing the graph, in pixels.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   149
	uint gd_height;    ///< The height of the graph in pixels.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   150
	StringID format_str_y_axis;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   151
	byte colors[GRAPH_MAX_DATASETS];
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   152
	OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   153
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   154
	void DrawGraph() const
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   155
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   156
		uint x, y;                       ///< Reused whenever x and y coordinates are needed.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   157
		OverflowSafeInt64 highest_value; ///< Highest value to be drawn.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   158
		int x_axis_offset;               ///< Distance from the top of the graph to the x axis.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   159
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   160
		/* the colors and cost array of GraphDrawer must accomodate
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   161
		* both values for cargo and players. So if any are higher, quit */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   162
		assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   163
		assert(this->num_vert_lines > 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   164
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   165
		byte grid_colour = _colour_gradient[14][4];
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   166
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   167
		/* The coordinates of the opposite edges of the graph. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   168
		int bottom = this->gd_top + this->gd_height - 1;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   169
		int right  = this->gd_left + GRAPH_X_POSITION_BEGINNING + this->num_vert_lines * GRAPH_X_POSITION_SEPARATION - 1;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   170
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   171
		/* Draw the vertical grid lines. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   172
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   173
		/* Don't draw the first line, as that's where the axis will be. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   174
		x = this->gd_left + GRAPH_X_POSITION_BEGINNING + GRAPH_X_POSITION_SEPARATION;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   175
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   176
		for (int i = 0; i < this->num_vert_lines; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   177
			GfxFillRect(x, this->gd_top, x, bottom, grid_colour);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   178
			x += GRAPH_X_POSITION_SEPARATION;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   179
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   180
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   181
		/* Draw the horizontal grid lines. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   182
		x = this->gd_left + GRAPH_X_POSITION_BEGINNING;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   183
		y = this->gd_height + this->gd_top;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   184
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   185
		for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   186
			GfxFillRect(x, y, right, y, grid_colour);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   187
			y -= (this->gd_height / (GRAPH_NUM_LINES_Y - 1));
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   188
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   189
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   190
		/* Draw the y axis. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   191
		GfxFillRect(x, this->gd_top, x, bottom, GRAPH_AXIS_LINE_COLOUR);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   192
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   193
		/* Find the distance from the gd_top of the graph to the x axis. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   194
		x_axis_offset = this->gd_height;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   195
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   196
		/* The graph is currently symmetrical about the x axis. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   197
		if (this->has_negative_values) x_axis_offset /= 2;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   198
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   199
		/* Draw the x axis. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   200
		y = x_axis_offset + this->gd_top;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   201
		GfxFillRect(x, y, right, y, GRAPH_AXIS_LINE_COLOUR);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   202
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   203
		/* Find the largest value that will be drawn. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   204
		if (this->num_on_x_axis == 0)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   205
			return;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   206
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   207
		assert(this->num_on_x_axis > 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   208
		assert(this->num_dataset > 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   209
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   210
		/* Start of with a value of twice the gd_height of the graph in pixels. It's a
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   211
		* bit arbitrary, but it makes the cargo payment graph look a little nicer,
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   212
		* and prevents division by zero when calculating where the datapoint
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   213
		* should be drawn. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   214
		highest_value = x_axis_offset * 2;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   215
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   216
		for (int i = 0; i < this->num_dataset; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   217
			if (!HasBit(this->excluded_data, i)) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   218
				for (int j = 0; j < this->num_on_x_axis; j++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   219
					OverflowSafeInt64 datapoint = this->cost[i][j];
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   220
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   221
					if (datapoint != INVALID_DATAPOINT) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   222
						/* For now, if the graph has negative values the scaling is
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   223
						* symmetrical about the x axis, so take the absolute value
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   224
						* of each data point. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   225
						highest_value = max(highest_value, abs(datapoint));
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   226
					}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   227
				}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   228
			}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   229
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   230
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   231
		/* Round up highest_value so that it will divide cleanly into the number of
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   232
		* axis labels used. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   233
		int round_val = highest_value % (GRAPH_NUM_LINES_Y - 1);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   234
		if (round_val != 0) highest_value += (GRAPH_NUM_LINES_Y - 1 - round_val);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   235
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   236
		/* draw text strings on the y axis */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   237
		int64 y_label = highest_value;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   238
		int64 y_label_separation = highest_value / (GRAPH_NUM_LINES_Y - 1);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   239
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   240
		/* If there are negative values, the graph goes from highest_value to
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   241
		* -highest_value, not highest_value to 0. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   242
		if (this->has_negative_values) y_label_separation *= 2;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   243
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   244
		x = this->gd_left + GRAPH_X_POSITION_BEGINNING + 1;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   245
		y = this->gd_top - 3;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   246
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   247
		for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   248
			SetDParam(0, this->format_str_y_axis);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   249
			SetDParam(1, y_label);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   250
			DrawStringRightAligned(x, y, STR_0170, GRAPH_AXIS_LABEL_COLOUR);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   251
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   252
			y_label -= y_label_separation;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   253
			y += (this->gd_height / (GRAPH_NUM_LINES_Y - 1));
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   254
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   255
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   256
		/* draw strings on the x axis */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   257
		if (this->month != 0xFF) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   258
			x = this->gd_left + GRAPH_X_POSITION_BEGINNING;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   259
			y = this->gd_top + this->gd_height + 1;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   260
			byte month = this->month;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   261
			Year year  = this->year;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   262
			for (int i = 0; i < this->num_on_x_axis; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   263
				SetDParam(0, month + STR_0162_JAN);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   264
				SetDParam(1, month + STR_0162_JAN + 2);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   265
				SetDParam(2, year);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   266
				DrawString(x, y, month == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   267
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   268
				month += 3;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   269
				if (month >= 12) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   270
					month = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   271
					year++;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   272
				}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   273
				x += GRAPH_X_POSITION_SEPARATION;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   274
			}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   275
		} else {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   276
			/* Draw the label under the data point rather than on the grid line. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   277
			x = this->gd_left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2) + 1;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   278
			y = this->gd_top + this->gd_height + 1;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   279
			uint16 label = this->x_values_start;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   280
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   281
			for (int i = 0; i < this->num_on_x_axis; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   282
				SetDParam(0, label);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   283
				DrawStringCentered(x, y, STR_01CB, GRAPH_AXIS_LABEL_COLOUR);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   284
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   285
				label += this->x_values_increment;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   286
				x += GRAPH_X_POSITION_SEPARATION;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   287
			}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   288
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   289
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   290
		/* draw lines and dots */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   291
		for (int i = 0; i < this->num_dataset; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   292
			if (!HasBit(this->excluded_data, i)) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   293
				/* Centre the dot between the grid lines. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   294
				x = this->gd_left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   295
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   296
				byte color  = this->colors[i];
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   297
				uint prev_x = INVALID_DATAPOINT_POS;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   298
				uint prev_y = INVALID_DATAPOINT_POS;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   299
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   300
				for (int j = 0; j < this->num_on_x_axis; j++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   301
					OverflowSafeInt64 datapoint = this->cost[i][j];
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   302
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   303
					if (datapoint != INVALID_DATAPOINT) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   304
						/*
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   305
						* Check whether we need to reduce the 'accuracy' of the
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   306
						* datapoint value and the highest value to splut overflows.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   307
						* And when 'drawing' 'one million' or 'one million and one'
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   308
						* there is no significant difference, so the least
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   309
						* significant bits can just be removed.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   310
						*
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   311
						* If there are more bits needed than would fit in a 32 bits
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   312
						* integer, so at about 31 bits because of the sign bit, the
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   313
						* least significant bits are removed.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   314
						*/
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   315
						int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint));
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   316
						int reduce_range = max(mult_range - 31, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   317
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   318
						/* Handle negative values differently (don't shift sign) */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   319
						if (datapoint < 0) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   320
							datapoint = -(abs(datapoint) >> reduce_range);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   321
						} else {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   322
							datapoint >>= reduce_range;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   323
						}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   324
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   325
						y = this->gd_top + x_axis_offset - (x_axis_offset * datapoint) / (highest_value >> reduce_range);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   326
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   327
						/* Draw the point. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   328
						GfxFillRect(x - 1, y - 1, x + 1, y + 1, color);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   329
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   330
						/* Draw the line connected to the previous point. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   331
						if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, color);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   332
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   333
						prev_x = x;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   334
						prev_y = y;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   335
					} else {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   336
						prev_x = INVALID_DATAPOINT_POS;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   337
						prev_y = INVALID_DATAPOINT_POS;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   338
					}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   339
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   340
					x += GRAPH_X_POSITION_SEPARATION;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   341
				}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   342
			}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   343
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   344
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   345
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   346
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   347
	BaseGraphWindow(const WindowDesc *desc, WindowNumber window_number, int left,
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   348
									int top, int height, bool has_negative_values, StringID format_str_y_axis) :
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   349
			Window(desc, window_number), has_negative_values(has_negative_values),
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   350
			gd_left(left), gd_top(top), gd_height(height), format_str_y_axis(format_str_y_axis)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   351
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   352
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   353
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   354
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   355
public:
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   356
	virtual void OnPaint()
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   357
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   358
		this->DrawWidgets();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   359
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   360
		uint excluded_players = _legend_excluded_players;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   361
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   362
		/* Exclude the players which aren't valid */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   363
		const Player* p;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   364
		FOR_ALL_PLAYERS(p) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   365
			if (!p->is_active) SetBit(excluded_players, p->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   366
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   367
		this->excluded_data = excluded_players;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   368
		this->num_vert_lines = 24;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   369
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   370
		byte nums = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   371
		FOR_ALL_PLAYERS(p) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   372
			if (p->is_active) nums = max(nums, p->num_valid_stat_ent);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   373
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   374
		this->num_on_x_axis = min(nums, 24);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   375
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   376
		int mo = (_cur_month / 3 - nums) * 3;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   377
		int yr = _cur_year;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   378
		while (mo < 0) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   379
			yr--;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   380
			mo += 12;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   381
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   382
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   383
		this->year = yr;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   384
		this->month = mo;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   385
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   386
		int numd = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   387
		FOR_ALL_PLAYERS(p) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   388
			if (p->is_active) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   389
				this->colors[numd] = _colour_gradient[p->player_color][6];
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   390
				for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   391
					this->cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(p, j);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   392
					i++;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   393
				}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   394
			}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   395
			numd++;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   396
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   397
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   398
		this->num_dataset = numd;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   399
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   400
		this->DrawGraph();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   401
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   402
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   403
	virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   404
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   405
		return INVALID_DATAPOINT;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   406
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   407
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   408
	virtual void OnClick(Point pt, int widget)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   409
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   410
		/* Clicked on legend? */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   411
		if (widget == 2) ShowGraphLegend();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   412
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   413
};
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   414
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
/********************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
/* OPERATING PROFIT */
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
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   419
struct OperatingProfitGraphWindow : BaseGraphWindow {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   420
	OperatingProfitGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   421
			BaseGraphWindow(desc, window_number, 2, 18, 136, true, STR_CURRCOMPACT)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   422
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   423
		this->FindWindowPlacementAndResize(desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   426
	virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   427
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   428
		return p->old_economy[j].income + p->old_economy[j].expenses;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   430
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
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
   433
{   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
   434
{    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
   435
{ 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
   436
{      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
   437
{   WIDGETS_END},
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
static const WindowDesc _operating_profit_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   441
	WDP_AUTO, WDP_AUTO, 576, 174, 576, 174,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   442
	WC_OPERATING_PROFIT, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	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
   444
	_operating_profit_widgets,
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   448
void ShowOperatingProfitGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   450
	AllocateWindowDescFront<OperatingProfitGraphWindow>(&_operating_profit_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
/* INCOME GRAPH */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   458
struct IncomeGraphWindow : BaseGraphWindow {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   459
	IncomeGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   460
			BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_CURRCOMPACT)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   461
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   462
		this->FindWindowPlacementAndResize(desc);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   463
	}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   464
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   465
	virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   466
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   467
		return p->old_economy[j].income;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   469
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
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
   472
{   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
   473
{    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
   474
{ 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
   475
{      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
   476
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
static const WindowDesc _income_graph_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   480
	WDP_AUTO, WDP_AUTO, 576, 142, 576, 142,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   481
	WC_INCOME_GRAPH, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	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
   483
	_income_graph_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   486
void ShowIncomeGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   488
	AllocateWindowDescFront<IncomeGraphWindow>(&_income_graph_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
/*******************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
/* DELIVERED CARGO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
/*******************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   495
struct DeliveredCargoGraphWindow : BaseGraphWindow {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   496
	DeliveredCargoGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   497
			BaseGraphWindow(desc, window_number, 2, 18, 104, false, STR_7024)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   498
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   499
		this->FindWindowPlacementAndResize(desc);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   500
	}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   501
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   502
	virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   503
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   504
		return p->old_economy[j].delivered_cargo;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   506
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
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
   509
{   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
   510
{    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
   511
{ 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
   512
{      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
   513
{   WIDGETS_END},
0
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 const WindowDesc _delivered_cargo_graph_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   517
	WDP_AUTO, WDP_AUTO, 576, 142, 576, 142,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   518
	WC_DELIVERED_CARGO, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	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
   520
	_delivered_cargo_graph_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   523
void ShowDeliveredCargoGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   525
	AllocateWindowDescFront<DeliveredCargoGraphWindow>(&_delivered_cargo_graph_desc, 0);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   526
}
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   527
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
   528
/***********************/
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
   529
/* 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
   530
/***********************/
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
   531
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   532
struct PerformanceHistoryGraphWindow : BaseGraphWindow {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   533
	PerformanceHistoryGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   534
			BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_7024)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   535
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   536
		this->FindWindowPlacementAndResize(desc);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   537
	}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   538
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   539
	virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   540
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   541
		return p->old_economy[j].performance_history;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   542
	}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   543
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   544
	virtual void OnClick(Point pt, int widget)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   545
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   546
		if (widget == 3) ShowPerformanceRatingDetail();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   547
		this->BaseGraphWindow::OnClick(pt, widget);
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
   548
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   549
};
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
   550
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
   551
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
   552
{   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
   553
{    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
   554
{ 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
   555
{ 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
   556
{      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
   557
{   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
   558
};
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
   559
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
   560
static const WindowDesc _performance_history_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   561
	WDP_AUTO, WDP_AUTO, 576, 238, 576, 238,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   562
	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
   563
	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
   564
	_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
   565
};
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
   566
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   567
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
   568
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   569
	AllocateWindowDescFront<PerformanceHistoryGraphWindow>(&_performance_history_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
   570
}
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
   571
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
   572
/*****************/
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
   573
/* 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
   574
/*****************/
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
   575
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   576
struct CompanyValueGraphWindow : BaseGraphWindow {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   577
	CompanyValueGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   578
			BaseGraphWindow(desc, window_number, 2, 18, 200, false, STR_CURRCOMPACT)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   579
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   580
		this->FindWindowPlacementAndResize(desc);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   581
	}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   582
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   583
	virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   584
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   585
		return p->old_economy[j].company_value;
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
   586
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   587
};
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
   588
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
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
   590
{   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
   591
{    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
   592
{ 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
   593
{      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
   594
{   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
   595
};
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
   596
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
   597
static const WindowDesc _company_value_graph_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   598
	WDP_AUTO, WDP_AUTO, 576, 238, 576, 238,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   599
	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
   600
	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
   601
	_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
   602
};
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
   603
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   604
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
   605
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   606
	AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_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
   607
}
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
   608
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
/*****************/
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
   610
/* 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
   611
/*****************/
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
   612
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   613
struct PaymentRatesGraphWindow : BaseGraphWindow {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   614
	PaymentRatesGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   615
			BaseGraphWindow(desc, window_number, 2, 24, 200, false, STR_CURRCOMPACT)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   616
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   617
		uint num_active = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   618
		for (CargoID c = 0; c < NUM_CARGO; c++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   619
			if (GetCargo(c)->IsValid()) num_active++;
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
   620
		}
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   621
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   622
		/* Resize the window to fit the cargo types */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   623
		ResizeWindow(this, 0, max(num_active, 12U) * 8);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   624
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   625
		/* Add widgets for each cargo type */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   626
		this->widget_count += num_active;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   627
		this->widget = ReallocT(this->widget, this->widget_count + 1);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   628
		this->widget[this->widget_count].type = WWT_LAST;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   629
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   630
		/* Set the properties of each widget */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   631
		for (uint i = 0; i != num_active; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   632
			Widget *wi = &this->widget[3 + i];
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   633
			wi->type     = WWT_PANEL;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   634
			wi->display_flags = RESIZE_NONE;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   635
			wi->color    = 12;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   636
			wi->left     = 493;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   637
			wi->right    = 562;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   638
			wi->top      = 24 + i * 8;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   639
			wi->bottom   = wi->top + 7;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   640
			wi->data     = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   641
			wi->tooltips = STR_7064_TOGGLE_GRAPH_FOR_CARGO;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   642
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   643
			if (!HasBit(_legend_excluded_cargo, i)) this->LowerWidget(i + 3);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   644
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   645
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   646
		this->SetDirty();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   647
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   648
		this->gd_height = this->height - 38;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   649
		this->num_on_x_axis = 20;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   650
		this->num_vert_lines = 20;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   651
		this->month = 0xFF;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   652
		this->x_values_start     = 10;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   653
		this->x_values_increment = 10;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   654
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   655
		this->FindWindowPlacementAndResize(desc);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   656
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   657
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   658
	virtual void OnPaint()
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   659
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   660
		this->DrawWidgets();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   661
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   662
		this->excluded_data = _legend_excluded_cargo;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   663
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   664
		int x = 495;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   665
		int y = 24;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   666
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   667
		uint i = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   668
		for (CargoID c = 0; c < NUM_CARGO; c++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   669
			const CargoSpec *cs = GetCargo(c);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   670
			if (!cs->IsValid()) continue;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   671
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   672
			/* Only draw labels for widgets that exist. If the widget doesn't
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   673
				* exist then the local player has used the climate cheat or
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   674
				* changed the NewGRF configuration with this window open. */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   675
			if (i + 3 < this->widget_count) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   676
				/* Since the buttons have no text, no images,
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   677
					* both the text and the colored box have to be manually painted.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   678
					* clk_dif will move one pixel down and one pixel to the right
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   679
					* when the button is clicked */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   680
				byte clk_dif = this->IsWidgetLowered(i + 3) ? 1 : 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   681
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   682
				GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   683
				GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   684
				SetDParam(0, cs->name);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   685
				DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, TC_FROMSTRING);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   686
				y += 8;
6529
c53737959606 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6518
diff changeset
   687
			}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   688
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   689
			this->colors[i] = cs->legend_colour;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   690
			for (uint j = 0; j != 20; j++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   691
				this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, c);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   692
			}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   693
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   694
			i++;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   695
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   696
		this->num_dataset = i;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   697
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   698
		this->DrawGraph();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   699
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   700
		DrawString(2 + 46, 24 + this->gd_height + 7, STR_7062_DAYS_IN_TRANSIT, TC_FROMSTRING);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   701
		DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, TC_FROMSTRING);
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
   702
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   703
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   704
	virtual void OnClick(Point pt, int widget)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   705
	{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   706
		if (widget >= 3) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   707
			ToggleBit(_legend_excluded_cargo, widget - 3);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   708
			this->ToggleWidgetLoweredState(widget);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   709
			this->SetDirty();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   710
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   711
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   712
};
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
   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
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
   715
{   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
   716
{    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
   717
{      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
   718
{   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
   719
};
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
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
   721
static const WindowDesc _cargo_payment_rates_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   722
	WDP_AUTO, WDP_AUTO, 568, 46, 568, 46,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   723
	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
   724
	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
   725
	_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
   726
};
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
   727
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
   728
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   729
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
   730
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   731
	AllocateWindowDescFront<PaymentRatesGraphWindow>(&_cargo_payment_rates_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
   732
}
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
   733
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
   734
/************************/
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
   735
/* 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
   736
/************************/
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
   737
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
   738
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
   739
	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
   740
	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
   741
	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
   742
	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
   743
	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
   744
	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
   745
	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
   746
	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
   747
	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
   748
	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
   749
	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
   750
	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
   751
	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
   752
	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
   753
	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
   754
	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
   755
};
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
   756
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
   757
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
   758
{
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
   759
	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
   760
}
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
   761
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   762
class CompanyLeagueWindow : public Window {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   763
private:
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   764
	GUIList<const Player*> players;
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   765
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   766
	/**
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   767
	 * (Re)Build the company league list
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   768
	 */
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   769
	void BuildPlayerList()
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   770
	{
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   771
		if (!this->players.NeedRebuild()) return;
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
   772
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   773
		this->players.Clear();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   774
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   775
		const Player *p;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   776
		FOR_ALL_PLAYERS(p) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   777
			if (p->is_active) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   778
				*this->players.Append() = p;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   779
			}
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   780
		}
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   781
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   782
		this->players.Compact();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   783
		this->players.RebuildDone();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   784
	}
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   785
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   786
	/** Sort the company league by performance history */
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   787
	static int CDECL PerformanceSorter(const Player* const *p1, const Player* const *p2)
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   788
	{
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   789
		return (*p2)->old_economy[1].performance_history - (*p1)->old_economy[1].performance_history;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   790
	}
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   791
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   792
public:
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   793
	CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   794
	{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   795
		this->players.ForceRebuild();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   796
		this->players.NeedResort();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   797
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   798
		this->FindWindowPlacementAndResize(desc);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   799
	}
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
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   801
	virtual void OnPaint()
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   802
	{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   803
		this->BuildPlayerList();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   804
		this->players.Sort(&PerformanceSorter);
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
   805
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   806
		this->DrawWidgets();
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   807
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   808
		for (uint i = 0; i != this->players.Length(); i++) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   809
			const Player *p = this->players[i];
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   810
			SetDParam(0, i + STR_01AC_1ST);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   811
			SetDParam(1, p->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   812
			SetDParam(2, p->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   813
			SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   814
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   815
			DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   816
			DrawPlayerIcon(p->index, 27, 16 + i * 10);
2656
796b75ba15e3 (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   817
		}
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
   818
	}
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   819
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   820
	virtual void OnTick()
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   821
	{
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   822
		if (this->players.NeedResort()) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   823
			this->SetDirty();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   824
		}
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   825
	}
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   826
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   827
	virtual void OnInvalidateData(int data)
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   828
	{
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   829
		if (data == 0) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   830
			this->players.ForceRebuild();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   831
		} else {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   832
			this->players.ForceResort();
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   833
		}
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10731
diff changeset
   834
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   835
};
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
   836
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
   837
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
   838
static const Widget _company_league_widgets[] = {
2869
5cf9acd29edd (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   839
{   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
   840
{    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
   841
{  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
   842
{      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
   843
{   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
   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
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
static const WindowDesc _company_league_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
   847
	WDP_AUTO, WDP_AUTO, 400, 97, 400, 97,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
   848
	WC_COMPANY_LEAGUE, WC_NONE,
2869
5cf9acd29edd (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   849
	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
   850
	_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
   851
};
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
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
   853
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
   854
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   855
	AllocateWindowDescFront<CompanyLeagueWindow>(&_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
   856
}
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
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   858
/*****************************/
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   859
/* PERFORMANCE RATING DETAIL */
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   860
/*****************************/
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   861
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   862
struct PerformanceRatingDetailWindow : Window {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   863
	static PlayerID player;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   864
	int timeout;
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   865
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   866
	PerformanceRatingDetailWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   867
	{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   868
		/* Disable the players who are not active */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   869
		for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   870
			this->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   871
		}
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   872
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   873
		this->UpdatePlayerStats();
6197
4ee36c52e467 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 6144
diff changeset
   874
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   875
		if (player != INVALID_PLAYER) this->LowerWidget(player + 13);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   876
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   877
		this->FindWindowPlacementAndResize(desc);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   878
	}
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   879
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   880
	void UpdatePlayerStats()
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   881
	{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   882
		/* Update all player stats with the current data
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   883
		 * (this is because _score_info is not saved to a savegame) */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   884
		Player *p;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   885
		FOR_ALL_PLAYERS(p) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   886
			if (p->is_active) UpdateCompanyRatingAndValue(p, false);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   887
		}
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   888
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   889
		this->timeout = DAY_TICKS * 5;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   890
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   891
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   892
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   893
	virtual void OnPaint()
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   894
	{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   895
		byte x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   896
		uint16 y = 14;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   897
		int total_score = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   898
		int color_done, color_notdone;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   899
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   900
		/* Draw standard stuff */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   901
		this->DrawWidgets();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   902
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   903
		/* Check if the currently selected player is still active. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   904
		if (player == INVALID_PLAYER || !GetPlayer(player)->is_active) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   905
			if (player != INVALID_PLAYER) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   906
				/* Raise and disable the widget for the previous selection. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   907
				this->RaiseWidget(player + 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   908
				this->DisableWidget(player + 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   909
				this->SetDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   910
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   911
				player = INVALID_PLAYER;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   912
			}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   913
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   914
			for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   915
				if (GetPlayer(i)->is_active) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   916
					/* Lower the widget corresponding to this player. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   917
					this->LowerWidget(i + 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   918
					this->SetDirty();
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   919
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   920
					player = i;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   921
					break;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   922
				}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   923
			}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   924
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   925
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   926
		/* If there are no active players, don't display anything else. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   927
		if (player == INVALID_PLAYER) return;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   928
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   929
		/* Paint the player icons */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   930
		for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   931
			if (!GetPlayer(i)->is_active) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   932
				/* Check if we have the player as an active player */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   933
				if (!this->IsWidgetDisabled(i + 13)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   934
					/* Bah, player gone :( */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   935
					this->DisableWidget(i + 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   936
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   937
					/* We need a repaint */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   938
					this->SetDirty();
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   939
				}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   940
				continue;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
   941
			}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   942
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   943
			/* Check if we have the player marked as inactive */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   944
			if (this->IsWidgetDisabled(i + 13)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   945
				/* New player! Yippie :p */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   946
				this->EnableWidget(i + 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   947
				/* We need a repaint */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   948
				this->SetDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   949
			}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   950
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   951
			x = (i == player) ? 1 : 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   952
			DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   953
		}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   954
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   955
		/* The colors used to show how the progress is going */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   956
		color_done = _colour_gradient[COLOUR_GREEN][4];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   957
		color_notdone = _colour_gradient[COLOUR_RED][4];
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   958
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   959
		/* Draw all the score parts */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   960
		for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   961
			int val    = _score_part[player][i];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   962
			int needed = _score_info[i].needed;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   963
			int score  = _score_info[i].score;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
   964
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   965
			y += 20;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   966
			/* SCORE_TOTAL has his own rulez ;) */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   967
			if (i == SCORE_TOTAL) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   968
				needed = total_score;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   969
				score = SCORE_MAX;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   970
			} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   971
				total_score += score;
3027
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   972
			}
43ffdf4d6a1f (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   973
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   974
			DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, TC_FROMSTRING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   975
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   976
			/* Draw the score */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   977
			SetDParam(0, score);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   978
			DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, TC_FROMSTRING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   979
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   980
			/* Calculate the %-bar */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   981
			x = Clamp(val, 0, needed) * 50 / needed;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   982
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   983
			/* SCORE_LOAN is inversed */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   984
			if (val < 0 && i == SCORE_LOAN) x = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   985
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   986
			/* Draw the bar */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   987
			if (x !=  0) GfxFillRect(112,     y - 2, 112 + x,  y + 10, color_done);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   988
			if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   989
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   990
			/* Calculate the % */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   991
			x = Clamp(val, 0, needed) * 100 / needed;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   992
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   993
			/* SCORE_LOAN is inversed */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   994
			if (val < 0 && i == SCORE_LOAN) x = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   995
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   996
			/* Draw it */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   997
			SetDParam(0, x);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   998
			DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
   999
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1000
			/* SCORE_LOAN is inversed */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1001
			if (i == SCORE_LOAN) val = needed - val;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1002
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1003
			/* Draw the amount we have against what is needed
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1004
				* For some of them it is in currency format */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1005
			SetDParam(0, val);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1006
			SetDParam(1, needed);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1007
			switch (i) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1008
				case SCORE_MIN_PROFIT:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1009
				case SCORE_MIN_INCOME:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1010
				case SCORE_MAX_INCOME:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1011
				case SCORE_MONEY:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1012
				case SCORE_LOAN:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1013
					DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, TC_FROMSTRING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1014
					break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1015
				default:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1016
					DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_INT, TC_FROMSTRING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1017
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1018
		}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1019
	}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1020
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1021
	virtual void OnClick(Point pt, int widget)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1022
	{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1023
		/* Check which button is clicked */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1024
		if (IsInsideMM(widget, 13, 21)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1025
			/* Is it no on disable? */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1026
			if (!this->IsWidgetDisabled(widget)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1027
				this->RaiseWidget(player + 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1028
				player = (PlayerID)(widget - 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1029
				this->LowerWidget(player + 13);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1030
				this->SetDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1031
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1032
		}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1033
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1034
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1035
	virtual void OnTick()
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1036
	{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1037
		if (_pause_game != 0) return;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1038
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1039
		/* Update the player score every 5 days */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1040
		if (--this->timeout == 0) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1041
			this->UpdatePlayerStats();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1042
			this->SetDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1043
		}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1044
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1045
};
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1046
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1047
PlayerID PerformanceRatingDetailWindow::player = INVALID_PLAYER;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1048
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1049
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1050
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
  1051
{   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
  1052
{    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
  1053
{      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
  1054
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1055
{      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
  1056
{      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
  1057
{      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
  1058
{      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
  1059
{      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
  1060
{      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
  1061
{      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
  1062
{      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
  1063
{      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
  1064
{      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
  1065
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1066
{      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
  1067
{      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
  1068
{      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
  1069
{      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
  1070
{      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
  1071
{      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
  1072
{      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
  1073
{      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
  1074
{   WIDGETS_END},
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1075
};
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1076
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1077
static const WindowDesc _performance_rating_detail_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6725
diff changeset
  1078
	WDP_AUTO, WDP_AUTO, 299, 228, 299, 228,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6063
diff changeset
  1079
	WC_PERFORMANCE_DETAIL, WC_NONE,
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1080
	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
  1081
	_performance_rating_detail_widgets,
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1082
};
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1083
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6529
diff changeset
  1084
void ShowPerformanceRatingDetail()
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1085
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 6877
diff changeset
  1086
	AllocateWindowDescFront<PerformanceRatingDetailWindow>(&_performance_rating_detail_desc, 0);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1087
}