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