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
 
@@ -48,6 +48,7 @@ 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);
src/industry_gui.cpp
Show inline comments
 
@@ -36,7 +36,7 @@
 
#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"
 
@@ -1410,6 +1410,10 @@ static const NWidgetPart _nested_industr
 
				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),
 
@@ -2023,7 +2027,8 @@ struct IndustryCargoesWindow : public Wi
 

	
 
	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()
 
@@ -2045,19 +2050,28 @@ struct IndustryCargoesWindow : public Wi
 
		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;
 
@@ -2069,9 +2083,19 @@ struct IndustryCargoesWindow : public Wi
 

	
 
	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;
 
		}
 
	}
 

	
 

	
 
@@ -2540,6 +2564,53 @@ struct IndustryCargoesWindow : public Wi
 
					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;
 
		}
 
	}
 

	
 
@@ -2593,11 +2664,20 @@ const int IndustryCargoesWindow::VERT_TE
 

	
 
/**
 
 * 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) {
 
@@ -2606,3 +2686,9 @@ static void ShowIndustryCargoesWindow(In
 
	}
 
	new IndustryCargoesWindow(id);
 
}
 

	
 
/** Open the industry and cargoes window with an industry. */
 
void ShowIndustryCargoesWindow()
 
{
 
	ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES);
 
}
src/lang/english.txt
Show inline comments
 
@@ -402,6 +402,7 @@ STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATI
 

	
 
############ 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
 

	
 
@@ -2389,6 +2390,10 @@ STR_INDUSTRY_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
src/script/api/game/game_window.hpp.sq
Show inline comments
 
@@ -564,6 +564,8 @@ void SQGSWindow_Register(Squirrel *engin
 
	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");
src/script/api/script_window.hpp
Show inline comments
 
@@ -1458,6 +1458,8 @@ public:
 
		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 */
src/toolbar_gui.cpp
Show inline comments
 
@@ -634,7 +634,7 @@ static CallBackFunction MenuClickLeague(
 
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;
 
}
 

	
 
@@ -647,8 +647,9 @@ static CallBackFunction ToolbarIndustryC
 
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;
 
}
src/widgets/industry_widget.h
Show inline comments
 
@@ -40,10 +40,12 @@ enum IndustryDirectoryWidgets {
 

	
 
/** 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)