local _, ns = ...
local L = ns.L

--local r, g, b, a = 19, 104, 121, 0.4 -- azul
local r, g, b, a = 225, 96, 25, 0.4 --actual
--local r, g, b, a = 0, 0, 0, 0.4 --gris
--local r, g, b, a = 198, 31, 74, 0.4 --rosa

local outterFrame = CreateFrame("Frame",nil,UIParent)

local function setTooltip(parentFrame,...)
    local text1,text2,text3,text4=...
    parentFrame:HookScript("OnEnter", function(self)
        GameTooltip:SetOwner( parentFrame, "ANCHOR_NONE" )
        if AutoScrap_CharSettings.CombatFrame.startPoint == "TOPRIGHT" or AutoScrap_CharSettings.CombatFrame.startPoint == "RIGHT" or AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMRIGHT" then
            GameTooltip:SetPoint("TOPRIGHT", outterFrame, "TOPLEFT", 2, 0)
        else
            GameTooltip:SetPoint("TOPLEFT", outterFrame, "TOPRIGHT", -2, 0)
        end
        if text1 then
        --print(HIGHLIGHT_FONT_COLOR_CODE..text1..FONT_COLOR_CODE_CLOSE)
            GameTooltip:AddLine(NORMAL_FONT_COLOR_CODE..text1..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        if text2 then
            GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..text2..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        if text3 then
            GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..text3..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        if text4 then
            GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..text4..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        --AutoScrapTooltip:AddDoubleLine("prob", "lala")
        GameTooltip:Show()
    end)
    parentFrame:HookScript("OnLeave", function(self)
        GameTooltip:Hide()
    end)
end
local updateStackDirection,updateBagFinalIconsDirection,updatePartyDirection
local function savePosition(frame)
    AutoScrap_CharSettings.CombatFrame.startPoint, _ , AutoScrap_CharSettings.CombatFrame.relativePoint, AutoScrap_CharSettings.CombatFrame.xOfs, AutoScrap_CharSettings.CombatFrame.yOfs = frame:GetPoint()
    updateStackDirection()
    updateBagFinalIconsDirection()
    updatePartyDirection()
end
local function setCombatOFPosition()
    outterFrame:ClearAllPoints()
    outterFrame:SetPoint(AutoScrap_CharSettings.CombatFrame.startPoint,UIParent,AutoScrap_CharSettings.CombatFrame.relativePoint,AutoScrap_CharSettings.CombatFrame.xOfs,AutoScrap_CharSettings.CombatFrame.yOfs)
end
ns.setCombatOFPosition=setCombatOFPosition

local wsize, hsize = 186-18,60+14
local bagFullsize = 5
outterFrame:SetSize(wsize,hsize+bagFullsize)
outterFrame:SetClampedToScreen(true)
outterFrame:SetMovable(true)
outterFrame:SetResizable(false)
outterFrame:EnableMouse(true)
outterFrame:SetToplevel(true)
outterFrame:SetFrameStrata("HIGH") --MEDIUM -- la barra secundaria de skills del juego sale por encima al redimensionar y evita pulsar los botoness
outterFrame:SetScript("OnMouseDown",function (self,button) if button=="LeftButton" then outterFrame:StartMoving() end end)
outterFrame:SetScript("OnMouseUp",function (self,button) if button=="LeftButton" then outterFrame:StopMovingOrSizing() savePosition(self) end end)
outterFrame:SetPoint("CENTER")
outterFrame.tex = outterFrame:CreateTexture()
outterFrame.tex:SetAllPoints(outterFrame)
outterFrame.tex:SetColorTexture(r/255, b/255, b/255 , a/1.2) --255/255, 20/255, 147/255 , 0.2

local z = CreateFrame("Frame",nil,outterFrame)
z:SetSize(wsize,hsize-14+bagFullsize)
z.tex = z:CreateTexture()
z.tex:SetAllPoints(z)
--z.tex:SetColorTexture(math.random(0, 255)/255, math.random(0, 255)/255, math.random(0, 255)/255 , 0.2)
z.tex:SetColorTexture(r/255, g/255, b/255 , a/1.2)
z:SetPoint("BOTTOM")

z.timerFrame = CreateFrame("Frame",nil,z)
z.timerFrame:SetSize(82,14)
z.timerFrame.tex = z.timerFrame:CreateTexture()
z.timerFrame.tex:SetAllPoints(z.timerFrame)
z.timerFrame.tex:SetColorTexture(r/255, g/255, b/255 , a/1.2)
z.timerFrame:SetPoint("TOP",outterFrame,"TOP")

--local relojIcon = ns.Utils.crearFrameConTextura (z,14*(9-1), 14*(9), 166 , 179, 1,"mailpanel")
local relojIcon = ns.crearBoton3Fases(z,"Interface\\AddOns\\AutoScrap\\images\\mailpanel", 159,173,37,50, function ()  ns.toggleMyTimerCountDown() end)
relojIcon:SetPoint ("LEFT",z.timerFrame,"LEFT", 0, 0)

local reloadButton = ns.crearBoton3Fases(outterFrame,"Interface\\AddOns\\AutoScrap\\images\\mailpanel", 0,14,179,192, function () ns.stopCombatFrame() ns.reanudarCombatFrameParado() ns.startCombatFrame() end)
reloadButton:SetPoint("TOPRIGHT",-2,-1)

local pauseButton = ns.crearBoton3Fases(outterFrame,"Interface\\AddOns\\AutoScrap\\images\\mailpanel", 0,14,192,205, function () ns.stopCombatFrame() ns.forceStopTimerKillBreakSell() end)
pauseButton:SetPoint("RIGHT",reloadButton,"LEFT",-2,0)

local enableMove, disableMove
local lockedButton = ns.crearBoton3Fases(outterFrame,"Interface\\AddOns\\AutoScrap\\images\\mailpanel", 0,14,218,231, function () enableMove() end)
lockedButton:SetPoint("TOPLEFT", 20,-1)
lockedButton:Hide()

local unlockedButton = ns.crearBoton3Fases(outterFrame,"Interface\\AddOns\\AutoScrap\\images\\mailpanel", 0,14,205,218, function () disableMove() end)
unlockedButton:SetPoint("TOPLEFT", 20,-1)

local info = ns.Utils.crearFrameConTextura (outterFrame,123, 123+14, 31, 31+14, 1,"mailpanel")
info:SetPoint ("TOPLEFT",outterFrame,"TOPLEFT", 2,0)

enableMove = function ()
    AutoScrap_CharSettings.combatLocked = false
    lockedButton:Hide()
    unlockedButton:Show()
    outterFrame:SetMovable(true)
    outterFrame:EnableMouse(true)
end

disableMove = function ()
    AutoScrap_CharSettings.combatLocked = true
    lockedButton:Show()
    unlockedButton:Hide()
    outterFrame:SetMovable(false)
    outterFrame:EnableMouse(false)
end

function ns.setCombatLocked(locked)
    if locked then
        disableMove()
    else
        enableMove()
    end
    
end


z.texto1 = z.timerFrame:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.texto2 = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
--z.texto3 = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.texto4 = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.texto5 = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.texto6 = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.textoTKH = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
--z.textoPKH = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.textoPKMH = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.textoMoneyH = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.plantasYMinas = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
z.plantasYMinasH = z:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")


local function restartText()
    z.texto1:SetText("0 sec")
    z.texto2:SetText("0")
    --z.texto3:SetText("0")
    z.texto4:SetText("0")
    z.texto6:SetText("0g")
    z.textoTKH:SetText("0")
    --z.textoPKH:SetText("0")
    z.textoPKMH:SetText("0")
    z.textoMoneyH:SetText("0g")
    z.plantasYMinas:SetText("0")
    z.plantasYMinasH:SetText("0")
end
restartText()

z.texto1:SetFont("Fonts\\FRIZQT_.TTF" ,10, "")
z.texto2:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
--z.texto3:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.texto4:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.texto5:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.texto6:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.textoTKH:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
--z.textoPKH:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.textoPKMH:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.textoMoneyH:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.plantasYMinas:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
z.plantasYMinasH:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
--[[ z.texto1:SetPoint("TOPLEFT",z,"TOPLEFT", 5, -2) -- timer
z.texto2:SetPoint("TOPLEFT",z.texto1,"BOTTOMLEFT", 0, -5) -- totakills
z.texto3:SetPoint("TOPLEFT",z.texto2,"BOTTOMLEFT", 0, -5) -- party kills
z.texto4:SetPoint("TOPLEFT",z.texto3,"BOTTOMLEFT", 0, -5) -- party kills mine
z.texto5:SetPoint("TOPLEFT",z.texto4,"BOTTOMLEFT", 0, -5) -- UD not used
z.texto6:SetPoint("TOPLEFT",z.texto5,"BOTTOMLEFT", 0, -5) -- money ]]

local totalkillsIcon = ns.Utils.crearFrameConTextura (z,14*(1-1), 14*(1), 166 , 179, 1,"mailpanel")
totalkillsIcon:SetPoint ("TOPLEFT",outterFrame,"TOPLEFT", 2,-2-14-1) -- EL MENOS 1 ES PARA bajarlo 1 de más porque la g del oro es un poco baja abajo.

local underFrameTK = CreateFrame("FRAME",nil, z)
underFrameTK:SetSize((wsize/2)-14-2,14)
underFrameTK:SetPoint("LEFT",totalkillsIcon,"RIGHT", 0,0)

local totalkillsIconH = ns.Utils.crearFrameConTextura (z,14*(5-1), 14*(5), 166 , 179, 1,"mailpanel")
totalkillsIconH:SetPoint ("LEFT",underFrameTK,"RIGHT", 2,0)

local underFrameTKH = CreateFrame("FRAME",nil, z)
underFrameTKH:SetSize((wsize/2)-14-2,14)
underFrameTKH:SetPoint("LEFT",totalkillsIconH,"RIGHT", 0,0)

z.texto2:SetPoint("CENTER",underFrameTK,"CENTER")
z.textoTKH:SetPoint("CENTER",underFrameTKH,"CENTER")

local underFramePKM = CreateFrame("FRAME",nil, z)
underFramePKM:SetSize((wsize/2)-14-2,14)
underFramePKM:SetPoint("TOPLEFT",underFrameTK,"BOTTOMLEFT", 0,0)

local partyKillsMIcon = ns.Utils.crearFrameConTextura (z,14*(3-1), 14*(3), 166 , 179, 1,"mailpanel")
partyKillsMIcon:SetPoint ("RIGHT",underFramePKM,"LEFT", 0,0)

local underFramePKMH = CreateFrame("FRAME",nil, z)
underFramePKMH:SetSize((wsize/2)-14-2,14)
underFramePKMH:SetPoint("TOPLEFT",underFrameTKH,"BOTTOMLEFT", 0,0)

local partyKillsMIconH = ns.Utils.crearFrameConTextura (z,14*(7-1), 14*(7), 166 , 179, 1,"mailpanel")
partyKillsMIconH:SetPoint ("RIGHT",underFramePKMH,"LEFT", 0,0)

z.texto4:SetPoint("CENTER",underFramePKM,"CENTER")
z.textoPKMH:SetPoint("CENTER",underFramePKMH,"CENTER")

local underFramePyM = CreateFrame("FRAME",nil, z)
underFramePyM:SetSize((wsize/2)-14-2,14)
underFramePyM:SetPoint("TOPLEFT",underFramePKM,"BOTTOMLEFT", 0,0)

local plantasYMenasIcon = ns.Utils.crearFrameConTextura (z,14*(11-1), 14*(11), 166 , 179, 1,"mailpanel")
plantasYMenasIcon:SetPoint ("RIGHT",underFramePyM,"LEFT", 0,0)

local underFramePyMH = CreateFrame("FRAME",nil, z)
underFramePyMH:SetSize((wsize/2)-14-2,14)
underFramePyMH:SetPoint("TOPLEFT",underFramePKMH,"BOTTOMLEFT", 0,0)

local plantasYMenasIconH = ns.Utils.crearFrameConTextura (z,14*(12-1), 14*(12), 166 , 179, 1,"mailpanel")
plantasYMenasIconH:SetPoint ("RIGHT",underFramePyMH,"LEFT", 0,0)

z.plantasYMinas:SetPoint("CENTER",underFramePyM,"CENTER")
z.plantasYMinasH:SetPoint("CENTER",underFramePyMH,"CENTER")

local underFrameMoney = CreateFrame("FRAME",nil, z)
underFrameMoney:SetSize((wsize/2)-14-2,14)
underFrameMoney:SetPoint("TOPLEFT",underFramePyM,"BOTTOMLEFT", 0,0)

local moneyIcon = ns.Utils.crearFrameConTextura (z,14*(4-1), 14*(4), 166 , 179, 1,"mailpanel")
moneyIcon:SetPoint ("RIGHT",underFrameMoney,"LEFT", 0,0)

local underFrameMoneyH = CreateFrame("FRAME",nil, z)
underFrameMoneyH:SetSize((wsize/2)-14-2,14)
underFrameMoneyH:SetPoint("TOPLEFT",underFramePyMH,"BOTTOMLEFT", 0,0)

local moneyIconH = ns.Utils.crearFrameConTextura (z,14*(8-1), 14*(8), 166 , 179, 1,"mailpanel")
moneyIconH:SetPoint ("RIGHT",underFrameMoneyH,"LEFT", 0,0)

z.texto6:SetPoint("CENTER",underFrameMoney,"CENTER")
z.textoMoneyH:SetPoint("CENTER",underFrameMoneyH,"CENTER")

z.texto1:SetPoint("LEFT",z.timerFrame,"LEFT",14,0)
z.texto1:SetPoint("RIGHT",z.timerFrame,"RIGHT",0,0)
z.texto1:SetJustifyH("CENTER") --LEFT

local myBagBar = CreateFrame("Frame",nil, z)
myBagBar:SetSize(wsize,bagFullsize)
myBagBar.tex = myBagBar:CreateTexture()
myBagBar.tex:SetPoint("LEFT")
myBagBar.tex:SetSize(0,bagFullsize)
myBagBar.tex:SetColorTexture(0/255, 10/255, 62/255 , 0.65) --azul oscuro
-------myBagBar.tex:SetColorTexture(115/255, 36/255, 4/255 , 0.85) --naranaja oscuro
--myBagBar.tex:SetColorTexture(75/255, 29/255, 3/255 , 0.65) --naranaja oscuro2
-------myBagBar.tex:SetColorTexture(26/255, 109/255, 91/255 , 1) --turquesa
--myBagBar.tex:SetColorTexture(243/255, 36/255, 26/255 , 0.65) --rojo
myBagBar:SetPoint("BOTTOMLEFT",z,"BOTTOMLEFT", 0,0)

local myBagPrecentage = 0
function ns.setMyBagsPercentage(percent)
    --print ("gereric tick")
    if myBagPrecentage~=percent then
        --print("non skipped tick")
        myBagPrecentage = percent
        myBagBar.tex:SetSize(math.floor(((wsize)*percent)/100),bagFullsize)
        if percent < 95 then
            myBagBar.tex:SetColorTexture(0/255, 10/255, 62/255 , 0.65)
        else
            myBagBar.tex:SetColorTexture(243/255, 36/255, 26/255 , 0.65)
        end
    end
end

function ns.getMyBagsPercentageFromCombatFrame()
    return myBagPrecentage
end

local function updateMyBagBar()
    ns.setMyBagsPercentage(ns.bolsaPorcentajeLlena() or 0)
end

local initTimer, initKillsAchievement, initKillsGraciaArchievement, killsPartyKillMine, killsUnitDead, initMoney, currentMoneyUpdated, plantasYMenas --killsPartyKill
function ns.updateCombatFrame()
    local tiempoTranscurrido = math.floor(GetTime()-initTimer)
    local statistics = GetStatistic(1197)
    if not tonumber(statistics) then statistics = 0 end
    local statisticsGracia = GetStatistic(1487)
    if not tonumber(statisticsGracia) then statisticsGracia = 0 end
    z.texto1:SetText("".. ns.Utils.horaBonita(tiempoTranscurrido))
    if tiempoTranscurrido == 0 then --solución simple a la división por cero
        tiempoTranscurrido = 1
    end
    z.texto2:SetText(""..(statistics - initKillsAchievement))
    z.textoTKH:SetText(math.floor(((statistics - initKillsAchievement)/tiempoTranscurrido)*3600))
    --z.textoPKH:SetText(math.floor((killsPartyKill/tiempoTranscurrido)*3600))
    --z.textoPKMH:SetText(math.floor((killsPartyKillMine/tiempoTranscurrido)*3600))
    z.texto4:SetText(""..(statisticsGracia - initKillsGraciaArchievement))
    z.textoPKMH:SetText(math.floor(((statisticsGracia - initKillsGraciaArchievement)/tiempoTranscurrido)*3600))
    z.textoMoneyH:SetText(math.floor(((currentMoneyUpdated/tiempoTranscurrido)*3600)/10000).."g")   
    z.plantasYMinasH:SetText(math.floor((plantasYMenas/tiempoTranscurrido)*3600))
end

--[[ function ns.combatFrameSumPartyKill()
    killsPartyKill = killsPartyKill + 1
    z.texto3:SetText(""..killsPartyKill)
end ]]

--[[ function ns.combatFrameSumPartyKillMine()
    killsPartyKillMine = killsPartyKillMine + 1
    z.texto4:SetText(""..killsPartyKillMine)
end ]]

function ns.combatFrameSumPlantasYMenas()
    plantasYMenas = plantasYMenas +1
    z.plantasYMinas:SetText(""..plantasYMenas)
end

--[[ function ns.combatFrameSumUnitDied()
    killsUnitDead = killsUnitDead + 1
    z.texto5:SetText("UD: "..killsUnitDead)
end ]]

function ns.combatFrameMoneyEvent(currentMoney)
    currentMoneyUpdated = currentMoney-initMoney
    z.texto6:SetText(""..math.floor((currentMoneyUpdated)/10000).."g")
end
local containerPartyFrame
function ns.startCombatFrame()
    restartText()
    initTimer = GetTime() --- (3600)
    initKillsAchievement = GetStatistic(1197) --- 450900
    if not tonumber(initKillsAchievement) then initKillsAchievement = 0 end
    initKillsGraciaArchievement = GetStatistic(1487)
    if not tonumber(initKillsGraciaArchievement) then initKillsGraciaArchievement = 0 end
    --killsPartyKill = 0 --+ 450900
    killsPartyKillMine = 0 --+ 450900
    --killsUnitDead = 0 + 450900--suele llegar depsués
    initMoney = GetMoney() --- 9450900*10000
    currentMoneyUpdated = 0 --+ 9450900*10000
    plantasYMenas = 0
    for x=1,4 do
        containerPartyFrame.guys[x]:ReloadButtonPressedToRestartDataExceptName()
    end
    ns.timerStart()
    --ns.setScriptOnMainFrame("COMBAT_LOG_EVENT_UNFILTERED")
    --print ("combat Start")
    ns.setScriptOnMainFrame("PLAYER_MONEY")
    ns.setScriptOnMainFrame("UNIT_SPELLCAST_SUCCEEDED") --al empezar se añade 2 veces, después se quita porque no se rearranca al pausar. se puede quitar de aquí y abajo si se queire cambiar esto.
    ns.combatFrameStartedToSendAddonMessageRequest()
end
local stopped = false

function ns.stopCombatFrame()
    stopped = true
    ns.timerStop()
    --ns.removeScriptOnMainFrame("COMBAT_LOG_EVENT_UNFILTERED")
    --print ("combat Stop")
    if not ns.isPartyRunning() then
        --print("Combat events down")
        ns.removeScriptOnMainFrame("PLAYER_MONEY")
        ns.removeScriptOnMainFrame("UNIT_SPELLCAST_SUCCEEDED")
    end
end

function ns.combatWasStoppedAnyTime()
    return stopped
end

local showed = false
outterFrame:Hide()

function ns.isCombatShown()
    return showed
end

function ns.combatToggle()
    if outterFrame:IsShown() then
        outterFrame:Hide()
        AutoScrap_CharSettings.combatStatisticsShowAtStart = false
        showed = false
        ns.removeScriptOnMainFrame("CURSOR_CHANGED")
    else
        updateStackDirection()
        updateBagFinalIconsDirection()
        updatePartyDirection()
        updateMyBagBar()
        if ns.cursorHasItem() then
            ns.setCombatFrameInteriorFullIconList()
        else
            ns.setCombatFrameInteriorIconsAndQuantities()
        end
        for x=1,4 do
            local name = containerPartyFrame.guys[x]:GetName()
            if  name ~= "" then
                local kills, plants, gold = ns.getAllDataFromName(name)
                if kills and plants and gold then -- puede ser nil si todavía no ha llegado.
                    containerPartyFrame.guys[x]:SetKillsPlantMoney(kills, plants,gold)
                end
                containerPartyFrame.guys[x]:RepopulateBolas()
                containerPartyFrame.guys[x]:SetBarPercentage(ns.getPorcentajeBolsaLlena(name) or 0)
            end
        end
        outterFrame:Show()
        AutoScrap_CharSettings.combatStatisticsShowAtStart = true
        showed = true
        ns.setScriptOnMainFrame("CURSOR_CHANGED")
    end
end

local containerFrameFarmIcons = CreateFrame("Frame",nil,outterFrame)
containerFrameFarmIcons.tex = containerFrameFarmIcons:CreateTexture()
containerFrameFarmIcons.tex:SetAllPoints(containerFrameFarmIcons)
--containerFrameFarmIcons.tex:SetColorTexture(120/255, 100/255, 200/255 , 0.5)
containerFrameFarmIcons:SetSize(wsize,50)

updateStackDirection = function ()
    containerFrameFarmIcons:ClearAllPoints()
    local xoffset,yoffset = 0,2
    --print(AutoScrap_CharSettings.CombatFrame.startPoint)
    if AutoScrap_CharSettings.CombatFrame.startPoint == "CENTER" then
        containerFrameFarmIcons:SetPoint("TOP",outterFrame, "BOTTOM", xoffset, -yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOP" then
        containerFrameFarmIcons:SetPoint("TOP",outterFrame, "BOTTOM", xoffset, -yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOM" then--
        containerFrameFarmIcons:SetPoint("BOTTOM",outterFrame, "TOP", xoffset, yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "LEFT" then
        containerFrameFarmIcons:SetPoint("TOP",outterFrame, "BOTTOM", xoffset, -yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "RIGHT" then
        containerFrameFarmIcons:SetPoint("TOP",outterFrame, "BOTTOM", xoffset, -yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOPLEFT" then
        containerFrameFarmIcons:SetPoint("TOP",outterFrame, "BOTTOM", xoffset, -yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOPRIGHT" then
        containerFrameFarmIcons:SetPoint("TOP",outterFrame, "BOTTOM", xoffset, -yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMLEFT" then--
        containerFrameFarmIcons:SetPoint("BOTTOM",outterFrame, "TOP", xoffset, yoffset)
    elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMRIGHT" then--
        containerFrameFarmIcons:SetPoint("BOTTOM",outterFrame, "TOP", xoffset, yoffset)
    else
        containerFrameFarmIcons:SetPoint("TOP",outterFrame, "BOTTOM", xoffset, -yoffset)
    end
end

local frameMiniBagIcons
local function crearBotonBolsa(slot, izq, parent, der)
    local boton = CreateFrame("Button",nil, frameMiniBagIcons)
    --boton.bag = bag
    boton.slot = slot
    boton:SetSize(40,40)
    boton:SetPoint(izq,parent,der)
    boton.tex = boton:CreateTexture(nil,"BACKGROUND") --BACKGROUND BORDER ARTWORK OVERLAY HIGHLIGHT
    boton.tex:SetAllPoints(boton)
    boton.tex:SetTexture("Interface\\PaperDoll\\UI-Backpack-EmptySlot")
    boton.tex:SetVertexColor(1, 0.6, 0.1 , 1)
    boton.tex.iconTex = boton:CreateTexture(nil,"OVERLAY")
    boton.tex.iconTex:Hide()
    --[[ if AutoScrap_CharSettings.miniBagIcons and AutoScrap_CharSettings.miniBagIcons[slot] then
        boton.tex.iconTex = boton:CreateTexture(nil,"OVERLAY") --AutoScrap_CharSettings.miniBagIcons[slot]
        boton.tex.iconTex:SetTexture(GetItemIcon(AutoScrap_CharSettings.miniBagIcons[slot]))
        boton.tex.iconTex:SetSize(38,38)
        boton.tex.iconTex:SetPoint("CENTER",boton.tex,"CENTER")
    end ]]
    boton:SetScript("OnClick", function (self,button)
        if button == "LeftButton" and CursorHasItem() then
            local cursorType,itemID,itemLink = GetCursorInfo()
            if IsShiftKeyDown() then
                AutoScrap_CharSettings.miniBagIcons[self.slot] = nil
                ns.updateBagIconTexSlots()
            elseif cursorType == "item" and itemID and itemID ~= 180653 and itemID ~= 82800 then
                AutoScrap_CharSettings.miniBagIcons[self.slot] = itemID
                --[[ print (self.slot,AutoScrap_CharSettings.miniBagIcons[self.slot])
                if not self.tex.iconTex then
                    self.tex.iconTex = boton:CreateTexture(nil,"OVERLAY")
                end
                self.tex.iconTex:SetTexture(GetItemIcon(itemID))
                self.tex.iconTex:SetSize(38,38)
                self.tex.iconTex:SetPoint("CENTER",self.tex,"CENTER") ]]
                for x=1,8 do
                    if x~=self.slot and AutoScrap_CharSettings.miniBagIcons[x] == itemID then
                        AutoScrap_CharSettings.miniBagIcons[x] = nil
                    end
                end
                ns.updateBagIconTexSlots()
                ClearCursor()
            end
        end
    end)
    ---------tooltip
    boton:HookScript("OnEnter", function(self)
        GameTooltip:SetOwner( boton, "ANCHOR_NONE" )
        if AutoScrap_CharSettings.CombatFrame.startPoint == "TOPRIGHT" or AutoScrap_CharSettings.CombatFrame.startPoint == "RIGHT" or AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMRIGHT" then
            GameTooltip:SetPoint("TOPRIGHT", containerFrameFarmIcons, "TOPLEFT", 2, 0)
        else
            GameTooltip:SetPoint("TOPLEFT", containerFrameFarmIcons, "TOPRIGHT", -2, 0)
        end

        --print(HIGHLIGHT_FONT_COLOR_CODE..text1..FONT_COLOR_CODE_CLOSE)
            if AutoScrap_CharSettings.miniBagIcons[self.slot] then
                local name = GetItemInfo (AutoScrap_CharSettings.miniBagIcons[self.slot])
                if name then
                    GameTooltip:AddLine(NORMAL_FONT_COLOR_CODE..name..FONT_COLOR_CODE_CLOSE,1,0,0,true)    
                end
            end
            GameTooltip:AddLine(NORMAL_FONT_COLOR_CODE..L["To remove an item use:"]..FONT_COLOR_CODE_CLOSE,1,0,0,true)
            GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..L["Shift + LeftClick"]..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        --AutoScrapTooltip:AddDoubleLine("prob", "lala")
        GameTooltip:Show()
    end)
    boton:HookScript("OnLeave", function(self)
        GameTooltip:Hide()
    end)
    ---------fin tooltip
    return boton
end


frameMiniBagIcons = CreateFrame("Frame",nil, containerFrameFarmIcons)
frameMiniBagIcons:SetSize(40*4,80)
local buttonHandlers = {}
buttonHandlers[1] = crearBotonBolsa(1,"BOTTOMLEFT",frameMiniBagIcons,"BOTTOMLEFT")
buttonHandlers[2] = crearBotonBolsa(2,"LEFT",buttonHandlers[1],"RIGHT")
buttonHandlers[3] = crearBotonBolsa(3,"LEFT",buttonHandlers[2],"RIGHT")
buttonHandlers[4] = crearBotonBolsa(4,"LEFT",buttonHandlers[3],"RIGHT")
buttonHandlers[5] = crearBotonBolsa(5,"BOTTOM",buttonHandlers[1],"TOP")
buttonHandlers[6] = crearBotonBolsa(6,"LEFT",buttonHandlers[5],"RIGHT")
buttonHandlers[7] = crearBotonBolsa(7,"LEFT",buttonHandlers[6],"RIGHT")
buttonHandlers[8] = crearBotonBolsa(8,"LEFT",buttonHandlers[7],"RIGHT")
frameMiniBagIcons:SetPoint("BOTTOM",containerFrameFarmIcons,"BOTTOM")


--[[ function ns.updateFarmBagIcon(itemID,cantidad)
    print ("actualizando",itemID, "con",cantidad)
end ]]

function ns.updateBagIconTexSlots()
    for slot=1,8 do
        if AutoScrap_CharSettings.miniBagIcons and AutoScrap_CharSettings.miniBagIcons[slot] then
            buttonHandlers[slot].tex.iconTex:SetTexture(GetItemIcon(AutoScrap_CharSettings.miniBagIcons[slot]))
            buttonHandlers[slot].tex.iconTex:SetSize(38,38)
            buttonHandlers[slot].tex.iconTex:SetPoint("CENTER",buttonHandlers[slot].tex,"CENTER")
            buttonHandlers[slot].tex.iconTex:Show()
        else
            buttonHandlers[slot].tex.iconTex:Hide()
        end
    end
    if ns.isPartyRunning() then
        for x=1,4 do
            local name = containerPartyFrame.guys[x]:GetName()
            if  name ~= "" then
                containerPartyFrame.guys[x]:RepopulateBolas()
            end
        end
    end
end

local frameMiniBagSelectionShown
local function crearBotonSelectionShown(slot,izq,parent,der)
    local tex = frameMiniBagSelectionShown:CreateTexture(nil,"ARTWORK")
    tex:SetSize(40,40)
    tex:SetTexture("Interface\\AddOns\\AutoScrap\\images\\mailpanel") --Interface\QUESTFRAME\AutoQuest
    tex:SetTexCoord(52/510,(52+40)/512,192/512,(192+40)/512)
    --tex:SetVertexColor(1, 0.6, 0.1 , 0)
    tex.slot = slot
  
    tex:SetPoint(izq,parent,der)
    tex.icon = frameMiniBagSelectionShown:CreateTexture(nil,"BACKGROUND")
    --tex.icon:SetVertexColor(1, 0.6, 0.1 , 1)
    tex.icon:SetSize(40,40)
    tex.icon:SetPoint(izq,parent,der)
    tex.mask = frameMiniBagSelectionShown:CreateMaskTexture()
    tex.mask:SetAllPoints(tex.icon)
    tex.mask:SetTexture("Interface/CHARACTERFRAME/TempPortraitAlphaMask", "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE")
    tex.icon:AddMaskTexture(tex.mask)
    tex.text = frameMiniBagSelectionShown:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
    tex.text:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE") --"OUTLINE,THICKOUTLINE"
    tex.text:SetJustifyH("CENTER")
    tex.text.size = 10
    tex.text:SetPoint("CENTER",tex.icon, "BOTTOM",0,12)
    tex:Hide()
    tex.qualityAtlasTex = frameMiniBagSelectionShown:CreateTexture(nil,"OVERLAY")
    tex.qualityAtlasTex:SetSize(25,25)
    tex.qualityAtlasTex:SetPoint("TOPLEFT",tex.icon, "TOPLEFT",-2,5)
    --tex.qualityAtlasTex:SetColorTexture(1, 0, 0, 0.5)
    tex.icon:Hide()
    tex.text:Hide()
    return tex
end


frameMiniBagSelectionShown = CreateFrame("Frame",nil,containerFrameFarmIcons)

local buttonHandlersShown = {}
buttonHandlersShown[1] = crearBotonSelectionShown(1,"BOTTOMLEFT",frameMiniBagSelectionShown,"BOTTOMLEFT")
buttonHandlersShown[2] = crearBotonSelectionShown(2,"LEFT",buttonHandlersShown[1],"RIGHT")
buttonHandlersShown[3] = crearBotonSelectionShown(3,"LEFT",buttonHandlersShown[2],"RIGHT")
buttonHandlersShown[4] = crearBotonSelectionShown(4,"LEFT",buttonHandlersShown[3],"RIGHT")
buttonHandlersShown[5] = crearBotonSelectionShown(5,"BOTTOM",buttonHandlersShown[1],"TOP")
buttonHandlersShown[6] = crearBotonSelectionShown(6,"LEFT",buttonHandlersShown[5],"RIGHT")
buttonHandlersShown[7] = crearBotonSelectionShown(7,"LEFT",buttonHandlersShown[6],"RIGHT")
buttonHandlersShown[8] = crearBotonSelectionShown(8,"LEFT",buttonHandlersShown[7],"RIGHT")
frameMiniBagSelectionShown:SetPoint("BOTTOM",containerFrameFarmIcons,"BOTTOM")
--frameMiniBagSelectionShown:SetSize(40*4,80)

local function clearAndSetPoint(tex,left, parent, right)
    tex:ClearAllPoints()
    tex.icon:ClearAllPoints()
    tex:SetPoint(left,parent,right)
    tex.icon:SetPoint(left,parent,right)
end

updateBagFinalIconsDirection = function ()
    if AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOM" or AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMLEFT" or AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMRIGHT" then
        clearAndSetPoint(buttonHandlersShown[1],"BOTTOMLEFT",frameMiniBagSelectionShown,"BOTTOMLEFT")
        clearAndSetPoint(buttonHandlersShown[2],"LEFT",buttonHandlersShown[1],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[3],"LEFT",buttonHandlersShown[2],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[4],"LEFT",buttonHandlersShown[3],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[5],"BOTTOM",buttonHandlersShown[1],"TOP")
        clearAndSetPoint(buttonHandlersShown[6],"LEFT",buttonHandlersShown[5],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[7],"LEFT",buttonHandlersShown[6],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[8],"LEFT",buttonHandlersShown[7],"RIGHT")
    else
        clearAndSetPoint(buttonHandlersShown[1],"TOPLEFT",frameMiniBagSelectionShown,"TOPLEFT")
        clearAndSetPoint(buttonHandlersShown[2],"LEFT",buttonHandlersShown[1],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[3],"LEFT",buttonHandlersShown[2],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[4],"LEFT",buttonHandlersShown[3],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[5],"TOP",buttonHandlersShown[1],"BOTTOM")
        clearAndSetPoint(buttonHandlersShown[6],"LEFT",buttonHandlersShown[5],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[7],"LEFT",buttonHandlersShown[6],"RIGHT")
        clearAndSetPoint(buttonHandlersShown[8],"LEFT",buttonHandlersShown[7],"RIGHT")
    end
end

--frameMiniBagSelectionShown:SetSize(frameMiniBagSelectionSize())

local function setCurrentMyDragonBallsFontSize (handler, cantidad)
    if cantidad/10 <1 then --1digito
        if handler.size ~= 14 then
            handler.size = 14
            handler:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
        end
    elseif cantidad/100 <1 then --2 digitos
        if handler.size ~= 14 then
            handler.size = 14
            handler:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
        end
    elseif cantidad/1000 <1 then --3 digitos
        if handler.size ~= 12 then
            handler.size = 12
            handler:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
        end
    else --4 o máss
        if handler.size ~= 10 then
            handler.size = 10
            handler:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
        end
    end
end

local function setPortraitIcon (slot,itemID,cantidad, atlas)
    --print(slot,itemID,cantidad)
    --print ("icono",GetItemIcon(itemID))
    --buttonHandlersShown[slot].icon:SetTexture(GetItemIcon(itemID))
    --12.0.0 SetPortraitToTexture se eliminó y señadieron varios en funcion del uni SetPortraitToAsset SetPortraitTovarios (supongo para eliminar el icon anterior limitado a 64x64)
    -- SetPortraitToTexture(buttonHandlersShown[slot].icon,GetItemIcon(itemID))
    -- por no investigar como funcionan el nuevo, porque es una función de algún framemixin o a saber, lo hago con máscara circular aplicada a la textura.

    local text_icon = C_Item.GetItemIconByID(itemID)
    if text_icon then
        buttonHandlersShown[slot].icon:SetTexture(text_icon)
    else
        buttonHandlersShown[slot].icon:SetTexture(nil)
    end
    buttonHandlersShown[slot].qualityAtlasTex:SetAtlas(atlas, false)


    setCurrentMyDragonBallsFontSize(buttonHandlersShown[slot].text,cantidad)
    buttonHandlersShown[slot].text:SetText(cantidad)
    buttonHandlersShown[slot]:Show()
    buttonHandlersShown[slot].icon:Show()
    buttonHandlersShown[slot].text:Show()
    buttonHandlersShown[slot].qualityAtlasTex:Show()
    --print(buttonHandlersShown[slot].qualityAtlasTex:GetPoint())
end
local function removeTexFromTo(from, to)
    if (from <=8) then
        for k= from, to do
            buttonHandlersShown[k]:Hide()
            buttonHandlersShown[k].icon:Hide()
            buttonHandlersShown[k].text:Hide()
            buttonHandlersShown[k].qualityAtlasTex:Hide()
        end
    end
end

local function getQualityAtlas(itemIDorLink)
    local reagentInfo = C_TradeSkillUI.GetItemReagentQualityInfo(itemIDorLink)
    local craftedInfo = C_TradeSkillUI.GetItemCraftedQualityInfo(itemIDorLink)
    local qualityInfo = reagentInfo or craftedInfo
    --local quality = qualityInfo and qualityInfo.quality or 0
    local icon = qualityInfo and qualityInfo.icon or nil
    if icon then
        return icon
    end
    return nil
end

function ns.updateFarmIconsWithInventoryNumbers()
    local number = 0
    for k,v in pairs(AutoScrap_CharSettings.miniBagIcons)do
        local cantidad = GetItemCount(v)
        if cantidad > 0 then
            number = number + 1
            setPortraitIcon(number, v , cantidad, getQualityAtlas(v))
        end
    end
    removeTexFromTo(number+1,8)
    local altura = math.floor(((number-1)/4)+1)*40
    if altura == 0 then --cant be 0
        altura = 1
    end
        containerFrameFarmIcons:SetSize(wsize,altura)
        frameMiniBagSelectionShown:SetSize(40*4,altura)
end

local bagOpened = false
function ns.setCombatFrameInteriorIconsAndQuantities()
    bagOpened = false
    ns.updateFarmIconsWithInventoryNumbers()
    frameMiniBagIcons:Hide()
    frameMiniBagSelectionShown:Show()
    --containerFrameFarmIcons:SetSize(wsize,10) --dinamic en updateFarmIconsWithInventoryNumbers
end

function ns.setCombatFrameInteriorFullIconList()
    bagOpened = true
    ns.updateBagIconTexSlots()
    containerFrameFarmIcons:SetSize(wsize,80)
    frameMiniBagSelectionShown:Hide()
    frameMiniBagIcons:Show()
end

function ns.isbagWithIconsAndNumbersOpened()
    return bagOpened
end

--------------------------- gui party running ------------------------------------
containerPartyFrame = CreateFrame("Frame",nil,outterFrame)
containerPartyFrame.guys = {}

local function setNameRecursive(source, text)
    text = text:gsub("%.%.","")
    source:SetText(text)
    local entered = false
    if source:GetWidth() >= (wsize/2) then
        entered = true
        text = text:sub(1,-2)
        source:SetText(text.."..")
        text=setNameRecursive(source, text)
    end
    if entered then
        source:SetText(text.."..")
    end
    return text
end


local sizeButtonW, spacingPF, sizeButtonH = 14, 3, 13
containerPartyFrame.tex = containerPartyFrame:CreateTexture()
containerPartyFrame.tex:SetAllPoints(containerPartyFrame)
--containerPartyFrame.tex:SetColorTexture(170/255, 200/255, 100/255 , 0.5)
--containerPartyFrame.tex:SetColorTexture(r/255, b/255, b/255 , a/1.2)
containerPartyFrame.tex:SetColorTexture(25/255, 152/255, 227/255 , 0.4)
containerPartyFrame:SetSize(sizeButtonW+((wsize/2)*4)+(spacingPF*4),hsize-14)

containerPartyFrame:SetPoint("TOPLEFT", outterFrame, "TOPRIGHT", spacingPF, 0)
containerPartyFrame:Hide()

local partyOrientacion = ns.crearBoton3Fases(containerPartyFrame,"Interface\\AddOns\\AutoScrap\\images\\mailpanel", 0,14,231,244, function ()
    if AutoScrap_CharSettings.partyDirection == "horizontal" then
        AutoScrap_CharSettings.partyDirection = "vertical"
    else
        AutoScrap_CharSettings.partyDirection = "horizontal"
    end
    updatePartyDirection()
end)
partyOrientacion:SetPoint("TOPLEFT")

--______________ guy 1 __________________________


local function crearBolaDeDragon(slot,izq,parent,der)
    local tex = containerPartyFrame:CreateTexture(nil,"ARTWORK")
    tex:SetSize(40,40)
    tex:SetTexture("Interface\\AddOns\\AutoScrap\\images\\mailpanel") --Interface\QUESTFRAME\AutoQuest
    tex:SetTexCoord(52/510,(52+40)/512,192/512,(192+40)/512)
    --tex:SetVertexColor(123/255 ,41/255, 234/255, 1)
    tex.slot = slot
  
    tex:SetPoint(izq,parent,der)
    tex.icon = containerPartyFrame:CreateTexture(nil,"BACKGROUND")
    --tex.icon:SetVertexColor(1, 0.6, 0.1 , 1)
    tex.icon:SetSize(40,40)
    tex.icon:SetPoint(izq,parent,der)
    tex.text = containerPartyFrame:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
    tex.text:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE") --"OUTLINE,THICKOUTLINE"
    tex.text:SetPoint("BOTTOM",tex.icon, "BOTTOM",0,3)
    tex.mask = frameMiniBagSelectionShown:CreateMaskTexture()
    tex.mask:SetAllPoints(tex.icon)
    tex.mask:SetTexture("Interface/CHARACTERFRAME/TempPortraitAlphaMask", "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE")
    tex.icon:AddMaskTexture(tex.mask)
    tex.qualityAtlasTex = frameMiniBagSelectionShown:CreateTexture(nil,"OVERLAY")
    tex.qualityAtlasTex:SetSize(25,25)
    tex.qualityAtlasTex:SetPoint("TOPLEFT",tex.icon, "TOPLEFT",-2,5)
    tex:Hide()
    tex.icon:Hide()
    tex.text:Hide()

    tex.itemID = nil
    tex.currentText = nil
    tex.size = 10
    function tex:setTextItemID(itemID, text, atlas)
        if itemID == self.itemID then
            if self.currentText ~= text then
                self.currentText = text
                self:setSize(text)
                self.text:SetText(text)
            end
        else
            self.itemID = itemID
            self.currentText = text
            self.qualityAtlasTex:SetAtlas(atlas, false)
            self.qualityAtlasTex:Show()
            -- en la v12 SetPortraitToTexture(self.icon,GetItemIcon(itemID)) no existe
            local text_item_icon = C_Item.GetItemIconByID(itemID)
            if text_item_icon then
                self.icon:SetTexture(text_item_icon)
            else
                self.icon:SetTexture(nil)
            end
            self:setSize(text)
            self.text:SetText(text)
            self:Show()
            self.icon:Show()
            self.text:Show()
        end
    end
    function tex:removeIcon()
        if self.itemID ~= nil then
            self.itemID = nil
            self.currentText = nil
            self:Hide()
            self.icon:Hide()
            self.text:Hide()
            self.qualityAtlasTex:Hide()
        end
    end
    function tex:getItemID()
        return self.itemID
    end
    function tex:setSize(cantidad)
        if cantidad/10 <1 then --1digito
            if self.size ~= 12 then
                self.size = 12
                self.text:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
            end
        elseif cantidad/100 <1 then --2 digitos
            if self.size ~= 12 then
                self.size = 12
                self.text:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
            end
        else --3 o más
            if self.size ~= 10 then
                self.size = 10
                self.text:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
            end
        end
    end
    return tex
end

local function createPartyGuy(parent, ancle)

    local containerPartyFrameGuy1 = CreateFrame("Frame",nil,parent)
    containerPartyFrameGuy1.tex = containerPartyFrameGuy1:CreateTexture()
    containerPartyFrameGuy1.tex:SetAllPoints(containerPartyFrameGuy1)
    --containerPartyFrameGuy1.tex:SetColorTexture(0/255, 200/255, 100/255 , 0.5)
    --containerPartyFrameGuy1.tex:SetColorTexture(r/255, b/255, b/255 , a/1.2)
    --containerPartyFrameGuy1.tex:SetColorTexture(55/255, 55/255, 55/255 , 0.5) --, , 
    containerPartyFrameGuy1.tex:SetColorTexture(23/255, 41/255, 234/255 , 0.3)

    containerPartyFrameGuy1:SetSize((wsize/2),hsize-14+bagFullsize)
    if parent == ancle then
        containerPartyFrameGuy1:SetPoint ("TOPLEFT", ancle, "TOPLEFT", sizeButtonW+spacingPF, 0)
    else
        containerPartyFrameGuy1:SetPoint ("TOPLEFT", ancle, "TOPRIGHT", spacingPF, 0)
    end


    containerPartyFrameGuy1.nameParty1 = containerPartyFrameGuy1:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
    containerPartyFrameGuy1.nameParty1:SetFont("Fonts\\FRIZQT_.TTF" ,10, "")
    containerPartyFrameGuy1.myKillsP1 = containerPartyFrameGuy1:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
    containerPartyFrameGuy1.myKillsP1:SetFont("Fonts\\FRIZQT_.TTF" ,10, "")
    containerPartyFrameGuy1.PyMP1 = containerPartyFrameGuy1:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
    containerPartyFrameGuy1.PyMP1:SetFont("Fonts\\FRIZQT_.TTF" ,10, "")
    containerPartyFrameGuy1.MoneyP1 = containerPartyFrameGuy1:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
    containerPartyFrameGuy1.MoneyP1:SetFont("Fonts\\FRIZQT_.TTF" ,10, "")


    local containerPartyFrameGuy1Name =  CreateFrame("Frame",nil,containerPartyFrameGuy1)
    containerPartyFrameGuy1Name.tex = containerPartyFrameGuy1Name:CreateTexture()
    containerPartyFrameGuy1Name.tex:SetAllPoints(containerPartyFrameGuy1Name)
    --containerPartyFrameGuy1Name.tex:SetColorTexture(50/255, 10/255, 200/255 , 0.5) --titulo
    --containerPartyFrameGuy1Name.tex:SetColorTexture(r/255, b/255, b/255 , a/1.2)
    containerPartyFrameGuy1Name.tex:SetColorTexture(2/255, 200/255, 11/255, 0.25)

    containerPartyFrameGuy1Name:SetSize((wsize/2),14)
    containerPartyFrameGuy1Name:SetPoint ("TOP", containerPartyFrameGuy1, "TOP")
    containerPartyFrameGuy1.nameParty1:SetPoint("CENTER",containerPartyFrameGuy1Name, "CENTER")
    containerPartyFrameGuy1.nameParty1:SetParent(containerPartyFrameGuy1Name)

    local containerPartyFrameGuy1PKM = CreateFrame("FRAME",nil, containerPartyFrameGuy1)
    containerPartyFrameGuy1PKM:SetSize((wsize/2)-14-2,14)
    containerPartyFrameGuy1PKM:SetPoint("TOPLEFT",containerPartyFrameGuy1Name,"BOTTOMLEFT", 14+1,0) -- cambio el 14+2 por 14+1 para que quede 1 pixel por cada lado

    local containerPartyFrameGuy1PKMicon = ns.Utils.crearFrameConTextura (containerPartyFrameGuy1,14*(3-1), 14*(3), 166 , 179, 1,"mailpanel")
    containerPartyFrameGuy1PKMicon:SetPoint ("RIGHT",containerPartyFrameGuy1PKM,"LEFT", 0,0)

    containerPartyFrameGuy1.myKillsP1:SetParent(containerPartyFrameGuy1)
    containerPartyFrameGuy1.myKillsP1:SetPoint("CENTER",containerPartyFrameGuy1PKM,"CENTER")

    local containerPartyFrameGuy1PyM = CreateFrame("FRAME",nil, containerPartyFrameGuy1)
    containerPartyFrameGuy1PyM:SetSize((wsize/2)-14-2,14)
    containerPartyFrameGuy1PyM:SetPoint("TOPLEFT",containerPartyFrameGuy1PKM,"BOTTOMLEFT", 0,0)

    local containerPartyFrameGuy1PyMIcon = ns.Utils.crearFrameConTextura (containerPartyFrameGuy1,14*(11-1), 14*(11), 166 , 179, 1,"mailpanel")
    containerPartyFrameGuy1PyMIcon:SetPoint ("RIGHT",containerPartyFrameGuy1PyM,"LEFT", 0,0)

    containerPartyFrameGuy1.PyMP1:SetParent(containerPartyFrameGuy1)
    containerPartyFrameGuy1.PyMP1:SetPoint("CENTER",containerPartyFrameGuy1PyM,"CENTER")

    local containerPartyFrameGuy1Money = CreateFrame("FRAME",nil, containerPartyFrameGuy1)
    containerPartyFrameGuy1Money:SetSize((wsize/2)-14-2,14)
    containerPartyFrameGuy1Money:SetPoint("TOPLEFT",containerPartyFrameGuy1PyM,"BOTTOMLEFT", 0,0)

    local containerPartyFrameGuy1MoneyIcon = ns.Utils.crearFrameConTextura (containerPartyFrameGuy1,14*(4-1), 14*(4), 166 , 179, 1,"mailpanel")
    containerPartyFrameGuy1MoneyIcon:SetPoint ("RIGHT",containerPartyFrameGuy1Money,"LEFT", 0,0)

    containerPartyFrameGuy1.MoneyP1:SetParent(containerPartyFrameGuy1)
    containerPartyFrameGuy1.MoneyP1:SetPoint("CENTER",containerPartyFrameGuy1Money,"CENTER")

    containerPartyFrameGuy1.bolasDeDragon = {}
    containerPartyFrameGuy1.bolasDeDragon[1] = crearBolaDeDragon(1,"TOPLEFT",containerPartyFrameGuy1,"BOTTOMLEFT")
    containerPartyFrameGuy1.bolasDeDragon[2] = crearBolaDeDragon(2,"LEFT",containerPartyFrameGuy1.bolasDeDragon[1],"RIGHT")
    containerPartyFrameGuy1.bolasDeDragon[3] = crearBolaDeDragon(3,"TOPLEFT",containerPartyFrameGuy1.bolasDeDragon[1],"BOTTOMLEFT")
    containerPartyFrameGuy1.bolasDeDragon[4] = crearBolaDeDragon(4,"LEFT",containerPartyFrameGuy1.bolasDeDragon[3],"RIGHT")
    containerPartyFrameGuy1.bolasDeDragon[5] = crearBolaDeDragon(5,"TOPLEFT",containerPartyFrameGuy1.bolasDeDragon[3],"BOTTOMLEFT")
    containerPartyFrameGuy1.bolasDeDragon[6] = crearBolaDeDragon(6,"LEFT",containerPartyFrameGuy1.bolasDeDragon[5],"RIGHT")
    containerPartyFrameGuy1.bolasDeDragon[7] = crearBolaDeDragon(7,"TOPLEFT",containerPartyFrameGuy1.bolasDeDragon[5],"BOTTOMLEFT")
    containerPartyFrameGuy1.bolasDeDragon[8] = crearBolaDeDragon(8,"LEFT",containerPartyFrameGuy1.bolasDeDragon[7],"RIGHT")


    containerPartyFrameGuy1.bagBar = CreateFrame("Frame",nil, containerPartyFrameGuy1)
    containerPartyFrameGuy1.bagBar:SetSize(wsize/2,bagFullsize)
    containerPartyFrameGuy1.bagBar.tex = containerPartyFrameGuy1.bagBar:CreateTexture()
    --containerPartyFrameGuy1.bagBar.tex:SetAllPoints(containerPartyFrameGuy1.bagBar)
    containerPartyFrameGuy1.bagBar.tex:SetPoint("LEFT")
    containerPartyFrameGuy1.bagBar.tex:SetSize(0,bagFullsize)
    --containerPartyFrameGuy1.bagBar.tex:SetColorTexture(244/255, 180/255, 43/255 , 1) --amarillo
    --containerPartyFrameGuy1.bagBar.tex:SetColorTexture(43/255, 46/255, 244/255 , 1) --azul
    containerPartyFrameGuy1.bagBar.tex:SetColorTexture(0/255, 10/255, 62/255 , 0.6) --azul oscuro
    --containerPartyFrameGuy1.bagBar.tex:SetColorTexture(243/255, 36/255, 26/255 , 1) --rojo
    --containerPartyFrameGuy1.bagBar.tex:SetColorTexture(56/255, 26/255, 5/255 , 1) --marron
    containerPartyFrameGuy1.bagBar:SetPoint("BOTTOMLEFT",containerPartyFrameGuy1,"BOTTOMLEFT", 0,0)

    containerPartyFrameGuy1.barPorcentaje = 0
    function containerPartyFrameGuy1:SetBarPercentage(percentage)
        if percentage ~= self.barPorcentaje then
            self.barPorcentaje = percentage
            --self.bagBar:SetSize(math.floor(((wsize/2)*percentage)/100),bagFullsize)
            self.bagBar.tex:SetSize(math.floor(((wsize/2)*percentage)/100),bagFullsize)
            if percentage<95 then
                self.bagBar.tex:SetColorTexture(0/255, 10/255, 62/255 , 0.6)
            else
                self.bagBar.tex:SetColorTexture(243/255, 36/255, 26/255 , 0.6)
            end
        end
    end
    --containerPartyFrameGuy1:SetBarPercentage(80)

    function containerPartyFrameGuy1:restartText() --except name
        self.myKillsP1:SetText("--")
        self.PyMP1:SetText("--")
        self.MoneyP1:SetText("--")
        self.lastKills, self.lastPlant, self.lastMoney = nil,nil,nil
        self.bolasDeDragon[1]:removeIcon()
        self.bolasDeDragon[2]:removeIcon()
        self.bolasDeDragon[3]:removeIcon()
        self.bolasDeDragon[4]:removeIcon()
        self.bolasDeDragon[5]:removeIcon()
        self.bolasDeDragon[6]:removeIcon()
        self.bolasDeDragon[7]:removeIcon()
        self.bolasDeDragon[8]:removeIcon()
        self.bolasDeDragonItem = {}
        self:SetBarPercentage(0)
    end
    containerPartyFrameGuy1.setName = ""
    function containerPartyFrameGuy1:SetName(name)
        self:restartText()
        self.setName = name
        setNameRecursive(self.nameParty1, name:sub(1,(name:find("-") or 0)-1))
        self:Show()
    end
    function containerPartyFrameGuy1:RemoveName()
        self:restartText()
        self.nameParty1:SetText("")
        self.setName = ""
        self:Hide()
    end
    function containerPartyFrameGuy1:GetName()
        return self.setName
    end
    function containerPartyFrameGuy1:ReloadButtonPressedToRestartDataExceptName()
        self:restartText()
    end
    containerPartyFrameGuy1.lastKills, containerPartyFrameGuy1.lastPlant, containerPartyFrameGuy1.lastMoney = nil,nil,nil
    function containerPartyFrameGuy1:SetKillsPlantMoney(kills, plant, money)
        if kills ~= self.lastKills then
            self.myKillsP1:SetText(kills)
            self.lastKills = kills 
        end
        if plant ~= self.lastPlant then
            self.PyMP1:SetText(plant)
            self.lastPlant = plant
        end
        if money ~= self.lastMoney then
            self.MoneyP1:SetText(money.."g")
            self.lastMoney = money
        end
    end
    containerPartyFrameGuy1.bolasDeDragonItem = {} -- [itemID] - slot
    function containerPartyFrameGuy1:NewItemToBalls(itemID, cantidad)
        --print (itemID, cantidad, self.bolasDeDragonItem[itemID])
        if self.bolasDeDragonItem[itemID] then
            self.bolasDeDragon[self.bolasDeDragonItem[itemID]]:setTextItemID(itemID, cantidad, getQualityAtlas(itemID))
        else
            for slot=1,8 do
                --print (AutoScrap_CharSettings.miniBagIcons[slot])
                if itemID == AutoScrap_CharSettings.miniBagIcons[slot] then
                    for ball=1, 8 do
                        --print("->", self.bolasDeDragon[ball]:getItemID())
                        if self.bolasDeDragon[ball]:getItemID() == nil then
                            self.bolasDeDragon[ball]:setTextItemID(itemID,cantidad,getQualityAtlas(itemID))
                            self.bolasDeDragonItem[itemID]=ball
                            break
                        end
                    end
                    break
                end
            end
        end
    end

    function containerPartyFrameGuy1:RepopulateBolas()
        self.bolasDeDragon[1]:removeIcon()
        self.bolasDeDragon[2]:removeIcon()
        self.bolasDeDragon[3]:removeIcon()
        self.bolasDeDragon[4]:removeIcon()
        self.bolasDeDragon[5]:removeIcon()
        self.bolasDeDragon[6]:removeIcon()
        self.bolasDeDragon[7]:removeIcon()
        self.bolasDeDragon[8]:removeIcon()
        self.bolasDeDragonItem={}
        for slot=1, 8 do
            local itemID = AutoScrap_CharSettings.miniBagIcons[slot]
            if itemID then
                local cantidad = ns.getItemDataFromName(self.setName, itemID)
                if cantidad then
                    self:NewItemToBalls(itemID, cantidad)
                end
            end
        end
        --[[ setTextItemID getItemID
        for bola = 1, 8 do
            if not self.bolasDeDragon[bola]:getItemID()
        end ]]
        
    end

    --local time = GetTimePreciseSec()
        
    --[[ for x=1,8 do
        containerPartyFrameGuy1.bolasDeDragon[x]:setTextItemID(86547,math.random(1,2)==1 and math.random(1,9) or math.random(1,5099))
        containerPartyFrameGuy1.bolasDeDragon[x]:SetScale(0.70)
        containerPartyFrameGuy1.bolasDeDragon[x].icon:SetScale(0.70)
        containerPartyFrameGuy1.bolasDeDragon[x].text:SetScale(0.80)
    end ]]
    --print("total exec time: ",(GetTimePreciseSec()-time)*1000)

    containerPartyFrameGuy1:Hide()
    return containerPartyFrameGuy1
end

local function clearAndSetPointDragonBall(tex, left, parent, right, xoffset, yoffset, size)
    tex:ClearAllPoints()
    tex.icon:ClearAllPoints()
    local xoff, yoff = 0,0
    if xoffset and yoffset then
        xoff = xoffset
        yoff = yoffset
    end
    if size then
        tex:SetSize(size,size)
        tex.icon:SetSize(size,size)
    end
    tex:SetPoint(left, parent, right, xoffset, yoffset)
    tex.icon:SetPoint(left, parent, right, xoffset, yoffset)
end

local function clearAndSetPartyNumber(container, direccion)
    if direccion == "derecha" then
        partyOrientacion:ClearAllPoints()
        partyOrientacion:SetPoint("TOPLEFT")
        for x=1, 4 do
            container[x]:ClearAllPoints()
            if x == 1 then
                container[x]:SetPoint ("TOPLEFT", containerPartyFrame, "TOPLEFT", sizeButtonW+spacingPF, 0)
            else
                container[x]:SetPoint ("TOPLEFT", container[x-1], "TOPRIGHT", spacingPF, 0)
            end
        end
    elseif direccion == "izquierda" then
        partyOrientacion:ClearAllPoints()
        partyOrientacion:SetPoint("TOPRIGHT")
        for x=1, 4 do
            container[x]:ClearAllPoints()
            if x == 1 then
                container[x]:SetPoint ("TOPRIGHT", containerPartyFrame, "TOPRIGHT", -(sizeButtonW+spacingPF), 0)
            else
                container[x]:SetPoint ("TOPRIGHT", container[x-1], "TOPLEFT", -spacingPF, 0)
            end
        end
    elseif direccion == "abajo" then
        partyOrientacion:ClearAllPoints()
        partyOrientacion:SetPoint("TOPLEFT")
        for x=1, 4 do
            container[x]:ClearAllPoints()
            if x == 1 then
                container[x]:SetPoint ("TOPLEFT", containerPartyFrame, "TOPLEFT", 0, -(sizeButtonH+spacingPF))
            else
                container[x]:SetPoint ("TOPLEFT", container[x-1], "BOTTOMLEFT",  0, -spacingPF)
            end
        end
    elseif direccion == "arriba" then
        partyOrientacion:ClearAllPoints()
        partyOrientacion:SetPoint("BOTTOMLEFT")
        for x=1, 4 do
            container[x]:ClearAllPoints()
            if x == 1 then
                container[x]:SetPoint ("BOTTOMLEFT", containerPartyFrame, "BOTTOMLEFT", 0, (sizeButtonH+spacingPF))
            else
                container[x]:SetPoint ("BOTTOMLEFT", container[x-1], "TOPLEFT",  0, spacingPF)
            end
        end
    end
end

local ballVSize, ballHSize = 30,36

local function updatePartyNumber(container,  direccion)
    if direccion == "abajo" then
        for x = 1, 4 do
            clearAndSetPointDragonBall(container[x].bolasDeDragon[1],"TOPLEFT",container[x],"BOTTOMLEFT",((wsize/2)-(ballHSize*2))/2,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[2],"LEFT",container[x].bolasDeDragon[1],"RIGHT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[3],"TOPLEFT",container[x].bolasDeDragon[1],"BOTTOMLEFT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[4],"LEFT",container[x].bolasDeDragon[3],"RIGHT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[5],"TOPLEFT",container[x].bolasDeDragon[3],"BOTTOMLEFT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[6],"LEFT",container[x].bolasDeDragon[5],"RIGHT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[7],"TOPLEFT",container[x].bolasDeDragon[5],"BOTTOMLEFT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[8],"LEFT",container[x].bolasDeDragon[7],"RIGHT",0,0,ballHSize)
        end
    elseif direccion == "arriba" then
        for x = 1, 4 do
            clearAndSetPointDragonBall(container[x].bolasDeDragon[1],"BOTTOMLEFT",container[x],"TOPLEFT",((wsize/2)-(ballHSize*2))/2,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[2],"LEFT",container[x].bolasDeDragon[1],"RIGHT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[3],"BOTTOMLEFT",container[x].bolasDeDragon[1],"TOPLEFT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[4],"LEFT",container[x].bolasDeDragon[3],"RIGHT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[5],"BOTTOMLEFT",container[x].bolasDeDragon[3],"TOPLEFT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[6],"LEFT",container[x].bolasDeDragon[5],"RIGHT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[7],"BOTTOMLEFT",container[x].bolasDeDragon[5],"TOPLEFT",0,0,ballHSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[8],"LEFT",container[x].bolasDeDragon[7],"RIGHT",0,0,ballHSize)
        end
    elseif direccion == "derecha" then
        for x = 1, 4 do
            clearAndSetPointDragonBall(container[x].bolasDeDragon[1],"TOPLEFT",container[x],"TOPRIGHT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[2],"TOPLEFT",container[x].bolasDeDragon[1],"BOTTOMLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[3],"TOPLEFT",container[x].bolasDeDragon[1],"TOPRIGHT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[4],"TOPLEFT",container[x].bolasDeDragon[3],"BOTTOMLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[5],"TOPLEFT",container[x].bolasDeDragon[3],"TOPRIGHT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[6],"TOPLEFT",container[x].bolasDeDragon[5],"BOTTOMLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[7],"TOPLEFT",container[x].bolasDeDragon[5],"TOPRIGHT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[8],"TOPLEFT",container[x].bolasDeDragon[7],"BOTTOMLEFT", 0,0,ballVSize)
        end
    elseif direccion == "izquierda" then
        for x = 1, 4 do
            clearAndSetPointDragonBall(container[x].bolasDeDragon[1],"TOPRIGHT",container[x],"TOPLEFT",0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[2],"TOPLEFT",container[x].bolasDeDragon[1],"BOTTOMLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[3],"TOPRIGHT",container[x].bolasDeDragon[1],"TOPLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[4],"TOPLEFT",container[x].bolasDeDragon[3],"BOTTOMLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[5],"TOPRIGHT",container[x].bolasDeDragon[3],"TOPLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[6],"TOPLEFT",container[x].bolasDeDragon[5],"BOTTOMLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[7],"TOPRIGHT",container[x].bolasDeDragon[5],"TOPLEFT", 0,0,ballVSize)
            clearAndSetPointDragonBall(container[x].bolasDeDragon[8],"TOPLEFT",container[x].bolasDeDragon[7],"BOTTOMLEFT", 0,0,ballVSize)
        end
    end
end

local numGuysOnPartyAtMoment = 0
local function resizeContainerPartyFrame()
    if AutoScrap_CharSettings.partyDirection == "horizontal" then
        containerPartyFrame:SetSize(sizeButtonW+((wsize/2)*numGuysOnPartyAtMoment)+(spacingPF*numGuysOnPartyAtMoment),hsize-14+bagFullsize)
        --print(sizeButtonW+((wsize/2)*numGuysOnPartyAtMoment)+(spacingPF*numGuysOnPartyAtMoment),hsize-14)
    else
        containerPartyFrame:SetSize(((wsize/2)*1)+(spacingPF*0),((hsize-14+bagFullsize)*numGuysOnPartyAtMoment)+sizeButtonH+(spacingPF*numGuysOnPartyAtMoment))
        --print(((wsize/2)*1)+(spacingPF*0),((hsize-14)*numGuysOnPartyAtMoment)+sizeButtonH+(spacingPF*numGuysOnPartyAtMoment))
    end
    if numGuysOnPartyAtMoment == 0 then
        containerPartyFrame:Hide()
    else
        containerPartyFrame:Show()
    end
end

updatePartyDirection = function ()
    containerPartyFrame:ClearAllPoints()
    if AutoScrap_CharSettings.partyDirection == "horizontal" then
        --containerPartyFrame:SetSize(sizeButtonW+((wsize/2)*4)+(spacingPF*4),hsize-14)
        resizeContainerPartyFrame()
        if AutoScrap_CharSettings.CombatFrame.startPoint == "CENTER" then
            containerPartyFrame:SetPoint("TOPLEFT", outterFrame, "TOPRIGHT", spacingPF, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "derecha")
            updatePartyNumber(containerPartyFrame.guys, "abajo")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOP" then
            containerPartyFrame:SetPoint("TOPLEFT", outterFrame, "TOPRIGHT", spacingPF, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "derecha")
            updatePartyNumber(containerPartyFrame.guys, "abajo")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOPLEFT" then
            containerPartyFrame:SetPoint("TOPLEFT", outterFrame, "TOPRIGHT", spacingPF, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "derecha")
            updatePartyNumber(containerPartyFrame.guys, "abajo")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "LEFT" then
            containerPartyFrame:SetPoint("TOPLEFT", outterFrame, "TOPRIGHT", spacingPF, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "derecha")
            updatePartyNumber(containerPartyFrame.guys, "abajo")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOM" then
            containerPartyFrame:SetPoint("BOTTOMLEFT", outterFrame, "BOTTOMRIGHT", spacingPF, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "derecha")
            updatePartyNumber(containerPartyFrame.guys, "arriba")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMLEFT" then
            containerPartyFrame:SetPoint("BOTTOMLEFT", outterFrame, "BOTTOMRIGHT", spacingPF, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "derecha")
            updatePartyNumber(containerPartyFrame.guys, "arriba")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOPRIGHT" then
            containerPartyFrame:SetPoint("TOPRIGHT", outterFrame, "TOPLEFT", -spacingPF-1, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "izquierda")
            updatePartyNumber(containerPartyFrame.guys, "abajo")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "RIGHT" then
            containerPartyFrame:SetPoint("TOPRIGHT", outterFrame, "TOPLEFT", -spacingPF-1, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "izquierda")
            updatePartyNumber(containerPartyFrame.guys, "abajo")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMRIGHT" then
            containerPartyFrame:SetPoint("BOTTOMRIGHT", outterFrame, "BOTTOMLEFT", -spacingPF-1, 0)
            clearAndSetPartyNumber(containerPartyFrame.guys, "izquierda")
            updatePartyNumber(containerPartyFrame.guys, "arriba")
        end
    else
        --containerPartyFrame:SetSize(((wsize/2)*1)+(spacingPF*0),((hsize-14)*4)+sizeButtonH+(spacingPF*4))
        resizeContainerPartyFrame()
        if AutoScrap_CharSettings.CombatFrame.startPoint == "CENTER" then
            containerPartyFrame:SetPoint("TOPLEFT", containerFrameFarmIcons, "BOTTOMLEFT", 0, -spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "abajo")
            updatePartyNumber(containerPartyFrame.guys, "derecha")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOP" then
            containerPartyFrame:SetPoint("TOPLEFT", containerFrameFarmIcons, "BOTTOMLEFT", 0, -spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "abajo")
            updatePartyNumber(containerPartyFrame.guys, "derecha")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOPLEFT" then
            containerPartyFrame:SetPoint("TOPLEFT", containerFrameFarmIcons, "BOTTOMLEFT", 0, -spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "abajo")
            updatePartyNumber(containerPartyFrame.guys, "derecha")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "LEFT" then
            containerPartyFrame:SetPoint("TOPLEFT", containerFrameFarmIcons, "BOTTOMLEFT", 0, -spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "abajo")
            updatePartyNumber(containerPartyFrame.guys, "derecha")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOM" then
            containerPartyFrame:SetPoint("BOTTOMLEFT", containerFrameFarmIcons, "TOPLEFT", 0, spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "arriba")
            updatePartyNumber(containerPartyFrame.guys, "derecha")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMLEFT" then
            containerPartyFrame:SetPoint("BOTTOMLEFT", containerFrameFarmIcons, "TOPLEFT", 0, spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "arriba")
            updatePartyNumber(containerPartyFrame.guys, "derecha")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "TOPRIGHT" then
            containerPartyFrame:SetPoint("TOPRIGHT", containerFrameFarmIcons, "BOTTOMRIGHT", 0, -spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "abajo")
            updatePartyNumber(containerPartyFrame.guys, "izquierda")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "RIGHT" then
            containerPartyFrame:SetPoint("TOPRIGHT", containerFrameFarmIcons, "BOTTOMRIGHT", 0, -spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "abajo")
            updatePartyNumber(containerPartyFrame.guys, "izquierda")
        elseif AutoScrap_CharSettings.CombatFrame.startPoint == "BOTTOMRIGHT" then
            containerPartyFrame:SetPoint("BOTTOMRIGHT", containerFrameFarmIcons, "TOPRIGHT", 0, spacingPF)
            clearAndSetPartyNumber(containerPartyFrame.guys, "arriba")
            updatePartyNumber(containerPartyFrame.guys, "izquierda")
        end
    end
end

containerPartyFrame.guys[1] = createPartyGuy(containerPartyFrame,containerPartyFrame)
containerPartyFrame.guys[2] = createPartyGuy(containerPartyFrame,containerPartyFrame.guys[1])
containerPartyFrame.guys[3] = createPartyGuy(containerPartyFrame,containerPartyFrame.guys[2])
containerPartyFrame.guys[4] = createPartyGuy(containerPartyFrame,containerPartyFrame.guys[3])

local tablaNombre = {} --[nombre] = hueco
local function resetPartyStatus()
    for x=1, 4 do
        containerPartyFrame.guys[x]:RemoveName()
    end
    numGuysOnPartyAtMoment = 0
    tablaNombre = {}
    resizeContainerPartyFrame()
end

local isPartyRunning = false
function ns.addNewPlayer(name)
    if isPartyRunning then
        --[[ if containerPartyFrame.guys[1]:GetName() == "" then
            containerPartyFrame.guys[1]:SetName(name)
            numGuysOnPartyAtMoment = numGuysOnPartyAtMoment + 1
            resizeContainerPartyFrame()
        else ]]
        for x=1, 4 do
            if containerPartyFrame.guys[x]:GetName() == "" then
                containerPartyFrame.guys[x]:SetName(name)
                tablaNombre[name] = x
                numGuysOnPartyAtMoment = numGuysOnPartyAtMoment + 1
                resizeContainerPartyFrame()
                break
            end
        end
        --end
    end
end
function ns.setPlayerKPD(name,k,p,d)
    --if isPartyRunning then --no es necesario xk en la cache y party.lua ya tiene eso para mandarlo
        containerPartyFrame.guys[tablaNombre[name]]:SetKillsPlantMoney(k,p,d)
    --end
end

function ns.senderHasNewItem (sender, itemID, cantidad)
    --if isPartyRunning then --no es necesario xk en la cache y party.lua ya tiene eso para mandarlo
        containerPartyFrame.guys[tablaNombre[sender]]:NewItemToBalls(itemID, cantidad)
    --end
end

function ns.senderHasNewBagPercentage(sender, bagPercentage)
    containerPartyFrame.guys[tablaNombre[sender]]:SetBarPercentage(bagPercentage)
end

local function populateData(tablaID,name)
    local kills, plants, gold = ns.getAllDataFromName(name)
    if kills and plants and gold then
        containerPartyFrame.guys[tablaID]:SetKillsPlantMoney(kills, plants,gold)
    end
    containerPartyFrame.guys[tablaID]:RepopulateBolas()
    containerPartyFrame.guys[tablaID]:SetBarPercentage(ns.getPorcentajeBolsaLlena(name) or 0)
end

function ns.removePlayerFromCombatFrame(name)
    if isPartyRunning then
        for x=1, 4 do
            if containerPartyFrame.guys[x]:GetName() == name then
                containerPartyFrame.guys[x]:RemoveName()
                tablaNombre[name] = nil
                numGuysOnPartyAtMoment = numGuysOnPartyAtMoment - 1
                for y=x+1, 4 do
                    local tempName = containerPartyFrame.guys[y]:GetName()
                    if tempName ~= "" then
                        containerPartyFrame.guys[y]:RemoveName()
                        containerPartyFrame.guys[y-1]:SetName(tempName)
                        tablaNombre[tempName] = y-1
                        populateData(y-1,tempName)
                    end
                end
                resizeContainerPartyFrame()
                break
            end
        end
    end
end

function ns.setPartyRunning(value)
    if value then
        isPartyRunning = true
        containerPartyFrame:Show()
        resetPartyStatus()
    else
        containerPartyFrame:Hide()
        isPartyRunning = false
        resetPartyStatus()
    end
end


--test
--ns.setPartyRunning(true)

--[[ ns.addNewPlayer("Silithiana-Nogganon")
ns.addNewPlayer("perez")
ns.addNewPlayer("Paco")
ns.addNewPlayer("Juan") ]]

      

--[[ ns.AddSendertkmkdp(4, 5, 6, "Silithiana-Nogganon")
ns.AddSendertkmkdp(4, 2, 7, "perez")
ns.AddSendertkmkdp(4, 3, 7, "Paco")
ns.AddSendertkmkdp(1, 6, 9, "Juan")

ns.AddSendertkmkdp(6, 8, 10, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 8, 11, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 8, 12, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 8, 13, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 8, 14, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 8, 15, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 8, 16, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 8, 17, "Silithiana-Nogganon")
ns.AddSendertkmkdp(6, 4, 9, "perez")
ns.AddSendertkmkdp(7,6, 10, "Paco")
ns.AddSendertkmkdp(5, 10, 13, "Juan")

--ns.removePlayer("perez")

ns.AddSenderItem(52326, 1, "perez")
ns.AddSenderItem(86547, 4, "perez")
ns.AddSenderItem(86547, 4, "perez")
ns.AddSenderItem(86547, 4, "perez")
ns.AddSenderItem(52326, 1, "perez")
local time = GetTimePreciseSec()
print("total exec time: ",(GetTimePreciseSec()-time)*1000)

ns.removePlayer("Silithiana-Nogganon")
ns.removePlayer("Paco") ]]




--[[ containerPartyFrame.guys[1]:SetName("Silithiana-Nogganon")
--containerPartyFrame.guys[1]:RemoveName()
containerPartyFrame.guys[2]:SetName("Paco-Nogganon")
containerPartyFrame.guys[3]:SetName("Susana")
containerPartyFrame.guys[4]:SetName("test-Draenor")
containerPartyFrame.guys[4]:SetKillsPlantMoney(3, 12, 134) ]]

--fin test

--[[ setTooltip(totalkillsIcon,L["Total Kills across partys"])
setTooltip(underFrameTK,L["Total Kills across partys"]) ]]
setTooltip(info, L["Kill Statistics"],L["On the left side it shows the kills across multiples partys, the kills of your party, your own kills and the gold you won."],L["On the right side It shows the same kills/gold but simulated per hour if you keep the same killing speed."],L["The bottom bar it's your inventory space occupied"])