Skip to content

Commit ef0822f

Browse files
committed
Added arrows to TextList and Purchase screen.
1 parent 5093254 commit ef0822f

4 files changed

Lines changed: 65 additions & 9 deletions

File tree

src/Basescape/BasescapeState.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ BasescapeState::BasescapeState(Game *game, Base *base, Globe *globe) : State(gam
156156
_btnTransfer->setText(_game->getLanguage()->getString("STR_NOT_AVAILABLE"));
157157

158158
_btnPurchase->setColor(Palette::blockOffset(13)+8);
159-
_btnPurchase->setText(_game->getLanguage()->getString("STR_NOT_AVAILABLE"));
159+
_btnPurchase->setText(_game->getLanguage()->getString("STR_PURCHASE_RECRUIT"));
160160
_btnPurchase->onMouseClick((ActionHandler)&BasescapeState::btnPurchaseClick);
161161

162162
_btnSell->setColor(Palette::blockOffset(13)+8);
@@ -329,7 +329,7 @@ void BasescapeState::btnManufactureClick(Action *action)
329329
*/
330330
void BasescapeState::btnPurchaseClick(Action *action)
331331
{
332-
//_game->pushState(new PurchaseState(_game));
332+
_game->pushState(new PurchaseState(_game));
333333
}
334334

335335
/**

src/Basescape/PurchaseState.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ PurchaseState::PurchaseState(Game *game) : State(game)
100100

101101
_lstItems->setColor(Palette::blockOffset(13)+10);
102102
_lstItems->setArrowColor(Palette::blockOffset(13)+13);
103+
_lstItems->setArrowColumn(227);
103104
_lstItems->setColumns(3, 162, 92, 32);
104105
_lstItems->setSelectable(true);
105106
_lstItems->setBackground(_window);
106107
_lstItems->setMargin(2);
107-
_lstItems->addRow(3, "Soldier", "40 000", "0");
108+
_lstItems->addRow(3, L"Soldier", L"40 000", L"0");
108109
}
109110

110111
/**

src/Interface/TextList.cpp

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace OpenXcom
3434
* @param x X position in pixels.
3535
* @param y Y position in pixels.
3636
*/
37-
TextList::TextList(int width, int height, int x, int y) : InteractiveSurface(width, height, x, y), _texts(), _columns(), _big(0), _small(0), _scroll(0), _visibleRows(0), _color(0), _align(ALIGN_LEFT), _dot(false), _selectable(false), _selRow(0), _bg(0), _selector(0), _margin(0)
37+
TextList::TextList(int width, int height, int x, int y) : InteractiveSurface(width, height, x, y), _texts(), _columns(), _big(0), _small(0), _scroll(0), _visibleRows(0), _color(0), _align(ALIGN_LEFT), _dot(false), _selectable(false), _selRow(0), _bg(0), _selector(0), _margin(0), _arrow1(), _arrow2(), _arrowPos(-1)
3838
{
3939
_up = new ArrowButton(ARROW_BIG_UP, 13, 14, getX() + getWidth() + 4, getY() + 1);
4040
_up->setVisible(false);
@@ -49,11 +49,21 @@ TextList::TextList(int width, int height, int x, int y) : InteractiveSurface(wid
4949
*/
5050
TextList::~TextList()
5151
{
52-
for (std::vector< std::vector<Text*> >::iterator u = _texts.begin(); u < _texts.end(); u++) {
53-
for (std::vector<Text*>::iterator v = (*u).begin(); v < (*u).end(); v++) {
54-
delete (*v);
52+
for (std::vector< std::vector<Text*> >::iterator u = _texts.begin(); u < _texts.end(); u++)
53+
{
54+
for (std::vector<Text*>::iterator v = (*u).begin(); v < (*u).end(); v++)
55+
{
56+
delete *v;
5557
}
5658
}
59+
for (std::vector<ArrowButton*>::iterator i = _arrow1.begin(); i < _arrow1.end(); i++)
60+
{
61+
delete *i;
62+
}
63+
for (std::vector<ArrowButton*>::iterator i = _arrow2.begin(); i < _arrow2.end(); i++)
64+
{
65+
delete *i;
66+
}
5767
delete _selector;
5868
delete _up;
5969
delete _down;
@@ -99,9 +109,13 @@ void TextList::addRow(int cols, ...)
99109
for (std::wstring::iterator c = buf.begin(); c < buf.end(); c++)
100110
{
101111
if (*c == ' ')
112+
{
102113
w += _small->getWidth() / 2;
114+
}
103115
else
116+
{
104117
w += _small->getChar(*c)->getCrop()->w + _small->getSpacing();
118+
}
105119
}
106120
while (w < _columns[i])
107121
{
@@ -118,10 +132,21 @@ void TextList::addRow(int cols, ...)
118132
rowX += _columns[i];
119133
}
120134
_texts.push_back(temp);
121-
draw();
122135

123-
va_end(args);
136+
if (_arrowPos != -1)
137+
{
138+
ArrowButton *a1 = new ArrowButton(ARROW_SMALL_UP, 11, 8, _arrowPos, getY());
139+
a1->setPalette(this->getPalette());
140+
a1->setColor(_up->getColor());
141+
_arrow1.push_back(a1);
142+
ArrowButton *a2 = new ArrowButton(ARROW_SMALL_DOWN, 11, 8, _arrowPos + 13, getY());
143+
a2->setPalette(this->getPalette());
144+
a2->setColor(_up->getColor());
145+
_arrow2.push_back(a2);
146+
}
124147

148+
draw();
149+
va_end(args);
125150
updateArrows();
126151
}
127152

@@ -162,8 +187,18 @@ void TextList::setPalette(SDL_Color *colors, int firstcolor, int ncolors)
162187
(*v)->setPalette(colors, firstcolor, ncolors);
163188
}
164189
}
190+
for (std::vector<ArrowButton*>::iterator i = _arrow1.begin(); i < _arrow1.end(); i++)
191+
{
192+
(*i)->setPalette(colors, firstcolor, ncolors);
193+
}
194+
for (std::vector<ArrowButton*>::iterator i = _arrow2.begin(); i < _arrow2.end(); i++)
195+
{
196+
(*i)->setPalette(colors, firstcolor, ncolors);
197+
}
165198
if (_selector != 0)
199+
{
166200
_selector->setPalette(colors, firstcolor, ncolors);
201+
}
167202
_up->setPalette(colors, firstcolor, ncolors);
168203
_down->setPalette(colors, firstcolor, ncolors);
169204
}
@@ -185,7 +220,9 @@ void TextList::setFonts(Font *big, Font *small)
185220
_selector->setVisible(false);
186221

187222
for (int y = 0; y < getHeight(); y += _small->getHeight() + _small->getSpacing())
223+
{
188224
_visibleRows++;
225+
}
189226
}
190227

191228
/**
@@ -275,6 +312,16 @@ void TextList::setArrowColor(Uint8 color)
275312
_down->setColor(color);
276313
}
277314

315+
/**
316+
* Sets the position of the column of arrow buttons
317+
* in the text list.
318+
* @param pos X in pixels (-1 to disable).
319+
*/
320+
void TextList::setArrowColumn(int pos)
321+
{
322+
_arrowPos = pos;
323+
}
324+
278325
/**
279326
* Removes all the rows currently stored in the list.
280327
*/
@@ -342,6 +389,10 @@ void TextList::draw()
342389
(*j)->setY((i - _scroll) * (_small->getHeight() + _small->getSpacing()));
343390
(*j)->blit(this);
344391
}
392+
_arrow1[i]->setY((i - _scroll) * (_small->getHeight() + _small->getSpacing()));
393+
_arrow1[i]->blit(this);
394+
_arrow2[i]->setY((i - _scroll) * (_small->getHeight() + _small->getSpacing()));
395+
_arrow2[i]->blit(this);
345396
}
346397
}
347398

src/Interface/TextList.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class TextList : public InteractiveSurface
4949
Surface *_bg, *_selector;
5050
ArrowButton *_up, *_down;
5151
int _margin;
52+
std::vector<ArrowButton*> _arrow1, _arrow2;
53+
int _arrowPos;
5254

5355
/// Updates the arrow buttons.
5456
void updateArrows();
@@ -85,6 +87,8 @@ class TextList : public InteractiveSurface
8587
void setMargin(int margin);
8688
/// Sets the arrow color of the text list.
8789
void setArrowColor(Uint8 color);
90+
/// Sets the arrow column of the text list.
91+
void setArrowColumn(int pos);
8892
/// Clears the list.
8993
void clearList();
9094
/// Scrolls the list up.

0 commit comments

Comments
 (0)