Changeset - r15737:acc9b17c80d0
[Not reviewed]
master
0 3 0
alberth - 14 years ago 2010-08-08 11:17:14
alberth@openttd.org
(svn r20414) -Feature: Enable industries in the smallmap displayed in the industry chain window.
3 files changed with 63 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/industry_gui.cpp
Show inline comments
 
@@ -3,51 +3,57 @@
 
/*
 
 * 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/>.
 
 */
 

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

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "gui.h"
 
#include "sound_func.h"
 
#include "window_func.h"
 
#include "textbuf_gui.h"
 
#include "command_func.h"
 
#include "viewport_func.h"
 
#include "gfx_func.h"
 
#include "industry.h"
 
#include "town.h"
 
#include "cheat_type.h"
 
#include "newgrf.h"
 
#include "newgrf_industries.h"
 
#include "newgrf_text.h"
 
#include "newgrf_debug.h"
 
#include "strings_func.h"
 
#include "company_func.h"
 
#include "tilehighlight_func.h"
 
#include "string_func.h"
 
#include "sortlist_type.h"
 
#include "widgets/dropdown_func.h"
 
#include "company_base.h"
 
#include "core/geometry_func.hpp"
 
#include "core/random_func.hpp"
 
#include "core/backup_type.hpp"
 
#include "genworld.h"
 
#include "smallmap_gui.h"
 

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

	
 
bool _ignore_restrictions;
 
uint64 _displayed_industries; ///< Communication from the industry chain window to the smallmap window about what industries to display.
 

	
 
assert_compile(NUM_INDUSTRYTYPES <= 64); // Make sure all industry types fit in _displayed_industries.
 

	
 
/** Cargo suffix type (for which window is it requested) */
 
enum CargoSuffixType {
 
	CST_FUND,  ///< Fund-industry window
 
	CST_VIEW,  ///< View-industry window
 
	CST_DIR,   ///< Industry-directory window
 
};
 

	
 
static void ShowIndustryCargoesWindow(IndustryType id);
 

	
 
/**
 
 * Gets the string to display after the cargo name (using callback 37)
 
@@ -1280,38 +1286,46 @@ static const WindowDesc _industry_direct
 
	WDF_UNCLICK_BUTTONS,
 
	_nested_industry_directory_widgets, lengthof(_nested_industry_directory_widgets)
 
);
 

	
 
void ShowIndustryDirectory()
 
{
 
	AllocateWindowDescFront<IndustryDirectoryWindow>(&_industry_directory_desc, 0);
 
}
 

	
 
/** Widget numbers of the industry cargoes window, */
 
enum IndustryCargoesWidgets {
 
	ICW_CAPTION,
 
	ICW_NOTIFY,
 
	ICW_PANEL,
 
	ICW_SCROLLBAR,
 
};
 

	
 
/** Widgets of the industry cargoes window. */
 
static const NWidgetPart _nested_industry_cargoes_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
 
		NWidget(WWT_CAPTION, COLOUR_BROWN, ICW_CAPTION), SetDataTip(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
 
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
 
	EndContainer(),
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_PANEL, COLOUR_BROWN, ICW_PANEL), SetResize(1, 10), SetMinimalSize(200, 90), EndContainer(),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(WWT_PANEL, COLOUR_BROWN, ICW_PANEL), SetResize(1, 10), SetMinimalSize(200, 90), EndContainer(),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_TEXTBTN, COLOUR_BROWN, ICW_NOTIFY),
 
					SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
 
				NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(1, 0), EndContainer(),
 
			EndContainer(),
 
		EndContainer(),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(WWT_SCROLLBAR, COLOUR_BROWN, ICW_SCROLLBAR),
 
			NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
 
		EndContainer(),
 
	EndContainer(),
 
};
 

	
 
/** Window description for the industry cargoes window. */
 
static const WindowDesc _industry_cargoes_desc(
 
	WDP_AUTO, 300, 210,
 
	WC_INDUSTRY_CARGOES, WC_NONE,
 
	0,
 
@@ -2100,31 +2114,44 @@ struct IndustryCargoesWindow : public Wi
 
	void PlaceIndustry(int row, int col, IndustryType it)
 
	{
 
		assert(this->fields[row].columns[col].type == CFT_EMPTY);
 
		this->fields[row].columns[col].MakeIndustry(it);
 
		if (col == 0) {
 
			this->fields[row].ConnectIndustryProduced(col);
 
		} else {
 
			this->fields[row].ConnectIndustryAccepted(col);
 
		}
 
	}
 

	
 
	/**
 
	 * Notify smallmap that new displayed industries have been selected (in #_displayed_industries).
 
	 */
 
	void NotifySmallmap()
 
	{
 
		if (!this->IsWidgetLowered(ICW_NOTIFY)) return;
 

	
 
		/* Only notify the smallmap window if it exists. In particular, do not
 
		 * bring it to the front to prevent messing up any nice layout of the user. */
 
		InvalidateWindowClassesData(WC_SMALLMAP, 0);
 
	}
 

	
 
	/**
 
	 * Compute what and where to display for industry type \a it.
 
	 * @param it Industry type to display.
 
	 */
 
	void ComputeIndustryDisplay(IndustryType it)
 
	{
 
		this->GetWidget<NWidgetCore>(ICW_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
 
		this->ind_cargo = it;
 
		_displayed_industries = 1 << it;
 

	
 
		this->fields.Clear();
 
		CargoesRow *row = this->fields.Append();
 
		row->columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
 
		row->columns[1].MakeEmpty(CFT_SMALL_EMPTY);
 
		row->columns[2].MakeEmpty(CFT_SMALL_EMPTY);
 
		row->columns[3].MakeEmpty(CFT_SMALL_EMPTY);
 
		row->columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
 

	
 
		const IndustrySpec *central_sp = GetIndustrySpec(it);
 
		bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
 
		bool houses_accept = HousesCanAccept(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
 
@@ -2150,55 +2177,59 @@ struct IndustryCargoesWindow : public Wi
 
		this->fields[central_row - 1].MakeCargoLabel(2, true);
 
		this->fields[central_row + 1].MakeCargoLabel(2, false);
 

	
 
		/* Add suppliers and customers of the 'it' industry. */
 
		int supp_count = 0;
 
		int cust_count = 0;
 
		for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
			const IndustrySpec *indsp = GetIndustrySpec(it);
 
			if (!indsp->enabled) continue;
 

	
 
			if (HasCommonValidCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo), indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
 
				this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
 
				SetBit(_displayed_industries, it);
 
				supp_count++;
 
			}
 
			if (HasCommonValidCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo), indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
 
				this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
 
				SetBit(_displayed_industries, it);
 
				cust_count++;
 
			}
 
		}
 
		if (houses_supply) {
 
			this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
 
			supp_count++;
 
		}
 
		if (houses_accept) {
 
			this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, NUM_INDUSTRYTYPES);
 
			cust_count++;
 
		}
 

	
 
		this->ShortenCargoColumn(1, 1, num_indrows);
 
		this->ShortenCargoColumn(3, 1, num_indrows);
 
		const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(ICW_PANEL);
 
		this->vscroll.SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y));
 
		this->SetDirty();
 
		this->NotifySmallmap();
 
	}
 

	
 
	/**
 
	 * Compute what and where to display for cargo id \a cid.
 
	 * @param cid Cargo id to display.
 
	 */
 
	void ComputeCargoDisplay(CargoID cid)
 
	{
 
		this->GetWidget<NWidgetCore>(ICW_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
 
		this->ind_cargo = cid + NUM_INDUSTRYTYPES;
 
		_displayed_industries = 0;
 

	
 
		this->fields.Clear();
 
		CargoesRow *row = this->fields.Append();
 
		row->columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
 
		row->columns[1].MakeEmpty(CFT_SMALL_EMPTY);
 
		row->columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
 
		row->columns[3].MakeEmpty(CFT_SMALL_EMPTY);
 
		row->columns[4].MakeEmpty(CFT_SMALL_EMPTY);
 

	
 
		bool houses_supply = HousesCanSupply(&cid, 1);
 
		bool houses_accept = HousesCanAccept(&cid, 1);
 
		int num_supp = CountMatchingProducingIndustries(&cid, 1) + houses_supply + 1; // Ensure room for the cargo label.
 
@@ -2215,44 +2246,47 @@ struct IndustryCargoesWindow : public Wi
 

	
 
		this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom.
 

	
 
		/* Add suppliers and customers of the cargo. */
 
		int supp_count = 0;
 
		int cust_count = 0;
 
		for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
			const IndustrySpec *indsp = GetIndustrySpec(it);
 
			if (!indsp->enabled) continue;
 

	
 
			if (HasCommonValidCargo(&cid, 1, indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
 
				this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
 
				SetBit(_displayed_industries, it);
 
				supp_count++;
 
			}
 
			if (HasCommonValidCargo(&cid, 1, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
 
				this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
 
				SetBit(_displayed_industries, it);
 
				cust_count++;
 
			}
 
		}
 
		if (houses_supply) {
 
			this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
 
			supp_count++;
 
		}
 
		if (houses_accept) {
 
			this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, NUM_INDUSTRYTYPES);
 
			cust_count++;
 
		}
 

	
 
		this->ShortenCargoColumn(1, 1, num_indrows);
 
		const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(ICW_PANEL);
 
		this->vscroll.SetCount(CeilDiv(WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + CargoesField::small_height + num_indrows * CargoesField::normal_height, nwp->resize_y));
 
		this->SetDirty();
 
		this->NotifySmallmap();
 
	}
 

	
 
	/**
 
	 * Notify the window to display another industry type.
 
	 * @param data The new industry type to display.
 
	 */
 
	virtual void OnInvalidateData(int data)
 
	{
 
		assert(data >= 0 && data < NUM_INDUSTRYTYPES);
 
		this->ComputeIndustryDisplay(data);
 
	}
 

	
 
@@ -2367,24 +2401,35 @@ struct IndustryCargoesWindow : public Wi
 

	
 
					case CFT_CARGO_LABEL: {
 
						CargoID cid = fld->CargoLabelClickedAt(xy);
 
						if (cid != INVALID_CARGO) this->ComputeCargoDisplay(cid);
 
						break;
 
					}
 

	
 
					default:
 
						break;
 
				}
 
				break;
 
			}
 

	
 
			case ICW_NOTIFY:
 
				this->ToggleWidgetLoweredState(ICW_NOTIFY);
 
				this->SetWidgetDirty(ICW_NOTIFY);
 
				SndPlayFx(SND_15_BEEP);
 

	
 
				if (this->IsWidgetLowered(ICW_NOTIFY)) {
 
					if (FindWindowByClass(WC_SMALLMAP) == NULL) ShowSmallMap();
 
					this->NotifySmallmap();
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnHover(Point pt, int widget)
 
	{
 
		if (widget != ICW_PANEL) return;
 

	
 
		Point fieldxy, xy;
 
		if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return;
 

	
 
		const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
 
		CargoID cid = INVALID_CARGO;
src/lang/english.txt
Show inline comments
 
@@ -2122,24 +2122,26 @@ STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY    
 
STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY                             :{BLACK}Fund
 

	
 
# Industry cargoes window
 
STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION                           :{WHITE}Industry chain for {STRING} industry
 
STR_INDUSTRY_CARGOES_CARGO_CAPTION                              :{WHITE}Industry chain for {STRING} cargo
 
STR_INDUSTRY_CARGOES_PRODUCERS                                  :{WHITE}Producing industries
 
STR_INDUSTRY_CARGOES_CUSTOMERS                                  :{WHITE}Accepting industries
 
STR_INDUSTRY_CARGOES_HOUSES                                     :{WHITE}Houses
 
STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP                           :{BLACK}Click at the industry to see its suppliers and customers
 
STR_INDUSTRY_CARGOES_CARGO_TOOLTIP                              :{BLACK}{STRING}{}Click at the cargo to see its suppliers and customers
 
STR_INDUSTRY_DISPLAY_CHAIN                                      :{BLACK}Display chain
 
STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP                              :{BLACK}Display cargo supplying and accepting industries
 
STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP                            :{BLACK}Link to smallmap
 
STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP                    :{BLACK}Select the displayed industries at the smallmap as well
 

	
 
# Land area window
 
STR_LAND_AREA_INFORMATION_CAPTION                               :{WHITE}Land Area Information
 
STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A                     :{BLACK}Cost to clear: {LTBLUE}N/A
 
STR_LAND_AREA_INFORMATION_COST_TO_CLEAR                         :{BLACK}Cost to clear: {RED}{CURRENCY}
 
STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED                  :{BLACK}Revenue when cleared: {LTBLUE}{CURRENCY}
 
STR_LAND_AREA_INFORMATION_OWNER_N_A                             :N/A
 
STR_LAND_AREA_INFORMATION_OWNER                                 :{BLACK}Owner: {LTBLUE}{STRING1}
 
STR_LAND_AREA_INFORMATION_ROAD_OWNER                            :{BLACK}Road owner: {LTBLUE}{STRING1}
 
STR_LAND_AREA_INFORMATION_TRAM_OWNER                            :{BLACK}Tramway owner: {LTBLUE}{STRING1}
 
STR_LAND_AREA_INFORMATION_RAIL_OWNER                            :{BLACK}Railway owner: {LTBLUE}{STRING1}
 
STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY                       :{BLACK}Local authority: {LTBLUE}{STRING1}
src/smallmap_gui.cpp
Show inline comments
 
@@ -1269,24 +1269,39 @@ public:
 
				}
 
				this->SetDirty();
 
				break;
 

	
 
			case SM_WIDGET_SHOW_HEIGHT: // Enable/disable showing of heightmap.
 
				_smallmap_industry_show_heightmap = !_smallmap_industry_show_heightmap;
 
				this->SetWidgetLoweredState(SM_WIDGET_SHOW_HEIGHT, _smallmap_industry_show_heightmap);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

	
 
	/**
 
	 * Notifications for the smallmap window.
 
	 * - data = 0: Displayed industries at the industry chain window have changed.
 
	 */
 
	virtual void OnInvalidateData(int data)
 
	{
 
		extern uint64 _displayed_industries;
 
		if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
 

	
 
		for (int i = 0; i != _smallmap_industry_count; i++) {
 
			_legend_from_industries[i].show_on_map = HasBit(_displayed_industries, _legend_from_industries[i].u.type);
 
		}
 
		this->SetDirty();
 
	}
 

	
 
	virtual bool OnRightClick(Point pt, int widget)
 
	{
 
		if (widget != SM_WIDGET_MAP || _scrolling_viewport) return false;
 

	
 
		_scrolling_viewport = true;
 
		return true;
 
	}
 

	
 
	virtual void OnMouseWheel(int wheel)
 
	{
 
		const NWidgetBase *wid = this->GetWidget<NWidgetBase>(SM_WIDGET_MAP);
 
		int cursor_x = _cursor.pos.x - this->left - wid->pos_x;
0 comments (0 inline, 0 general)