mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
4 Commits
93df734ce6
...
fa1c84b5a6
Author | SHA1 | Date |
---|---|---|
|
fa1c84b5a6 | |
|
03f5f7145f | |
|
0dc40877fd | |
|
f02b13d52b |
|
@ -500,6 +500,8 @@ add_files(
|
|||
textbuf_type.h
|
||||
texteff.cpp
|
||||
texteff.hpp
|
||||
texteff_cmd.cpp
|
||||
texteff_cmd.h
|
||||
textfile_gui.cpp
|
||||
textfile_gui.h
|
||||
textfile_type.h
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "station_cmd.h"
|
||||
#include "story_cmd.h"
|
||||
#include "subsidy_cmd.h"
|
||||
#include "texteff_cmd.h"
|
||||
#include "terraform_cmd.h"
|
||||
#include "timetable_cmd.h"
|
||||
#include "town_cmd.h"
|
||||
|
|
|
@ -372,6 +372,10 @@ enum Commands : uint8_t {
|
|||
CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE, ///< update the score of a league table element
|
||||
CMD_REMOVE_LEAGUE_TABLE_ELEMENT, ///< remove a league table element
|
||||
|
||||
CMD_CREATE_TEXT_EFFECT, ///< create a new text effect
|
||||
CMD_UPDATE_TEXT_EFFECT, ///< update text effect
|
||||
CMD_REMOVE_TEXT_EFFECT, ///< remove text effect
|
||||
|
||||
CMD_END, ///< Must ALWAYS be on the end of this list!! (period)
|
||||
};
|
||||
|
||||
|
|
|
@ -2369,7 +2369,7 @@ static bool ConFont(std::span<std::string_view> argv)
|
|||
FontCacheSubSetting *setting = GetFontCacheSubSetting(fs);
|
||||
/* Make sure all non sprite fonts are loaded. */
|
||||
if (!setting->font.empty() && !fc->HasParent()) {
|
||||
InitFontCache(fs == FS_MONO);
|
||||
InitFontCache(fs);
|
||||
fc = FontCache::Get(fs);
|
||||
}
|
||||
IConsolePrint(CC_DEFAULT, "{} font:", FontSizeToName(fs));
|
||||
|
|
|
@ -126,10 +126,10 @@ void SetFont(FontSize fontsize, const std::string &font, uint size)
|
|||
CheckForMissingGlyphs();
|
||||
_fcsettings = std::move(backup);
|
||||
} else {
|
||||
InitFontCache(true);
|
||||
InitFontCache(fontsize);
|
||||
}
|
||||
|
||||
LoadStringWidthTable(fontsize == FS_MONO);
|
||||
LoadStringWidthTable(fontsize);
|
||||
UpdateAllVirtCoords();
|
||||
ReInitAllWindows(true);
|
||||
|
||||
|
@ -213,15 +213,13 @@ std::string GetFontCacheFontName(FontSize fs)
|
|||
|
||||
/**
|
||||
* (Re)initialize the font cache related things, i.e. load the non-sprite fonts.
|
||||
* @param monospace Whether to initialise the monospace or regular fonts.
|
||||
* @param fontsizes Font sizes to be initialised.
|
||||
*/
|
||||
void InitFontCache(bool monospace)
|
||||
void InitFontCache(FontSizes fontsizes)
|
||||
{
|
||||
FontCache::InitializeFontCaches();
|
||||
|
||||
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
||||
if (monospace != (fs == FS_MONO)) continue;
|
||||
|
||||
for (FontSize fs : fontsizes) {
|
||||
FontCache *fc = FontCache::Get(fs);
|
||||
if (fc->HasParent()) delete fc;
|
||||
|
||||
|
|
|
@ -167,9 +167,9 @@ inline void InitializeUnicodeGlyphMap()
|
|||
}
|
||||
}
|
||||
|
||||
inline void ClearFontCache()
|
||||
inline void ClearFontCache(FontSizes fontsizes)
|
||||
{
|
||||
for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
|
||||
for (FontSize fs : fontsizes) {
|
||||
FontCache::Get(fs)->ClearFontCache();
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ inline FontCacheSubSetting *GetFontCacheSubSetting(FontSize fs)
|
|||
|
||||
uint GetFontCacheFontSize(FontSize fs);
|
||||
std::string GetFontCacheFontName(FontSize fs);
|
||||
void InitFontCache(bool monospace);
|
||||
void InitFontCache(FontSizes fontsizes);
|
||||
void UninitFontCache();
|
||||
|
||||
bool GetFontAAState();
|
||||
|
|
29
src/gfx.cpp
29
src/gfx.cpp
|
@ -8,6 +8,7 @@
|
|||
/** @file gfx.cpp Handling of drawing text and other gfx related stuff. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "gfx_func.h"
|
||||
#include "gfx_layout.h"
|
||||
#include "progress.h"
|
||||
#include "zoom_func.h"
|
||||
|
@ -579,7 +580,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
|
|||
|
||||
const uint shadow_offset = ScaleGUITrad(1);
|
||||
|
||||
auto draw_line = [&](const ParagraphLayouter::Line &line, bool do_shadow, int left, int min_x, int max_x, bool truncation) {
|
||||
auto draw_line = [&](const ParagraphLayouter::Line &line, bool do_shadow, int left, int min_x, int max_x, bool truncation, TextColour &last_colour) {
|
||||
const DrawPixelInfo *dpi = _cur_dpi;
|
||||
int dpi_left = dpi->left;
|
||||
int dpi_right = dpi->left + dpi->width - 1;
|
||||
|
@ -592,10 +593,15 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
|
|||
|
||||
FontCache *fc = f->fc;
|
||||
TextColour colour = f->colour;
|
||||
if (colour == TC_INVALID || HasFlag(default_colour, TC_FORCED)) colour = default_colour;
|
||||
if (colour == TC_INVALID || HasFlag(last_colour, TC_FORCED)) {
|
||||
colour = last_colour;
|
||||
} else {
|
||||
/* Update the last colour for the truncation ellipsis. */
|
||||
last_colour = colour;
|
||||
}
|
||||
bool colour_has_shadow = (colour & TC_NO_SHADE) == 0 && colour != TC_BLACK;
|
||||
SetColourRemap(do_shadow ? TC_BLACK : colour); // the last run also sets the colour for the truncation dots
|
||||
if (do_shadow && (!fc->GetDrawGlyphShadow() || !colour_has_shadow)) continue;
|
||||
SetColourRemap(do_shadow ? TC_BLACK : colour);
|
||||
|
||||
for (int i = 0; i < run.GetGlyphCount(); i++) {
|
||||
GlyphID glyph = glyphs[i];
|
||||
|
@ -623,11 +629,12 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left,
|
|||
|
||||
/* Draw shadow, then foreground */
|
||||
for (bool do_shadow : {true, false}) {
|
||||
draw_line(line, do_shadow, left - offset_x, min_x, max_x, truncation);
|
||||
TextColour last_colour = default_colour;
|
||||
draw_line(line, do_shadow, left - offset_x, min_x, max_x, truncation, last_colour);
|
||||
|
||||
if (truncation) {
|
||||
int x = (_current_text_dir == TD_RTL) ? left : (right - truncation_width);
|
||||
draw_line(*truncation_layout->front(), do_shadow, x, INT32_MIN, INT32_MAX, false);
|
||||
draw_line(*truncation_layout->front(), do_shadow, x, INT32_MIN, INT32_MAX, false, last_colour);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1240,14 +1247,14 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode,
|
|||
}
|
||||
|
||||
/**
|
||||
* Initialize _stringwidth_table cache
|
||||
* @param monospace Whether to load the monospace cache or the normal fonts.
|
||||
* Initialize _stringwidth_table cache for the specified font sizes.
|
||||
* @param fontsizes Font sizes to initialise.
|
||||
*/
|
||||
void LoadStringWidthTable(bool monospace)
|
||||
void LoadStringWidthTable(FontSizes fontsizes)
|
||||
{
|
||||
ClearFontCache();
|
||||
ClearFontCache(fontsizes);
|
||||
|
||||
for (FontSize fs = monospace ? FS_MONO : FS_BEGIN; fs < (monospace ? FS_END : FS_MONO); fs++) {
|
||||
for (FontSize fs : fontsizes) {
|
||||
for (uint i = 0; i != 224; i++) {
|
||||
_stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32);
|
||||
}
|
||||
|
@ -1812,7 +1819,7 @@ bool AdjustGUIZoom(bool automatic)
|
|||
if (old_font_zoom != _font_zoom) {
|
||||
GfxClearFontSpriteCache();
|
||||
}
|
||||
ClearFontCache();
|
||||
ClearFontCache(FONTSIZES_ALL);
|
||||
LoadStringWidthTable();
|
||||
|
||||
SetupWidgetDimensions();
|
||||
|
|
|
@ -149,7 +149,7 @@ int GetStringHeight(StringID str, int maxw);
|
|||
int GetStringLineCount(std::string_view str, int maxw);
|
||||
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion);
|
||||
Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion, FontSize fontsize = FS_NORMAL);
|
||||
void LoadStringWidthTable(bool monospace = false);
|
||||
void LoadStringWidthTable(FontSizes fontsizes = FONTSIZES_REQUIRED);
|
||||
|
||||
void DrawDirtyBlocks();
|
||||
void AddDirtyBlock(int left, int top, int right, int bottom);
|
||||
|
|
|
@ -258,6 +258,13 @@ enum FontSize : uint8_t {
|
|||
};
|
||||
DECLARE_INCREMENT_DECREMENT_OPERATORS(FontSize)
|
||||
|
||||
using FontSizes = EnumBitSet<FontSize, uint8_t>;
|
||||
|
||||
/** Mask of all possible font sizes. */
|
||||
constexpr FontSizes FONTSIZES_ALL{FS_NORMAL, FS_SMALL, FS_LARGE, FS_MONO};
|
||||
/** Mask of font sizes required to be present. */
|
||||
constexpr FontSizes FONTSIZES_REQUIRED{FS_NORMAL, FS_SMALL, FS_LARGE};
|
||||
|
||||
inline std::string_view FontSizeToName(FontSize fs)
|
||||
{
|
||||
static const std::string_view SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };
|
||||
|
|
|
@ -245,7 +245,7 @@ static void RealChangeBlitter(std::string_view repl_blitter)
|
|||
|
||||
/* Clear caches that might have sprites for another blitter. */
|
||||
VideoDriver::GetInstance()->ClearSystemSprites();
|
||||
ClearFontCache();
|
||||
ClearFontCache(FONTSIZES_ALL);
|
||||
GfxClearSpriteCache();
|
||||
ReInitAllWindows(false);
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ void CheckBlitter()
|
|||
{
|
||||
if (!SwitchNewGRFBlitter()) return;
|
||||
|
||||
ClearFontCache();
|
||||
ClearFontCache(FONTSIZES_ALL);
|
||||
GfxClearSpriteCache();
|
||||
ReInitAllWindows(false);
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ void GfxLoadSprites()
|
|||
|
||||
SwitchNewGRFBlitter();
|
||||
VideoDriver::GetInstance()->ClearSystemSprites();
|
||||
ClearFontCache();
|
||||
ClearFontCache(FONTSIZES_ALL);
|
||||
GfxInitSpriteMem();
|
||||
LoadSpriteTables();
|
||||
GfxInitPalettes();
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "../station_cmd.h"
|
||||
#include "../story_cmd.h"
|
||||
#include "../subsidy_cmd.h"
|
||||
#include "../texteff_cmd.h"
|
||||
#include "../terraform_cmd.h"
|
||||
#include "../timetable_cmd.h"
|
||||
#include "../town_cmd.h"
|
||||
|
|
|
@ -700,7 +700,7 @@ int openttd_main(std::span<std::string_view> arguments)
|
|||
InitializeLanguagePacks();
|
||||
|
||||
/* Initialize the font cache */
|
||||
InitFontCache(false);
|
||||
InitFontCache(FONTSIZES_REQUIRED);
|
||||
|
||||
/* This must be done early, since functions use the SetWindowDirty* calls */
|
||||
InitWindowSystem();
|
||||
|
|
|
@ -182,6 +182,6 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
|||
if (best_font == nullptr) return false;
|
||||
|
||||
callback->SetFontNames(settings, best_font, &best_index);
|
||||
InitFontCache(callback->Monospace());
|
||||
InitFontCache(callback->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -206,6 +206,7 @@ add_files(
|
|||
script_subsidylist.hpp
|
||||
script_testmode.hpp
|
||||
script_text.hpp
|
||||
script_text_effect.hpp
|
||||
script_tile.hpp
|
||||
script_tilelist.hpp
|
||||
script_town.hpp
|
||||
|
@ -278,6 +279,7 @@ add_files(
|
|||
script_subsidylist.cpp
|
||||
script_testmode.cpp
|
||||
script_text.cpp
|
||||
script_text_effect.cpp
|
||||
script_tile.cpp
|
||||
script_tilelist.cpp
|
||||
script_town.cpp
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/** @file script_text_effect.cpp Implementation of ScriptTextEffect with multiplayer support. */
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_text_effect.hpp"
|
||||
#include "script_error.hpp"
|
||||
#include "script_map.hpp"
|
||||
#include "../script_instance.hpp"
|
||||
#include "../../texteff.hpp"
|
||||
#include "../../strings_func.h"
|
||||
#include "../../tile_map.h"
|
||||
#include "../../command_func.h"
|
||||
#include "../../texteff_cmd.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
/* static */ TextEffectID ScriptTextEffect::CreateAtPosition(SQInteger x, SQInteger y, Text *text, ScriptTextEffectMode mode)
|
||||
{
|
||||
ScriptObjectRef counter(text);
|
||||
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, text != nullptr);
|
||||
EnforcePrecondition(false, !text->GetEncodedText().empty());
|
||||
EnforcePrecondition(false, mode == TE_RISING || mode == TE_STATIC);
|
||||
|
||||
return ScriptObject::Command<CMD_CREATE_TEXT_EFFECT>::Do(&ScriptInstance::DoCommandReturnTextEffectID, x, y, (TextEffectMode)mode, text->GetEncodedText());
|
||||
}
|
||||
|
||||
/* static */ TextEffectID ScriptTextEffect::Create(TileIndex tile, Text *text, ScriptTextEffectMode mode)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
|
||||
|
||||
int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
|
||||
int y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
|
||||
|
||||
return CreateAtPosition(x, y, text, mode);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptTextEffect::Update(TextEffectID te_id, Text *text)
|
||||
{
|
||||
ScriptObjectRef counter(text);
|
||||
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, te_id != INVALID_TE_ID);
|
||||
EnforcePrecondition(false, text != nullptr);
|
||||
EnforcePrecondition(false, !text->GetEncodedText().empty());
|
||||
|
||||
return ScriptObject::Command<CMD_UPDATE_TEXT_EFFECT>::Do(te_id, text->GetEncodedText());
|
||||
}
|
||||
|
||||
/* static */ bool ScriptTextEffect::Remove(TextEffectID te_id)
|
||||
{
|
||||
EnforceDeityMode(false);
|
||||
EnforcePrecondition(false, te_id != INVALID_TE_ID);
|
||||
|
||||
return ScriptObject::Command<CMD_REMOVE_TEXT_EFFECT>::Do(te_id);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/** @file script_text_effect.hpp Everything to display animated text in the game world. */
|
||||
|
||||
#ifndef SCRIPT_TEXT_EFFECT_HPP
|
||||
#define SCRIPT_TEXT_EFFECT_HPP
|
||||
|
||||
#include "script_object.hpp"
|
||||
#include "script_text.hpp"
|
||||
#include "../../texteff.hpp"
|
||||
|
||||
/**
|
||||
* Class that handles text effect display in the game world.
|
||||
* @api game
|
||||
*/
|
||||
class ScriptTextEffect : public ScriptObject {
|
||||
public:
|
||||
/**
|
||||
* Text effect animation modes.
|
||||
*/
|
||||
enum ScriptTextEffectMode {
|
||||
TE_RISING = ::TE_RISING, ///< Text slowly rises upwards
|
||||
TE_STATIC = ::TE_STATIC, ///< Text stays in place
|
||||
};
|
||||
|
||||
/**
|
||||
* Create animated text at a tile location.
|
||||
* @param tile The tile where to show the text.
|
||||
* @param text The text to display.
|
||||
* @param mode The animation mode to use.
|
||||
* @return True if the text effect was created successfully.
|
||||
*/
|
||||
static TextEffectID Create(TileIndex tile, Text *text, ScriptTextEffectMode mode);
|
||||
|
||||
/**
|
||||
* Create animated text at the specified location.
|
||||
* @param x X coordinate in the game world.
|
||||
* @param y Y coordinate in the game world.
|
||||
* @param text The text to display.
|
||||
* @param mode The animation mode to use.
|
||||
* @return True if the text effect was created successfully.
|
||||
*/
|
||||
static TextEffectID CreateAtPosition(SQInteger x, SQInteger y, Text *text, ScriptTextEffectMode mode);
|
||||
|
||||
/**
|
||||
* Update animated text
|
||||
* @param te_id Text effect ID.
|
||||
* @param text The text to update
|
||||
* @return True if the text effect was updated successfully
|
||||
*/
|
||||
static bool Update(TextEffectID te_id, Text *text);
|
||||
|
||||
/**
|
||||
* Update animated text
|
||||
* @param te_id Text effect ID.
|
||||
* @return True if the text effect was removed successfully
|
||||
*/
|
||||
static bool Remove(TextEffectID te_id);
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_TEXT_EFFECT_HPP */
|
|
@ -31,6 +31,7 @@
|
|||
#include "../signs_type.h"
|
||||
#include "../story_type.h"
|
||||
#include "../misc/endian_buffer.hpp"
|
||||
#include "../texteff.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
|
@ -329,6 +330,10 @@ void ScriptInstance::CollectGarbage()
|
|||
instance.engine->InsertResult(EndianBufferReader::ToValue<LeagueTableID>(ScriptObject::GetLastCommandResData()));
|
||||
}
|
||||
|
||||
/* static */ void ScriptInstance::DoCommandReturnTextEffectID(ScriptInstance *instance)
|
||||
{
|
||||
instance->engine->InsertResult(EndianBufferReader::ToValue<TextEffectID>(ScriptObject::GetLastCommandResData()));
|
||||
}
|
||||
|
||||
ScriptStorage &ScriptInstance::GetStorage()
|
||||
{
|
||||
|
|
|
@ -143,6 +143,11 @@ public:
|
|||
*/
|
||||
static void DoCommandReturnLeagueTableElementID(ScriptInstance &instance);
|
||||
|
||||
/**
|
||||
* Return a TextEffectID reply for a DoCommand.
|
||||
*/
|
||||
static void DoCommandReturnTextEffectID(ScriptInstance *instance);
|
||||
|
||||
/**
|
||||
* Get the controller attached to the instance.
|
||||
*/
|
||||
|
|
|
@ -1036,9 +1036,8 @@ struct GameOptionsWindow : Window {
|
|||
this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
|
||||
this->SetDirty();
|
||||
|
||||
InitFontCache(false);
|
||||
InitFontCache(true);
|
||||
ClearFontCache();
|
||||
InitFontCache(FONTSIZES_ALL);
|
||||
ClearFontCache(FONTSIZES_ALL);
|
||||
CheckForMissingGlyphs();
|
||||
SetupWidgetDimensions();
|
||||
UpdateAllVirtCoords();
|
||||
|
@ -1051,7 +1050,7 @@ struct GameOptionsWindow : Window {
|
|||
this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
|
||||
MarkWholeScreenDirty();
|
||||
|
||||
ClearFontCache();
|
||||
ClearFontCache(FONTSIZES_ALL);
|
||||
break;
|
||||
#endif /* HAS_TRUETYPE_FONT */
|
||||
|
||||
|
|
|
@ -2278,7 +2278,7 @@ std::string_view GetCurrentLanguageIsoCode()
|
|||
*/
|
||||
bool MissingGlyphSearcher::FindMissingGlyphs()
|
||||
{
|
||||
InitFontCache(this->Monospace());
|
||||
InitFontCache(this->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
|
||||
|
||||
this->Reset();
|
||||
for (auto text = this->NextString(); text.has_value(); text = this->NextString()) {
|
||||
|
@ -2395,7 +2395,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
|
|||
/* Our fallback font does miss characters too, so keep the
|
||||
* user chosen font as that is more likely to be any good than
|
||||
* the wild guess we made */
|
||||
InitFontCache(searcher->Monospace());
|
||||
InitFontCache(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -2412,12 +2412,12 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
|
|||
ShowErrorMessage(GetEncodedString(STR_JUST_RAW_STRING, std::move(err_str)), {}, WL_WARNING);
|
||||
|
||||
/* Reset the font width */
|
||||
LoadStringWidthTable(searcher->Monospace());
|
||||
LoadStringWidthTable(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Update the font with cache */
|
||||
LoadStringWidthTable(searcher->Monospace());
|
||||
LoadStringWidthTable(searcher->Monospace() ? FontSizes{FS_MONO} : FONTSIZES_REQUIRED);
|
||||
|
||||
#if !(defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ)) && !defined(WITH_UNISCRIBE) && !defined(WITH_COCOA)
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/** @file texteff_cmd.cpp Command handling for text effects */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "command_func.h"
|
||||
#include "texteff.hpp"
|
||||
#include "strings_func.h"
|
||||
#include "tile_map.h"
|
||||
#include "texteff_cmd.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
#include "landscape.h"
|
||||
|
||||
/**
|
||||
* Show a text effect at the specified location.
|
||||
* @param flags operation to perform
|
||||
* @param x X coordinate in the game
|
||||
* @param y Y coordinate in the game
|
||||
* @param mode The animation mode to use
|
||||
* @param text The text to display
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
std::tuple<CommandCost, TextEffectID> CmdCreateTextEffect(DoCommandFlags flags, int32_t x, int32_t y, TextEffectMode mode, const EncodedString &text)
|
||||
{
|
||||
if (text.empty()) return { CMD_ERROR, INVALID_TE_ID };
|
||||
if (mode != TE_RISING && mode != TE_STATIC) return { CMD_ERROR, INVALID_TE_ID };
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
Point pt = RemapCoords2(x, y);
|
||||
EncodedString encoded_text = text;
|
||||
TextEffectID te_id;
|
||||
|
||||
if (mode == TE_RISING) {
|
||||
te_id = AddTextEffect(std::move(encoded_text), pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
|
||||
} else {
|
||||
te_id = AddTextEffect(std::move(encoded_text), pt.x, pt.y, 0, TE_STATIC);
|
||||
}
|
||||
|
||||
return { CommandCost(), te_id };
|
||||
}
|
||||
|
||||
return { CommandCost(), INVALID_TE_ID };
|
||||
}
|
||||
|
||||
CommandCost CmdUpdateTextEffect(DoCommandFlags flags, TextEffectID te_id, const EncodedString &text)
|
||||
{
|
||||
if (te_id == INVALID_TE_ID) return CMD_ERROR;
|
||||
if (text.empty()) return CMD_ERROR;
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
EncodedString encoded_text = text;
|
||||
UpdateTextEffect(te_id, std::move(encoded_text));
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
CommandCost CmdRemoveTextEffect(DoCommandFlags flags, TextEffectID te_id)
|
||||
{
|
||||
if (te_id == INVALID_TE_ID) return CMD_ERROR;
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
RemoveTextEffect(te_id);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/** @file texteff_cmd.h Command declarations for text effects */
|
||||
|
||||
#ifndef TEXTEFF_CMD_H
|
||||
#define TEXTEFF_CMD_H
|
||||
|
||||
#include "command_type.h"
|
||||
#include "texteff.hpp"
|
||||
|
||||
std::tuple<CommandCost, TextEffectID> CmdCreateTextEffect(DoCommandFlags flags, int32_t x, int32_t y, TextEffectMode mode, const EncodedString &text);
|
||||
CommandCost CmdUpdateTextEffect(DoCommandFlags flags, TextEffectID te_id, const EncodedString &text);
|
||||
CommandCost CmdRemoveTextEffect(DoCommandFlags flags, TextEffectID te_id);
|
||||
|
||||
DEF_CMD_TRAIT(CMD_CREATE_TEXT_EFFECT, CmdCreateTextEffect, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT)
|
||||
DEF_CMD_TRAIT(CMD_UPDATE_TEXT_EFFECT, CmdUpdateTextEffect, CommandFlags({CommandFlag::Deity, CommandFlag::StrCtrl}), CMDT_OTHER_MANAGEMENT)
|
||||
DEF_CMD_TRAIT(CMD_REMOVE_TEXT_EFFECT, CmdRemoveTextEffect, CommandFlag::Deity, CMDT_OTHER_MANAGEMENT)
|
||||
|
||||
#endif /* TEXTEFF_CMD_H */
|
Loading…
Reference in New Issue