1
0
Fork 0

Codechange: use StringParameters to pass parameters for TextEffect strings

pull/11956/head
Patric Stout 2024-02-02 19:10:06 +01:00
parent 27eeaf0160
commit fcc3365b1f
4 changed files with 18 additions and 18 deletions

View File

@ -572,8 +572,8 @@ void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
cost = -cost; cost = -cost;
msg = STR_INCOME_FLOAT_INCOME; msg = STR_INCOME_FLOAT_INCOME;
} }
SetDParam(0, cost);
AddTextEffect(msg, pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING); AddTextEffect(msg, MakeParameters(cost), pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
} }
/** /**
@ -588,17 +588,15 @@ void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income
{ {
Point pt = RemapCoords(x, y, z); Point pt = RemapCoords(x, y, z);
SetDParam(0, transfer);
if (income == 0) { if (income == 0) {
AddTextEffect(STR_FEEDER, pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING); AddTextEffect(STR_FEEDER, MakeParameters(transfer), pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
} else { } else {
StringID msg = STR_FEEDER_COST; StringID msg = STR_FEEDER_COST;
if (income < 0) { if (income < 0) {
income = -income; income = -income;
msg = STR_FEEDER_INCOME; msg = STR_FEEDER_INCOME;
} }
SetDParam(1, income); AddTextEffect(msg, MakeParameters(transfer, income), pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
AddTextEffect(msg, pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
} }
} }
@ -617,8 +615,7 @@ TextEffectID ShowFillingPercent(int x, int y, int z, uint8_t percent, StringID s
assert(string != STR_NULL); assert(string != STR_NULL);
SetDParam(0, percent); return AddTextEffect(string, MakeParameters(percent), pt.x, pt.y, 0, TE_STATIC);
return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC);
} }
/** /**
@ -630,8 +627,9 @@ void UpdateFillingPercent(TextEffectID te_id, uint8_t percent, StringID string)
{ {
assert(string != STR_NULL); assert(string != STR_NULL);
SetDParam(0, percent); auto params = MakeParameters(1);
UpdateTextEffect(te_id, string); params.SetParam(0, percent);
UpdateTextEffect(te_id, string, std::move(params));
} }
/** /**

View File

@ -38,7 +38,7 @@ struct TextEffect : public ViewportSign {
static std::vector<struct TextEffect> _text_effects; ///< Text effects are stored there static std::vector<struct TextEffect> _text_effects; ///< Text effects are stored there
/* Text Effects */ /* Text Effects */
TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, TextEffectMode mode) TextEffectID AddTextEffect(StringID msg, StringParameters &&params, int center, int y, uint8_t duration, TextEffectMode mode)
{ {
if (_game_mode == GM_MENU) return INVALID_TE_ID; if (_game_mode == GM_MENU) return INVALID_TE_ID;
@ -54,24 +54,25 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te
/* Start defining this object */ /* Start defining this object */
te.string_id = msg; te.string_id = msg;
te.duration = duration; te.duration = duration;
CopyOutDParam(te.params, 2); CopyOutDParam(te.params, std::move(params));
te.mode = mode; te.mode = mode;
/* Make sure we only dirty the new area */ /* Make sure we only dirty the new area */
te.width_normal = 0; te.width_normal = 0;
CopyInDParam(te.params);
te.UpdatePosition(center, y, msg); te.UpdatePosition(center, y, msg);
return static_cast<TextEffectID>(it - std::begin(_text_effects)); return static_cast<TextEffectID>(it - std::begin(_text_effects));
} }
void UpdateTextEffect(TextEffectID te_id, StringID msg) void UpdateTextEffect(TextEffectID te_id, StringID msg, StringParameters &&params)
{ {
/* Update details */ /* Update details */
TextEffect &te = _text_effects[te_id]; TextEffect &te = _text_effects[te_id];
if (msg == te.string_id && !HaveDParamChanged(te.params)) return;
te.string_id = msg; te.string_id = msg;
CopyOutDParam(te.params, 2); CopyOutDParam(te.params, std::move(params));
CopyInDParam(te.params);
te.UpdatePosition(te.center, te.top, te.string_id, te.string_id - 1); te.UpdatePosition(te.center, te.top, te.string_id, te.string_id - 1);
} }

View File

@ -26,10 +26,10 @@ using TextEffectID = uint16_t;
static const TextEffectID INVALID_TE_ID = UINT16_MAX; static const TextEffectID INVALID_TE_ID = UINT16_MAX;
TextEffectID AddTextEffect(StringID msg, int x, int y, uint8_t duration, TextEffectMode mode); TextEffectID AddTextEffect(StringID msg, class StringParameters &&params, int x, int y, uint8_t duration, TextEffectMode mode);
void InitTextEffects(); void InitTextEffects();
void DrawTextEffects(DrawPixelInfo *dpi); void DrawTextEffects(DrawPixelInfo *dpi);
void UpdateTextEffect(TextEffectID effect_id, StringID msg); void UpdateTextEffect(TextEffectID effect_id, StringID msg, StringParameters &&params);
void RemoveTextEffect(TextEffectID effect_id); void RemoveTextEffect(TextEffectID effect_id);
void UpdateAllTextEffectVirtCoords(); void UpdateAllTextEffectVirtCoords();

View File

@ -2899,7 +2899,8 @@ void CcStartStopVehicle(Commands, const CommandCost &result, VehicleID veh_id, b
StringID msg = (v->vehstatus & VS_STOPPED) ? STR_VEHICLE_COMMAND_STOPPED : STR_VEHICLE_COMMAND_STARTED; StringID msg = (v->vehstatus & VS_STOPPED) ? STR_VEHICLE_COMMAND_STOPPED : STR_VEHICLE_COMMAND_STARTED;
Point pt = RemapCoords(v->x_pos, v->y_pos, v->z_pos); Point pt = RemapCoords(v->x_pos, v->y_pos, v->z_pos);
AddTextEffect(msg, pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
AddTextEffect(msg, MakeParameters(), pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
} }
/** /**