From fb892f4b2060344b1ca1dbcb9b120aa628fc4785 Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 25 Nov 2012 15:24:02 +0000 Subject: [PATCH] (svn r24763) -Feature: Add industry type and cargo dropdown selection for easier navigating in the industry chain window. --- src/gui.h | 1 + src/industry_gui.cpp | 108 ++++++++++++++++++++++--- src/lang/english.txt | 5 ++ src/script/api/game/game_window.hpp.sq | 2 + src/script/api/script_window.hpp | 2 + src/toolbar_gui.cpp | 7 +- src/widgets/industry_widget.h | 10 ++- 7 files changed, 117 insertions(+), 18 deletions(-) diff --git a/src/gui.h b/src/gui.h index 43fa310b30..47e687206a 100644 --- a/src/gui.h +++ b/src/gui.h @@ -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); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 26d84d2362..507ee81dee 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -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_industry_cargoes_widgets[] = { 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 Window { 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 Window { 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 Window { 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(); } 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. - * @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(IndustryType id) } new IndustryCargoesWindow(id); } + +/** Open the industry and cargoes window with an industry. */ +void ShowIndustryCargoesWindow() +{ + ShowIndustryCargoesWindow(NUM_INDUSTRYTYPES); +} diff --git a/src/lang/english.txt b/src/lang/english.txt index 0d0ae6a6bf..a714244933 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -402,6 +402,7 @@ STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING :Detailed perfor ############ 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 :{BLACK}Display 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 diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index c438c610e8..c175fda6bb 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -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_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"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 18c6449ede..bfe0f81e87 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -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 */ diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index a7548834de..0bc7a6245b 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -634,7 +634,7 @@ static CallBackFunction MenuClickLeague(int index) 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 ToolbarIndustryClick(Window *w) 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; } diff --git a/src/widgets/industry_widget.h b/src/widgets/industry_widget.h index 0cadc6e3a5..711694db72 100644 --- a/src/widgets/industry_widget.h +++ b/src/widgets/industry_widget.h @@ -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 */