Optimize toasts
This commit is contained in:
parent
8a4c64c2db
commit
fdda6244d3
2
deps/mongoose
vendored
2
deps/mongoose
vendored
@ -1 +1 @@
|
||||
Subproject commit 4d65cb1c0ff6c8e50127afd6d9e2a88fe5f30972
|
||||
Subproject commit a478dc59354deb19d01a9e9138bcfac76a0347e3
|
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
||||
Subproject commit dc0aeaa9030bdac264b44d56d07b6839a1ae94e9
|
||||
Subproject commit e0016c5b6ae61ad60d260a78c5834cc537b46d10
|
@ -23,19 +23,22 @@ namespace Components
|
||||
int duration = toast->Length;
|
||||
int startTime = toast->Start;
|
||||
|
||||
int aCorners = 0; // Adjust the corners. They seem to have a 1px border
|
||||
int border = 1;
|
||||
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;
|
||||
float fontSize = 0.9f;
|
||||
float descSize = 0.9f;
|
||||
|
||||
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::Font* font = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_FONT, "fonts/objectiveFont").font;
|
||||
Game::Font* descfont = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_FONT, "fonts/normalFont").font;
|
||||
Game::vec4_t wColor = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
Game::vec4_t bgColor = { 0.0f, 0.0f, 0.0f, 0.5f };
|
||||
Game::vec4_t borderColor = { 1.0f, 1.0f, 1.0f, 0.2f };
|
||||
|
||||
height /= 5;
|
||||
height *= 4;
|
||||
@ -48,7 +51,7 @@ namespace Components
|
||||
int diffH = Renderer::Height() / 5;
|
||||
int diff = Game::Com_Milliseconds() - startTime;
|
||||
double scale = 1.0 - ((1.0 * diff) / (1.0 * slideTime));
|
||||
diffH = static_cast<int>(diffH* scale);
|
||||
diffH = static_cast<int>(diffH * scale);
|
||||
height += diffH;
|
||||
}
|
||||
|
||||
@ -58,48 +61,42 @@ namespace Components
|
||||
int diffH = Renderer::Height() / 5;
|
||||
int diff = (startTime + duration) - Game::Com_Milliseconds();
|
||||
double scale = 1.0 - ((1.0 * diff) / (1.0 * slideTime));
|
||||
diffH = static_cast<int>(diffH* scale);
|
||||
diffH = static_cast<int>(diffH * scale);
|
||||
height += diffH;
|
||||
}
|
||||
|
||||
height += bHeight / 2 + aCorners - cornerSize;
|
||||
height += bHeight / 2 - cornerSize;
|
||||
|
||||
// Calculate width data
|
||||
int iOffset = (bHeight - imgDim) / 2 + aCorners;
|
||||
int iOffset = (bHeight - imgDim) / 2;
|
||||
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);
|
||||
float titleSize = Game::R_TextWidth(toast->Title.data(), 0x7FFFFFFF, font) * fontSize;
|
||||
float descrSize = Game::R_TextWidth(toast->Desc.data(), 0x7FFFFFFF, descfont) * descSize;
|
||||
float 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);
|
||||
bWidth = (static_cast<int>(bWidth) + (static_cast<int>(bWidth) % 2)) * 1.0f;
|
||||
bHeight += (bHeight % 2);
|
||||
|
||||
// Corners
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2), static_cast<float>(height - bHeight / 2), cornerSize * 1.0f, cornerSize * 1.0f, 0, 0, 0.5f, 0.5f, color, circle); // Top-Left
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 + bWidth / 2 - cornerSize), static_cast<float>(height - bHeight / 2), cornerSize * 1.0f, cornerSize * 1.0f, 0.5f, 0, 0, 0.5f, color, circle); // Top-Right
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2), static_cast<float>(height + bHeight / 2 - cornerSize), cornerSize * 1.0f, cornerSize * 1.0f, 0, 0.5f, 0.5f, 0, color, circle); // Bottom-Left
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 + bWidth / 2 - cornerSize), static_cast<float>(height + bHeight / 2 - cornerSize), cornerSize * 1.0f, cornerSize * 1.0f, 0.5f, 0.5f, 0, 0, color, circle); // Bottom-Right
|
||||
// Background
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2), static_cast<float>(height - bHeight / 2), bWidth * 1.0f, bHeight * 1.0f, 0, 0, 1.0f, 1.0f, bgColor, white);
|
||||
|
||||
// Border
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2 + cornerSize), static_cast<float>(height - bHeight / 2 + aCorners), static_cast<float>(bWidth - cornerSize * 2), static_cast<float>(cornerSize - aCorners), 0, 0, 1.0f, 1.0f, color, white); // Top
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2 + cornerSize), static_cast<float>(height + bHeight / 2 - cornerSize), static_cast<float>(bWidth - cornerSize * 2), static_cast<float>(cornerSize - aCorners), 0, 0, 1.0f, 1.0f, color, white); // Bottom
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2 + aCorners), static_cast<float>(height - bHeight / 2 + cornerSize), static_cast<float>(cornerSize - aCorners), static_cast<float>(bHeight - cornerSize * 2), 0, 0, 1.0f, 1.0f, color, white); // Left
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 + bWidth / 2 - cornerSize), static_cast<float>(height - bHeight / 2 + cornerSize), static_cast<float>(cornerSize - aCorners), static_cast<float>(bHeight - cornerSize * 2), 0, 0, 1.0f, 1.0f, color, white); // Right
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2 - border), static_cast<float>(height - bHeight / 2 - border), border * 1.0f, bHeight + (border * 2.0f), 0, 0, 1.0f, 1.0f, borderColor, white); // Left
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2 + bWidth), static_cast<float>(height - bHeight / 2 - border), border * 1.0f, bHeight + (border * 2.0f), 0, 0, 1.0f, 1.0f, borderColor, white); // Right
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2), static_cast<float>(height - bHeight / 2 - border), bWidth * 1.0f, border * 1.0f, 0, 0, 1.0f, 1.0f, borderColor, white); // Top
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2), static_cast<float>(height + bHeight / 2), bWidth * 1.0f, border * 1.0f, 0, 0, 1.0f, 1.0f, borderColor, white); // Bottom
|
||||
|
||||
// Center
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - (bWidth - cornerSize * 2) / 2), static_cast<float>(height - (bHeight - cornerSize * 2) / 2), static_cast<float>(bWidth - cornerSize * 2), static_cast<float>(bHeight - cornerSize * 2), 0, 0, 1.0f, 1.0f, color, white);
|
||||
|
||||
// Image
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2 + iOffsetLeft), static_cast<float>(height - bHeight / 2 + iOffset), imgDim * 1.0f, imgDim * 1.0f, 0, 0, 1.0f, 1.0f, wColor, image);
|
||||
// Image
|
||||
Game::CL_DrawStretchPicPhysical(static_cast<float>(width / 2 - bWidth / 2 + iOffsetLeft), static_cast<float>(height - bHeight / 2 + iOffset), imgDim * 1.0f, imgDim * 1.0f, 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, static_cast<float>(leftText + (rightText - leftText) / 2 - titleSize / 2 + cornerSize), static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 7), 1.0f, 1.0f, 0, wColor, 0); // Title
|
||||
Game::R_AddCmdDrawText(toast->Desc.data(), 0x7FFFFFFF, font, static_cast<float>(leftText + (rightText - leftText) / 2 - descrSize / 2 + cornerSize), static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 33), 1.0f, 1.0f, 0, wColor, 0); // Description
|
||||
float leftText = width / 2 - bWidth / 2 - cornerSize + iOffsetLeft * 2 + imgDim;
|
||||
float rightText = width / 2 + bWidth / 2 - cornerSize - iOffsetLeft;
|
||||
Game::R_AddCmdDrawText(Utils::StrToUpper(toast->Title).data(), 0x7FFFFFFF, font, static_cast<float>(leftText + (rightText - leftText) / 2 - titleSize / 2 + cornerSize), static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 7), fontSize, fontSize, 0, wColor, Game::ITEM_TEXTSTYLE_SHADOWED); // Title
|
||||
Game::R_AddCmdDrawText(toast->Desc.data(), 0x7FFFFFFF, descfont, leftText + (rightText - leftText) / 2 - descrSize / 2 + cornerSize, static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 33), descSize, descSize, 0, wColor, Game::ITEM_TEXTSTYLE_SHADOWED); // Description
|
||||
}
|
||||
|
||||
void Toast::Handler()
|
||||
|
@ -39,6 +39,12 @@ namespace Utils
|
||||
return input;
|
||||
}
|
||||
|
||||
std::string StrToUpper(std::string input)
|
||||
{
|
||||
std::transform(input.begin(), input.end(), input.begin(), ::toupper);
|
||||
return input;
|
||||
}
|
||||
|
||||
bool EndsWith(std::string haystack, std::string needle)
|
||||
{
|
||||
return (strstr(haystack.data(), needle.data()) == (haystack.data() + haystack.size() - needle.size()));
|
||||
|
@ -5,6 +5,7 @@ namespace Utils
|
||||
std::string GetMimeType(std::string url);
|
||||
const char *VA(const char *fmt, ...);
|
||||
std::string StrToLower(std::string input);
|
||||
std::string StrToUpper(std::string input);
|
||||
bool EndsWith(std::string haystack, std::string needle);
|
||||
std::vector<std::string> Explode(const std::string& str, char delim);
|
||||
void Replace(std::string &string, std::string find, std::string replace);
|
||||
|
Loading…
Reference in New Issue
Block a user