From a965fb1468826dd6d8cc785fd9b2438f66fa894e Mon Sep 17 00:00:00 2001 From: /dev/root Date: Sat, 4 Feb 2017 18:42:12 +0100 Subject: [PATCH] [Changelog] Changelog as Feeder --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/Changelog.cpp | 60 ++++++++++++++++++++++++++++ src/Components/Modules/Changelog.hpp | 29 ++++++++++++++ src/Components/Modules/News.cpp | 2 - 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/Components/Modules/Changelog.cpp create mode 100644 src/Components/Modules/Changelog.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 788fde46..39571c43 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -55,6 +55,7 @@ namespace Components #ifndef DISABLE_ANTICHEAT Loader::Register(new AntiCheat()); #endif + Loader::Register(new Changelog()); Loader::Register(new Dedicated()); Loader::Register(new Discovery()); Loader::Register(new Exception()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 0f918eba..8c1ae8d2 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -74,6 +74,7 @@ namespace Components #include "Modules/Renderer.hpp" #include "Modules/UIFeeder.hpp" #include "Modules/AntiCheat.hpp" +#include "Modules/Changelog.hpp" #include "Modules/Dedicated.hpp" #include "Modules/Discovery.hpp" #include "Modules/Exception.hpp" diff --git a/src/Components/Modules/Changelog.cpp b/src/Components/Modules/Changelog.cpp new file mode 100644 index 00000000..376c855f --- /dev/null +++ b/src/Components/Modules/Changelog.cpp @@ -0,0 +1,60 @@ +#include "STDInclude.hpp" + +namespace Components +{ + std::vector Changelog::Line; + + void Changelog::LoadChangelog(UIScript::Token) + { + std::vector changelog; + Changelog::Line.clear(); + + { + std::string uncleaned = Utils::Cache::GetFile("/iw4/changelog.txt"); + + changelog = Utils::String::Explode(uncleaned, '\n'); + } + + for (auto line : changelog) + { + Changelog::changelogLine info; + + Utils::String::Replace(line, "\r", ""); + info.line = Utils::String::Trim(line); + + Changelog::Line.push_back(info); + } + + // Reverse, latest demo first! + //std::reverse(Changelog::Line.begin(), Changelog::Line.end()); + } + + unsigned int Changelog::GetChangelogCount() + { + return Changelog::Line.size(); + } + + // Omit column here + const char* Changelog::GetChangelogText(unsigned int item, int /*column*/) + { + if (item < Changelog::Line.size()) + { + std::string info = Changelog::Line[item].line; + + return Utils::String::VA("%s", info.data()); + } + + return ""; + } + + void Changelog::SelectChangelog(unsigned int index) { index; } + + Changelog::Changelog() + { + // UIScripts + UIScript::Add("loadChangelog", Changelog::LoadChangelog); + + // Changelog + UIFeeder::Add(39.0f, Changelog::GetChangelogCount, Changelog::GetChangelogText, Changelog::SelectChangelog); + } +} diff --git a/src/Components/Modules/Changelog.hpp b/src/Components/Modules/Changelog.hpp new file mode 100644 index 00000000..2b4259c3 --- /dev/null +++ b/src/Components/Modules/Changelog.hpp @@ -0,0 +1,29 @@ +#pragma once + +namespace Components +{ + class Changelog : public Component + { + public: + Changelog(); + +#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) + const char* getName() override { return "Changelog"; }; +#endif + + class changelogLine + { + public: + std::string line; + }; + + private: + static std::vector Line; + + static void LoadChangelog(UIScript::Token); + + static unsigned int GetChangelogCount(); + static const char* GetChangelogText(unsigned int item, int column); + static void SelectChangelog(unsigned int index); + }; +} diff --git a/src/Components/Modules/News.cpp b/src/Components/Modules/News.cpp index 9c714dd8..0a69c701 100644 --- a/src/Components/Modules/News.cpp +++ b/src/Components/Modules/News.cpp @@ -175,8 +175,6 @@ namespace Components News::Terminate = false; News::Thread = std::thread([]() { - Localization::Set("MPUI_CHANGELOG_TEXT", Utils::Cache::GetFile("/iw4/changelog.txt")); - std::string data = Utils::Cache::GetFile("/iw4/motd.txt"); if (!data.empty())