Skip to content

Commit 3e8feb7

Browse files
committed
[cleanup] Split eUnitDataSymbolType with big symbols
1 parent d81d216 commit 3e8feb7

File tree

8 files changed

+91
-74
lines changed

8 files changed

+91
-74
lines changed

src/lib/resources/uidata.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ SDL_Rect cGraphicsData::getSmallSymbolPosition (eUnitDataSymbolType symbolType)
3939
switch (symbolType)
4040
{
4141
case eUnitDataSymbolType::Speed: return getRect_SmallSymbol_Speed();
42-
case eUnitDataSymbolType::Hits: return getRect_SmallSymbol_Hits();
42+
case eUnitDataSymbolType::HitsGreen: return getRect_SmallSymbol_HitsGreen();
43+
case eUnitDataSymbolType::HitsOrange: return getRect_SmallSymbol_HitsOrange();
44+
case eUnitDataSymbolType::HitsRed: return getRect_SmallSymbol_HitsRed();
4345
case eUnitDataSymbolType::Ammo: return getRect_SmallSymbol_Ammo();
4446
case eUnitDataSymbolType::Shots: return getRect_SmallSymbol_Shots();
4547
case eUnitDataSymbolType::Metal: return getRect_SmallSymbol_Metal();
@@ -49,13 +51,6 @@ SDL_Rect cGraphicsData::getSmallSymbolPosition (eUnitDataSymbolType symbolType)
4951
case eUnitDataSymbolType::Human: return getRect_SmallSymbol_Human();
5052
case eUnitDataSymbolType::TransportTank: return getRect_SmallSymbol_TransportTank();
5153
case eUnitDataSymbolType::TransportAir: return getRect_SmallSymbol_TransportAir();
52-
53-
case eUnitDataSymbolType::Attack:
54-
case eUnitDataSymbolType::Range:
55-
case eUnitDataSymbolType::Armor:
56-
case eUnitDataSymbolType::Scan:
57-
case eUnitDataSymbolType::MetalEmpty:
58-
break;
5954
}
6055
return {};
6156
}

src/lib/resources/uidata.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ class cGraphicsData
187187
static SDL_Rect getSmallSymbolPosition (eUnitDataSymbolType);
188188

189189
static SDL_Rect getRect_SmallSymbol_Speed() { return {0, 98, 7, 7}; }
190-
static SDL_Rect getRect_SmallSymbol_Hits() { return {14, 98, 6, 9}; }
190+
static SDL_Rect getRect_SmallSymbol_HitsGreen() { return {14, 98, 6, 9}; }
191+
static SDL_Rect getRect_SmallSymbol_HitsOrange() { return {26, 98, 6, 9}; }
192+
static SDL_Rect getRect_SmallSymbol_HitsRed() { return {38, 98, 6, 9}; }
191193
static SDL_Rect getRect_SmallSymbol_Ammo() { return {50, 98, 5, 7}; }
192194
static SDL_Rect getRect_SmallSymbol_Shots() { return {88, 98, 8, 4}; }
193195
static SDL_Rect getRect_SmallSymbol_Metal() { return {60, 98, 7, 10}; }

src/lib/resources/unitdatasymboltype.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@
2121
#define resources_unitdatasymboltypeH
2222

2323
enum class eUnitDataSymbolType
24+
{
25+
Speed,
26+
HitsGreen,
27+
HitsOrange,
28+
HitsRed,
29+
Ammo,
30+
Shots,
31+
Metal,
32+
Oil,
33+
Gold,
34+
Energy,
35+
Human,
36+
TransportTank,
37+
TransportAir
38+
};
39+
40+
enum class eUnitDataBigSymbolType
2441
{
2542
Speed,
2643
Hits,
@@ -35,9 +52,7 @@ enum class eUnitDataSymbolType
3552
Oil,
3653
Gold,
3754
Energy,
38-
Human,
39-
TransportTank,
40-
TransportAir
55+
Human
4156
};
4257

4358
#endif

src/ui/graphical/game/widgets/unitdetailshud.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace
6060
case eStorageUnitsImageType::None: throw std::runtime_error ("unreachable");
6161
}
6262
}
63+
6364
} // namespace
6465

6566
//------------------------------------------------------------------------------
@@ -136,7 +137,7 @@ void cUnitDetailsHud::reset()
136137
const auto& data = unit->data;
137138
const auto& staticData = unit->getStaticUnitData();
138139

139-
drawRow (0, eUnitDataSymbolType::Hits, data.getHitpoints(), data.getHitpointsMax(), lngPack.i18n ("Others~Hitpoints_7"));
140+
drawRow (0, getUnitDataSymbolTypeHits(data.getHitpoints(), data.getHitpointsMax()), data.getHitpoints(), data.getHitpointsMax(), lngPack.i18n ("Others~Hitpoints_7"));
140141

141142
if (data.getSpeedMax() > 0) drawRow (2, eUnitDataSymbolType::Speed, data.getSpeed() / 4, data.getSpeedMax() / 4, lngPack.i18n ("Others~Speed_7"));
142143

@@ -251,18 +252,6 @@ void cUnitDetailsHud::drawRow (size_t index, eUnitDataSymbolType symbolType, int
251252
auto src = GraphicsData.getSmallSymbolPosition (symbolType);
252253
const cPosition srcSize = {src.w, src.h};
253254
int toValue = value2;
254-
255-
if (symbolType == eUnitDataSymbolType::Hits)
256-
{
257-
if (value1 <= value2 / 4) // red
258-
{
259-
src.x += srcSize.x() * 4;
260-
}
261-
else if (value1 <= value2 / 2) // orange
262-
{
263-
src.x += srcSize.x() * 2;
264-
}
265-
}
266255
int offX = srcSize.x();
267256
int step = 1;
268257

@@ -295,3 +284,20 @@ void cUnitDetailsHud::drawRow (size_t index, eUnitDataSymbolType symbolType, int
295284
value1 -= step;
296285
}
297286
}
287+
288+
//------------------------------------------------------------------------------
289+
eUnitDataSymbolType cUnitDetailsHud::getUnitDataSymbolTypeHits (int value, int valueMax)
290+
{
291+
if (value <= valueMax / 4) // red
292+
{
293+
return eUnitDataSymbolType::HitsRed;
294+
}
295+
else if (value <= valueMax / 2) // orange
296+
{
297+
return eUnitDataSymbolType::HitsOrange;
298+
}
299+
else
300+
{
301+
return eUnitDataSymbolType::HitsGreen;
302+
}
303+
}

src/ui/graphical/game/widgets/unitdetailshud.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class cUnitDetailsHud : public cWidget
4343

4444
// TODO: find nice place for these functions
4545
static void drawSmallSymbols (SDL_Surface* destination, int rowHeight, eUnitDataSymbolType, const cPosition&, int value1, int value2);
46+
static eUnitDataSymbolType getUnitDataSymbolTypeHits (int value, int valueMax);
4647

4748
private:
4849
UniqueSurface surface;

src/ui/graphical/game/widgets/unitdetailsstored.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ void cUnitDetailsStored::reset()
9494

9595
const auto& data = unit->data;
9696

97-
drawRow (0, eUnitDataSymbolType::Hits, data.getHitpoints(), data.getHitpointsMax(), lngPack.i18n ("Others~Hitpoints_7"));
97+
drawRow (0, cUnitDetailsHud::getUnitDataSymbolTypeHits (data.getHitpoints(), data.getHitpointsMax()), data.getHitpoints(), data.getHitpointsMax(), lngPack.i18n ("Others~Hitpoints_7"));
9898

9999
if (unit->getStaticUnitData().canAttack) drawRow (1, eUnitDataSymbolType::Ammo, data.getAmmo(), data.getAmmoMax(), lngPack.i18n ("Others~Ammo_7"));
100100

101101
const cVehicle* vehicle = dynamic_cast<const cVehicle*> (unit);
102102
const auto storedResources = vehicle->getStoredResources();
103-
const auto storagedResMax = vehicle->getStaticUnitData().storageResMax;
103+
const auto storageResMax = vehicle->getStaticUnitData().storageResMax;
104104
const auto title = toTranslatedString (unit->getStaticUnitData().storeResType);
105105
switch (unit->getStaticUnitData().storeResType)
106106
{
107107
case eResourceType::None: break;
108-
case eResourceType::Metal: drawRow (1, eUnitDataSymbolType::Metal, storedResources, storagedResMax, title); break;
109-
case eResourceType::Oil: drawRow (1, eUnitDataSymbolType::Oil, storedResources, storagedResMax, title); break;
110-
case eResourceType::Gold: drawRow (1, eUnitDataSymbolType::Gold, storedResources, storagedResMax, title); break;
108+
case eResourceType::Metal: drawRow (1, eUnitDataSymbolType::Metal, storedResources, storageResMax, title); break;
109+
case eResourceType::Oil: drawRow (1, eUnitDataSymbolType::Oil, storedResources, storageResMax, title); break;
110+
case eResourceType::Gold: drawRow (1, eUnitDataSymbolType::Gold, storedResources, storageResMax, title); break;
111111
}
112112
}
113113

0 commit comments

Comments
 (0)