Skip to content

Commit 7016cb0

Browse files
committed
- Finished Battlescape Options.
- Fixed crash when unit moved. - Changed language format to user-editable format.
1 parent 0b1a7fa commit 7016cb0

11 files changed

Lines changed: 264 additions & 8 deletions

File tree

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.lng eol=lf

‎bin/DATA/Language/English.lng‎

452 Bytes
Binary file not shown.

‎bin/DATA/Language/French.lng‎

1.79 KB
Binary file not shown.

‎bin/DATA/Language/German.lng‎

1.46 KB
Binary file not shown.

‎bin/DATA/Language/Italian.lng‎

782 Bytes
Binary file not shown.

‎bin/DATA/Language/Spanish.lng‎

1.5 KB
Binary file not shown.

‎src/Battlescape/BattlescapeOptionsState.cpp‎

Lines changed: 240 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,45 @@ BattlescapeOptionsState::BattlescapeOptionsState(Game *game) : State(game)
4949
_btnScrollSpeed5 = new TextButton(22, 30, 112, 42);
5050

5151
_txtScrollType = new Text(120, 9, 150, 32);
52+
_txtTriggerScroll = new Text(80, 9, 182, 45);
53+
_txtAutoScroll = new Text(80, 9, 182, 61);
5254
_btnScrollType1 = new TextButton(30, 14, 150, 42);
5355
_btnScrollType2 = new TextButton(30, 14, 150, 58);
5456

57+
_txtFireSpeed = new Text(120, 9, 16, 74);
58+
_btnFireSpeed1 = new TextButton(22, 12, 16, 84);
59+
_btnFireSpeed2 = new TextButton(28, 12, 40, 84);
60+
_btnFireSpeed3 = new TextButton(36, 12, 70, 84);
61+
_btnFireSpeed4 = new TextButton(45, 12, 108, 84);
62+
_btnFireSpeed5 = new TextButton(56, 12, 155, 84);
63+
_btnFireSpeed6 = new TextButton(69, 12, 213, 84);
64+
65+
_txtXcomSpeed = new Text(120, 9, 16, 106);
66+
_btnXcomSpeed1 = new TextButton(22, 12, 16, 116);
67+
_btnXcomSpeed2 = new TextButton(28, 12, 40, 116);
68+
_btnXcomSpeed3 = new TextButton(36, 12, 70, 116);
69+
_btnXcomSpeed4 = new TextButton(45, 12, 108, 116);
70+
_btnXcomSpeed5 = new TextButton(56, 12, 155, 116);
71+
_btnXcomSpeed6 = new TextButton(69, 12, 213, 116);
72+
73+
_txtAlienSpeed = new Text(120, 9, 16, 138);
74+
_btnAlienSpeed1 = new TextButton(22, 12, 16, 148);
75+
_btnAlienSpeed2 = new TextButton(28, 12, 40, 148);
76+
_btnAlienSpeed3 = new TextButton(36, 12, 70, 148);
77+
_btnAlienSpeed4 = new TextButton(45, 12, 108, 148);
78+
_btnAlienSpeed5 = new TextButton(56, 12, 155, 148);
79+
_btnAlienSpeed6 = new TextButton(69, 12, 213, 148);
80+
5581
_btnOk = new TextButton(120, 16, 16, 174);
5682
_btnSave = new TextButton(120, 16, 184, 174);
5783

5884
switch (Options::getInt("battleScrollSpeed"))
5985
{
60-
case 40: _scrollSpeed = _btnScrollSpeed1; break;
61-
case 32: _scrollSpeed = _btnScrollSpeed2; break;
86+
case 8: _scrollSpeed = _btnScrollSpeed1; break;
87+
case 16: _scrollSpeed = _btnScrollSpeed2; break;
6288
case 24: _scrollSpeed = _btnScrollSpeed3; break;
63-
case 16: _scrollSpeed = _btnScrollSpeed4; break;
64-
case 8: _scrollSpeed = _btnScrollSpeed5; break;
89+
case 32: _scrollSpeed = _btnScrollSpeed4; break;
90+
case 40: _scrollSpeed = _btnScrollSpeed5; break;
6591
default: _scrollSpeed = 0; break;
6692
}
6793
switch (Options::getInt("battleScrollType"))
@@ -154,6 +180,159 @@ BattlescapeOptionsState::BattlescapeOptionsState(Game *game) : State(game)
154180
_txtTitle->setHighContrast(true);
155181
_txtTitle->setText(_game->getLanguage()->getString("STR_GAME_OPTIONS"));
156182

183+
_txtScrollSpeed->setColor(Palette::blockOffset(0));
184+
_txtScrollSpeed->setHighContrast(true);
185+
_txtScrollSpeed->setText(_game->getLanguage()->getString("STR_SCROLL_SPEED"));
186+
187+
_btnScrollSpeed1->setColor(Palette::blockOffset(0)+3);
188+
_btnScrollSpeed1->setHighContrast(true);
189+
_btnScrollSpeed1->setText(L"1");
190+
_btnScrollSpeed1->setGroup(&_scrollSpeed);
191+
192+
_btnScrollSpeed2->setColor(Palette::blockOffset(0)+3);
193+
_btnScrollSpeed2->setHighContrast(true);
194+
_btnScrollSpeed2->setText(L"2");
195+
_btnScrollSpeed2->setGroup(&_scrollSpeed);
196+
197+
_btnScrollSpeed3->setColor(Palette::blockOffset(0)+3);
198+
_btnScrollSpeed3->setHighContrast(true);
199+
_btnScrollSpeed3->setText(L"3");
200+
_btnScrollSpeed3->setGroup(&_scrollSpeed);
201+
202+
_btnScrollSpeed4->setColor(Palette::blockOffset(0)+3);
203+
_btnScrollSpeed4->setHighContrast(true);
204+
_btnScrollSpeed4->setText(L"4");
205+
_btnScrollSpeed4->setGroup(&_scrollSpeed);
206+
207+
_btnScrollSpeed5->setColor(Palette::blockOffset(0)+3);
208+
_btnScrollSpeed5->setHighContrast(true);
209+
_btnScrollSpeed5->setText(L"5");
210+
_btnScrollSpeed5->setGroup(&_scrollSpeed);
211+
212+
_txtScrollType->setColor(Palette::blockOffset(0));
213+
_txtScrollType->setHighContrast(true);
214+
_txtScrollType->setText(_game->getLanguage()->getString("STR_SCROLL_TYPE"));
215+
216+
_txtTriggerScroll->setColor(Palette::blockOffset(0));
217+
_txtTriggerScroll->setHighContrast(true);
218+
_txtTriggerScroll->setText(_game->getLanguage()->getString("STR_TRIGGER_SCROLL"));
219+
220+
_txtAutoScroll->setColor(Palette::blockOffset(0));
221+
_txtAutoScroll->setHighContrast(true);
222+
_txtAutoScroll->setText(_game->getLanguage()->getString("STR_AUTO_SCROLL"));
223+
224+
_btnScrollType1->setColor(Palette::blockOffset(0)+3);
225+
_btnScrollType1->setHighContrast(true);
226+
_btnScrollType1->setText(L"1");
227+
_btnScrollType1->setGroup(&_scrollType);
228+
229+
_btnScrollType2->setColor(Palette::blockOffset(0)+3);
230+
_btnScrollType2->setHighContrast(true);
231+
_btnScrollType2->setText(L"2");
232+
_btnScrollType2->setGroup(&_scrollType);
233+
234+
_txtFireSpeed->setColor(Palette::blockOffset(0));
235+
_txtFireSpeed->setHighContrast(true);
236+
_txtFireSpeed->setText(_game->getLanguage()->getString("STR_FIRE_SPEED"));
237+
238+
_btnFireSpeed1->setColor(Palette::blockOffset(0)+3);
239+
_btnFireSpeed1->setHighContrast(true);
240+
_btnFireSpeed1->setText(L"1");
241+
_btnFireSpeed1->setGroup(&_fireSpeed);
242+
243+
_btnFireSpeed2->setColor(Palette::blockOffset(0)+3);
244+
_btnFireSpeed2->setHighContrast(true);
245+
_btnFireSpeed2->setText(L"2");
246+
_btnFireSpeed2->setGroup(&_fireSpeed);
247+
248+
_btnFireSpeed3->setColor(Palette::blockOffset(0)+3);
249+
_btnFireSpeed3->setHighContrast(true);
250+
_btnFireSpeed3->setText(L"3");
251+
_btnFireSpeed3->setGroup(&_fireSpeed);
252+
253+
_btnFireSpeed4->setColor(Palette::blockOffset(0)+3);
254+
_btnFireSpeed4->setHighContrast(true);
255+
_btnFireSpeed4->setText(L"4");
256+
_btnFireSpeed4->setGroup(&_fireSpeed);
257+
258+
_btnFireSpeed5->setColor(Palette::blockOffset(0)+3);
259+
_btnFireSpeed5->setHighContrast(true);
260+
_btnFireSpeed5->setText(L"5");
261+
_btnFireSpeed5->setGroup(&_fireSpeed);
262+
263+
_btnFireSpeed6->setColor(Palette::blockOffset(0)+3);
264+
_btnFireSpeed6->setHighContrast(true);
265+
_btnFireSpeed6->setText(L"6");
266+
_btnFireSpeed6->setGroup(&_fireSpeed);
267+
268+
_txtXcomSpeed->setColor(Palette::blockOffset(0));
269+
_txtXcomSpeed->setHighContrast(true);
270+
_txtXcomSpeed->setText(_game->getLanguage()->getString("STR_XCOM_MOVEMENT_SPEED"));
271+
272+
_btnXcomSpeed1->setColor(Palette::blockOffset(0)+3);
273+
_btnXcomSpeed1->setHighContrast(true);
274+
_btnXcomSpeed1->setText(L"1");
275+
_btnXcomSpeed1->setGroup(&_xcomSpeed);
276+
277+
_btnXcomSpeed2->setColor(Palette::blockOffset(0)+3);
278+
_btnXcomSpeed2->setHighContrast(true);
279+
_btnXcomSpeed2->setText(L"2");
280+
_btnXcomSpeed2->setGroup(&_xcomSpeed);
281+
282+
_btnXcomSpeed3->setColor(Palette::blockOffset(0)+3);
283+
_btnXcomSpeed3->setHighContrast(true);
284+
_btnXcomSpeed3->setText(L"3");
285+
_btnXcomSpeed3->setGroup(&_xcomSpeed);
286+
287+
_btnXcomSpeed4->setColor(Palette::blockOffset(0)+3);
288+
_btnXcomSpeed4->setHighContrast(true);
289+
_btnXcomSpeed4->setText(L"4");
290+
_btnXcomSpeed4->setGroup(&_xcomSpeed);
291+
292+
_btnXcomSpeed5->setColor(Palette::blockOffset(0)+3);
293+
_btnXcomSpeed5->setHighContrast(true);
294+
_btnXcomSpeed5->setText(L"5");
295+
_btnXcomSpeed5->setGroup(&_xcomSpeed);
296+
297+
_btnXcomSpeed6->setColor(Palette::blockOffset(0)+3);
298+
_btnXcomSpeed6->setHighContrast(true);
299+
_btnXcomSpeed6->setText(L"6");
300+
_btnXcomSpeed6->setGroup(&_xcomSpeed);
301+
302+
_txtAlienSpeed->setColor(Palette::blockOffset(0));
303+
_txtAlienSpeed->setHighContrast(true);
304+
_txtAlienSpeed->setText(_game->getLanguage()->getString("STR_ALIEN_MOVEMENT_SPEED"));
305+
306+
_btnAlienSpeed1->setColor(Palette::blockOffset(0)+3);
307+
_btnAlienSpeed1->setHighContrast(true);
308+
_btnAlienSpeed1->setText(L"1");
309+
_btnAlienSpeed1->setGroup(&_alienSpeed);
310+
311+
_btnAlienSpeed2->setColor(Palette::blockOffset(0)+3);
312+
_btnAlienSpeed2->setHighContrast(true);
313+
_btnAlienSpeed2->setText(L"2");
314+
_btnAlienSpeed2->setGroup(&_alienSpeed);
315+
316+
_btnAlienSpeed3->setColor(Palette::blockOffset(0)+3);
317+
_btnAlienSpeed3->setHighContrast(true);
318+
_btnAlienSpeed3->setText(L"3");
319+
_btnAlienSpeed3->setGroup(&_alienSpeed);
320+
321+
_btnAlienSpeed4->setColor(Palette::blockOffset(0)+3);
322+
_btnAlienSpeed4->setHighContrast(true);
323+
_btnAlienSpeed4->setText(L"4");
324+
_btnAlienSpeed4->setGroup(&_alienSpeed);
325+
326+
_btnAlienSpeed5->setColor(Palette::blockOffset(0)+3);
327+
_btnAlienSpeed5->setHighContrast(true);
328+
_btnAlienSpeed5->setText(L"5");
329+
_btnAlienSpeed5->setGroup(&_alienSpeed);
330+
331+
_btnAlienSpeed6->setColor(Palette::blockOffset(0)+3);
332+
_btnAlienSpeed6->setHighContrast(true);
333+
_btnAlienSpeed6->setText(L"6");
334+
_btnAlienSpeed6->setGroup(&_alienSpeed);
335+
157336
_btnOk->setColor(Palette::blockOffset(0)+3);
158337
_btnOk->setHighContrast(true);
159338
_btnOk->setText(_game->getLanguage()->getString("STR_OK"));
@@ -174,11 +353,67 @@ BattlescapeOptionsState::~BattlescapeOptionsState()
174353
}
175354

176355
/**
177-
* Returns to the previous screen.
356+
* Saves options and returns to the previous screen.
178357
* @param action Pointer to an action.
179358
*/
180359
void BattlescapeOptionsState::btnOkClick(Action *action)
181360
{
361+
if (_scrollSpeed == _btnScrollSpeed1)
362+
Options::setInt("battleScrollSpeed", 8);
363+
else if (_scrollSpeed == _btnScrollSpeed2)
364+
Options::setInt("battleScrollSpeed", 16);
365+
else if (_scrollSpeed == _btnScrollSpeed3)
366+
Options::setInt("battleScrollSpeed", 24);
367+
else if (_scrollSpeed == _btnScrollSpeed4)
368+
Options::setInt("battleScrollSpeed", 32);
369+
else if (_scrollSpeed == _btnScrollSpeed5)
370+
Options::setInt("battleScrollSpeed", 40);
371+
372+
if (_scrollType == _btnScrollType1)
373+
Options::setInt("battleScrollType", SCROLL_TRIGGER);
374+
else if (_scrollType == _btnScrollType2)
375+
Options::setInt("battleScrollType", SCROLL_AUTO);
376+
377+
if (_fireSpeed == _btnFireSpeed1)
378+
Options::setInt("battleFireSpeed", 30);
379+
else if (_fireSpeed == _btnFireSpeed2)
380+
Options::setInt("battleFireSpeed", 25);
381+
else if (_fireSpeed == _btnFireSpeed3)
382+
Options::setInt("battleFireSpeed", 20);
383+
else if (_fireSpeed == _btnFireSpeed4)
384+
Options::setInt("battleFireSpeed", 15);
385+
else if (_fireSpeed == _btnFireSpeed5)
386+
Options::setInt("battleFireSpeed", 10);
387+
else if (_fireSpeed == _btnFireSpeed6)
388+
Options::setInt("battleFireSpeed", 5);
389+
390+
if (_xcomSpeed == _btnXcomSpeed1)
391+
Options::setInt("battleXcomSpeed", 60);
392+
else if (_xcomSpeed == _btnXcomSpeed2)
393+
Options::setInt("battleXcomSpeed", 50);
394+
else if (_xcomSpeed == _btnXcomSpeed3)
395+
Options::setInt("battleXcomSpeed", 40);
396+
else if (_xcomSpeed == _btnXcomSpeed4)
397+
Options::setInt("battleXcomSpeed", 30);
398+
else if (_xcomSpeed == _btnXcomSpeed5)
399+
Options::setInt("battleXcomSpeed", 20);
400+
else if (_xcomSpeed == _btnXcomSpeed6)
401+
Options::setInt("battleXcomSpeed", 10);
402+
403+
if (_alienSpeed == _btnAlienSpeed1)
404+
Options::setInt("battleAlienSpeed", 60);
405+
else if (_alienSpeed == _btnAlienSpeed2)
406+
Options::setInt("battleAlienSpeed", 50);
407+
else if (_alienSpeed == _btnAlienSpeed3)
408+
Options::setInt("battleAlienSpeed", 40);
409+
else if (_alienSpeed == _btnAlienSpeed4)
410+
Options::setInt("battleAlienSpeed", 30);
411+
else if (_alienSpeed == _btnAlienSpeed5)
412+
Options::setInt("battleAlienSpeed", 20);
413+
else if (_alienSpeed == _btnAlienSpeed6)
414+
Options::setInt("battleAlienSpeed", 10);
415+
416+
Options::save();
182417
_game->popState();
183418
}
184419

‎src/Battlescape/UnitWalkBState.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ UnitWalkBState::~UnitWalkBState()
5757

5858
void UnitWalkBState::init()
5959
{
60-
setNormalWalkSpeed();
6160
_unit = _action.actor;
61+
setNormalWalkSpeed();
6262
_pf = _parent->getGame()->getSavedGame()->getBattleGame()->getPathfinding();
6363
_terrain = _parent->getGame()->getSavedGame()->getBattleGame()->getTerrainModifier();
6464
_target = _action.target;

‎src/Engine/Language.cpp‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ std::string Language::wstrToUtf8(const std::wstring& src)
142142
return dest;
143143
}
144144

145+
/**
146+
* Replaces every instance of a substring.
147+
* @param str The string to modify.
148+
* @param find The substring to find.
149+
* @param replace The substring to replace it with.
150+
*/
151+
void Language::replace(std::string &str, const std::string &find, const std::string &replace)
152+
{
153+
for (size_t i = str.find(find); i != std::string::npos;)
154+
{
155+
str.replace(i, find.length(), replace);
156+
++i;
157+
i = str.find(find, i);
158+
}
159+
}
160+
145161
/**
146162
* Loads pairs of null-terminated strings contained in
147163
* a raw text file into the Language. Each pair is made of
@@ -167,7 +183,7 @@ void Language::loadLng(const std::string &filename)
167183

168184
while (txtFile.read(&value, 1))
169185
{
170-
if (value != '\0')
186+
if (value != '\n')
171187
{
172188
buffer += value;
173189
}
@@ -189,6 +205,8 @@ void Language::loadLng(const std::string &filename)
189205
// Get string
190206
else
191207
{
208+
replace(buffer, "{NEWLINE}", "\n");
209+
replace(buffer, "{SMALLLINE}", "\x02");
192210
bufstr = utf8ToWstr(buffer);
193211
_strings[bufid] = bufstr;
194212
}

‎src/Engine/Language.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Language
4343
static std::string wstrToUtf8(const std::wstring& src);
4444
/// Converts a UTF-8 string to wide-string.
4545
static std::wstring utf8ToWstr(const std::string& src);
46+
/// Replaces a substring.
47+
static void replace(std::string &str, const std::string &find, const std::string &replace);
4648
/// Loads an OpenXcom language file.
4749
void loadLng(const std::string &filename);
4850
/// Gets the language's name.

0 commit comments

Comments
 (0)