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/>.
10 /** @file texteff.cpp Handling of text effects. */
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 /** Container for all information about a text effect */
21 struct TextEffect
: public ViewportSign
{
22 uint64 params_1
; ///< DParam parameter
23 uint64 params_2
; ///< second DParam parameter
24 StringID string_id
; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
25 uint8 duration
; ///< How long the text effect should stay, in ticks (applies only when mode == TE_RISING)
26 TextEffectMode mode
; ///< Type of text effect
28 /** Reset the text effect */
32 this->width_normal
= 0;
33 this->string_id
= INVALID_STRING_ID
;
37 static SmallVector
<struct TextEffect
, 32> _text_effects
; ///< Text effects are stored there
40 TextEffectID
AddTextEffect(StringID msg
, int center
, int y
, uint8 duration
, TextEffectMode mode
)
42 if (_game_mode
== GM_MENU
) return INVALID_TE_ID
;
45 for (i
= 0; i
< _text_effects
.Length(); i
++) {
46 if (_text_effects
[i
].string_id
== INVALID_STRING_ID
) break;
48 if (i
== _text_effects
.Length()) _text_effects
.Append();
50 TextEffect
*te
= _text_effects
.Get(i
);
52 /* Start defining this object */
54 te
->duration
= duration
;
55 te
->params_1
= GetDParam(0);
56 te
->params_2
= GetDParam(1);
59 /* Make sure we only dirty the new area */
61 te
->UpdatePosition(center
, y
, msg
);
66 void UpdateTextEffect(TextEffectID te_id
, StringID msg
)
69 TextEffect
*te
= _text_effects
.Get(te_id
);
70 if (msg
== te
->string_id
&& GetDParam(0) == te
->params_1
) return;
72 te
->params_1
= GetDParam(0);
73 te
->params_2
= GetDParam(1);
75 te
->UpdatePosition(te
->center
, te
->top
, msg
);
78 void RemoveTextEffect(TextEffectID te_id
)
80 _text_effects
[te_id
].Reset();
83 void MoveAllTextEffects()
85 const TextEffect
*end
= _text_effects
.End();
86 for (TextEffect
*te
= _text_effects
.Begin(); te
!= end
; te
++) {
87 if (te
->string_id
== INVALID_STRING_ID
) continue;
88 if (te
->mode
!= TE_RISING
) continue;
90 if (te
->duration
-- == 0) {
95 te
->MarkDirty(ZOOM_LVL_OUT_8X
);
96 te
->top
-= ZOOM_LVL_BASE
;
97 te
->MarkDirty(ZOOM_LVL_OUT_8X
);
101 void InitTextEffects()
103 _text_effects
.Reset();
106 void DrawTextEffects (BlitArea
*area
, DrawPixelInfo
*dpi
)
108 /* Don't draw the text effects when zoomed out a lot */
109 if (dpi
->zoom
> ZOOM_LVL_OUT_8X
) return;
111 const TextEffect
*end
= _text_effects
.End();
112 for (TextEffect
*te
= _text_effects
.Begin(); te
!= end
; te
++) {
113 if (te
->string_id
== INVALID_STRING_ID
) continue;
114 if (te
->mode
== TE_RISING
|| (_settings_client
.gui
.loading_indicators
&& !IsTransparencySet(TO_LOADING
))) {
115 ViewportAddString (area
, dpi
, ZOOM_LVL_OUT_8X
, te
, te
->string_id
, te
->string_id
- 1, STR_NULL
, te
->params_1
, te
->params_2
);