Skip to content

Commit 92d183a

Browse files
committed
apply battlescape buttons
1 parent 4c231fc commit 92d183a

6 files changed

Lines changed: 84 additions & 83 deletions

File tree

‎src/Battlescape/BattlescapeState.cpp‎

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "../Interface/Text.h"
5858
#include "../Interface/Bar.h"
5959
#include "../Interface/ImageButton.h"
60+
#include "../Interface/BattlescapeButton.h"
6061
#include "../Interface/NumberText.h"
6162
#include "../Savegame/SavedGame.h"
6263
#include "../Savegame/SavedBattleGame.h"
@@ -117,27 +118,27 @@ BattlescapeState::BattlescapeState() : _reserve(0), _popups(), _xBeforeMouseScro
117118
_rank = new Surface(26, 23, x + 107, y + 33);
118119

119120
// Create buttons
120-
_btnUnitUp = new InteractiveSurface(32, 16, x + 48, y);
121-
_btnUnitDown = new InteractiveSurface(32, 16, x + 48, y + 16);
122-
_btnMapUp = new InteractiveSurface(32, 16, x + 80, y);
123-
_btnMapDown = new InteractiveSurface(32, 16, x + 80, y + 16);
124-
_btnShowMap = new InteractiveSurface(32, 16, x + 112, y);
125-
_btnKneel = new InteractiveSurface(32, 16, x + 112, y + 16);
126-
_btnInventory = new InteractiveSurface(32, 16, x + 144, y);
127-
_btnCenter = new InteractiveSurface(32, 16, x + 144, y + 16);
128-
_btnNextSoldier = new InteractiveSurface(32, 16, x + 176, y);
129-
_btnNextStop = new InteractiveSurface(32, 16, x + 176, y + 16);
130-
_btnShowLayers = new InteractiveSurface(32, 16, x + 208, y);
131-
_btnHelp = new InteractiveSurface(32, 16, x + 208, y + 16);
132-
_btnEndTurn = new InteractiveSurface(32, 16, x + 240, y);
133-
_btnAbort = new InteractiveSurface(32, 16, x + 240, y + 16);
121+
_btnUnitUp = new BattlescapeButton(32, 16, x + 48, y);
122+
_btnUnitDown = new BattlescapeButton(32, 16, x + 48, y + 16);
123+
_btnMapUp = new BattlescapeButton(32, 16, x + 80, y);
124+
_btnMapDown = new BattlescapeButton(32, 16, x + 80, y + 16);
125+
_btnShowMap = new BattlescapeButton(32, 16, x + 112, y);
126+
_btnKneel = new BattlescapeButton(32, 16, x + 112, y + 16);
127+
_btnInventory = new BattlescapeButton(32, 16, x + 144, y);
128+
_btnCenter = new BattlescapeButton(32, 16, x + 144, y + 16);
129+
_btnNextSoldier = new BattlescapeButton(32, 16, x + 176, y);
130+
_btnNextStop = new BattlescapeButton(32, 16, x + 176, y + 16);
131+
_btnShowLayers = new BattlescapeButton(32, 16, x + 208, y);
132+
_btnHelp = new BattlescapeButton(32, 16, x + 208, y + 16);
133+
_btnEndTurn = new BattlescapeButton(32, 16, x + 240, y);
134+
_btnAbort = new BattlescapeButton(32, 16, x + 240, y + 16);
134135
_btnStats = new InteractiveSurface(164, 23, x + 107, y + 33);
135-
_btnReserveNone = new ImageButton(17, 11, x + 60, y + 33);
136-
_btnReserveSnap = new ImageButton(17, 11, x + 78, y + 33);
137-
_btnReserveAimed = new ImageButton(17, 11, x + 60, y + 45);
138-
_btnReserveAuto = new ImageButton(17, 11, x + 78, y + 45);
139-
_btnReserveKneel = new ImageButton(10, 23, x + 96, y + 33);
140-
_btnZeroTUs = new ImageButton(10, 23, x + 49, y + 33);
136+
_btnReserveNone = new BattlescapeButton(17, 11, x + 60, y + 33);
137+
_btnReserveSnap = new BattlescapeButton(17, 11, x + 78, y + 33);
138+
_btnReserveAimed = new BattlescapeButton(17, 11, x + 60, y + 45);
139+
_btnReserveAuto = new BattlescapeButton(17, 11, x + 78, y + 45);
140+
_btnReserveKneel = new BattlescapeButton(10, 23, x + 96, y + 33);
141+
_btnZeroTUs = new BattlescapeButton(10, 23, x + 49, y + 33);
141142
_btnLeftHandItem = new InteractiveSurface(32, 48, x + 8, y + 5);
142143
_numAmmoLeft = new NumberText(30, 5, x + 8, y + 4);
143144
_btnRightHandItem = new InteractiveSurface(32, 48, x + 280, y + 5);
@@ -151,9 +152,9 @@ BattlescapeState::BattlescapeState() : _reserve(0), _popups(), _xBeforeMouseScro
151152
}
152153
_numVisibleUnit[9]->setX(_numVisibleUnit[9]->getX() - 2); // center number 10
153154
_warning = new WarningMessage(224, 24, x + 48, y + 32);
154-
_btnLaunch = new InteractiveSurface(32, 24, screenWidth - 32, 0); // we need screenWidth, because that is independent of the black bars on the screen
155+
_btnLaunch = new BattlescapeButton(32, 24, screenWidth - 32, 0); // we need screenWidth, because that is independent of the black bars on the screen
155156
_btnLaunch->setVisible(false);
156-
_btnPsi = new InteractiveSurface(32, 24, screenWidth - 32, 25); // we need screenWidth, because that is independent of the black bars on the screen
157+
_btnPsi = new BattlescapeButton(32, 24, screenWidth - 32, 25); // we need screenWidth, because that is independent of the black bars on the screen
157158
_btnPsi->setVisible(false);
158159

159160
// Create soldier stats summary
@@ -183,7 +184,32 @@ BattlescapeState::BattlescapeState() : _reserve(0), _popups(), _xBeforeMouseScro
183184

184185
add(_map);
185186
add(_icons);
186-
add(_numLayers, "numLayers", "battlescape", _icons);
187+
188+
// Add in custom reserve buttons
189+
Surface *icons = _game->getResourcePack()->getSurface("ICONS.PCK");
190+
if (_game->getResourcePack()->getSurface("TFTDReserve"))
191+
{
192+
Surface *tftdIcons = _game->getResourcePack()->getSurface("TFTDReserve");
193+
tftdIcons->setX(48);
194+
tftdIcons->setY(176);
195+
tftdIcons->blit(icons);
196+
}
197+
198+
// there is some cropping going on here, because the icons image is 320x200 while we only need the bottom of it.
199+
SDL_Rect *r = icons->getCrop();
200+
r->x = 0;
201+
r->y = 200 - iconsHeight;
202+
r->w = iconsWidth;
203+
r->h = iconsHeight;
204+
// we need to blit the icons before we add the battlescape buttons, as they copy the underlying parent surface.
205+
icons->blit(_icons);
206+
207+
// this is a hack to fix the single transparent pixel on TFTD's icon panel.
208+
if (_game->getRuleset()->getInterface("battlescape")->getElement("icons")->TFTDMode)
209+
{
210+
_icons->setPixel(46, 44, 8);
211+
}
212+
187213
add(_rank, "rank", "battlescape", _icons);
188214
add(_btnUnitUp, "buttonUnitUp", "battlescape", _icons);
189215
add(_btnUnitDown, "buttonUnitDown", "battlescape", _icons);
@@ -196,6 +222,7 @@ BattlescapeState::BattlescapeState() : _reserve(0), _popups(), _xBeforeMouseScro
196222
add(_btnNextSoldier, "buttonNextSoldier", "battlescape", _icons);
197223
add(_btnNextStop, "buttonNextStop", "battlescape", _icons);
198224
add(_btnShowLayers, "buttonShowLayers", "battlescape", _icons);
225+
add(_numLayers, "numLayers", "battlescape", _icons);
199226
add(_btnHelp, "buttonHelp", "battlescape", _icons);
200227
add(_btnEndTurn, "buttonEndTurn", "battlescape", _icons);
201228
add(_btnAbort, "buttonAbort", "battlescape", _icons);
@@ -240,24 +267,6 @@ BattlescapeState::BattlescapeState() : _reserve(0), _popups(), _xBeforeMouseScro
240267
_map->onMouseClick((ActionHandler)&BattlescapeState::mapClick, 0);
241268
_map->onMouseIn((ActionHandler)&BattlescapeState::mapIn);
242269

243-
// Add in custom reserve buttons
244-
Surface *icons = _game->getResourcePack()->getSurface("ICONS.PCK");
245-
if (_game->getResourcePack()->getSurface("TFTDReserve"))
246-
{
247-
Surface *tftdIcons = _game->getResourcePack()->getSurface("TFTDReserve");
248-
tftdIcons->setX(48);
249-
tftdIcons->setY(176);
250-
tftdIcons->blit(icons);
251-
}
252-
253-
// there is some cropping going on here, because the icons image is 320x200 while we only need the bottom of it.
254-
SDL_Rect *r = icons->getCrop();
255-
r->x = 0;
256-
r->y = 200 - iconsHeight;
257-
r->w = iconsWidth;
258-
r->h = iconsHeight;
259-
icons->blit(_icons);
260-
261270
_numLayers->setColor(Palette::blockOffset(1)-2);
262271
_numLayers->setValue(1);
263272

@@ -397,12 +406,14 @@ BattlescapeState::BattlescapeState() : _reserve(0), _popups(), _xBeforeMouseScro
397406
_btnReserveKneel->setTooltip("STR_RESERVE_TIME_UNITS_FOR_KNEEL");
398407
_btnReserveKneel->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
399408
_btnReserveKneel->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
409+
_btnReserveKneel->allowToggleInversion();
400410

401411
_btnZeroTUs->onMouseClick((ActionHandler)&BattlescapeState::btnZeroTUsClick, SDL_BUTTON_RIGHT);
402412
_btnZeroTUs->onKeyboardPress((ActionHandler)&BattlescapeState::btnZeroTUsClick, Options::keyBattleZeroTUs);
403413
_btnZeroTUs->setTooltip("STR_EXPEND_ALL_TIME_UNITS");
404414
_btnZeroTUs->onMouseIn((ActionHandler)&BattlescapeState::txtTooltipIn);
405415
_btnZeroTUs->onMouseOut((ActionHandler)&BattlescapeState::txtTooltipOut);
416+
_btnZeroTUs->allowClickInversion();
406417

407418
// shortcuts without a specific button
408419
_btnStats->onKeyboardPress((ActionHandler)&BattlescapeState::btnReloadClick, Options::keyBattleReload);
@@ -448,28 +459,11 @@ BattlescapeState::BattlescapeState() : _reserve(0), _popups(), _xBeforeMouseScro
448459

449460
_txtTooltip->setHighContrast(true);
450461

451-
_btnReserveNone->copy(_icons);
452-
_btnReserveNone->setColor(Palette::blockOffset(4)+3);
453462
_btnReserveNone->setGroup(&_reserve);
454-
455-
_btnReserveSnap->copy(_icons);
456-
_btnReserveSnap->setColor(Palette::blockOffset(2)+3);
457463
_btnReserveSnap->setGroup(&_reserve);
458-
459-
_btnReserveAimed->copy(_icons);
460-
_btnReserveAimed->setColor(Palette::blockOffset(2)+3);
461464
_btnReserveAimed->setGroup(&_reserve);
462-
463-
_btnReserveAuto->copy(_icons);
464-
_btnReserveAuto->setColor(Palette::blockOffset(2)+3);
465465
_btnReserveAuto->setGroup(&_reserve);
466-
467-
_btnReserveKneel->copy(_icons);
468-
_btnReserveKneel->setColor(Palette::blockOffset(2)+3);
469-
470-
_btnZeroTUs->copy(_icons);
471-
_btnZeroTUs->setColor(Palette::blockOffset(2)+3);
472-
466+
473467
// Set music
474468
_game->getResourcePack()->playMusic("GMTACTIC");
475469

‎src/Battlescape/BattlescapeState.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace OpenXcom
3131
class Surface;
3232
class Map;
3333
class ImageButton;
34+
class BattlescapeButton;
3435
class InteractiveSurface;
3536
class Text;
3637
class Bar;
@@ -51,11 +52,11 @@ class BattlescapeState : public State
5152
Surface *_rank;
5253
InteractiveSurface *_icons;
5354
Map *_map;
54-
InteractiveSurface *_btnUnitUp, *_btnUnitDown, *_btnMapUp, *_btnMapDown, *_btnShowMap, *_btnKneel;
55-
InteractiveSurface *_btnInventory, *_btnCenter, *_btnNextSoldier, *_btnNextStop, *_btnShowLayers, *_btnHelp;
56-
InteractiveSurface *_btnEndTurn, *_btnAbort, *_btnStats, *_btnLaunch, *_btnPsi;
57-
ImageButton *_reserve;
58-
ImageButton *_btnReserveNone, *_btnReserveSnap, *_btnReserveAimed, *_btnReserveAuto, *_btnReserveKneel, *_btnZeroTUs;
55+
BattlescapeButton *_btnUnitUp, *_btnUnitDown, *_btnMapUp, *_btnMapDown, *_btnShowMap, *_btnKneel;
56+
BattlescapeButton *_btnInventory, *_btnCenter, *_btnNextSoldier, *_btnNextStop, *_btnShowLayers, *_btnHelp;
57+
BattlescapeButton *_btnEndTurn, *_btnAbort, *_btnLaunch, *_btnPsi, *_reserve;
58+
InteractiveSurface *_btnStats;
59+
BattlescapeButton *_btnReserveNone, *_btnReserveSnap, *_btnReserveAimed, *_btnReserveAuto, *_btnReserveKneel, *_btnZeroTUs;
5960
InteractiveSurface *_btnLeftHandItem, *_btnRightHandItem;
6061
static const int VISIBLE_MAX = 10;
6162
InteractiveSurface *_btnVisibleUnit[VISIBLE_MAX];

‎src/Battlescape/InventoryState.cpp‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "../Engine/Palette.h"
2828
#include "../Engine/Surface.h"
2929
#include "../Interface/Text.h"
30+
#include "../Interface/BattlescapeButton.h"
3031
#include "../Engine/Action.h"
3132
#include "../Engine/InteractiveSurface.h"
3233
#include "../Engine/Sound.h"
@@ -91,21 +92,25 @@ InventoryState::InventoryState(bool tu, BattlescapeState *parent) : _tu(tu), _pa
9192
_txtPStr = new Text(40, 9, 245, 56);
9293
_txtItem = new Text(160, 9, 128, 140);
9394
_txtAmmo = new Text(66, 24, 254, 64);
94-
_btnOk = new InteractiveSurface(35, 22, 237, 1);
95-
_btnPrev = new InteractiveSurface(23, 22, 273, 1);
96-
_btnNext = new InteractiveSurface(23, 22, 297, 1);
97-
_btnUnload = new InteractiveSurface(32, 25, 288, 32);
98-
_btnGround = new InteractiveSurface(32, 15, 289, 137);
99-
_btnRank = new InteractiveSurface(26, 23, 0, 0);
100-
_btnCreateTemplate = new InteractiveSurface(32, 22, _templateBtnX, _createTemplateBtnY);
101-
_btnApplyTemplate = new InteractiveSurface(32, 22, _templateBtnX, _applyTemplateBtnY);
95+
_btnOk = new BattlescapeButton(35, 22, 237, 1);
96+
_btnPrev = new BattlescapeButton(23, 22, 273, 1);
97+
_btnNext = new BattlescapeButton(23, 22, 297, 1);
98+
_btnUnload = new BattlescapeButton(32, 25, 288, 32);
99+
_btnGround = new BattlescapeButton(32, 15, 289, 137);
100+
_btnRank = new BattlescapeButton(26, 23, 0, 0);
101+
_btnCreateTemplate = new BattlescapeButton(32, 22, _templateBtnX, _createTemplateBtnY);
102+
_btnApplyTemplate = new BattlescapeButton(32, 22, _templateBtnX, _applyTemplateBtnY);
102103
_selAmmo = new Surface(RuleInventory::HAND_W * RuleInventory::SLOT_W, RuleInventory::HAND_H * RuleInventory::SLOT_H, 272, 88);
103104
_inv = new Inventory(_game, 320, 200, 0, 0, _parent == 0);
104105

105106
// Set palette
106107
setPalette("PAL_BATTLESCAPE");
107108

108109
add(_bg);
110+
111+
// Set up objects
112+
_game->getResourcePack()->getSurface("TAC01.SCR")->blit(_bg);
113+
109114
add(_soldier);
110115
add(_txtName, "textName", "inventory", _bg);
111116
add(_txtTus, "textTUs", "inventory", _bg);
@@ -136,8 +141,6 @@ InventoryState::InventoryState(bool tu, BattlescapeState *parent) : _tu(tu), _pa
136141
centerAllSurfaces();
137142

138143

139-
// Set up objects
140-
_game->getResourcePack()->getSurface("TAC01.SCR")->blit(_bg);
141144

142145
_txtName->setBig();
143146
_txtName->setHighContrast(true);
@@ -928,6 +931,8 @@ void InventoryState::_updateTemplateButtons(bool isVisible)
928931
_game->getResourcePack()->getSurface("InvCopyActive")->blit(_btnCreateTemplate);
929932
_game->getResourcePack()->getSurface("InvPaste")->blit(_btnApplyTemplate);
930933
}
934+
_btnCreateTemplate->initSurfaces();
935+
_btnApplyTemplate->initSurfaces();
931936
}
932937
else
933938
{

‎src/Battlescape/InventoryState.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Inventory;
3535
class SavedBattleGame;
3636
class BattlescapeState;
3737
class BattleUnit;
38+
class BattlescapeButton;
3839

3940
/**
4041
* Screen which displays soldier's inventory.
@@ -44,8 +45,8 @@ class InventoryState : public State
4445
private:
4546
Surface *_bg, *_soldier;
4647
Text *_txtName, *_txtItem, *_txtAmmo, *_txtWeight, *_txtTus, *_txtFAcc, *_txtReact, *_txtPSkill, *_txtPStr;
47-
InteractiveSurface *_btnOk, *_btnPrev, *_btnNext, *_btnUnload, *_btnGround, *_btnRank;
48-
InteractiveSurface *_btnCreateTemplate, *_btnApplyTemplate;
48+
BattlescapeButton *_btnOk, *_btnPrev, *_btnNext, *_btnUnload, *_btnGround, *_btnRank;
49+
BattlescapeButton *_btnCreateTemplate, *_btnApplyTemplate;
4950
Surface *_selAmmo;
5051
Inventory *_inv;
5152
std::vector<EquipmentLayoutItem*> _curInventoryTemplate;

‎src/Battlescape/MiniMapState.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <sstream>
2222
#include "../Engine/Game.h"
2323
#include "../Engine/Screen.h"
24-
#include "../Engine/InteractiveSurface.h"
24+
#include "../Interface/BattlescapeButton.h"
2525
#include "../Resource/ResourcePack.h"
2626
#include "../Ruleset/Ruleset.h"
2727
#include "../Ruleset/RuleInterface.h"
@@ -55,15 +55,16 @@ MiniMapState::MiniMapState (Camera * camera, SavedBattleGame * battleGame)
5555

5656
_bg = new Surface(320, 200);
5757
_miniMapView = new MiniMapView(221, 148, 48, 16, _game, camera, battleGame);
58-
_btnLvlUp = new InteractiveSurface(18, 20, 24, 62);
59-
_btnLvlDwn = new InteractiveSurface(18, 20, 24, 88);
60-
_btnOk = new InteractiveSurface(32, 32, 275, 145);
58+
_btnLvlUp = new BattlescapeButton(18, 20, 24, 62);
59+
_btnLvlDwn = new BattlescapeButton(18, 20, 24, 88);
60+
_btnOk = new BattlescapeButton(32, 32, 275, 145);
6161
_txtLevel = new Text(28, 16, 281, 75);
6262

6363
// Set palette
6464
battleGame->setPaletteByDepth(this);
6565

6666
add(_bg);
67+
_game->getResourcePack()->getSurface("SCANBORD.PCK")->blit(_bg);
6768
add(_miniMapView);
6869
add(_btnLvlUp, "buttonUp", "minimap", _bg);
6970
add(_btnLvlDwn, "buttonDown", "minimap", _bg);
@@ -78,7 +79,6 @@ MiniMapState::MiniMapState (Camera * camera, SavedBattleGame * battleGame)
7879
_bg->drawRect(46, 14, 223, 151, Palette::blockOffset(15)+15);
7980
}
8081

81-
_game->getResourcePack()->getSurface("SCANBORD.PCK")->blit(_bg);
8282
_btnLvlUp->onMouseClick((ActionHandler)&MiniMapState::btnLevelUpClick);
8383
_btnLvlDwn->onMouseClick((ActionHandler)&MiniMapState::btnLevelDownClick);
8484
_btnOk->onMouseClick((ActionHandler)&MiniMapState::btnOkClick);

‎src/Battlescape/MiniMapState.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace OpenXcom
2525
{
2626

2727
class Camera;
28-
class InteractiveSurface;
28+
class BattlescapeButton;
2929
class Text;
3030
class MiniMapView;
3131
class Timer;
@@ -38,7 +38,7 @@ class MiniMapState : public State
3838
{
3939
Surface * _bg;
4040
MiniMapView *_miniMapView;
41-
InteractiveSurface *_btnLvlUp, *_btnLvlDwn, *_btnOk;
41+
BattlescapeButton *_btnLvlUp, *_btnLvlDwn, *_btnOk;
4242
Text *_txtLevel;
4343
Timer *_timerAnimate;
4444
/// Handles Minimap animation.

0 commit comments

Comments
 (0)