From 6434b0ac87b4ce6640437dcc3a92b97120ce5e0b Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Mon, 6 Mar 2023 13:22:05 +0100 Subject: [PATCH] Don't show motd if not available --- data/cdata/ui_scripts/motd/motd.lua | 4 ++++ src/client/component/motd.cpp | 9 +++++++++ src/client/component/motd.hpp | 1 + src/client/component/ui_scripting.cpp | 2 ++ 4 files changed, 16 insertions(+) diff --git a/data/cdata/ui_scripts/motd/motd.lua b/data/cdata/ui_scripts/motd/motd.lua index 0750a430..fa056ce5 100644 --- a/data/cdata/ui_scripts/motd/motd.lua +++ b/data/cdata/ui_scripts/motd/motd.lua @@ -11,6 +11,10 @@ LUI.MenuBuilder.registerPopupType("motd", function() end) LUI.onmenuopen("main_campaign", function(menu) + if (not motd.hasmotd()) then + return + end + if (not motd.hasseentoday()) then motd.sethasseentoday() LUI.FlowManager.RequestPopupMenu(nil, "motd") diff --git a/src/client/component/motd.cpp b/src/client/component/motd.cpp index 577ac674..83014526 100644 --- a/src/client/component/motd.cpp +++ b/src/client/component/motd.cpp @@ -233,6 +233,15 @@ namespace motd }); } + bool has_motd() + { + return marketing.access([](nlohmann::json& data) + -> nlohmann::json + { + return data.is_object() && data["motd"].is_object(); + }); + } + class component final : public component_interface { public: diff --git a/src/client/component/motd.hpp b/src/client/component/motd.hpp index 4a94b751..547204d0 100644 --- a/src/client/component/motd.hpp +++ b/src/client/component/motd.hpp @@ -8,4 +8,5 @@ namespace motd int get_num_featured_tabs(); nlohmann::json get_motd(); nlohmann::json get_featured_tab(const int index); + bool has_motd(); } diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 9c9d6f42..e7d0393a 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -654,6 +654,8 @@ namespace ui_scripting const auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); config::set("motd_last_seen", static_cast(now)); }; + + motd_table["hasmotd"] = motd::has_motd; } void start()