diff options
author | dP <dp@dpointer.org> | 2021-01-15 17:38:14 +0300 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2021-01-22 09:50:53 +0000 |
commit | bab7de6cf23dce124ef8b1e284d0d1f3996dc8b8 (patch) | |
tree | 3686edd1b3ebb285e802a8a16b79552972c0b1b4 /src/script | |
parent | 4b42ecb0f64c0044786412c15fb31b3705016375 (diff) | |
download | openttd-bab7de6cf23dce124ef8b1e284d0d1f3996dc8b8.tar.xz |
Feature: Allow GameScripts to add additional text to Industry view window
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/game_changelog.hpp | 1 | ||||
-rw-r--r-- | src/script/api/script_industry.cpp | 15 | ||||
-rw-r--r-- | src/script/api/script_industry.hpp | 10 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 82f0c0523..edc588407 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -30,6 +30,7 @@ * \li GSIndustry::SetControlFlags * \li GSIndustry::SetExclusiveConsumer * \li GSIndustry::SetExclusiveSupplier + * \li GSIndustry::SetText * \li GSStoryPage::MakePushButtonReference * \li GSStoryPage::MakeTileButtonReference * \li GSStoryPage::MakeVehicleButtonReference diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index 14ba8e402..0a5ca98d3 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -15,6 +15,7 @@ #include "script_map.hpp" #include "../../company_base.h" #include "../../industry.h" +#include "../../string_func.h" #include "../../strings_func.h" #include "../../station_base.h" #include "../../newgrf_industries.h" @@ -47,6 +48,20 @@ return GetString(STR_INDUSTRY_NAME); } +/* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text) +{ + CCountedPtr<Text> counter(text); + + const char *encoded_text = nullptr; + if (text != nullptr) { + encoded_text = text->GetEncodedText(); + EnforcePreconditionEncodedText(false, encoded_text); + } + EnforcePrecondition(false, IsValidIndustry(industry_id)); + + return ScriptObject::DoCommand(0, industry_id, static_cast<uint32>(IndustryAction::SetText), CMD_INDUSTRY_CTRL, encoded_text); +} + /* static */ ScriptIndustry::CargoAcceptState ScriptIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id) { if (!IsValidIndustry(industry_id)) return CAS_NOT_ACCEPTED; diff --git a/src/script/api/script_industry.hpp b/src/script/api/script_industry.hpp index dac3d32fd..95133da0e 100644 --- a/src/script/api/script_industry.hpp +++ b/src/script/api/script_industry.hpp @@ -82,6 +82,16 @@ public: static char *GetName(IndustryID industry_id); /** + * Set the custom text of an industry, shown in the GUI. + * @param industry_id The industry to set the custom text of. + * @param text The text to set it to (can be either a raw string, or a ScriptText object). If null is passed, the text will be removed. + * @pre IsValidIndustry(industry_id). + * @return True if the action succeeded. + * @api -ai + */ + static bool SetText(IndustryID industry_id, Text *text); + + /** * See whether an industry currently accepts a certain cargo. * @param industry_id The index of the industry. * @param cargo_id The index of the cargo. |