[Changelog] Changelog as Feeder

This commit is contained in:
/dev/root 2017-02-04 18:42:12 +01:00
parent aa2562e420
commit a965fb1468
5 changed files with 91 additions and 2 deletions

View File

@ -55,6 +55,7 @@ namespace Components
#ifndef DISABLE_ANTICHEAT #ifndef DISABLE_ANTICHEAT
Loader::Register(new AntiCheat()); Loader::Register(new AntiCheat());
#endif #endif
Loader::Register(new Changelog());
Loader::Register(new Dedicated()); Loader::Register(new Dedicated());
Loader::Register(new Discovery()); Loader::Register(new Discovery());
Loader::Register(new Exception()); Loader::Register(new Exception());

View File

@ -74,6 +74,7 @@ namespace Components
#include "Modules/Renderer.hpp" #include "Modules/Renderer.hpp"
#include "Modules/UIFeeder.hpp" #include "Modules/UIFeeder.hpp"
#include "Modules/AntiCheat.hpp" #include "Modules/AntiCheat.hpp"
#include "Modules/Changelog.hpp"
#include "Modules/Dedicated.hpp" #include "Modules/Dedicated.hpp"
#include "Modules/Discovery.hpp" #include "Modules/Discovery.hpp"
#include "Modules/Exception.hpp" #include "Modules/Exception.hpp"

View File

@ -0,0 +1,60 @@
#include "STDInclude.hpp"
namespace Components
{
std::vector<Changelog::changelogLine> Changelog::Line;
void Changelog::LoadChangelog(UIScript::Token)
{
std::vector<std::string> 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);
}
}

View File

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

View File

@ -175,8 +175,6 @@ namespace Components
News::Terminate = false; News::Terminate = false;
News::Thread = std::thread([]() News::Thread = std::thread([]()
{ {
Localization::Set("MPUI_CHANGELOG_TEXT", Utils::Cache::GetFile("/iw4/changelog.txt"));
std::string data = Utils::Cache::GetFile("/iw4/motd.txt"); std::string data = Utils::Cache::GetFile("/iw4/motd.txt");
if (!data.empty()) if (!data.empty())