📄 cooldowncount.lua
字号:
-- Constants
COOLDOWNCOUNT_CUTOFF_TIME = 2; -- how many seconds the cooldown has to be for CooldownCount to be displayed
COOLDOWNCOUNT_HOUR_MINUTES_FORMAT_LIMIT = 3600;
COOLDOWNCOUNT_MINUTES_SECONDS_FORMAT_LIMIT = 60;
COOLDOWNCOUNT_WIDTH = 64;
COOLDOWNCOUNT_HEIGHT = 32;
-- how many seconds between updates
COOLDOWNCOUNT_UPDATE_TIME = 0.25;
-- how many seconds the flashing will occur (maximum)
COOLDOWNCOUNT_MAXIMUM_FLASH_TIME = 10;
-- Variables
CooldownCount_NoSpaces = 1;
CooldownCount_Enabled = 1;
CooldownCount_UseLongTimerDescriptions = 0;
CooldownCount_UseLongTimerDescriptionsForSeconds = 0;
CooldownCount_TimeBetweenFlashes = 0.3;
CooldownCount_HideUntilTimeLeft = 0;
CooldownCount_RogueStealth = 1;
CooldownCount_Saved_CooldownFrame_SetTimer = nil;
CooldownCount_Cosmos_Registered = 0;
CooldownCount_LastUpdate = 0;
CooldownCount_UserScale = 1.7;
CooldownCount_FramesAndTheirButtonNames = {
};
CooldownCountColorDefaultNormal = { 1.0, 0.82, 0.0 };
CooldownCountColorDefaultFlash = { 1.0, 0.12, 0.12 };
CooldownCountAlpha = 1.0;
CooldownCountOptions = {
color = {
normal = { 1.0, 0.82, 0.0 };
flash = { 1.0, 0.12, 0.12 };
};
alpha = 1.0;
};
CooldownCount_ButtonNames = {
"ActionButton", "BonusActionButton",
"MultiBarBottomLeftButton", "MultiBarBottomRightButton", "MultiBarRightButton", "MultiBarLeftButton",
};
CooldownCount_DisplayValues_WithSpace = nil;
CooldownCount_DisplayValues_WithoutSpace = nil;
function CooldownCount_PrecalcDisplayValues()
CooldownCount_DisplayValues_WithSpace = {};
CooldownCount_DisplayValues_WithoutSpace = {};
for i = 1, 60 do
CooldownCount_DisplayValues_WithSpace[i] = i.."";
CooldownCount_DisplayValues_WithoutSpace[i] = i.."";
CooldownCount_DisplayValues_WithSpace[i*60] = i.." m";
CooldownCount_DisplayValues_WithoutSpace[i*60] = i.."m";
end
for i = 1, 96 do
CooldownCount_DisplayValues_WithSpace[i*60*60] = i.." h";
CooldownCount_DisplayValues_WithoutSpace[i*60*60] = i.."h";
end
end
-- executed on load, calls general set-up functions
function CooldownCount_OnLoad()
CooldownCount_PrecalcDisplayValues();
CooldownCount_Register();
local f = CooldownCountFrame;
f:RegisterEvent("VARIABLES_LOADED");
end
function COOLDOWNCOUNT_ROGUE_STEALTH_Enabled(toggle)
CooldownCount_RogueStealth = toggle;
gLim_COOLDOWNCOUNT_USELONGTIMERS = toggle;
end
function Glim_CooldownCount_Register()
gLim_RegisterButton (
"Cooldown Count",
"冷却时间",
"Interface\\AddOns\\CooldownCount\\Icon",
function()
gLimModSecBookShowConfig("gLimCooldown");
end,
2,
4
);
gLim_RegisterConfigClass(
"gLimCooldown",
"Combat Sct",
"黑眼圈"
);
gLim_RegisterConfigSection(
"gLimCooldownSection",
COOLDOWNCOUNT_CONFIG_HEADER,
COOLDOWNCOUNT_CONFIG_HEADER.." by Pigbaby(gLim开发小组)",
"Pigbaby",
"gLimCooldown"
);
gLim_RegisterConfigCheckBox(
"gLim_COOLDOWNCOUNT_ENABLED",
COOLDOWNCOUNT_ENABLED,
COOLDOWNCOUNT_ENABLED_INFO,
CooldownCount_Enabled,
CooldownCount_Toggle_Enabled,
"gLimCooldown"
);
CooldownCount_UseLongTimerDescriptions = 0;
gLim_RegisterConfigCheckBox(
"gLim_COOLDOWNCOUNT_USELONGTIMERS",
COOLDOWNCOUNT_ROGUE_STEALTH,
COOLDOWNCOUNT_ROGUE_STEALTH_INFO,
CooldownCount_RogueStealth,
COOLDOWNCOUNT_ROGUE_STEALTH_Enabled,
"gLimCooldown"
);
--Maybe delete
gLim_RegisterConfigCheckBox(
"gLim_COOLDOWNCOUNT_RogueStealth",
COOLDOWNCOUNT_USELONGTIMERS,
COOLDOWNCOUNT_USELONGTIMERS_INFO,
CooldownCount_UseLongTimerDescriptions,
CooldownCount_Toggle_UseLongTimers,
"gLimCooldown"
);
gLim_RegisterConfigSlider(
"gLim_COOLDOWNCOUNT_FLASHSPEED",
COOLDOWNCOUNT_FLASHSPEED,
COOLDOWNCOUNT_FLASHSPEED_INFO,
COOLDOWNCOUNT_FLASHSPEED_SLIDER_DESCRIPTION,
COOLDOWNCOUNT_FLASHSPEED_SLIDER_APPEND,
0.1,
0.1,
1,
CooldownCount_TimeBetweenFlashes,
CooldownCount_SetFlashSpeed,
"gLimCooldown"
);
gLim_RegisterConfigSlider(
"gLim_COOLDOWNCOUNT_FLASHSCALE",
COOLDOWNCOUNT_USERSCALE,
COOLDOWNCOUNT_USERSCALE_INFO,
COOLDOWNCOUNT_USERSCALE_SLIDER_DESCRIPTION,
COOLDOWNCOUNT_USERSCALE_SLIDER_APPEND,
0.1,
0.8,
3,
CooldownCount_UserScale,
CooldownCount_SetUserScale,
"gLimCooldown"
);
CooldownCount_Registered = 1;
gLim_RegisterConfigButton(
"gLim_CDColor_bind",
"",
"设置技能冷却的正常显示颜色",
"设置颜色",
function()
CooldownCount_NormalColorSetButton();
gLimConfigSubFrame:Hide();
end,
"gLimCooldown"
);
end
function CooldownCount_SetFlashSpeed(speed, quiet)
if ( speed ) then
if ( speed ~= CooldownCount_TimeBetweenFlashes ) then
CooldownCount_TimeBetweenFlashes = speed;
end
end
end
function CooldownCount_SetHideUntilTimeLeft(value, quiet)
if ( value ) then
if ( CooldownCount_HideUntilTimeLeft ~= value ) then
if ( not quiet ) then
CooldownCount_Print(format(COOLDOWNCOUNT_CHAT_HIDEUNTILTIMELEFT, value));
end
CooldownCount_HideUntilTimeLeft = value;
CooldownCount_DoUpdate(true);
end
end
end
function CooldownCount_SetUserScale(scale, quiet)
if ( scale ) then
if ( scale ~= CooldownCount_UserScale ) then
CooldownCount_UserScale = scale;
CooldownCount_DoUpdate(true);
end
end
end
function CooldownCount_CooldownFrame_SetTimer(this, start, duration, enable)
CooldownCount_Saved_CooldownFrame_SetTimer(this, start, duration, enable);
CooldownCount_UpdateCooldownCount(this, start, duration, enable);
end
function CooldownCount_GenerateButtonUpdateList()
local updateList = {};
local name = nil;
for k, v in CooldownCount_ButtonNames do
for i = 1, 48 do
name = v..i;
if ( getglobal(name) ) then
table.insert(updateList, name);
end
end
end
return updateList;
end
CooldownCount_ButtonUpdateList = nil;
function CooldownCount_RegenerateList()
CooldownCount_ButtonUpdateList = CooldownCount_GenerateButtonUpdateList();
end
function CooldownCount_DoUpdate(force)
local curTime = GetTime();
if ( not CooldownCount_ButtonUpdateList ) then
CooldownCount_RegenerateList();
end
for k, v in CooldownCount_ButtonUpdateList do
CooldownCount_DoUpdateCooldownCount(v, force);
end
CooldownCount_LastUpdate = curTime;
end
function CooldownCount_OnUpdate(elapsed)
local curTime = GetTime();
if ( ( CooldownCount_LastUpdate ) and ( CooldownCount_LastUpdate > 0 ) ) then
if ( ( CooldownCount_LastUpdate + COOLDOWNCOUNT_UPDATE_TIME) < curTime ) then
CooldownCount_DoUpdate();
end
else
CooldownCount_LastUpdate = curTime;
end
end
function CooldownCount_GetFormattedNumber(number)
if (strlen(number) < 2 ) then
return "0"..number;
else
return number;
end
end
function CooldownCount_GetFormattedTime(time)
local newTime = math.floor(time);
local formattedTime = "";
local arr = CooldownCount_DisplayValues_WithSpace;
if ( CooldownCount_NoSpaces == 1 ) then arr = CooldownCount_DisplayValues_WithoutSpace; end
if ( newTime > COOLDOWNCOUNT_HOUR_MINUTES_FORMAT_LIMIT ) then
local hours = 0;
if ( CooldownCount_UseLongTimerDescriptions == 1 ) then
hours = math.floor((newTime / 3600));
local minutes = math.floor( (( newTime - ( 3600 * hours ) ) / 60) + 0.5 );
formattedTime = format(COOLDOWNCOUNT_HOUR_MINUTES_FORMAT, hours, CooldownCount_GetFormattedNumber(minutes));
else
hours = math.floor((newTime / 3600)+0.5);
--formattedTime = format(COOLDOWNCOUNT_HOURS_FORMAT, hours);
formattedTime = arr[hours*3600];
end
elseif ( newTime > COOLDOWNCOUNT_MINUTES_SECONDS_FORMAT_LIMIT ) then
local minutes = 0;
if ( CooldownCount_UseLongTimerDescriptions == 1 ) then
minutes = math.floor( ( newTime / 60 ));
local seconds = math.ceil( newTime - ( 60 * minutes ));
formattedTime = format(COOLDOWNCOUNT_MINUTES_SECONDS_FORMAT, minutes, CooldownCount_GetFormattedNumber(seconds));
else
minutes = math.ceil( ( newTime / 60 ));
--formattedTime = format(COOLDOWNCOUNT_MINUTES_FORMAT, minutes);
formattedTime = arr[minutes*60];
end
else
--[[
if ( CooldownCount_UseLongTimerDescriptionsForSeconds == 1 ) then
formattedTime = format(COOLDOWNCOUNT_SECONDS_LONG_FORMAT, newTime);
else
--formattedTime = format(COOLDOWNCOUNT_SECONDS_FORMAT, newTime);
formattedTime = arr[newTime];
end
]]--
formattedTime = format(COOLDOWNCOUNT_SECONDS_FORMAT, newTime);
end
return formattedTime;
end
--/script CooldownCount_CooldownFrame_SetTimer(getglobal("SecondActionButton3Cooldown"), 544630, 300, 1);
--/script getglobal("SecondActionButton3CooldownCount"):SetText("15"); getglobal("SecondActionButton3CooldownCount"):Show();
--/script Print(getglobal("SecondActionButton3CooldownCount"):GetText());
CooldownCount_OneLetterScale = 1.5;
CooldownCount_TwoLetterScale = 1;
CooldownCount_ThreeLetterScale = 0.66;
CooldownCount_FourLetterScale = 0.5;
CooldownCount_PrecalculatedSizes = {
[1] = 1,
[2] = 0.8,
[3] = 0.7,
[4] = 0.5,
[5] = 0.4
};
function CooldownCount_GetAppropriateScale(newTime, noAutoScale)
if ( not newTime ) then
newTime = "";
end
local lenWithoutSpaces = strlen(string.gsub(newTime, " ", ""));
local len = strlen(newTime);
local lenSpaces = len-lenWithoutSpaces;
local scale = (2 / (lenWithoutSpaces + floor(lenSpaces/2)));
if ( noAutoScale ) then
scale = 1;
else
if ( lenWithoutSpaces < len ) then
scale = (2 / len);
end
if ( CooldownCount_PrecalculatedSizes[len] ) then
scale = CooldownCount_PrecalculatedSizes[len];
else
for k, v in CooldownCount_PrecalculatedSizes do
if ( k >= len ) then
scale = v;
break;
end
end
end
end
if ( scale > 1 ) then scale = 1; end
if ( CooldownCount_UserScale ) and ( CooldownCount_UserScale > 0 ) then
scale = scale * CooldownCount_UserScale;
end
if ( not noAutoScale ) then if ( scale > 2 ) then scale = 2; end end
if ( noAutoScale ) then if ( scale > 2 ) then scale = 2; end end
return scale;
end
CooldownCount_BasePosition = "CENTER";
CooldownCount_RelativeToPosition = "CENTER";
function CooldownCount_DoUpdateCooldownCount(name, force)
local cooldownName = name.."Cooldown";
local parent = getglobal(name);
local icon = getglobal(name.."Icon");
local buttonCooldown = getglobal(cooldownName);
local cooldownCount = getglobal(cooldownName.."Count");
local cooldownCountFrame = getglobal(cooldownName.."CountFrame");
local debug = false;
if ( ( ( not parent ) or ( not parent:IsVisible() ) ) or ( ( icon ) and ( not icon:IsVisible() ) ) ) then
if ( cooldownCount ) then
cooldownCount:Hide();
end
if ( cooldownCountFrame ) then
cooldownCountFrame:Hide();
end
return;
else
local frameLevel = parent:GetFrameLevel();
if ( cooldownCountFrame ) then
cooldownCountFrame:SetFrameLevel(frameLevel+4);
end
if ( cooldownCount ) then
cooldownCount:SetWidth(COOLDOWNCOUNT_WIDTH);
cooldownCount:SetHeight(COOLDOWNCOUNT_HEIGHT);
end
end
local cooldownCountValuesName = (cooldownName.."CountValues");
local cooldownCountValues = getglobal(cooldownCountValuesName);
if ( not cooldownCountValues ) then
if ( cooldownCount ) then
cooldownCount:Hide();
end
if ( cooldownCountFrame ) then
cooldownCountFrame:Hide();
end
return;
end
local start = cooldownCountValues[1];
local duration = cooldownCountValues[2];
local enable = cooldownCountValues[3];
if ( (CooldownCount_Enabled == 1) and ( start > 0 and duration > 0) ) then
local remainingTimeCutOff = COOLDOWNCOUNT_CUTOFF_TIME;
local remainingTime = -1;
local flashTimeMax = COOLDOWNCOUNT_MAXIMUM_FLASH_TIME;
local flashTime = duration / 4;
if ( flashTime > flashTimeMax ) then
flashTime = flashTimeMax;
end
if ( start <= 0 ) then
remainingTime = -1;
else
remainingTime = ceil(( start + duration ) - GetTime());
end
if ( ( cooldownCount ) and ( cooldownCountFrame ) ) then
--Print(format("Remaining time : %d", remainingTime));
if ( ( not cooldownCount:IsVisible() ) and ( duration <= remainingTimeCutOff ) ) then
--if ( debug ) then Print("cut off engaged lixom"); end
return;
end
if ( ( remainingTime <= 0 ) ) then
if ( cooldownCount:IsVisible() ) then
cooldownCount:Hide();
end
if ( cooldownCountFrame:IsVisible() ) then
cooldownCountFrame:Hide();
end
else
if ( CooldownCount_HideUntilTimeLeft > 0 ) then
if ( CooldownCount_HideUntilTimeLeft < remainingTime ) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -