Toasts
This commit is contained in:
parent
5c70ca9011
commit
75af2aa24e
2
deps/json11
vendored
2
deps/json11
vendored
@ -1 +1 @@
|
||||
Subproject commit a20878aaa5bd2546466585b18b6d09808a98233d
|
||||
Subproject commit 913269c7a4cf9ab61a9748090c7e2484a2546a02
|
2
deps/mongoose
vendored
2
deps/mongoose
vendored
@ -1 +1 @@
|
||||
Subproject commit 3f1a33e4b468c1bfcd9f56348847df788f55c27b
|
||||
Subproject commit 290e5f83d43286c015feea0356a3aa0cf6e14e60
|
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
||||
Subproject commit 4f93098eb35b4868543b73d6023b07cb169c5a3a
|
||||
Subproject commit 0ab78e19eb56fb992105eba034f3b63fd67b4ae5
|
@ -16,6 +16,7 @@ namespace Components
|
||||
Loader::Register(new Node());
|
||||
Loader::Register(new RCon());
|
||||
Loader::Register(new Menus());
|
||||
Loader::Register(new Toast());
|
||||
Loader::Register(new Party());
|
||||
Loader::Register(new Colors());
|
||||
Loader::Register(new D3D9Ex());
|
||||
|
@ -29,6 +29,7 @@ namespace Components
|
||||
#include "Modules\News.hpp"
|
||||
#include "Modules\Flags.hpp"
|
||||
#include "Modules\Menus.hpp"
|
||||
#include "Modules\Toast.hpp"
|
||||
#include "Modules\Colors.hpp"
|
||||
#include "Modules\D3D9Ex.hpp"
|
||||
#include "Modules\Logger.hpp"
|
||||
|
@ -250,6 +250,23 @@ namespace Components
|
||||
// DB_AddXAsset
|
||||
Utils::Hook(0x5BB650, AssetHandler::AddAssetStub, HOOK_JUMP).Install()->Quick();
|
||||
|
||||
Command::Add("listassets", [] (Command::Params params)
|
||||
{
|
||||
if (params.Length() < 2) return;
|
||||
|
||||
Game::XAssetType type = Game::DB_GetXAssetNameType(params[1]);
|
||||
|
||||
if (type != Game::XAssetType::ASSET_TYPE_INVALID)
|
||||
{
|
||||
Game::DB_EnumXAssets(type, [] (Game::XAssetHeader header, void* data)
|
||||
{
|
||||
Game::XAssetType type = *static_cast<Game::XAssetType*>(data);
|
||||
Game::XAsset asset = { type, header };
|
||||
Logger::Print("%s\n", Game::DB_GetXAssetName(&asset));
|
||||
}, &type, false);
|
||||
}
|
||||
});
|
||||
|
||||
// Register asset interfaces
|
||||
AssetHandler::RegisterInterface(new Assets::IXModel());
|
||||
AssetHandler::RegisterInterface(new Assets::IMapEnts());
|
||||
@ -266,6 +283,7 @@ namespace Components
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialVertexShader());
|
||||
AssetHandler::RegisterInterface(new Assets::IStructuredDataDefSet());
|
||||
AssetHandler::RegisterInterface(new Assets::IMaterialVertexDeclaration());
|
||||
|
||||
}
|
||||
|
||||
AssetHandler::~AssetHandler()
|
||||
|
@ -396,9 +396,12 @@ namespace Components
|
||||
{
|
||||
if (params.Length() < 2)
|
||||
{
|
||||
Logger::Print("Your current security level is %d\n", Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.GetPublicKey()));
|
||||
uint32_t level = Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.GetPublicKey());
|
||||
Logger::Print("Your current security level is %d\n", level);
|
||||
Logger::Print("Your security token is: %s\n", Utils::DumpHex(Auth::GuidToken.ToString(), "").data());
|
||||
Logger::Print("Your computation token is: %s\n", Utils::DumpHex(Auth::ComputeToken.ToString(), "").data());
|
||||
|
||||
Toast::Show("cardicon_locked", "^5Security Level", Utils::VA("Your security level is %d", level), 3000);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
157
src/Components/Modules/Toast.cpp
Normal file
157
src/Components/Modules/Toast.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
#include "STDInclude.hpp"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
std::queue<Toast::UIToast> Toast::Queue;
|
||||
std::mutex Toast::Mutex;
|
||||
|
||||
void Toast::Show(const char* image, const char* title, const char* description, int length)
|
||||
{
|
||||
Toast::Mutex.lock();
|
||||
Toast::Queue.push({ image, title, description, length, 0 });
|
||||
Toast::Mutex.unlock();
|
||||
}
|
||||
|
||||
void Toast::Draw(UIToast* toast)
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4244)
|
||||
if (!toast) return;
|
||||
|
||||
int width = Renderer::Width();
|
||||
int height = Renderer::Height();
|
||||
int slideTime = 100;
|
||||
|
||||
int duration = toast->Length;
|
||||
int startTime = toast->Start;
|
||||
|
||||
int aCorners = 0; // Adjust the corners. They seem to have a 1px border
|
||||
int cornerSize = 15;
|
||||
int bHeight = 74;
|
||||
int bWidth = 200;
|
||||
|
||||
int imgDim = 60;
|
||||
|
||||
Game::Material* circle = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "circle").material;
|
||||
Game::Material* white = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "white").material;
|
||||
Game::Material* image = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, toast->Image.data()).material;
|
||||
Game::Font* font = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_FONT, "fonts/normalFont").font;
|
||||
Game::vec4_t color = { 0, 0, 0, 0.7f };
|
||||
Game::vec4_t wColor = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
if (Game::Com_Milliseconds() < startTime || (startTime + duration) < Game::Com_Milliseconds()) return;
|
||||
|
||||
// Fadein stuff
|
||||
else if (Game::Com_Milliseconds() - startTime < slideTime)
|
||||
{
|
||||
height /= 5;
|
||||
height *= 4;
|
||||
|
||||
int diffH = Renderer::Height() / 5;
|
||||
int diff = Game::Com_Milliseconds() - startTime;
|
||||
double scale = 1.0 - ((1.0 * diff) / (1.0 * slideTime));
|
||||
diffH *= scale;
|
||||
height += diffH;
|
||||
}
|
||||
|
||||
// Fadeout stuff
|
||||
else if (Game::Com_Milliseconds() - startTime > (duration - slideTime))
|
||||
{
|
||||
height /= 5;
|
||||
height *= 4;
|
||||
|
||||
int diffH = Renderer::Height() / 5;
|
||||
int diff = (startTime + duration) - Game::Com_Milliseconds();
|
||||
double scale = 1.0 - ((1.0 * diff) / (1.0 * slideTime));
|
||||
diffH *= scale;
|
||||
height += diffH;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
height /= 5;
|
||||
height *= 4;
|
||||
}
|
||||
|
||||
height += bHeight / 2 + aCorners - cornerSize;
|
||||
|
||||
// Calculate width data
|
||||
int iOffset = (bHeight - imgDim) / 2 + aCorners;
|
||||
int iOffsetLeft = iOffset * 2;
|
||||
int titleSize = Game::R_TextWidth(toast->Title.data(), 0x7FFFFFFF, font);
|
||||
int descrSize = Game::R_TextWidth(toast->Desc.data(), 0x7FFFFFFF, font);
|
||||
bWidth = iOffsetLeft * 3 + imgDim + std::max(titleSize, descrSize);
|
||||
|
||||
// Make stuff divisible by 2
|
||||
// Otherwise there are overlapping images
|
||||
// and I'm too lazy to figure out the actual problem :P
|
||||
bWidth += (bWidth % 2);
|
||||
bHeight += (bHeight % 2);
|
||||
|
||||
// Corners
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 - bWidth / 2, height - bHeight / 2, cornerSize, cornerSize, 0, 0, 0.5f, 0.5f, color, circle); // Top-Left
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 + bWidth / 2 - cornerSize, height - bHeight / 2, cornerSize, cornerSize, 0.5f, 0, 0, 0.5f, color, circle); // Top-Right
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 - bWidth / 2, height + bHeight / 2 - cornerSize, cornerSize, cornerSize, 0, 0.5f, 0.5f, 0, color, circle); // Bottom-Left
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 + bWidth / 2 - cornerSize, height + bHeight / 2 - cornerSize, cornerSize, cornerSize, 0.5f, 0.5f, 0, 0, color, circle); // Bottom-Right
|
||||
|
||||
// Border
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 - bWidth / 2 + cornerSize, height - bHeight / 2 + aCorners, bWidth - cornerSize * 2, cornerSize - aCorners, 0, 0, 1.0f, 1.0f, color, white); // Top
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 - bWidth / 2 + cornerSize, height + bHeight / 2 - cornerSize, bWidth - cornerSize * 2, cornerSize - aCorners, 0, 0, 1.0f, 1.0f, color, white); // Bottom
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 - bWidth / 2 + aCorners, height - bHeight / 2 + cornerSize, cornerSize - aCorners, bHeight - cornerSize * 2, 0, 0, 1.0f, 1.0f, color, white); // Left
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 + bWidth / 2 - cornerSize, height - bHeight / 2 + cornerSize, cornerSize - aCorners, bHeight - cornerSize * 2, 0, 0, 1.0f, 1.0f, color, white); // Right
|
||||
|
||||
// Center
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 - (bWidth - cornerSize * 2) / 2, height - (bHeight - cornerSize * 2) / 2, bWidth - cornerSize * 2, bHeight - cornerSize * 2, 0, 0, 1.0f, 1.0f, color, white);
|
||||
|
||||
// Image
|
||||
Game::R_AddCmdDrawStretchPic(width / 2 - bWidth / 2 + iOffsetLeft, height - bHeight / 2 + iOffset, imgDim, imgDim, 0, 0, 1.0f, 1.0f, wColor, image);
|
||||
|
||||
// Text
|
||||
int leftText = width / 2 - bWidth / 2 - cornerSize + iOffsetLeft * 2 + imgDim;
|
||||
int rightText = width / 2 + bWidth / 2 - cornerSize - aCorners - iOffsetLeft;
|
||||
Game::R_AddCmdDrawText(toast->Title.data(), 0x7FFFFFFF, font, leftText + (rightText - leftText) / 2 - titleSize / 2 + cornerSize, height - bHeight / 2 + cornerSize * 2 + 7, 1.0f, 1.0f, 0, wColor, 0); // Title
|
||||
Game::R_AddCmdDrawText(toast->Desc.data(), 0x7FFFFFFF, font, leftText + (rightText - leftText) / 2 - descrSize / 2 + cornerSize, height - bHeight / 2 + cornerSize * 2 + 33, 1.0f, 1.0f, 0, wColor, 0); // Description
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
void Toast::Handler()
|
||||
{
|
||||
if (Toast::Queue.empty()) return;
|
||||
|
||||
Toast::Mutex.lock();
|
||||
|
||||
Toast::UIToast* toast = &Toast::Queue.front();
|
||||
|
||||
// Set start time
|
||||
if (!toast->Start)
|
||||
{
|
||||
toast->Start = Game::Com_Milliseconds();
|
||||
}
|
||||
|
||||
if ((toast->Start + toast->Length) < Game::Com_Milliseconds())
|
||||
{
|
||||
Toast::Queue.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast::Draw(toast);
|
||||
}
|
||||
|
||||
Toast::Mutex.unlock();
|
||||
}
|
||||
|
||||
Toast::Toast()
|
||||
{
|
||||
Renderer::OnFrame(Toast::Handler);
|
||||
|
||||
Command::Add("testtoast", [] (Command::Params)
|
||||
{
|
||||
Toast::Show("specialty_nuke", "Test", "This is a test toast", 3000);
|
||||
});
|
||||
}
|
||||
|
||||
Toast::~Toast()
|
||||
{
|
||||
Toast::Queue = std::queue<Toast::UIToast>();
|
||||
}
|
||||
}
|
28
src/Components/Modules/Toast.hpp
Normal file
28
src/Components/Modules/Toast.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
namespace Components
|
||||
{
|
||||
class Toast : public Component
|
||||
{
|
||||
public:
|
||||
Toast();
|
||||
~Toast();
|
||||
const char* GetName() { return "Toast"; };
|
||||
|
||||
static void Show(const char* image, const char* title, const char* description, int length);
|
||||
|
||||
private:
|
||||
struct UIToast
|
||||
{
|
||||
std::string Image;
|
||||
std::string Title;
|
||||
std::string Desc;
|
||||
int Length;
|
||||
int Start;
|
||||
};
|
||||
|
||||
static void Handler();
|
||||
static void Draw(UIToast* toast);
|
||||
|
||||
static std::queue<UIToast> Queue;
|
||||
static std::mutex Mutex;
|
||||
};
|
||||
}
|
@ -39,6 +39,7 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <queue>
|
||||
|
||||
// Submodules
|
||||
// Ignore the warnings, it's no our code!
|
||||
|
Loading…
x
Reference in New Issue
Block a user