texteff.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "openttd.h"
00014 #include "strings_type.h"
00015 #include "texteff.hpp"
00016 #include "core/bitmath_func.hpp"
00017 #include "transparency.h"
00018 #include "strings_func.h"
00019 #include "core/alloc_func.hpp"
00020 #include "viewport_func.h"
00021 #include "settings_type.h"
00022
00023 enum {
00024 INIT_NUM_TEXT_EFFECTS = 20,
00025 };
00026
00028 struct TextEffect : public ViewportSign{
00029 StringID string_id;
00030 uint16 duration;
00031 uint64 params_1;
00032 TextEffectMode mode;
00033
00035 void Reset()
00036 {
00037 this->MarkDirty();
00038 this->width_normal = 0;
00039 this->string_id = INVALID_STRING_ID;
00040 }
00041 };
00042
00043
00044 static TextEffect *_text_effect_list = NULL;
00045 static uint16 _num_text_effects = INIT_NUM_TEXT_EFFECTS;
00046
00047
00048 TextEffectID AddTextEffect(StringID msg, int center, int y, uint16 duration, TextEffectMode mode)
00049 {
00050 TextEffectID i;
00051
00052 if (_game_mode == GM_MENU) return INVALID_TE_ID;
00053
00054
00055 for (i = 0; i < _num_text_effects; i++) {
00056 if (_text_effect_list[i].string_id == INVALID_STRING_ID) break;
00057 }
00058
00059
00060 if (i == _num_text_effects) {
00061 _num_text_effects += 25;
00062 _text_effect_list = ReallocT<TextEffect>(_text_effect_list, _num_text_effects);
00063 for (; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
00064 i = _num_text_effects - 1;
00065 }
00066
00067 TextEffect *te = &_text_effect_list[i];
00068
00069
00070 te->string_id = msg;
00071 te->duration = duration;
00072 te->params_1 = GetDParam(0);
00073 te->mode = mode;
00074
00075
00076 te->width_normal = 0;
00077 te->UpdatePosition(center, y, msg);
00078
00079 return i;
00080 }
00081
00082 void UpdateTextEffect(TextEffectID te_id, StringID msg)
00083 {
00084 assert(te_id < _num_text_effects);
00085
00086
00087 TextEffect *te = &_text_effect_list[te_id];
00088 te->string_id = msg;
00089 te->params_1 = GetDParam(0);
00090
00091 te->UpdatePosition(te->center, te->top, msg);
00092 }
00093
00094 void RemoveTextEffect(TextEffectID te_id)
00095 {
00096 assert(te_id < _num_text_effects);
00097 _text_effect_list[te_id].Reset();
00098 }
00099
00100 static void MoveTextEffect(TextEffect *te)
00101 {
00102
00103 if (te->duration == 0xFFFF) return;
00104 if (te->duration < 8) {
00105 te->Reset();
00106 } else {
00107 te->duration -= 8;
00108 te->MarkDirty();
00109 te->top--;
00110 te->MarkDirty();
00111 }
00112 }
00113
00114 void MoveAllTextEffects()
00115 {
00116 for (TextEffectID i = 0; i < _num_text_effects; i++) {
00117 TextEffect *te = &_text_effect_list[i];
00118 if (te->string_id != INVALID_STRING_ID && te->mode == TE_RISING) MoveTextEffect(te);
00119 }
00120 }
00121
00122 void InitTextEffects()
00123 {
00124 if (_text_effect_list == NULL) _text_effect_list = MallocT<TextEffect>(_num_text_effects);
00125
00126 for (TextEffectID i = 0; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
00127 }
00128
00129 void DrawTextEffects(DrawPixelInfo *dpi)
00130 {
00131
00132 if (dpi->zoom > ZOOM_LVL_OUT_2X) return;
00133
00134 for (TextEffectID i = 0; i < _num_text_effects; i++) {
00135 const TextEffect *te = &_text_effect_list[i];
00136 if (te->string_id == INVALID_STRING_ID) continue;
00137
00138 if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
00139 ViewportAddString(dpi, ZOOM_LVL_OUT_2X, te, te->string_id, te->string_id - 1, 0, te->params_1);
00140 }
00141 }
00142 }