--## Author: Krionel ## Version: 1.1.5 ## SavedVariables: classColors, nameBackgroundColor, prestigeIcons, outlineNameplates, combatIndicator, combatIndicatorPlayer, restedGlowFX, restedZZZFx, redFlashInCombat, rG, gG, bG, aG, cornerIcon, hideQuestTracker
local ans = {}

-- To not have many digits in the number of a color value
local function ceilColor(color)
    return math.ceil(color*100)/100;
end

-- Transform three color numbers into a string for compare
local function colorToString(r, g, b, a)
    if (not a) then a = 1 end;
    return ceilColor(r) ..",".. ceilColor(g) ..",".. ceilColor(b) ..",".. ceilColor(a);
end

-- Util function to not duplicate frames
local function isFrameExist(name)
    local frame = _G[name];
    local result = false;

    if (frame and frame:GetObjectType() == "Frame") then
        result = true;
    end

    return result;
end

ans.isFrameExist = isFrameExist;

--addon name, addon namespace
local isFrameExist = ans.isFrameExist;
local krioUiFrameName = "KrioUiMainFrame";
local pveInstances = {"scenario", "party", "raid"};
local pvpInstances = {"arena", "pvp"};
rG,gG,bG,aG = 1,1,1,1;

local function arrayContainsItem(array, item)
    for key, value in pairs(array) do
        if value == item then return true end
    end
    return false
end

if  (not isFrameExist(krio)) then
    local frame = CreateFrame("Frame", krioUiFrameName);
    frame:RegisterEvent("PLAYER_ENTERING_WORLD");

    local function onEvent(self, event, ...)
        --Tracking when player log into the world (logging in, /reload-ing)
        if (event == "PLAYER_ENTERING_WORLD" or event) then
            local initialLogin, reloadingUI = ...;
            local inInstance, instanceType = IsInInstance();
            ans.setPlayerIsInPVEInstance(arrayContainsItem(pveInstances, instanceType));
            if hideQuestTracker == true and isInBattleground == true then
                ans.returnQuestTrackerToPreviousState(not arrayContainsItem(pvpInstances, instanceType)); 
            end

            if (initialLogin or reloadingUI) then

                -- Load class colors
                ans.Setings_Load();
                -- Style unit frames with class color
                if (classColors == true) then
                    ans.classColor();
                end
                if (nameBackgroundColor == true) then
                    ans.nameBackgroundColor();
                end
                if (prestigeIcons == true) then
                    ans.removePrestigeIcons();
                                end
                if (outlineNameplates == true) then
                    ans.outlineOnNamePlates();
                end
                if (combatIndicator == true) then
                    ans.combatIndicator();
                end
                if (combatIndicatorPlayer == true) then
                    ans.combatIndicatorPlayer();
                end
                if (cornerIcon == true) then
                    ans.cornerIcon();
                end
                -- change color of Frames
                if (rG == 1 and gG == 1 and bG == 1) then
                    PlayerFrame.PlayerFrameContainer.FrameTexture:SetDesaturated(false)
                end
                
                PlayerFrame.PlayerFrameContainer.FrameTexture:SetVertexColor(rG,gG,bG)
                PlayerFrame.PlayerFrameContent.PlayerFrameContentContextual.PlayerPortraitCornerIcon:SetVertexColor(rG,gG,bG)
                TargetFrame.TargetFrameContainer.FrameTexture:SetVertexColor(rG,gG,bG)
                TargetFrameToT.FrameTexture:SetVertexColor(rG,gG,bG)
                FocusFrame.TargetFrameContainer.FrameTexture:SetVertexColor(rG,gG,bG)
                FocusFrameToT.FrameTexture:SetVertexColor(rG,gG,bG)
                PetFrameTexture:SetVertexColor(rG,gG,bG)
            end
        end
    end
    frame:SetScript("OnEvent", onEvent); 

    local bgQueuePopFrame = CreateFrame("Frame", "bgQueuePopFrame");
    bgQueuePopFrame:RegisterEvent("UPDATE_BATTLEFIELD_STATUS");

    local function onBGQueuePop(self, event, ...)
        local status, mapName, instanceID, lowestlevel, highestlevel, teamSize, registeredMatch = GetBattlefieldStatus(1);
        if (hideQuestTracker == true and status == "confirm") then
            -- ObjectiveTrackerFrame.collapsed returns true or nil
            isQuestTrackerCollapsed = ObjectiveTrackerFrame.collapsed
        end
    end

    bgQueuePopFrame:SetScript("OnEvent", onBGQueuePop);

    --Tracking event PLAYER_ENTERING_BATTLEGROUND to be able to specify if player enters battleground
    local changeAreaFrame = CreateFrame("Frame", "KrioUiAreaChangeFrame");
    changeAreaFrame:RegisterEvent("PLAYER_ENTERING_BATTLEGROUND");

    local function onEnterBattleground(self, event, ...)
        --collapse quest tracker on entering battleground
        if (hideQuestTracker == true) then
            isInBattleground = true;
            ObjectiveTrackerFrame.Header.MinimizeButton:Click()
        end
    end

    changeAreaFrame:SetScript("OnEvent", onEnterBattleground);
end

-- Remove PlayerFrame glow effect in rested area
hooksecurefunc("PlayerFrame_UpdateStatus", function(self)
    local statusTexture = PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.StatusTexture;
    if (IsResting() and restedGlowFX == true) then
        statusTexture:Hide();
        PlayerFrame_UpdatePlayerRestLoop(true);
    end
    if (cornerIcon == true) then
        ans.cornerIcon();
    end    
end)

-- Remove "zZZ" effect on PlayerFrame
hooksecurefunc("PlayerFrame_UpdatePlayerRestLoop", function(state)
    local playerRestLoop = PlayerFrame.PlayerFrameContent.PlayerFrameContentContextual.PlayerRestLoop;
    if(state and restedZZZFx) then
        playerRestLoop:Hide();
        playerRestLoop.PlayerRestLoopAnim:Stop();
    end
end)

-- Remove red flash on Playerframe while in combat (melee)
hooksecurefunc("PlayerFrame_UpdateStatus", function(self)
    local combatStatusTexture = PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.StatusTexture;
    local playerFrameTargetContextual = PlayerFrame_GetPlayerFrameContentContextual();
    local playerPortraitCornerIcon = playerFrameTargetContextual.PlayerPortraitCornerIcon;
    local attackIcon = playerFrameTargetContextual.AttackIcon;
    if (PlayerFrame.inCombat and redFlashInCombat == true) then
        combatStatusTexture:Hide();
    end
    --attackIcon:Hide();
end)


local defaultColor = {r = 0, g = 0.9, b = 0.3};

local function updateColor(unit, frame)
    if UnitIsPlayer(unit) then
        classColor = RAID_CLASS_COLORS[select(2, UnitClass(unit))];
        frame:SetStatusBarDesaturated(true);
        frame:SetStatusBarColor(classColor.r, classColor.g, classColor.b);
    else
        frame:SetStatusBarDesaturated(false);
        frame:SetStatusBarColor(defaultColor.r, defaultColor.g, defaultColor.b);
    end
end 

--[[
    Change the text of target and focus frame name.
    Change the player, target and focus color.
]]--
local function classColor()
    -- player
    local classColor = RAID_CLASS_COLORS[select(2, UnitClass("player"))];
    local playerFrameHealthBar = PlayerFrame_GetHealthBar();
    playerFrameHealthBar:SetStatusBarDesaturated(true);
    playerFrameHealthBar:SetStatusBarColor(classColor.r, classColor.g, classColor.b);

    -- target and focus
    local frame = CreateFrame('Frame');
    frame:RegisterEvent("PLAYER_TARGET_CHANGED");
    frame:RegisterEvent("PLAYER_FOCUS_CHANGED");
    frame:SetScript("OnEvent", function(self, event, ...)
        if (event == "PLAYER_TARGET_CHANGED") then
            updateColor("target", TargetFrame.TargetFrameContent.TargetFrameContentMain.HealthBarsContainer.HealthBar);
        elseif (event == "PLAYER_FOCUS_CHANGED") then
            updateColor("focus", FocusFrame.TargetFrameContent.TargetFrameContentMain.HealthBarsContainer.HealthBar);
        end
    end)

    -- targettarget and focustarget
    hooksecurefunc("UnitFramePortrait_Update", function(self) 
        if self.unit == "targettarget" then
            updateColor("targettarget", TargetFrameToT.HealthBar);
        end
        if self.unit == "focustarget" then
            updateColor("focustarget", FocusFrameToT.HealthBar);
        end
    end);
end

ans.classColor = classColor;

--addon name, addon namespace
local krioUiPanelName = "KrioMods";
local r,g,b,a = 1, 0, 0, 1;

r = rG;
g = gG;
b = bG;
a = aG;

--.TOC file global variables
classColors = false;
nameBackgroundColor = false;
prestigeIcons = false;
outlineNameplates = false;
combatIndicator = false;
restedGlowFX = false;
restedZZZFx = false;
redFlashInCombat = false;
cornerIcon = false;
combatIndicatorPlayer = false;
hideQuestTracker = false;

--classic global variables
isInBattleground = false;
isQuestTrackerCollapsed = false;
isInPVEInstance = false

--Show RGB pallete to pick players favorite color
local function ShowColorPicker(r, g, b)
    ColorPickerFrame:SetupColorPickerAndShow({
        r = r,
        g = g,
        b = b,
        opacity = 1,
        hasOpacity = true,
        swatchFunc = function()
            r, g, b = ColorPickerFrame:GetColorRGB()
            a = ColorPickerFrame:GetColorAlpha()

            PlayerFrame.PlayerFrameContainer.FrameTexture:SetDesaturated(true)
            PlayerFrame.PlayerFrameContainer.FrameTexture:SetVertexColor(r,g,b)
            PlayerFrame.PlayerFrameContent.PlayerFrameContentContextual.PlayerPortraitCornerIcon:SetVertexColor(rG,gG,bG)
            TargetFrame.TargetFrameContainer.FrameTexture:SetVertexColor(r,g,b)
            TargetFrameToT.FrameTexture:SetVertexColor(r,g,b)
            FocusFrame.TargetFrameContainer.FrameTexture:SetVertexColor(r,g,b)
            FocusFrameToT.FrameTexture:SetVertexColor(r,g,b)
            PetFrameTexture:SetVertexColor(r,g,b)

            rG = r
            gG = g
            bG = b
        end,
        cancelFunc = function()
            r, g, b, a =
            ColorPickerFrame.previousValues.r, ColorPickerFrame.previousValues.g,
                ColorPickerFrame.previousValues.b, ColorPickerFrame.previousValues.a
        end
    })
end

local function Setings_Load()
    if  (not ans.isFrameExist(krioUiPanelName)) then
        
        local panel = CreateFrame("Frame")
        panel.name = "KrioUI"
        local category = Settings.RegisterCanvasLayoutCategory(panel, panel.name)         
        Settings.RegisterAddOnCategory(category);

        local title = panel:CreateFontString("ARTWORK", nil, "GameFontNormalLarge")
        title:SetPoint("TOPLEFT", 0, -10)
        title:SetText("|cffed8428Krio|rUI Settings")


        local settingsFrame = CreateFrame("Frame", "settingsFrame", panel)
        settingsFrame:SetPoint("TOPLEFT")
        settingsFrame:SetSize(600, 300)

            local classColorText = CreateFrame("MessageFrame", "classColorText", settingsFrame)
            classColorText:SetPoint("TOPLEFT")
            classColorText:SetSize(100, 150)
            classColorText.text = classColorText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            classColorText.text:SetPoint("LEFT",0,10)
            classColorText.text:SetText("Add Class Colors to UnitFrames")

            local outlineOnNameplatesText = CreateFrame("MessageFrame", "outlineOnNameplatesText", settingsFrame)
            outlineOnNameplatesText:SetPoint("TOPLEFT")
            outlineOnNameplatesText:SetSize(100, 150)
            outlineOnNameplatesText.text = outlineOnNameplatesText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            outlineOnNameplatesText.text:SetPoint("LEFT",0, -25)
            outlineOnNameplatesText.text:SetText("Add Outline to Nameplates")

            local combatIndicatorText = CreateFrame("MessageFrame", "combatIndicatorText", settingsFrame)
            combatIndicatorText:SetPoint("TOPLEFT")
            combatIndicatorText:SetSize(100, 150)
            combatIndicatorText.text = combatIndicatorText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            combatIndicatorText.text:SetPoint("LEFT",0, -65)
            combatIndicatorText.text:SetText("Add Combat Indicator to Target/Focus")

            local combatIndicatorPlayerText = CreateFrame("MessageFrame", "combatIndicatorText", settingsFrame)
            combatIndicatorPlayerText:SetPoint("TOPLEFT")
            combatIndicatorPlayerText:SetSize(100, 150)
            combatIndicatorPlayerText.text = combatIndicatorPlayerText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            combatIndicatorPlayerText.text:SetPoint("LEFT",0, -105)
            combatIndicatorPlayerText.text:SetText("Add Combat Indicator to PlayerFrame")

            local nameBackgroundColorText = CreateFrame("MessageFrame", "nameBackgroundColorText", settingsFrame)
            nameBackgroundColorText:SetPoint("TOPLEFT")
            nameBackgroundColorText:SetSize(100, 150)
            nameBackgroundColorText.text = nameBackgroundColorText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            nameBackgroundColorText.text:SetPoint("LEFT",0, -145)
            nameBackgroundColorText.text:SetText("Remove Backround Behind PlayerNames")

            local prestigeIconsText = CreateFrame("MessageFrame", "prestigeIconsText", settingsFrame)
            prestigeIconsText:SetPoint("TOPLEFT")
            prestigeIconsText:SetSize(100, 150)
            prestigeIconsText.text = prestigeIconsText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            prestigeIconsText.text:SetPoint("LEFT",0, -185)
            prestigeIconsText.text:SetText("Remove Prestige Icons on UnitFrames")

            local restedGlowEffectText = CreateFrame("MessageFrame", "restedGlowEffectText", settingsFrame)
            restedGlowEffectText:SetPoint("TOPLEFT")
            restedGlowEffectText:SetSize(100, 150)
            restedGlowEffectText.text = restedGlowEffectText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            restedGlowEffectText.text:SetPoint("LEFT",0, -225)
            restedGlowEffectText.text:SetText("Remove rested GlowFX on PlayerFrame ")
            
            local restedZZZEffectText = CreateFrame("MessageFrame", "restedZZZEffectText", settingsFrame)
            restedZZZEffectText:SetPoint("TOPLEFT")
            restedZZZEffectText:SetSize(100, 150)
            restedZZZEffectText.text = restedZZZEffectText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            restedZZZEffectText.text:SetPoint("LEFT",0, -265)
            restedZZZEffectText.text:SetText("Remove rested \"zzZ\" FX on PlayerFrame ")

            local portraitCornerIconText = CreateFrame("MessageFrame", "restedZZZEffectText", settingsFrame)
            portraitCornerIconText:SetPoint("TOPLEFT")
            portraitCornerIconText:SetSize(100, 150)
            portraitCornerIconText.text = portraitCornerIconText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            portraitCornerIconText.text:SetPoint("LEFT",0, -305)
            portraitCornerIconText.text:SetText("Remove portrait corner icon (arrow) on PlayerFrame ")

            local redFlashInCombatText = CreateFrame("MessageFrame", "redFlashInCombatText", settingsFrame)
            redFlashInCombatText:SetPoint("TOPLEFT")
            redFlashInCombatText:SetSize(100, 150)
            redFlashInCombatText.text = redFlashInCombatText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            redFlashInCombatText.text:SetPoint("LEFT",0, -345)
            redFlashInCombatText.text:SetText("Remove red flash while in combat on PlayerFrame")

            local hideQuestTrackerInBGText = CreateFrame("MessageFrame", "hideQuestTrackerInBGText", settingsFrame)
            hideQuestTrackerInBGText:SetPoint("TOPLEFT")
            hideQuestTrackerInBGText:SetSize(100, 150)
            hideQuestTrackerInBGText.text = hideQuestTrackerInBGText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            hideQuestTrackerInBGText.text:SetPoint("LEFT",0, -385)
            hideQuestTrackerInBGText.text:SetText("Collapse Quest tracker on entering battleground")
            
            local frameColorText = CreateFrame("MessageFrame", "frameColorText", settingsFrame)
            frameColorText:SetPoint("TOPLEFT")
            frameColorText:SetSize(100, 150)
            frameColorText.text = frameColorText:CreateFontString("ARTWORK", nil, "GameFontNormal")
            frameColorText.text:SetPoint("LEFT",0, -425)
            frameColorText.text:SetText("Change color of frames to your preference")
            
            
            local classColorCheckBox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            classColorCheckBox:SetPoint("TOPRIGHT", 0, -45)
            classColorCheckBox:SetChecked(classColors)
            classColorCheckBox:HookScript("OnClick", function()
                classColors = not classColors
            end)

            local nameplateOutline = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            nameplateOutline:SetPoint("TOPRIGHT", 0, -85)
            nameplateOutline:SetChecked(outlineNameplates)
            nameplateOutline:HookScript("OnClick", function()
                outlineNameplates = not outlineNameplates
            end)

            local combatIndicatorCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            combatIndicatorCheckbox:SetPoint("TOPRIGHT", 0, -125)
            combatIndicatorCheckbox:SetChecked(combatIndicator)
            combatIndicatorCheckbox:HookScript("OnClick", function()
                combatIndicator = not combatIndicator
            end)

            local combatIndicatorPlayerCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            combatIndicatorPlayerCheckbox:SetPoint("TOPRIGHT", 0, -165)
            combatIndicatorPlayerCheckbox:SetChecked(combatIndicatorPlayer)
            combatIndicatorPlayerCheckbox:HookScript("OnClick", function()
                combatIndicatorPlayer = not combatIndicatorPlayer
            end)

            local nameBackgroundColorCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            nameBackgroundColorCheckbox:SetPoint("TOPRIGHT", 0, -205)
            nameBackgroundColorCheckbox:SetChecked(nameBackgroundColor)
            nameBackgroundColorCheckbox:HookScript("OnClick", function()
                nameBackgroundColor = not nameBackgroundColor
            end)

            local prestigeIconsCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            prestigeIconsCheckbox:SetPoint("TOPRIGHT", 0, -245)
            prestigeIconsCheckbox:SetChecked(prestigeIcons)
            prestigeIconsCheckbox:HookScript("OnClick", function()
                prestigeIcons = not prestigeIcons
            end)

            local restedGlowEffectCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            restedGlowEffectCheckbox:SetPoint("TOPRIGHT", 0, -285)
            restedGlowEffectCheckbox:SetChecked(restedGlowFX)
            restedGlowEffectCheckbox:HookScript("OnClick", function()
                restedGlowFX = not restedGlowFX
            end)

            local restedZZZEffectCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            restedZZZEffectCheckbox:SetPoint("TOPRIGHT", 0, -325)
            restedZZZEffectCheckbox:SetChecked(restedZZZFx)
            restedZZZEffectCheckbox:HookScript("OnClick", function()
                restedZZZFx = not restedZZZFx
            end)

            local portraitCornerIconCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            portraitCornerIconCheckbox:SetPoint("TOPRIGHT", 0, -365)
            portraitCornerIconCheckbox:SetChecked(cornerIcon)
            portraitCornerIconCheckbox:HookScript("OnClick", function()
                cornerIcon = not cornerIcon
            end)

            local redFlashInCombatCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            redFlashInCombatCheckbox:SetPoint("TOPRIGHT", 0, -405)
            redFlashInCombatCheckbox:SetChecked(redFlashInCombat)
            redFlashInCombatCheckbox:HookScript("OnClick", function()
                redFlashInCombat = not redFlashInCombat
            end)
            local hideQuestTrackerInBGCheckbox = CreateFrame("CheckButton", nil, settingsFrame, "UICheckButtonTemplate")
            hideQuestTrackerInBGCheckbox:SetPoint("TOPRIGHT", 0, -445)
            hideQuestTrackerInBGCheckbox:SetChecked(hideQuestTracker)
            hideQuestTrackerInBGCheckbox:HookScript("OnClick", function()
                hideQuestTracker = not hideQuestTracker
            end)

            local frameColorButton = CreateFrame("Button", nil, settingsFrame, "UIPanelButtonTemplate")
            frameColorButton:SetPoint("TOPRIGHT",-100, -485)
            frameColorButton:SetSize(100 ,30)
            frameColorButton:SetText("Change Color")
            frameColorButton:SetPoint("CENTER")
            frameColorButton:HookScript("OnClick", function()
                ShowColorPicker(r,g,b);
            end)

            local defaultColorButton = CreateFrame("Button", nil, settingsFrame, "UIPanelButtonTemplate")
            defaultColorButton:SetPoint("TOPRIGHT",-0, -485)
            defaultColorButton:SetSize(100 ,30)
            defaultColorButton:SetText("Default Color")
            defaultColorButton:SetPoint("CENTER")
            defaultColorButton:HookScript("OnClick", function()
                PlayerFrame.PlayerFrameContainer.FrameTexture:SetDesaturated(false)
                PlayerFrame.PlayerFrameContainer.FrameTexture:SetVertexColor(1,1,1)
                PlayerFrame.PlayerFrameContent.PlayerFrameContentContextual.PlayerPortraitCornerIcon:SetVertexColor(1,1,1)
                TargetFrame.TargetFrameContainer.FrameTexture:SetVertexColor(1,1,1)
                TargetFrameToT.FrameTexture:SetVertexColor(1,1,1)
                FocusFrame.TargetFrameContainer.FrameTexture:SetVertexColor(1,1,1)
                FocusFrameToT.FrameTexture:SetVertexColor(1,1,1)
                PetFrameTexture:SetVertexColor(1,1,1)
                rG,gG,bG = 1,1,1;
            end)

            local reloadButton = CreateFrame("Button", nil, settingsFrame, "UIPanelButtonTemplate")
            reloadButton:SetPoint("BOTTOMLEFT",0, -296)
            reloadButton:SetSize(135, 42)
            reloadButton:SetText("Save Settings")
            reloadButton:SetPoint("CENTER")
            reloadButton:HookScript("OnClick", function()
                ReloadUI();
            end)
    end
end

local function nameBackgroundColor()
    -- remove colors on top of unit frame
    TargetFrame.TargetFrameContent.TargetFrameContentMain.ReputationColor:SetTexture(nil)
    FocusFrame.TargetFrameContent.TargetFrameContentMain.ReputationColor:SetTexture(nil)
end

local function removePrestigeIcons()
    -- remove prestigeIcons on unit frames
    PlayerFrame.PlayerFrameContent.PlayerFrameContentContextual.PrestigeBadge:SetAlpha(
        0)
    PlayerFrame.PlayerFrameContent.PlayerFrameContentContextual.PrestigePortrait:SetAlpha(
        0)
    TargetFrame.TargetFrameContent.TargetFrameContentContextual.PrestigePortrait:SetAlpha(
        0)
    TargetFrame.TargetFrameContent.TargetFrameContentContextual.PrestigeBadge:SetAlpha(
        0)
    FocusFrame.TargetFrameContent.TargetFrameContentContextual.PrestigePortrait:SetAlpha(
        0)
    FocusFrame.TargetFrameContent.TargetFrameContentContextual.PrestigeBadge:SetAlpha(
        0)
end

local function SetFont(obj, optSize)
    local fontName= obj:GetFont()
    obj:SetFont(fontName,optSize,"OUTLINE")
end

local function outlineOnNamePlates()
    SetFont(SystemFont_LargeNamePlate,11)
    SetFont(SystemFont_NamePlate,11)
    SetFont(SystemFont_LargeNamePlateFixed,11)
    SetFont(SystemFont_NamePlateFixed,11) 
end

-- return different x coordination in case prestige icons are turned on/off 
local function combatIndicatorYPosition_byPrestigeAndInstanceFlag() 
    if (isInPVEInstance) then
        return 0
    end

    return prestigeIcons and 0 or 15
end

local function combatIndicator()
    if combatIndicator then
        -- return different x coordination in case unit is rare/elite/rareelite
        local function combatIndicatorXPosition_byUnitClassification(unitClassification)
            local x = -20
           
            -- Blizz function to retrieve unit type
            local uC = UnitClassification(unitClassification)
            if ( uC == "elite" or uC == "rareelite" or uC == "rare" ) then
                x = -13
            end

            return x
        end

        -- Attach combat icon to target frame and hide by default
        local targetFrame = CreateFrame("Frame", nil , TargetFrame)
        targetFrame:SetSize(26,26)
        targetFrame.icon = targetFrame:CreateTexture(nil, "BORDER")
        targetFrame.icon:SetAllPoints()
        targetFrame.icon:SetTexture([[Interface\Icons\ABILITY_DUALWIELD]])
        targetFrame:Hide()

        -- Attach combat icon to focus frame and hide by default
        local focusFrame = CreateFrame("Frame", nil , FocusFrame)
        focusFrame:SetSize(26,26)
        focusFrame.icon = focusFrame:CreateTexture(nil, "BORDER")
        focusFrame.icon:SetAllPoints()
        focusFrame.icon:SetTexture([[Interface\Icons\ABILITY_DUALWIELD]])
        focusFrame:Hide()

        local function CombatIndicators_Update()
            -- show combat indicator in case target is in combat
            -- plus one correction as it seems like the target is indicator of center
            targetFrame:SetPoint("LEFT", TargetFrame, "RIGHT", combatIndicatorXPosition_byUnitClassification("target"), combatIndicatorYPosition_byPrestigeAndInstanceFlag() + 1)
            targetFrame:SetShown(UnitAffectingCombat("target"))
            -- show combat indicator in case focus is in combat
            focusFrame:SetPoint("LEFT", FocusFrame, "RIGHT", combatIndicatorXPosition_byUnitClassification("focus"), combatIndicatorYPosition_byPrestigeAndInstanceFlag())
            focusFrame:SetShown(UnitAffectingCombat("focus"))
        end
        -- update timer to check if unit frame is in combat
        C_Timer.NewTicker(0.01, CombatIndicators_Update)
    end
end

local function combatIndicatorPlayer() 
    if combatIndicatorPlayer then
        local playerFrame = CreateFrame("Frame", nil , PlayerFrame)
     
        playerFrame:SetSize(26,26)
        playerFrame.icon = playerFrame:CreateTexture(nil, "BORDER")
        playerFrame.icon:SetAllPoints()
        playerFrame.icon:SetTexture([[Interface\Icons\ABILITY_DUALWIELD]])
        playerFrame:Hide()

        local function CombatIndicator_Update()
            playerFrame:SetPoint("LEFT", PlayerFrame, "LEFT", -10, combatIndicatorYPosition_byPrestigeAndInstanceFlag())
            playerFrame:SetShown(UnitAffectingCombat("player"))
        end

        C_Timer.NewTicker(0.01, CombatIndicator_Update)
    end
end

local function cornerIcon()
    local playerFrameTargetContextual = PlayerFrame_GetPlayerFrameContentContextual();
    local playerPortraitCornerIcon = playerFrameTargetContextual.PlayerPortraitCornerIcon;
    playerPortraitCornerIcon:Hide();
end

local function setPlayerIsInPVEInstance(pveInstance) 
    isInPVEInstance = pveInstance
end

local function returnQuestTrackerToPreviousState(nonPvpInstance)
    if nonPvpInstance ~= false then
        if isQuestTrackerCollapsed ~= true then
            ObjectiveTrackerFrame.Header.MinimizeButton:Click()
        end
        isInBattleground = false;
    end
end

ans.removeRestedGlowEffect = removeRestedGlowEffect;
ans.combatIndicator = combatIndicator;
ans.outlineOnNamePlates = outlineOnNamePlates;
ans.removePrestigeIcons = removePrestigeIcons;
ans.nameBackgroundColor = nameBackgroundColor;
ans.Setings_Load = Setings_Load;
ans.cornerIcon = cornerIcon;
ans.combatIndicatorPlayer = combatIndicatorPlayer;
ans.setPlayerIsInPVEInstance = setPlayerIsInPVEInstance;
ans.returnQuestTrackerToPreviousState = returnQuestTrackerToPreviousState;