Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "texteff.hpp"
00014 #include "transparency.h"
00015 #include "strings_func.h"
00016 #include "core/smallvec_type.hpp"
00017 #include "viewport_func.h"
00018 #include "settings_type.h"
00019
00021 struct TextEffect : public ViewportSign {
00022 uint64 params_1;
00023 uint64 params_2;
00024 StringID string_id;
00025 uint8 duration;
00026 TextEffectMode mode;
00027
00029 void Reset()
00030 {
00031 this->MarkDirty();
00032 this->width_normal = 0;
00033 this->string_id = INVALID_STRING_ID;
00034 }
00035 };
00036
00037 static SmallVector<struct TextEffect, 32> _text_effects;
00038
00039
00040 TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode)
00041 {
00042 if (_game_mode == GM_MENU) return INVALID_TE_ID;
00043
00044 TextEffectID i;
00045 for (i = 0; i < _text_effects.Length(); i++) {
00046 if (_text_effects[i].string_id == INVALID_STRING_ID) break;
00047 }
00048 if (i == _text_effects.Length()) _text_effects.Append();
00049
00050 TextEffect *te = _text_effects.Get(i);
00051
00052
00053 te->string_id = msg;
00054 te->duration = duration;
00055 te->params_1 = GetDParam(0);
00056 te->params_2 = GetDParam(1);
00057 te->mode = mode;
00058
00059
00060 te->width_normal = 0;
00061 te->UpdatePosition(center, y, msg);
00062
00063 return i;
00064 }
00065
00066 void UpdateTextEffect(TextEffectID te_id, StringID msg)
00067 {
00068
00069 TextEffect *te = _text_effects.Get(te_id);
00070 te->string_id = msg;
00071 te->params_1 = GetDParam(0);
00072 te->params_2 = GetDParam(1);
00073
00074 te->UpdatePosition(te->center, te->top, msg);
00075 }
00076
00077 void RemoveTextEffect(TextEffectID te_id)
00078 {
00079 _text_effects[te_id].Reset();
00080 }
00081
00082 void MoveAllTextEffects()
00083 {
00084 const TextEffect *end = _text_effects.End();
00085 for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
00086 if (te->string_id == INVALID_STRING_ID) continue;
00087 if (te->mode != TE_RISING) continue;
00088
00089 if (te->duration-- == 0) {
00090 te->Reset();
00091 continue;
00092 }
00093
00094 te->MarkDirty();
00095 te->top -= ZOOM_LVL_BASE;
00096 te->MarkDirty();
00097 }
00098 }
00099
00100 void InitTextEffects()
00101 {
00102 _text_effects.Reset();
00103 }
00104
00105 void DrawTextEffects(DrawPixelInfo *dpi)
00106 {
00107
00108 if (dpi->zoom > ZOOM_LVL_OUT_8X) return;
00109
00110 const TextEffect *end = _text_effects.End();
00111 for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
00112 if (te->string_id == INVALID_STRING_ID) continue;
00113 if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
00114 ViewportAddString(dpi, ZOOM_LVL_OUT_8X, te, te->string_id, te->string_id - 1, 0, te->params_1, te->params_2);
00115 }
00116 }
00117 }