(svn r24763) -Feature: Add industry type and cargo dropdown selection for easier navigating in the industry chain window.

This commit is contained in:
alberth 2012-11-25 15:24:02 +00:00
parent e67c717c2f
commit fb892f4b20
7 changed files with 117 additions and 18 deletions

View File

@ -48,6 +48,7 @@ void ShowAboutWindow();
void ShowBuildTreesToolbar(); void ShowBuildTreesToolbar();
void ShowTownDirectory(); void ShowTownDirectory();
void ShowIndustryDirectory(); void ShowIndustryDirectory();
void ShowIndustryCargoesWindow();
void ShowSubsidiesList(); void ShowSubsidiesList();
void ShowGoalsList(); void ShowGoalsList();
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question); void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question);

View File

@ -36,7 +36,7 @@
#include "core/backup_type.hpp" #include "core/backup_type.hpp"
#include "genworld.h" #include "genworld.h"
#include "smallmap_gui.h" #include "smallmap_gui.h"
#include "widgets/dropdown_type.h"
#include "widgets/industry_widget.h" #include "widgets/industry_widget.h"
#include "table/strings.h" #include "table/strings.h"
@ -1410,6 +1410,10 @@ static const NWidgetPart _nested_industry_cargoes_widgets[] = {
NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_IC_NOTIFY), NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_IC_NOTIFY),
SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP), 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_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(),
EndContainer(), EndContainer(),
NWidget(NWID_VERTICAL), NWidget(NWID_VERTICAL),
@ -2023,7 +2027,8 @@ struct IndustryCargoesWindow : public Window {
Fields fields; ///< Fields to display in the #WID_IC_PANEL. 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. 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; Scrollbar *vscroll;
IndustryCargoesWindow(int id) : Window() IndustryCargoesWindow(int id) : Window()
@ -2045,19 +2050,28 @@ struct IndustryCargoesWindow : public Window {
CargoesField::small_height = d.height; CargoesField::small_height = d.height;
/* Decide about the size of the box holding the text of an industry type. */ /* 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++) { for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
const IndustrySpec *indsp = GetIndustrySpec(it); const IndustrySpec *indsp = GetIndustrySpec(it);
if (!indsp->enabled) continue; if (!indsp->enabled) continue;
SetDParam(0, indsp->name); this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
d = maxdim(d, GetStringBoundingBox(STR_JUST_STRING));
} }
/* 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++) { for (uint i = 0; i < NUM_CARGO; i++) {
const CargoSpec *csp = CargoSpec::Get(i); const CargoSpec *csp = CargoSpec::Get(i);
if (!csp->IsValid()) continue; 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; 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. */ /* 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; 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 Window {
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) 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 Window {
this->NotifySmallmap(); this->NotifySmallmap();
} }
break; 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_TEXT_PADDING = 5; ///< Vertical padding ar
/** /**
* Open the industry and cargoes window. * 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) 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); Window *w = BringWindowToFrontById(WC_INDUSTRY_CARGOES, 0);
if (w != NULL) { if (w != NULL) {
@ -2606,3 +2686,9 @@ static void ShowIndustryCargoesWindow(IndustryType id)
} }
new IndustryCargoesWindow(id); new IndustryCargoesWindow(id);
} }
/** Open the industry and cargoes window with an industry. */
void ShowIndustryCargoesWindow()
{
ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES);
}

View File

@ -402,6 +402,7 @@ STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING :Detailed perfor
############ range for industry menu starts ############ range for industry menu starts
STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY :Industry directory STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY :Industry directory
STR_INDUSTRY_MENU_INDUSTRY_CHAIN :Industry chains
STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY :Fund new industry STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY :Fund new industry
############ range ends here ############ range ends here
@ -2389,6 +2390,10 @@ STR_INDUSTRY_DISPLAY_CHAIN :{BLACK}Display
STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP :{BLACK}Display cargo supplying and accepting industries 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 :{BLACK}Link to smallmap
STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP :{BLACK}Select the displayed industries at the smallmap as well 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 # Land area window
STR_LAND_AREA_INFORMATION_CAPTION :{WHITE}Land Area Information STR_LAND_AREA_INFORMATION_CAPTION :{WHITE}Land Area Information

View File

@ -564,6 +564,8 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_NOTIFY, "WID_IC_NOTIFY"); 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_PANEL, "WID_IC_PANEL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_IC_SCROLLBAR, "WID_IC_SCROLLBAR"); 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_GENERATE_GAME, "WID_SGI_GENERATE_GAME");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SGI_LOAD_GAME, "WID_SGI_LOAD_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_SCENARIO, "WID_SGI_PLAY_SCENARIO");

View File

@ -1458,6 +1458,8 @@ public:
WID_IC_NOTIFY = ::WID_IC_NOTIFY, ///< Row of buttons at the bottom. 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_PANEL = ::WID_IC_PANEL, ///< Panel that shows the chain.
WID_IC_SCROLLBAR = ::WID_IC_SCROLLBAR, ///< Scrollbar of the panel. 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 */ /* automatically generated from ../../widgets/intro_widget.h */

View File

@ -634,7 +634,7 @@ static CallBackFunction MenuClickLeague(int index)
static CallBackFunction ToolbarIndustryClick(Window *w) static CallBackFunction ToolbarIndustryClick(Window *w)
{ {
/* Disable build-industry menu if we are a spectator */ /* 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; return CBF_NONE;
} }
@ -647,8 +647,9 @@ static CallBackFunction ToolbarIndustryClick(Window *w)
static CallBackFunction MenuClickIndustry(int index) static CallBackFunction MenuClickIndustry(int index)
{ {
switch (index) { switch (index) {
case 0: ShowIndustryDirectory(); break; case 0: ShowIndustryDirectory(); break;
case 1: ShowBuildIndustryWindow(); break; case 1: ShowIndustryCargoesWindow(); break;
case 2: ShowBuildIndustryWindow(); break;
} }
return CBF_NONE; return CBF_NONE;
} }

View File

@ -40,10 +40,12 @@ enum IndustryDirectoryWidgets {
/** Widgets of the #IndustryCargoesWindow class */ /** Widgets of the #IndustryCargoesWindow class */
enum IndustryCargoesWidgets { enum IndustryCargoesWidgets {
WID_IC_CAPTION, ///< Caption of the window. WID_IC_CAPTION, ///< Caption of the window.
WID_IC_NOTIFY, ///< Row of buttons at the bottom. WID_IC_NOTIFY, ///< Row of buttons at the bottom.
WID_IC_PANEL, ///< Panel that shows the chain. WID_IC_PANEL, ///< Panel that shows the chain.
WID_IC_SCROLLBAR, ///< Scrollbar of the panel. 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 */ #endif /* WIDGETS_INDUSTRY_WIDGET_H */