src/industry_gui.cpp
author belugas
Wed, 06 Aug 2008 04:01:07 +0000
changeset 9858 c8e0746a5945
parent 9777 5c14eb4bb2bc
child 10145 849ba8b8626b
permissions -rw-r--r--
(svn r14003) -Codechange: Replace numbers with Colours enum opn some DrawArrowButtons calls
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9110
diff changeset
     3
/** @file industry_gui.cpp GUIs related to industries. */
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6200
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1786
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1287
diff changeset
     7
#include "debug.h"
1386
0de4f8541aea (svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents: 1309
diff changeset
     8
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
     9
#include "window_gui.h"
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    10
#include "textbuf_gui.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    11
#include "command_func.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8179
diff changeset
    12
#include "viewport_func.h"
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8179
diff changeset
    13
#include "gfx_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "town.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2084
diff changeset
    16
#include "variables.h"
8965
29a591456a2f (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 8779
diff changeset
    17
#include "cheat_func.h"
6091
c8827d9ae04a (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: 5893
diff changeset
    18
#include "cargotype.h"
7195
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7185
diff changeset
    19
#include "newgrf.h"
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7185
diff changeset
    20
#include "newgrf_callbacks.h"
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7185
diff changeset
    21
#include "newgrf_industries.h"
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7185
diff changeset
    22
#include "newgrf_text.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    23
#include "strings_func.h"
8139
4e91c448c409 (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8131
diff changeset
    24
#include "map_func.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8237
diff changeset
    25
#include "player_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    26
#include "settings_type.h"
9127
14f21c5954ee (svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents: 9116
diff changeset
    27
#include "tilehighlight_func.h"
9164
18e971e0b44f (svn r13027) -Codechange: use StrEmpty instead of arr[0] == '\0' and remove the need for WE_ON_EDIT_TEXT_CANCEL.
rubidium
parents: 9161
diff changeset
    28
#include "string_func.h"
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
    29
#include "sortlist_type.h"
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
    30
#include "widgets/dropdown_func.h"
9659
187142ff9b6c (svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents: 9652
diff changeset
    31
#include "player_base.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    33
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    34
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    35
7218
8e73038b7586 (svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents: 7195
diff changeset
    36
bool _ignore_restrictions;
8e73038b7586 (svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents: 7195
diff changeset
    37
9104
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    38
enum CargoSuffixType {
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    39
	CST_FUND,
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    40
	CST_VIEW,
9105
7409216f1656 (svn r12965) -Codechange: add support for callback 37 in industries directory window
glx
parents: 9104
diff changeset
    41
	CST_DIR,
9104
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    42
};
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    43
8759
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    44
/**
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    45
 * Gets the string to display after the cargo name (using callback 37)
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    46
 * @param cargo the cargo for which the suffix is requested
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    47
 * - 00 - first accepted cargo type
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    48
 * - 01 - second accepted cargo type
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    49
 * - 02 - third accepted cargo type
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    50
 * - 03 - first produced cargo type
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    51
 * - 04 - second produced cargo type
9104
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    52
 * @param cst the cargo suffix type (for which window is it requested)
8759
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    53
 * @param ind the industry (NULL if in fund window)
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    54
 * @param ind_type the industry type
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    55
 * @param indspec the industry spec
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    56
 * @return the string to display
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    57
 */
9104
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    58
static StringID GetCargoSuffix(uint cargo, CargoSuffixType cst, Industry *ind, IndustryType ind_type, const IndustrySpec *indspec)
8759
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    59
{
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    60
	if (HasBit(indspec->callback_flags, CBM_IND_CARGO_SUFFIX)) {
9104
deb34792f84d (svn r12964) -Codechange: rewrite callback 37 related code so it will be easier to add supported windows
glx
parents: 9099
diff changeset
    61
		uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, ind, ind_type, (cst != CST_FUND) ? ind->xy : INVALID_TILE);
9019
fe04abd3f58f (svn r12818) -Codechange: make callbacks 31 and 37 behave like they do in TTDP according to frosch's survey.
rubidium
parents: 8994
diff changeset
    62
		if (GB(callback, 0, 8) != 0xFF) return GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback);
8759
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    63
	}
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    64
	return STR_EMPTY;
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    65
}
dc74629e649f (svn r12455) -Codechange: Implement NewGRF callback 37 (cargo sub-type display for industries)
glx
parents: 8476
diff changeset
    66
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    67
/** Names of the widgets of the dynamic place industries gui */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    68
enum DynamicPlaceIndustriesWidgets {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    69
	DPIW_CLOSEBOX = 0,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    70
	DPIW_CAPTION,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    71
	DPIW_MATRIX_WIDGET,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    72
	DPIW_SCROLLBAR,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    73
	DPIW_INFOPANEL,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    74
	DPIW_FUND_WIDGET,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    75
	DPIW_RESIZE_WIDGET,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    76
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
    78
/** Widget definition of the dynamic place industries gui */
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    79
static const Widget _build_industry_widgets[] = {
9744
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
    80
{   WWT_CLOSEBOX,    RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},            // DPIW_CLOSEBOX
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
    81
{    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_DARK_GREEN,    11,   169,     0,    13, STR_0314_FUND_NEW_INDUSTRY,     STR_018C_WINDOW_TITLE_DRAG_THIS},  // DPIW_CAPTION
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
    82
{     WWT_MATRIX,      RESIZE_RB,  COLOUR_DARK_GREEN,     0,   157,    14,   118, 0x801,                          STR_INDUSTRY_SELECTION_HINT},      // DPIW_MATRIX_WIDGET
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
    83
{  WWT_SCROLLBAR,     RESIZE_LRB,  COLOUR_DARK_GREEN,   158,   169,    14,   118, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DPIW_SCROLLBAR
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
    84
{      WWT_PANEL,     RESIZE_RTB,  COLOUR_DARK_GREEN,     0,   169,   119,   199, 0x0,                            STR_NULL},                         // DPIW_INFOPANEL
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
    85
{    WWT_TEXTBTN,     RESIZE_RTB,  COLOUR_DARK_GREEN,     0,   157,   200,   211, STR_FUND_NEW_INDUSTRY,          STR_NULL},                         // DPIW_FUND_WIDGET
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
    86
{  WWT_RESIZEBOX,    RESIZE_LRTB,  COLOUR_DARK_GREEN,   158,   169,   200,   211, 0x0,                            STR_RESIZE_BUTTON},                // DPIW_RESIZE_WIDGET
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
    87
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
    90
/** Window definition of the dynamic place industries gui */
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    91
static const WindowDesc _build_industry_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7319
diff changeset
    92
	WDP_AUTO, WDP_AUTO, 170, 212, 170, 212,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5609
diff changeset
    93
	WC_BUILD_INDUSTRY, WC_NONE,
7218
8e73038b7586 (svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents: 7195
diff changeset
    94
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    95
	_build_industry_widgets,
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    96
};
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    97
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    98
class BuildIndustryWindow : public Window {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
    99
	int selected_index;                         ///< index of the element in the matrix
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   100
	IndustryType selected_type;                 ///< industry corresponding to the above index
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   101
	uint16 callback_timer;                      ///< timer counter for callback eventual verification
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   102
	bool timer_enabled;                         ///< timer can be used
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   103
	uint16 count;                               ///< How many industries are loaded
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   104
	IndustryType index[NUM_INDUSTRYTYPES + 1];  ///< Type of industry, in the order it was loaded
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   105
	StringID text[NUM_INDUSTRYTYPES + 1];       ///< Text coming from CBM_IND_FUND_MORE_TEXT (if ever)
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   106
	bool enabled[NUM_INDUSTRYTYPES + 1];        ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   107
9194
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   108
	void SetupArrays()
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   109
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   110
		IndustryType ind;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   111
		const IndustrySpec *indsp;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   112
9194
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   113
		this->count = 0;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   114
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   115
		for (uint i = 0; i < lengthof(this->index); i++) {
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   116
			this->index[i]   = INVALID_INDUSTRYTYPE;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   117
			this->text[i]    = STR_NULL;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   118
			this->enabled[i] = false;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   119
		}
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   120
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   121
		if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   122
			this->index[this->count] = INVALID_INDUSTRYTYPE;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   123
			this->count++;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   124
			this->timer_enabled = false;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   125
		}
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   126
		/* Fill the arrays with industries.
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   127
		 * The tests performed after the enabled allow to load the industries
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   128
		 * In the same way they are inserted by grf (if any)
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   129
		 */
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   130
		for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   131
			indsp = GetIndustrySpec(ind);
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   132
			if (indsp->enabled){
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   133
				/* Rule is that editor mode loads all industries.
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   134
				 * In game mode, all non raw industries are loaded too
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   135
				 * and raw ones are loaded only when setting allows it */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9400
diff changeset
   136
				if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
9194
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   137
					/* Unselect if the industry is no longer in the list */
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   138
					if (this->selected_type == ind) this->selected_index = -1;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   139
					continue;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   140
				}
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   141
				this->index[this->count] = ind;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   142
				this->enabled[this->count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   143
				/* Keep the selection to the correct line */
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   144
				if (this->selected_type == ind) this->selected_index = this->count;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   145
				this->count++;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   146
			}
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   147
		}
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   148
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   149
		/* first indutry type is selected if the current selection is invalid.
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   150
		 * I'll be damned if there are none available ;) */
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   151
		if (this->selected_index == -1) {
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   152
			this->selected_index = 0;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   153
			this->selected_type = this->index[0];
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   154
		}
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   155
	}
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   156
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   157
public:
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   158
	BuildIndustryWindow() : Window(&_build_industry_desc)
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   159
	{
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   160
		/* Shorten the window to the equivalant of the additionnal purchase
9194
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   161
		 * info coming from the callback.  SO it will only be available to its full
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   162
		 * height when newindistries are loaded */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   163
		if (!_loaded_newgrf_features.has_newindustries) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   164
			this->widget[DPIW_INFOPANEL].bottom -= 44;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   165
			this->widget[DPIW_FUND_WIDGET].bottom -= 44;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   166
			this->widget[DPIW_FUND_WIDGET].top -= 44;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   167
			this->widget[DPIW_RESIZE_WIDGET].bottom -= 44;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   168
			this->widget[DPIW_RESIZE_WIDGET].top -= 44;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   169
			this->resize.height = this->height -= 44;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   170
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   171
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   172
		this->timer_enabled = _loaded_newgrf_features.has_newindustries;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   174
		this->vscroll.cap = 8; // rows in grid, same in scroller
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   175
		this->resize.step_height = 13;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   176
9194
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   177
		this->selected_index = -1;
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   178
		this->selected_type = INVALID_INDUSTRYTYPE;
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   179
9194
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   180
		/* Initialize arrays */
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   181
		this->SetupArrays();
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   182
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   183
		this->callback_timer = DAY_TICKS;
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9173
diff changeset
   184
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9173
diff changeset
   185
		this->FindWindowPlacementAndResize(&_build_industry_desc);
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   186
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   187
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   188
	virtual void OnPaint()
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   189
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   190
		const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   191
		int x_str = this->widget[DPIW_INFOPANEL].left + 3;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   192
		int y_str = this->widget[DPIW_INFOPANEL].top + 3;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   193
		const Widget *wi = &this->widget[DPIW_INFOPANEL];
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   194
		int max_width = wi->right - wi->left - 4;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   195
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   196
		/* Raw industries might be prospected. Show this fact by changing the string
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   197
		 * In Editor, you just build, while ingame, or you fund or you prospect */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   198
		if (_game_mode == GM_EDITOR) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   199
			/* We've chosen many random industries but no industries have been specified */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9400
diff changeset
   200
			if (indsp == NULL) this->enabled[this->selected_index] = _settings_game.difficulty.number_industries != 0;
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   201
			this->widget[DPIW_FUND_WIDGET].data = STR_BUILD_NEW_INDUSTRY;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   202
		} else {
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9400
diff changeset
   203
			this->widget[DPIW_FUND_WIDGET].data = (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_PROSPECT_NEW_INDUSTRY : STR_FUND_NEW_INDUSTRY;
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   204
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   205
		this->SetWidgetDisabledState(DPIW_FUND_WIDGET, !this->enabled[this->selected_index]);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   206
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   207
		SetVScrollCount(this, this->count);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   208
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9203
diff changeset
   209
		this->DrawWidgets();
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   210
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   211
		/* and now with the matrix painting */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   212
		for (byte i = 0; i < this->vscroll.cap && ((i + this->vscroll.pos) < this->count); i++) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   213
			int offset = i * 13;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   214
			int x = 3;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   215
			int y = 16;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   216
			bool selected = this->selected_index == i + this->vscroll.pos;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   217
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   218
			if (this->index[i + this->vscroll.pos] == INVALID_INDUSTRYTYPE) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   219
				DrawStringTruncated(20, y + offset, STR_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE, max_width - 25);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   220
				continue;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   221
			}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   222
			const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll.pos]);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   223
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   224
			/* Draw the name of the industry in white is selected, otherwise, in orange */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   225
			DrawStringTruncated(20, y + offset, indsp->name, selected ? TC_WHITE : TC_ORANGE, max_width - 25);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   226
			GfxFillRect(x,     y + 1 + offset,  x + 10, y + 7 + offset, selected ? 15 : 0);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   227
			GfxFillRect(x + 1, y + 2 + offset,  x +  9, y + 6 + offset, indsp->map_colour);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   228
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   229
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   230
		if (this->selected_type == INVALID_INDUSTRYTYPE) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   231
			DrawStringMultiLine(x_str, y_str, STR_RANDOM_INDUSTRIES_TIP, max_width, wi->bottom - wi->top - 40);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   232
			return;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   233
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   234
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   235
		if (_game_mode != GM_EDITOR) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   236
			SetDParam(0, indsp->GetConstructionCost());
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   237
			DrawStringTruncated(x_str, y_str, STR_482F_COST, TC_FROMSTRING, max_width);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   238
			y_str += 11;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   239
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   240
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   241
		/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   242
		StringID str = STR_4827_REQUIRES;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   243
		byte p = 0;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   244
		SetDParam(0, STR_00D0_NOTHING);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   245
		SetDParam(1, STR_EMPTY);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   246
		for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   247
			if (indsp->accepts_cargo[j] == CT_INVALID) continue;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   248
			if (p > 0) str++;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   249
			SetDParam(p++, GetCargo(indsp->accepts_cargo[j])->name);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   250
			SetDParam(p++, GetCargoSuffix(j, CST_FUND, NULL, this->selected_type, indsp));
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   251
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   252
		DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   253
		y_str += 11;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   254
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   255
		/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   256
		str = STR_4827_PRODUCES;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   257
		p = 0;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   258
		SetDParam(0, STR_00D0_NOTHING);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   259
		SetDParam(1, STR_EMPTY);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   260
		for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   261
			if (indsp->produced_cargo[j] == CT_INVALID) continue;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   262
			if (p > 0) str++;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   263
			SetDParam(p++, GetCargo(indsp->produced_cargo[j])->name);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   264
			SetDParam(p++, GetCargoSuffix(j + 3, CST_FUND, NULL, this->selected_type, indsp));
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   265
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   266
		DrawStringTruncated(x_str, y_str, str, TC_FROMSTRING, max_width);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   267
		y_str += 11;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   268
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   269
		/* Get the additional purchase info text, if it has not already been */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   270
		if (this->text[this->selected_index] == STR_NULL) {   // Have i been called already?
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   271
			if (HasBit(indsp->callback_flags, CBM_IND_FUND_MORE_TEXT)) {          // No. Can it be called?
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   272
				uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, NULL, this->selected_type, INVALID_TILE);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   273
				if (callback_res != CALLBACK_FAILED) {  // Did it failed?
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   274
					StringID newtxt = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res);  // No. here's the new string
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   275
					this->text[this->selected_index] = newtxt;   // Store it for further usage
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   276
				}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   277
			}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   278
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   279
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   280
		/* Draw the Additional purchase text, provided by newgrf callback, if any.
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   281
		 * Otherwhise, will print Nothing */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   282
		str = this->text[this->selected_index];
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   283
		if (str != STR_NULL && str != STR_UNDEFINED) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   284
			SetDParam(0, str);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   285
			DrawStringMultiLine(x_str, y_str, STR_JUST_STRING, max_width, wi->bottom - wi->top - 40);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   286
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   287
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   288
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   289
	virtual void OnDoubleClick(Point pt, int widget)
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   290
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   291
		if (widget != DPIW_MATRIX_WIDGET) return;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   292
		this->OnClick(pt, DPIW_FUND_WIDGET);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   293
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   294
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   295
	virtual void OnClick(Point pt, int widget)
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   296
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   297
		switch (widget) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   298
			case DPIW_MATRIX_WIDGET: {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   299
				const IndustrySpec *indsp;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   300
				int y = (pt.y - this->widget[DPIW_MATRIX_WIDGET].top) / 13 + this->vscroll.pos ;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   301
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   302
				if (y >= 0 && y < count) { // Is it within the boundaries of available data?
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   303
					this->selected_index = y;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   304
					this->selected_type = this->index[y];
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   305
					indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   306
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   307
					this->SetDirty();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   308
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9400
diff changeset
   309
					if ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != NULL && indsp->IsRawIndustry()) ||
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   310
							this->selected_type == INVALID_INDUSTRYTYPE) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   311
						/* Reset the button state if going to prospecting or "build many industries" */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   312
						this->RaiseButtons();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   313
						ResetObjectToPlace();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   314
					}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   315
				}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   316
			} break;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   317
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   318
			case DPIW_FUND_WIDGET: {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   319
				if (this->selected_type == INVALID_INDUSTRYTYPE) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   320
					this->HandleButtonClick(DPIW_FUND_WIDGET);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   321
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   322
					if (GetNumTowns() == 0) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   323
						ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   324
					} else {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   325
						extern void GenerateIndustries();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   326
						_generating_world = true;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   327
						GenerateIndustries();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   328
						_generating_world = false;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   329
					}
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9400
diff changeset
   330
				} else if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   331
					DoCommandP(0, this->selected_type, InteractiveRandom(), NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   332
					this->HandleButtonClick(DPIW_FUND_WIDGET);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   333
				} else {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   334
					HandlePlacePushButton(this, DPIW_FUND_WIDGET, SPR_CURSOR_INDUSTRY, VHM_RECT, NULL);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   335
				}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   336
			} break;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   337
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   338
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   339
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   340
	virtual void OnResize(Point new_size, Point delta)
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   341
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   342
		/* Adjust the number of items in the matrix depending of the rezise */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   343
		this->vscroll.cap  += delta.y / (int)this->resize.step_height;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   344
		this->widget[DPIW_MATRIX_WIDGET].data = (this->vscroll.cap << 8) + 1;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   345
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   346
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   347
	virtual void OnPlaceObject(Point pt, TileIndex tile)
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   348
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   349
		bool success = true;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   350
		/* We do not need to protect ourselves against "Random Many Industries" in this mode */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   351
		const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   352
		uint32 seed = InteractiveRandom();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   353
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   354
		if (_game_mode == GM_EDITOR) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   355
			/* Show error if no town exists at all */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   356
			if (GetNumTowns() == 0) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   357
				SetDParam(0, indsp->name);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   358
				ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_0285_CAN_T_BUILD_HERE, pt.x, pt.y);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   359
				return;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   360
			}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   361
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   362
			_current_player = OWNER_NONE;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   363
			_generating_world = true;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   364
			_ignore_restrictions = true;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   365
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   366
			if (!success) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   367
				SetDParam(0, indsp->name);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   368
				ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE, pt.x, pt.y);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   369
			}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   370
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   371
			_ignore_restrictions = false;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   372
			_generating_world = false;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   373
		} else {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   374
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   375
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   376
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   377
		/* If an industry has been built, just reset the cursor and the system */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   378
		if (success) ResetObjectToPlace();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   379
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   380
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   381
	virtual void OnTick()
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   382
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   383
		if (_pause_game != 0) return;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   384
		if (!this->timer_enabled) return;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   385
		if (--this->callback_timer == 0) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   386
			/* We have just passed another day.
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   387
			 * See if we need to update availability of currently selected industry */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   388
			this->callback_timer = DAY_TICKS;  //restart counter
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   389
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   390
			const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   391
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   392
			if (indsp->enabled) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   393
				bool call_back_result = CheckIfCallBackAllowsAvailability(this->selected_type, IACT_USERCREATION);
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   394
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   395
				/* Only if result does match the previous state would it require a redraw. */
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   396
				if (call_back_result != this->enabled[this->selected_index]) {
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   397
					this->enabled[this->selected_index] = call_back_result;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   398
					this->SetDirty();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   399
				}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   400
			}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   401
		}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   402
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   403
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   404
	virtual void OnTimeout()
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   405
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   406
		this->RaiseButtons();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   407
	}
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   408
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   409
	virtual void OnPlaceObjectAbort()
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   410
	{
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   411
		this->RaiseButtons();
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   412
	}
9194
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   413
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   414
	virtual void OnInvalidateData(int data = 0)
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   415
	{
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   416
		this->SetupArrays();
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   417
		this->SetDirty();
2c9920f2c445 (svn r13060) -Codechange: update build industry window when raw_industry_construction setting is modified
glx
parents: 9187
diff changeset
   418
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   421
void ShowBuildIndustryWindow()
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   422
{
9652
0405e98d8e96 (svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents: 9467
diff changeset
   423
	if (_game_mode != GM_EDITOR && !IsValidPlayerID(_current_player)) return;
9173
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   424
	if (BringWindowToFrontById(WC_BUILD_INDUSTRY, 0)) return;
b38373e203a9 (svn r13036) -Codechange: make a class of the BuildIndustry Window.
glx
parents: 9169
diff changeset
   425
	new BuildIndustryWindow();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
7218
8e73038b7586 (svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents: 7195
diff changeset
   428
static void UpdateIndustryProduction(Industry *i);
8e73038b7586 (svn r10496) -Feature: Replace all the windows for Industry building by a more flexible one.
belugas
parents: 7195
diff changeset
   429
9110
9c48301b2e19 (svn r12970) -Codechange: coding style for some function names
glx
parents: 9105
diff changeset
   430
static inline bool IsProductionMinimum(const Industry *i, int pt)
7284
d7903fff2d0b (svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents: 7283
diff changeset
   431
{
7790
49e446d753b2 (svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents: 7750
diff changeset
   432
	return i->production_rate[pt] == 0;
4211
5ee54ab361c9 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   433
}
5ee54ab361c9 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   434
9110
9c48301b2e19 (svn r12970) -Codechange: coding style for some function names
glx
parents: 9105
diff changeset
   435
static inline bool IsProductionMaximum(const Industry *i, int pt)
7284
d7903fff2d0b (svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents: 7283
diff changeset
   436
{
7790
49e446d753b2 (svn r11340) -Fix[FS#1362]: Newindustries can provide no production at start. So the Modifying Production cheat was a bit puzzled on how to deal with it. This will help a bit.
belugas
parents: 7750
diff changeset
   437
	return i->production_rate[pt] >= 255;
4211
5ee54ab361c9 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   438
}
5ee54ab361c9 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   439
4194
7df740c3b712 (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   440
static inline bool IsProductionAlterable(const Industry *i)
7df740c3b712 (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   441
{
7df740c3b712 (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   442
	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7616
diff changeset
   443
			(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
4194
7df740c3b712 (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   444
}
7df740c3b712 (svn r5654) -Cleanup: Change an ugly define into a function
Darkvater
parents: 4193
diff changeset
   445
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   446
/** Names of the widgets of the view industry gui */
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   447
enum IndustryViewWidgets {
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   448
	IVW_CLOSEBOX = 0,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   449
	IVW_CAPTION,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   450
	IVW_STICKY,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   451
	IVW_BACKGROUND,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   452
	IVW_VIEWPORT,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   453
	IVW_INFO,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   454
	IVW_GOTO,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   455
	IVW_SPACER,
9169
2dc9af0f4704 (svn r13032) -Codechange: make industry view window resizable and truncate strings
glx
parents: 9164
diff changeset
   456
	IVW_RESIZE,
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   457
};
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   458
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   459
class IndustryViewWindow : public Window
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   460
{
7284
d7903fff2d0b (svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents: 7283
diff changeset
   461
	byte editbox_line;        ///< The line clicked to open the edit box
d7903fff2d0b (svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents: 7283
diff changeset
   462
	byte clicked_line;        ///< The line of the button that has been clicked
d7903fff2d0b (svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents: 7283
diff changeset
   463
	byte clicked_button;      ///< The button that has been clicked (to raise)
d7903fff2d0b (svn r10624) -Fix [FS#1047]: the production of banks could not be modified (either in scenario editor or with the cheat).
rubidium
parents: 7283
diff changeset
   464
	byte production_offset_y; ///< The offset of the production texts/buttons
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   466
public:
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9194
diff changeset
   467
	IndustryViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   468
	{
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   469
		this->flags4 |= WF_DISABLE_VP_SCROLL;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   470
		this->editbox_line = 0;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   471
		this->clicked_line = 0;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   472
		this->clicked_button = 0;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   473
		InitializeWindowViewport(this, 3, 17, 254, 86, GetIndustry(window_number)->xy + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   474
		this->FindWindowPlacementAndResize(desc);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   475
	}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   476
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   477
	virtual void OnPaint()
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   478
	{
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   479
		Industry *i = GetIndustry(this->window_number);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   480
		const IndustrySpec *ind = GetIndustrySpec(i->type);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   481
		int y = this->widget[IVW_INFO].top + 1;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   482
		bool first = true;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   483
		bool has_accept = false;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   484
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   485
		SetDParam(0, this->window_number);
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9203
diff changeset
   486
		this->DrawWidgets();
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   487
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   488
		if (HasBit(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   489
			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   490
				if (i->accepts_cargo[j] == CT_INVALID) continue;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   491
				has_accept = true;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   492
				if (first) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   493
					DrawStringTruncated(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, TC_FROMSTRING, this->widget[IVW_INFO].right - 2);
7195
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7185
diff changeset
   494
					y += 10;
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   495
					first = false;
7195
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7185
diff changeset
   496
				}
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   497
				SetDParam(0, i->accepts_cargo[j]);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   498
				SetDParam(1, i->incoming_cargo_waiting[j]);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   499
				SetDParam(2, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   500
				DrawStringTruncated(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, TC_FROMSTRING, this->widget[IVW_INFO].right - 4);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   501
				y += 10;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   502
			}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   503
		} else {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   504
			StringID str = STR_4827_REQUIRES;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   505
			byte p = 0;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   506
			for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   507
				if (i->accepts_cargo[j] == CT_INVALID) continue;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   508
				has_accept = true;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   509
				if (p > 0) str++;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   510
				SetDParam(p++, GetCargo(i->accepts_cargo[j])->name);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   511
				SetDParam(p++, GetCargoSuffix(j, CST_VIEW, i, i->type, ind));
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   512
			}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   513
			if (has_accept) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   514
				DrawStringTruncated(2, y, str, TC_FROMSTRING, this->widget[IVW_INFO].right - 2);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   515
				y += 10;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   516
			}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   517
		}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   518
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   519
		first = true;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   520
		for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   521
			if (i->produced_cargo[j] == CT_INVALID) continue;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   522
			if (first) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   523
				if (has_accept) y += 10;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   524
				DrawStringTruncated(2, y, STR_482A_PRODUCTION_LAST_MONTH, TC_FROMSTRING, this->widget[IVW_INFO].right - 2);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   525
				y += 10;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   526
				this->production_offset_y = y;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   527
				first = false;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   528
			}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   529
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   530
			SetDParam(0, i->produced_cargo[j]);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   531
			SetDParam(1, i->last_month_production[j]);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   532
			SetDParam(2, GetCargoSuffix(j + 3, CST_VIEW, i, i->type, ind));
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   533
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   534
			SetDParam(3, i->last_month_pct_transported[j] * 100 >> 8);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   535
			uint x = 4 + (IsProductionAlterable(i) ? 30 : 0);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   536
			DrawStringTruncated(x, y, STR_482B_TRANSPORTED, TC_FROMSTRING, this->widget[IVW_INFO].right - x);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   537
			/* Let's put out those buttons.. */
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   538
			if (IsProductionAlterable(i)) {
9858
c8e0746a5945 (svn r14003) -Codechange: Replace numbers with Colours enum opn some DrawArrowButtons calls
belugas
parents: 9777
diff changeset
   539
				DrawArrowButtons(5, y, COLOUR_YELLOW, (this->clicked_line == j + 1) ? this->clicked_button : 0,
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   540
						!IsProductionMinimum(i, j), !IsProductionMaximum(i, j));
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   541
			}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   542
			y += 10;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   543
		}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   544
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   545
		/* Get the extra message for the GUI */
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   546
		if (HasBit(ind->callback_flags, CBM_IND_WINDOW_MORE_TEXT)) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   547
			uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->xy);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   548
			if (callback_res != CALLBACK_FAILED) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   549
				StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   550
				if (message != STR_NULL && message != STR_UNDEFINED) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   551
					const Widget *wi = &this->widget[IVW_INFO];
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   552
					y += 10;
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   553
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   554
					PrepareTextRefStackUsage(6);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   555
					/* Use all the available space left from where we stand up to the end of the window */
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   556
					y += DrawStringMultiLine(2, y, message, wi->right - wi->left - 4, -1);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   557
					StopTextRefStackUsage();
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   558
				}
7195
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7185
diff changeset
   559
			}
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   560
		}
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   561
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   562
		if (y > this->widget[IVW_INFO].bottom) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   563
			this->SetDirty();
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   564
			ResizeWindowForWidget(this, IVW_INFO, 0, y - this->widget[IVW_INFO].top);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   565
			this->SetDirty();
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   566
			return;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   567
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9203
diff changeset
   569
		this->DrawViewport();
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   570
	}
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7341
diff changeset
   571
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   572
	virtual void OnClick(Point pt, int widget)
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   573
	{
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   574
		Industry *i;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   575
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   576
		switch (widget) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   577
			case IVW_INFO: {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   578
				int line, x;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   579
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   580
				i = GetIndustry(this->window_number);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   581
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   582
				/* We should work if needed.. */
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   583
				if (!IsProductionAlterable(i)) return;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   584
				x = pt.x;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   585
				line = (pt.y - this->production_offset_y) / 10;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   586
				if (pt.y >= this->production_offset_y && IsInsideMM(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   587
					if (IsInsideMM(x, 5, 25) ) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   588
						/* Clicked buttons, decrease or increase production */
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   589
						if (x < 15) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   590
							if (IsProductionMinimum(i, line)) return;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   591
							i->production_rate[line] = max(i->production_rate[line] / 2, 0);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   592
						} else {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   593
							/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   594
							int new_prod = i->production_rate[line] == 0 ? 1 : i->production_rate[line] * 2;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   595
							if (IsProductionMaximum(i, line)) return;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   596
							i->production_rate[line] = minu(new_prod, 255);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   597
						}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   598
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   599
						UpdateIndustryProduction(i);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   600
						this->SetDirty();
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   601
						this->flags4 |= 5 << WF_TIMEOUT_SHL;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   602
						this->clicked_line = line + 1;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   603
						this->clicked_button = (x < 15 ? 1 : 2);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   604
					} else if (IsInsideMM(x, 34, 160)) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   605
						/* clicked the text */
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   606
						this->editbox_line = line;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   607
						SetDParam(0, i->production_rate[line] * 8);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   608
						ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_GAME_PRODUCTION, 10, 100, this, CS_ALPHANUMERAL);
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   609
					}
4211
5ee54ab361c9 (svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents: 4194
diff changeset
   610
				}
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   611
			} break;
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   612
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   613
			case IVW_GOTO:
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   614
				i = GetIndustry(this->window_number);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   615
				if (_ctrl_pressed) {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   616
					ShowExtraViewPortWindow(i->xy + TileDiffXY(1, 1));
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   617
				} else {
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   618
					ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   619
				}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   620
				break;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   621
		}
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   622
	}
4193
9e82090fef58 (svn r5653) -Cleanup: Do a little cleanup of the industry gui code.
Darkvater
parents: 4192
diff changeset
   623
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   624
	virtual void OnTimeout()
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   625
	{
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   626
		this->clicked_line = 0;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   627
		this->clicked_button = 0;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   628
		this->SetDirty();
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   629
	}
1004
dcc3c5747e22 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   630
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   631
	virtual void OnResize(Point new_size, Point delta)
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   632
	{
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   633
		this->viewport->width            += delta.x;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   634
		this->viewport->height           += delta.y;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   635
		this->viewport->virtual_width    += delta.x;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   636
		this->viewport->virtual_height   += delta.y;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   637
		this->viewport->dest_scrollpos_x -= delta.x;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   638
		this->viewport->dest_scrollpos_y -= delta.y;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   639
		UpdateViewportPosition(this);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   640
	}
9169
2dc9af0f4704 (svn r13032) -Codechange: make industry view window resizable and truncate strings
glx
parents: 9164
diff changeset
   641
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   642
	virtual void OnQueryTextFinished(char *str)
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   643
	{
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   644
		if (StrEmpty(str)) return;
1004
dcc3c5747e22 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   645
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   646
		Industry* i = GetIndustry(this->window_number);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   647
		int line = this->editbox_line;
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   648
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   649
		i->production_rate[line] = ClampU(atoi(str), 0, 255);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   650
		UpdateIndustryProduction(i);
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   651
		this->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	}
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   653
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
1004
dcc3c5747e22 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   655
static void UpdateIndustryProduction(Industry *i)
dcc3c5747e22 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   656
{
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7616
diff changeset
   657
	for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7616
diff changeset
   658
		if (i->produced_cargo[j] != CT_INVALID) {
6819
f986f54e2660 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 6815
diff changeset
   659
			i->last_month_production[j] = 8 * i->production_rate[j];
6636
fec086b5c340 (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 6624
diff changeset
   660
		}
fec086b5c340 (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 6624
diff changeset
   661
	}
1004
dcc3c5747e22 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   662
}
dcc3c5747e22 (svn r1503) Added feature:
miham
parents: 919
diff changeset
   663
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   664
/** Widget definition of the view industy gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
static const Widget _industry_view_widgets[] = {
9744
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   666
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_CREAM,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},            // IVW_CLOSEBOX
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   667
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_CREAM,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},  // IVW_CAPTION
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   668
{  WWT_STICKYBOX,     RESIZE_LR,  COLOUR_CREAM,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},                // IVW_STICKY
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   669
{      WWT_PANEL,     RESIZE_RB,  COLOUR_CREAM,     0,   259,    14,   105, 0x0,               STR_NULL},                         // IVW_BACKGROUND
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   670
{      WWT_INSET,     RESIZE_RB,  COLOUR_CREAM,     2,   257,    16,   103, 0x0,               STR_NULL},                         // IVW_VIEWPORT
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   671
{      WWT_PANEL,    RESIZE_RTB,  COLOUR_CREAM,     0,   259,   106,   107, 0x0,               STR_NULL},                         // IVW_INFO
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   672
{ WWT_PUSHTXTBTN,     RESIZE_TB,  COLOUR_CREAM,     0,   129,   108,   119, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON}, // IVW_GOTO
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   673
{      WWT_PANEL,    RESIZE_RTB,  COLOUR_CREAM,   130,   247,   108,   119, 0x0,               STR_NULL},                         // IVW_SPACER
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   674
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_CREAM,   248,   259,   108,   119, 0x0,               STR_RESIZE_BUTTON},                // IVW_RESIZE
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   675
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   678
/** Window definition of the view industy gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
static const WindowDesc _industry_view_desc = {
8779
038e02efbc0a (svn r12479) -Codechange [FS#1723]: Simplify the method used to resize the industry view window. The window is now shown the correct size so the resize button is also removed.
peter1138
parents: 8759
diff changeset
   680
	WDP_AUTO, WDP_AUTO, 260, 120, 260, 120,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5609
diff changeset
   681
	WC_INDUSTRY_VIEW, WC_NONE,
9169
2dc9af0f4704 (svn r13032) -Codechange: make industry view window resizable and truncate strings
glx
parents: 9164
diff changeset
   682
	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
   683
	_industry_view_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
void ShowIndustryViewWindow(int industry)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
{
9187
ea1ad8a526a4 (svn r13050) -Codechange: make a class of IndustryViewWindow.
glx
parents: 9184
diff changeset
   688
	AllocateWindowDescFront<IndustryViewWindow>(&_industry_view_desc, industry);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   691
/** Names of the widgets of the industry directory gui */
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   692
enum IndustryDirectoryWidgets {
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   693
	IDW_CLOSEBOX = 0,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   694
	IDW_CAPTION,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   695
	IDW_STICKY,
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   696
	IDW_DROPDOWN_ORDER,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   697
	IDW_DROPDOWN_CRITERIA,
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   698
	IDW_SPACER,
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   699
	IDW_INDUSTRY_LIST,
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   700
	IDW_SCROLLBAR,
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   701
	IDW_RESIZE,
7278
c5b4203c6e1c (svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents: 7271
diff changeset
   702
};
c5b4203c6e1c (svn r10617) -Codechange: code style changes (removing an erroneous tab plus switch case alignment)
belugas
parents: 7271
diff changeset
   703
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   704
/** Widget definition of the industy directory gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
static const Widget _industry_directory_widgets[] = {
9744
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   706
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_BROWN,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},             // IDW_CLOSEBOX
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   707
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_BROWN,    11,   415,     0,    13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},   // IDW_CAPTION
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   708
{  WWT_STICKYBOX,     RESIZE_LR,  COLOUR_BROWN,   416,   427,     0,    13, 0x0,                     STR_STICKY_BUTTON},                 // IDW_STICKY
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   709
9744
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   710
{    WWT_TEXTBTN,   RESIZE_NONE,  COLOUR_BROWN,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},                // IDW_DROPDOWN_ORDER
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   711
{   WWT_DROPDOWN,   RESIZE_NONE,  COLOUR_BROWN,    81,   243,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},             // IDW_DROPDOWN_CRITERIA
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   712
{      WWT_PANEL,  RESIZE_RIGHT,  COLOUR_BROWN,   244,   415,    14,    25, 0x0,                     STR_NULL},                          // IDW_SPACER
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   713
9777
5c14eb4bb2bc (svn r13917) -Fix [FS#2178]: wrong tooltip for the industry directory's list.
rubidium
parents: 9744
diff changeset
   714
{      WWT_PANEL,     RESIZE_RB,  COLOUR_BROWN,     0,   415,    26,   189, 0x0,                     STR_INDUSTRYDIR_LIST_CAPTION},      // IDW_INDUSRTY_LIST
9744
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   715
{  WWT_SCROLLBAR,    RESIZE_LRB,  COLOUR_BROWN,   416,   427,    14,   177, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST},  // IDW_SCROLLBAR
a1964a9acb91 (svn r13879) -Codechange: Replace numbers with Colours enum on engine, industries and group gui
belugas
parents: 9659
diff changeset
   716
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_BROWN,   416,   427,   178,   189, 0x0,                     STR_RESIZE_BUTTON},                 // IDW_RESIZE
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   717
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   720
typedef GUIList<const Industry*> GUIIndustryList;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   721
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   722
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   723
/**
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   724
 * The list of industries.
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   725
 */
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   726
class IndustryDirectoryWindow : public Window {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   727
protected:
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   728
	/* Runtime saved values */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   729
	static Listing last_sorting;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   730
	static const Industry *last_industry;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   731
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   732
	/* Constants for sorting stations */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   733
	static const StringID sorter_names[];
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   734
	static GUIIndustryList::SortFunction *const sorter_funcs[];
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   735
9384
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   736
	GUIIndustryList industries;
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   737
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   738
	/** (Re)Build industries list */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   739
	void BuildIndustriesList()
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   740
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   741
		if (!this->industries.NeedRebuild()) return;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   742
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   743
		this->industries.Clear();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   744
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   745
		DEBUG(misc, 3, "Building industry list");
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   746
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   747
		const Industry *i;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   748
		FOR_ALL_INDUSTRIES(i) {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   749
			*this->industries.Append() = i;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   750
		}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   751
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   752
		this->industries.Compact();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   753
		this->industries.RebuildDone();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   754
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   755
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   756
	/**
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   757
	 * Returns percents of cargo transported if industry produces this cargo, else -1
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   758
	 *
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   759
	 * @param i industry to check
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   760
	 * @param id cargo slot
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   761
	 * @return percents of cargo transported, or -1 if industry doesn't use this cargo slot
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   762
	 */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   763
	static inline int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   764
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   765
		assert(id < lengthof(i->produced_cargo));
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   766
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   767
		if (i->produced_cargo[id] == CT_INVALID) return 101;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   768
		return i->last_month_pct_transported[id] * 100 >> 8;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   769
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   770
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   771
	/**
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   772
	 * Returns value representing industry's transported cargo
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   773
	 *  percentage for industry sorting
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   774
	 *
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   775
	 * @param i industry to check
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   776
	 * @return value used for sorting
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   777
	 */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   778
	static int GetCargoTransportedSortValue(const Industry *i)
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   779
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   780
		int p1 = GetCargoTransportedPercentsIfValid(i, 0);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   781
		int p2 = GetCargoTransportedPercentsIfValid(i, 1);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   782
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   783
		if (p1 > p2) Swap(p1, p2); // lower value has higher priority
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   784
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   785
		return (p1 << 8) + p2;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   786
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   787
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   788
	/** Sort industries by name */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   789
	static int CDECL IndustryNameSorter(const Industry* const *a, const Industry* const *b)
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   790
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   791
		static char buf_cache[96];
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   792
		static char buf[96];
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   793
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   794
		SetDParam(0, (*a)->town->index);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   795
		GetString(buf, STR_TOWN, lastof(buf));
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   796
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   797
		if (*b != last_industry) {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   798
			last_industry = *b;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   799
			SetDParam(0, (*b)->town->index);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   800
			GetString(buf_cache, STR_TOWN, lastof(buf_cache));
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   801
		}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   802
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   803
		return strcmp(buf, buf_cache);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   804
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   805
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   806
	/** Sort industries by type and name */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   807
	static int CDECL IndustryTypeSorter(const Industry* const *a, const Industry* const *b)
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   808
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   809
		int r = (*a)->type - (*b)->type;
9467
8a767629b643 (svn r13387) -Fix: industry directory sorting not working correctly (= != ==)
rubidium
parents: 9413
diff changeset
   810
		return (r == 0) ? IndustryNameSorter(a, b) : r;
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   811
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   812
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   813
	/** Sort industries by production and name */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   814
	static int CDECL IndustryProductionSorter(const Industry* const *a, const Industry* const *b)
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   815
	{
9467
8a767629b643 (svn r13387) -Fix: industry directory sorting not working correctly (= != ==)
rubidium
parents: 9413
diff changeset
   816
		int r = 0;
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   817
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   818
		if ((*a)->produced_cargo[0] == CT_INVALID) {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   819
			if ((*b)->produced_cargo[0] != CT_INVALID) return -1;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   820
		} else {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   821
			if ((*b)->produced_cargo[0] == CT_INVALID) return 1;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   822
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   823
			r = ((*a)->last_month_production[0] + (*a)->last_month_production[1]) -
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   824
			    ((*b)->last_month_production[0] + (*b)->last_month_production[1]);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   825
		}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   826
9467
8a767629b643 (svn r13387) -Fix: industry directory sorting not working correctly (= != ==)
rubidium
parents: 9413
diff changeset
   827
		return (r == 0) ? IndustryNameSorter(a, b) : r;
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   828
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   829
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   830
	/** Sort industries by transported cargo and name */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   831
	static int CDECL IndustryTransportedCargoSorter(const Industry* const *a, const Industry* const *b)
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   832
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   833
		int r = GetCargoTransportedSortValue(*a) - GetCargoTransportedSortValue(*b);
9467
8a767629b643 (svn r13387) -Fix: industry directory sorting not working correctly (= != ==)
rubidium
parents: 9413
diff changeset
   834
		return (r == 0) ? IndustryNameSorter(a, b) : r;
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   835
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   836
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   837
	/** Sort the industries list */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   838
	void SortIndustriesList()
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   839
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   840
		if (!this->industries.Sort()) return;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   841
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   842
		/* Reset name sorter sort cache */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   843
		this->last_industry = NULL;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   844
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   845
		/* Set the modified widget dirty */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   846
		this->InvalidateWidget(IDW_INDUSTRY_LIST);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   847
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   848
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   849
public:
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   850
	IndustryDirectoryWindow(const WindowDesc *desc, WindowNumber number) : Window(desc, number)
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   851
	{
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   852
		this->vscroll.cap = 16;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   853
		this->resize.height = this->height - 6 * 10; // minimum 10 items
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   854
		this->resize.step_height = 10;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   855
		this->FindWindowPlacementAndResize(desc);
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   856
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   857
		this->industries.SetListing(this->last_sorting);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   858
		this->industries.SetSortFuncs(this->sorter_funcs);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   859
		this->industries.ForceRebuild();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   860
		this->industries.NeedResort();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   861
		this->SortIndustriesList();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   862
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   863
		this->widget[IDW_DROPDOWN_CRITERIA].data = this->sorter_names[this->industries.SortType()];
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   864
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   865
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   866
	~IndustryDirectoryWindow()
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   867
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   868
		this->last_sorting = this->industries.GetListing();
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   869
	}
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   870
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   871
	virtual void OnPaint()
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   872
	{
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   873
		BuildIndustriesList();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   874
		SortIndustriesList();
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   875
9384
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   876
		SetVScrollCount(this, this->industries.Length());
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   877
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   878
		this->DrawWidgets();
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   879
		this->DrawSortButtonState(IDW_DROPDOWN_ORDER, this->industries.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   880
9384
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   881
		int max = min(this->vscroll.pos + this->vscroll.cap, this->industries.Length());
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   882
		int y = 28; // start of the list-widget
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   883
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   884
		for (int n = this->vscroll.pos; n < max; ++n) {
9384
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   885
			const Industry* i = this->industries[n];
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   886
			const IndustrySpec *indsp = GetIndustrySpec(i->type);
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   887
			byte p = 0;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   888
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   889
			/* Industry name */
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   890
			SetDParam(p++, i->index);
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   891
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   892
			/* Industry productions */
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   893
			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   894
				if (i->produced_cargo[j] == CT_INVALID) continue;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   895
				SetDParam(p++, i->produced_cargo[j]);
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   896
				SetDParam(p++, i->last_month_production[j]);
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   897
				SetDParam(p++, GetCargoSuffix(j + 3, CST_DIR, (Industry*)i, i->type, indsp));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   900
			/* Transported productions */
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   901
			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   902
				if (i->produced_cargo[j] == CT_INVALID) continue;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   903
				SetDParam(p++, i->last_month_pct_transported[j] * 100 >> 8);
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   904
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   906
			/* Drawing the right string */
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   907
			StringID str = STR_INDUSTRYDIR_ITEM_NOPROD;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   908
			if (p != 1) str = (p == 5) ? STR_INDUSTRYDIR_ITEM : STR_INDUSTRYDIR_ITEM_TWO;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   909
			DrawStringTruncated(4, y, str, TC_FROMSTRING, this->widget[IDW_INDUSTRY_LIST].right - 4);
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   910
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   911
			y += 10;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   912
		}
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   913
	}
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   914
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   915
	virtual void OnClick(Point pt, int widget)
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   916
	{
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   917
		switch (widget) {
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   918
			case IDW_DROPDOWN_ORDER:
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   919
				this->industries.ToggleSortOrder();
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   920
				this->SetDirty();
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   921
				break;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   922
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   923
			case IDW_DROPDOWN_CRITERIA:
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   924
				ShowDropDownMenu(this, this->sorter_names, this->industries.SortType(), IDW_DROPDOWN_CRITERIA, 0, 0);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   925
				break;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   926
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   927
			case IDW_INDUSTRY_LIST: {
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   928
				int y = (pt.y - 28) / 10;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   929
				uint16 p;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   930
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   931
				if (!IsInsideMM(y, 0, this->vscroll.cap)) return;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   932
				p = y + this->vscroll.pos;
9384
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   933
				if (p < this->industries.Length()) {
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   934
					if (_ctrl_pressed) {
9384
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   935
						ShowExtraViewPortWindow(this->industries[p]->xy);
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   936
					} else {
9384
c179b5df936d (svn r13294) -Codechange: convert the inheritance of GUIList in IndustryDirectoryWindow to a member object
skidd13
parents: 9381
diff changeset
   937
						ScrollMainWindowToTile(this->industries[p]->xy);
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   938
					}
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   939
				}
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   940
			} break;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   941
		}
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   942
	}
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   943
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   944
	virtual void OnDropdownSelect(int widget, int index)
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   945
	{
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   946
		if (this->industries.SortType() != index) {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   947
			this->industries.SetSortType(index);
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   948
			this->widget[IDW_DROPDOWN_CRITERIA].data = this->sorter_names[this->industries.SortType()];
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   949
			this->SetDirty();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   950
		}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   951
	}
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   952
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   953
	virtual void OnResize(Point new_size, Point delta)
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   954
	{
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   955
		this->vscroll.cap += delta.y / 10;
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   956
	}
9096
93e9f718a5c9 (svn r12956) -Codechange: Code-style application on switch-case aligment
belugas
parents: 9094
diff changeset
   957
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   958
	virtual void OnInvalidateData(int data)
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   959
	{
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   960
		if (data == 0) {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   961
			this->industries.ForceRebuild();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   962
		} else {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   963
			this->industries.ForceResort();
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   964
		}
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   965
		this->InvalidateWidget(IDW_INDUSTRY_LIST);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   966
	}
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   967
};
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
   968
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   969
Listing IndustryDirectoryWindow::last_sorting = {false, 0};
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   970
const Industry *IndustryDirectoryWindow::last_industry = NULL;
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   971
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   972
/* Availible station sorting functions */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   973
GUIIndustryList::SortFunction* const IndustryDirectoryWindow::sorter_funcs[] = {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   974
	&IndustryNameSorter,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   975
	&IndustryTypeSorter,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   976
	&IndustryProductionSorter,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   977
	&IndustryTransportedCargoSorter
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   978
};
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   979
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   980
/* Names of the sorting functions */
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   981
const StringID IndustryDirectoryWindow::sorter_names[] = {
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   982
	STR_SORT_BY_DROPDOWN_NAME,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   983
	STR_SORT_BY_TYPE,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   984
	STR_SORT_BY_PRODUCTION,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   985
	STR_SORT_BY_TRANSPORTED,
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   986
	INVALID_STRING_ID
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   987
};
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   988
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
8047
50d438fdf470 (svn r11607) -Codechange: Enumify the industry widgets
skidd13
parents: 8040
diff changeset
   990
/** Window definition of the industy directory gui */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
static const WindowDesc _industry_directory_desc = {
9400
e0c0c8f6c958 (svn r13311) -Codechange: Use GUIList for the industry directory window
skidd13
parents: 9384
diff changeset
   992
	WDP_AUTO, WDP_AUTO, 428, 190, 428, 190,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5609
diff changeset
   993
	WC_INDUSTRY_DIRECTORY, WC_NONE,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 830
diff changeset
   994
	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
   995
	_industry_directory_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   998
void ShowIndustryDirectory()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
{
9306
7dd0a9130ebf (svn r13174) -Codechange: make a class of the IndustryDirectoryWindow.
glx
parents: 9273
diff changeset
  1000
	AllocateWindowDescFront<IndustryDirectoryWindow>(&_industry_directory_desc, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
}