mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
7 Commits
76dc9a3ab3
...
b9ac0d5441
Author | SHA1 | Date |
---|---|---|
|
b9ac0d5441 | |
|
1d38cbafcb | |
|
992d58d799 | |
|
8f34b7a821 | |
|
bf6d0c4934 | |
|
3c4fb21a5e | |
|
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
|
||||
|
|
|
@ -90,7 +90,7 @@ template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq
|
|||
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
|
||||
sq_setinstanceup(vm, 2, nullptr);
|
||||
/* Register the AI to the base system */
|
||||
info->GetScanner()->RegisterScript(info);
|
||||
info->GetScanner()->RegisterScript(std::unique_ptr<AIInfo>{info});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -136,22 +136,21 @@ bool AIInfo::CanLoadFromVersion(int version) const
|
|||
/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm)
|
||||
{
|
||||
/* Create a new library */
|
||||
AILibrary *library = new AILibrary();
|
||||
auto library = std::make_unique<AILibrary>();
|
||||
|
||||
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
||||
if (res != 0) {
|
||||
delete library;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Cache the category */
|
||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||
delete library;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
/* Register the Library to the base system */
|
||||
library->GetScanner()->RegisterScript(library);
|
||||
ScriptScanner *scanner = library->GetScanner();
|
||||
scanner->RegisterScript(std::move(library));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void AIScannerInfo::Initialize()
|
|||
{
|
||||
ScriptScanner::Initialize("AIScanner");
|
||||
|
||||
ScriptAllocatorScope alloc_scope(this->engine);
|
||||
ScriptAllocatorScope alloc_scope(this->engine.get());
|
||||
|
||||
/* Create the dummy AI */
|
||||
this->main_script = "%_dummy";
|
||||
|
|
|
@ -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)
|
||||
};
|
||||
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
|
||||
#include "safeguards.h"
|
||||
|
||||
/** Default heights for the different sizes of fonts. */
|
||||
static const int _default_font_height[FS_END] = {10, 6, 18, 10};
|
||||
static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
|
||||
/** Default unscaled heights for the different sizes of fonts. */
|
||||
/* static */ const int FontCache::DEFAULT_FONT_HEIGHT[FS_END] = {10, 6, 18, 10};
|
||||
/** Default unscaled ascenders for the different sizes of fonts. */
|
||||
/* static */ const int FontCache::DEFAULT_FONT_ASCENDER[FS_END] = {8, 5, 15, 8};
|
||||
|
||||
FontCacheSettings _fcsettings;
|
||||
|
||||
|
@ -32,8 +33,7 @@ FontCacheSettings _fcsettings;
|
|||
* Create a new font cache.
|
||||
* @param fs The size of the font.
|
||||
*/
|
||||
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_default_font_height[fs]),
|
||||
ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] - _default_font_height[fs])
|
||||
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs)
|
||||
{
|
||||
assert(this->parent == nullptr || this->fs == this->parent->fs);
|
||||
FontCache::caches[this->fs] = this;
|
||||
|
@ -50,7 +50,7 @@ FontCache::~FontCache()
|
|||
|
||||
int FontCache::GetDefaultFontHeight(FontSize fs)
|
||||
{
|
||||
return _default_font_height[fs];
|
||||
return FontCache::DEFAULT_FONT_HEIGHT[fs];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,9 +23,9 @@ protected:
|
|||
static FontCache *caches[FS_END]; ///< All the font caches.
|
||||
FontCache *parent; ///< The parent of this font cache.
|
||||
const FontSize fs; ///< The size of the font.
|
||||
int height; ///< The height of the font.
|
||||
int ascender; ///< The ascender value of the font.
|
||||
int descender; ///< The descender value of the font.
|
||||
int height = 0; ///< The height of the font.
|
||||
int ascender = 0; ///< The ascender value of the font.
|
||||
int descender = 0; ///< The descender value of the font.
|
||||
|
||||
public:
|
||||
FontCache(FontSize fs);
|
||||
|
@ -33,6 +33,11 @@ public:
|
|||
|
||||
static void InitializeFontCaches();
|
||||
|
||||
/** Default unscaled font heights. */
|
||||
static const int DEFAULT_FONT_HEIGHT[FS_END];
|
||||
/** Default unscaled font ascenders. */
|
||||
static const int DEFAULT_FONT_ASCENDER[FS_END];
|
||||
|
||||
static int GetDefaultFontHeight(FontSize fs);
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,7 +78,7 @@ template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) {
|
|||
/* Remove the link to the real instance, else it might get deleted by RegisterGame() */
|
||||
sq_setinstanceup(vm, 2, nullptr);
|
||||
/* Register the Game to the base system */
|
||||
info->GetScanner()->RegisterScript(info);
|
||||
info->GetScanner()->RegisterScript(std::unique_ptr<GameInfo>{info});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -106,22 +106,21 @@ bool GameInfo::CanLoadFromVersion(int version) const
|
|||
/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm)
|
||||
{
|
||||
/* Create a new library */
|
||||
GameLibrary *library = new GameLibrary();
|
||||
auto library = std::make_unique<GameLibrary>();
|
||||
|
||||
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
||||
if (res != 0) {
|
||||
delete library;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Cache the category */
|
||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||
delete library;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
/* Register the Library to the base system */
|
||||
library->GetScanner()->RegisterScript(library);
|
||||
ScriptScanner *scanner = library->GetScanner();
|
||||
scanner->RegisterScript(std::move(library));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -92,8 +92,8 @@ GameLibrary *GameScannerLibrary::FindLibrary(const std::string &library, int ver
|
|||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
||||
/* Check if the library + version exists */
|
||||
ScriptInfoList::iterator it = this->info_list.find(library_name);
|
||||
auto it = this->info_list.find(library_name);
|
||||
if (it == this->info_list.end()) return nullptr;
|
||||
|
||||
return static_cast<GameLibrary *>((*it).second);
|
||||
return static_cast<GameLibrary *>(it->second);
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 */
|
|
@ -29,6 +29,7 @@
|
|||
#include "../fileio_func.h"
|
||||
#include "../league_type.h"
|
||||
#include "../misc/endian_buffer.hpp"
|
||||
#include "../texteff.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
|
@ -315,6 +316,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.
|
||||
*/
|
||||
|
|
|
@ -44,10 +44,7 @@ bool ScriptScanner::AddFile(const std::string &filename, size_t, const std::stri
|
|||
return true;
|
||||
}
|
||||
|
||||
ScriptScanner::ScriptScanner() :
|
||||
engine(nullptr)
|
||||
{
|
||||
}
|
||||
ScriptScanner::ScriptScanner() = default;
|
||||
|
||||
void ScriptScanner::ResetEngine()
|
||||
{
|
||||
|
@ -58,7 +55,7 @@ void ScriptScanner::ResetEngine()
|
|||
|
||||
void ScriptScanner::Initialize(std::string_view name)
|
||||
{
|
||||
this->engine = new Squirrel(name);
|
||||
this->engine = std::make_unique<Squirrel>(name);
|
||||
|
||||
this->RescanDir();
|
||||
|
||||
|
@ -68,8 +65,6 @@ void ScriptScanner::Initialize(std::string_view name)
|
|||
ScriptScanner::~ScriptScanner()
|
||||
{
|
||||
this->Reset();
|
||||
|
||||
delete this->engine;
|
||||
}
|
||||
|
||||
void ScriptScanner::RescanDir()
|
||||
|
@ -83,15 +78,12 @@ void ScriptScanner::RescanDir()
|
|||
|
||||
void ScriptScanner::Reset()
|
||||
{
|
||||
for (const auto &item : this->info_list) {
|
||||
delete item.second;
|
||||
}
|
||||
|
||||
this->info_list.clear();
|
||||
this->info_single_list.clear();
|
||||
this->info_vector.clear();
|
||||
}
|
||||
|
||||
void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||
void ScriptScanner::RegisterScript(std::unique_ptr<ScriptInfo> &&info)
|
||||
{
|
||||
std::string script_original_name = this->GetScriptName(*info);
|
||||
std::string script_name = fmt::format("{}.{}", script_original_name, info->GetVersion());
|
||||
|
@ -99,7 +91,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
|||
/* Check if GetShortName follows the rules */
|
||||
if (info->GetShortName().size() != 4) {
|
||||
Debug(script, 0, "The script '{}' returned a string from GetShortName() which is not four characters. Unable to load the script.", info->GetName());
|
||||
delete info;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -111,7 +102,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
|||
#else
|
||||
if (it->second->GetMainScript() == info->GetMainScript()) {
|
||||
#endif
|
||||
delete info;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -120,20 +110,20 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
|||
Debug(script, 1, " 2: {}", info->GetMainScript());
|
||||
Debug(script, 1, "The first is taking precedence.");
|
||||
|
||||
delete info;
|
||||
return;
|
||||
}
|
||||
|
||||
this->info_list[script_name] = info;
|
||||
ScriptInfo *script_info = this->info_vector.emplace_back(std::move(info)).get();
|
||||
this->info_list[script_name] = script_info;
|
||||
|
||||
if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
|
||||
if (!script_info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
|
||||
/* Add the script to the 'unique' script list, where only the highest version
|
||||
* of the script is registered. */
|
||||
auto it = this->info_single_list.find(script_original_name);
|
||||
if (it == this->info_single_list.end()) {
|
||||
this->info_single_list[script_original_name] = info;
|
||||
} else if (it->second->GetVersion() < info->GetVersion()) {
|
||||
it->second = info;
|
||||
this->info_single_list[script_original_name] = script_info;
|
||||
} else if (it->second->GetVersion() < script_info->GetVersion()) {
|
||||
it->second = script_info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,17 +185,17 @@ struct ScriptFileChecksumCreator : FileScanner {
|
|||
* @param info The script to get the shortname and md5 sum from.
|
||||
* @return True iff they're the same.
|
||||
*/
|
||||
static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, Subdirectory dir)
|
||||
static bool IsSameScript(const ContentInfo &ci, bool md5sum, const ScriptInfo &info, Subdirectory dir)
|
||||
{
|
||||
uint32_t id = 0;
|
||||
auto str = std::string_view{info->GetShortName()}.substr(0, 4);
|
||||
auto str = std::string_view{info.GetShortName()}.substr(0, 4);
|
||||
for (size_t j = 0; j < str.size(); j++) id |= static_cast<uint8_t>(str[j]) << (8 * j);
|
||||
|
||||
if (id != ci.unique_id) return false;
|
||||
if (!md5sum) return true;
|
||||
|
||||
ScriptFileChecksumCreator checksum(dir);
|
||||
const auto &tar_filename = info->GetTarFile();
|
||||
const auto &tar_filename = info.GetTarFile();
|
||||
TarList::iterator iter;
|
||||
if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
|
||||
/* The main script is in a tar file, so find all files that
|
||||
|
@ -224,7 +214,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
|
|||
/* There'll always be at least 1 path separator character in a script
|
||||
* main script name as the search algorithm requires the main script to
|
||||
* be in a subdirectory of the script directory; so <dir>/<path>/main.nut. */
|
||||
const std::string &main_script = info->GetMainScript();
|
||||
const std::string &main_script = info.GetMainScript();
|
||||
std::string path = main_script.substr(0, main_script.find_last_of(PATHSEPCHAR));
|
||||
checksum.Scan(".nut", path);
|
||||
}
|
||||
|
@ -235,7 +225,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
|
|||
bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
|
||||
{
|
||||
for (const auto &item : this->info_list) {
|
||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return true;
|
||||
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -243,7 +233,7 @@ bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
|
|||
std::optional<std::string_view> ScriptScanner::FindMainScript(const ContentInfo &ci, bool md5sum)
|
||||
{
|
||||
for (const auto &item : this->info_list) {
|
||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return item.second->GetMainScript();
|
||||
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return item.second->GetMainScript();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "../fileio_func.h"
|
||||
#include "../string_func.h"
|
||||
|
||||
typedef std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator> ScriptInfoList; ///< Type for the list of scripts.
|
||||
using ScriptInfoList = std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator>; ///< Type for the list of scripts.
|
||||
|
||||
/** Scanner to help finding scripts. */
|
||||
class ScriptScanner : public FileScanner {
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
/**
|
||||
* Get the engine of the main squirrel handler (it indexes all available scripts).
|
||||
*/
|
||||
class Squirrel *GetEngine() { return this->engine; }
|
||||
class Squirrel *GetEngine() { return this->engine.get(); }
|
||||
|
||||
/**
|
||||
* Get the current main script the ScanDir is currently tracking.
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
/**
|
||||
* Register a ScriptInfo to the scanner.
|
||||
*/
|
||||
void RegisterScript(class ScriptInfo *info);
|
||||
void RegisterScript(std::unique_ptr<class ScriptInfo> &&info);
|
||||
|
||||
/**
|
||||
* Get the list of registered scripts to print on the console.
|
||||
|
@ -84,10 +84,12 @@ public:
|
|||
void RescanDir();
|
||||
|
||||
protected:
|
||||
class Squirrel *engine; ///< The engine we're scanning with.
|
||||
std::unique_ptr<class Squirrel> engine; ///< The engine we're scanning with.
|
||||
std::string main_script; ///< The full path of the script.
|
||||
std::string tar_file; ///< If, which tar file the script was in.
|
||||
|
||||
std::vector<std::unique_ptr<ScriptInfo>> info_vector;
|
||||
|
||||
ScriptInfoList info_list; ///< The list of all script.
|
||||
ScriptInfoList info_single_list; ///< The list of all unique script. The best script (highest version) is shown.
|
||||
|
||||
|
|
|
@ -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 */
|
|
@ -401,6 +401,40 @@ static void CancelIMEComposition(HWND hwnd)
|
|||
HandleTextInput({}, true);
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && defined(NTDDI_WIN10_RS4)
|
||||
/* We only use WinRT functions on Windows 10 or later. Unfortunately, newer Windows SDKs are now
|
||||
* linking the two functions below directly instead of using dynamic linking as previously.
|
||||
* To avoid any runtime linking errors on Windows 7 or older, we stub in our own dynamic
|
||||
* linking trampoline. */
|
||||
|
||||
static LibraryLoader _combase("combase.dll");
|
||||
|
||||
extern "C" int32_t __stdcall WINRT_IMPL_RoOriginateLanguageException(int32_t error, void *message, void *languageException) noexcept
|
||||
{
|
||||
typedef BOOL(WINAPI *PFNRoOriginateLanguageException)(int32_t, void *, void *);
|
||||
static PFNRoOriginateLanguageException RoOriginateLanguageException = _combase.GetFunction("RoOriginateLanguageException");
|
||||
|
||||
if (RoOriginateLanguageException != nullptr) {
|
||||
return RoOriginateLanguageException(error, message, languageException);
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int32_t __stdcall WINRT_IMPL_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept
|
||||
{
|
||||
typedef BOOL(WINAPI *PFNRoGetActivationFactory)(void *, winrt::guid const &, void **);
|
||||
static PFNRoGetActivationFactory RoGetActivationFactory = _combase.GetFunction("RoGetActivationFactory");
|
||||
|
||||
if (RoGetActivationFactory != nullptr) {
|
||||
return RoGetActivationFactory(classId, iid, factory);
|
||||
} else {
|
||||
*factory = nullptr;
|
||||
return winrt::impl::error_class_not_available;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool IsDarkModeEnabled()
|
||||
{
|
||||
/* Only build if SDK is Windows 10 1803 or later. */
|
||||
|
|
Loading…
Reference in New Issue