1
0
Fork 0
Norbert 2025-06-24 07:00:00 +00:00 committed by GitHub
commit f7373ca8d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 248 additions and 0 deletions

View File

@ -500,6 +500,8 @@ add_files(
textbuf_type.h textbuf_type.h
texteff.cpp texteff.cpp
texteff.hpp texteff.hpp
texteff_cmd.cpp
texteff_cmd.h
textfile_gui.cpp textfile_gui.cpp
textfile_gui.h textfile_gui.h
textfile_type.h textfile_type.h

View File

@ -46,6 +46,7 @@
#include "station_cmd.h" #include "station_cmd.h"
#include "story_cmd.h" #include "story_cmd.h"
#include "subsidy_cmd.h" #include "subsidy_cmd.h"
#include "texteff_cmd.h"
#include "terraform_cmd.h" #include "terraform_cmd.h"
#include "timetable_cmd.h" #include "timetable_cmd.h"
#include "town_cmd.h" #include "town_cmd.h"

View File

@ -372,6 +372,10 @@ enum Commands : uint8_t {
CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE, ///< update the score of a league table element 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_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) CMD_END, ///< Must ALWAYS be on the end of this list!! (period)
}; };

View File

@ -40,6 +40,7 @@
#include "../station_cmd.h" #include "../station_cmd.h"
#include "../story_cmd.h" #include "../story_cmd.h"
#include "../subsidy_cmd.h" #include "../subsidy_cmd.h"
#include "../texteff_cmd.h"
#include "../terraform_cmd.h" #include "../terraform_cmd.h"
#include "../timetable_cmd.h" #include "../timetable_cmd.h"
#include "../town_cmd.h" #include "../town_cmd.h"

View File

@ -206,6 +206,7 @@ add_files(
script_subsidylist.hpp script_subsidylist.hpp
script_testmode.hpp script_testmode.hpp
script_text.hpp script_text.hpp
script_text_effect.hpp
script_tile.hpp script_tile.hpp
script_tilelist.hpp script_tilelist.hpp
script_town.hpp script_town.hpp
@ -278,6 +279,7 @@ add_files(
script_subsidylist.cpp script_subsidylist.cpp
script_testmode.cpp script_testmode.cpp
script_text.cpp script_text.cpp
script_text_effect.cpp
script_tile.cpp script_tile.cpp
script_tilelist.cpp script_tilelist.cpp
script_town.cpp script_town.cpp

View File

@ -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);
}

View File

@ -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 */

View File

@ -29,6 +29,7 @@
#include "../fileio_func.h" #include "../fileio_func.h"
#include "../league_type.h" #include "../league_type.h"
#include "../misc/endian_buffer.hpp" #include "../misc/endian_buffer.hpp"
#include "../texteff.hpp"
#include "../safeguards.h" #include "../safeguards.h"
@ -315,6 +316,10 @@ void ScriptInstance::CollectGarbage()
instance.engine->InsertResult(EndianBufferReader::ToValue<LeagueTableID>(ScriptObject::GetLastCommandResData())); 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() ScriptStorage *ScriptInstance::GetStorage()
{ {

View File

@ -143,6 +143,11 @@ public:
*/ */
static void DoCommandReturnLeagueTableElementID(ScriptInstance &instance); static void DoCommandReturnLeagueTableElementID(ScriptInstance &instance);
/**
* Return a TextEffectID reply for a DoCommand.
*/
static void DoCommandReturnTextEffectID(ScriptInstance *instance);
/** /**
* Get the controller attached to the instance. * Get the controller attached to the instance.
*/ */

View File

@ -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();
}

24
src/texteff_cmd.h 100644
View File

@ -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 */