📄 countdoomtimer.lua
字号:
function CDTimer_Create( priority, duration )
local timerIndex = -1;
timerIndex = CDTimer_GetInsertionIndex( priority, duration );
CountDoom.DebugPrint( "CDTimer_Create: Insertion Index is " .. timerIndex );
CDTimer_Constructor( timerIndex );
CDTimers[ timerIndex ].priority = priority;
CDTimers[ timerIndex ].warningTime = duration;
CDTimers[ timerIndex ].duration = duration;
CDTimer_ShowButton( timerIndex, true );
CountDoomFrame:Show();
return timerIndex;
end
function CDTimer_Destroy( removeID )
CountDoom.DebugPrint( "Destroy: " .. removeID );
if CDTimers[ removeID ] == nil then
CountDoom.DebugPrint( "Invalid index(" .. timerIndex .. ") in CDTimer_Destroy. " .. CDTimer_numTimers );
return;
end
CDTimer_DumpAll();
if( removeID ~= ( CDTimer_numTimers - 1 ) ) then
-- shift all buttons down by one
local oldID;
for oldID = removeID + 1, CDTimer_numTimers - 1, 1 do
local newID = oldID - 1;
CountDoom.DebugPrint( "oldID: " .. oldID .. " newID: " .. newID );
CDTimer_Copy( newID, oldID );
end
end
-- Erase the button
local deleteID = CDTimer_numTimers - 1;
CDTimers[ deleteID ] = nil;
-- And hide the last one
CDTimer_ShowButton( deleteID, false );
CDTimer_numTimers = CDTimer_numTimers - 1;
if CDTimer_numTimers <= 0 then
if CountDoom.config.isLocked == true then
CountDoomFrame:Hide();
end
end
CDTimer_DumpAll();
end
function CDTimer_SetFunctionHandler( timerIndex, handlerName, funcHandler )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetFunctionHandler" );
return;
end
CountDoom.DebugPrint( "SetFunctionHandler before: " .. table.getn( CDTimers[ timerIndex ].funcHandlers ) );
CDTimers[ timerIndex ].funcHandlers[ handlerName ] = funcHandler;
CountDoom.DebugPrint( "SetFunctionHandler after: " .. table.getn( CDTimers[ timerIndex ].funcHandlers ) );
end
function CDTimer_GetRemainingTime( timerIndex )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_GetRemainingTime" );
return nil;
end
return CDTimers[ timerIndex ].duration - (GetTime() - CDTimers[ timerIndex ].startTime);
end
function CDTimer_SetWarningTime( timerIndex, warningTime )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetWarningTime" );
return;
end
CDTimers[ timerIndex ].warningTime = warningTime;
end
function CDTimer_GetWarningTime( timerIndex )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_GetWarningTime" );
return nil;
end
return CDTimers[ timerIndex ].warningTime;
end
function CDTimer_SetUserHandle( timerIndex, userHandle )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetUserHandle" );
return;
end
CDTimers[ timerIndex ].userHandle = userHandle;
end
function CDTimer_GetUserHandle( timerIndex )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_GetUserHandle" );
return nil;
end
return CDTimers[ timerIndex ].userHandle;
end
function CDTimer_SetCountDown( timerIndex, countDown )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetCountDown" );
return;
end
CDTimers[ timerIndex ].countDown = countDown;
end
function CDTimer_GetCountDown( timerIndex )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_GetCountDown" );
return nil;
end
return CDTimers[ timerIndex ].countDown;
end
function CDTimer_SetText( timerIndex, timerText, textColor )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetText" );
return;
end
local red = 1.0;
local green = 1.0;
local blue = 1.0;
if textColor ~= nil then
red = textColor["r"];
green = textColor["g"];
blue = textColor["b"];
end
CDTimers[ timerIndex ].text = timerText;
local buttonName = "CDTimerButton" .. timerIndex .. "_DurationText";
local buttonItem = getglobal( buttonName );
if( buttonItem ~= nil ) then
buttonItem:SetTextColor( red, green, blue );
buttonItem:SetText( timerText );
elseif timerIndex < CDTimer_maxButtons then
CountDoom.DebugPrint( "Unable to call " .. buttonName .. ":SetText()" );
end
end
function CDTimer_GetText( timerIndex )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_GetText" );
return nil;
end
return CDTimers[ timerIndex ].text;
end
function CDTimer_SetIcon( timerIndex, timerIcon )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetIcon" );
return;
end
CDTimers[ timerIndex ].icon = timerIcon;
local buttonName = "CDTimerButton" .. timerIndex .. "_Icon";
local buttonItem = getglobal( buttonName );
if( buttonItem ~= nil ) then
buttonItem:SetTexture( timerIcon );
elseif timerIndex < CDTimer_maxButtons then
CountDoom.DebugPrint( "Unable to call " .. buttonName .. ":SetTexture()" );
end
end
function CDTimer_GetIcon( timerIndex )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_GetIcon" );
return nil;
end
return CDTimers[ timerIndex ].icon;
end
function CDTimer_EnableFlash( timerIndex, interval )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_EnableFlash" );
return;
end
if interval <= 0 then
interval = 0.0;
end
CDTimers[ timerIndex ].flashTime = 0.0;
CDTimers[ timerIndex ].flashInterval = interval;
end
function CDTimer_SetTimerPrefix( timerIndex, prefixStr )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetTimerPrefix" );
return;
end
CDTimers[ timerIndex ].prefix = prefixStr;
end
function CDTimer_SetTimerSuffix( timerIndex, suffixStr )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_SetTimerSuffix" );
return;
end
CDTimers[ timerIndex ].suffix = suffixStr;
end
function CDTimer_DisableFlash( timerIndex )
if CDTimers[ timerIndex ] == nil then
CountDoom.DebugPrint( "Invalid timerIndex in CDTimer_DisableFlash" );
return;
end
CDTimers[ timerIndex ].flashTime = 0.0;
CDTimers[ timerIndex ].flashInterval = 0.0;
end
function CDTimer_Copy( destIndex, srcIndex )
CountDoom.DebugPrint( "CDTimer_Copy(" .. CountDoom.ToString( destIndex ) .. ", " .. CountDoom.ToString( srcIndex ) .. ")" );
if CDTimers[ srcIndex ] == nil then
CDTimers[ destIndex ] = nil;
else
if CDTimers[ destIndex ] == nil then
CDTimers[ destIndex ] = {};
end
CDTimers[ destIndex ].userHandle = CDTimers[ srcIndex ].userHandle;
CDTimers[ destIndex ].priority = CDTimers[ srcIndex ].priority;
CDTimers[ destIndex ].startTime = CDTimers[ srcIndex ].startTime;
CDTimers[ destIndex ].warningTime = CDTimers[ srcIndex ].warningTime;
CDTimers[ destIndex ].duration = CDTimers[ srcIndex ].duration;
CDTimers[ destIndex ].icon = CDTimers[ srcIndex ].icon;
CDTimers[ destIndex ].text = CDTimers[ srcIndex ].text;
CDTimers[ destIndex ].flashInterval = CDTimers[ srcIndex ].flashInterval;
CDTimers[ destIndex ].flashTime = CDTimers[ srcIndex ].flashTime;
CDTimers[ destIndex ].countDown = CDTimers[ srcIndex ].countDown;
CDTimers[ destIndex ].prefix = CDTimers[ srcIndex ].prefix;
CDTimers[ destIndex ].suffix = CDTimers[ srcIndex ].suffix;
-- Copy the event table
CDTimers[ destIndex ].funcHandlers = {};
if CDTimers[ srcIndex ].funcHandlers ~= nil then
local index;
for index=1, CDTIMEREVENT_MAXEVENTS, 1 do
CDTimers[ destIndex ].funcHandlers[ index ] = CDTimers[ srcIndex ].funcHandlers[ index ];
end
CDTimers[ srcIndex ].funcHandlers = nil;
end
-- Move the visual items
CDTimer_SetText( destIndex, CDTimers[ destIndex ].text );
CDTimer_SetIcon( destIndex, CDTimers[ destIndex ].icon );
end
-- Notify client of new timer index
CDTimer_GenericHandler( destIndex, CDTIMEREVENT_ONMOVETIMER, srcIndex );
end
function CDTimers_GetButtonSize()
if CountDoom.config.scale == "large" then
return 50;
elseif CountDoom.config.scale == "small" then
return 30;
end;
return 40;
end
function CDTimers_LayoutHorizontal()
local buttonID = 0;
local prevButton = nil;
local buttonSize = CDTimers_GetButtonSize();
for buttonID = 0, CDTimer_maxButtons - 1 do
local button = getglobal( "CDTimerButton" .. buttonID);
if button ~= nil then
if prevButton ~= nil then
button:ClearAllPoints();
button:SetPoint("TOPLEFT", prevButton, "TOPRIGHT", 0, 0);
end
local buttonTexture = getglobal( "CDTimerButton" .. buttonID .. "_Icon" );
if buttonTexture ~= nil then
buttonTexture:Show();
end
button:SetHeight(buttonSize);
button:SetWidth(buttonSize);
end
local buttonText = getglobal( "CDTimerButton" .. buttonID .. "_DurationText" );
if buttonText ~= nil then
if button ~= nil then
buttonText:ClearAllPoints();
buttonText:SetPoint("LEFT", button, "LEFT", 0, -(5 + (buttonSize/2)));
end
end
prevButton = button;
end
local numTimers = CDTimer_maxButtons;
if numTimers == 0 then
numTimers = 1;
end
CountDoomFrame:SetWidth( 5 + 5 + (buttonSize * numTimers) );
CountDoomFrame:SetHeight( 5 + 5 + buttonSize + 12 );
end
function CDTimers_LayoutVertical()
local buttonID = 0;
local prevButton = nil;
local buttonSize = CDTimers_GetButtonSize();
for buttonID = 0, CDTimer_maxButtons - 1 do
local button = getglobal( "CDTimerButton" .. buttonID);
if button ~= nil then
if prevButton ~= nil then
button:ClearAllPoints();
button:SetPoint("TOPLEFT", prevButton, "BOTTOMLEFT", 0, 0);
end
local buttonTexture = getglobal( "CDTimerButton" .. buttonID .. "_Icon" );
if buttonTexture ~= nil then
buttonTexture:Show();
end
button:SetHeight(buttonSize);
button:SetWidth(buttonSize);
end
local buttonText = getglobal( "CDTimerButton" .. buttonID .. "_DurationText" );
if buttonText ~= nil then
if button ~= nil then
buttonText:ClearAllPoints();
buttonText:SetPoint("LEFT", button, "LEFT", buttonSize + 10, -7);
end
end
prevButton = button;
end
local numTimers = CDTimer_maxButtons;
if numTimers == 0 then
numTimers = 1;
end
CountDoomFrame:SetWidth( 5 + 5 + buttonSize + 40 );
CountDoomFrame:SetHeight( 5 + 5 + ( buttonSize * numTimers ) );
end
function CDTimers_LayoutTextOnly()
local buttonID = 0;
local prevButton = nil;
local prevButtonText = nil;
for buttonID = 0, CDTimer_maxButtons - 1 do
local button = getglobal( "CDTimerButton" .. buttonID);
if button ~= nil then
if prevButton ~= nil then
button:ClearAllPoints();
button:SetPoint("TOPLEFT", prevButton, "BOTTOMLEFT", 0, 0);
end
end
if button ~= nil then
local buttonTexture = getglobal( "CDTimerButton" .. buttonID .. "_Icon" );
if buttonTexture ~= nil then
buttonTexture:Hide();
end
button:SetHeight(15);
button:SetWidth(30);
end
local buttonText = getglobal( "CDTimerButton" .. buttonID .. "_DurationText" );
if buttonText ~= nil then
buttonText:ClearAllPoints();
buttonText:SetPoint("LEFT", button, "LEFT", 0, 0);
end
prevButtonText = buttonText;
prevButton = button;
end
local numTimers = CDTimer_maxButtons;
if numTimers == 0 then
numTimers = 1;
end
CountDoomFrame:SetWidth( 5 + 5 + 250 );
CountDoomFrame:SetHeight( 5 + 5 + ( 15 * numTimers ) );
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -