src/industry_gui.cpp
author richk
Tue, 15 Apr 2008 00:47:19 +0000
branchNewGRF_ports
changeset 10184 fcf5fb2548eb
parent 6877 889301acc299
child 10242 52b4a9006029
permissions -rw-r--r--
(svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
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
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6526
diff changeset
     3
/** @file industry_gui.cpp */
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6526
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: 1786
diff changeset
     6
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1287
diff changeset
     7
#include "debug.h"
1386
aa5a172a8431 (svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents: 1309
diff changeset
     8
#include "gui.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
     9
#include "window_gui.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    10
#include "textbuf_gui.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    11
#include "command_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    12
#include "viewport_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    13
#include "gfx_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "town.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    16
#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: 6144
diff changeset
    17
#include "cargotype.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    18
#include "newgrf.h"
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    19
#include "newgrf_callbacks.h"
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    20
#include "newgrf_industries.h"
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    21
#include "newgrf_text.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    22
#include "strings_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    23
#include "map_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    24
#include "player_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    25
#include "settings_type.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    26
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    27
#include "table/strings.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    28
#include "table/sprites.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    29
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    30
bool _ignore_restrictions;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    31
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    32
/** Names of the widgets of the dynamic place industries gui */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    33
enum DynamicPlaceIndustriesWidgets {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    34
	DPIW_CLOSEBOX = 0,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    35
	DPIW_CAPTION,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    36
	DPIW_MATRIX_WIDGET,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    37
	DPIW_SCROLLBAR,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    38
	DPIW_INFOPANEL,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    39
	DPIW_FUND_WIDGET,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    40
	DPIW_RESIZE_WIDGET,
4995
e6152c0dc612 (svn r7001) -Codechange: _build_industry_trypes is now only used by industry_gui.c. Move it there.
belugas
parents: 4939
diff changeset
    41
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    43
/** Attached struct to the window extended data */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    44
struct fnd_d {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    45
	int index;             ///< index of the element in the matrix
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    46
	IndustryType select;   ///< industry corresponding to the above index
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    47
	uint16 callback_timer; ///< timer counter for callback eventual verification
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    48
	bool timer_enabled;    ///< timer can be used
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    49
};
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    50
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(fnd_d));
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    51
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    52
/** Helper struct holding the available industries for current situation */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    53
static struct IndustryData {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    54
	uint16 count;                               ///< How many industries are loaded
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    55
	IndustryType index[NUM_INDUSTRYTYPES + 1];  ///< Type of industry, in the order it was loaded
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    56
	StringID text[NUM_INDUSTRYTYPES + 1];       ///< Text coming from CBM_IND_FUND_MORE_TEXT (if ever)
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    57
	bool enabled[NUM_INDUSTRYTYPES + 1];        ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    58
} _fund_gui;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
    59
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
    60
assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.text));
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
    61
assert_compile(lengthof(_fund_gui.index) == lengthof(_fund_gui.enabled));
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
    62
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    63
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    64
 * Gets the string to display after the cargo name (using callback 37)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    65
 * @param cargo the cargo for which the suffix is requested
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    66
 * - 00 - first accepted cargo type
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    67
 * - 01 - second accepted cargo type
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    68
 * - 02 - third accepted cargo type
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    69
 * - 03 - first produced cargo type
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    70
 * - 04 - second produced cargo type
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    71
 * @param ind the industry (NULL if in fund window)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    72
 * @param ind_type the industry type
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    73
 * @param indspec the industry spec
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    74
 * @return the string to display
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    75
 */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    76
static StringID GetCargoSuffix(uint cargo, Industry *ind, IndustryType ind_type, const IndustrySpec *indspec)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    77
{
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    78
	if (HasBit(indspec->callback_flags, CBM_IND_CARGO_SUFFIX)) {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    79
		bool fund = ind == NULL;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    80
		uint8 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, ((!fund) ? 1 << 8 : 0) | cargo, ind, ind_type, (!fund) ? ind->xy : INVALID_TILE);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    81
		if (callback != 0xFF) return GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    82
	}
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    83
	return STR_EMPTY;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    84
}
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
    85
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    86
static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
    88
	switch (e->event) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    89
		case WE_CREATE: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    90
			IndustryType ind;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    91
			const IndustrySpec *indsp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    93
			/* Shorten the window to the equivalant of the additionnal purchase
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    94
			 * info coming from the callback.  SO it will only be available to tis full
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    95
			 * height when newindistries are loaded */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    96
			if (!_loaded_newgrf_features.has_newindustries) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    97
				w->widget[DPIW_INFOPANEL].bottom -= 44;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    98
				w->widget[DPIW_FUND_WIDGET].bottom -= 44;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    99
				w->widget[DPIW_FUND_WIDGET].top -= 44;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   100
				w->widget[DPIW_RESIZE_WIDGET].bottom -= 44;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   101
				w->widget[DPIW_RESIZE_WIDGET].top -= 44;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   102
				w->resize.height = w->height -= 44;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   103
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   105
			WP(w, fnd_d).timer_enabled = _loaded_newgrf_features.has_newindustries;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   106
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   107
			/* Initilialize structures */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   108
			_fund_gui.count = 0;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   109
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   110
			for (uint i = 0; i < lengthof(_fund_gui.index); i++) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   111
				_fund_gui.index[i]   = 0xFF;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   112
				_fund_gui.text[i]    = STR_NULL;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   113
				_fund_gui.enabled[i] = false;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   114
			}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   115
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   116
			w->vscroll.cap = 8; // rows in grid, same in scroller
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   117
			w->resize.step_height = 13;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   118
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   119
			if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   120
				_fund_gui.index[_fund_gui.count] = INVALID_INDUSTRYTYPE;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   121
				_fund_gui.count++;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   122
				WP(w, fnd_d).timer_enabled = false;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   123
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   124
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   125
			/* Fill the _fund_gui structure with industries.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   126
			 * The tests performed after the enabled allow to load the industries
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   127
			 * In the same way they are inserted by grf (if any)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   128
			 */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   129
			for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   130
				indsp = GetIndustrySpec(ind);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   131
				if (indsp->enabled){
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   132
					/* Rule is that editor mode loads all industries.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   133
					 * In game mode, all non raw industries are loaded too
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   134
					 * and raw ones are loaded only when setting allows it */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   135
					if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _patches.raw_industry_construction == 0) continue;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   136
					_fund_gui.index[_fund_gui.count] = ind;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   137
					_fund_gui.enabled[_fund_gui.count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   138
					_fund_gui.count++;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   139
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   140
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   141
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   142
			/* first indutry type is selected.
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   143
			 * I'll be damned if there are none available ;) */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   144
			WP(w, fnd_d).index = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   145
			WP(w, fnd_d).select = _fund_gui.index[0];
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   146
			WP(w, fnd_d).callback_timer = DAY_TICKS;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   147
		} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   148
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   149
		case WE_PAINT: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   150
			const IndustrySpec *indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   151
			int x_str = w->widget[DPIW_INFOPANEL].left + 3;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   152
			int y_str = w->widget[DPIW_INFOPANEL].top + 3;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   153
			const Widget *wi = &w->widget[DPIW_INFOPANEL];
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   154
			int max_width = wi->right - wi->left - 4;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   155
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   156
			/* Raw industries might be prospected. Show this fact by changing the string
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   157
			 * In Editor, you just build, while ingame, or you fund or you prospect */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   158
			if (_game_mode == GM_EDITOR) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   159
				/* We've chosen many random industries but no industries have been specified */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   160
				if (indsp == NULL) _fund_gui.enabled[WP(w, fnd_d).index] = _opt.diff.number_industries != 0;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   161
				w->widget[DPIW_FUND_WIDGET].data = STR_BUILD_NEW_INDUSTRY;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   162
			} else {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   163
				w->widget[DPIW_FUND_WIDGET].data = (_patches.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_PROSPECT_NEW_INDUSTRY : STR_FUND_NEW_INDUSTRY;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   164
			}
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   165
			w->SetWidgetDisabledState(DPIW_FUND_WIDGET, !_fund_gui.enabled[WP(w, fnd_d).index]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   166
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   167
			SetVScrollCount(w, _fund_gui.count);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   168
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   169
			DrawWindowWidgets(w);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   170
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   171
			/* and now with the matrix painting */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   172
			for (byte i = 0; i < w->vscroll.cap && ((i + w->vscroll.pos) < _fund_gui.count); i++) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   173
				int offset = i * 13;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   174
				int x = 3;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   175
				int y = 16;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   176
				bool selected = WP(w, fnd_d).index == i + w->vscroll.pos;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   177
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   178
				if (_fund_gui.index[i + w->vscroll.pos] == INVALID_INDUSTRYTYPE) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   179
					DrawStringTruncated(20, y + offset, STR_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE, max_width - 25);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   180
					continue;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   181
				}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   182
				const IndustrySpec *indsp = GetIndustrySpec(_fund_gui.index[i + w->vscroll.pos]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   183
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   184
				/* Draw the name of the industry in white is selected, otherwise, in orange */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   185
				DrawStringTruncated(20, y + offset, indsp->name, selected ? TC_WHITE : TC_ORANGE, max_width - 25);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   186
				GfxFillRect(x,     y + 1 + offset,  x + 10, y + 7 + offset, selected ? 15 : 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   187
				GfxFillRect(x + 1, y + 2 + offset,  x +  9, y + 6 + offset, indsp->map_colour);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   188
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   189
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   190
			if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   191
				DrawStringMultiLine(x_str, y_str, STR_RANDOM_INDUSTRIES_TIP, max_width, wi->bottom - wi->top - 40);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   192
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   193
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   194
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   195
			if (_game_mode != GM_EDITOR) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   196
				SetDParam(0, indsp->GetConstructionCost());
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   197
				DrawStringTruncated(x_str, y_str, STR_482F_COST, TC_FROMSTRING, max_width);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   198
				y_str += 11;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   199
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   200
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   201
			/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   202
			StringID str = STR_4827_REQUIRES;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   203
			byte p = 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   204
			SetDParam(0, STR_00D0_NOTHING);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   205
			SetDParam(1, STR_EMPTY);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   206
			for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   207
				if (indsp->accepts_cargo[j] == CT_INVALID) continue;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   208
				if (p > 0) str++;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   209
				SetDParam(p++, GetCargo(indsp->accepts_cargo[j])->name);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   210
				SetDParam(p++, GetCargoSuffix(j, NULL, WP(w, fnd_d).select, indsp));
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   211
			}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   212
			DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   213
			y_str += 11;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   214
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   215
			/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   216
			str = STR_4827_PRODUCES;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   217
			p = 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   218
			SetDParam(0, STR_00D0_NOTHING);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   219
			SetDParam(1, STR_EMPTY);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   220
			for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   221
				if (indsp->produced_cargo[j] == CT_INVALID) continue;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   222
				if (p > 0) str++;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   223
				SetDParam(p++, GetCargo(indsp->produced_cargo[j])->name);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   224
				SetDParam(p++, GetCargoSuffix(j + 3, NULL, WP(w, fnd_d).select, indsp));
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   225
			}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   226
			DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   227
			y_str += 11;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   228
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   229
			/* Get the additional purchase info text, if it has not already been */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   230
			if (_fund_gui.text[WP(w, fnd_d).index] == STR_NULL) {   // Have i been called already?
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   231
				if (HasBit(indsp->callback_flags, CBM_IND_FUND_MORE_TEXT)) {          // No. Can it be called?
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   232
					uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, NULL, WP(w, fnd_d).select, INVALID_TILE);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   233
					if (callback_res != CALLBACK_FAILED) {  // Did it failed?
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   234
						StringID newtxt = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res);  // No. here's the new string
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   235
						_fund_gui.text[WP(w, fnd_d).index] = newtxt;   // Store it for further usage
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   236
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   237
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   238
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   239
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   240
			/* Draw the Additional purchase text, provided by newgrf callback, if any.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   241
			 * Otherwhise, will print Nothing */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   242
			str = _fund_gui.text[WP(w, fnd_d).index];
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   243
			if (str != STR_NULL && str != STR_UNDEFINED) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   244
				SetDParam(0, str);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   245
				DrawStringMultiLine(x_str, y_str, STR_JUST_STRING, max_width, wi->bottom - wi->top - 40);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   246
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   247
		} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   248
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   249
		case WE_DOUBLE_CLICK:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   250
			if (e->we.click.widget != DPIW_MATRIX_WIDGET) break;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   251
			e->we.click.widget = DPIW_FUND_WIDGET;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   252
			/* Fall through */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   253
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   254
		case WE_CLICK:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   255
			switch (e->we.click.widget) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   256
				case DPIW_MATRIX_WIDGET: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   257
					const IndustrySpec *indsp;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   258
					int y = (e->we.click.pt.y - w->widget[DPIW_MATRIX_WIDGET].top) / 13 + w->vscroll.pos ;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   259
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   260
					if (y >= 0 && y < _fund_gui.count) { // Is it within the boundaries of available data?
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   261
						WP(w, fnd_d).index = y;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   262
						WP(w, fnd_d).select = _fund_gui.index[WP(w, fnd_d).index];
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   263
						indsp = (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(WP(w, fnd_d).select);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   264
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   265
						SetWindowDirty(w);
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   266
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   267
						if ((_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && indsp != NULL && indsp->IsRawIndustry()) ||
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   268
								WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   269
							/* Reset the button state if going to prospecting or "build many industries" */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   270
							w->RaiseButtons();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   271
							ResetObjectToPlace();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   272
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   273
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   274
				} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   275
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   276
				case DPIW_FUND_WIDGET: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   277
					if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   278
						w->HandleButtonClick(DPIW_FUND_WIDGET);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   279
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   280
						if (GetNumTowns() == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   281
							ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   282
						} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   283
							extern void GenerateIndustries();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   284
							_generating_world = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   285
							GenerateIndustries();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   286
							_generating_world = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   287
						}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   288
					} else if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && GetIndustrySpec(WP(w, fnd_d).select)->IsRawIndustry()) {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   289
						DoCommandP(0, WP(w, fnd_d).select, InteractiveRandom(), NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   290
						w->HandleButtonClick(DPIW_FUND_WIDGET);
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   291
					} else {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   292
						HandlePlacePushButton(w, DPIW_FUND_WIDGET, SPR_CURSOR_INDUSTRY, VHM_RECT, NULL);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   293
					}
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   294
				} break;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   295
			}
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   296
			break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   297
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   298
		case WE_RESIZE: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   299
			/* Adjust the number of items in the matrix depending of the rezise */
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   300
			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   301
			w->widget[DPIW_MATRIX_WIDGET].data = (w->vscroll.cap << 8) + 1;
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   302
		} break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   303
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   304
		case WE_PLACE_OBJ: {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   305
			bool success = true;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   306
			/* We do not need to protect ourselves against "Random Many Industries" in this mode */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   307
			const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select);
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   308
			uint32 seed = InteractiveRandom();
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   309
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   310
			if (_game_mode == GM_EDITOR) {
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   311
				/* Show error if no town exists at all */
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   312
				if (GetNumTowns() == 0) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   313
					SetDParam(0, indsp->name);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   314
					ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_0285_CAN_T_BUILD_HERE, e->we.place.pt.x, e->we.place.pt.y);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   315
					return;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   316
				}
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   317
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   318
				_current_player = OWNER_NONE;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   319
				_generating_world = true;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   320
				_ignore_restrictions = true;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   321
				success = DoCommandP(e->we.place.tile, (InteractiveRandomRange(indsp->num_table) << 16) | WP(w, fnd_d).select, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   322
				if (!success) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   323
					SetDParam(0, indsp->name);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   324
					ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE, e->we.place.pt.x, e->we.place.pt.y);
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   325
				}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   326
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   327
				_ignore_restrictions = false;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   328
				_generating_world = false;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   329
			} else {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   330
				success = DoCommandP(e->we.place.tile, (InteractiveRandomRange(indsp->num_table) << 16) | WP(w, fnd_d).select, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   331
			}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   332
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   333
			/* If an industry has been built, just reset the cursor and the system */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   334
			if (success) ResetObjectToPlace();
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   335
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   337
		case WE_TICK:
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   338
			if (_pause_game != 0) break;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   339
			if (!WP(w, fnd_d).timer_enabled) break;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   340
			if (--WP(w, fnd_d).callback_timer == 0) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   341
				/* We have just passed another day.
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   342
				 * See if we need to update availability of currently selected industry */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   343
				WP(w, fnd_d).callback_timer = DAY_TICKS;  //restart counter
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   344
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   345
				const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   346
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   347
				if (indsp->enabled) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   348
					bool call_back_result = CheckIfCallBackAllowsAvailability(WP(w, fnd_d).select, IACT_USERCREATION);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   349
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   350
					/* Only if result does match the previous state would it require a redraw. */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   351
					if (call_back_result != _fund_gui.enabled[WP(w, fnd_d).index]) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   352
						_fund_gui.enabled[WP(w, fnd_d).index] = call_back_result;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   353
						SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   354
					}
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   355
				}
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   356
			}
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   357
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   358
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   359
		case WE_TIMEOUT:
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   360
		case WE_ABORT_PLACE_OBJ:
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   361
			w->RaiseButtons();
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   362
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   366
/** Widget definition of the dynamic place industries gui */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   367
static const Widget _build_dynamic_industry_widgets[] = {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   368
{   WWT_CLOSEBOX,    RESIZE_NONE,    7,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},            // DPIW_CLOSEBOX
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   369
{    WWT_CAPTION,   RESIZE_RIGHT,    7,    11,   169,     0,    13, STR_0314_FUND_NEW_INDUSTRY,     STR_018C_WINDOW_TITLE_DRAG_THIS},  // DPIW_CAPTION
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   370
{     WWT_MATRIX,      RESIZE_RB,    7,     0,   157,    14,   118, 0x801,                          STR_INDUSTRY_SELECTION_HINT},      // DPIW_MATRIX_WIDGET
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   371
{  WWT_SCROLLBAR,     RESIZE_LRB,    7,   158,   169,    14,   118, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DPIW_SCROLLBAR
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   372
{      WWT_PANEL,     RESIZE_RTB,    7,     0,   169,   119,   199, 0x0,                            STR_NULL},                         // DPIW_INFOPANEL
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   373
{    WWT_TEXTBTN,     RESIZE_RTB,    7,     0,   157,   200,   211, STR_FUND_NEW_INDUSTRY,          STR_NULL},                         // DPIW_FUND_WIDGET
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   374
{  WWT_RESIZEBOX,    RESIZE_LRTB,    7,   158,   169,   200,   211, 0x0,                            STR_RESIZE_BUTTON},                // DPIW_RESIZE_WIDGET
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   375
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   378
/** Window definition of the dynamic place industries gui */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   379
static const WindowDesc _build_industry_dynamic_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   380
	WDP_AUTO, WDP_AUTO, 170, 212, 170, 212,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5860
diff changeset
   381
	WC_BUILD_INDUSTRY, WC_NONE,
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   382
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   383
	_build_dynamic_industry_widgets,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   384
	BuildDynamicIndustryWndProc,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   387
void ShowBuildIndustryWindow()
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   388
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   389
	if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   390
	AllocateWindowDescFront(&_build_industry_dynamic_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   393
static void UpdateIndustryProduction(Industry *i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   394
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   395
static inline bool isProductionMinimum(const Industry *i, int pt)
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   396
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   397
	return i->production_rate[pt] == 0;
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   398
}
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   399
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   400
static inline bool isProductionMaximum(const Industry *i, int pt)
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   401
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   402
	return i->production_rate[pt] >= 255;
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   403
}
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   404
4194
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   405
static inline bool IsProductionAlterable(const Industry *i)
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   406
{
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   407
	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   408
			(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
4194
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   409
}
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   410
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   411
/** Names of the widgets of the view industry gui */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   412
enum IndustryViewWidgets {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   413
	IVW_CLOSEBOX = 0,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   414
	IVW_CAPTION,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   415
	IVW_STICKY,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   416
	IVW_BACKGROUND,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   417
	IVW_VIEWPORT,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   418
	IVW_INFO,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   419
	IVW_GOTO,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   420
	IVW_SPACER,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   421
};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   422
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   423
/** Information to store about the industry window */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   424
struct indview_d : public vp_d {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   425
	byte editbox_line;        ///< The line clicked to open the edit box
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   426
	byte clicked_line;        ///< The line of the button that has been clicked
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   427
	byte clicked_button;      ///< The button that has been clicked (to raise)
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   428
	byte production_offset_y; ///< The offset of the production texts/buttons
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   429
};
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   430
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(indview_d));
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   431
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   432
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
static void IndustryViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
   435
	switch (e->event) {
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   436
	case WE_PAINT: {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   437
		Industry *i = GetIndustry(w->window_number);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   438
		const IndustrySpec *ind = GetIndustrySpec(i->type);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   439
		int y = w->widget[IVW_INFO].top + 1;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   440
		bool first = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   441
		bool has_accept = false;
2557
3ed00023e382 (svn r3090) Remove long dead pieces of code
tron
parents: 2469
diff changeset
   442
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   443
		SetDParam(0, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   446
		if (HasBit(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   447
			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   448
				if (i->accepts_cargo[j] == CT_INVALID) continue;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   449
				has_accept = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   450
				if (first) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   451
					DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, TC_FROMSTRING);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   452
					y += 10;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   453
					first = false;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   454
				}
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   455
				SetDParam(0, i->accepts_cargo[j]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   456
				SetDParam(1, i->incoming_cargo_waiting[j]);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   457
				SetDParam(2, GetCargoSuffix(j, i, i->type, ind));
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   458
				DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, TC_FROMSTRING);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   459
				y += 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   460
			}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   461
		} else {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   462
			StringID str = STR_4827_REQUIRES;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   463
			byte p = 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   464
			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   465
				if (i->accepts_cargo[j] == CT_INVALID) continue;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   466
				has_accept = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   467
				if (p > 0) str++;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   468
				SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   469
				SetDParam(p++, GetCargoSuffix(j, i, i->type, ind));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
			}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   471
			if (has_accept) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   472
				DrawString(2, y, str, TC_FROMSTRING);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   473
				y += 10;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   474
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   476
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   477
		first = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   478
		for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   479
			if (i->produced_cargo[j] == CT_INVALID) continue;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   480
			if (first) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   481
				if (has_accept) y += 10;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   482
				DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, TC_FROMSTRING);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   483
				y += 10;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   484
				WP(w, indview_d).production_offset_y = y;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   485
				first = false;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   486
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   488
			SetDParam(0, i->produced_cargo[j]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   489
			SetDParam(1, i->last_month_production[j]);
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   490
			SetDParam(2, GetCargoSuffix(j + 3, i, i->type, ind));
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 1981
diff changeset
   491
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   492
			SetDParam(3, i->last_month_pct_transported[j] * 100 >> 8);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   493
			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, TC_FROMSTRING);
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6526
diff changeset
   494
			/* Let's put out those buttons.. */
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   495
			if (IsProductionAlterable(i)) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   496
				DrawArrowButtons(5, y, 3, (WP(w, indview_d).clicked_line == j + 1) ? WP(w, indview_d).clicked_button : 0,
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   497
						!isProductionMinimum(i, j), !isProductionMaximum(i, j));
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   498
			}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   499
			y += 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   500
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   502
		/* Get the extra message for the GUI */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   503
		if (HasBit(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   504
			uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->xy);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   505
			if (callback_res != CALLBACK_FAILED) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   506
				StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   507
				if (message != STR_NULL && message != STR_UNDEFINED) {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   508
					const Widget *wi = &w->widget[IVW_INFO];
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   509
					y += 10;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   510
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   511
					PrepareTextRefStackUsage(6);
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   512
					/* Use all the available space left from where we stand up to the end of the window */
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   513
					y += DrawStringMultiLine(2, y, message, wi->right - wi->left - 4, -1);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   514
					StopTextRefStackUsage();
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   515
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   519
		if (y > w->widget[IVW_INFO].bottom) {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   520
			SetWindowDirty(w);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   521
			ResizeWindowForWidget(w, IVW_INFO, 0, y - w->widget[IVW_INFO].top);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   522
			SetWindowDirty(w);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   523
			return;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   524
		}
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   525
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
		DrawWindowViewport(w);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   527
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   529
	case WE_CLICK: {
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   530
		Industry *i;
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   531
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4617
diff changeset
   532
		switch (e->we.click.widget) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   533
		case IVW_INFO: {
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   534
			int line, x;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   535
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   536
			i = GetIndustry(w->window_number);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   537
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6526
diff changeset
   538
			/* We should work if needed.. */
4194
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   539
			if (!IsProductionAlterable(i)) return;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4617
diff changeset
   540
			x = e->we.click.pt.x;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   541
			line = (e->we.click.pt.y - WP(w, indview_d).production_offset_y) / 10;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   542
			if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IsInsideMM(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   543
				if (IsInsideMM(x, 5, 25) ) {
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   544
					/* Clicked buttons, decrease or increase production */
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1004
diff changeset
   545
					if (x < 15) {
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   546
						if (isProductionMinimum(i, line)) return;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   547
						i->production_rate[line] = max(i->production_rate[line] / 2, 0);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   548
					} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   549
						/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   550
						int new_prod = i->production_rate[line] == 0 ? 1 : i->production_rate[line] * 2;
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   551
						if (isProductionMaximum(i, line)) return;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   552
						i->production_rate[line] = minu(new_prod, 255);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   553
					}
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   554
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   555
					UpdateIndustryProduction(i);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   556
					SetWindowDirty(w);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   557
					w->flags4 |= 5 << WF_TIMEOUT_SHL;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   558
					WP(w, indview_d).clicked_line = line + 1;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   559
					WP(w, indview_d).clicked_button = (x < 15 ? 1 : 2);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   560
				} else if (IsInsideMM(x, 34, 160)) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6526
diff changeset
   561
					/* clicked the text */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   562
					WP(w, indview_d).editbox_line = line;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   563
					SetDParam(0, i->production_rate[line] * 8);
5682
eeddbbacd4ac (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5568
diff changeset
   564
					ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, w, CS_ALPHANUMERAL);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   565
				}
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1004
diff changeset
   566
			}
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   567
		} break;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   568
		case IVW_GOTO:
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   569
			i = GetIndustry(w->window_number);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1914
diff changeset
   570
			ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   571
		} break;
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   572
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   573
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
		break;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   575
	case WE_TIMEOUT:
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   576
		WP(w, indview_d).clicked_line = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   577
		WP(w, indview_d).clicked_button = 0;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   578
		SetWindowDirty(w);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   579
		break;
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   580
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   581
	case WE_ON_EDIT_TEXT:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4617
diff changeset
   582
		if (e->we.edittext.str[0] != '\0') {
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2989
diff changeset
   583
			Industry* i = GetIndustry(w->window_number);
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   584
			int line = WP(w, indview_d).editbox_line;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   585
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   586
			i->production_rate[line] = ClampU(atoi(e->we.edittext.str), 0, 255);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   587
			UpdateIndustryProduction(i);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   588
			SetWindowDirty(w);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   589
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   593
static void UpdateIndustryProduction(Industry *i)
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   594
{
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   595
	for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   596
		if (i->produced_cargo[j] != CT_INVALID) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   597
			i->last_month_production[j] = 8 * i->production_rate[j];
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   598
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   599
	}
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   600
}
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   601
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   602
/** Widget definition of the view industy gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
static const Widget _industry_view_widgets[] = {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   604
{   WWT_CLOSEBOX,   RESIZE_NONE,     9,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},            // IVW_CLOSEBOX
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   605
{    WWT_CAPTION,   RESIZE_NONE,     9,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},  // IVW_CAPTION
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   606
{  WWT_STICKYBOX,   RESIZE_NONE,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},                // IVW_STICKY
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   607
{      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,    14,   105, 0x0,               STR_NULL},                         // IVW_BACKGROUND
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   608
{      WWT_INSET,   RESIZE_NONE,     9,     2,   257,    16,   103, 0x0,               STR_NULL},                         // IVW_VIEWPORT
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   609
{      WWT_PANEL, RESIZE_BOTTOM,     9,     0,   259,   106,   107, 0x0,               STR_NULL},                         // IVW_INFO
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   610
{ WWT_PUSHTXTBTN,     RESIZE_TB,     9,     0,   129,   108,   119, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   611
{      WWT_PANEL,     RESIZE_TB,     9,   130,   259,   108,   119, 0x0,               STR_NULL},                         // IVW_SPACER
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   612
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   615
/** Window definition of the view industy gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
static const WindowDesc _industry_view_desc = {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   617
	WDP_AUTO, WDP_AUTO, 260, 120, 260, 120,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5860
diff changeset
   618
	WC_INDUSTRY_VIEW, WC_NONE,
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6877
diff changeset
   619
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	_industry_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	IndustryViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
void ShowIndustryViewWindow(int industry)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3689
diff changeset
   626
	Window *w = AllocateWindowDescFront(&_industry_view_desc, industry);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   628
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
		w->flags4 |= WF_DISABLE_VP_SCROLL;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   630
		WP(w, indview_d).editbox_line = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   631
		WP(w, indview_d).clicked_line = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   632
		WP(w, indview_d).clicked_button = 0;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   633
		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   637
/** Names of the widgets of the industry directory gui */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   638
enum IndustryDirectoryWidgets {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   639
	IDW_CLOSEBOX = 0,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   640
	IDW_CAPTION,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   641
	IDW_STICKY,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   642
	IDW_SORTBYNAME,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   643
	IDW_SORTBYTYPE,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   644
	IDW_SORTBYPROD,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   645
	IDW_SORTBYTRANSPORT,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   646
	IDW_SPACER,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   647
	IDW_INDUSRTY_LIST,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   648
	IDW_SCROLLBAR,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   649
	IDW_RESIZE,
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   650
};
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   651
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   652
/** Widget definition of the industy directory gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
static const Widget _industry_directory_widgets[] = {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   654
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},             // IDW_CLOSEBOX
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   655
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   495,     0,    13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},   // IDW_CAPTION
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   656
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   496,   507,     0,    13, 0x0,                     STR_STICKY_BUTTON},                 // IDW_STICKY
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   657
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,   100,    14,    25, STR_SORT_BY_NAME,        STR_SORT_ORDER_TIP},                // IDW_SORTBYNAME
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   658
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   101,   200,    14,    25, STR_SORT_BY_TYPE,        STR_SORT_ORDER_TIP},                // IDW_SORTBYTYPE
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   659
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   201,   300,    14,    25, STR_SORT_BY_PRODUCTION,  STR_SORT_ORDER_TIP},                // IDW_SORTBYPROD
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   660
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   301,   400,    14,    25, STR_SORT_BY_TRANSPORTED, STR_SORT_ORDER_TIP},                // IDW_SORTBYTRANSPORT
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   661
{      WWT_PANEL,   RESIZE_NONE,    13,   401,   495,    14,    25, 0x0,                     STR_NULL},                          // IDW_SPACER
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   662
{      WWT_PANEL, RESIZE_BOTTOM,    13,     0,   495,    26,   189, 0x0,                     STR_200A_TOWN_NAMES_CLICK_ON_NAME}, // IDW_INDUSRTY_LIST
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   663
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   496,   507,    14,   177, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},  // IDW_SCROLLBAR
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   664
{  WWT_RESIZEBOX,     RESIZE_TB,    13,   496,   507,   178,   189, 0x0,                     STR_RESIZE_BUTTON},                 // IDW_RESIZE
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   665
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
static uint _num_industry_sort;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
static char _bufcache[96];
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   671
static const Industry* _last_industry;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
static byte _industry_sort_order;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 69
diff changeset
   675
static int CDECL GeneralIndustrySorter(const void *a, const void *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
{
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   677
	const Industry* i = *(const Industry**)a;
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   678
	const Industry* j = *(const Industry**)b;
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   679
	int r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
	switch (_industry_sort_order >> 1) {
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   682
		default: NOT_REACHED();
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   683
		case 0: /* Sort by Name (handled later) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
			r = 0;
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   685
			break;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   686
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   687
		case 1: /* Sort by Type */
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   688
			r = i->type - j->type;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   689
			break;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   690
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   691
		case 2: /* Sort by Production */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   692
			if (i->produced_cargo[0] == CT_INVALID) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   693
				r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   694
			} else {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   695
				if (j->produced_cargo[0] == CT_INVALID) {
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   696
					r = 1;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   697
				} else {
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   698
					r =
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   699
						(i->last_month_production[0] + i->last_month_production[1]) -
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   700
						(j->last_month_production[0] + j->last_month_production[1]);
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   701
				}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   702
			}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   703
			break;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   704
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   705
		case 3: /* Sort by transported fraction */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   706
			if (i->produced_cargo[0] == CT_INVALID) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   707
				r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   708
			} else {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   709
				if (j->produced_cargo[0] == CT_INVALID) {
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   710
					r = 1;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   711
				} else {
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   712
					int pi;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   713
					int pj;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   714
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   715
					pi = i->last_month_pct_transported[0] * 100 >> 8;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   716
					if (i->produced_cargo[1] != CT_INVALID) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   717
						int p = i->last_month_pct_transported[1] * 100 >> 8;
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   718
						if (p < pi) pi = p;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   719
					}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   720
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   721
					pj = j->last_month_pct_transported[0] * 100 >> 8;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   722
					if (j->produced_cargo[1] != CT_INVALID) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   723
						int p = j->last_month_pct_transported[1] * 100 >> 8;
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   724
						if (p < pj) pj = p;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   725
					}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   726
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   727
					r = pi - pj;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   728
				}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   729
			}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   730
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6526
diff changeset
   733
	/* default to string sorting if they are otherwise equal */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
	if (r == 0) {
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   735
		char buf1[96];
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   736
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   737
		SetDParam(0, i->town->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   738
		GetString(buf1, STR_TOWN, lastof(buf1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   740
		if (j != _last_industry) {
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   741
			_last_industry = j;
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   742
			SetDParam(0, j->town->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   743
			GetString(_bufcache, STR_TOWN, lastof(_bufcache));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
		r = strcmp(buf1, _bufcache);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   747
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   748
	if (_industry_sort_order & 1) r = -r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
6526
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   752
/**
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   753
 * Makes a sorted industry list.
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   754
 * When there are no industries, the list has to be made. This so when one
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   755
 * starts a new game without industries after playing a game with industries
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   756
 * the list is not populated with invalid industries from the previous game.
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   757
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   758
static void MakeSortedIndustryList()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
{
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   760
	const Industry* i;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   761
	int n = 0;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   762
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   763
	/* Create array for sorting */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5852
diff changeset
   764
	_industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
6526
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   766
	/* Don't attempt a sort if there are no industries */
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   767
	if (GetNumIndustries() != 0) {
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   768
		FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   769
		qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
85cfa44803d0 (svn r8980) -Fix (FS#656): the industry list should also be (re)set when the number of industries is 0.
rubidium
parents: 6417
diff changeset
   770
	}
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   771
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	_num_industry_sort = n;
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   773
	_last_industry = NULL; // used for "cache"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5247
diff changeset
   775
	DEBUG(misc, 3, "Resorting industries list");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
   781
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
	case WE_PAINT: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
		if (_industry_sort_dirty) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
			_industry_sort_dirty = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
			MakeSortedIndustryList();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
1666
b36927825adb (svn r2170) -fix: [1179457] the industry list can now no longer scroll down then the end of the list is reached (Hackykid)
bjarni
parents: 1388
diff changeset
   788
		SetVScrollCount(w, _num_industry_sort);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		DrawWindowWidgets(w);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   791
		DrawSortButtonState(w, IDW_SORTBYNAME + (_industry_sort_order >> 1), _industry_sort_order & 1 ? SBS_DOWN : SBS_UP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   793
		uint p = w->vscroll.pos;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   794
		int n = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
		while (p < _num_industry_sort) {
4277
3539bd14f023 (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 4211
diff changeset
   797
			const Industry* i = _industry_sort[p];
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   798
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   799
			SetDParam(0, i->index);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   800
			if (i->produced_cargo[0] != CT_INVALID) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   801
				SetDParam(1, i->produced_cargo[0]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   802
				SetDParam(2, i->last_month_production[0]);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   803
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   804
				if (i->produced_cargo[1] != CT_INVALID) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6743
diff changeset
   805
					SetDParam(3, i->produced_cargo[1]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   806
					SetDParam(4, i->last_month_production[1]);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   807
					SetDParam(5, i->last_month_pct_transported[0] * 100 >> 8);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   808
					SetDParam(6, i->last_month_pct_transported[1] * 100 >> 8);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   809
					DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_TWO, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   811
					SetDParam(3, i->last_month_pct_transported[0] * 100 >> 8);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   812
					DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
			} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   815
				DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_NOPROD, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
			p++;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
   818
			if (++n == w->vscroll.cap) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	case WE_CLICK:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4617
diff changeset
   823
		switch (e->we.click.widget) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   824
			case IDW_SORTBYNAME: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   825
				_industry_sort_order = _industry_sort_order == 0 ? 1 : 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   826
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   827
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   828
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   830
			case IDW_SORTBYTYPE: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   831
				_industry_sort_order = _industry_sort_order == 2 ? 3 : 2;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   832
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   833
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   834
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   836
			case IDW_SORTBYPROD: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   837
				_industry_sort_order = _industry_sort_order == 4 ? 5 : 4;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   838
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   839
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   840
			} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   841
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   842
			case IDW_SORTBYTRANSPORT: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   843
				_industry_sort_order = _industry_sort_order == 6 ? 7 : 6;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   844
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   845
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   846
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   848
			case IDW_INDUSRTY_LIST: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   849
				int y = (e->we.click.pt.y - 28) / 10;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   850
				uint16 p;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   851
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   852
				if (!IsInsideMM(y, 0, w->vscroll.cap)) return;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   853
				p = y + w->vscroll.pos;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   854
				if (p < _num_industry_sort) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   855
					ScrollMainWindowToTile(_industry_sort[p]->xy);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   856
				}
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   857
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
		break;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   864
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   865
	case WE_RESIZE:
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4617
diff changeset
   866
		w->vscroll.cap += e->we.sizing.diff.y / 10;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   867
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   868
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   871
/** Window definition of the industy directory gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
static const WindowDesc _industry_directory_desc = {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   873
	WDP_AUTO, WDP_AUTO, 508, 190, 508, 190,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5860
diff changeset
   874
	WC_INDUSTRY_DIRECTORY, WC_NONE,
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   875
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	_industry_directory_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	IndustryDirectoryWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   880
void ShowIndustryDirectory()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3689
diff changeset
   882
	Window *w = AllocateWindowDescFront(&_industry_directory_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   884
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
		w->vscroll.cap = 16;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   886
		w->resize.height = w->height - 6 * 10; // minimum 10 items
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   887
		w->resize.step_height = 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
}