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