Skip to content

Commit e192e8a

Browse files
committed
Print distances and speeds in terms of tiles, not in 1/128ths of tiles.
Changelog: Print distances and speeds in terms of tiles.
1 parent baf63f1 commit e192e8a

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

lib/widget/bar.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ W_BARGRAPH* barGraphCreate(const W_BARINIT* psInit)
121121
psWidget->majorCol = psInit->sMinorCol;
122122
}
123123

124+
psWidget->denominator = MAX(psInit->denominator, 1);
125+
psWidget->precision = psInit->precision;
126+
124127
barGraphInitialise(psWidget);
125128

126129
return psWidget;

lib/widget/bar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ typedef struct _w_bargraph
3737
UWORD iRange; // Maximum range
3838
UWORD iValue; // Current value
3939
UWORD iOriginal; // hack to keep uncapped value around
40+
int denominator; // Denominator, 1 by default.
41+
int precision; // Number of places after the decimal point to display, 0 by default.
4042
PIELIGHT majorCol; // Colour for the major bar
4143
PIELIGHT minorCol; // Colour for the minor bar
4244
const char *pTip; // The tool tip for the graph

lib/widget/widget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ typedef struct
230230
UWORD size; ///< Initial percentage of the graph that is filled
231231
UWORD minorSize; ///< Percentage of second bar graph if there is one
232232
UWORD iRange; ///< Maximum range
233+
int denominator; ///< Denominator, 1 by default.
234+
int precision; ///< Number of places after the decimal point to display, 0 by default.
233235
PIELIGHT sCol; ///< Bar colour
234236
PIELIGHT sMinorCol; ///< Minor bar colour
235237
const char *pTip; ///< Tool tip text

src/design.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,20 +1549,27 @@ static BOOL _intSetSystemForm(COMPONENT_STATS *psStats)
15491549
/* Add the bar graphs*/
15501550
sBarInit.id = IDDES_SENSORRANGE;
15511551
sBarInit.iRange = (UWORD)getMaxSensorRange();//DBAR_SENSORMAXRANGE;
1552+
sBarInit.pTip = _("Sensor Range");
1553+
sBarInit.denominator = TILE_UNITS;
1554+
sBarInit.precision = 1;
15521555
if (!widgAddBarGraph(psWScreen, &sBarInit))
15531556
{
15541557
return false;
15551558
}
1559+
sBarInit.denominator = 0;
1560+
sBarInit.precision = 0;
15561561
sBarInit.id = IDDES_SENSORPOWER;
15571562
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
15581563
sBarInit.iRange = (UWORD)getMaxSensorPower();//DBAR_SENSORMAXPOWER;
1564+
sBarInit.pTip = _("Sensor Power");
15591565
if (!widgAddBarGraph(psWScreen, &sBarInit))
15601566
{
15611567
return false;
15621568
}
15631569
sBarInit.id = IDDES_SENSORWEIGHT;
15641570
sBarInit.y = DES_STATBAR_Y3; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
15651571
sBarInit.iRange = (UWORD)getMaxComponentWeight();//DBAR_MAXWEIGHT;
1572+
sBarInit.pTip = _("Weight");
15661573
if (!widgAddBarGraph(psWScreen, &sBarInit))
15671574
{
15681575
return false;
@@ -1602,13 +1609,15 @@ static BOOL _intSetSystemForm(COMPONENT_STATS *psStats)
16021609
/* Add the bar graphs */
16031610
sBarInit.id = IDDES_ECMPOWER;
16041611
sBarInit.iRange = (UWORD)getMaxECMPower();//DBAR_ECMMAXPOWER;
1612+
sBarInit.pTip = _("ECM Power");
16051613
if (!widgAddBarGraph(psWScreen, &sBarInit))
16061614
{
16071615
return false;
16081616
}
16091617
sBarInit.id = IDDES_ECMWEIGHT;
16101618
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
16111619
sBarInit.iRange = (UWORD)getMaxComponentWeight();//DBAR_MAXWEIGHT;
1620+
sBarInit.pTip = _("Weight");
16121621
if (!widgAddBarGraph(psWScreen, &sBarInit))
16131622
{
16141623
return false;
@@ -1718,10 +1727,14 @@ static BOOL _intSetSystemForm(COMPONENT_STATS *psStats)
17181727
sBarInit.id = IDDES_WEAPRANGE;
17191728
sBarInit.iRange = (UWORD)getMaxWeaponRange();//DBAR_WEAPMAXRANGE;
17201729
sBarInit.pTip = _("Range");
1730+
sBarInit.denominator = TILE_UNITS;
1731+
sBarInit.precision = 1;
17211732
if (!widgAddBarGraph(psWScreen, &sBarInit))
17221733
{
17231734
return false;
17241735
}
1736+
sBarInit.denominator = 0;
1737+
sBarInit.precision = 0;
17251738
sBarInit.id = IDDES_WEAPDAMAGE;
17261739
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
17271740
sBarInit.iRange = (UWORD)getMaxWeaponDamage();//DBAR_WEAPMAXDAMAGE;
@@ -1904,10 +1917,14 @@ static BOOL intSetPropulsionForm(PROPULSION_STATS *psStats)
19041917
sBarInit.id = IDDES_PROPAIR;
19051918
sBarInit.iRange = (UWORD)getMaxPropulsionSpeed();//DBAR_PROPMAXSPEED;
19061919
sBarInit.pTip = _("Air Speed");
1920+
sBarInit.denominator = TILE_UNITS;
1921+
sBarInit.precision = 2;
19071922
if (!widgAddBarGraph(psWScreen, &sBarInit))
19081923
{
19091924
return false;
19101925
}
1926+
sBarInit.denominator = 0;
1927+
sBarInit.precision = 0;
19111928
sBarInit.id = IDDES_PROPWEIGHT;
19121929
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
19131930
sBarInit.iRange = (UWORD)getMaxComponentWeight();//DBAR_MAXWEIGHT;
@@ -1941,6 +1958,8 @@ static BOOL intSetPropulsionForm(PROPULSION_STATS *psStats)
19411958
sBarInit.id = IDDES_PROPROAD;
19421959
sBarInit.pTip = _("Road Speed");
19431960
sBarInit.iRange = (UWORD)getMaxPropulsionSpeed();//DBAR_PROPMAXSPEED;
1961+
sBarInit.denominator = TILE_UNITS;
1962+
sBarInit.precision = 2;
19441963
if (!widgAddBarGraph(psWScreen, &sBarInit))
19451964
{
19461965
return false;
@@ -1961,6 +1980,8 @@ static BOOL intSetPropulsionForm(PROPULSION_STATS *psStats)
19611980
{
19621981
return false;
19631982
}
1983+
sBarInit.denominator = 0;
1984+
sBarInit.precision = 0;
19641985
sBarInit.id = IDDES_PROPWEIGHT;
19651986
sBarInit.y = DES_STATBAR_Y4; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
19661987
sBarInit.pTip = _("Weight");

src/intdisplay.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,13 +2908,14 @@ void StatGetResearchImage(BASE_STATS *psStat, SDWORD *Image, iIMDShape **Shape,
29082908
static void intDisplayBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, bool isPowerBar)
29092909
{
29102910
W_BARGRAPH *BarGraph = (W_BARGRAPH *)psWidget;
2911-
char szVal[6];
2911+
char szVal[30];
29122912
char const *szCheckWidth = "00000";
29132913
int x0 = xOffset + BarGraph->x;
29142914
int y0 = yOffset + BarGraph->y;
29152915
int arbitaryOffset = 3;
29162916
int iX, iY;
29172917
int barWidth = 100, width;
2918+
int i, precisionFactor = 1, value;
29182919

29192920
if (isPowerBar)
29202921
{
@@ -2942,7 +2943,12 @@ static void intDisplayBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, bool
29422943
iV_DrawImageRect(IntImages, IMAGE_DES_STATSCURR, iX, y0, width, iV_GetImageHeight(IntImages, IMAGE_DES_STATSCURR));
29432944

29442945
/* draw text value */
2945-
sprintf(szVal, "%d", BarGraph->iOriginal);
2946+
for (i = 0; i < BarGraph->precision; ++i)
2947+
{
2948+
precisionFactor *= 10;
2949+
}
2950+
value = (BarGraph->iOriginal * precisionFactor + BarGraph->denominator/2) / BarGraph->denominator;
2951+
sprintf(szVal, "%d%s%.*d", value/precisionFactor, precisionFactor == 1? "" : ".", BarGraph->precision, value%precisionFactor);
29462952
iV_SetTextColour(WZCOL_TEXT_BRIGHT);
29472953
#ifdef WZ_OS_MAC
29482954
iV_DrawText( szVal, x0, iY+2 );

0 commit comments

Comments
 (0)