Skip to content

Commit aa07acf

Browse files
committed
Merge pull request OpenXcom#880 from OmniscientQ/mfgCategory
Add a Category Filter to the Manufacturing Window
2 parents e324b09 + dcc2e72 commit aa07acf

5 files changed

Lines changed: 67 additions & 8 deletions

File tree

bin/data/Language/en-GB.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,3 +1360,4 @@ en-GB:
13601360
STR_JAPANESE_FONT: "If you have a Japanese font that works in OpenXCom: please, send it to us and let us know if we can use it."
13611361
STR_NOT_ENOUGH_ITEMS_FOR_TEMPLATE: "Not enough items to copy template!"
13621362
STR_UNLOAD_WEAPON: "Unload weapon"
1363+
STR_ALL_ITEMS: "All Items"

bin/data/Language/en-US.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,3 +1360,4 @@ en-US:
13601360
STR_JAPANESE_FONT: "If you have a Japanese font that works in OpenXCom: please, send it to us and let us know if we can use it."
13611361
STR_NOT_ENOUGH_ITEMS_FOR_TEMPLATE: "Not enough items to copy template!"
13621362
STR_UNLOAD_WEAPON: "Unload weapon"
1363+
STR_ALL_ITEMS: "All Items"

src/Basescape/NewManufactureListState.cpp

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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
*/
118147
void 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

src/Basescape/NewManufactureListState.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Window;
3030
class Text;
3131
class TextList;
3232
class RuleManufacture;
33+
class ComboBox;
3334

3435
/**
3536
* Screen which list possible productions.
@@ -42,7 +43,10 @@ class NewManufactureListState : public State
4243
Window *_window;
4344
Text *_txtTitle, *_txtItem, *_txtCategory;
4445
TextList *_lstManufacture;
46+
ComboBox *_cbxCategory;
4547
std::vector<RuleManufacture *> _possibleProductions;
48+
std::vector<std::string> _catStrings;
49+
std::vector<std::string> _displayedStrings;
4650

4751
public:
4852
/// Creates the state.
@@ -53,6 +57,8 @@ class NewManufactureListState : public State
5357
void btnOkClick(Action * action);
5458
/// Handler for clicking on the list.
5559
void lstProdClick (Action * action);
60+
/// Handler for changing the category filter
61+
void cbxCategoryChange (Action * action);
5662
/// Fills the list of possible productions.
5763
void fillProductionList();
5864
};

src/Interface/TextList.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ void TextList::clearList()
759759
}
760760
u->clear();
761761
}
762+
scrollUp(true, false);
762763
_texts.clear();
763764
_rows.clear();
764765
_redraw = true;

0 commit comments

Comments
 (0)