2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 21:21:05 +01: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 16:11:33 +01:00
|
|
|
/** @file texteff.cpp Handling of text effects. */
|
2007-04-04 04:21:14 +01:00
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
#include "stdafx.h"
|
2005-06-02 20:30:21 +01:00
|
|
|
#include "openttd.h"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "strings_type.h"
|
2007-06-21 17:17:47 +01:00
|
|
|
#include "texteff.hpp"
|
2008-08-11 23:45:11 +01:00
|
|
|
#include "core/bitmath_func.hpp"
|
2007-11-10 01:17:15 +00:00
|
|
|
#include "transparency.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 09:48:53 +00:00
|
|
|
#include "core/alloc_func.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 18:04:08 +01:00
|
|
|
|
2006-12-30 00:46:48 +00:00
|
|
|
enum {
|
2008-08-11 23:45:11 +01:00
|
|
|
INIT_NUM_TEXT_EFFECTS = 20,
|
2006-12-30 00:46:48 +00:00
|
|
|
};
|
|
|
|
|
2009-12-22 12:50:41 +00:00
|
|
|
/** Container for all information about a text effect */
|
|
|
|
struct TextEffect : public ViewportSign{
|
|
|
|
StringID string_id; ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
|
|
|
|
uint16 duration; ///< How long the text effect should stay
|
|
|
|
uint64 params_1; ///< DParam parameter
|
|
|
|
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 18:04:08 +01:00
|
|
|
|
2007-08-19 10:38:30 +01:00
|
|
|
/* used for text effects */
|
2007-06-21 17:17:47 +01:00
|
|
|
static TextEffect *_text_effect_list = NULL;
|
2008-08-11 23:45:11 +01:00
|
|
|
static uint16 _num_text_effects = INIT_NUM_TEXT_EFFECTS;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-09-09 11:13:17 +01:00
|
|
|
/* Text Effects */
|
2009-12-22 12:50:41 +00:00
|
|
|
TextEffectID AddTextEffect(StringID msg, int center, int y, uint16 duration, TextEffectMode mode)
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-06-21 17:17:47 +01:00
|
|
|
TextEffectID i;
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-06-21 17:17:47 +01:00
|
|
|
if (_game_mode == GM_MENU) return INVALID_TE_ID;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2007-06-21 17:17:47 +01:00
|
|
|
/* Look for a free spot in the text effect array */
|
|
|
|
for (i = 0; i < _num_text_effects; i++) {
|
|
|
|
if (_text_effect_list[i].string_id == INVALID_STRING_ID) break;
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
2007-06-21 17:17:47 +01:00
|
|
|
/* If there is none found, we grow the array */
|
|
|
|
if (i == _num_text_effects) {
|
|
|
|
_num_text_effects += 25;
|
2007-12-08 14:50:41 +00:00
|
|
|
_text_effect_list = ReallocT<TextEffect>(_text_effect_list, _num_text_effects);
|
2007-06-21 17:17:47 +01:00
|
|
|
for (; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
|
|
|
|
i = _num_text_effects - 1;
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:50:41 +00:00
|
|
|
TextEffect *te = &_text_effect_list[i];
|
2007-06-21 17:17:47 +01:00
|
|
|
|
|
|
|
/* Start defining this object */
|
2004-08-09 18:04:08 +01:00
|
|
|
te->string_id = msg;
|
|
|
|
te->duration = duration;
|
2004-12-02 22:53:07 +00:00
|
|
|
te->params_1 = GetDParam(0);
|
2007-06-21 17:17:47 +01:00
|
|
|
te->mode = mode;
|
2004-08-09 18:04:08 +01: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 17:17:47 +01:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
|
|
|
{
|
|
|
|
assert(te_id < _num_text_effects);
|
|
|
|
|
|
|
|
/* Update details */
|
2009-12-22 12:50:41 +00:00
|
|
|
TextEffect *te = &_text_effect_list[te_id];
|
2007-06-21 17:17:47 +01: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 17:17:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveTextEffect(TextEffectID te_id)
|
|
|
|
{
|
|
|
|
assert(te_id < _num_text_effects);
|
2009-12-22 12:50:41 +00:00
|
|
|
_text_effect_list[te_id].Reset();
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MoveTextEffect(TextEffect *te)
|
|
|
|
{
|
2007-06-21 17:17:47 +01:00
|
|
|
/* Never expire for duration of 0xFFFF */
|
|
|
|
if (te->duration == 0xFFFF) return;
|
2004-08-09 18:04:08 +01:00
|
|
|
if (te->duration < 8) {
|
2009-12-22 12:50:41 +00:00
|
|
|
te->Reset();
|
2004-08-09 18:04:08 +01:00
|
|
|
} else {
|
2005-10-23 14:04:44 +01:00
|
|
|
te->duration -= 8;
|
2009-12-22 12:50:41 +00:00
|
|
|
te->MarkDirty();
|
|
|
|
te->top--;
|
|
|
|
te->MarkDirty();
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void MoveAllTextEffects()
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-06-21 17:17:47 +01:00
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) {
|
|
|
|
TextEffect *te = &_text_effect_list[i];
|
|
|
|
if (te->string_id != INVALID_STRING_ID && te->mode == TE_RISING) MoveTextEffect(te);
|
2004-08-09 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitTextEffects()
|
2004-08-09 18:04:08 +01:00
|
|
|
{
|
2007-06-21 17:17:47 +01:00
|
|
|
if (_text_effect_list == NULL) _text_effect_list = MallocT<TextEffect>(_num_text_effects);
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-06-21 17:17:47 +01:00
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) _text_effect_list[i].string_id = INVALID_STRING_ID;
|
2004-08-09 18:04:08 +01: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;
|
|
|
|
|
|
|
|
for (TextEffectID i = 0; i < _num_text_effects; i++) {
|
|
|
|
const TextEffect *te = &_text_effect_list[i];
|
|
|
|
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 18:04:08 +01:00
|
|
|
}
|
|
|
|
}
|