Changeset - r19808:698bcdaa2d41
[Not reviewed]
master
0 7 0
alberth - 12 years ago 2012-11-25 15:24:02
alberth@openttd.org
(svn r24763) -Feature: Add industry type and cargo dropdown selection for easier navigating in the industry chain window.
7 files changed with 117 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/gui.h
Show inline comments
 
@@ -45,12 +45,13 @@ void ShowHeightmapLoad();
 
/* misc_gui.cpp */
 
void ShowLandInfo(TileIndex tile);
 
void ShowAboutWindow();
 
void ShowBuildTreesToolbar();
 
void ShowTownDirectory();
 
void ShowIndustryDirectory();
 
void ShowIndustryCargoesWindow();
 
void ShowSubsidiesList();
 
void ShowGoalsList();
 
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question);
 

	
 
void ShowEstimatedCostOrIncome(Money cost, int x, int y);
 

	
src/industry_gui.cpp
Show inline comments
 
@@ -33,13 +33,13 @@
 
#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 "widgets/dropdown_type.h"
 
#include "widgets/industry_widget.h"
 

	
 
#include "table/strings.h"
 

	
 
bool _ignore_restrictions;
 
uint64 _displayed_industries; ///< Communication from the industry chain window to the smallmap window about what industries to display.
 
@@ -1407,12 +1407,16 @@ static const NWidgetPart _nested_industr
 
		NWidget(NWID_VERTICAL),
 
			NWidget(WWT_PANEL, COLOUR_BROWN, WID_IC_PANEL), SetResize(1, 10), SetMinimalSize(200, 90), SetScrollbar(WID_IC_SCROLLBAR), EndContainer(),
 
			NWidget(NWID_HORIZONTAL),
 
				NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_IC_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(),
 
				NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_IND_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
 
						SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
 
				NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_CARGO_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
 
						SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
 
			EndContainer(),
 
		EndContainer(),
 
		NWidget(NWID_VERTICAL),
 
			NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_IC_SCROLLBAR),
 
			NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
 
		EndContainer(),
 
@@ -2020,13 +2024,14 @@ struct IndustryCargoesWindow : public Wi
 
	static const int HOR_TEXT_PADDING, VERT_TEXT_PADDING;
 

	
 
	typedef SmallVector<CargoesRow, 4> Fields;
 

	
 
	Fields fields;  ///< Fields to display in the #WID_IC_PANEL.
 
	uint ind_cargo; ///< If less than #NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
 

	
 
	Dimension cargo_textsize; ///< Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
 
	Dimension ind_textsize;   ///< Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
 
	Scrollbar *vscroll;
 

	
 
	IndustryCargoesWindow(int id) : Window()
 
	{
 
		this->OnInit();
 
		this->CreateNestedTree(&_industry_cargoes_desc);
 
@@ -2042,39 +2047,58 @@ struct IndustryCargoesWindow : public Wi
 
		d = maxdim(d, GetStringBoundingBox(STR_INDUSTRY_CARGOES_CUSTOMERS));
 
		d.width  += WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
 
		d.height += WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM;
 
		CargoesField::small_height = d.height;
 

	
 
		/* Decide about the size of the box holding the text of an industry type. */
 
		d.height = 0;
 
		this->ind_textsize.width = 0;
 
		this->ind_textsize.height = 0;
 
		for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
			const IndustrySpec *indsp = GetIndustrySpec(it);
 
			if (!indsp->enabled) continue;
 
			SetDParam(0, indsp->name);
 
			d = maxdim(d, GetStringBoundingBox(STR_JUST_STRING));
 
			this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
 
		}
 
		/* Box must also be wide enough to hold any cargo label. */
 
		d.width = max(d.width, this->ind_textsize.width);
 
		d.height = this->ind_textsize.height;
 
		this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY));
 

	
 
		/* Compute max size of the cargo texts. */
 
		this->cargo_textsize.width = 0;
 
		this->cargo_textsize.height = 0;
 
		for (uint i = 0; i < NUM_CARGO; i++) {
 
			const CargoSpec *csp = CargoSpec::Get(i);
 
			if (!csp->IsValid()) continue;
 
			d = maxdim(d, GetStringBoundingBox(csp->name));
 
			this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(csp->name));
 
		}
 
		d = maxdim(d, this->cargo_textsize); // Box must also be wide enough to hold any cargo label.
 
		this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_CARGO));
 

	
 
		d.width  += 2 * HOR_TEXT_PADDING;
 
		/* Ensure the height is enough for the industry type text, for the horizontal connections, and for the cargo labels. */
 
		uint min_ind_height = CargoesField::VERT_CARGO_EDGE * 2 + MAX_CARGOES * FONT_HEIGHT_NORMAL + (MAX_CARGOES - 1) *  CargoesField::VERT_CARGO_SPACE;
 
		d.height = max(d.height + 2 * VERT_TEXT_PADDING, min_ind_height);
 

	
 
		CargoesField::industry_width = d.width;
 
		CargoesField::normal_height = d.height + CargoesField::VERT_INTER_INDUSTRY_SPACE;
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget != WID_IC_PANEL) return;
 
		switch (widget) {
 
			case WID_IC_PANEL:
 
				size->width = WD_FRAMETEXT_LEFT + CargoesField::industry_width * 3 + CargoesField::CARGO_FIELD_WIDTH * 2 + WD_FRAMETEXT_RIGHT;
 
				break;
 

	
 
		size->width = WD_FRAMETEXT_LEFT + CargoesField::industry_width * 3 + CargoesField::CARGO_FIELD_WIDTH * 2 + WD_FRAMETEXT_RIGHT;
 
			case WID_IC_IND_DROPDOWN:
 
				size->width = max(size->width, this->ind_textsize.width + padding.width);
 
				break;
 

	
 
			case WID_IC_CARGO_DROPDOWN:
 
				size->width = max(size->width, this->cargo_textsize.width + padding.width);
 
				break;
 
		}
 
	}
 

	
 

	
 
	CargoesFieldType type; ///< Type of field.
 
	virtual void SetStringParameters  (int widget) const
 
	{
 
@@ -2537,12 +2561,59 @@ struct IndustryCargoesWindow : public Wi
 

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

	
 
			case WID_IC_CARGO_DROPDOWN: {
 
				DropDownList *lst = new DropDownList;
 
				const CargoSpec *cs;
 
				FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
					lst->push_back(new DropDownListStringItem(cs->name, cs->Index(), false));
 
				}
 
				if (lst->size() == 0) {
 
					delete lst;
 
					break;
 
				}
 
				int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? this->ind_cargo - NUM_INDUSTRYTYPES : -1;
 
				ShowDropDownList(this, lst, selected, WID_IC_CARGO_DROPDOWN, 0, true);
 
				break;
 
			}
 

	
 
			case WID_IC_IND_DROPDOWN: {
 
				DropDownList *lst = new DropDownList;
 
				for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
					IndustryType ind = _sorted_industry_types[i];
 
					const IndustrySpec *indsp = GetIndustrySpec(ind);
 
					if (!indsp->enabled) continue;
 
					lst->push_back(new DropDownListStringItem(indsp->name, ind, false));
 
				}
 
				if (lst->size() == 0) {
 
					delete lst;
 
					break;
 
				}
 
				int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? this->ind_cargo : -1;
 
				ShowDropDownList(this, lst, selected, WID_IC_IND_DROPDOWN, 0, true);
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		if (index < 0) return;
 

	
 
		switch (widget) {
 
			case WID_IC_CARGO_DROPDOWN:
 
				this->ComputeCargoDisplay(index);
 
				break;
 

	
 
			case WID_IC_IND_DROPDOWN:
 
				this->ComputeIndustryDisplay(index);
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnHover(Point pt, int widget)
 
	{
 
		if (widget != WID_IC_PANEL) return;
 
@@ -2590,19 +2661,34 @@ struct IndustryCargoesWindow : public Wi
 

	
 
const int IndustryCargoesWindow::HOR_TEXT_PADDING  = 5; ///< Horizontal padding around the industry type text.
 
const int IndustryCargoesWindow::VERT_TEXT_PADDING = 5; ///< Vertical padding around the industry type text.
 

	
 
/**
 
 * Open the industry and cargoes window.
 
 * @param id Industry type to display.
 
 * @param id Industry type to display, \c NUM_INDUSTRYTYPES selects a default industry type.
 
 */
 
static void ShowIndustryCargoesWindow(IndustryType id)
 
{
 
	assert(id < NUM_INDUSTRYTYPES);
 
	if (id >= NUM_INDUSTRYTYPES) {
 
		for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
			const IndustrySpec *indsp = GetIndustrySpec(_sorted_industry_types[i]);
 
			if (indsp->enabled) {
 
				id = _sorted_industry_types[i];
 
				break;
 
			}
 
		}
 
		if (id >= NUM_INDUSTRYTYPES) return;
 
	}
 

	
 
	Window *w = BringWindowToFrontById(WC_INDUSTRY_CARGOES, 0);
 
	if (w != NULL) {
 
		w->InvalidateData(id);
 
		return;
 
	}
 
	new IndustryCargoesWindow(id);
 
}
 

	
 
/** Open the industry and cargoes window with an industry. */
 
void ShowIndustryCargoesWindow()
 
{
 
	ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES);
 
}
src/lang/english.txt
Show inline comments
 
@@ -399,12 +399,13 @@ STR_GRAPH_MENU_CARGO_PAYMENT_RATES      
 
STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE                             :Company league table
 
STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING                      :Detailed performance rating
 
############ range ends here
 

	
 
############ range for industry menu starts
 
STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY                            :Industry directory
 
STR_INDUSTRY_MENU_INDUSTRY_CHAIN                                :Industry chains
 
STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY                             :Fund new industry
 
############ range ends here
 

	
 
############ range for railway construction menu starts
 
STR_RAIL_MENU_RAILROAD_CONSTRUCTION                             :Railway construction
 
STR_RAIL_MENU_ELRAIL_CONSTRUCTION                               :Electrified railway construction
 
@@ -2386,12 +2387,16 @@ STR_INDUSTRY_CARGOES_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
 
STR_INDUSTRY_CARGOES_SELECT_CARGO                               :{BLACK}Select cargo
 
STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP                       :{BLACK}Select the cargo you want to display
 
STR_INDUSTRY_CARGOES_SELECT_INDUSTRY                            :{BLACK}Select industry
 
STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP                    :{BLACK}Select the industry you want to display
 

	
 
# 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_LONG}
 
STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED                  :{BLACK}Revenue when cleared: {LTBLUE}{CURRENCY_LONG}
src/script/api/game/game_window.hpp.sq
Show inline comments
 
@@ -561,12 +561,14 @@ void SQGSWindow_Register(Squirrel *engin
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ID_INDUSTRY_LIST,                      "WID_ID_INDUSTRY_LIST");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ID_SCROLLBAR,                          "WID_ID_SCROLLBAR");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_CAPTION,                            "WID_IC_CAPTION");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_NOTIFY,                             "WID_IC_NOTIFY");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_PANEL,                              "WID_IC_PANEL");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_SCROLLBAR,                          "WID_IC_SCROLLBAR");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_CARGO_DROPDOWN,                     "WID_IC_CARGO_DROPDOWN");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_IND_DROPDOWN,                       "WID_IC_IND_DROPDOWN");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SGI_GENERATE_GAME,                     "WID_SGI_GENERATE_GAME");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SGI_LOAD_GAME,                         "WID_SGI_LOAD_GAME");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SGI_PLAY_SCENARIO,                     "WID_SGI_PLAY_SCENARIO");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SGI_PLAY_HEIGHTMAP,                    "WID_SGI_PLAY_HEIGHTMAP");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SGI_EDIT_SCENARIO,                     "WID_SGI_EDIT_SCENARIO");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SGI_PLAY_NETWORK,                      "WID_SGI_PLAY_NETWORK");
src/script/api/script_window.hpp
Show inline comments
 
@@ -1455,12 +1455,14 @@ public:
 
	/** Widgets of the #IndustryCargoesWindow class */
 
	enum IndustryCargoesWidgets {
 
		WID_IC_CAPTION                               = ::WID_IC_CAPTION,                               ///< Caption of the window.
 
		WID_IC_NOTIFY                                = ::WID_IC_NOTIFY,                                ///< Row of buttons at the bottom.
 
		WID_IC_PANEL                                 = ::WID_IC_PANEL,                                 ///< Panel that shows the chain.
 
		WID_IC_SCROLLBAR                             = ::WID_IC_SCROLLBAR,                             ///< Scrollbar of the panel.
 
		WID_IC_CARGO_DROPDOWN                        = ::WID_IC_CARGO_DROPDOWN,                        ///< Select cargo dropdown.
 
		WID_IC_IND_DROPDOWN                          = ::WID_IC_IND_DROPDOWN,                          ///< Select industry dropdown.
 
	};
 

	
 
	/* automatically generated from ../../widgets/intro_widget.h */
 
	/** Widgets of the #SelectGameWindow class. */
 
	enum SelectGameIntroWidgets {
 
		WID_SGI_GENERATE_GAME                        = ::WID_SGI_GENERATE_GAME,                        ///< Generate game button.
src/toolbar_gui.cpp
Show inline comments
 
@@ -631,27 +631,28 @@ static CallBackFunction MenuClickLeague(
 

	
 
/* --- Industries button menu --- */
 

	
 
static CallBackFunction ToolbarIndustryClick(Window *w)
 
{
 
	/* Disable build-industry menu if we are a spectator */
 
	PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 1 : 2);
 
	PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
 
	return CBF_NONE;
 
}
 

	
 
/**
 
 * Handle click on the entry in the Industry menu.
 
 *
 
 * @param index Menu entry number.
 
 * @return #CBF_NONE
 
 */
 
static CallBackFunction MenuClickIndustry(int index)
 
{
 
	switch (index) {
 
		case 0: ShowIndustryDirectory();   break;
 
		case 1: ShowBuildIndustryWindow(); break;
 
		case 0: ShowIndustryDirectory();     break;
 
		case 1: ShowIndustryCargoesWindow(); break;
 
		case 2: ShowBuildIndustryWindow();   break;
 
	}
 
	return CBF_NONE;
 
}
 

	
 
/* --- Trains button menu + 1 helper function for all vehicles. --- */
 

	
src/widgets/industry_widget.h
Show inline comments
 
@@ -37,13 +37,15 @@ enum IndustryDirectoryWidgets {
 
	WID_ID_INDUSTRY_LIST,     ///< Industry list.
 
	WID_ID_SCROLLBAR,         ///< Scrollbar of the list.
 
};
 

	
 
/** Widgets of the #IndustryCargoesWindow class */
 
enum IndustryCargoesWidgets {
 
	WID_IC_CAPTION,   ///< Caption of the window.
 
	WID_IC_NOTIFY,    ///< Row of buttons at the bottom.
 
	WID_IC_PANEL,     ///< Panel that shows the chain.
 
	WID_IC_SCROLLBAR, ///< Scrollbar of the panel.
 
	WID_IC_CAPTION,        ///< Caption of the window.
 
	WID_IC_NOTIFY,         ///< Row of buttons at the bottom.
 
	WID_IC_PANEL,          ///< Panel that shows the chain.
 
	WID_IC_SCROLLBAR,      ///< Scrollbar of the panel.
 
	WID_IC_CARGO_DROPDOWN, ///< Select cargo dropdown.
 
	WID_IC_IND_DROPDOWN,   ///< Select industry dropdown.
 
};
 

	
 
#endif /* WIDGETS_INDUSTRY_WIDGET_H */
0 comments (0 inline, 0 general)