2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file industry_gui.cpp GUIs related to industries. */
|
2007-03-03 04:04:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-19 14:40:32 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gfx_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "cheat_type.h"
|
2007-07-08 00:25:05 +00:00
|
|
|
#include "newgrf.h"
|
|
|
|
#include "newgrf_industries.h"
|
|
|
|
#include "newgrf_text.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2008-05-07 13:10:15 +00:00
|
|
|
#include "tilehighlight_func.h"
|
2008-05-10 08:58:52 +00:00
|
|
|
#include "string_func.h"
|
2008-05-18 23:36:33 +00:00
|
|
|
#include "sortlist_type.h"
|
2008-05-28 16:45:00 +00:00
|
|
|
#include "widgets/dropdown_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_base.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
|
2007-07-10 00:59:00 +00:00
|
|
|
bool _ignore_restrictions;
|
|
|
|
|
2009-08-14 18:41:03 +00:00
|
|
|
/** Cargo suffix type (for which window is it requested) */
|
2008-05-05 22:37:40 +00:00
|
|
|
enum CargoSuffixType {
|
2009-08-14 18:41:03 +00:00
|
|
|
CST_FUND, ///< Fund-industry window
|
|
|
|
CST_VIEW, ///< View-industry window
|
|
|
|
CST_DIR, ///< Industry-directory window
|
2008-05-05 22:37:40 +00:00
|
|
|
};
|
|
|
|
|
2008-03-28 02:30:10 +00:00
|
|
|
/**
|
|
|
|
* Gets the string to display after the cargo name (using callback 37)
|
|
|
|
* @param cargo the cargo for which the suffix is requested
|
|
|
|
* - 00 - first accepted cargo type
|
|
|
|
* - 01 - second accepted cargo type
|
|
|
|
* - 02 - third accepted cargo type
|
|
|
|
* - 03 - first produced cargo type
|
|
|
|
* - 04 - second produced cargo type
|
2009-08-14 18:41:03 +00:00
|
|
|
* @param cst the cargo suffix type (for which window is it requested). @see CargoSuffixType
|
2008-03-28 02:30:10 +00:00
|
|
|
* @param ind the industry (NULL if in fund window)
|
|
|
|
* @param ind_type the industry type
|
|
|
|
* @param indspec the industry spec
|
2009-10-18 15:36:30 +00:00
|
|
|
* @param suffix is filled with the string to display
|
|
|
|
* @param suffix_last lastof(suffix)
|
2008-03-28 02:30:10 +00:00
|
|
|
*/
|
2009-10-18 15:36:30 +00:00
|
|
|
static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, char *suffix, const char *suffix_last)
|
2008-03-28 02:30:10 +00:00
|
|
|
{
|
2009-10-18 15:36:30 +00:00
|
|
|
suffix[0] = '\0';
|
2009-09-14 12:22:57 +00:00
|
|
|
if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
|
2009-10-18 15:36:30 +00:00
|
|
|
uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, (cst != CST_FUND) ? ind->xy : INVALID_TILE);
|
|
|
|
if (GB(callback, 0, 8) != 0xFF) {
|
|
|
|
PrepareTextRefStackUsage(6);
|
|
|
|
GetString(suffix, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), suffix_last);
|
|
|
|
StopTextRefStackUsage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets all strings to display after the cargos of industries (using callback 37)
|
|
|
|
* @param cb_offset The offset for the cargo used in cb37, 0 for accepted cargos, 3 for produced cargos
|
|
|
|
* @param cst the cargo suffix type (for which window is it requested). @see CargoSuffixType
|
|
|
|
* @param ind the industry (NULL if in fund window)
|
|
|
|
* @param ind_type the industry type
|
|
|
|
* @param indspec the industry spec
|
|
|
|
* @param cargos array with cargotypes. for CT_INVALID no suffix will be determined
|
|
|
|
* @param suffixes is filled with the suffixes
|
|
|
|
*/
|
|
|
|
template <typename TC, typename TS>
|
|
|
|
static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargos, TS &suffixes)
|
|
|
|
{
|
2009-11-13 15:53:51 +00:00
|
|
|
assert_compile(lengthof(cargos) <= lengthof(suffixes));
|
2009-10-18 15:36:30 +00:00
|
|
|
for (uint j = 0; j < lengthof(cargos); j++) {
|
|
|
|
if (cargos[j] != CT_INVALID) {
|
|
|
|
GetCargoSuffix(cb_offset + j, cst, ind, ind_type, indspec, suffixes[j], lastof(suffixes[j]));
|
|
|
|
} else {
|
|
|
|
suffixes[j][0] = '\0';
|
|
|
|
}
|
2008-03-28 02:30:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
/** Names of the widgets of the dynamic place industries gui */
|
|
|
|
enum DynamicPlaceIndustriesWidgets {
|
|
|
|
DPIW_CLOSEBOX = 0,
|
|
|
|
DPIW_CAPTION,
|
|
|
|
DPIW_MATRIX_WIDGET,
|
|
|
|
DPIW_SCROLLBAR,
|
|
|
|
DPIW_INFOPANEL,
|
|
|
|
DPIW_FUND_WIDGET,
|
|
|
|
DPIW_RESIZE_WIDGET,
|
|
|
|
};
|
2007-07-19 01:47:32 +00:00
|
|
|
|
2009-03-28 19:08:55 +00:00
|
|
|
static const NWidgetPart _nested_build_industry_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN, DPIW_CLOSEBOX),
|
2009-11-22 11:20:12 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, DPIW_CAPTION), SetDataTip(STR_FUND_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-28 19:08:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_DARK_GREEN, DPIW_MATRIX_WIDGET), SetDataTip(0x801, STR_FUND_INDUSTRY_SELECTION_TOOLTIP), SetFill(1, 0), SetResize(1, 1),
|
2009-11-22 11:24:30 +00:00
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_DARK_GREEN, DPIW_SCROLLBAR),
|
2009-03-28 19:08:55 +00:00
|
|
|
EndContainer(),
|
2009-10-24 19:36:24 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, DPIW_INFOPANEL), SetResize(1, 0),
|
2009-03-28 19:08:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, DPIW_FUND_WIDGET), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
|
2009-03-28 19:08:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN, DPIW_RESIZE_WIDGET),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
/** Window definition of the dynamic place industries gui */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _build_industry_desc(
|
2009-11-17 19:16:48 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 170, 212,
|
2008-05-10 23:43:08 +00:00
|
|
|
WC_BUILD_INDUSTRY, WC_NONE,
|
2009-02-04 16:59:41 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE | WDF_CONSTRUCTION,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_build_industry_widgets, lengthof(_nested_build_industry_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2008-02-03 12:41:06 +00:00
|
|
|
|
2009-10-20 20:06:25 +00:00
|
|
|
/** Build (fund or prospect) a new industry, */
|
2008-05-10 23:43:08 +00:00
|
|
|
class BuildIndustryWindow : public Window {
|
|
|
|
int selected_index; ///< index of the element in the matrix
|
|
|
|
IndustryType selected_type; ///< industry corresponding to the above index
|
|
|
|
uint16 callback_timer; ///< timer counter for callback eventual verification
|
|
|
|
bool timer_enabled; ///< timer can be used
|
|
|
|
uint16 count; ///< How many industries are loaded
|
|
|
|
IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded
|
|
|
|
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
|
2007-07-10 00:59:00 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
/** The offset for the text in the matrix. */
|
|
|
|
static const int MATRIX_TEXT_OFFSET = 17;
|
|
|
|
|
2008-05-12 14:54:33 +00:00
|
|
|
void SetupArrays()
|
2008-05-10 23:43:08 +00:00
|
|
|
{
|
|
|
|
this->count = 0;
|
|
|
|
|
|
|
|
for (uint i = 0; i < lengthof(this->index); i++) {
|
2008-05-12 14:54:33 +00:00
|
|
|
this->index[i] = INVALID_INDUSTRYTYPE;
|
2008-05-10 23:43:08 +00:00
|
|
|
this->enabled[i] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
|
|
|
|
this->index[this->count] = INVALID_INDUSTRYTYPE;
|
|
|
|
this->count++;
|
|
|
|
this->timer_enabled = false;
|
|
|
|
}
|
2008-05-12 14:54:33 +00:00
|
|
|
/* Fill the arrays with industries.
|
2008-05-10 23:43:08 +00:00
|
|
|
* The tests performed after the enabled allow to load the industries
|
|
|
|
* In the same way they are inserted by grf (if any)
|
|
|
|
*/
|
2009-10-20 20:06:25 +00:00
|
|
|
for (IndustryType ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(ind);
|
2009-08-14 17:11:59 +00:00
|
|
|
if (indsp->enabled) {
|
2008-05-10 23:43:08 +00:00
|
|
|
/* Rule is that editor mode loads all industries.
|
|
|
|
* In game mode, all non raw industries are loaded too
|
|
|
|
* and raw ones are loaded only when setting allows it */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
|
2008-05-12 14:54:33 +00:00
|
|
|
/* Unselect if the industry is no longer in the list */
|
|
|
|
if (this->selected_type == ind) this->selected_index = -1;
|
|
|
|
continue;
|
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
this->index[this->count] = ind;
|
|
|
|
this->enabled[this->count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
|
2008-05-12 14:54:33 +00:00
|
|
|
/* Keep the selection to the correct line */
|
|
|
|
if (this->selected_type == ind) this->selected_index = this->count;
|
2008-05-10 23:43:08 +00:00
|
|
|
this->count++;
|
2007-07-10 00:59:00 +00:00
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2007-07-10 00:59:00 +00:00
|
|
|
|
2008-05-12 14:54:33 +00:00
|
|
|
/* first indutry type is selected if the current selection is invalid.
|
2008-05-10 23:43:08 +00:00
|
|
|
* I'll be damned if there are none available ;) */
|
2008-05-12 14:54:33 +00:00
|
|
|
if (this->selected_index == -1) {
|
|
|
|
this->selected_index = 0;
|
|
|
|
this->selected_type = this->index[0];
|
|
|
|
}
|
2009-10-24 19:36:24 +00:00
|
|
|
|
|
|
|
this->vscroll.SetCount(this->count);
|
2008-05-12 14:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2009-10-24 19:36:24 +00:00
|
|
|
BuildIndustryWindow() : Window()
|
2008-05-12 14:54:33 +00:00
|
|
|
{
|
|
|
|
this->timer_enabled = _loaded_newgrf_features.has_newindustries;
|
|
|
|
|
|
|
|
this->selected_index = -1;
|
|
|
|
this->selected_type = INVALID_INDUSTRYTYPE;
|
|
|
|
|
|
|
|
/* Initialize arrays */
|
|
|
|
this->SetupArrays();
|
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
this->callback_timer = DAY_TICKS;
|
2008-05-11 11:41:18 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
this->InitNested(&_build_industry_desc, 0);
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2007-07-10 00:59:00 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
|
2008-05-10 23:43:08 +00:00
|
|
|
{
|
2009-10-24 19:36:24 +00:00
|
|
|
switch (widget) {
|
|
|
|
case DPIW_MATRIX_WIDGET: {
|
|
|
|
Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
|
|
|
|
for (byte i = 0; i < this->count; i++) {
|
|
|
|
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
|
|
|
|
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name));
|
|
|
|
}
|
|
|
|
resize->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
|
|
|
d.width += MATRIX_TEXT_OFFSET + padding.width;
|
|
|
|
d.height = 5 * resize->height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
case DPIW_INFOPANEL: {
|
|
|
|
/* Extra line for cost outside of editor + extra lines for 'extra' information for NewGRFs. */
|
|
|
|
int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1) + (_loaded_newgrf_features.has_newindustries ? 4 : 0);
|
|
|
|
Dimension d = {0, 0};
|
|
|
|
for (byte i = 0; i < this->count; i++) {
|
|
|
|
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
|
|
|
|
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
|
|
|
|
|
|
|
|
char cargo_suffix[3][512];
|
|
|
|
GetAllCargoSuffixes(0, CST_FUND, NULL, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
|
|
|
|
StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
|
|
|
|
byte p = 0;
|
|
|
|
SetDParam(0, STR_JUST_NOTHING);
|
|
|
|
SetDParamStr(1, "");
|
|
|
|
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
|
|
|
|
if (indsp->accepts_cargo[j] == CT_INVALID) continue;
|
|
|
|
if (p > 0) str++;
|
|
|
|
SetDParam(p++, CargoSpec::Get(indsp->accepts_cargo[j])->name);
|
|
|
|
SetDParamStr(p++, cargo_suffix[j]);
|
|
|
|
}
|
|
|
|
d = maxdim(d, GetStringBoundingBox(str));
|
|
|
|
|
|
|
|
/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
|
|
|
|
GetAllCargoSuffixes(3, CST_FUND, NULL, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
|
|
|
|
str = STR_INDUSTRY_VIEW_PRODUCES_CARGO;
|
|
|
|
p = 0;
|
|
|
|
SetDParam(0, STR_JUST_NOTHING);
|
|
|
|
SetDParamStr(1, "");
|
|
|
|
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
|
|
|
|
if (indsp->produced_cargo[j] == CT_INVALID) continue;
|
|
|
|
if (p > 0) str++;
|
|
|
|
SetDParam(p++, CargoSpec::Get(indsp->produced_cargo[j])->name);
|
|
|
|
SetDParamStr(p++, cargo_suffix[j]);
|
|
|
|
}
|
|
|
|
d = maxdim(d, GetStringBoundingBox(str));
|
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
/* Set it to something more sane :) */
|
|
|
|
size->height = height * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
size->width = d.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
|
|
} break;
|
2008-05-10 23:43:08 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
case DPIW_FUND_WIDGET: {
|
|
|
|
Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY));
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY));
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
2007-07-10 00:59:00 +00:00
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2009-10-24 19:36:24 +00:00
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case DPIW_FUND_WIDGET:
|
|
|
|
/* Raw industries might be prospected. Show this fact by changing the string
|
|
|
|
* In Editor, you just build, while ingame, or you fund or you prospect */
|
|
|
|
if (_game_mode == GM_EDITOR) {
|
|
|
|
/* We've chosen many random industries but no industries have been specified */
|
|
|
|
SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
|
|
|
|
} else {
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(this->index[this->selected_index]);
|
|
|
|
SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
|
|
|
|
}
|
|
|
|
break;
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2009-10-24 19:36:24 +00:00
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case DPIW_MATRIX_WIDGET:
|
|
|
|
for (byte i = 0; i < this->vscroll.GetCapacity() && i + this->vscroll.GetPosition() < this->count; i++) {
|
|
|
|
int x = r.left + WD_MATRIX_LEFT;
|
|
|
|
int y = r.top + WD_MATRIX_TOP + i * this->resize.step_height;
|
|
|
|
bool selected = this->selected_index == i + this->vscroll.GetPosition();
|
|
|
|
|
|
|
|
if (this->index[i + this->vscroll.GetPosition()] == INVALID_INDUSTRYTYPE) {
|
|
|
|
DrawString(x + MATRIX_TEXT_OFFSET, r.right - WD_MATRIX_RIGHT, y, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll.GetPosition()]);
|
2008-05-10 23:43:08 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
/* Draw the name of the industry in white is selected, otherwise, in orange */
|
|
|
|
DrawString(x + MATRIX_TEXT_OFFSET, r.right - WD_MATRIX_RIGHT, y, indsp->name, selected ? TC_WHITE : TC_ORANGE);
|
|
|
|
GfxFillRect(x, y + 1, x + 10, y + 7, selected ? 15 : 0);
|
|
|
|
GfxFillRect(x + 1, y + 2, x + 9, y + 6, indsp->map_colour);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DPIW_INFOPANEL: {
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
|
|
|
int bottom = r.bottom - WD_FRAMERECT_BOTTOM;
|
|
|
|
int left = r.left + WD_FRAMERECT_LEFT;
|
|
|
|
int right = r.right - WD_FRAMERECT_RIGHT;
|
|
|
|
|
|
|
|
if (this->selected_type == INVALID_INDUSTRYTYPE) {
|
|
|
|
DrawStringMultiLine(left, right, y, bottom, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
|
|
|
|
|
|
|
|
if (_game_mode != GM_EDITOR) {
|
|
|
|
SetDParam(0, indsp->GetConstructionCost());
|
|
|
|
DrawString(left, right, y, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-07-10 00:59:00 +00:00
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
/* Draw the accepted cargos, if any. Otherwhise, will print "Nothing" */
|
|
|
|
char cargo_suffix[3][512];
|
|
|
|
GetAllCargoSuffixes(0, CST_FUND, NULL, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
|
|
|
|
StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
|
|
|
|
byte p = 0;
|
|
|
|
SetDParam(0, STR_JUST_NOTHING);
|
|
|
|
SetDParamStr(1, "");
|
|
|
|
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
|
|
|
|
if (indsp->accepts_cargo[j] == CT_INVALID) continue;
|
|
|
|
if (p > 0) str++;
|
|
|
|
SetDParam(p++, CargoSpec::Get(indsp->accepts_cargo[j])->name);
|
|
|
|
SetDParamStr(p++, cargo_suffix[j]);
|
|
|
|
}
|
|
|
|
DrawString(left, right, y, str);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
|
|
|
|
/* Draw the produced cargos, if any. Otherwhise, will print "Nothing" */
|
|
|
|
GetAllCargoSuffixes(3, CST_FUND, NULL, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
|
|
|
|
str = STR_INDUSTRY_VIEW_PRODUCES_CARGO;
|
|
|
|
p = 0;
|
|
|
|
SetDParam(0, STR_JUST_NOTHING);
|
|
|
|
SetDParamStr(1, "");
|
|
|
|
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
|
|
|
|
if (indsp->produced_cargo[j] == CT_INVALID) continue;
|
|
|
|
if (p > 0) str++;
|
|
|
|
SetDParam(p++, CargoSpec::Get(indsp->produced_cargo[j])->name);
|
|
|
|
SetDParamStr(p++, cargo_suffix[j]);
|
|
|
|
}
|
|
|
|
DrawString(left, right, y, str);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
|
|
|
|
/* Get the additional purchase info text, if it has not already been queried. */
|
|
|
|
str = STR_NULL;
|
|
|
|
if (HasBit(indsp->callback_mask, CBM_IND_FUND_MORE_TEXT)) {
|
|
|
|
uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, NULL, this->selected_type, INVALID_TILE);
|
|
|
|
if (callback_res != CALLBACK_FAILED) { // Did it fail?
|
|
|
|
str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the Additional purchase text, provided by newgrf callback, if any.
|
|
|
|
* Otherwhise, will print Nothing */
|
|
|
|
if (str != STR_NULL && str != STR_UNDEFINED) {
|
|
|
|
SetDParam(0, str);
|
|
|
|
DrawStringMultiLine(left, right, y, bottom, STR_JUST_STRING);
|
|
|
|
}
|
|
|
|
} break;
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-10 00:59:00 +00:00
|
|
|
|
2009-10-24 19:36:24 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
virtual void OnDoubleClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
if (widget != DPIW_MATRIX_WIDGET) return;
|
|
|
|
this->OnClick(pt, DPIW_FUND_WIDGET);
|
|
|
|
}
|
2007-07-10 00:59:00 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case DPIW_MATRIX_WIDGET: {
|
|
|
|
const IndustrySpec *indsp;
|
2009-10-24 19:36:24 +00:00
|
|
|
int y = (pt.y - this->GetWidget<NWidgetBase>(DPIW_MATRIX_WIDGET)->pos_y) / this->resize.step_height + this->vscroll.GetPosition() ;
|
2008-05-10 23:43:08 +00:00
|
|
|
|
|
|
|
if (y >= 0 && y < count) { // Is it within the boundaries of available data?
|
|
|
|
this->selected_index = y;
|
|
|
|
this->selected_type = this->index[y];
|
|
|
|
indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != NULL && indsp->IsRawIndustry()) ||
|
2008-05-10 23:43:08 +00:00
|
|
|
this->selected_type == INVALID_INDUSTRYTYPE) {
|
|
|
|
/* Reset the button state if going to prospecting or "build many industries" */
|
|
|
|
this->RaiseButtons();
|
|
|
|
ResetObjectToPlace();
|
2007-07-10 00:59:00 +00:00
|
|
|
}
|
2009-10-24 19:36:24 +00:00
|
|
|
|
|
|
|
this->SetWidgetDisabledState(DPIW_FUND_WIDGET, !this->enabled[this->selected_index]);
|
2007-07-10 00:59:00 +00:00
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
} break;
|
2007-07-10 00:59:00 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
case DPIW_FUND_WIDGET: {
|
|
|
|
if (this->selected_type == INVALID_INDUSTRYTYPE) {
|
|
|
|
this->HandleButtonClick(DPIW_FUND_WIDGET);
|
|
|
|
|
2009-05-22 15:23:47 +00:00
|
|
|
if (Town::GetNumItems() == 0) {
|
2009-10-31 19:46:51 +00:00
|
|
|
ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_INDUSTRIES, STR_ERROR_MUST_FOUND_TOWN_FIRST, 0, 0);
|
2007-07-19 01:35:48 +00:00
|
|
|
} else {
|
2008-05-10 23:43:08 +00:00
|
|
|
extern void GenerateIndustries();
|
|
|
|
_generating_world = true;
|
|
|
|
GenerateIndustries();
|
|
|
|
_generating_world = false;
|
2007-07-10 00:59:00 +00:00
|
|
|
}
|
2008-05-29 15:13:28 +00:00
|
|
|
} else if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
|
2009-04-21 23:40:56 +00:00
|
|
|
DoCommandP(0, this->selected_type, InteractiveRandom(), CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
|
2008-05-10 23:43:08 +00:00
|
|
|
this->HandleButtonClick(DPIW_FUND_WIDGET);
|
|
|
|
} else {
|
2009-04-19 10:31:30 +00:00
|
|
|
HandlePlacePushButton(this, DPIW_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT, NULL);
|
2007-07-16 23:48:25 +00:00
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 23:48:25 +00:00
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2008-05-10 23:43:08 +00:00
|
|
|
{
|
2009-10-24 19:36:24 +00:00
|
|
|
/* Adjust the number of items in the matrix depending of the resize */
|
|
|
|
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(DPIW_MATRIX_WIDGET)->current_y / this->resize.step_height);
|
|
|
|
this->GetWidget<NWidgetCore>(DPIW_MATRIX_WIDGET)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2007-07-19 01:35:48 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
/* We do not need to protect ourselves against "Random Many Industries" in this mode */
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
|
|
|
|
uint32 seed = InteractiveRandom();
|
|
|
|
|
|
|
|
if (_game_mode == GM_EDITOR) {
|
|
|
|
/* Show error if no town exists at all */
|
2009-05-22 15:23:47 +00:00
|
|
|
if (Town::GetNumItems() == 0) {
|
2008-05-10 23:43:08 +00:00
|
|
|
SetDParam(0, indsp->name);
|
2009-10-31 19:46:51 +00:00
|
|
|
ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, STR_ERROR_MUST_FOUND_TOWN_FIRST, pt.x, pt.y);
|
2008-05-10 23:43:08 +00:00
|
|
|
return;
|
2007-10-17 14:54:18 +00:00
|
|
|
}
|
2007-07-19 01:35:48 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
_current_company = OWNER_NONE;
|
2008-05-10 23:43:08 +00:00
|
|
|
_generating_world = true;
|
|
|
|
_ignore_restrictions = true;
|
2009-09-04 20:04:54 +00:00
|
|
|
success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
|
2008-05-10 23:43:08 +00:00
|
|
|
if (!success) {
|
|
|
|
SetDParam(0, indsp->name);
|
2009-10-31 19:46:51 +00:00
|
|
|
ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, _error_message, pt.x, pt.y);
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2007-07-16 23:48:25 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
_ignore_restrictions = false;
|
|
|
|
_generating_world = false;
|
|
|
|
} else {
|
2009-09-04 20:04:54 +00:00
|
|
|
success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2007-07-19 01:47:32 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
/* If an industry has been built, just reset the cursor and the system */
|
2009-01-07 17:40:17 +00:00
|
|
|
if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2007-07-19 01:47:32 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
virtual void OnTick()
|
|
|
|
{
|
2009-05-06 15:06:57 +00:00
|
|
|
if (_pause_mode != PM_UNPAUSED) return;
|
2008-05-10 23:43:08 +00:00
|
|
|
if (!this->timer_enabled) return;
|
|
|
|
if (--this->callback_timer == 0) {
|
|
|
|
/* We have just passed another day.
|
|
|
|
* See if we need to update availability of currently selected industry */
|
2009-03-15 00:32:18 +00:00
|
|
|
this->callback_timer = DAY_TICKS; // restart counter
|
2007-07-19 01:47:32 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
|
|
|
|
|
|
|
|
if (indsp->enabled) {
|
|
|
|
bool call_back_result = CheckIfCallBackAllowsAvailability(this->selected_type, IACT_USERCREATION);
|
|
|
|
|
|
|
|
/* Only if result does match the previous state would it require a redraw. */
|
|
|
|
if (call_back_result != this->enabled[this->selected_index]) {
|
|
|
|
this->enabled[this->selected_index] = call_back_result;
|
2009-10-24 19:36:24 +00:00
|
|
|
this->SetWidgetDisabledState(DPIW_FUND_WIDGET, !this->enabled[this->selected_index]);
|
2008-05-10 23:43:08 +00:00
|
|
|
this->SetDirty();
|
2007-07-19 01:47:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-10 23:43:08 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
|
|
|
this->RaiseButtons();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-10 23:43:08 +00:00
|
|
|
virtual void OnPlaceObjectAbort()
|
|
|
|
{
|
|
|
|
this->RaiseButtons();
|
|
|
|
}
|
2008-05-12 14:54:33 +00:00
|
|
|
|
|
|
|
virtual void OnInvalidateData(int data = 0)
|
|
|
|
{
|
|
|
|
this->SetupArrays();
|
2009-10-24 19:36:24 +00:00
|
|
|
|
|
|
|
const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
|
|
|
|
if (indsp == NULL) this->enabled[this->selected_index] = _settings_game.difficulty.number_industries != 0;
|
|
|
|
this->SetWidgetDisabledState(DPIW_FUND_WIDGET, !this->enabled[this->selected_index]);
|
2008-05-12 14:54:33 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowBuildIndustryWindow()
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2009-05-17 01:00:56 +00:00
|
|
|
if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
|
2008-05-10 23:43:08 +00:00
|
|
|
if (BringWindowToFrontById(WC_BUILD_INDUSTRY, 0)) return;
|
|
|
|
new BuildIndustryWindow();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-10 00:59:00 +00:00
|
|
|
static void UpdateIndustryProduction(Industry *i);
|
|
|
|
|
2008-05-06 15:06:19 +00:00
|
|
|
static inline bool IsProductionMinimum(const Industry *i, int pt)
|
2007-07-19 16:24:48 +00:00
|
|
|
{
|
2007-10-25 02:26:02 +00:00
|
|
|
return i->production_rate[pt] == 0;
|
2006-08-02 18:36:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 15:06:19 +00:00
|
|
|
static inline bool IsProductionMaximum(const Industry *i, int pt)
|
2007-07-19 16:24:48 +00:00
|
|
|
{
|
2007-10-25 02:26:02 +00:00
|
|
|
return i->production_rate[pt] >= 255;
|
2006-08-02 18:36:53 +00:00
|
|
|
}
|
|
|
|
|
2006-07-30 14:56:40 +00:00
|
|
|
static inline bool IsProductionAlterable(const Industry *i)
|
|
|
|
{
|
|
|
|
return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
|
2007-09-27 21:39:13 +00:00
|
|
|
(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
|
2006-07-30 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 17:07:50 +00:00
|
|
|
/** Names of the widgets of the view industry gui */
|
|
|
|
enum IndustryViewWidgets {
|
|
|
|
IVW_CLOSEBOX = 0,
|
|
|
|
IVW_CAPTION,
|
|
|
|
IVW_STICKY,
|
|
|
|
IVW_BACKGROUND,
|
2009-10-18 14:10:59 +00:00
|
|
|
IVW_INSET,
|
2007-12-09 17:07:50 +00:00
|
|
|
IVW_VIEWPORT,
|
|
|
|
IVW_INFO,
|
|
|
|
IVW_GOTO,
|
|
|
|
IVW_SPACER,
|
2008-05-10 15:58:22 +00:00
|
|
|
IVW_RESIZE,
|
2007-12-09 17:07:50 +00:00
|
|
|
};
|
|
|
|
|
2008-05-11 17:44:56 +00:00
|
|
|
class IndustryViewWindow : public Window
|
|
|
|
{
|
2007-07-19 16:24:48 +00:00
|
|
|
byte editbox_line; ///< The line clicked to open the edit box
|
|
|
|
byte clicked_line; ///< The line of the button that has been clicked
|
|
|
|
byte clicked_button; ///< The button that has been clicked (to raise)
|
|
|
|
byte production_offset_y; ///< The offset of the production texts/buttons
|
2009-10-18 14:10:59 +00:00
|
|
|
int info_height; ///< Height needed for the #IVW_INFO panel
|
2007-07-19 16:24:48 +00:00
|
|
|
|
2008-05-11 17:44:56 +00:00
|
|
|
public:
|
2009-10-18 14:10:59 +00:00
|
|
|
IndustryViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
|
2008-05-11 17:44:56 +00:00
|
|
|
{
|
|
|
|
this->flags4 |= WF_DISABLE_VP_SCROLL;
|
|
|
|
this->editbox_line = 0;
|
|
|
|
this->clicked_line = 0;
|
|
|
|
this->clicked_button = 0;
|
2009-10-18 14:10:59 +00:00
|
|
|
this->info_height = WD_FRAMERECT_TOP + 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + 1; // Info panel has at least two lines text.
|
|
|
|
|
|
|
|
this->InitNested(desc, window_number);
|
|
|
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(IVW_VIEWPORT);
|
|
|
|
nvp->InitializeViewport(this, Industry::Get(window_number)->xy + TileDiffXY(1, 1), ZOOM_LVL_INDUSTRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
|
2009-11-22 13:22:53 +00:00
|
|
|
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(IVW_INFO);
|
2009-10-18 14:10:59 +00:00
|
|
|
uint expected = this->DrawInfo(nwi->pos_x, nwi->pos_x + nwi->current_x - 1, nwi->pos_y) - nwi->pos_y;
|
|
|
|
if (expected > nwi->current_y - 1) {
|
|
|
|
this->info_height = expected + 1;
|
|
|
|
this->ReInit();
|
|
|
|
return;
|
|
|
|
}
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
2007-07-19 16:24:48 +00:00
|
|
|
|
2009-10-18 13:40:11 +00:00
|
|
|
/** Draw the text in the #IVW_INFO panel.
|
|
|
|
* @param left Left edge of the panel.
|
|
|
|
* @param right Right edge of the panel.
|
|
|
|
* @param top Top edge of the panel.
|
|
|
|
* @return Expected position of the bottom edge of the panel.
|
|
|
|
*/
|
|
|
|
int DrawInfo(uint left, uint right, uint top)
|
2008-05-11 17:44:56 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
Industry *i = Industry::Get(this->window_number);
|
2008-05-11 17:44:56 +00:00
|
|
|
const IndustrySpec *ind = GetIndustrySpec(i->type);
|
2009-10-18 13:56:09 +00:00
|
|
|
int y = top + WD_FRAMERECT_TOP;
|
2008-05-11 17:44:56 +00:00
|
|
|
bool first = true;
|
|
|
|
bool has_accept = false;
|
2009-10-18 15:36:30 +00:00
|
|
|
char cargo_suffix[3][512];
|
2008-05-11 17:44:56 +00:00
|
|
|
|
2009-09-14 12:22:57 +00:00
|
|
|
if (HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
|
2009-10-18 15:36:30 +00:00
|
|
|
GetAllCargoSuffixes(0, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
|
2008-05-11 17:44:56 +00:00
|
|
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
|
|
|
if (i->accepts_cargo[j] == CT_INVALID) continue;
|
|
|
|
has_accept = true;
|
2007-11-03 15:32:07 +00:00
|
|
|
if (first) {
|
2009-10-18 13:56:09 +00:00
|
|
|
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_WAITING_FOR_PROCESSING);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2007-11-03 15:32:07 +00:00
|
|
|
first = false;
|
2007-07-08 00:25:05 +00:00
|
|
|
}
|
2008-05-11 17:44:56 +00:00
|
|
|
SetDParam(0, i->accepts_cargo[j]);
|
|
|
|
SetDParam(1, i->incoming_cargo_waiting[j]);
|
2009-10-18 15:36:30 +00:00
|
|
|
SetDParamStr(2, cargo_suffix[j]);
|
2009-10-18 13:56:09 +00:00
|
|
|
DrawString(left + WD_FRAMETEXT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_WAITING_STOCKPILE_CARGO);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-10-18 15:36:30 +00:00
|
|
|
GetAllCargoSuffixes(0, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
|
2009-04-21 23:40:56 +00:00
|
|
|
StringID str = STR_INDUSTRY_VIEW_REQUIRES_CARGO;
|
2008-05-11 17:44:56 +00:00
|
|
|
byte p = 0;
|
|
|
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
|
|
|
if (i->accepts_cargo[j] == CT_INVALID) continue;
|
|
|
|
has_accept = true;
|
|
|
|
if (p > 0) str++;
|
2009-07-16 19:00:13 +00:00
|
|
|
SetDParam(p++, CargoSpec::Get(i->accepts_cargo[j])->name);
|
2009-10-18 15:36:30 +00:00
|
|
|
SetDParamStr(p++, cargo_suffix[j]);
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
|
|
|
if (has_accept) {
|
2009-10-18 13:56:09 +00:00
|
|
|
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, str);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-10-18 15:36:30 +00:00
|
|
|
GetAllCargoSuffixes(3, CST_VIEW, i, i->type, ind, i->produced_cargo, cargo_suffix);
|
2008-05-11 17:44:56 +00:00
|
|
|
first = true;
|
|
|
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
|
if (i->produced_cargo[j] == CT_INVALID) continue;
|
|
|
|
if (first) {
|
2009-10-18 13:59:25 +00:00
|
|
|
if (has_accept) y += WD_PAR_VSEP_WIDE;
|
2009-10-18 13:56:09 +00:00
|
|
|
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-11 17:44:56 +00:00
|
|
|
this->production_offset_y = y;
|
|
|
|
first = false;
|
2007-07-08 00:25:05 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-11 17:44:56 +00:00
|
|
|
SetDParam(0, i->produced_cargo[j]);
|
|
|
|
SetDParam(1, i->last_month_production[j]);
|
2009-10-18 15:36:30 +00:00
|
|
|
SetDParamStr(2, cargo_suffix[j]);
|
2009-08-27 13:31:26 +00:00
|
|
|
SetDParam(3, ToPercent8(i->last_month_pct_transported[j]));
|
2009-10-18 13:56:09 +00:00
|
|
|
uint x = left + WD_FRAMETEXT_LEFT + (IsProductionAlterable(i) ? 30 : 0);
|
|
|
|
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
|
2008-05-11 17:44:56 +00:00
|
|
|
/* Let's put out those buttons.. */
|
|
|
|
if (IsProductionAlterable(i)) {
|
2009-10-18 13:56:09 +00:00
|
|
|
DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == j + 1) ? this->clicked_button : 0,
|
2008-05-11 17:44:56 +00:00
|
|
|
!IsProductionMinimum(i, j), !IsProductionMaximum(i, j));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2009-10-18 13:56:09 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL;
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-11 17:44:56 +00:00
|
|
|
/* Get the extra message for the GUI */
|
2009-09-14 12:22:57 +00:00
|
|
|
if (HasBit(ind->callback_mask, CBM_IND_WINDOW_MORE_TEXT)) {
|
2008-05-11 17:44:56 +00:00
|
|
|
uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->xy);
|
|
|
|
if (callback_res != CALLBACK_FAILED) {
|
|
|
|
StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
|
|
|
|
if (message != STR_NULL && message != STR_UNDEFINED) {
|
2009-10-18 13:59:25 +00:00
|
|
|
y += WD_PAR_VSEP_WIDE;
|
2008-05-11 17:44:56 +00:00
|
|
|
|
|
|
|
PrepareTextRefStackUsage(6);
|
2009-04-09 01:10:35 +00:00
|
|
|
/* Use all the available space left from where we stand up to the
|
|
|
|
* end of the window. We ALSO enlarge the window if needed, so we
|
|
|
|
* can 'go' wild with the bottom of the window. */
|
2009-10-18 13:56:09 +00:00
|
|
|
y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, message);
|
2008-05-11 17:44:56 +00:00
|
|
|
StopTextRefStackUsage();
|
|
|
|
}
|
2008-05-05 16:05:36 +00:00
|
|
|
}
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
2009-10-18 14:10:59 +00:00
|
|
|
return y + WD_FRAMERECT_BOTTOM;
|
2009-10-18 13:40:11 +00:00
|
|
|
}
|
|
|
|
|
2009-10-18 14:10:59 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
2009-10-18 13:40:11 +00:00
|
|
|
{
|
2009-10-18 14:10:59 +00:00
|
|
|
if (widget== IVW_CAPTION) SetDParam(0, this->window_number);
|
|
|
|
}
|
2008-05-11 17:44:56 +00:00
|
|
|
|
2009-10-18 14:10:59 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
|
|
|
|
{
|
|
|
|
if (widget == IVW_INFO) size->height = this->info_height;
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
Industry *i;
|
|
|
|
|
|
|
|
switch (widget) {
|
|
|
|
case IVW_INFO: {
|
2009-05-16 23:34:14 +00:00
|
|
|
i = Industry::Get(this->window_number);
|
2008-05-11 17:44:56 +00:00
|
|
|
|
|
|
|
/* We should work if needed.. */
|
|
|
|
if (!IsProductionAlterable(i)) return;
|
2009-10-18 13:56:09 +00:00
|
|
|
uint x = pt.x;
|
|
|
|
int line = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
|
2008-05-11 17:44:56 +00:00
|
|
|
if (pt.y >= this->production_offset_y && IsInsideMM(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
|
2009-11-22 13:22:53 +00:00
|
|
|
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
|
2009-10-18 14:10:59 +00:00
|
|
|
uint left = nwi->pos_x + WD_FRAMETEXT_LEFT;
|
|
|
|
uint right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
|
2009-10-18 13:56:09 +00:00
|
|
|
if (IsInsideMM(x, left, left + 20) ) {
|
2008-05-11 17:44:56 +00:00
|
|
|
/* Clicked buttons, decrease or increase production */
|
2009-10-18 13:56:09 +00:00
|
|
|
if (x < left + 10) {
|
2008-05-11 17:44:56 +00:00
|
|
|
if (IsProductionMinimum(i, line)) return;
|
|
|
|
i->production_rate[line] = max(i->production_rate[line] / 2, 0);
|
|
|
|
} else {
|
|
|
|
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
|
|
|
|
int new_prod = i->production_rate[line] == 0 ? 1 : i->production_rate[line] * 2;
|
|
|
|
if (IsProductionMaximum(i, line)) return;
|
|
|
|
i->production_rate[line] = minu(new_prod, 255);
|
2008-05-05 16:05:36 +00:00
|
|
|
}
|
2005-01-14 00:14:13 +00:00
|
|
|
|
2008-05-11 17:44:56 +00:00
|
|
|
UpdateIndustryProduction(i);
|
|
|
|
this->SetDirty();
|
2008-09-23 15:24:15 +00:00
|
|
|
this->flags4 |= WF_TIMEOUT_BEGIN;
|
2008-05-11 17:44:56 +00:00
|
|
|
this->clicked_line = line + 1;
|
2009-10-18 13:56:09 +00:00
|
|
|
this->clicked_button = (x < left + 10 ? 1 : 2);
|
|
|
|
} else if (IsInsideMM(x, left + 30, right)) {
|
2008-05-11 17:44:56 +00:00
|
|
|
/* clicked the text */
|
|
|
|
this->editbox_line = line;
|
|
|
|
SetDParam(0, i->production_rate[line] * 8);
|
2009-07-23 19:31:50 +00:00
|
|
|
ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, 100, this, CS_ALPHANUMERAL, QSF_NONE);
|
2005-01-14 00:14:13 +00:00
|
|
|
}
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
2008-05-05 16:05:36 +00:00
|
|
|
} break;
|
2008-05-11 17:44:56 +00:00
|
|
|
|
|
|
|
case IVW_GOTO:
|
2009-05-16 23:34:14 +00:00
|
|
|
i = Industry::Get(this->window_number);
|
2008-05-11 17:44:56 +00:00
|
|
|
if (_ctrl_pressed) {
|
|
|
|
ShowExtraViewPortWindow(i->xy + TileDiffXY(1, 1));
|
|
|
|
} else {
|
|
|
|
ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2008-05-11 17:44:56 +00:00
|
|
|
|
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
|
|
|
this->clicked_line = 0;
|
|
|
|
this->clicked_button = 0;
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2008-05-11 17:44:56 +00:00
|
|
|
{
|
2009-10-18 14:10:59 +00:00
|
|
|
if (this->viewport != NULL) {
|
|
|
|
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(IVW_VIEWPORT);
|
|
|
|
nvp->UpdateViewportCoordinates(this);
|
|
|
|
}
|
2008-05-11 17:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (StrEmpty(str)) return;
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
Industry *i = Industry::Get(this->window_number);
|
2008-05-11 17:44:56 +00:00
|
|
|
int line = this->editbox_line;
|
|
|
|
|
2009-08-16 07:28:00 +00:00
|
|
|
i->production_rate[line] = ClampU(atoi(str) / 8, 0, 255);
|
2008-05-11 17:44:56 +00:00
|
|
|
UpdateIndustryProduction(i);
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-14 00:14:13 +00:00
|
|
|
static void UpdateIndustryProduction(Industry *i)
|
|
|
|
{
|
2007-09-27 21:39:13 +00:00
|
|
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
|
if (i->produced_cargo[j] != CT_INVALID) {
|
2007-06-07 14:38:45 +00:00
|
|
|
i->last_month_production[j] = 8 * i->production_rate[j];
|
2007-05-18 00:33:47 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-14 00:14:13 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 17:07:50 +00:00
|
|
|
/** Widget definition of the view industy gui */
|
2009-03-28 19:08:55 +00:00
|
|
|
static const NWidgetPart _nested_industry_view_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_CREAM, IVW_CLOSEBOX),
|
2009-11-22 11:20:12 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_CREAM, IVW_CAPTION), SetDataTip(STR_INDUSTRY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-28 19:08:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_CREAM, IVW_STICKY),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_CREAM, IVW_BACKGROUND),
|
2009-10-18 14:10:59 +00:00
|
|
|
NWidget(WWT_INSET, COLOUR_CREAM, IVW_INSET), SetPadding(2, 2, 2, 2),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(NWID_VIEWPORT, INVALID_COLOUR, IVW_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetPadding(1, 1, 1, 1), SetResize(1, 1),
|
2009-03-28 19:08:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_CREAM, IVW_INFO), SetMinimalSize(260, 2), SetResize(1, 0),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-04-21 23:40:56 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, IVW_GOTO), SetMinimalSize(130, 12), SetDataTip(STR_BUTTON_LOCATION, STR_INDUSTRY_VIEW_LOCATION_TOOLTIP),
|
2009-03-28 19:08:55 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_CREAM, IVW_SPACER), /*SetMinimalSize(118, 12),*/ SetResize(1, 0), EndContainer(),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_CREAM, IVW_RESIZE),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2007-12-09 17:07:50 +00:00
|
|
|
/** Window definition of the view industy gui */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _industry_view_desc(
|
2009-11-17 19:16:48 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 260, 120,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_INDUSTRY_VIEW, WC_NONE,
|
2008-05-10 15:58:22 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_industry_view_widgets, lengthof(_nested_industry_view_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
void ShowIndustryViewWindow(int industry)
|
|
|
|
{
|
2008-05-11 17:44:56 +00:00
|
|
|
AllocateWindowDescFront<IndustryViewWindow>(&_industry_view_desc, industry);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 17:07:50 +00:00
|
|
|
/** Names of the widgets of the industry directory gui */
|
|
|
|
enum IndustryDirectoryWidgets {
|
|
|
|
IDW_CLOSEBOX = 0,
|
|
|
|
IDW_CAPTION,
|
|
|
|
IDW_STICKY,
|
2008-05-28 16:45:00 +00:00
|
|
|
IDW_DROPDOWN_ORDER,
|
|
|
|
IDW_DROPDOWN_CRITERIA,
|
2007-12-09 17:07:50 +00:00
|
|
|
IDW_SPACER,
|
2008-05-18 23:36:33 +00:00
|
|
|
IDW_INDUSTRY_LIST,
|
2007-12-09 17:07:50 +00:00
|
|
|
IDW_SCROLLBAR,
|
|
|
|
IDW_RESIZE,
|
2007-07-18 15:59:08 +00:00
|
|
|
};
|
|
|
|
|
2007-12-09 17:07:50 +00:00
|
|
|
/** Widget definition of the industy directory gui */
|
2009-03-28 19:08:55 +00:00
|
|
|
static const NWidgetPart _nested_industry_directory_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN, IDW_CLOSEBOX),
|
2009-08-30 15:25:20 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN, IDW_CAPTION), SetDataTip(STR_INDUSTRY_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-28 19:08:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN, IDW_STICKY),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-08-30 15:25:20 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_BROWN, IDW_DROPDOWN_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_BROWN, IDW_DROPDOWN_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIAP),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, IDW_SPACER), SetResize(1, 0),
|
2009-03-28 19:08:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2009-08-30 15:25:20 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, IDW_INDUSTRY_LIST), SetDataTip(0x0, STR_INDUSTRY_DIRECTORY_LIST_CAPTION), SetResize(1, 1),
|
2009-03-28 19:08:55 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2009-11-22 11:24:30 +00:00
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_BROWN, IDW_SCROLLBAR),
|
2009-03-28 19:08:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, IDW_RESIZE),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
typedef GUIList<const Industry*> GUIIndustryList;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The list of industries.
|
2008-05-25 17:26:16 +00:00
|
|
|
*/
|
2008-05-28 16:45:00 +00:00
|
|
|
class IndustryDirectoryWindow : public Window {
|
|
|
|
protected:
|
|
|
|
/* Runtime saved values */
|
|
|
|
static Listing last_sorting;
|
|
|
|
static const Industry *last_industry;
|
2008-05-25 17:26:16 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/* Constants for sorting stations */
|
|
|
|
static const StringID sorter_names[];
|
2009-03-15 16:04:39 +00:00
|
|
|
static GUIIndustryList::SortFunction * const sorter_funcs[];
|
2008-05-25 17:26:16 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
GUIIndustryList industries;
|
2008-05-25 17:26:16 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/** (Re)Build industries list */
|
2009-08-30 13:44:25 +00:00
|
|
|
void BuildSortIndustriesList()
|
2008-05-28 16:45:00 +00:00
|
|
|
{
|
2009-08-30 13:44:25 +00:00
|
|
|
if (this->industries.NeedRebuild()) {
|
|
|
|
this->industries.Clear();
|
2008-05-25 17:26:16 +00:00
|
|
|
|
2009-08-30 13:44:25 +00:00
|
|
|
const Industry *i;
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
|
|
|
*this->industries.Append() = i;
|
|
|
|
}
|
2006-08-15 13:31:43 +00:00
|
|
|
|
2009-08-30 13:44:25 +00:00
|
|
|
this->industries.Compact();
|
|
|
|
this->industries.RebuildDone();
|
2009-09-02 07:36:39 +00:00
|
|
|
this->vscroll.SetCount(this->industries.Length()); // Update scrollbar as well.
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
2009-09-07 08:52:01 +00:00
|
|
|
|
|
|
|
if (!this->industries.Sort()) return;
|
|
|
|
IndustryDirectoryWindow::last_industry = NULL; // Reset name sorter sort cache
|
2009-09-13 19:15:59 +00:00
|
|
|
this->SetWidgetDirty(IDW_INDUSTRY_LIST); // Set the modified widget dirty
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
2006-08-15 13:31:43 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/**
|
|
|
|
* Returns percents of cargo transported if industry produces this cargo, else -1
|
|
|
|
*
|
|
|
|
* @param i industry to check
|
|
|
|
* @param id cargo slot
|
|
|
|
* @return percents of cargo transported, or -1 if industry doesn't use this cargo slot
|
|
|
|
*/
|
|
|
|
static inline int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
|
|
|
|
{
|
|
|
|
assert(id < lengthof(i->produced_cargo));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
if (i->produced_cargo[id] == CT_INVALID) return 101;
|
2009-08-27 13:31:26 +00:00
|
|
|
return ToPercent8(i->last_month_pct_transported[id]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/**
|
|
|
|
* Returns value representing industry's transported cargo
|
|
|
|
* percentage for industry sorting
|
|
|
|
*
|
|
|
|
* @param i industry to check
|
|
|
|
* @return value used for sorting
|
|
|
|
*/
|
|
|
|
static int GetCargoTransportedSortValue(const Industry *i)
|
|
|
|
{
|
|
|
|
int p1 = GetCargoTransportedPercentsIfValid(i, 0);
|
|
|
|
int p2 = GetCargoTransportedPercentsIfValid(i, 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
if (p1 > p2) Swap(p1, p2); // lower value has higher priority
|
2008-05-18 23:36:33 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
return (p1 << 8) + p2;
|
|
|
|
}
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/** Sort industries by name */
|
2009-01-10 00:31:47 +00:00
|
|
|
static int CDECL IndustryNameSorter(const Industry * const *a, const Industry * const *b)
|
2008-05-28 16:45:00 +00:00
|
|
|
{
|
|
|
|
static char buf_cache[96];
|
|
|
|
static char buf[96];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
SetDParam(0, (*a)->town->index);
|
2009-07-20 11:21:57 +00:00
|
|
|
GetString(buf, STR_TOWN_NAME, lastof(buf));
|
2008-05-18 23:36:33 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
if (*b != last_industry) {
|
|
|
|
last_industry = *b;
|
|
|
|
SetDParam(0, (*b)->town->index);
|
2009-07-20 11:21:57 +00:00
|
|
|
GetString(buf_cache, STR_TOWN_NAME, lastof(buf_cache));
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return strcmp(buf, buf_cache);
|
2008-05-26 16:23:23 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/** Sort industries by type and name */
|
2009-01-10 00:31:47 +00:00
|
|
|
static int CDECL IndustryTypeSorter(const Industry * const *a, const Industry * const *b)
|
2008-05-28 16:45:00 +00:00
|
|
|
{
|
|
|
|
int r = (*a)->type - (*b)->type;
|
2008-06-05 11:34:26 +00:00
|
|
|
return (r == 0) ? IndustryNameSorter(a, b) : r;
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
2008-05-18 23:36:33 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/** Sort industries by production and name */
|
2009-01-10 00:31:47 +00:00
|
|
|
static int CDECL IndustryProductionSorter(const Industry * const *a, const Industry * const *b)
|
2008-05-28 16:45:00 +00:00
|
|
|
{
|
2008-06-05 11:34:26 +00:00
|
|
|
int r = 0;
|
2008-05-28 16:45:00 +00:00
|
|
|
|
|
|
|
if ((*a)->produced_cargo[0] == CT_INVALID) {
|
|
|
|
if ((*b)->produced_cargo[0] != CT_INVALID) return -1;
|
|
|
|
} else {
|
|
|
|
if ((*b)->produced_cargo[0] == CT_INVALID) return 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
r = ((*a)->last_month_production[0] + (*a)->last_month_production[1]) -
|
|
|
|
((*b)->last_month_production[0] + (*b)->last_month_production[1]);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-06-05 11:34:26 +00:00
|
|
|
return (r == 0) ? IndustryNameSorter(a, b) : r;
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
/** Sort industries by transported cargo and name */
|
2009-01-10 00:31:47 +00:00
|
|
|
static int CDECL IndustryTransportedCargoSorter(const Industry * const *a, const Industry * const *b)
|
2008-05-28 16:45:00 +00:00
|
|
|
{
|
|
|
|
int r = GetCargoTransportedSortValue(*a) - GetCargoTransportedSortValue(*b);
|
2008-06-05 11:34:26 +00:00
|
|
|
return (r == 0) ? IndustryNameSorter(a, b) : r;
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-08-30 14:06:55 +00:00
|
|
|
/**
|
|
|
|
* Get the StringID to draw and set the appropriate DParams.
|
|
|
|
* @param i the industry to get the StringID of.
|
|
|
|
* @return the StringID.
|
|
|
|
*/
|
2009-08-30 15:25:20 +00:00
|
|
|
StringID GetIndustryString(const Industry *i) const
|
2009-08-30 14:06:55 +00:00
|
|
|
{
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
|
|
|
byte p = 0;
|
|
|
|
|
|
|
|
/* Industry name */
|
|
|
|
SetDParam(p++, i->index);
|
|
|
|
|
2009-10-18 15:36:30 +00:00
|
|
|
char cargo_suffix[lengthof(i->produced_cargo)][512];
|
|
|
|
GetAllCargoSuffixes(3, CST_DIR, i, i->type, indsp, i->produced_cargo, cargo_suffix);
|
|
|
|
|
2009-08-30 14:06:55 +00:00
|
|
|
/* Industry productions */
|
|
|
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
|
if (i->produced_cargo[j] == CT_INVALID) continue;
|
|
|
|
SetDParam(p++, i->produced_cargo[j]);
|
|
|
|
SetDParam(p++, i->last_month_production[j]);
|
2009-10-18 15:36:30 +00:00
|
|
|
SetDParamStr(p++, cargo_suffix[j]);
|
2009-08-30 14:06:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Transported productions */
|
|
|
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
|
if (i->produced_cargo[j] == CT_INVALID) continue;
|
|
|
|
SetDParam(p++, ToPercent8(i->last_month_pct_transported[j]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Drawing the right string */
|
|
|
|
switch (p) {
|
|
|
|
case 1: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
|
|
|
|
case 5: return STR_INDUSTRY_DIRECTORY_ITEM;
|
|
|
|
default: return STR_INDUSTRY_DIRECTORY_ITEM_TWO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
public:
|
2009-08-30 15:25:20 +00:00
|
|
|
IndustryDirectoryWindow(const WindowDesc *desc, WindowNumber number) : Window()
|
2008-05-18 23:36:33 +00:00
|
|
|
{
|
2008-05-28 16:45:00 +00:00
|
|
|
this->industries.SetListing(this->last_sorting);
|
2009-08-30 15:25:20 +00:00
|
|
|
this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
|
2008-05-28 16:45:00 +00:00
|
|
|
this->industries.ForceRebuild();
|
2009-08-30 13:44:25 +00:00
|
|
|
this->BuildSortIndustriesList();
|
2008-05-28 16:45:00 +00:00
|
|
|
|
2009-08-30 15:25:20 +00:00
|
|
|
this->InitNested(desc, 0);
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~IndustryDirectoryWindow()
|
|
|
|
{
|
|
|
|
this->last_sorting = this->industries.GetListing();
|
2008-05-18 23:36:33 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-08-30 15:25:20 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
if (widget == IDW_DROPDOWN_CRITERIA) SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.SortType()]);
|
|
|
|
}
|
|
|
|
|
2008-05-18 23:36:33 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
2009-08-30 15:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case IDW_DROPDOWN_ORDER:
|
|
|
|
this->DrawSortButtonState(widget, this->industries.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDW_INDUSTRY_LIST: {
|
|
|
|
int n = 0;
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
2009-09-05 11:27:28 +00:00
|
|
|
if (this->industries.Length() == 0) {
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_DIRECTORY_NONE);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-02 07:36:39 +00:00
|
|
|
for (uint i = this->vscroll.GetPosition(); i < this->industries.Length(); i++) {
|
2009-08-30 15:25:20 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, this->GetIndustryString(this->industries[i]));
|
2008-05-18 23:36:33 +00:00
|
|
|
|
2009-08-30 15:25:20 +00:00
|
|
|
y += this->resize.step_height;
|
2009-09-02 07:36:39 +00:00
|
|
|
if (++n == this->vscroll.GetCapacity()) break; // max number of industries in 1 window
|
2009-08-30 15:25:20 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case IDW_DROPDOWN_ORDER: {
|
2009-09-19 11:31:12 +00:00
|
|
|
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
2009-08-30 15:25:20 +00:00
|
|
|
d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the word is centered, also looks nice.
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-18 23:36:33 +00:00
|
|
|
|
2009-08-30 15:25:20 +00:00
|
|
|
case IDW_DROPDOWN_CRITERIA: {
|
|
|
|
Dimension d = {0, 0};
|
|
|
|
for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
|
|
|
|
d = maxdim(d, GetStringBoundingBox(IndustryDirectoryWindow::sorter_names[i]));
|
|
|
|
}
|
|
|
|
d.width += padding.width;
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IDW_INDUSTRY_LIST: {
|
2009-09-05 11:27:28 +00:00
|
|
|
Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
|
2009-08-30 15:25:20 +00:00
|
|
|
for (uint i = 0; i < this->industries.Length(); i++) {
|
|
|
|
d = maxdim(d, GetStringBoundingBox(this->GetIndustryString(this->industries[i])));
|
|
|
|
}
|
|
|
|
resize->height = d.height;
|
|
|
|
d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
|
|
|
d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-18 23:36:33 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2008-05-18 23:36:33 +00:00
|
|
|
|
2009-08-30 15:25:20 +00:00
|
|
|
|
2008-05-18 23:36:33 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2008-05-28 16:45:00 +00:00
|
|
|
case IDW_DROPDOWN_ORDER:
|
|
|
|
this->industries.ToggleSortOrder();
|
2008-05-18 23:36:33 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
case IDW_DROPDOWN_CRITERIA:
|
2009-08-30 15:25:20 +00:00
|
|
|
ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), IDW_DROPDOWN_CRITERIA, 0, 0);
|
2008-05-28 16:45:00 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-18 23:36:33 +00:00
|
|
|
case IDW_INDUSTRY_LIST: {
|
2009-09-19 11:31:12 +00:00
|
|
|
int y = (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height;
|
2008-05-18 23:36:33 +00:00
|
|
|
uint16 p;
|
|
|
|
|
2009-09-02 07:36:39 +00:00
|
|
|
if (!IsInsideMM(y, 0, this->vscroll.GetCapacity())) return;
|
|
|
|
p = y + this->vscroll.GetPosition();
|
2008-05-27 18:50:31 +00:00
|
|
|
if (p < this->industries.Length()) {
|
2008-05-18 23:36:33 +00:00
|
|
|
if (_ctrl_pressed) {
|
2008-05-27 18:50:31 +00:00
|
|
|
ShowExtraViewPortWindow(this->industries[p]->xy);
|
2008-05-18 23:36:33 +00:00
|
|
|
} else {
|
2008-05-27 18:50:31 +00:00
|
|
|
ScrollMainWindowToTile(this->industries[p]->xy);
|
2008-05-18 23:36:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
|
|
|
if (this->industries.SortType() != index) {
|
|
|
|
this->industries.SetSortType(index);
|
2009-09-07 08:52:01 +00:00
|
|
|
this->BuildSortIndustriesList();
|
2008-05-28 16:45:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2008-05-18 23:36:33 +00:00
|
|
|
{
|
2009-10-17 14:29:10 +00:00
|
|
|
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(IDW_INDUSTRY_LIST)->current_y / this->resize.step_height);
|
2008-05-18 23:36:33 +00:00
|
|
|
}
|
|
|
|
|
2009-08-30 13:44:25 +00:00
|
|
|
virtual void OnHundredthTick()
|
|
|
|
{
|
2009-09-07 08:52:01 +00:00
|
|
|
this->industries.ForceResort();
|
2009-08-30 13:44:25 +00:00
|
|
|
this->BuildSortIndustriesList();
|
|
|
|
}
|
|
|
|
|
2008-05-18 23:36:33 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
|
|
|
{
|
2008-05-28 16:45:00 +00:00
|
|
|
if (data == 0) {
|
|
|
|
this->industries.ForceRebuild();
|
|
|
|
} else {
|
|
|
|
this->industries.ForceResort();
|
|
|
|
}
|
2009-08-30 13:44:25 +00:00
|
|
|
this->BuildSortIndustriesList();
|
2008-05-18 23:36:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-28 16:45:00 +00:00
|
|
|
Listing IndustryDirectoryWindow::last_sorting = {false, 0};
|
|
|
|
const Industry *IndustryDirectoryWindow::last_industry = NULL;
|
|
|
|
|
|
|
|
/* Availible station sorting functions */
|
2009-01-10 00:31:47 +00:00
|
|
|
GUIIndustryList::SortFunction * const IndustryDirectoryWindow::sorter_funcs[] = {
|
2008-05-28 16:45:00 +00:00
|
|
|
&IndustryNameSorter,
|
|
|
|
&IndustryTypeSorter,
|
|
|
|
&IndustryProductionSorter,
|
|
|
|
&IndustryTransportedCargoSorter
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Names of the sorting functions */
|
|
|
|
const StringID IndustryDirectoryWindow::sorter_names[] = {
|
2009-07-23 19:31:50 +00:00
|
|
|
STR_SORT_BY_NAME,
|
2008-05-28 16:45:00 +00:00
|
|
|
STR_SORT_BY_TYPE,
|
|
|
|
STR_SORT_BY_PRODUCTION,
|
|
|
|
STR_SORT_BY_TRANSPORTED,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-12-09 17:07:50 +00:00
|
|
|
/** Window definition of the industy directory gui */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _industry_directory_desc(
|
2009-11-17 19:16:48 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 428, 190,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_INDUSTRY_DIRECTORY, WC_NONE,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_industry_directory_widgets, lengthof(_nested_industry_directory_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowIndustryDirectory()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-05-18 23:36:33 +00:00
|
|
|
AllocateWindowDescFront<IndustryDirectoryWindow>(&_industry_directory_desc, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|