src/industry_gui.cpp
author richk
Sun, 22 Jul 2007 21:24:42 +0000
branchNewGRF_ports
changeset 6732 ca1b466db422
parent 6730 f09255ea0123
child 6743 cabfaa4a0295
permissions -rw-r--r--
(svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
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"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     8
#include "functions.h"
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1299
diff changeset
     9
#include "strings.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 222
diff changeset
    10
#include "table/strings.h"
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
    11
#include "table/sprites.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 534
diff changeset
    12
#include "map.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
    13
#include "gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "town.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    20
#include "variables.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    21
#include "helpers.hpp"
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6144
diff changeset
    22
#include "cargotype.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    23
#include "newgrf.h"
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    24
#include "newgrf_callbacks.h"
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    25
#include "newgrf_industries.h"
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    26
#include "newgrf_text.h"
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    27
#include "date.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    29
extern Industry *CreateNewIndustry(TileIndex tile, IndustryType type);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    30
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    31
/**
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    32
 * Search callback function for TryBuildIndustry
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    33
 * @param tile to test
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    34
 * @param data that is passed by the caller.  In this case, the type of industry been tested
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    35
 * @return the success (or not) of the operation
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    36
 */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    37
static bool SearchTileForIndustry(TileIndex tile, uint32 data)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    38
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    39
	return CreateNewIndustry(tile, data) != NULL;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    40
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    41
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    42
/**
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    43
 * Perform a 9*9 tiles circular search around a tile
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    44
 * in order to find a suitable zone to create the desired industry
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    45
 * @param tile to start search for
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    46
 * @param type of the desired industry
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    47
 * @return the success (or not) of the operation
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    48
 */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    49
static bool TryBuildIndustry(TileIndex tile, int type)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    50
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    51
	return CircularTileSearch(tile, 9, SearchTileForIndustry, type);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    52
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    53
bool _ignore_restrictions;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    54
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    55
enum {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    56
	DYNA_INDU_MATRIX_WIDGET = 2,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    57
	DYNA_INDU_INFOPANEL = 4,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    58
	DYNA_INDU_FUND_WIDGET,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    59
	DYNA_INDU_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
    60
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    62
/** Attached struct to the window extended data */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    63
struct fnd_d {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    64
	int index;             ///< index of the element in the matrix
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    65
	IndustryType select;   ///< industry corresponding to the above index
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    66
	uint16 callback_timer; ///< timer counter for callback eventual verification
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    67
	bool timer_enabled;    ///< timer can be used
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    68
};
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    69
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(fnd_d));
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    70
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    71
/** 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
    72
static struct IndustryData {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    73
	uint16 count;                               ///< How many industries are loaded
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    74
	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
    75
	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
    76
	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
    77
} _fund_gui;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
    78
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    79
static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
    81
	switch (e->event) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    82
		case WE_CREATE: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    83
			IndustryType ind;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    84
			const IndustrySpec *indsp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    86
			/* 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
    87
			 * 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
    88
			 * height when newindistries are loaded */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    89
			if (!_loaded_newgrf_features.has_newindustries) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    90
				w->widget[DYNA_INDU_INFOPANEL].bottom -= 44;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    91
				w->widget[DYNA_INDU_FUND_WIDGET].bottom -= 44;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    92
				w->widget[DYNA_INDU_FUND_WIDGET].top -= 44;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    93
				w->widget[DYNA_INDU_RESIZE_WIDGET].bottom -= 44;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    94
				w->widget[DYNA_INDU_RESIZE_WIDGET].top -= 44;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    95
				w->resize.height = w->height -= 44;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    96
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
    98
			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
    99
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   100
			/* Initilialize structures */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   101
			memset(&_fund_gui.index, 0xFF, NUM_INDUSTRYTYPES);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   102
			memset(&_fund_gui.text, STR_NULL, NUM_INDUSTRYTYPES);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   103
			memset(&_fund_gui.enabled, false, NUM_INDUSTRYTYPES);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   104
			_fund_gui.count = 0;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   105
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   106
			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
   107
			w->resize.step_height = 13;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   108
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   109
			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
   110
				_fund_gui.index[_fund_gui.count] = INVALID_INDUSTRYTYPE;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   111
				_fund_gui.count++;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   112
				WP(w, fnd_d).timer_enabled = false;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   113
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   114
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   115
			/* We'll perform two distinct loops, one for secondary industries, and the other one for
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   116
			 * primary ones. Each loop will fill the _fund_gui structure. */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   117
			for (ind = IT_COAL_MINE; ind < NUM_INDUSTRYTYPES; ind++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   118
				indsp = GetIndustrySpec(ind);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   119
				if (indsp->enabled && (!indsp->IsRawIndustry() || _game_mode == GM_EDITOR)) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   120
					_fund_gui.index[_fund_gui.count] = ind;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   121
					_fund_gui.enabled[_fund_gui.count] = CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   122
					_fund_gui.count++;
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
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   125
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   126
			if (_patches.raw_industry_construction != 0 && _game_mode != GM_EDITOR) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   127
				for (ind = IT_COAL_MINE; ind < NUM_INDUSTRYTYPES; ind++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   128
					indsp = GetIndustrySpec(ind);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   129
					if (indsp->enabled && indsp->IsRawIndustry()) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   130
						_fund_gui.index[_fund_gui.count] = ind;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   131
						_fund_gui.enabled[_fund_gui.count] = CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   132
						_fund_gui.count++;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   133
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   134
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   135
			}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   136
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   137
			/* first indutry type is selected.
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   138
			 * I'll be damned if there are none available ;) */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   139
			WP(w, fnd_d).index = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   140
			WP(w, fnd_d).select = _fund_gui.index[0];
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   141
			WP(w, fnd_d).callback_timer = DAY_TICKS;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   142
		} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   143
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   144
		case WE_PAINT: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   145
			const IndustrySpec *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
   146
			StringID str = STR_4827_REQUIRES;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   147
			int x_str = w->widget[DYNA_INDU_INFOPANEL].left + 3;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   148
			int y_str = w->widget[DYNA_INDU_INFOPANEL].top + 3;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   149
			const Widget *wi = &w->widget[DYNA_INDU_INFOPANEL];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   150
			int max_width = wi->right - wi->left - 4;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   151
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   152
			/* 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
   153
			 * 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
   154
			if (_game_mode == GM_EDITOR) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   155
				/* 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
   156
				if (indsp == NULL) _fund_gui.enabled[WP(w, fnd_d).index] = _opt.diff.number_industries != 0;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   157
				w->widget[DYNA_INDU_FUND_WIDGET].data = STR_BUILD_NEW_INDUSTRY;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   158
			} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   159
				w->widget[DYNA_INDU_FUND_WIDGET].data = (_patches.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_PROSPECT_NEW_INDUSTRY : STR_FUND_NEW_INDUSTRY;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   160
			}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   161
			SetWindowWidgetDisabledState(w, DYNA_INDU_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
   162
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   163
			SetVScrollCount(w, _fund_gui.count);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   164
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   165
			DrawWindowWidgets(w);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   166
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   167
			/* and now with the matrix painting */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   168
			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
   169
				int offset = i * 13;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   170
				int x = 3;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   171
				int y = 16;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   172
				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
   173
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   174
				if (_fund_gui.index[i + w->vscroll.pos] == INVALID_INDUSTRYTYPE) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   175
					DrawString(21, y + offset, STR_MANY_RANDOM_INDUSTRIES, selected ? 12 : 6);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   176
					continue;
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
				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
   179
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   180
				/* Draw the name of the industry in white is selected, otherwise, in orange */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   181
				DrawString(20,     y + offset, indsp->name, selected ? 12 : 6);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   182
				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
   183
				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
   184
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   185
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   186
			if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   187
				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
   188
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   189
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   190
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   191
			if (_game_mode != GM_EDITOR) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   192
				SetDParam(0, indsp->GetConstructionCost());
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   193
				DrawStringTruncated(x_str, y_str, STR_482F_COST, 0, max_width);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   194
				y_str += 11;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   195
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   196
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   197
			/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   198
			if (indsp->accepts_cargo[0] != CT_INVALID) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   199
				SetDParam(0, GetCargo(indsp->accepts_cargo[0])->name);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   200
				if (indsp->accepts_cargo[1] != CT_INVALID) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   201
					SetDParam(1, GetCargo(indsp->accepts_cargo[1])->name);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   202
					str = STR_4828_REQUIRES;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   203
					if (indsp->accepts_cargo[2] != CT_INVALID) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   204
						SetDParam(2, GetCargo(indsp->accepts_cargo[2])->name);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   205
						str = STR_4829_REQUIRES;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   206
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   207
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   208
			} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   209
				SetDParam(0, STR_00D0_NOTHING);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   210
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   211
			DrawStringTruncated(x_str, y_str, str, 0, max_width);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   212
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   213
			y_str += 11;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   214
			/* 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
   215
			str = STR_4827_PRODUCES;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   216
			if (indsp->produced_cargo[0] != CT_INVALID) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   217
				SetDParam(0, GetCargo(indsp->produced_cargo[0])->name);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   218
				if (indsp->produced_cargo[1] != CT_INVALID) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   219
					SetDParam(1, GetCargo(indsp->produced_cargo[1])->name);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   220
					str = STR_4828_PRODUCES;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   221
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   222
			} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   223
				SetDParam(0, STR_00D0_NOTHING);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   224
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   225
			DrawStringTruncated(x_str, y_str, str, 0, max_width);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   226
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   227
			/* 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
   228
			if (_fund_gui.text[WP(w, fnd_d).index] == STR_NULL) {   // Have i been called already?
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   229
				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
   230
					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
   231
					if (callback_res != CALLBACK_FAILED) {  // Did it failed?
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   232
						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
   233
						_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
   234
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   235
				}
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
			y_str += 11;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   239
			/* 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
   240
			 * Otherwhise, will print Nothing */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   241
			str = _fund_gui.text[WP(w, fnd_d).index];
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   242
			if (str != STR_NULL && str != STR_UNDEFINED) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   243
				SetDParam(0, str);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   244
				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
   245
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   246
		} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   247
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   248
		case WE_CLICK:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   249
			switch (e->we.click.widget) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   250
				case DYNA_INDU_MATRIX_WIDGET: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   251
					const IndustrySpec *indsp;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   252
					int y = (e->we.click.pt.y - w->widget[DYNA_INDU_MATRIX_WIDGET].top) / 13 + w->vscroll.pos ;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   253
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   254
					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
   255
						WP(w, fnd_d).index = y;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   256
						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
   257
						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
   258
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   259
						SetWindowDirty(w);
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   260
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   261
						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
   262
								WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   263
							/* Reset the button state if going to prospecting or "build many industries" */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   264
							RaiseWindowButtons(w);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   265
							ResetObjectToPlace();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   266
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   267
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   268
				} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   269
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   270
				case DYNA_INDU_FUND_WIDGET: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   271
					if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   272
						HandleButtonClick(w, DYNA_INDU_FUND_WIDGET);
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
						if (GetNumTowns() == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   275
							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
   276
						} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   277
							extern void GenerateIndustries();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   278
							_generating_world = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   279
							GenerateIndustries();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   280
							_generating_world = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   281
						}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   282
					} else if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && GetIndustrySpec(WP(w, fnd_d).select)->IsRawIndustry()) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   283
						DoCommandP(0, WP(w, fnd_d).select, 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   284
						HandleButtonClick(w, DYNA_INDU_FUND_WIDGET);
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   285
					} else {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   286
						HandlePlacePushButton(w, DYNA_INDU_FUND_WIDGET, SPR_CURSOR_INDUSTRY, 1, NULL);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   287
					}
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   288
				} break;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   289
			}
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   290
			break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   291
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   292
		case WE_RESIZE: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   293
			/* 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
   294
			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   295
			w->widget[DYNA_INDU_MATRIX_WIDGET].data = (w->vscroll.cap << 8) + 1;
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_PLACE_OBJ: {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   299
			/* 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
   300
			const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   301
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   302
			if (_game_mode == GM_EDITOR) {
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   303
				/* Show error if no town exists at all */
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   304
				if (GetNumTowns() == 0) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   305
					SetDParam(0, indsp->name);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   306
					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
   307
					return;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   308
				}
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
				_current_player = OWNER_NONE;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   311
				_generating_world = true;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   312
				_ignore_restrictions = true;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   313
				if (!TryBuildIndustry(e->we.place.tile, WP(w, fnd_d).select)) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   314
					SetDParam(0, indsp->name);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   315
					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
   316
				}
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   317
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   318
				_ignore_restrictions = false;
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   319
				_generating_world = false;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   320
			} else DoCommandP(e->we.place.tile, WP(w, fnd_d).select, 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   321
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   322
			/* Whatever the outcome of the actions, just reset the cursor and the system */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   323
			ResetObjectToPlace();
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   324
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   326
		case WE_TICK:
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   327
			if (!WP(w, fnd_d).timer_enabled) break;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   328
			if (--WP(w, fnd_d).callback_timer == 0) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   329
				/* We have just passed another day.
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   330
				 * 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
   331
				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
   332
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   333
				const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   334
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   335
				if (indsp->enabled) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   336
					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
   337
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   338
					/* 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
   339
					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
   340
						_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
   341
						SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   342
					}
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   343
				}
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   344
			}
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   345
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   346
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   347
		case WE_TIMEOUT:
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   348
		case WE_ABORT_PLACE_OBJ:
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   349
			RaiseWindowButtons(w);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6720
diff changeset
   350
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   354
static const Widget _build_dynamic_industry_widgets[] = {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   355
{   WWT_CLOSEBOX,    RESIZE_NONE,    7,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   356
{    WWT_CAPTION,   RESIZE_RIGHT,    7,    11,   169,     0,    13, STR_0314_FUND_NEW_INDUSTRY,     STR_018C_WINDOW_TITLE_DRAG_THIS},
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   357
{     WWT_MATRIX,      RESIZE_RB,    7,     0,   157,    14,   118, 0x801,                          STR_INDUSTRY_SELECTION_HINT},
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   358
{  WWT_SCROLLBAR,     RESIZE_LRB,    7,   158,   169,    14,   118, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST},
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   359
{      WWT_PANEL,     RESIZE_RTB,    7,     0,   169,   119,   199, 0x0,                            STR_NULL},
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   360
{    WWT_TEXTBTN,     RESIZE_RTB,    7,     0,   157,   200,   211, STR_FUND_NEW_INDUSTRY,          STR_NULL},
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   361
{  WWT_RESIZEBOX,    RESIZE_LRTB,    7,   158,   169,   200,   211, 0x0,                            STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   362
{   WIDGETS_END},
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
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   365
static const WindowDesc _build_industry_dynamic_desc = {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   366
	WDP_AUTO, WDP_AUTO, 170, 212,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5860
diff changeset
   367
	WC_BUILD_INDUSTRY, WC_NONE,
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   368
	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
   369
	_build_dynamic_industry_widgets,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   370
	BuildDynamicIndustryWndProc,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   373
void ShowBuildIndustryWindow()
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   374
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   375
	if (_game_mode != GM_EDITOR && !IsValidPlayer(_current_player)) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   376
	AllocateWindowDescFront(&_build_industry_dynamic_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   379
static void UpdateIndustryProduction(Industry *i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   380
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   381
static inline bool isProductionMinimum(const Industry *i, int pt)
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   382
{
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   383
	return i->production_rate[pt] == 1;
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   384
}
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   385
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   386
static inline bool isProductionMaximum(const Industry *i, int pt)
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   387
{
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   388
	return i->production_rate[pt] == 255;
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   389
}
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   390
4194
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   391
static inline bool IsProductionAlterable(const Industry *i)
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   392
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   393
	const IndustrySpec *ind = GetIndustrySpec(i->type);
4194
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   394
	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   395
			(ind->accepts_cargo[0] == CT_INVALID || ind->accepts_cargo[0] == CT_VALUABLES));
4194
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   396
}
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   397
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   398
/** Information to store about the industry window */
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   399
struct indview_d : public vp_d {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   400
	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
   401
	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
   402
	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
   403
	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
   404
};
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   405
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(indview_d));
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   406
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   407
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
static void IndustryViewWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
   410
	switch (e->event) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   411
	case WE_CREATE: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   412
		/* Count the number of lines that we need to resize the GUI with */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   413
		const IndustrySpec *ind = GetIndustrySpec(GetIndustry(w->window_number)->type);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   414
		int lines = -3;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   415
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   416
		if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   417
			for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   418
				if (j == 0) lines++;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   419
				lines++;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   420
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   421
		} else if (ind->accepts_cargo[0] != CT_INVALID) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   422
			lines++;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   423
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   424
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   425
		for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   426
			if (j == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   427
				if (ind->accepts_cargo[0] != CT_INVALID) lines++;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   428
				lines++;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   429
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   430
			lines++;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   431
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   432
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   433
		if (HASBIT(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) lines += 2;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   434
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   435
		for (uint j = 5; j <= 7; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   436
			if (j != 5) w->widget[j].top += lines * 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   437
			w->widget[j].bottom += lines * 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   438
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   439
		w->height += lines * 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   440
	} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   441
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   442
	case WE_PAINT: {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   443
		Industry *i = GetIndustry(w->window_number);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   444
		const IndustrySpec *ind = GetIndustrySpec(i->type);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   445
		int y = 111;
2557
3ed00023e382 (svn r3090) Remove long dead pieces of code
tron
parents: 2469
diff changeset
   446
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   447
		SetDParam(0, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
		DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   450
		if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   451
			for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   452
				if (j == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   453
					DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   454
					y += 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   455
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   456
				SetDParam(0, ind->accepts_cargo[j]);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   457
				SetDParam(1, i->incoming_cargo_waiting[j]);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   458
				DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0);
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
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   461
		} else if (ind->accepts_cargo[0] != CT_INVALID) {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   462
			StringID str;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   463
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   464
			SetDParam(0, GetCargo(ind->accepts_cargo[0])->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
			str = STR_4827_REQUIRES;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   466
			if (ind->accepts_cargo[1] != CT_INVALID) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   467
				SetDParam(1, GetCargo(ind->accepts_cargo[1])->name);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   468
				str = STR_4828_REQUIRES;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   469
				if (ind->accepts_cargo[2] != CT_INVALID) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   470
					SetDParam(2, GetCargo(ind->accepts_cargo[2])->name);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   471
					str = STR_4829_REQUIRES;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
			}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   474
			DrawString(2, y, str, 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   475
			y += 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   477
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   478
		for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   479
			if (j == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   480
				if (ind->accepts_cargo[0] != CT_INVALID) y += 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   481
				DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   482
				y += 10;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   483
				WP(w, indview_d).production_offset_y = y;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   484
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   486
			SetDParam(0, ind->produced_cargo[j]);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   487
			SetDParam(1, i->last_month_production[j]);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 1981
diff changeset
   488
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   489
			SetDParam(2, i->last_month_pct_transported[j] * 100 >> 8);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   490
			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, 0);
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
   491
			/* Let's put out those buttons.. */
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   492
			if (IsProductionAlterable(i)) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   493
				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
   494
						!isProductionMinimum(i, j), !isProductionMaximum(i, j));
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   495
			}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   496
			y += 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   497
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   499
		/* Get the extra message for the GUI */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   500
		if (HASBIT(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   501
			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
   502
			if (callback_res != CALLBACK_FAILED) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   503
				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
   504
				if (message != STR_NULL && message != STR_UNDEFINED) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   505
					y += 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   506
					DrawString(2, y, message, 0);
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   507
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
		DrawWindowViewport(w);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   512
	} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   514
	case WE_CLICK: {
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   515
		Industry *i;
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   516
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4617
diff changeset
   517
		switch (e->we.click.widget) {
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   518
		case 5: {
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   519
			int line, x;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   520
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   521
			i = GetIndustry(w->window_number);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   522
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
   523
			/* We should work if needed.. */
4194
18a32dace8ba (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   524
			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
   525
			x = e->we.click.pt.x;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   526
			line = (e->we.click.pt.y - WP(w, indview_d).production_offset_y) / 10;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   527
			if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IS_INT_INSIDE(line, 0, 2) &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   528
					GetIndustrySpec(i->type)->produced_cargo[line] != CT_INVALID) {
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1004
diff changeset
   529
				if (IS_INT_INSIDE(x, 5, 25) ) {
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   530
					/* Clicked buttons, decrease or increase production */
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1004
diff changeset
   531
					if (x < 15) {
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   532
						if (isProductionMinimum(i, line)) return;
5852
cb3f71b16e1a (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5838
diff changeset
   533
						i->production_rate[line] = max(i->production_rate[line] / 2, 1);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   534
					} else {
4211
d8c4c40eba62 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   535
						if (isProductionMaximum(i, line)) return;
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   536
						i->production_rate[line] = minu(i->production_rate[line] * 2, 255);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   537
					}
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   538
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   539
					UpdateIndustryProduction(i);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   540
					SetWindowDirty(w);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   541
					w->flags4 |= 5 << WF_TIMEOUT_SHL;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   542
					WP(w, indview_d).clicked_line = line + 1;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   543
					WP(w, indview_d).clicked_button = (x < 15 ? 1 : 2);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   544
				} else if (IS_INT_INSIDE(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
   545
					/* clicked the text */
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   546
					WP(w, indview_d).editbox_line = line;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   547
					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
   548
					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
   549
				}
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 1004
diff changeset
   550
			}
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   551
		} break;
758
bd9e868b9fae (svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents: 727
diff changeset
   552
		case 6:
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   553
			i = GetIndustry(w->window_number);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1914
diff changeset
   554
			ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   555
		} break;
4193
ef08dda0369e (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   556
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   557
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		break;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   559
	case WE_TIMEOUT:
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   560
		WP(w, indview_d).clicked_line = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   561
		WP(w, indview_d).clicked_button = 0;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   562
		SetWindowDirty(w);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   563
		break;
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   564
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   565
	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
   566
		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
   567
			Industry* i = GetIndustry(w->window_number);
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   568
			int line = WP(w, indview_d).editbox_line;
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   569
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4617
diff changeset
   570
			i->production_rate[line] = clampu(atoi(e->we.edittext.str), 0, 255);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   571
			UpdateIndustryProduction(i);
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   572
			SetWindowDirty(w);
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   577
static void UpdateIndustryProduction(Industry *i)
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   578
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   579
	const IndustrySpec *ind = GetIndustrySpec(i->type);
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   580
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   581
	for (byte j = 0; j < lengthof(ind->produced_cargo); j++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   582
		if (ind->produced_cargo[j] != CT_INVALID) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   583
			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
   584
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   585
	}
1004
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   586
}
edbdc62fbf24 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   587
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
static const Widget _industry_view_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   589
{   WWT_CLOSEBOX,   RESIZE_NONE,     9,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   590
{    WWT_CAPTION,   RESIZE_NONE,     9,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   591
{  WWT_STICKYBOX,   RESIZE_NONE,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   592
{      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,    14,   105, 0x0,               STR_NULL},
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   593
{      WWT_INSET,   RESIZE_NONE,     9,     2,   257,    16,   103, 0x0,               STR_NULL},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   594
{      WWT_PANEL,   RESIZE_NONE,     9,     0,   259,   106,   147, 0x0,               STR_NULL},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   595
{ WWT_PUSHTXTBTN,   RESIZE_NONE,     9,     0,   129,   148,   159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   596
{      WWT_PANEL,   RESIZE_NONE,     9,   130,   259,   148,   159, 0x0,               STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   597
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
static const WindowDesc _industry_view_desc = {
5070
0bbf5264bfb7 (svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents: 5005
diff changeset
   601
	WDP_AUTO, WDP_AUTO, 260, 160,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5860
diff changeset
   602
	WC_INDUSTRY_VIEW, WC_NONE,
758
bd9e868b9fae (svn r1214) -Feature: Stickified Industries (list & window), Smallmaps (all three), Stations (list & window) and Towns (list & window). I hope I didn't forget to update a widget somewhere :O
darkvater
parents: 727
diff changeset
   603
	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
   604
	_industry_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
	IndustryViewWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
void ShowIndustryViewWindow(int industry)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3689
diff changeset
   610
	Window *w = AllocateWindowDescFront(&_industry_view_desc, industry);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   612
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
		w->flags4 |= WF_DISABLE_VP_SCROLL;
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   614
		WP(w, indview_d).editbox_line = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   615
		WP(w, indview_d).clicked_line = 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   616
		WP(w, indview_d).clicked_button = 0;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   617
		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
   618
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   621
enum {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   622
	DIRECTORY_INDU_SORTBYNAME = 3,
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   623
	DIRECTORY_INDU_SORTBYTYPE,
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   624
	DIRECTORY_INDU_SORTBYPROD,
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   625
	DIRECTORY_INDU_SORTBYTRANSPORT,
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   626
	DIRECTORY_INDU_SHOWINDU = 8,
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   627
};
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   628
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
static const Widget _industry_directory_widgets[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   630
{   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   631
{    WWT_CAPTION,   RESIZE_NONE,    13,    11,   495,     0,    13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   632
{  WWT_STICKYBOX,   RESIZE_NONE,    13,   496,   507,     0,    13, 0x0,                     STR_STICKY_BUTTON},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   633
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,   100,    14,    25, STR_SORT_BY_NAME,        STR_SORT_ORDER_TIP},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   634
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   101,   200,    14,    25, STR_SORT_BY_TYPE,        STR_SORT_ORDER_TIP},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   635
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   201,   300,    14,    25, STR_SORT_BY_PRODUCTION,  STR_SORT_ORDER_TIP},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   636
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    13,   301,   400,    14,    25, STR_SORT_BY_TRANSPORTED, STR_SORT_ORDER_TIP},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   637
{      WWT_PANEL,   RESIZE_NONE,    13,   401,   495,    14,    25, 0x0,                     STR_NULL},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   638
{      WWT_PANEL, RESIZE_BOTTOM,    13,     0,   495,    26,   189, 0x0,                     STR_200A_TOWN_NAMES_CLICK_ON_NAME},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   639
{  WWT_SCROLLBAR, RESIZE_BOTTOM,    13,   496,   507,    14,   177, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4299
diff changeset
   640
{  WWT_RESIZEBOX,     RESIZE_TB,    13,   496,   507,   178,   189, 0x0,                     STR_RESIZE_BUTTON},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   641
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
static uint _num_industry_sort;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
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
   647
static const Industry* _last_industry;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
static byte _industry_sort_order;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
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
   651
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
   652
{
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
   653
	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
   654
	const Industry* j = *(const Industry**)b;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   655
	const IndustrySpec *ind_i = GetIndustrySpec(i->type);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   656
	const IndustrySpec *ind_j = GetIndustrySpec(j->type);
4282
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   657
	int r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	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
   660
		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
   661
		case 0: /* Sort by Name (handled later) */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
			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
   663
			break;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   664
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   665
		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
   666
			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
   667
			break;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   668
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   669
		case 2: /* Sort by Production */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   670
			if (ind_i->produced_cargo[0] == CT_INVALID) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   671
				r = (ind_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
   672
			} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   673
				if (ind_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
   674
					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
   675
				} else {
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   676
					r =
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   677
						(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
   678
						(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
   679
				}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   680
			}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   681
			break;
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   682
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 3: /* Sort by transported fraction */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   684
			if (ind_i->produced_cargo[0] == CT_INVALID) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   685
				r = (ind_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
   686
			} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   687
				if (ind_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
   688
					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
   689
				} else {
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   690
					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
   691
					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
   692
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   693
					pi = i->last_month_pct_transported[0] * 100 >> 8;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   694
					if (ind_i->produced_cargo[1] != CT_INVALID) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   695
						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
   696
						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
   697
					}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   698
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   699
					pj = j->last_month_pct_transported[0] * 100 >> 8;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   700
					if (ind_j->produced_cargo[1] != CT_INVALID) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   701
						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
   702
						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
   703
					}
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
					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
   706
				}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   707
			}
cd0af1cdc454 (svn r5912) -Fix: Sort order for produced amount and transported percentage was reversed in the industry list
tron
parents: 4277
diff changeset
   708
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
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
   711
	/* 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
   712
	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
   713
		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
   714
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   715
		SetDParam(0, i->town->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   716
		GetString(buf1, STR_TOWN, lastof(buf1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
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
   718
		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
   719
			_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
   720
			SetDParam(0, j->town->index);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
   721
			GetString(_bufcache, STR_TOWN, lastof(_bufcache));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
		r = strcmp(buf1, _bufcache);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   725
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   726
	if (_industry_sort_order & 1) r = -r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
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
   730
/**
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
   731
 * 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
   732
 * 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
   733
 * 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
   734
 * 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
   735
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   736
static void MakeSortedIndustryList()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
{
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
   738
	const Industry* i;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   739
	int n = 0;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   740
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   741
	/* 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
   742
	_industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5247
diff changeset
   743
	if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
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
   745
	/* 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
   746
	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
   747
		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
   748
		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
   749
	}
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   750
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
	_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
   752
	_last_industry = NULL; // used for "cache"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5247
diff changeset
   754
	DEBUG(misc, 3, "Resorting industries list");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
   760
	switch (e->event) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
	case WE_PAINT: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
		int n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
		uint p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
		static const uint16 _indicator_positions[4] = {88, 187, 284, 387};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
		if (_industry_sort_dirty) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
			_industry_sort_dirty = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
			MakeSortedIndustryList();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
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
   771
		SetVScrollCount(w, _num_industry_sort);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
		DrawWindowWidgets(w);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   774
		DoDrawString(_industry_sort_order & 1 ? DOWNARROW : UPARROW, _indicator_positions[_industry_sort_order >> 1], 15, 0x10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
		p = w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
		n = 0;
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
		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
   780
			const Industry* i = _industry_sort[p];
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   781
			const IndustrySpec *ind = GetIndustrySpec(i->type);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   782
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   783
			SetDParam(0, i->index);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   784
			if (ind->produced_cargo[0] != CT_INVALID) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   785
				SetDParam(1, ind->produced_cargo[0]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   786
				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
   787
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   788
				if (ind->produced_cargo[1] != CT_INVALID) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   789
					SetDParam(3, ind->produced_cargo[1]);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   790
					SetDParam(4, i->last_month_production[1]);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   791
					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
   792
					SetDParam(6, i->last_month_pct_transported[1] * 100 >> 8);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   793
					DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_TWO, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   795
					SetDParam(3, i->last_month_pct_transported[0] * 100 >> 8);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   796
					DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
			} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6573
diff changeset
   799
				DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_NOPROD, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
			p++;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2866
diff changeset
   802
			if (++n == w->vscroll.cap) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
	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
   807
		switch (e->we.click.widget) {
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   808
			case DIRECTORY_INDU_SORTBYNAME: {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   809
				_industry_sort_order = _industry_sort_order == 0 ? 1 : 0;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   810
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   811
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   812
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   814
			case DIRECTORY_INDU_SORTBYTYPE: {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   815
				_industry_sort_order = _industry_sort_order == 2 ? 3 : 2;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   816
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   817
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   818
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   820
			case DIRECTORY_INDU_SORTBYPROD: {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   821
				_industry_sort_order = _industry_sort_order == 4 ? 5 : 4;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   822
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   823
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   824
			} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   825
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   826
			case DIRECTORY_INDU_SORTBYTRANSPORT: {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   827
				_industry_sort_order = _industry_sort_order == 6 ? 7 : 6;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   828
				_industry_sort_dirty = true;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   829
				SetWindowDirty(w);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   830
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   832
			case DIRECTORY_INDU_SHOWINDU: {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   833
				int y = (e->we.click.pt.y - 28) / 10;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   834
				uint16 p;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   835
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   836
				if (!IS_INT_INSIDE(y, 0, w->vscroll.cap)) return;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   837
				p = y + w->vscroll.pos;
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   838
				if (p < _num_industry_sort) {
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   839
					ScrollMainWindowToTile(_industry_sort[p]->xy);
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   840
				}
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6730
diff changeset
   841
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	case WE_4:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
		break;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   848
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   849
	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
   850
		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
   851
		break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   852
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
/* Industry List */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
static const WindowDesc _industry_directory_desc = {
5070
0bbf5264bfb7 (svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents: 5005
diff changeset
   858
	WDP_AUTO, WDP_AUTO, 508, 190,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5860
diff changeset
   859
	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
   860
	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
   861
	_industry_directory_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	IndustryDirectoryWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   866
void ShowIndustryDirectory()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
{
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 3689
diff changeset
   868
	Window *w = AllocateWindowDescFront(&_industry_directory_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   870
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
		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
   872
		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
   873
		w->resize.step_height = 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
}