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/>.
|
|
|
|
*/
|
|
|
|
|
2007-12-21 19:49:27 +00:00
|
|
|
/** @file strings_func.h Functions related to OTTD's strings. */
|
2007-04-04 01:35:16 +00:00
|
|
|
|
2007-12-21 19:49:27 +00:00
|
|
|
#ifndef STRINGS_FUNC_H
|
|
|
|
#define STRINGS_FUNC_H
|
|
|
|
|
|
|
|
#include "strings_type.h"
|
2010-12-09 20:57:52 +00:00
|
|
|
#include "string_type.h"
|
2011-11-19 18:43:00 +00:00
|
|
|
#include "gfx_type.h"
|
2017-02-26 19:39:58 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
2023-06-21 04:35:06 +00:00
|
|
|
#include "core/span_type.hpp"
|
2023-08-12 18:14:21 +00:00
|
|
|
#include "core/strong_typedef_type.hpp"
|
2023-04-08 16:26:13 +00:00
|
|
|
#include "vehicle_type.h"
|
2017-02-26 19:39:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the StringTab from a StringID.
|
|
|
|
* @param str String identifier
|
|
|
|
* @return StringTab from \a str
|
|
|
|
*/
|
2017-02-26 19:40:53 +00:00
|
|
|
static inline StringTab GetStringTab(StringID str)
|
2017-02-26 19:39:58 +00:00
|
|
|
{
|
2017-02-26 19:41:30 +00:00
|
|
|
StringTab result = (StringTab)(str >> TAB_SIZE_BITS);
|
|
|
|
if (result >= TEXT_TAB_NEWGRF_START) return TEXT_TAB_NEWGRF_START;
|
|
|
|
if (result >= TEXT_TAB_GAMESCRIPT_START) return TEXT_TAB_GAMESCRIPT_START;
|
|
|
|
return result;
|
2017-02-26 19:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the StringIndex from a StringID.
|
|
|
|
* @param str String identifier
|
|
|
|
* @return StringIndex from \a str
|
|
|
|
*/
|
|
|
|
static inline uint GetStringIndex(StringID str)
|
|
|
|
{
|
2017-02-26 19:41:30 +00:00
|
|
|
return str - (GetStringTab(str) << TAB_SIZE_BITS);
|
2017-02-26 19:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a StringID
|
|
|
|
* @param tab StringTab
|
|
|
|
* @param index StringIndex
|
|
|
|
* @return StringID composed from \a tab and \a index
|
|
|
|
*/
|
2017-02-26 19:40:53 +00:00
|
|
|
static inline StringID MakeStringID(StringTab tab, uint index)
|
2017-02-26 19:39:58 +00:00
|
|
|
{
|
2017-02-26 19:41:30 +00:00
|
|
|
if (tab == TEXT_TAB_NEWGRF_START) {
|
|
|
|
assert(index < TAB_SIZE_NEWGRF);
|
|
|
|
} else if (tab == TEXT_TAB_GAMESCRIPT_START) {
|
|
|
|
assert(index < TAB_SIZE_GAMESCRIPT);
|
|
|
|
} else {
|
|
|
|
assert(tab < TEXT_TAB_END);
|
|
|
|
assert(index < TAB_SIZE);
|
|
|
|
}
|
|
|
|
return (tab << TAB_SIZE_BITS) + index;
|
2017-02-26 19:39:58 +00:00
|
|
|
}
|
2005-02-06 08:18:00 +00:00
|
|
|
|
2021-05-14 16:32:58 +00:00
|
|
|
std::string GetString(StringID string);
|
2008-01-29 17:09:00 +00:00
|
|
|
const char *GetStringPtr(StringID string);
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2023-04-08 16:26:13 +00:00
|
|
|
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type);
|
|
|
|
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
|
|
|
|
* @param speed Display speed for parameter.
|
|
|
|
* @param type Type of vehicle for parameter.
|
|
|
|
* @return Bit-packed velocity and vehicle type, for use with SetDParam().
|
|
|
|
*/
|
2023-05-08 17:01:06 +00:00
|
|
|
static inline int64_t PackVelocity(uint speed, VehicleType type)
|
2023-04-08 16:26:13 +00:00
|
|
|
{
|
|
|
|
/* Vehicle type is a byte, so packed into the top 8 bits of the 64-bit
|
|
|
|
* parameter, although only values from 0-3 are relevant. */
|
2023-05-08 17:01:06 +00:00
|
|
|
return speed | (static_cast<uint64_t>(type) << 56);
|
2023-04-08 16:26:13 +00:00
|
|
|
}
|
2012-02-14 17:03:56 +00:00
|
|
|
|
2023-06-18 05:35:30 +00:00
|
|
|
void SetDParam(size_t n, uint64_t v);
|
|
|
|
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL);
|
|
|
|
void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL);
|
2012-12-08 17:18:51 +00:00
|
|
|
|
2023-08-12 18:14:21 +00:00
|
|
|
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
|
|
|
void SetDParam(size_t n, T v)
|
|
|
|
{
|
2023-11-06 20:29:35 +00:00
|
|
|
SetDParam(n, v.base());
|
2023-08-12 18:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
|
|
|
void SetDParamMaxValue(size_t n, T max_value, uint min_count = 0, FontSize size = FS_NORMAL)
|
|
|
|
{
|
2023-11-06 20:29:35 +00:00
|
|
|
SetDParamMaxValue(n, max_value.base(), min_count, size);
|
2023-08-12 18:14:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-18 05:35:30 +00:00
|
|
|
void SetDParamStr(size_t n, const char *str);
|
|
|
|
void SetDParamStr(size_t n, const std::string &str);
|
2023-06-27 14:59:44 +00:00
|
|
|
void SetDParamStr(size_t n, std::string &&str);
|
2007-07-16 09:16:58 +00:00
|
|
|
|
2023-06-21 04:35:06 +00:00
|
|
|
void CopyInDParam(const span<const StringParameterBackup> backup);
|
|
|
|
void CopyOutDParam(std::vector<StringParameterBackup> &backup, size_t num);
|
2023-06-25 04:26:37 +00:00
|
|
|
bool HaveDParamChanged(const std::vector<StringParameterBackup> &backup);
|
2023-06-21 04:35:06 +00:00
|
|
|
|
2023-06-18 05:35:30 +00:00
|
|
|
uint64_t GetDParam(size_t n);
|
2007-07-16 09:16:58 +00:00
|
|
|
|
2010-11-13 09:56:25 +00:00
|
|
|
extern TextDirection _current_text_dir; ///< Text direction of the currently selected language
|
2005-02-06 08:18:00 +00:00
|
|
|
|
2007-03-17 22:21:05 +00:00
|
|
|
void InitializeLanguagePacks();
|
2009-10-17 20:34:09 +00:00
|
|
|
const char *GetCurrentLanguageIsoCode();
|
2007-03-17 22:21:05 +00:00
|
|
|
|
2011-11-19 18:43:00 +00:00
|
|
|
/**
|
|
|
|
* A searcher for missing glyphs.
|
|
|
|
*/
|
|
|
|
class MissingGlyphSearcher {
|
|
|
|
public:
|
|
|
|
/** Make sure everything gets destructed right. */
|
2023-05-14 21:31:03 +00:00
|
|
|
virtual ~MissingGlyphSearcher() = default;
|
2011-11-19 18:43:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next string to search through.
|
2023-05-09 19:35:50 +00:00
|
|
|
* @return The next string or nullopt if there is none.
|
2011-11-19 18:43:00 +00:00
|
|
|
*/
|
2023-05-09 19:35:50 +00:00
|
|
|
virtual std::optional<std::string_view> NextString() = 0;
|
2011-11-19 18:43:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the default (font) size of the string.
|
|
|
|
* @return The font size.
|
|
|
|
*/
|
|
|
|
virtual FontSize DefaultSize() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the search, i.e. begin from the beginning again.
|
|
|
|
*/
|
|
|
|
virtual void Reset() = 0;
|
|
|
|
|
2011-11-20 12:01:42 +00:00
|
|
|
/**
|
|
|
|
* Whether to search for a monospace font or not.
|
|
|
|
* @return True if searching for monospace.
|
|
|
|
*/
|
|
|
|
virtual bool Monospace() = 0;
|
|
|
|
|
2011-11-19 21:02:37 +00:00
|
|
|
/**
|
|
|
|
* Set the right font names.
|
|
|
|
* @param settings The settings to modify.
|
|
|
|
* @param font_name The new font name.
|
2018-11-25 01:02:20 +00:00
|
|
|
* @param os_data Opaque pointer to OS-specific data.
|
2011-11-19 21:02:37 +00:00
|
|
|
*/
|
2022-09-15 17:21:27 +00:00
|
|
|
virtual void SetFontNames(struct FontCacheSettings *settings, const char *font_name, const void *os_data = nullptr) = 0;
|
2011-11-19 21:02:37 +00:00
|
|
|
|
2021-01-12 18:52:30 +00:00
|
|
|
bool FindMissingGlyphs();
|
2011-11-19 18:43:00 +00:00
|
|
|
};
|
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = nullptr);
|
2007-12-16 18:38:19 +00:00
|
|
|
|
2010-12-22 10:50:32 +00:00
|
|
|
#endif /* STRINGS_FUNC_H */
|