File diff r10959:4b345c618e31 → r10960:e97ebf9cf99b
src/industry_gui.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file industry_gui.cpp GUIs related to industries. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "debug.h"
 
#include "gui.h"
 
#include "window_gui.h"
 
#include "textbuf_gui.h"
 
#include "command_func.h"
 
#include "viewport_func.h"
 
#include "gfx_func.h"
 
#include "industry.h"
 
#include "town.h"
 
#include "variables.h"
 
#include "cheat_func.h"
 
#include "cargotype.h"
 
#include "cheat_type.h"
 
#include "newgrf.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_industries.h"
 
#include "newgrf_text.h"
 
#include "strings_func.h"
 
#include "map_func.h"
 
#include "company_func.h"
 
#include "settings_type.h"
 
#include "tilehighlight_func.h"
 
#include "string_func.h"
 
#include "sortlist_type.h"
 
#include "widgets/dropdown_func.h"
 
#include "company_base.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 

	
 
bool _ignore_restrictions;
 

	
 
enum CargoSuffixType {
 
	CST_FUND,
 
	CST_VIEW,
 
	CST_DIR,
 
};
 

	
 
/**
 
 * 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
 
 * @param cst the cargo suffix type (for which window is it requested)
 
 * @param ind the industry (NULL if in fund window)
 
 * @param ind_type the industry type
 
 * @param indspec the industry spec
 
 * @return the string to display
 
 */
 
static StringID GetCargoSuffix(uint cargo, CargoSuffixType cst, Industry *ind, IndustryType ind_type, const IndustrySpec *indspec)
 
{
 
	if (HasBit(indspec->callback_flags, CBM_IND_CARGO_SUFFIX)) {
 
		uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, ind, ind_type, (cst != CST_FUND) ? ind->xy : INVALID_TILE);
 
		if (GB(callback, 0, 8) != 0xFF) return GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback);
 
	}
 
	return STR_EMPTY;
 
}
 

	
 
/** 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,
 
};
 

	
 
/** Widget definition of the dynamic place industries gui */
 
static const Widget _build_industry_widgets[] = {
 
{   WWT_CLOSEBOX,    RESIZE_NONE,  COLOUR_DARK_GREEN,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},            // DPIW_CLOSEBOX
 
{    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_DARK_GREEN,    11,   169,     0,    13, STR_0314_FUND_NEW_INDUSTRY,     STR_018C_WINDOW_TITLE_DRAG_THIS},  // DPIW_CAPTION
 
{     WWT_MATRIX,      RESIZE_RB,  COLOUR_DARK_GREEN,     0,   157,    14,   118, 0x801,                          STR_INDUSTRY_SELECTION_HINT},      // DPIW_MATRIX_WIDGET
 
{  WWT_SCROLLBAR,     RESIZE_LRB,  COLOUR_DARK_GREEN,   158,   169,    14,   118, 0x0,                            STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DPIW_SCROLLBAR
 
{      WWT_PANEL,     RESIZE_RTB,  COLOUR_DARK_GREEN,     0,   169,   119,   199, 0x0,                            STR_NULL},                         // DPIW_INFOPANEL
 
{    WWT_TEXTBTN,     RESIZE_RTB,  COLOUR_DARK_GREEN,     0,   157,   200,   211, STR_FUND_NEW_INDUSTRY,          STR_NULL},                         // DPIW_FUND_WIDGET
 
{  WWT_RESIZEBOX,    RESIZE_LRTB,  COLOUR_DARK_GREEN,   158,   169,   200,   211, 0x0,                            STR_RESIZE_BUTTON},                // DPIW_RESIZE_WIDGET
 
{   WIDGETS_END},
 
};
 

	
 
/** Window definition of the dynamic place industries gui */
 
static const WindowDesc _build_industry_desc = {
 
	WDP_AUTO, WDP_AUTO, 170, 212, 170, 212,
 
	WC_BUILD_INDUSTRY, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
 
	_build_industry_widgets,
 
};
 

	
 
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
 
	StringID text[NUM_INDUSTRYTYPES + 1];       ///< Text coming from CBM_IND_FUND_MORE_TEXT (if ever)
 
	bool enabled[NUM_INDUSTRYTYPES + 1];        ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
 

	
 
	void SetupArrays()
 
	{
 
		IndustryType ind;
 
		const IndustrySpec *indsp;
 

	
 
		this->count = 0;
 

	
 
		for (uint i = 0; i < lengthof(this->index); i++) {
 
			this->index[i]   = INVALID_INDUSTRYTYPE;
 
			this->text[i]    = STR_NULL;
 
			this->enabled[i] = false;
 
		}
 

	
 
		if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
 
			this->index[this->count] = INVALID_INDUSTRYTYPE;