WoWInterface SVN Broker_Wintergrasp

[/] [trunk/] [Broker_Wintergrasp/] [Broker_Wintergrasp.lua] - Rev 4

Compare with Previous | Blame | View Log

local locale = GetLocale()
local dummy = CreateFrame('Frame')
local math_floor = math.floor
local string_format = string.format
local UPDATEPERIOD = 5

local broker = LibStub:GetLibrary('LibDataBroker-1.1'):NewDataObject('Broker_Wintergrasp', {
        type = 'data source',
        text = 'Wintergrasp',
        icon = 'Interface\\Icons\\ACHIEVEMENT_WIN_WINTERGRASP',
        iconCoords = {0.065, 0.935, 0.065, 0.935}
})

local MINUTES, SECONDS, HOUR, UNKNOWN, TIMEUNTIL, BEGINS, ERROR
if(locale == 'frFR') then
        -- todo
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
elseif(locale == 'deDE') then
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minuten', 'sekunden', 'stunde', 'Unbekannt'
        TIMEUNTIL = 'Zeit bis zum n\195\164chsten kampf:'
        BEGINS = 'Tausendwinter startet in '
        ERROR = 'Du musst dich in Nordend befinden, um die zeit sehen zu k\195\182nnen'
elseif(locale == 'koKR') then
        -- todo
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
elseif(locale == 'zhCN') then
        -- todo
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
elseif(locale == 'zhTW') then
        -- todo
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
elseif(locale == 'ruRU') then
        -- todo
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
elseif(locale == 'esES') then
        -- todo
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
elseif(locale == 'esMX') then
        -- todo
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
else
        MINUTES, SECONDS, HOUR, UNKNOWN = 'minutes', 'seconds', 'hour', 'Unknown'
        LEFTMOUSE, RIGHTMOUSE = 'Left-click to print time left to chat', 'Right-click to exit Wintergrasp'
        TIMEUNTIL = 'Time until next battle:'
        BEGINS = 'Wintergrasp begins in '
        ERROR = 'You must be in Northrend to see the time'
end

local function TimeAbbrev(time, short)
        if(not time) then
                return ''
        elseif(time < 60) then
                if(short) then
                        return string_format('%d', time)
                else
                        return string_format('%d %s', time, SECONDS)
                end
        elseif(time < 3600) then
                if(short) then
                        return string_format('%d:%02d', math_floor(time / 60), time % 60)
                else
                        return string_format('%d %s %d %s', math_floor(time / 60), MINUTES, time % 60, SECONDS)
                end
        else
                local min = math_floor(time / 60)
                if(short) then
                        return string_format('%d:%02d:%02d', math_floor(min / 60), min % 60, time % 60)
                else
                        return string_format('%d %s %d %s %d %s', math_floor(min / 60), HOUR, min % 60, MINUTES, time % 60, SECONDS)
                end
        end
end

function broker.OnClick(self, button)
        if(not GetWintergraspWaitTime()) then return end

        if(button == 'RightButton' and CanHearthAndResurrectFromArea()) then
                HearthAndResurrectFromArea()
        else
                if(ChatFrameEditBox:IsShown()) then
                        local text = ChatFrameEditBox:GetText()
                        ChatFrameEditBox:SetText(text..TimeAbbrev(GetWintergraspWaitTime(), true))
                else
                        ChatFrame_OpenChat(BEGINS..TimeAbbrev(GetWintergraspWaitTime()))
                end
        end
end

function broker.OnTooltipShow(self)
        local timeLeft = GetWintergraspWaitTime()
        self:AddLine('|cff0090ffBroker Wintergrasp|r')
        if(timeLeft) then
                self:AddLine(string_format('%s %s', TIMEUNTIL, TimeAbbrev(timeLeft)))
        else
                self:AddLine(string_format('%s %s', TIMEUNTIL, UNKNOWN))
                self:AddLine(ERROR)
        end
        self:AddLine('')
        self:AddLine(LEFTMOUSE)
        if(CanHearthAndResurrectFromArea()) then
                self:AddLine(RIGHTMOUSE)
        end
end

dummy:SetScript('OnUpdate', function(self, elapsed)
        if(UPDATEPERIOD) then
                UPDATEPERIOD = UPDATEPERIOD - elapsed
                if(UPDATEPERIOD <= 0) then
                        UPDATEPERIOD = 5
                else
                        broker.text = string.format('%s', GetWintergraspWaitTime() and TimeAbbrev(GetWintergraspWaitTime(), true) or 'Wintergrasp')
                end
        end
end)


-- GetWintergraspWaitTime() returns in seconds
-- Show something else if a battle is going on
-- If WG is going on, and the player is in the zone, make the right click work as 'Leave Battleground'

Compare with Previous | Blame