Skip to content

Commit 6215bf1

Browse files
committed
Fix up Ufopaedia
1 parent 90cda8c commit 6215bf1

7 files changed

Lines changed: 58 additions & 77 deletions

File tree

‎src/Mod/Mod.cpp‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ void Mod::loadFile(const std::string &filename)
915915
}
916916
_ufopaediaListOrder += 100;
917917
rule->load(*i, _ufopaediaListOrder);
918+
if (rule->section != UFOPAEDIA_NOT_AVAILABLE &&
919+
std::find(_ufopaediaCatIndex.begin(), _ufopaediaCatIndex.end(), rule->section) == _ufopaediaCatIndex.end())
920+
{
921+
_ufopaediaCatIndex.push_back(rule->section);
922+
}
918923
}
919924
else if ((*i)["delete"])
920925
{
@@ -1640,6 +1645,16 @@ const std::vector<std::string> &Mod::getUfopaediaList() const
16401645
return _ufopaediaIndex;
16411646
}
16421647

1648+
/**
1649+
* Returns the list of all article categories
1650+
* provided by the mod.
1651+
* @return List of categories.
1652+
*/
1653+
const std::vector<std::string> &Mod::getUfopaediaCategoryList() const
1654+
{
1655+
return _ufopaediaCatIndex;
1656+
}
1657+
16431658
/**
16441659
* Returns the list of inventories.
16451660
* @return Pointer to inventory list.
@@ -1947,16 +1962,13 @@ struct compareRule<ArticleDefinition> : public std::binary_function<const std::s
19471962

19481963
compareRule(Mod *mod) : _mod(mod)
19491964
{
1950-
_sections[UFOPAEDIA_XCOM_CRAFT_ARMAMENT] = 0;
1951-
_sections[UFOPAEDIA_HEAVY_WEAPONS_PLATFORMS] = 1;
1952-
_sections[UFOPAEDIA_WEAPONS_AND_EQUIPMENT] = 2;
1953-
_sections[UFOPAEDIA_ALIEN_ARTIFACTS] = 3;
1954-
_sections[UFOPAEDIA_BASE_FACILITIES] = 4;
1955-
_sections[UFOPAEDIA_ALIEN_LIFE_FORMS] = 5;
1956-
_sections[UFOPAEDIA_ALIEN_RESEARCH] = 6;
1957-
_sections[UFOPAEDIA_UFO_COMPONENTS] = 7;
1958-
_sections[UFOPAEDIA_UFOS] = 8;
1959-
_sections[UFOPAEDIA_NOT_AVAILABLE] = 9;
1965+
const std::vector<std::string> &list = mod->getUfopaediaCategoryList();
1966+
int order = 0;
1967+
for (std::vector<std::string>::const_iterator i = list.begin(); i != list.end(); ++i)
1968+
{
1969+
_sections[*i] = order++;
1970+
}
1971+
_sections[UFOPAEDIA_NOT_AVAILABLE] = order++;
19601972
}
19611973

19621974
bool operator()(const std::string &r1, const std::string &r2) const

‎src/Mod/Mod.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Mod
139139
GameTime _startingTime;
140140

141141
std::vector<std::string> _countriesIndex, _regionsIndex, _facilitiesIndex, _craftsIndex, _craftWeaponsIndex, _itemsIndex, _invsIndex, _ufosIndex;
142-
std::vector<std::string> _soldiersIndex, _aliensIndex, _deploymentsIndex, _armorsIndex, _ufopaediaIndex, _researchIndex, _manufactureIndex, _MCDPatchesIndex;
142+
std::vector<std::string> _soldiersIndex, _aliensIndex, _deploymentsIndex, _armorsIndex, _ufopaediaIndex, _ufopaediaCatIndex, _researchIndex, _manufactureIndex, _MCDPatchesIndex;
143143
std::vector<std::string> _alienMissionsIndex, _terrainIndex, _extraSpritesIndex, _extraSoundsIndex, _extraStringsIndex, _missionScriptIndex;
144144
std::vector<std::vector<int> > _alienItemLevels;
145145
std::vector<SDL_Color> _transparencies;
@@ -305,6 +305,8 @@ class Mod
305305
ArticleDefinition *getUfopaediaArticle(const std::string &name) const;
306306
/// Gets the available articles.
307307
const std::vector<std::string> &getUfopaediaList() const;
308+
/// Gets the available article categories.
309+
const std::vector<std::string> &getUfopaediaCategoryList() const;
308310
/// Gets the inventory list.
309311
std::map<std::string, RuleInventory*> *getInventories();
310312
/// Gets the ruleset for a specific inventory.

‎src/Ufopaedia/Ufopaedia.h‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,14 @@ namespace OpenXcom
3333
/// definition of an article list
3434
typedef std::vector<ArticleDefinition *> ArticleDefinitionList;
3535

36-
/// define Ufopaedia sections, which must be consistent
37-
static const std::string UFOPAEDIA_XCOM_CRAFT_ARMAMENT = "STR_XCOM_CRAFT_ARMAMENT";
38-
static const std::string UFOPAEDIA_HEAVY_WEAPONS_PLATFORMS = "STR_HEAVY_WEAPONS_PLATFORMS";
39-
static const std::string UFOPAEDIA_WEAPONS_AND_EQUIPMENT = "STR_WEAPONS_AND_EQUIPMENT";
40-
static const std::string UFOPAEDIA_ALIEN_ARTIFACTS = "STR_ALIEN_ARTIFACTS";
41-
static const std::string UFOPAEDIA_BASE_FACILITIES = "STR_BASE_FACILITIES";
42-
static const std::string UFOPAEDIA_ALIEN_LIFE_FORMS = "STR_ALIEN_LIFE_FORMS";
43-
static const std::string UFOPAEDIA_ALIEN_RESEARCH = "STR_ALIEN_RESEARCH_UC";
44-
static const std::string UFOPAEDIA_UFO_COMPONENTS = "STR_UFO_COMPONENTS";
45-
static const std::string UFOPAEDIA_UFOS = "STR_UFOS";
46-
static const std::string UFOPAEDIA_COMMENDATIONS = "STR_COMMENDATIONS_UC";
47-
static const std::string UFOPAEDIA_NOT_AVAILABLE = "STR_NOT_AVAILABLE";
48-
// This last section is meant for articles, that have to be activated,
36+
// This section is meant for articles, that have to be activated,
4937
// but have no own entry in a list. E.g. Ammunition items.
5038
// Maybe others as well, that should just not be selectable.
39+
static const std::string UFOPAEDIA_NOT_AVAILABLE = "STR_NOT_AVAILABLE";
5140

5241
/**
5342
* This static class encapsulates all functions related to Ufopaedia
54-
* for the game. It manages the relationship between the UfopaediaSaved
55-
* instance in SavedGame and the UfopaediaFactory in Mod.
43+
* for the game.
5644
* Main purpose is to open Ufopaedia from Geoscape, navigate between articles
5745
* and release new articles after successful research.
5846
*/

‎src/Ufopaedia/UfopaediaSelectState.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131

3232
namespace OpenXcom
3333
{
34-
UfopaediaSelectState::UfopaediaSelectState(const std::string &section, int commendationsYAdjustment) : _section(section), _commendationsYAdjustment(commendationsYAdjustment)
34+
UfopaediaSelectState::UfopaediaSelectState(const std::string &section) : _section(section)
3535
{
3636
_screen = false;
3737

3838
// set background window
39-
_window = new Window(this, 256, 180 + 2*_commendationsYAdjustment, 32, 10 - _commendationsYAdjustment, POPUP_NONE);
39+
_window = new Window(this, 256, 180, 32, 10, POPUP_NONE);
4040

4141
// set title
42-
_txtTitle = new Text(224, 17, 48, 26 - _commendationsYAdjustment);
42+
_txtTitle = new Text(224, 17, 48, 26);
4343

4444
// set buttons
45-
_btnOk = new TextButton(224, 16, 48, 166 + _commendationsYAdjustment);
45+
_btnOk = new TextButton(224, 16, 48, 166);
4646
_lstSelection = new TextList(224, 104, 40, 50);
4747

4848
// Set palette

‎src/Ufopaedia/UfopaediaSelectState.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace OpenXcom
4040
class UfopaediaSelectState : public State
4141
{
4242
public:
43-
UfopaediaSelectState(const std::string &section, int commendationsYAdjustment);
43+
UfopaediaSelectState(const std::string &section);
4444
virtual ~UfopaediaSelectState();
4545
void init();
4646
protected:
@@ -50,8 +50,6 @@ namespace OpenXcom
5050
TextButton *_btnOk;
5151
TextList *_lstSelection;
5252
ArticleDefinitionList _article_list;
53-
bool _commendations;
54-
int _commendationsYAdjustment;
5553

5654
/// Handler for clicking the OK button
5755
void btnOkClick(Action *action);

‎src/Ufopaedia/UfopaediaStartState.cpp‎

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,63 +28,46 @@
2828
#include "../Interface/Text.h"
2929
#include "../Interface/TextButton.h"
3030
#include "../Mod/Mod.h"
31+
#include "../Mod/ArticleDefinition.h"
3132

3233
namespace OpenXcom
33-
{
34-
const std::string UfopaediaStartState::SECTIONS[] = {UFOPAEDIA_XCOM_CRAFT_ARMAMENT,
35-
UFOPAEDIA_HEAVY_WEAPONS_PLATFORMS,
36-
UFOPAEDIA_WEAPONS_AND_EQUIPMENT,
37-
UFOPAEDIA_ALIEN_ARTIFACTS,
38-
UFOPAEDIA_BASE_FACILITIES,
39-
UFOPAEDIA_ALIEN_LIFE_FORMS,
40-
UFOPAEDIA_ALIEN_RESEARCH,
41-
UFOPAEDIA_UFO_COMPONENTS,
42-
UFOPAEDIA_UFOS,
43-
UFOPAEDIA_COMMENDATIONS};
44-
34+
{
4535
UfopaediaStartState::UfopaediaStartState()
4636
{
47-
// Modify the Ufopaedia in case the commendations mod is enabled or not.
48-
bool commendations = false;
49-
_commendationsYAdjustment = 0;
50-
if (!_game->getMod()->getCommendation().empty())
51-
{
52-
commendations = true;
53-
_commendationsYAdjustment = 7;
54-
}
55-
5637
_screen = false;
5738

5839
// set background window
59-
_window = new Window(this, 256, 180 + 2*_commendationsYAdjustment, 32, 10 - _commendationsYAdjustment, POPUP_BOTH);
40+
_window = new Window(this, 256, 180, 32, 10, POPUP_BOTH);
6041

6142
// set title
62-
_txtTitle = new Text(224, 17, 48, 33 - _commendationsYAdjustment);
43+
_txtTitle = new Text(224, 17, 48, 33);
6344

6445
// Set palette
6546
setInterface("ufopaedia");
6647

67-
6848
add(_window, "window", "ufopaedia");
6949
add(_txtTitle, "text", "ufopaedia");
50+
51+
_btnOk = new TextButton(224, 12, 48, 167);
52+
add(_btnOk, "button1", "ufopaedia");
53+
7054
// set buttons
71-
int y = 50 - _commendationsYAdjustment;
72-
for (int i = 0; i < NUM_SECTIONS; ++i)
55+
const std::vector<std::string> &list = _game->getMod()->getUfopaediaCategoryList();
56+
int y = 50;
57+
y -= 13 * (list.size() - 9);
58+
for (std::vector<std::string>::const_iterator i = list.begin(); i != list.end(); ++i)
7359
{
74-
if (!commendations && SECTIONS[i] == UFOPAEDIA_COMMENDATIONS)
75-
{
76-
continue;
77-
}
78-
_btnSection[i] = new TextButton(224, 12, 48, y);
60+
TextButton *button = new TextButton(224, 12, 48, y);
7961
y += 13;
8062

81-
add(_btnSection[i], "button1", "ufopaedia");
63+
add(button, "button1", "ufopaedia");
8264

83-
_btnSection[i]->setText(tr(SECTIONS[i]));
84-
_btnSection[i]->onMouseClick((ActionHandler)&UfopaediaStartState::btnSectionClick);
65+
button->setText(tr(*i));
66+
button->onMouseClick((ActionHandler)&UfopaediaStartState::btnSectionClick);
67+
68+
_btnSections.push_back(button);
8569
}
86-
_btnOk = new TextButton(224, 12, 48, y);
87-
add(_btnOk, "button1", "ufopaedia");
70+
_txtTitle->setY(_btnSections.front()->getY() - _txtTitle->getHeight());
8871

8972
centerAllSurfaces();
9073

@@ -118,11 +101,12 @@ namespace OpenXcom
118101
*/
119102
void UfopaediaStartState::btnSectionClick(Action *action)
120103
{
121-
for (int i = 0; i < NUM_SECTIONS; ++i)
104+
const std::vector<std::string> &list = _game->getMod()->getUfopaediaCategoryList();
105+
for (size_t i = 0; i < list.size(); ++i)
122106
{
123-
if (action->getSender() == _btnSection[i])
107+
if (action->getSender() == _btnSections[i])
124108
{
125-
_game->pushState(new UfopaediaSelectState(SECTIONS[i], _commendationsYAdjustment));
109+
_game->pushState(new UfopaediaSelectState(list[i]));
126110
break;
127111
}
128112
}

‎src/Ufopaedia/UfopaediaStartState.h‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "../Engine/State.h"
2424
#include <string>
25+
#include <vector>
2526

2627
namespace OpenXcom
2728
{
@@ -41,16 +42,12 @@ namespace OpenXcom
4142
public:
4243
UfopaediaStartState();
4344
virtual ~UfopaediaStartState();
44-
int _commendationsYAdjustment;
4545

4646
protected:
47-
static const int NUM_SECTIONS = 10;
48-
static const std::string SECTIONS[NUM_SECTIONS];
49-
5047
Window *_window;
5148
Text *_txtTitle;
5249
TextButton *_btnOk;
53-
TextButton *_btnSection[NUM_SECTIONS];
50+
std::vector<TextButton*> _btnSections;
5451

5552
// navigation callbacks
5653
void btnSectionClick(Action *action);

0 commit comments

Comments
 (0)