WoWInterface SVN hankui

[/] [Interface/] [AddOns/] [hankui/] [elements/] [chat.lua] - Rev 17

Compare with Previous | Blame | View Log

setfenv(1, select(2, ...))

SetCVar("chatStyle", "classic")
SetCVar("showToastWindow", "0")
SetCVar("chatMouseScroll", "1")
SetCVar("conversationMode", "inline")
SetCVar("showTimestamps", "0")
AddCallback("VARIABLES_LOADED", function() _G.CHAT_TIMESTAMP_FORMAT = nil end)

local chatIcons = {}
for y = 0, 1 do
        for x = 0, 7 do
                chatIcons[y * 8 + x + 1] = "|T" .. media.misc["Chat icons"] .. ":0:0:0:0:128:32:" ..
                        (x * 16) .. ":" ..
                        ((x + 1) * 16) .. ":" ..
                        (y * 16) .. ":" ..
                        ((y + 1) * 16) .. ":" ..
                        "|t"
        end
end

-- Chat flags
_G.CHAT_FLAG_AFK = "Afk||"
_G.CHAT_FLAG_DND = "DnD||"
_G.CHAT_FLAG_GM = "GM||"

-- Chat type
_G.CHAT_SAY_GET                         = "%s:\32"
_G.CHAT_YELL_GET                        = "%s:\32"
_G.CHAT_EMOTE_GET                       = "%s\32"

_G.CHAT_WHISPER_GET                     = "%s" .. chatIcons[4] .. ":\32"
_G.CHAT_WHISPER_INFORM_GET      = chatIcons[4] .. "%s:\32"

_G.CHAT_BN_WHISPER_GET                  = "%s" .. chatIcons[4] .. ":\32"
_G.CHAT_BN_WHISPER_INFORM_GET   = chatIcons[4] .. "%s:\32"
_G.CHAT_BN_CONVERSATION_GET             = "%s:\32"

_G.CHAT_PARTY_GET                       = "%s:\32"
_G.CHAT_PARTY_GUIDE_GET         = chatIcons[6] .. "%s:\32"
_G.CHAT_PARTY_LEADER_GET        = chatIcons[2] .. "%s:\32"

_G.CHAT_RAID_GET                        = "%s:\32"
_G.CHAT_RAID_LEADER_GET         = chatIcons[3] .. "%s:\32"
_G.CHAT_RAID_WARNING_GET        = chatIcons[5] .. "%s:\32"

_G.CHAT_BATTLEGROUND_GET        = "%s:\32"
_G.CHAT_BATTLEGROUND_LEADER_GET = chatIcons[3] .. "%s:\32"

_G.CHAT_GUILD_GET                       = "%s:\32"
_G.CHAT_OFFICER_GET                     = chatIcons[1] .. "%s:\32"

_G.CHAT_MONSTER_SAY_GET         = "%s:\32"
_G.CHAT_MONSTER_WHISPER_GET     = "%s:\32"
_G.CHAT_MONSTER_YELL_GET        = "%s:\32"
_G.CHAT_MONSTER_PARTY_GET       = "%s:\32"

_G.CHAT_AFK_GET                         = "%s is Away:\32"
_G.CHAT_DND_GET                         = "%s does not wish to be disturbed:\32"

_G.CHAT_CHANNEL_LIST_GET        = "|Hchannel:CHANNEL:%d|h[%s]|h\32"
_G.CHAT_CHANNEL_GET                     = "%s:\32"
_G.CHAT_CHANNEL_JOIN_GET        = "+ %s"
_G.CHAT_CHANNEL_LEAVE_GET       = "- %s"

-- Chat editbox types
_G.CHAT_WHISPER_SEND            = "w\\%s>\32"
_G.CHAT_YELL_SEND                       = "y>\32"
_G.CHAT_BATTLEGROUND_SEND       = "bg>\32"
_G.CHAT_BN_WHISPER_SEND         = "w\\%s>\32"
_G.CHAT_CHANNEL_SEND            = "%d>\32"
_G.CHAT_EMOTE_SEND                      = "%s>\32"
_G.CHAT_GUILD_SEND                      = "g>\32"
_G.CHAT_OFFICER_SEND            = "o>\32"
_G.CHAT_PARTY_SEND                      = "p>\32"
_G.CHAT_RAID_SEND                       = "r>\32"
_G.CHAT_RAID_WARNING_SEND       = "rw>\32"
_G.CHAT_SAY_SEND                        = "s>\32"

-- Sticky channels
for k, _ in pairs(ChatTypeInfo) do
        ChatTypeInfo[k].sticky = 1
end

-- Shift scroll
local oldFloatingChatFrame_OnMouseScroll = FloatingChatFrame_OnMouseScroll
_G.FloatingChatFrame_OnMouseScroll = function(self, delta)
        if IsShiftKeyDown() then
                if delta < 0 then
                        self:ScrollToBottom()
                else
                        self:ScrollToTop()
                end
        else
                oldFloatingChatFrame_OnMouseScroll(self, delta)
        end
end

-- Modify incoming messages
local function AddMessage(self, text, ...)
        -- Remove braces
        text = text:gsub("(|H.-|h)%[(.-)%]|h", "%1%2|h")
        
        -- Replace channel names with icons
        text = text:gsub("|Hchannel.-(%d-)|h.-|h", function(channelId)
                return "|Hchannel:channel:" .. channelId .. "|h" .. chatIcons[tonumber(channelId) + 6] .. "|h"
        end)
        
        -- Remove braces from Battle.net names
        text = text:gsub("%[(|K.-|k)%]", "%1")

        -- Chat timestamp (http://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html)
        text = date("|cFFFFFFFF%H%M\226\136\153%S|r\32") .. text
        return self:oldAddMessage(text, ...)
end

-- Set up copy editbox
local copyBox = CreateFrame("EditBox", UIParent)
copyBox:SetMultiLine(true)
copyBox:SetJustifyV("BOTTOM")
copyBox:SetBackdrop({ bgFile = media.background["Flat"] })
copyBox:SetBackdropColor(unpack(colors["Background light"]))
copyBox:Hide()

copyBox:SetScript("OnEnterPressed", function(self) self:Hide() end)
copyBox:SetScript("OnEscapePressed", function(self) self:Hide() end)

-- Strip images and icons from text when copying for better readibility
-- ... and to prevent icons from messing with the line height
local copyGsub = {
        {chatIcons[1], "[O] "},
        {chatIcons[2], "[L] "},
        {chatIcons[3], "[RL] "},
        {"(.-)" .. chatIcons[4] .. ":", "%1 whispers:"},
        {chatIcons[4] .. "(.-):", "To %1:"},
        {chatIcons[5], "[RW] "},
        {chatIcons[6], "[PG] "},
}

for i = 7, 16 do
        table.insert(copyGsub, {chatIcons[i], "[" .. (i - 6) .. "]"})
end

table.insert(copyGsub, {"|H.-|h(.-)|h", "%1"})
table.insert(copyGsub, {"|T.-|t", ""})
table.insert(copyGsub, {"|c%x%x%x%x%x%x%x%x(.-)|r", "%1"})

-- Skin chat frames
for _, frame in ipairs(CHAT_FRAMES) do
        local chatFrame, buttonFrame, chatTab, editBox = _G[frame], _G[frame .. "ButtonFrame"], _G[frame .. "Tab"], _G[frame .. "EditBox"]
        local tabLeft, tabRight = _G[frame .. "TabLeft"], _G[frame .. "TabRight"]
        local tabSelMid, tabSelRight, tabText = _G[frame .. "TabSelectedMiddle"], _G[frame .. "TabSelectedRight"], _G[frame .. "TabText"]

        chatFrame:SetClampedToScreen(false)
        chatFrame.oldAddMessage = chatFrame.AddMessage
        chatFrame.AddMessage = AddMessage
        
        -- Font
        SetFont(chatFrame, fonts.masterfont, nil, nil)
        _G.CHAT_FONT_HEIGHTS = {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24}

        -- Hide all background textures
        for i = 1, 9 do select(i, chatFrame:GetRegions()):SetTexture(nil) end
        
        -- New background
        local bd = CreateFrame("Frame", frame .. "Backdrop", chatFrame)
        bd:SetPoint("LEFT", -2, 0)
        bd:SetPoint("RIGHT", 2, 0)
        bd:SetPoint("BOTTOM", 0, -6)
        bd:SetPoint("TOP", chatTab, 0, 0)
        bd:SetBackdrop({ bgFile = media.background["Flat"] })
        bd:SetBackdropColor(unpack(colors["Background"]))
        bd:SetFrameLevel(chatFrame:GetFrameLevel() > 0 and chatFrame:GetFrameLevel() - 1 or 0)
        
        bd.tex = bd:CreateTexture(nil, "BACKGROUND", nil, 1)
        bd.tex:SetAllPoints()
        bd.tex:SetTexture(media.background["hankui: Thin stripes"], true)
        bd.tex:SetHorizTile(true)
        bd.tex:SetVertTile(true)
        bd.tex:SetBlendMode("ADD")
        
        bd.hl = bd:CreateTexture(nil, "ARTWORK")
        bd.hl:SetHeight(2)
        bd.hl:SetPoint("LEFT")
        bd.hl:SetPoint("RIGHT")
        bd.hl:SetPoint("TOP", chatTab, "BOTTOM", 0, 1)
        bd.hl:SetTexture(media.background["hankui: Horizontal line"], true)
        bd.hl:SetTexCoord(0, 1, 0, 0.25)
        bd.hl:SetVertexColor(unpack(colors["Background light"]))
        
        -- Chat tabs
        chatTab:SetHeight(24)
        chatTab:SetAlpha(0)
        chatTab.mouseOverAlpha = 1
        chatTab.noMouseAlpha = 0
        
        for i = 1, 10 do select(i, chatTab:GetRegions()):SetTexture(nil) end
        tabSelMid:SetTexture(media.background["Flat"])
        tabSelMid:SetBlendMode("BLEND")
        tabSelMid:SetVertexColor(unpack(colors["Background light"]))
        tabSelMid.SetVertexColor = function() end
        tabSelMid:ClearAllPoints()
        tabSelMid:SetAllPoints()
        
        -- New tab title independent from tab alpha
        tabText:Hide()
        chatFrame.caption = UIParent:CreateFontString(nil, "OVERLAY")
        chatFrame.caption:SetAllPoints(chatTab)
        chatFrame.caption:SetFontObject("ChatTabFontNormal")
        chatFrame.caption:SetShadowOffset(1.25, -1.25)
        chatFrame.caption:SetShadowColor(unpack(colors["Background"]))
        if not chatTab:IsShown() then chatFrame.caption:Hide() end
        chatTab:SetScript("OnShow", function() chatFrame.caption:Show() end)
        chatTab:SetScript("OnHide", function() chatFrame.caption:Hide() end)
        
        -- Turn right texture into arrow
        tabSelRight:SetTexture(media.misc["Chat tab"])
        tabSelRight:SetTexCoord(0, 21 / 32, 0, 10 / 16)
        tabSelRight:SetBlendMode("BLEND")
        tabSelRight:SetVertexColor(unpack(colors["Background light"]))
        tabSelRight.SetVertexColor = function() end
        tabSelRight:SetSize(21, 10)
        tabSelRight:ClearAllPoints()
        tabSelRight:SetPoint("TOP", tabSelMid, "BOTTOM")
        
        -- Hide chat buttons
        buttonFrame:Hide()
        buttonFrame.Show = buttonFrame.Hide
        
        -- Editbox changes
        editBox:SetAltArrowKeyMode(false)
        editBox:SetBlinkSpeed(0.25)
        editBox:ClearAllPoints()
        editBox:SetPoint("LEFT", chatFrame)
        editBox:SetPoint("RIGHT", chatFrame)
        editBox:SetPoint("BOTTOM", chatTab, "TOP")
        
        for _, tex in ipairs({"Left", "Right", "Mid", "FocusLeft", "FocusRight", "FocusMid"}) do
                _G[frame .. "EditBox" .. tex]:SetTexture(nil)
        end
        
        -- Editbox animation
        local editBoxAnimIn = editBox:CreateAnimationGroup()
        local fadeIn = editBoxAnimIn:CreateAnimation("Alpha")
        fadeIn:SetChange(1)
        fadeIn:SetDuration(1)
        fadeIn:SetSmoothing("IN_OUT")
        fadeIn:SetOrder(0)
        
        editBoxAnimIn:SetScript("OnFinished", function() editBox:SetAlpha(1) end)
        editBox:HookScript("OnHide", function() if editBoxAnimIn:IsPlaying() then editBoxAnimIn:Stop() end end)
        editBox:HookScript("OnShow", function()
                editBox:SetAlpha(0)
                editBoxAnimIn:Play()
        end)

        -- Copy button
        local copyFrame = CreateFrame("Frame", frame .. "Copypasta", chatFrame)
        copyFrame:SetSize(16, 16)
        copyFrame:SetPoint("RIGHT", -3, 0)
        copyFrame:SetPoint("TOP", chatTab, 0, -3)
        
        copyFrame.btn = CreateFrame("Button", nil, copyFrame)
        copyFrame.btn:SetAllPoints()
        copyFrame.btn:SetNormalTexture(media.button["Copypasta"])
        copyFrame.btn:SetHighlightTexture(media.button["Copypasta"], "BLEND")
        copyFrame.btn:GetNormalTexture():SetVertexColor(unpack(colors["Signature color"]))
        copyFrame.btn:GetHighlightTexture():SetVertexColor(unpack(colors["White"]))
        
        copyFrame.btn:SetScript("OnClick", function()
                if copyBox:IsShown() then
                        copyBox:Hide()
                else
                        local text, firstLine = "", true
                        for i = select("#", chatFrame:GetRegions()), 1, -1 do
                                local r = select(i, chatFrame:GetRegions())
                                if r:GetObjectType() == "FontString" then
                                        local lineText = r:GetText()
                                        for _, repTbl in pairs(copyGsub) do
                                                lineText = lineText:gsub(repTbl[1], repTbl[2])
                                        end
                                        text = text .. (firstLine and "" or "\n") .. lineText
                                        firstLine = false
                                end
                        end
                        copyBox:SetText(text)

                        local font, size, flags = chatFrame:GetFont()
                        copyBox:SetFont(font, FixedScale(size), flags)
                        copyBox:ClearAllPoints()
                        copyBox:SetPoint("TOP", bd.hl)
                        copyBox:SetPoint("LEFT", bd)
                        copyBox:SetPoint("RIGHT", bd)
                        copyBox:SetPoint("BOTTOM", bd)
                        copyBox:Show()
                end
        end)
        
end

FriendsMicroButton:Hide()
ChatFrameMenuButton:Hide()
_G.ChatFrameMenuButton.Show = ChatFrameMenuButton.Hide

-- Mouse over alpha
_G.DEFAULT_CHATFRAME_ALPHA = 0.85
-- Tab alpha
_G.CHAT_FRAME_TAB_SELECTED_MOUSEOVER_ALPHA = 1
_G.CHAT_FRAME_TAB_SELECTED_NOMOUSE_ALPHA = 0
-- Time (in seconds) to wait before fading in after cursor entered ChatFrame
_G.CHAT_TAB_SHOW_DELAY = 0.2
-- Time to wait before fading out after cursor left ChatFrame
_G.CHAT_TAB_HIDE_DELAY = 0.25
-- Duration of fade out animation
_G.CHAT_FRAME_FADE_OUT_TIME = 0.5

-- Add custom elements to the region table (processed by FloatingChatFrame functions)
table.insert(_G.CHAT_FRAME_TEXTURES, "Backdrop")
table.insert(_G.CHAT_FRAME_TEXTURES, "Copypasta")

-- Keep the UI from messing with our alpha values
local oldFCF_SetWindowAlpha = FCF_SetWindowAlpha
_G.FCF_SetWindowAlpha = function(frame, alpha, doNotSave) oldFCF_SetWindowAlpha(frame, 0, true) end

-- Intercept UI functions to set up our new tab titles
local oldFCF_SetWindowName = FCF_SetWindowName
_G.FCF_SetWindowName = function(frame, name, doNotSave)
        -- Set tab title text
        frame.caption:SetText(name)
        oldFCF_SetWindowName(frame, name, doNotSave)
end

local oldFCFTab_UpdateColors = FCFTab_UpdateColors
_G.FCFTab_UpdateColors = function(self, selected)
        -- Color tab title
        local title = _G[self:GetName():match("(.-)Tab")].caption
        title:SetTextColor(unpack(colors[selected and "White" or "Signature color"]))
        oldFCFTab_UpdateColors(self, selected)
end

local oldFCF_SetTabPosition = FCF_SetTabPosition
_G.FCF_SetTabPosition = function(chatFrame, x)
        -- First tab on new dock, set Y distance
        local chatTab = _G[chatFrame:GetName() .. "Tab"]
        chatTab:ClearAllPoints()
        chatTab:SetPoint("BOTTOMLEFT", chatFrame:GetName() .. "Background", "TOPLEFT", x + 2, 10)
end

-- First tab of general dock, set Y distance
GeneralDockManager:SetPoint("BOTTOMLEFT", ({GeneralDockManager:GetPoint(1)})[2], "TOPLEFT", 0, 10)

-- Skin combatlog header
CallAfter("Blizzard_CombatLog", function()
        CombatLogQuickButtonFrame_Custom:SetFrameLevel(0)
        CombatLogQuickButtonFrame_CustomTexture:Hide()
        CombatLogQuickButtonFrame_CustomProgressBar:SetHeight(2)
        CombatLogQuickButtonFrame_CustomProgressBar:SetStatusBarTexture(media.background["Flat"])
        CombatLogQuickButtonFrame_CustomProgressBar:SetStatusBarColor(unpack(colors["Signature color"]))
        
        local oldBlizzard_CombatLog_Update_QuickButtons = Blizzard_CombatLog_Update_QuickButtons
        _G.Blizzard_CombatLog_Update_QuickButtons = function()
                oldBlizzard_CombatLog_Update_QuickButtons()

                local buttonIndex = 1
                for index, filter in ipairs(_G.Blizzard_CombatLog_Filters.filters) do
                        local button = _G["CombatLogQuickButtonFrameButton" .. buttonIndex]
                        button:SetNormalFontObject("ChatTabFontSmall")
                        button:SetHighlightFontObject("ChatTabFontSmallHighlight")
                        buttonIndex = buttonIndex + 1
                end
        end
        Blizzard_CombatLog_Update_QuickButtons()
end)

Compare with Previous | Blame