|
|
@ -17,13 +17,10 @@
|
|
|
|
#include "transparency.h"
|
|
|
|
#include "transparency.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "core/alloc_func.hpp"
|
|
|
|
#include "core/alloc_func.hpp"
|
|
|
|
|
|
|
|
#include "core/smallvec_type.hpp"
|
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "settings_type.h"
|
|
|
|
#include "settings_type.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
|
|
|
INIT_NUM_TEXT_EFFECTS = 20,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Container for all information about a text effect */
|
|
|
|
/** Container for all information about a text effect */
|
|
|
|
struct TextEffect : public ViewportSign{
|
|
|
|
struct TextEffect : public ViewportSign{
|
|
|
|
StringID string_id; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
|
|
|
|
StringID string_id; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
|
|
|
@ -40,31 +37,20 @@ struct TextEffect : public ViewportSign{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* used for text effects */
|
|
|
|
static SmallVector<struct TextEffect, 32> _text_effects; ///< Text effects are stored there
|
|
|
|
static TextEffect *_text_effect_list = NULL;
|
|
|
|
|
|
|
|
static uint16 _num_text_effects = INIT_NUM_TEXT_EFFECTS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Text Effects */
|
|
|
|
/* Text Effects */
|
|
|
|
TextEffectID AddTextEffect(StringID msg, int center, int y, uint16 duration, TextEffectMode mode)
|
|
|
|
TextEffectID AddTextEffect(StringID msg, int center, int y, uint16 duration, TextEffectMode mode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TextEffectID i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
|
|
|
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
|
|
|
|
|
|
|
|
|
|
|
/* Look for a free spot in the text effect array */
|
|
|
|
TextEffectID i;
|
|
|
|
for (i = 0; i < _num_text_effects; i++) {
|
|
|
|
for (i = 0; i < _text_effects.Length(); i++) {
|
|
|
|
if (_text_effect_list[i].string_id == INVALID_STRING_ID) break;
|
|
|
|
if (_text_effects[i].string_id == INVALID_STRING_ID) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* If there is none found, we grow the array */
|
|
|
|
|
|
|
|
if (i == _num_text_effects) {
|
|
|
|
|
|
|
|
_num_text_effects += 25;
|
|
|
|
|
|
|
|
_text_effect_list = ReallocT<TextEffect>(_text_effect_list, _num_text_effects);
|
|
|
|
|
|
|
|
for (; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
|
|
|
|
|
|
|
|
i = _num_text_effects - 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == _text_effects.Length()) _text_effects.Append();
|
|
|
|
|
|
|
|
|
|
|
|
TextEffect *te = &_text_effect_list[i];
|
|
|
|
TextEffect *te = _text_effects.Get(i);
|
|
|
|
|
|
|
|
|
|
|
|
/* Start defining this object */
|
|
|
|
/* Start defining this object */
|
|
|
|
te->string_id = msg;
|
|
|
|
te->string_id = msg;
|
|
|
@ -81,10 +67,8 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint16 duration, Tex
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
|
|
|
void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(te_id < _num_text_effects);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Update details */
|
|
|
|
/* Update details */
|
|
|
|
TextEffect *te = &_text_effect_list[te_id];
|
|
|
|
TextEffect *te = _text_effects.Get(te_id);
|
|
|
|
te->string_id = msg;
|
|
|
|
te->string_id = msg;
|
|
|
|
te->params_1 = GetDParam(0);
|
|
|
|
te->params_1 = GetDParam(0);
|
|
|
|
|
|
|
|
|
|
|
@ -93,8 +77,7 @@ void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
|
|
|
|
|
|
|
|
|
|
|
void RemoveTextEffect(TextEffectID te_id)
|
|
|
|
void RemoveTextEffect(TextEffectID te_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(te_id < _num_text_effects);
|
|
|
|
_text_effects[te_id].Reset();
|
|
|
|
_text_effect_list[te_id].Reset();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void MoveTextEffect(TextEffect *te)
|
|
|
|
static void MoveTextEffect(TextEffect *te)
|
|
|
@ -113,17 +96,15 @@ static void MoveTextEffect(TextEffect *te)
|
|
|
|
|
|
|
|
|
|
|
|
void MoveAllTextEffects()
|
|
|
|
void MoveAllTextEffects()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) {
|
|
|
|
const TextEffect *end = _text_effects.End();
|
|
|
|
TextEffect *te = &_text_effect_list[i];
|
|
|
|
for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
|
|
|
|
if (te->string_id != INVALID_STRING_ID && te->mode == TE_RISING) MoveTextEffect(te);
|
|
|
|
if (te->string_id != INVALID_STRING_ID && te->mode == TE_RISING) MoveTextEffect(te);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InitTextEffects()
|
|
|
|
void InitTextEffects()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_text_effect_list == NULL) _text_effect_list = MallocT<TextEffect>(_num_text_effects);
|
|
|
|
_text_effects.Reset();
|
|
|
|
|
|
|
|
|
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DrawTextEffects(DrawPixelInfo *dpi)
|
|
|
|
void DrawTextEffects(DrawPixelInfo *dpi)
|
|
|
@ -131,10 +112,9 @@ void DrawTextEffects(DrawPixelInfo *dpi)
|
|
|
|
/* Don't draw the text effects when zoomed out a lot */
|
|
|
|
/* Don't draw the text effects when zoomed out a lot */
|
|
|
|
if (dpi->zoom > ZOOM_LVL_OUT_2X) return;
|
|
|
|
if (dpi->zoom > ZOOM_LVL_OUT_2X) return;
|
|
|
|
|
|
|
|
|
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) {
|
|
|
|
const TextEffect *end = _text_effects.End();
|
|
|
|
const TextEffect *te = &_text_effect_list[i];
|
|
|
|
for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
|
|
|
|
if (te->string_id == INVALID_STRING_ID) continue;
|
|
|
|
if (te->string_id == INVALID_STRING_ID) continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
|
|
|
|
if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
|
|
|
|
ViewportAddString(dpi, ZOOM_LVL_OUT_2X, te, te->string_id, te->string_id - 1, 0, te->params_1);
|
|
|
|
ViewportAddString(dpi, ZOOM_LVL_OUT_2X, te, te->string_id, te->string_id - 1, 0, te->params_1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|