2222#include " ../Interface/TextButton.h"
2323#include " ../Interface/Text.h"
2424#include " ../Interface/TextList.h"
25+ #include " ../Interface/ComboBox.h"
2526#include " ../Engine/Game.h"
2627#include " ../Engine/Language.h"
2728#include " ../Engine/Palette.h"
@@ -47,12 +48,13 @@ NewManufactureListState::NewManufactureListState(Base *base) : _base(base)
4748{
4849 _screen = false ;
4950
50- _window = new Window (this , 320 , 140 , 0 , 30 , POPUP_BOTH );
51- _btnOk = new TextButton (304 , 16 , 8 , 146 );
52- _txtTitle = new Text (320 , 17 , 0 , 38 );
53- _txtItem = new Text (156 , 9 , 10 , 54 );
54- _txtCategory = new Text (130 , 9 , 166 , 54 );
55- _lstManufacture = new TextList (288 , 80 , 8 , 62 );
51+ _window = new Window (this , 320 , 156 , 0 , 22 , POPUP_BOTH );
52+ _btnOk = new TextButton (304 , 16 , 8 , 154 );
53+ _txtTitle = new Text (320 , 17 , 0 , 30 );
54+ _txtItem = new Text (156 , 9 , 10 , 62 );
55+ _txtCategory = new Text (130 , 9 , 166 , 62 );
56+ _lstManufacture = new TextList (288 , 80 , 8 , 70 );
57+ _cbxCategory = new ComboBox (this , 146 , 16 , 166 , 46 );
5658
5759 // Set palette
5860 setPalette (" PAL_BASESCAPE" , 6 );
@@ -63,6 +65,7 @@ NewManufactureListState::NewManufactureListState(Base *base) : _base(base)
6365 add (_txtItem);
6466 add (_txtCategory);
6567 add (_lstManufacture);
68+ add (_cbxCategory);
6669
6770 centerAllSurfaces ();
6871
@@ -91,6 +94,32 @@ NewManufactureListState::NewManufactureListState(Base *base) : _base(base)
9194 _btnOk->setText (tr (" STR_OK" ));
9295 _btnOk->onMouseClick ((ActionHandler)&NewManufactureListState::btnOkClick);
9396 _btnOk->onKeyboardPress ((ActionHandler)&NewManufactureListState::btnOkClick, Options::keyCancel);
97+
98+ _possibleProductions.clear ();
99+ _game->getSavedGame ()->getAvailableProductions (_possibleProductions, _game->getRuleset (), _base);
100+ _catStrings.push_back (" STR_ALL_ITEMS" );
101+
102+ for (std::vector<RuleManufacture *>::iterator it = _possibleProductions.begin (); it != _possibleProductions.end (); ++it)
103+ {
104+ bool addCategory = true ;
105+ for (size_t x = 0 ; x < _catStrings.size (); ++x)
106+ {
107+ if ((*it)->getCategory ().c_str () == _catStrings[x])
108+ {
109+ addCategory = false ;
110+ break ;
111+ }
112+ }
113+ if (addCategory)
114+ {
115+ _catStrings.push_back ((*it)->getCategory ().c_str ());
116+ }
117+ }
118+
119+ _cbxCategory->setColor (Palette::blockOffset (15 )+1 );
120+ _cbxCategory->setOptions (_catStrings);
121+ _cbxCategory->onChange ((ActionHandler)&NewManufactureListState::cbxCategoryChange);
122+
94123}
95124
96125/* *
@@ -117,7 +146,15 @@ void NewManufactureListState::btnOkClick(Action *)
117146*/
118147void NewManufactureListState::lstProdClick (Action *)
119148{
120- RuleManufacture *rule = _possibleProductions[_lstManufacture->getSelectedRow ()];
149+ RuleManufacture *rule;
150+ for (std::vector<RuleManufacture *>::iterator it = _possibleProductions.begin (); it != _possibleProductions.end (); ++it)
151+ {
152+ if ((*it)->getName ().c_str () == _displayedStrings[_lstManufacture->getSelectedRow ()])
153+ {
154+ rule = (*it);
155+ break ;
156+ }
157+ }
121158 if (rule->getCategory () == " STR_CRAFT" && _base->getAvailableHangars () - _base->getUsedHangars () == 0 )
122159 {
123160 _game->pushState (new ErrorMessageState (tr (" STR_NO_FREE_HANGARS_FOR_CRAFT_PRODUCTION" ), _palette, Palette::blockOffset (15 )+1 , " BACK17.SCR" , 6 ));
@@ -132,6 +169,14 @@ void NewManufactureListState::lstProdClick(Action *)
132169 }
133170}
134171
172+ /* *
173+ * Updates the production list to match the category filter
174+ */
175+
176+ void NewManufactureListState::cbxCategoryChange (Action *)
177+ {
178+ fillProductionList ();
179+ }
135180
136181/* *
137182 * Fills the list of possible productions.
@@ -141,10 +186,15 @@ void NewManufactureListState::fillProductionList()
141186 _lstManufacture->clearList ();
142187 _possibleProductions.clear ();
143188 _game->getSavedGame ()->getAvailableProductions (_possibleProductions, _game->getRuleset (), _base);
189+ _displayedStrings.clear ();
144190
145191 for (std::vector<RuleManufacture *>::iterator it = _possibleProductions.begin (); it != _possibleProductions.end (); ++it)
146192 {
147- _lstManufacture->addRow (2 , tr ((*it)->getName ()).c_str (), tr ((*it)->getCategory ()).c_str ());
193+ if (((*it)->getCategory ().c_str () == _catStrings[_cbxCategory->getSelected ()]) || (_catStrings[_cbxCategory->getSelected ()] == " STR_ALL_ITEMS" ))
194+ {
195+ _lstManufacture->addRow (2 , tr ((*it)->getName ()).c_str (), tr ((*it)->getCategory ()).c_str ());
196+ _displayedStrings.push_back ((*it)->getName ().c_str ());
197+ }
148198 }
149199}
150200
0 commit comments