From 391dabc4f93608bb674edff2da30bfe58b911dba Mon Sep 17 00:00:00 2001 From: gsckoco Date: Mon, 28 Sep 2020 12:28:31 +0100 Subject: [PATCH 1/4] Made add_news_item argument assoc optional --- src/openrct2/interface/InteractiveConsole.cpp | 29 +++++++++++++++---- src/openrct2/management/NewsItem.cpp | 21 +++++++++++++- src/openrct2/management/NewsItem.h | 2 ++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 671b513657..7a5ed75f78 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1661,11 +1661,11 @@ static int32_t cc_assert([[maybe_unused]] InteractiveConsole& console, [[maybe_u static int32_t cc_add_news_item([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv) { printf("argv.size() = %zu\n", argv.size()); - if (argv.size() < 3) + if (argv.size() < 2) { console.WriteLineWarning("Too few arguments"); static_assert(News::ItemTypeCount == 10, "News::ItemType::Count changed, update console command!"); - console.WriteLine("add_news_item "); + console.WriteLine("add_news_item [assoc]"); console.WriteLine("type is one of:"); console.WriteLine(" 0 (News::ItemType::Null)"); console.WriteLine(" 1 (News::ItemType::Ride)"); @@ -1678,13 +1678,32 @@ static int32_t cc_add_news_item([[maybe_unused]] InteractiveConsole& console, [[ console.WriteLine(" 8 (News::ItemType::Award)"); console.WriteLine(" 9 (News::ItemType::Graph)"); console.WriteLine("message is the message to display, wrapped in quotes for multiple words"); - console.WriteLine("assoc is the associated id of ride/peep/tile/etc."); + console.WriteLine("assoc is the associated id of ride/peep/tile/etc. If the selected ItemType doesn't need an assoc " + "(Null, Money, Award, Graph), you can leave this field blank"); return 1; } + auto type = atoi(argv[0].c_str()); auto msg = argv[1].c_str(); - auto assoc = atoi(argv[2].c_str()); - News::AddItemToQueue(static_cast(type), msg, assoc); + auto assoc = 0; + + News::ItemType itemType = static_cast(type); + + if (argv.size() == 3) // 3 arguments passed, set assoc + { + assoc = atoi(argv[2].c_str()); + } + else + { + if (News::CheckIfItemRequiresAssoc(itemType)) + { + console.WriteLine("Selected ItemType requires an assoc"); + return 0; + } + } + + News::AddItemToQueue(itemType, msg, assoc); + console.WriteLine("Successfully added News Item"); return 0; } diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index 006a63853e..5286ac4aa4 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -315,7 +315,7 @@ News::Item* News::AddItemToQueue(News::ItemType type, const utf8* text, uint32_t News::Item* newsItem = gNewsItems.FirstOpenOrNewSlot(); newsItem->Type = type; newsItem->Flags = 0; - newsItem->Assoc = assoc; + newsItem->Assoc = assoc; // Make optional for Award, Money, Graph and Null newsItem->Ticks = 0; newsItem->MonthYear = static_cast(gDateMonthsElapsed); newsItem->Day = ((days_in_month[date_get_month(newsItem->MonthYear)] * gDateMonthTicks) >> 16) + 1; @@ -324,6 +324,25 @@ News::Item* News::AddItemToQueue(News::ItemType type, const utf8* text, uint32_t return newsItem; } +/** + * Checks if News::ItemType requires an assoc + * @return A boolean if assoc is required. + */ + +bool News::CheckIfItemRequiresAssoc(News::ItemType type) +{ + switch (type) + { + case News::ItemType::Null: + case News::ItemType::Award: + case News::ItemType::Money: + case News::ItemType::Graph: + return false; + default: + return true; // Everything else requires assoc + } +} + /** * Opens the window/tab for the subject of the news item * diff --git a/src/openrct2/management/NewsItem.h b/src/openrct2/management/NewsItem.h index 88129dcab9..9bfbfee416 100644 --- a/src/openrct2/management/NewsItem.h +++ b/src/openrct2/management/NewsItem.h @@ -292,6 +292,8 @@ namespace News News::Item* AddItemToQueue(News::ItemType type, rct_string_id string_id, uint32_t assoc, const Formatter& formatter); News::Item* AddItemToQueue(News::ItemType type, const utf8* text, uint32_t assoc); + bool CheckIfItemRequiresAssoc(News::ItemType type); + void OpenSubject(News::ItemType type, int32_t subject); void DisableNewsItems(News::ItemType type, uint32_t assoc); From 0e607fff43efca6180d148d93950675526a31d1e Mon Sep 17 00:00:00 2001 From: gsckoco Date: Mon, 28 Sep 2020 12:29:22 +0100 Subject: [PATCH 2/4] Added myself to contributors.md --- contributors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.md b/contributors.md index 8061b748ba..e24dfaac3b 100644 --- a/contributors.md +++ b/contributors.md @@ -158,6 +158,7 @@ The following people are not part of the development team, but have been contrib * Tom Parsons (tombomp) * Stephan Spengler (Sadret) * Roger Seekell (rpstester) +* Ben Johnston (gsckoco) ## Toolchain * (Balletie) - macOS From 48ee6e02da077ccedde255014c1fb96026904eb0 Mon Sep 17 00:00:00 2001 From: gsckoco Date: Mon, 28 Sep 2020 12:31:40 +0100 Subject: [PATCH 3/4] Updated changelog.txt --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a6813853e9..ae4bc07174 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -2,6 +2,7 @@ ------------------------------------------------------------------------ - Feature: [#13000] objective_options command for console - Fix: [#3200] Close Construction window upon selecting vehicle page +- Improved: [#13013] Made add_news_item console command last argument, assoc, optional. 0.3.1 (2020-09-27) ------------------------------------------------------------------------ From 869c3e938ba4e88512a731320108b1e555a207f6 Mon Sep 17 00:00:00 2001 From: gsckoco Date: Mon, 28 Sep 2020 12:35:51 +0100 Subject: [PATCH 4/4] Updated PR id in changelog.txt --- distribution/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index ae4bc07174..e73cc41948 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -2,7 +2,7 @@ ------------------------------------------------------------------------ - Feature: [#13000] objective_options command for console - Fix: [#3200] Close Construction window upon selecting vehicle page -- Improved: [#13013] Made add_news_item console command last argument, assoc, optional. +- Improved: [#13023] Made add_news_item console command last argument, assoc, optional. 0.3.1 (2020-09-27) ------------------------------------------------------------------------