2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file texteff.cpp Handling of text effects. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2007-06-21 16:17:47 +00:00
|
|
|
#include "texteff.hpp"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2009-12-25 23:15:08 +00:00
|
|
|
#include "core/smallvec_type.hpp"
|
2008-01-09 09:57:48 +00:00
|
|
|
#include "viewport_func.h"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-12-22 12:50:41 +00:00
|
|
|
/** Container for all information about a text effect */
|
2010-02-10 17:37:47 +00:00
|
|
|
struct TextEffect : public ViewportSign {
|
2009-12-22 12:50:41 +00:00
|
|
|
uint64 params_1; ///< DParam parameter
|
2009-12-25 23:22:41 +00:00
|
|
|
StringID string_id; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
|
|
|
|
uint8 duration; ///< How long the text effect should stay, in ticks (applies only when mode == TE_RISING)
|
2009-12-22 12:50:41 +00:00
|
|
|
TextEffectMode mode; ///< Type of text effect
|
|
|
|
|
|
|
|
/** Reset the text effect */
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
this->MarkDirty();
|
|
|
|
this->width_normal = 0;
|
|
|
|
this->string_id = INVALID_STRING_ID;
|
|
|
|
}
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-12-25 23:15:08 +00:00
|
|
|
static SmallVector<struct TextEffect, 32> _text_effects; ///< Text effects are stored there
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-09-09 10:13:17 +00:00
|
|
|
/* Text Effects */
|
2009-12-25 23:22:41 +00:00
|
|
|
TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, TextEffectMode mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-21 16:17:47 +00:00
|
|
|
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-12-25 23:15:08 +00:00
|
|
|
TextEffectID i;
|
|
|
|
for (i = 0; i < _text_effects.Length(); i++) {
|
|
|
|
if (_text_effects[i].string_id == INVALID_STRING_ID) break;
|
2007-06-21 16:17:47 +00:00
|
|
|
}
|
2009-12-25 23:15:08 +00:00
|
|
|
if (i == _text_effects.Length()) _text_effects.Append();
|
2007-06-21 16:17:47 +00:00
|
|
|
|
2009-12-25 23:15:08 +00:00
|
|
|
TextEffect *te = _text_effects.Get(i);
|
2007-06-21 16:17:47 +00:00
|
|
|
|
|
|
|
/* Start defining this object */
|
2004-08-09 17:04:08 +00:00
|
|
|
te->string_id = msg;
|
|
|
|
te->duration = duration;
|
2004-12-02 22:53:07 +00:00
|
|
|
te->params_1 = GetDParam(0);
|
2007-06-21 16:17:47 +00:00
|
|
|
te->mode = mode;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-12-22 12:50:41 +00:00
|
|
|
/* Make sure we only dirty the new area */
|
|
|
|
te->width_normal = 0;
|
|
|
|
te->UpdatePosition(center, y, msg);
|
2007-06-21 16:17:47 +00:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
|
|
|
{
|
|
|
|
/* Update details */
|
2009-12-25 23:15:08 +00:00
|
|
|
TextEffect *te = _text_effects.Get(te_id);
|
2007-06-21 16:17:47 +00:00
|
|
|
te->string_id = msg;
|
|
|
|
te->params_1 = GetDParam(0);
|
|
|
|
|
2009-12-22 12:50:41 +00:00
|
|
|
te->UpdatePosition(te->center, te->top, msg);
|
2007-06-21 16:17:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveTextEffect(TextEffectID te_id)
|
|
|
|
{
|
2009-12-25 23:15:08 +00:00
|
|
|
_text_effects[te_id].Reset();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void MoveAllTextEffects()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-12-25 23:15:08 +00:00
|
|
|
const TextEffect *end = _text_effects.End();
|
|
|
|
for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
|
2009-12-25 23:22:41 +00:00
|
|
|
if (te->string_id == INVALID_STRING_ID) continue;
|
|
|
|
if (te->mode != TE_RISING) continue;
|
|
|
|
|
|
|
|
if (te->duration-- == 0) {
|
|
|
|
te->Reset();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
te->MarkDirty();
|
|
|
|
te->top--;
|
|
|
|
te->MarkDirty();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitTextEffects()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-12-25 23:15:08 +00:00
|
|
|
_text_effects.Reset();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawTextEffects(DrawPixelInfo *dpi)
|
|
|
|
{
|
2009-12-22 12:50:41 +00:00
|
|
|
/* Don't draw the text effects when zoomed out a lot */
|
|
|
|
if (dpi->zoom > ZOOM_LVL_OUT_2X) return;
|
|
|
|
|
2009-12-25 23:15:08 +00:00
|
|
|
const TextEffect *end = _text_effects.End();
|
|
|
|
for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
|
2009-12-22 12:50:41 +00:00
|
|
|
if (te->string_id == INVALID_STRING_ID) continue;
|
|
|
|
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);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|