⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countdoomlayout.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:

            --
            -- Set button width
            --
            local width = CDL.button.width;
            if CDL[overrideString] ~= nil and
                CDL[overrideString].width ~= nil then
                width = CDL[overrideString].width;
            end;

            if width ~= nil then
                obj:SetWidth(width);
            end;

            --
            -- Set button height
            --
            local height = CDL.button.height;
            if CDL[overrideString] ~= nil and
                CDL[overrideString].height ~= nil then
                height = CDL[overrideString].height;
            end;

            if height ~= nil then
                obj:SetHeight(height);
            end;

            --
            -- Button visibility is determined by an active timer.
            -- Not sure we should be setting here.
            --
        end;

        prevObj = obj;        
    end;
end;


CountDoomLayout.LoadTextSettings = function( CDL )
    local buttonID = 0;
    local prevObj = nil;

    if CDL.button == nil then
        CountDoom.ChatPrint( "No button settings found." );
        return;
    end;

    for buttonID = 0, CDTimer_maxButtons - 1 do
        local obj = getglobal( "CDTimerButton" .. buttonID .. "_DurationText" );
        
        if obj ~= nil then

            local point = CDL.text.point;
            local relativeObjectString = CDL.text.relativeObject;
            local relativePoint = CDL.text.relativePoint;
            local xoffset = CDL.text.xoffset;
            local yoffset = CDL.text.yoffset;

            if relativeObjectString == "previous" then
                relativeObject = prevObj;
            elseif relativeObjectString == "frame" then
                relativeObject = CountDoomFrame;
            elseif relativeObjectString == "button" then
                relativeObject = getglobal( "CDTimerButton" .. buttonID );
            else
                relativeObject = getglobal( relativeObjectString );
            end;

            if  point ~= nil and
                relativeObject ~= nil and
                relativePoint ~= nil and
                xoffset ~= nil and
                yoffset ~= nil then
                --
                -- Set this button's anchor information
                obj:ClearAllPoints();
                obj:SetPoint(point, relativeObject, relativePoint, xoffset, yoffset);
            end;

            --
            -- Set width
            --
            local width = CDL.text.width;
            if width ~= nil then
                obj:SetWidth(width);
            end;

            --
            -- Set height
            --
            local height = CDL.text.height;
            if height ~= nil then
                obj:SetHeight(height);
            end;

            --
            -- Set visibility
            --
            local visible = CDL.text.visible;
            if visible then
                obj:Show();
            else
                obj:Hide();
            end;
        end;

        prevObj = obj;        
    end;

end;


CountDoomLayout.LoadIconSettings = function( CDL )
    local buttonID = 0;
    local prevObj = nil;

    if CDL.button == nil then
        CountDoom.ChatPrint( "No button settings found." );
        return;
    end;

    for buttonID = 0, CDTimer_maxButtons - 1 do
        local obj = getglobal( "CDTimerButton" .. buttonID .. "_Icon" );
        
        if obj ~= nil then
            local width = CDL.texture.width;
            if width ~= nil then
                obj:SetWidth(width);
            end;

            local height = CDL.texture.height;
            if height ~= nil then
                obj:SetHeight(height);
            end;

            local visible = CDL.texture.visible;
            if visible then
                obj:Show();
            else
                obj:Hide();
            end;
        end;

        prevObj = obj;        
    end;
end;


-- Function to load a layout
CountDoomLayout.Load = function ( layout )
    if layout == nil then
        CountDoom.ChatPrint( "nil passed to CountDoomLayout.Load" );
        return;
    end;

    local CDL = CountDoomLayouts[ layout ];
    if CDL == nil then
        CountDoom.ChatPrint( "Layout " .. layout .. " not found." );
        return;
    end;

    CountDoomLayout.LoadFrameSettings( CDL );
    CountDoomLayout.LoadButtonSettings( CDL );
    CountDoomLayout.LoadTextSettings( CDL );
    CountDoomLayout.LoadIconSettings( CDL );

    CountDoom.ChatPrint( "Layout " .. layout .. " loaded." );
end;


CountDoomLayout.Delete = function ( layout )
    if layout == nil then
        CountDoom.ChatPrint( "nil passed to CountDoomLayout.Delete" );
        return;
    end;

    if CountDoomLayouts[ layout ] == nil then
        CountDoom.ChatPrint( "Layout " .. layout .. " not found." );
        return;
    end;

    CountDoomLayouts[ layout ] = nil;

    CountDoom.ChatPrint( "Layout " .. layout .. " deleted." );
end;


function CDIcon_Update(arg1)
end;


CountDoomLayout.textTable = {};


CountDoomLayout.GetRemainingTime = function( timerIndex, countDown )
    local minutes = 0;
    local seconds = 0;
    local hseconds = 0;

    if( CDTimers[ timerIndex ] == nil ) then
        CountDoom.DebugPrint( "Invalid timerIndex in CountDoomLayout.textTable: " .. timerIndex );
        return minutes, seconds, hseconds;
    end
    
    local currentTime = GetTime();
    local rawDelta = currentTime - CDTimers[ timerIndex ].startTime;
    local duration = CDTimers[ timerIndex ].duration;
    local warningTime = CDTimers[ timerIndex ].warningTime;

    local delta = floor(rawDelta);
    if( delta > duration ) then
        delta = duration;
    end
    
    -- Invert for count down situations
    local timeDelta = rawDelta;
    if( countDown ) then
        timeDelta = duration - rawDelta;
    end

    local signScalar = 1;
    if timeDelta < 0 then
        signScalar = -1;
        timeDelta = -timeDelta;
    end

    local minutes = signScalar * floor(timeDelta/60);
    local seconds = floor(math.mod(timeDelta, 60));
    local hseconds = floor(math.mod(floor(rawDelta*100), 100));

    return minutes, seconds, hseconds;
end;


CountDoomLayout.textTable[ "$t1" ] = function( textStr, timerIndex )
    local countDown = CDTimers[ timerIndex ].countDown;
    local minutes, seconds, hseconds = CountDoomLayout.GetRemainingTime( timerIndex, countDown );

    local timeText = "" .. minutes;
	textStr = string.gsub(textStr, '$t1', timeText);
	return textStr;
end;


CountDoomLayout.textTable[ "$t2" ] = function( textStr, timerIndex )
    local countDown = CDTimers[ timerIndex ].countDown;
    local minutes, seconds, hseconds = CountDoomLayout.GetRemainingTime( timerIndex, countDown );

    local timeText = "";
    if (seconds >= 10) then
        timeText = minutes .. ":" .. seconds;
    else
        timeText = minutes .. ":0" .. seconds;
    end

	textStr = string.gsub(textStr, '$t2', timeText);
	return textStr;
end;


CountDoomLayout.textTable[ "$t3" ] = function( textStr, timerIndex )
    local countDown = CDTimers[ timerIndex ].countDown;
    local minutes, seconds, hseconds = CountDoomLayout.GetRemainingTime( timerIndex, countDown );

    local timeText = "";
    if (seconds >= 10) then
        timeText = minutes .. ":" .. seconds;
    else
        timeText = minutes .. ":0" .. seconds;
    end

    local htimeText = "";
    if (hseconds >= 10) then
        htimeText = "." .. hseconds;
    else
        htimeText = ".0" .. hseconds;
    end

	textStr = string.gsub(textStr, '$t3', timeText .. htimeText);
	return textStr;
end;


function CDText_Update(arg1)
    --[[
    if( CDTimers[ timerIndex ] == nil ) then
        CountDoom.DebugPrint( "Invalid timerIndex in CountDoomLayout.textTable: " .. timerIndex );
        return;
    end
    --]]
end;


CDLTest = function()
    CountDoomLayout.Load( "NotFoundLayout" );
    CountDoomLayout.Load( "horizontal" );
    CountDoomLayout.Load( "vertical" );
    CountDoomLayout.Load( "textonly" );

    --CountDoomLayout.Delete( "textonly" );

    CountDoomLayout.Load( "horizontal" );
    CountDoomLayout.Load( "vertical" );
    CountDoomLayout.Load( "textonly" );
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -