Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138465 additions and 70987 deletions

View File

@@ -11,19 +11,19 @@
#include "texteff.hpp"
#include "transparency.h"
#include "strings_func.h"
#include "core/smallvec_type.hpp"
#include "viewport_func.h"
#include "settings_type.h"
#include "guitimer_func.h"
#include "command_type.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "safeguards.h"
/** Container for all information about a text effect */
struct TextEffect : public ViewportSign {
uint64 params_1; ///< DParam parameter
uint64 params_2; ///< second DParam parameter
std::vector<StringParameterBackup> params; ///< Backup of string parameters
StringID string_id; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
uint8 duration; ///< How long the text effect should stay, in ticks (applies only when mode == TE_RISING)
uint8_t duration; ///< How long the text effect should stay, in ticks (applies only when mode == TE_RISING)
TextEffectMode mode; ///< Type of text effect
/** Reset the text effect */
@@ -38,50 +38,48 @@ struct TextEffect : public ViewportSign {
static std::vector<struct TextEffect> _text_effects; ///< Text effects are stored there
/* Text Effects */
TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode)
TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, TextEffectMode mode)
{
if (_game_mode == GM_MENU) return INVALID_TE_ID;
TextEffectID i;
for (i = 0; i < _text_effects.size(); i++) {
if (_text_effects[i].string_id == INVALID_STRING_ID) break;
auto it = std::find_if(std::begin(_text_effects), std::end(_text_effects), [](const TextEffect &te) { return te.string_id == INVALID_STRING_ID; });
if (it == std::end(_text_effects)) {
/* _text_effects.size() is the maximum ID + 1 that has been allocated. We should not allocate INVALID_TE_ID or beyond. */
if (_text_effects.size() >= INVALID_TE_ID) return INVALID_TE_ID;
it = _text_effects.emplace(std::end(_text_effects));
}
if (i == _text_effects.size()) _text_effects.emplace_back();
TextEffect &te = _text_effects[i];
TextEffect &te = *it;
/* Start defining this object */
te.string_id = msg;
te.duration = duration;
te.params_1 = GetDParam(0);
te.params_2 = GetDParam(1);
CopyOutDParam(te.params, 2);
te.mode = mode;
/* Make sure we only dirty the new area */
te.width_normal = 0;
te.UpdatePosition(center, y, msg);
return i;
return static_cast<TextEffectID>(it - std::begin(_text_effects));
}
void UpdateTextEffect(TextEffectID te_id, StringID msg)
{
/* Update details */
TextEffect *te = _text_effects.data() + te_id;
if (msg == te->string_id && GetDParam(0) == te->params_1) return;
te->string_id = msg;
te->params_1 = GetDParam(0);
te->params_2 = GetDParam(1);
TextEffect &te = _text_effects[te_id];
if (msg == te.string_id && !HaveDParamChanged(te.params)) return;
te.string_id = msg;
CopyOutDParam(te.params, 2);
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);
}
void UpdateAllTextEffectVirtCoords()
{
for (auto &te : _text_effects) {
if (te.string_id == INVALID_STRING_ID) continue;
SetDParam(0, te.params_1);
SetDParam(1, te.params_2);
CopyInDParam(te.params);
te.UpdatePosition(te.center, te.top, te.string_id, te.string_id - 1);
}
}
@@ -91,11 +89,9 @@ void RemoveTextEffect(TextEffectID te_id)
_text_effects[te_id].Reset();
}
void MoveAllTextEffects(uint delta_ms)
{
static GUITimer texteffecttimer = GUITimer(MILLISECONDS_PER_TICK);
uint count = texteffecttimer.CountElapsed(delta_ms);
if (count == 0) return;
/** Slowly move text effects upwards. */
IntervalTimer<TimerWindow> move_all_text_effects_interval = {std::chrono::milliseconds(30), [](uint count) {
if (_pause_mode && _game_mode != GM_EDITOR && _settings_game.construction.command_pause_level <= CMDPL_NO_CONSTRUCTION) return;
for (TextEffect &te : _text_effects) {
if (te.string_id == INVALID_STRING_ID) continue;
@@ -111,7 +107,7 @@ void MoveAllTextEffects(uint delta_ms)
te.top -= count * ZOOM_LVL_BASE;
te.MarkDirty(ZOOM_LVL_OUT_8X);
}
}
}};
void InitTextEffects()
{
@@ -123,11 +119,12 @@ void DrawTextEffects(DrawPixelInfo *dpi)
{
/* Don't draw the text effects when zoomed out a lot */
if (dpi->zoom > ZOOM_LVL_OUT_8X) return;
if (IsTransparencySet(TO_TEXT)) return;
for (TextEffect &te : _text_effects) {
if (te.string_id == INVALID_STRING_ID) continue;
if (te.mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
ViewportAddString(dpi, ZOOM_LVL_OUT_8X, &te, te.string_id, te.string_id - 1, STR_NULL, te.params_1, te.params_2);
if (te.mode == TE_RISING || _settings_client.gui.loading_indicators) {
CopyInDParam(te.params);
ViewportAddString(dpi, ZOOM_LVL_OUT_8X, &te, te.string_id, te.string_id - 1, STR_NULL);
}
}
}