(svn r27953) -Cleanup: Adjust other languages for r27952
[openttd.git] / src / texteff.cpp
blobcdb8b8ce6a5b7e7d74037edfb23f6fa48564d214
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file texteff.cpp Handling of text effects. */
12 #include "stdafx.h"
13 #include "texteff.hpp"
14 #include "transparency.h"
15 #include "strings_func.h"
16 #include "core/smallvec_type.hpp"
17 #include "viewport_func.h"
18 #include "settings_type.h"
20 #include "safeguards.h"
22 /** Container for all information about a text effect */
23 struct TextEffect : public ViewportSign {
24 uint64 params_1; ///< DParam parameter
25 uint64 params_2; ///< second DParam parameter
26 StringID string_id; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
27 uint8 duration; ///< How long the text effect should stay, in ticks (applies only when mode == TE_RISING)
28 TextEffectMode mode; ///< Type of text effect
30 /** Reset the text effect */
31 void Reset()
33 this->MarkDirty();
34 this->width_normal = 0;
35 this->string_id = INVALID_STRING_ID;
39 static SmallVector<struct TextEffect, 32> _text_effects; ///< Text effects are stored there
41 /* Text Effects */
42 TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode)
44 if (_game_mode == GM_MENU) return INVALID_TE_ID;
46 TextEffectID i;
47 for (i = 0; i < _text_effects.Length(); i++) {
48 if (_text_effects[i].string_id == INVALID_STRING_ID) break;
50 if (i == _text_effects.Length()) _text_effects.Append();
52 TextEffect *te = _text_effects.Get(i);
54 /* Start defining this object */
55 te->string_id = msg;
56 te->duration = duration;
57 te->params_1 = GetDParam(0);
58 te->params_2 = GetDParam(1);
59 te->mode = mode;
61 /* Make sure we only dirty the new area */
62 te->width_normal = 0;
63 te->UpdatePosition(center, y, msg);
65 return i;
68 void UpdateTextEffect(TextEffectID te_id, StringID msg)
70 /* Update details */
71 TextEffect *te = _text_effects.Get(te_id);
72 if (msg == te->string_id && GetDParam(0) == te->params_1) return;
73 te->string_id = msg;
74 te->params_1 = GetDParam(0);
75 te->params_2 = GetDParam(1);
77 te->UpdatePosition(te->center, te->top, msg);
80 void RemoveTextEffect(TextEffectID te_id)
82 _text_effects[te_id].Reset();
85 void MoveAllTextEffects()
87 const TextEffect *end = _text_effects.End();
88 for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
89 if (te->string_id == INVALID_STRING_ID) continue;
90 if (te->mode != TE_RISING) continue;
92 if (te->duration-- == 0) {
93 te->Reset();
94 continue;
97 te->MarkDirty(ZOOM_LVL_OUT_8X);
98 te->top -= ZOOM_LVL_BASE;
99 te->MarkDirty(ZOOM_LVL_OUT_8X);
103 void InitTextEffects()
105 _text_effects.Reset();
108 void DrawTextEffects(DrawPixelInfo *dpi)
110 /* Don't draw the text effects when zoomed out a lot */
111 if (dpi->zoom > ZOOM_LVL_OUT_8X) return;
113 const TextEffect *end = _text_effects.End();
114 for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
115 if (te->string_id == INVALID_STRING_ID) continue;
116 if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
117 ViewportAddString(dpi, ZOOM_LVL_OUT_8X, te, te->string_id, te->string_id - 1, STR_NULL, te->params_1, te->params_2);