mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-15 23:50:38 +00:00
* Add retail Cooldown methods and OnCooldownDone Port the post-4.3.4 Cooldown API onto the native CGCooldown frame: Clear, Pause/Resume/SetPaused/IsPaused, GetCooldownTimes, GetCooldownDuration, GetCooldownDisplayDuration, SetCooldownDuration, SetCooldownFromExpirationTime, the modRate argument, SetDrawSwipe, SetDrawBling, SetSwipeColor, SetEdgeColor, the drawSwipe/drawBling XML attributes, and the OnCooldownDone script (via Frame::ExtraScripts). Behavior follows retail probes, not the generated doc strings: the getters report the end flash once the sweep ends, modRate scales the flash and the display duration but not the sweep, and a reverse cooldown flashes and hides like any other. Add CooldownFrame_Set, CooldownFrame_Clear and CooldownFrame_SetDisplayAsPercentage to the embedded addon. * List the new Cooldown methods in the README table * Add Cooldown swipe, edge and bling textures SetSwipeTexture, SetEdgeTexture and SetBlingTexture, and the <SwipeTexture>, <EdgeTexture> and <BlingTexture> XML elements, split 4.3.4's star texture into three slots. An empty file is the engine's solid texture tinted by the slot colour, and Interface\Cooldown\edge maps to the built-in edge texels. A setter without r, g, b keeps the colour, as retail does. Slots left unset get 4.3.4's textures at the first SetCooldown, so the defaults stay 4.3.4's. The swipe's texcoords now map its positions over the frame so a custom texture lines up. * Add Cooldown rotation SetRotation / GetRotation and the XML rotation attribute (degrees) move where the sweep starts, clockwise from the top, as retail does. The sweep is now one polygon along the frame's outline in place of 4.3.4's four octant functions, with the same timing (each half side an eighth of the duration) and, at rotation 0, the same shape. The one difference is 4.3.4's reverse octant 1, which drew one triangle twice. * Add Cooldown countdown numbers Every Cooldown gets a countdown font string (FRIZQT__ 16 OUTLINE, centred), shown while retail's countdownForCooldowns CVar is 1; the CVar defaults to 0, so the default look stays 4.3.4's. The text follows retail: seconds, then m:ss below the abbreviation threshold, then whole minutes, hours and days rounded up, and nothing for cooldowns no longer than the minimum duration or during the flash. Adds SetHideCountdownNumbers / GetHideCountdownNumbers, GetCountdownFontString, SetCountdownAbbrevThreshold / GetCountdownAbbrevThreshold, SetMinimumCountdownDuration / GetMinimumCountdownDuration and the hideCountdownNumbers and minimumCountdownDuration XML attributes. * Add the Cooldown countdown milliseconds threshold SetCountdownMillisecondsThreshold / GetCountdownMillisecondsThreshold: below the threshold the numbers show tenths, rounded up, as retail does (threshold 5: 4.973 shows 5.0, 3.24 shows 3.3, 0.039 shows 0.1). The default is 0, so the numbers stay whole seconds. * Fix the Cooldown review findings - A zero-length timer (a new frame, SetCooldown(t, 0)) hides without the bling flash or OnCooldownDone, instead of flashing and reporting (now, 1000) from the getters. - Countdown text rounds up with integer math (700 ms read "0.8") and picks its unit on the rounded-up seconds (59.4 s read "60", not "1:00"). - SetMinimumCountdownDuration and minimumCountdownDuration clamp to the uint32 range. - The edge texcoord rotation uses the guarded done fraction (0/0 gave NaN). - Texture slots are one array with per-slot tag, default file and draw layer (Offsets::DRAWLAYER_*), replacing the ternaries and bare 2/3. - The header lists where the state machine follows retail over 4.3.4. edge.blp is now served to every texture load by texture/Builtin.cpp, a hook on TextureCreateFromBlp that falls back to the DLL's texels only when SFile has no such file; TextureCreate caches and ref-counts it like a file. Cooldown loads it by path and drops its edge special case. Frame::Region::CreateTexture / CreateFontString replace the hand-rolled pool-alloc + ctor copies in Cooldown, LinePool, BarTexture, SoftTargetIcon and InlineTexturePool.
84 lines
3.6 KiB
C++
84 lines
3.6 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
|
|
// of the GNU General Public License as published by the Free Software Foundation, either
|
|
// version 3 of the License, or (at your option) any later version.
|
|
//
|
|
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
// PURPOSE. See the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// BLPs the later clients ship and 1.12 does not, served to every texture load.
|
|
//
|
|
// A texture under the embedded addon's path would not load: BLPs open through
|
|
// SFile, not the read the addon redirects. So the image is texels in the DLL,
|
|
// handed out by TextureCreateFromBlp when SFile has no such file. TextureCreate
|
|
// (FUN_TEXTURE_LOAD_BY_PATH) reaches the BLP loader only on a miss in its
|
|
// texture hash and inserts what it returns under the name and flags, so the
|
|
// engine's own cache deduplicates and reference-counts the result like any
|
|
// file's. A real file of the same name (a patch MPQ, a loose file) still wins.
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
#include "texture/Load.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Texture::Builtin {
|
|
|
|
namespace {
|
|
|
|
// interface\cooldown\edge.blp (4.3.4): 16x16 DXT5, decoded the standard way
|
|
// (565 widened by bit replication), as 4.3.4's device samples it. Each of rows
|
|
// 0-7 is one colour with alpha only in column 8, a line from the centre to the
|
|
// top edge fading out; rows 8-15 are transparent black.
|
|
constexpr uint32_t kEdgeSize = 16;
|
|
constexpr uint32_t kEdgeColumn = 8;
|
|
const uint32_t kEdgeRowColor[8] = {0xFFD300, 0xFFD300, 0xFFD300, 0xDEBA00,
|
|
0xB59200, 0x806900, 0x4C4000, 0x181800};
|
|
const uint8_t kEdgeColumnAlpha[8] = {0xFF, 0xEB, 0xC9, 0xA7, 0x7E, 0x5A, 0x36, 0x12};
|
|
|
|
// Outlives every handle: the engine reads it whenever it uploads one.
|
|
struct EdgeTexels {
|
|
uint32_t texels[kEdgeSize * kEdgeSize] = {};
|
|
EdgeTexels() {
|
|
for (uint32_t y = 0; y < 8; ++y)
|
|
for (uint32_t x = 0; x < kEdgeSize; ++x)
|
|
texels[y * kEdgeSize + x] =
|
|
kEdgeRowColor[y] | (x == kEdgeColumn ? uint32_t{kEdgeColumnAlpha[y]} << 24 : 0);
|
|
}
|
|
};
|
|
const EdgeTexels g_edge;
|
|
|
|
// `path` names `file` (the loader's path, extension included), either slash, any case.
|
|
bool IsPath(const char *path, const char *file) {
|
|
for (; *file != '\0'; ++file, ++path) {
|
|
const char c = *path == '/' ? '\\' : *path;
|
|
if (c == '\0' || (c | 0x20) != (*file | 0x20))
|
|
return false;
|
|
}
|
|
return *path == '\0';
|
|
}
|
|
|
|
using CreateFromBlp_t = void *(__fastcall *)(const char *path, uint32_t fileFlag, uint32_t flags,
|
|
void *log);
|
|
CreateFromBlp_t CreateFromBlp_o = nullptr;
|
|
|
|
void *__fastcall CreateFromBlp_h(const char *path, uint32_t fileFlag, uint32_t flags, void *log) {
|
|
void *handle = CreateFromBlp_o(path, fileFlag, flags, log);
|
|
if (handle == nullptr && path != nullptr && IsPath(path, "interface\\cooldown\\edge.blp"))
|
|
handle = CreateFromPixels(path, kEdgeSize, kEdgeSize, g_edge.texels, flags);
|
|
return handle;
|
|
}
|
|
|
|
const Game::HookAutoRegister _createFromBlpHook{Offsets::FUN_TEXTURE_CREATE_FROM_BLP,
|
|
reinterpret_cast<void *>(&CreateFromBlp_h),
|
|
reinterpret_cast<void **>(&CreateFromBlp_o)};
|
|
|
|
} // namespace
|
|
|
|
} // namespace Texture::Builtin
|