Codechange: Store EncodedString for tooltip text.

This replaces capturing and storing string parameters.
This commit is contained in:
2024-12-07 01:41:31 +00:00
committed by Peter Nelson
parent 1f21e9dc74
commit 2cb9f55183
12 changed files with 67 additions and 77 deletions

View File

@@ -2761,13 +2761,12 @@ void UpdateTileSelection()
/**
* Displays the measurement tooltips when selecting multiple tiles
* @param str String to be displayed
* @param paramcount number of params to deal with
* @param text String to be displayed
*/
static inline void ShowMeasurementTooltips(StringID str, uint paramcount)
static inline void ShowMeasurementTooltips(EncodedString &&text)
{
if (!_settings_client.gui.measure_tooltip) return;
GuiShowTooltips(_thd.GetCallbackWnd(), str, TCC_EXIT_VIEWPORT, paramcount);
GuiShowTooltips(_thd.GetCallbackWnd(), std::move(text), TCC_EXIT_VIEWPORT);
}
static void HideMeasurementTooltips()
@@ -2843,8 +2842,7 @@ void VpSetPresizeRange(TileIndex from, TileIndex to)
/* show measurement only if there is any length to speak of */
if (distance > 1) {
SetDParam(0, distance);
ShowMeasurementTooltips(STR_MEASURE_LENGTH, 1);
ShowMeasurementTooltips(GetEncodedString(STR_MEASURE_LENGTH, distance));
} else {
HideMeasurementTooltips();
}
@@ -3019,8 +3017,6 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t
return (int)(h1 - h0) * TILE_HEIGHT_STEP;
}
static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF};
/**
* Check for underflowing the map.
* @param test the variable to test for underflowing
@@ -3240,9 +3236,10 @@ static void CalcRaildirsDrawstyle(int x, int y, int method)
TileIndex t0 = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
TileIndex t1 = TileVirtXY(x, y);
uint distance = DistanceManhattan(t0, t1) + 1;
uint8_t index = 0;
if (distance != 1) {
if (distance == 1) {
HideMeasurementTooltips();
} else {
int heightdiff = CalcHeightdiff(b, distance, t0, t1);
/* If we are showing a tooltip for horizontal or vertical drags,
* 2 tiles have a length of 1. To bias towards the ceiling we add
@@ -3251,11 +3248,12 @@ static void CalcRaildirsDrawstyle(int x, int y, int method)
distance = CeilDiv(distance, 2);
}
SetDParam(index++, distance);
if (heightdiff != 0) SetDParam(index++, heightdiff);
if (heightdiff == 0) {
ShowMeasurementTooltips(GetEncodedString(STR_MEASURE_LENGTH, distance));
} else {
ShowMeasurementTooltips(GetEncodedString(STR_MEASURE_LENGTH_HEIGHTDIFF, distance, heightdiff));
}
}
ShowMeasurementTooltips(measure_strings_length[index], index);
}
_thd.selend.x = x;
@@ -3336,9 +3334,10 @@ calc_heightdiff_single_direction:;
TileIndex t0 = TileVirtXY(sx, sy);
TileIndex t1 = TileVirtXY(x, y);
uint distance = DistanceManhattan(t0, t1) + 1;
uint8_t index = 0;
if (distance != 1) {
if (distance == 1) {
HideMeasurementTooltips();
} else {
/* With current code passing a HT_LINE style to calculate the height
* difference is enough. However if/when a point-tool is created
* with this method, function should be called with new_style (below)
@@ -3346,11 +3345,12 @@ calc_heightdiff_single_direction:;
* new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */
int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1);
SetDParam(index++, distance);
if (heightdiff != 0) SetDParam(index++, heightdiff);
if (heightdiff == 0) {
ShowMeasurementTooltips(GetEncodedString(STR_MEASURE_LENGTH, distance));
} else {
ShowMeasurementTooltips(GetEncodedString(STR_MEASURE_LENGTH_HEIGHTDIFF, distance, heightdiff));
}
}
ShowMeasurementTooltips(measure_strings_length[index], index);
}
break;
@@ -3362,15 +3362,10 @@ calc_heightdiff_single_direction:;
case VPM_X_AND_Y: // drag an X by Y area
if (_settings_client.gui.measure_tooltip) {
static const StringID measure_strings_area[] = {
STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF
};
TileIndex t0 = TileVirtXY(sx, sy);
TileIndex t1 = TileVirtXY(x, y);
uint dx = Delta(TileX(t0), TileX(t1)) + 1;
uint dy = Delta(TileY(t0), TileY(t1)) + 1;
uint8_t index = 0;
/* If dragging an area (eg dynamite tool) and it is actually a single
* row/column, change the type to 'line' to get proper calculation for height */
@@ -3415,12 +3410,15 @@ calc_heightdiff_single_direction:;
if (dx != 1 || dy != 1) {
int heightdiff = CalcHeightdiff(style, 0, t0, t1);
SetDParam(index++, dx - (style & HT_POINT ? 1 : 0));
SetDParam(index++, dy - (style & HT_POINT ? 1 : 0));
if (heightdiff != 0) SetDParam(index++, heightdiff);
}
dx -= (style & HT_POINT ? 1 : 0);
dy -= (style & HT_POINT ? 1 : 0);
ShowMeasurementTooltips(measure_strings_area[index], index);
if (heightdiff == 0) {
ShowMeasurementTooltips(GetEncodedString(STR_MEASURE_AREA, dx, dy));
} else {
ShowMeasurementTooltips(GetEncodedString(STR_MEASURE_AREA_HEIGHTDIFF, dx, dy, heightdiff));
}
}
}
break;