WoWInterface SVN FarmFu

[/] [trunk/] [FuBar_FarmFu/] [FarmFu.lua] - Rev 5

Compare with Previous | Blame | View Log

local tablet = AceLibrary("Tablet-2.0")
local dewdrop = AceLibrary("Dewdrop-2.0")
local abacus = LibStub("LibAbacus-3.0")
local L = AceLibrary("AceLocale-2.2"):new("FarmFu") --need to uses this at some point

FarmFu = AceLibrary("AceAddon-2.0"):new("FuBarPlugin-2.0", "AceDB-2.0", "AceEvent-2.0", "AceHook-2.1", "AceConsole-2.0")
FarmFu.hideWithoutStandby = true
FarmFu.hasIcon = true
FarmFu:RegisterDB("FarmFuDB") -- registers db with AceDB 2.0
FarmFu.version = "0.1.wowi:revision"
FarmFu.frame = FarmFu:CreateBasicPluginFrame("FarmFuFrame") -- makes the button on FuBar?

--
local self = FarmFu
local zoneAreaOld
local zoneBagOld
local zoneDurOld
local zoneKeyOld
local zoneInvOld
local zoneGoldOld
local zoneTotalOld
local zoneTimeOld

local sessionAreaOld
local sessionBagOld
local sessionDurOld
local sessionKeyOld
local sessionInvOld
local sessionGoldOld
local sessionTotalOld
local sessionTimeOld

local browser
local DurabilityTooltip

function self:OnInitialize()
        self:RegisterEvent("ZONE_CHANGED")
        self:RegisterEvent("ZONE_CHANGED_INDOORS")
        self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
        self:RegisterEvent("PLAYER_LOGOUT")
        self:RegisterEvent("CHAT_MSG_ADDON")
        
        zoneAreaOld = "The Real World"
        zoneBagOld = self:AppraiseBags()
        zoneDurOld = self:AppraiseDurability()
        zoneKeyOld = self:AppraiseKeyring()
        zoneInvOld = self:AppraiseInventory()
        zoneGoldOld = GetMoney()
        zoneTotalOld = (zoneBagOld + zoneKeyOld + zoneInvOld + zoneGoldOld)
        zoneTimeOld = time()
        
        -- FuBar Button
        self.hasIcon = true
        self.canHideText = true
        local FuBarButton = self.frame
        local FuBarIcon = FuBarButton:CreateTexture("FarmFuFrameIcon", "ARTWORK")
        FuBarIcon:SetWidth(16)
        FuBarIcon:SetHeight(16)
        FuBarIcon:SetPoint("LEFT", FuBarButton, "LEFT")
        self.iconFrame = FuBarIcon

        local FuBarText = FuBarButton:CreateFontString("FarmFuFrameText", "OVERLAY")
        FuBarText:SetJustifyH("RIGHT")
        FuBarText:SetPoint("RIGHT", FuBarButton, "RIGHT", 0, 1)
        FuBarText:SetFontObject(GameFontNormal)
        self.textFrame = FuBarText
        -- ----------------
        
        self:DurabilityTooltip()

        self:SetIcon(true)
        
        self:setDefaults()
        
        self:ScheduleRepeatingEvent("FarmFuUpdater", self.UpdateText, 2, self)
        
end

-- ---------UI section--local money, bagvalue, invvalue, keyvalue, durvalue, totalvalue = self:AppraiseEverything()
function self:DurabilityTooltip() --creates a little hidden tooltip so I can get durability data
        DurabilityTooltip = CreateFrame("GameTooltip", "DurabilityTooltip", nil, "GameTooltipTemplate")
        DurabilityTooltip:SetOwner(WorldFrame, "UIParent")
        DurabilityTooltip:SetPoint("CENTER",0,0)
        DurabilityTooltip:Hide()
end

function self:OnClick() -- left click
        self:SetupFrames()
end

function self:OnMenuRequest(level, value) -- Right click menu
        if level == 1 then
                --[[ From here ]]--
                dewdrop:AddLine(
                        'text', "print DB",
                        'tooltipTitle', "it's ugly",
                        'arg1', self,
                        'func', "showZonesToChat",
                        'closeWhenClicked', true
                )
                
                dewdrop:AddLine(
                        'text', "delete DB",
                        'tooltipTitle', "Permanantly deletes data.",
                        'arg1', self,
                        'func', "resetZones",
                        'closeWhenClicked', true
                )
                --[[ to here should get deleted when FarmFuBrowser works ]]--
                
                dewdrop:AddLine(
                        'text', L["Reset_Session"],
                        'tooltipTitle', L["Reset_Session_Tooltip"],
                        'arg1', self,
                        'func', "ResetSession",
                        'closeWhenClicked', true
                )
                                
                dewdrop:AddLine(
                        'text', L["Show_Session"],
                        'tooltipTitle', L["Show_Session_Tooltip"],
                        'arg1', self,
                        'func', function()
                                self.db.profile.showSession = not self.db.profile.showSession
                                self:UpdateText()
                        end,
                        'checked', self.db.profile.showSession
                )

                dewdrop:AddLine(
                        'text', L["Show_Total"],
                        'tooltipTitle', L["Show_Total_Tooltip"],
                        'arg1', self,
                        'func', function()
                                self.db.profile.showTotalValue = not self.db.profile.showTotalValue
                                self:UpdateText()
                        end,
                        'checked', self.db.profile.showTotalValue
                )
                
                dewdrop:AddLine(
                        'text', L["Show_Debug"],
                        'tooltipTitle', L["Show_Debug_Tooltip"],
                        'arg1', self,
                        'func', function()
                                self.db.profile.showDebug = not self.db.profile.showDebug
                                self:UpdateText()
                        end,
                        'checked', self.db.profile.showDebug
                )
                
                dewdrop:AddLine(
                        'text', L["Instance_Zones"],
                        'tooltipTitle', L["Instance_Zones_Tooltip"],
                        'arg1', self,
                        'func', function()
                                self.db.profile.instances = not self.db.profile.instances
                                self:UpdateText()
                        end,
                        'checked', self.db.profile.instances
                )
                dewdrop:AddLine(
                        'text', L["Ignore_Mules"],
                        'tooltipTitle', L["Ignore_Mules_Tooltip"],
                        'arg1', self,
                        'func', function()
                                self.db.profile.ignoremules = not self.db.profile.ignoremules
                                self:UpdateText()
                        end,
                        'checked', self.db.profile.instances
                )
                
                dewdrop:AddLine()
        end
end

function self:OnTooltipUpdate() -- this is  mouseover
        local now = time()
        local func = abacus.FormatMoneyFull
        local money, bagvalue, invvalue, keyvalue, durvalue, totalvalue = self:AppraiseEverything()
        local sessionTime = (now - sessionTimeOld)
        local zoneTime = (now - zoneTimeOld)
        local supercat = tablet:AddCategory(
                'columns', 5,
                'child_text', "",
                'child_text2', L["Mouseover_Start"],
                'child_text3', L["Mouseover_Current"],
                'child_text4', L["Mouseover_Change"],
                'child_text5', L["Mouseover_perhour"],
                'child_child_textR', 1,
                'child_child_textG', 1,
                'child_child_textB', 0,
                'child_child_text2R', 1,
                'child_child_text2G', 1,
                'child_child_text2B', 1,
                'child_child_text3R', 1,
                'child_child_text3G', 1,
                'child_child_text3B', 1,
                'child_child_text4R', 1,
                'child_child_text4G', 1,
                'child_child_text4B', 1,
                'child_child_text5R', 1,
                'child_child_text5G', 1,
                'child_child_text5B', 1
        )

        ------------
        -- Session totals
        -- ------------
        cat = supercat:AddCategory(
                'text', L["Mouseover_Session"]
        )
    --abacus:FormatMoneyFull(hourlytotalprofit, true)
        cat:AddLine(
                'text', L["Mouseover_Inventory"],
                'text2', abacus:FormatMoneyFull(sessionInvOld, true),
                'text3', abacus:FormatMoneyFull(invvalue, true),
                'text4', abacus:FormatMoneyFull((invvalue - sessionInvOld), true),
                'text5', abacus:FormatMoneyFull((((invvalue - sessionInvOld) / sessionTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Bags"],
                'text2', abacus:FormatMoneyFull(sessionBagsOld, true),
                'text3', abacus:FormatMoneyFull(bagvalue, true),
                'text4', abacus:FormatMoneyFull((bagvalue - sessionBagsOld), true),
                'text5', abacus:FormatMoneyFull((((bagvalue - sessionBagsOld) / sessionTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Keys"],
                'text2', abacus:FormatMoneyFull(sessionKeysOld, true),
                'text3', abacus:FormatMoneyFull(keyvalue, true),
                'text4', abacus:FormatMoneyFull((keyvalue - sessionKeysOld), true),
                'text5', abacus:FormatMoneyFull((((keyvalue - sessionKeysOld) / sessionTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Repair"],
                'text2', abacus:FormatMoneyFull(sessionDurOld, true),
                'text3', abacus:FormatMoneyFull(durvalue, true),
                'text4', abacus:FormatMoneyFull((durvalue - sessionDurOld), true),
                'text5', abacus:FormatMoneyFull((((durvalue - sessionDurOld) / sessionTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Gold"],
                'text2', abacus:FormatMoneyFull(sessionGoldOld, true),
                'text3', abacus:FormatMoneyFull(money, true),
                'text4', abacus:FormatMoneyFull((money - sessionGoldOld), true),
                'text5', abacus:FormatMoneyFull((((money - sessionGoldOld) / sessionTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Total"],
                'text2', abacus:FormatMoneyFull(sessionTotalOld, true),
                'text3', abacus:FormatMoneyFull(totalvalue, true),
                'text4', abacus:FormatMoneyFull((totalvalue - sessionTotalOld), true),
                'text5', abacus:FormatMoneyFull((((totalvalue - sessionTotalOld) / sessionTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Time"],
                'text2', self:PrettyDate(sessionTimeOld),
                'text3', self:PrettyDate(now),
                'text4', SecondsToTime(sessionTime)
        )
        
        -- -----------
        -- Zone totals
        -- -----------
        cat = supercat:AddCategory(
                'text', L["Mouseover_Zone"]
        )

        cat:AddLine(
                'text', L["Mouseover_Inventory"],
                'text2', abacus:FormatMoneyFull(zoneInvOld, true),
                'text3', abacus:FormatMoneyFull(invvalue, true),
                'text4', abacus:FormatMoneyFull((invvalue - zoneInvOld), true),
                'text5', abacus:FormatMoneyFull((((invvalue - zoneInvOld) / zoneTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Bags"],
                'text2', abacus:FormatMoneyFull(zoneBagOld, true),
                'text3', abacus:FormatMoneyFull(bagvalue, true),
                'text4', abacus:FormatMoneyFull((bagvalue - zoneBagOld), true),
                'text5', abacus:FormatMoneyFull((((bagvalue - zoneBagOld) / zoneTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Keys"],
                'text2', abacus:FormatMoneyFull(zoneKeyOld, true),
                'text3', abacus:FormatMoneyFull(keyvalue, true),
                'text4', abacus:FormatMoneyFull((keyvalue - zoneKeyOld), true),
                'text5', abacus:FormatMoneyFull((((keyvalue - zoneKeyOld) / zoneTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Repair"],
                'text2', abacus:FormatMoneyFull(zoneDurOld, true),
                'text3', abacus:FormatMoneyFull(durvalue, true),
                'text4', abacus:FormatMoneyFull((durvalue - zoneDurOld), true),
                'text5', abacus:FormatMoneyFull((((durvalue - zoneDurOld) / zoneTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Gold"],
                'text2', abacus:FormatMoneyFull(zoneGoldOld, true),
                'text3', abacus:FormatMoneyFull(money, true),
                'text4', abacus:FormatMoneyFull((money - zoneGoldOld), true),
                'text5', abacus:FormatMoneyFull((((money - zoneGoldOld) / zoneTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Total"],
                'text2', abacus:FormatMoneyFull(zoneTotalOld, true),
                'text3', abacus:FormatMoneyFull(totalvalue, true),
                'text4', abacus:FormatMoneyFull((totalvalue - zoneTotalOld), true),
                'text5', abacus:FormatMoneyFull((((totalvalue - zoneTotalOld) / zoneTime) * 3600), true)
        )
        cat:AddLine(
                'text', L["Mouseover_Time"],
                'text2', self:PrettyDate(sessionTimeOld),
                'text3', self:PrettyDate(now),
                'text4', SecondsToTime(zoneTime)
        )

        tablet:SetHint(L["Hint"])

        self:ScheduleRepeatingEvent("FarmFuTootltipUpdater", self.UpdateTooltip, 2, self)
end

function self:UpdateText() --this updates the FuBar button
        if self.db.profile == nil then
                return
        end
        if not self.hasIcon then
                self.hasIcon = true
                if self.db.profile.iconVisible then
                        self:ShowIcon()
                end
        end
        self.db.profile.iconVisible = false

        FarmFuFrameText:Show()
        
        if self.db.profile.showSession then
                total, hourlytotalprofit = self:HourlyMoney("session")
        else
                total, hourlytotalprofit = self:HourlyMoney("zone")
        end

        if self.db.profile.showTotalValue then
                self:SetText(abacus:FormatMoneyFull(total, true).."   "..abacus:FormatMoneyFull(hourlytotalprofit, true).."/h")
        else
                self:SetText(abacus:FormatMoneyFull(hourlytotalprofit, true).."/hour")
        end
        total, hourlyprofit = nil
        
        self:CheckWidth(true)
end

function self:HourlyMoney(depth) --Provides numbers for UpdateText
        local _, _, _, _, _, totalvalue = self:AppraiseEverything()
        -- error catching, sometimes this fires before ZoneMoney runs ResetSession
        if not totalvalue then totalvalue = 0 end
        if not zoneTimeOld then zoneTimeOld = 0 end
        if not zoneTotalOld then zoneTotalOld = 0 end
        if not sessionTimeOld then sessionTimeOld = 0 end
        if not sessionTotalOld then sessionTotalOld = 0 end
        -- -----------------
        if depth == "zone" then
                inzone = time() - zoneTimeOld
                hourlytotal = totalvalue - zoneTotalOld
        elseif depth == "session" then
                inzone = time() - sessionTimeOld
                hourlytotal = totalvalue - sessionTotalOld
        else
                inzone = 1
                hourlytotal = 0
        end
        
        local hourlytotalprofit = ((hourlytotal / inzone) * 3600)
        
        return hourlytotal, hourlytotalprofit
end

function self:SetFontSize(size) -- i dunno why I need this, But it cries when I delete it.
        self.fontSize = size
        self.iconFrame:SetWidth(size)
        self.iconFrame:SetHeight(size)
        self:UpdateText()
end

-- -----------------------------
-- --------Data Browser
function self:SetupFrames() --Rabbitbunny
        if self.frame then self.frame:Show() self:out("quitting") return end
        --Start with the frame and backdrop
        self:out("first checkpoint")
        self.frame = CreateFrame("Frame", "FarmFuBrowser", UIParent)
        self.frame:SetBackdrop({
                --bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
                edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 32,
                insets = {left = 11, right = 12, top = 12, bottom = 11}
        })
        self.frame.backdrop = self.frame:CreateTexture("$parentBG", "BACKGROUND")
        self.frame.backdrop:SetPoint("TOPLEFT", 6, -6)
        self.frame.backdrop:SetPoint("BOTTOMRIGHT", -6, 6)
        self.frame.backdrop:SetTexture(0,0,0,1)

        self.frame:SetWidth(632)
        self.frame:SetHeight(535)
        self.frame:SetPoint("CENTER")
        self.frame:SetFrameStrata("DIALOG")
        self.frame:EnableMouse(true)
        self.frame:SetMovable(true)
        
        self.frame:SetScript("OnMouseDown",function()
        if ( arg1 == "LeftButton" ) then
                        self.frame:StartMoving()
                end
    end)
    self.frame:SetScript("OnMouseUp",function()
        if ( arg1 == "LeftButton" ) then
                        self.frame:StopMovingOrSizing()
                end
    end)
        self.frame:SetScript("OnShow",function()
                self:UpdateFunction()
        end)
        
        --Initialize arrays
        self.frame.textures = {}
        self.frame.fontstrings = {}
        self.frame.catButtons = {}
        self.frame.achButtons = {}
        self.frame.tabButtons = {}
        self.frame.achSort = {}
        
        --Header
        local header = self.frame:CreateTexture("$parentHeader", "ARTWORK")
        header:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
        header:SetWidth(256)
        header:SetHeight(64)
        header:SetPoint("TOP")
        
        --Points Display Shield
        local shield = self.frame:CreateTexture("$parentPointShield", "ARTWORK")
        shield:SetTexture("Interface\\AchievementFrame\\UI-Achievement-TinyShield")
        shield:SetWidth(20)
        shield:SetHeight(20)
        shield:SetPoint("TOP", 76, -14)
        shield:SetTexCoord(0, 0.6, 0, 0.6)
        
        --Iterate through the textures
        --[[for _, t in next, frameElements.textures do
                local texture = self.frame:CreateTexture("$parent"..t.name, t.layer)
                texture:SetTexture(t.path)
                texture:SetWidth(t.width)
                texture:SetHeight(t.height)
                for _,p in next, t.points do
                        texture:SetPoint(p.point, self.frame, p.relativePoint, p.xOff, p.yOff)
                end
                if t.texCoord then
                        texture:SetTexCoord(t.texCoord.left, t.texCoord.right, t.texCoord.top, t.texCoord.bottom)
                end
                self.frame.textures[t.name] = texture
        end]]--
        
        --Header Text
        local headerText = self.frame:CreateFontString("$parentHeaderText", "ARTWORK", "GameFontNormal")
        headerText:SetText("Urban Achiever")
        headerText:SetPoint("CENTER", header, 0, 12)
        
        --Points Text
        self.pointsText = self.frame:CreateFontString("$parentPointText", "ARTWORK", "GameFontNormal")
        self.pointsText:SetText("12345")
        self.pointsText:SetPoint("LEFT", shield, "RIGHT", 0, 2)
        
        --Iterate through the fontstrings
        --[[
        for _, t in next, frameElements.fontstrings do
                local font = self.frame:CreateFontString("$parent"..t.name, t.layer, "GameFontNormal")
                font:SetText(t.text)
                for _,p in next, t.points do
                        font:SetPoint(p.point, p.anchor, p.relativePoint, p.xOff, p.yOff)
                end
                self.frame.fontstrings[t.name] = font
        end
        ]]--
        
        --Category Frame
        self.frame.category = CreateFrame("Frame", "$parentCategoryFrame", self.frame)
        self.frame.category:SetWidth(190)
        self.frame.category:SetHeight(470)
        self.frame.category:SetBackdrop({
                --bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
                edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", tile = true, tileSize = 32, edgeSize = 32,
                insets = {left = 11, right = 12, top = 12, bottom = 11}
        })
        self.frame.category.backdrop = self.frame.category:CreateTexture("$parentBG", "BACKGROUND")
        self.frame.category.backdrop:SetPoint("TOPLEFT", 6, -6)
        self.frame.category.backdrop:SetPoint("BOTTOMRIGHT", -6, 6)
        self.frame.category.backdrop:SetTexture(0,0,0,1)
        self.frame.category:SetPoint("RIGHT", self.frame, "LEFT", 12, 0)
        
        --Tab Buttons
        self.frame.tabButtons[1] = self:CreateTab("$parentTab1", self.frame, "Achievements", "achievements")
        self.frame.tabButtons[1]:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT", 20, 6)
        
        self.frame.tabButtons[2] = self:CreateTab("$parentTab1", self.frame, "Statistics", "statistics")
        self.frame.tabButtons[2]:SetPoint("TOPLEFT", self.frame.tabButtons[1], "TOPRIGHT", 5, 0)
        
        --self.frame.tabButtons[3] = self:CreateTab("$parentTab1", self.frame, "Search", "search")
        --self.frame.tabButtons[3]:SetPoint("TOPLEFT", self.frame.tabButtons[2], "TOPRIGHT", 5, 0)
        
        --Category Buttons
        self.frame.catButtons[1] = self:CreateCategoryButton("$parentCatButton1", self.frame.category)
        self.frame.catButtons[1]:SetPoint("TOPLEFT", self.frame.category, 12, -12)
        for i=2, 28 do
                self.frame.catButtons[i] = self:CreateCategoryButton("$parentCatButton"..i, self.frame.category)
                self.frame.catButtons[i]:SetPoint("TOPLEFT", self.frame.catButtons[i-1], "BOTTOMLEFT")
        end
        
        --Achievement Buttons
        self.frame.achButtons[1] = self:CreateAchievementButton("$parentAchButton1", self.frame)
        self.frame.achButtons[1]:SetPoint("TOPLEFT", 12, -90)
        for i=2, 27 do
                self.frame.achButtons[i] = self:CreateAchievementButton("$parentAchButton" .. i, self.frame)
                self.frame.achButtons[i]:SetPoint("TOPLEFT", self.frame.achButtons[i-1], "BOTTOMLEFT")
        end
        
        --Achievement Sort Buttons
        self.frame.achSort.name = self:CreateAchievementSortButton("$parentSortNameButton", 190, self.frame, "Name", "name")
        self.frame.achSort.name:SetPoint("BOTTOMLEFT", self.frame.achButtons[1], "TOPLEFT", 10, 1)
        
        self.frame.achSort.points = self:CreateAchievementSortButton("$parentSortPointsButton", 48, self.frame, "Points", "points")
        self.frame.achSort.points:SetPoint("LEFT", self.frame.achSort.name, "RIGHT", 1, 0)
        
        self.frame.achSort.completed = self:CreateAchievementSortButton("$parentSortCompletedButton", 50, self.frame, "Date", "completed")
        self.frame.achSort.completed:SetPoint("LEFT", self.frame.achSort.points, "RIGHT", 1, 0)
        
        --Close Button
        self.frame.close = CreateFrame("Button", "$parentCloseButton", self.frame, "UIPanelCloseButton")
        self.frame.close:SetPoint("TOPRIGHT", self.frame, "TOPRIGHT", -4, -5)
        
        --Category Toggle Button
        self.frame.catToggle = CreateFrame("Button", "$parentCategoryToggleButton", self.frame)
        self.frame.catToggle:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
        self.frame.catToggle:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down")
        self.frame.catToggle:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Round", "ADD")
        self.frame.catToggle:SetWidth(32)
        self.frame.catToggle:SetHeight(32)
        self.frame.catToggle:SetPoint("BOTTOMLEFT", self.frame.achButtons[1], "TOPLEFT", 5, 21)
        self.frame.catToggle:SetScript("OnClick", function()
                if self.frame.category:IsShown() then
                        self.frame.category:Hide()
                else
                        self.frame.category:Show()
                end
        end)
        
        --Search Editbox
        self.frame.editbox = self:CreateEditbox(self.frame)
        self.frame.editbox:SetWidth(200)
        self.frame.editbox:SetPoint("TOPLEFT", self.frame.catToggle, "TOPRIGHT", 10, 0)
        
        --Category Scroll Bar
        self.frame.catScroll = CreateFrame("Slider", "$parentCatSlider", self.frame, "UIPanelScrollBarTemplate")
        self.frame.catScroll:SetPoint("TOPLEFT", self.frame.catButtons[2], "TOPRIGHT")
        self.frame.catScroll:SetPoint("BOTTOMLEFT", self.frame.catButtons[#self.frame.catButtons - 1], "BOTTOMRIGHT")
        self.frame.catScroll:SetWidth(16)
        self.frame.catScroll:SetMinMaxValues(0,0)
        self.frame.catScroll:SetValueStep(1)
        self.frame.catScroll:SetScript("OnValueChanged", function()
                self:OnCatScroll()
        end)
        self.frame.catScroll:SetValue(1)
        
        --Achievement Button Scroll Bar
        self.frame.achScroll = CreateFrame("Slider", "$parentAchSlider", self.frame, "UIPanelScrollBarTemplate")
        self.frame.achScroll:SetPoint("TOPLEFT", self.frame.achButtons[2], "TOPRIGHT")
        self.frame.achScroll:SetPoint("BOTTOMLEFT", self.frame.achButtons[#self.frame.achButtons - 1], "BOTTOMRIGHT")
        self.frame.achScroll:SetWidth(16)
        self.frame.achScroll:SetMinMaxValues(0,0)
        self.frame.achScroll:SetValueStep(1)
        self.frame.achScroll:SetScript("OnValueChanged", function()
                self:OnAchScroll()
        end)
        self.frame.achScroll:SetValue(1)
        
        --Achievement Display Frame
        self.frame.display = CreateFrame("Frame", "$parentDisplayFrame", self.frame)
        self.frame.display.backdrop = self.frame.display:CreateTexture("$parentBG", "BACKGROUND")
        self.frame.display.backdrop:SetPoint("TOPLEFT")
        self.frame.display.backdrop:SetPoint("BOTTOMRIGHT")
        --self.frame.display.backdrop:SetTexture(1,0,0,1)
        
        
        self.frame.display:SetWidth(290)
        self.frame.display:SetHeight(448)
        self.frame.display:SetPoint("TOPLEFT", self.frame.achButtons[1], "TOPRIGHT", 19, 0)
        self.frame.display:Hide()
        
        --Display Icon
        self.frame.display.icon = CreateFrame("Button", "$parentIcon", self.frame.display)
        self.frame.display.icon:SetWidth(64)
        self.frame.display.icon:SetHeight(64)
        self.frame.display.icon:SetPoint("TOPLEFT")
        self.frame.display.icon:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Round", "ADD")
        self.frame.display.icon:SetScript("OnClick", function()
                self:InsertIntoChat(self.currentAch)
        end)
        
        --Display Name
        self.frame.display.name = self.frame.display:CreateFontString("$parentName", "ARTWORK", "AchievementPointsFont")
        self.frame.display.name:SetPoint("TOPLEFT", self.frame.display.icon, "TOPRIGHT", 5, 0)
        --self.frame.display.name:SetPoint("TOPRIGHT", -15,-15)
        self.frame.display.name:SetWidth(220)
        self.frame.display.name:SetHeight(70)
        self.frame.display.name:SetJustifyH("CENTER")
        self.frame.display.name:SetJustifyV("TOP")
        
        --Display Shield Icon
        self.frame.display.shield = self.frame.display:CreateTexture("$parentShield", "ARTWORK")
        self.frame.display.shield:SetPoint("TOPLEFT", self.frame.display.icon, "BOTTOMLEFT", 0, -5)
        self.frame.display.shield:SetTexture("Interface\\AchievementFrame\\UI-Achievement-Shields")
        self.frame.display.shield:SetTexCoord(0, .5, 0, 1);
        self.frame.display.shield:SetWidth(64)
        self.frame.display.shield:SetHeight(64)
        
        --Display Points
        self.frame.display.points = self.frame.display:CreateFontString("$parentPoints", "ARTWORK", "AchievementPointsFont")
        self.frame.display.points:SetPoint("CENTER", self.frame.display.shield, "CENTER", -2, 3)
        
        --Display Description
        self.frame.display.desc = self.frame.display:CreateFontString("$parentDescription", "ARTWORK", "GameFontNormal")
        self.frame.display.desc:SetPoint("TOPLEFT", self.frame.display.shield, "TOPRIGHT", 5, 0)
        --self.frame.display.desc:SetPoint("BOTTOMRIGHT", self.frame.display, "TOPRIGHT", -15,-109)
        self.frame.display.desc:SetWidth(220)
        self.frame.display.desc:SetHeight(65)
        
        --Display Reward
        self.frame.display.reward = self.frame.display:CreateFontString("$parentReward", "ARTWORK", "GameFontNormal")
        self.frame.display.reward:SetPoint("TOP", self.frame.display, "TOP", 0, -127)
        self.frame.display.reward:SetTextColor(1,1,1)
        
        self.frame.display.criteriaButtons = {}
        
        --Criteria Buttons
        self.frame.display.criteriaButtons[1] = self:CreateCriteriaButton("$parentCriteriaButton1", self.frame.display)
        self.frame.display.criteriaButtons[1]:SetPoint("TOPLEFT", 0, -145)
        for i=2, 18 do
                self.frame.display.criteriaButtons[i] = self:CreateCriteriaButton("$parentCriteriaButton" .. i, self.frame.display)
                self.frame.display.criteriaButtons[i]:SetPoint("TOPLEFT", self.frame.display.criteriaButtons[i-1], "BOTTOMLEFT")
        end
        
        --Display Scroll Bar
        self.frame.criteriaScroll = CreateFrame("Slider", "$parentSlider", self.frame.display, "UIPanelScrollBarTemplate")
        self.frame.criteriaScroll:SetPoint("TOPLEFT", self.frame.display.criteriaButtons[2], "TOPRIGHT")
        self.frame.criteriaScroll:SetPoint("BOTTOMLEFT", self.frame.display.criteriaButtons[#self.frame.display.criteriaButtons - 1], "BOTTOMRIGHT")
        self.frame.criteriaScroll:SetWidth(16)
        self.frame.criteriaScroll:SetMinMaxValues(0,0)
        self.frame.criteriaScroll:SetValueStep(1)
        self.frame.criteriaScroll:SetScript("OnValueChanged", function()
                self:OnCriteriaScroll()
        end)
        self.frame.criteriaScroll:SetValue(1)
        self.frame.criteriaScroll:Show()
        
        self.frame.display.criteria = self.frame.display:CreateFontString("$parentCriteria", "ARTWORK", "GameFontNormal")
        self.frame.display.criteria:SetPoint("TOPLEFT", 0, -135)
        self.frame.display.criteria:SetJustifyH("LEFT")
        self.frame.display.criteria:SetJustifyV("TOP")
        
        tinsert(UISpecialFrames,self.frame:GetName())
        self.frame:SetScript("OnShow", function()
                if self.masterList[self.currentAch] then
                        self.masterList[self.currentAch].searchString = self:GetSearchString(self.currentAch)
                end
                PlaySound("AchievementMenuOpen");
        end)
        self.frame:SetScript("OnHide", function()
                PlaySound("AchievementMenuClose");
        end)
        
        self:RefreshCategoryButtons()
        self:RefreshAchievementButtons()
        self:UpdateFunction()
        
        self.frame:Hide()
end

function self:CreateCategoryButton(name, parent) --Rabbitbunny
        local button = CreateFrame("Button", name, parent)
        button:EnableMouseWheel(true)
        button:SetWidth(150)
        button:SetHeight(16)
        
        button.text = button:CreateFontString("$parentText", "BORDER", "GameFontNormal")
        button.text:SetPoint("LEFT")
        
        --button:SetNormalTexture("Interface/FriendsFrame/UI-FriendsFrame-HighlightBar")
        button:SetHighlightTexture("Interface/FriendsFrame/UI-FriendsFrame-HighlightBar", "ADD")
        
        button:SetScript("OnClick", function()
                local id = button:GetID()
                self.currentCat = id
                for _,v in next, self.categories[self.currentTab] do
                        if v.id == id then
                                v.collapsed = not v.collapsed
                                break
                        end
                end
                self:RefreshCategoryButtons()
                self:RefreshAchievementButtons()
        end)
        button:SetScript("OnMouseWheel", function()
                self:ButtonScroll(arg1, "catScroll", "catOffset")
                --[[--arg1 = 1 for up, -1 for down
                local sMin, sMax = self.frame.catScroll:GetMinMaxValues()
                self.catOffset = math.min(sMax, math.max(sMin, self.catOffset + (arg1 * -1)))
                self.frame.catScroll:SetValue(self.catOffset)
                --self:RefreshCategoryButtons()]]--
                
        end)
        
        return button
end

function self:CreateAchievementButton(name, parent) --Rabbitbunny
        local button = CreateFrame("Button", name, parent)
        button:EnableMouseWheel(true)
        button:SetWidth(300)
                button:SetHeight(16)
        
        button.expand = button:CreateFontString("$parentExpand", "BORDER", "GameFontNormal")
        button.expand:SetText("+")
        button.expand:SetWidth(10)
        button.expand:SetHeight(10)
        button.expand:SetPoint("TOPLEFT")

        button.offset = CreateFrame("Frame", nil, button)
        button.offset:SetWidth(10)
        button.offset:SetHeight(1)
        button.offset:SetPoint("TOPLEFT", 9, 0)
        
        button.background = button:CreateTexture("$parentBackground", "BACKGROUND")
        button.background:SetTexture("Interface\\AchievementFrame\\UI-Achievement-Parchment-Horizontal")
        button.background:SetPoint("TOPLEFT", button.offset, "TOPRIGHT")
        button.background:SetPoint("BOTTOMRIGHT", button)
        --button.background:SetWidth(190)
        --button.background:SetHeight(30)
        
        button.name = button:CreateFontString("$parentNameText","BORDER", "GameFontNormal")
        button.name:SetPoint("TOPLEFT", button.background)
        --button.text:SetPoint("TOPRIGHT", button, "TOPRIGHT")
        button.name:SetWidth(200)
        button.name:SetHeight(16)
        button.name:SetJustifyH("LEFT")
        button.name:SetJustifyV("TOP")
        button.name:SetTextColor(1,1,1)
        
        button.points = button:CreateFontString("$parentPointsText","BORDER", "GameFontNormal")
        button.points:SetPoint("TOPLEFT", button, "TOPLEFT", 217, 0)
        --button.text:SetPoint("TOPRIGHT", button, "TOPRIGHT")
        button.points:SetWidth(20)
        button.points:SetJustifyH("LEFT")
        button.points:SetJustifyV("TOP")
        button.points:SetTextColor(1,1,1)
        
        button.completed = button:CreateFontString("$parentCompletedText","BORDER", "GameFontNormal")
        button.completed:SetPoint("TOPLEFT", button.points, "TOPRIGHT", 3, 0)
        --button.text:SetPoint("TOPRIGHT", button, "TOPRIGHT")
        button.completed:SetWidth(60)
        button.completed:SetJustifyH("LEFT")
        button.completed:SetJustifyV("TOP")
        button.completed:SetTextColor(1,1,1)
        
        
        button:SetHighlightTexture("Interface/FriendsFrame/UI-FriendsFrame-HighlightBar", "ADD")
        
        button:SetScript("OnClick", function()
                local id = button:GetID()
                if GetPreviousAchievement(id) and (not GetNextAchievement(id)) then
                        self.expandList[id] = not self.expandList[id]
                        self:RefreshAchievementButtons(false)
                end
                self:SetDisplayAchievement(id)
        end)
        button:SetScript("OnMouseWheel", function()
                self:ButtonScroll(arg1, "achScroll", "achOffset")
                --[[--arg1 = 1 for up, -1 for down
                local sMin, sMax = self.frame.achScroll:GetMinMaxValues()
                self.achOffset = math.min(sMax, math.max(sMin, self.achOffset + (arg1 * -1)))
                self.frame.achScroll:SetValue(self.achOffset)
                --self:RefreshAchievementButtons()
                ]]--
        end)
        
        return button
end

function self:UpdateFunction()
        if (not self.frame) or (not self.frame:IsShown()) then return end
        self:RefreshCategoryButtons()
        self:RefreshAchievementButtons()
        self.pointsText:SetText(GetTotalAchievementPoints())
end
        
-- -----------------------------
-- --------Event Hooks
function self:PLAYER_LOGOUT() -- Save partial zones, Not sure if it works
        self:ZoneMoney("PLAYER_LOGOUT")
end

function self:ZONE_CHANGED()
        self:ZoneMoney("ZONE_CHANGED")
end

function self:ZONE_CHANGED_NEW_AREA()
        self:ZoneMoney("ZONE_CHANGED_NEW_AREA")
end

function self:ZONE_CHANGED_INDOORS()
        self:ZoneMoney("ZONE_CHANGED_INDOORS")
end

function self:CHAT_MSG_ADDON()
        self:GetData()
end

-- -----------------------------
-- ------------Resets
function self:setDefaults()
        self.db.profile.minInZone = 60
        self.db.profile.showDebug = false
        self.db.profile.showTotalValue = true
        self.db.profile.showSession = true
        self.db.profile.instances = true
        self.db.profile.ignoremules = false
end

function self:ResetSession()
        if self.db.profile.showDebug then
                self:out(L["Name"]..": "..L["Session_Reset"])
        end
        sessionBagsOld = self:AppraiseBags()
        sessionKeysOld = self:AppraiseKeyring()
        sessionDurOld = self:AppraiseDurability()
        sessionInvOld = self:AppraiseInventory()
        sessionGoldOld = GetMoney()
        sessionTotalOld = (sessionBagsOld + sessionKeysOld + sessionDurOld + sessionInvOld + sessionGoldOld)
        sessionTimeOld = time()
end

function self:ResetZone(area, entered, money, keyvalue, invvalue, bagvalue, durvalue, totalvalue)
        zoneTotalOld = totalvalue
        zoneInvOld = invvalue
        zoneBagOld = bagvalue
        zoneDurOld = durvalue
        zoneKeyOld = keyvalue
        zoneTimeOld = entered
        zoneGoldOld = money
        zoneAreaOld = area
end

function self:resetZones() --deletes entire DB
        self.db.realm = {}
end

-- ----------------------------
-- ------------Appraisers
function self:AppraiseEverything() --local money, bagvalue, invvalue, keyvalue, durvalue, totalvalue = self:AppraiseEverything()
        local money = GetMoney()
        local bagvalue = self:AppraiseBags()
        local invvalue = self:AppraiseInventory()
        local keyvalue = self:AppraiseKeyring()
        local durvalue = self:AppraiseDurability()
        local totalvalue = money + bagvalue + invvalue + keyvalue + durvalue

        return money, bagvalue, invvalue, keyvalue, durvalue, totalvalue
end

function self:AppraiseDurability()
        local value = 0
        
        --if self.db.profile.showDebug then
                --self:out("Appraising Durability.........")
        --end
        
        local t = {
                ["1"] = "Head",
                ["2"] = "Unknown",
                ["3"] = "Shoulder",
                ["4"] = "Unknown",
                ["5"] = "Chest",
                ["6"] = "Waist",
                ["7"] = "Legs",
                ["8"] = "Feet",
                ["9"] = "Wrist",
                ["10"] = "Hand",
                ["11"] = "Unknown",
                ["12"] = "Unknown",
                ["13"] = "Unknown",
                ["14"] = "Unknown",
                ["15"] = "Unknown",
                ["16"] = "Mainhand",
                ["17"] = "Offhand",
                ["18"] = "Ranged",
                ["19"] = "Unknown"
        }
                        --[[ ["Ammo"] = "AmmoSlot", ]]--
        
    for slot = 1,19 do
                local key = t[tostring(slot)]
                if key ~= "Unknown" then
                        if DurabilityTooltip then
                                local _,_,cost = DurabilityTooltip:SetInventoryItem("player", slot)
                                --if self.db.profile.showDebug then
                                                --self:out(">> "..slot..":"..key.." "..cost)
                                --end
                                value = value + cost
                        end
                end
    end
        
        value = math.floor((0 - value)+.5)

        --if self.db.profile.showDebug then
        --      self:out("Durability is worth........."..value)
        --end
        
        return value
end

function self:AppraiseKeyring()
        local value = 0
        
        --if self.db.profile.showDebug then
                --self:out("Appraising Keyring.........")
        --end

        if HasKey() then
                local bagname = GetBagName(KEYRING_CONTAINER)
                local slots = GetContainerNumSlots(KEYRING_CONTAINER)
                for b = 1, slots do
                        local item = GetContainerItemLink(KEYRING_CONTAINER, b)
                        local _,itemCount = GetContainerItemInfo(KEYRING_CONTAINER, b)
                        if item ~= nil then
                                appraisal = self:GetPriceData(item) * itemCount
                                --if self.db.profile.showDebug then
                                        --self:out(">> slot "..b.." "..item.."x"..itemCount.." "..appraisal)
                                --end
                                value = value + appraisal
                        else
                                --if self.db.profile.showDebug then
                                        --self:out(">> slot "..b.." Empty")
                                --end
                        end
                end
        end

        --if self.db.profile.showDebug then
                --self:out("Keyring is worth........."..value)
        --end
        
        return value
end

function self:AppraiseBags()
        local value = 0
        --if self.db.profile.showDebug then
                --self:out("Appraising Bags.........")
        --end

        for a = 0, 4 do
                local bagvalue = 0
                local bagname = GetBagName(a)
                local slots = GetContainerNumSlots(a)
                --if self.db.profile.showDebug then
                        --self:out(">> "..bagname.."("..a.."): "..slots.." slots")
                --end
                for b = 1, slots do
                        local item = GetContainerItemLink(a, b)
                        local _,itemCount = GetContainerItemInfo(a, b)
                        if item ~= nil then
                                local appraisal = self:GetPriceData(item) * itemCount
                                local repair = 0
                                if DurabilityTooltip then
                                        _,repair = DurabilityTooltip:SetBagItem(a, b)
                                        --self:out("havetooltip")
                                end
                                if repair ~= nil and repair ~= 0 then
                                        appraisal = appraisal - repair
                                        --self:out(">> >> slot "..b.." "..item.."x"..itemCount.." "..appraisal.." Repair: "..tostring(repair))
                                end
                                bagvalue = bagvalue + appraisal
                        else
                                --if self.db.profile.showDebug then
                                        --self:out(">> >> slot "..b.." Empty")
                                --end
                        end
                end
                value = value + bagvalue
                --if self.db.profile.showDebug then
                --      self:out(">> "..bagname.."("..a.."): "..slots.." slots "..bagvalue)
                --end
        end
        --if self.db.profile.showDebug then
                --self:out("Bags are worth........."..value)
        --end
        
        return value
end
        
function self:AppraiseInventory()
        local money = 0
        --if self.db.profile.showDebug then
                --self:out("Appraising Inventory.........")
        --end

        local t = {
                ["HeadSlot"] = "HeadSlot",
                ["NeckSlot"] = "NeckSlot",
                ["ShoulderSlot"] = "ShoulderSlot",
                ["BackSlot"] = "BackSlot",
                ["ChestSlot"] = "ChestSlot",
                ["ShirtSlot"] = "ShirtSlot",
                ["TabardSlot"] = "TabardSlot",
                ["WristSlot"] = "WristSlot",
                ["HandsSlot"] = "HandSlot",
                ["WaistSlot"] = "WaistSlot",
                ["LegsSlot"] = "LegSlot",
                ["FeetSlot"] = "FeetSlot",
                ["Finger0Slot"] = "Finger0Slot",
                ["Finger1Slot"] = "Finger1Slot",
                ["Trinket0Slot"] = "Trinket0Slot",
                ["Trinket1Slot"] = "Trinket1Slot",
                ["MainHandSlot"] = "MainHandSlot",
                ["SecondaryHandSlot"] = "SecondaryHandSlot",
                ["RangedSlot"] = "RangedSlot",
                ["Bag0Slot"] = "Bag0Slot",
                ["Bag1Slot"] = "Bag1Slot",
                ["Bag2Slot"] = "Bag2Slot",
                ["Bag3Slot"] = "Bag3Slot"
        }
                        --[[ ["Ammo"] = "AmmoSlot", ]]--
        
        for key, value in pairs(t) do
                local SlotLink = GetInventoryItemLink("player",GetInventorySlotInfo(key))
                local SlotAppraisal = self:GetPriceData(SlotLink)
                money = money + SlotAppraisal
                --if self.db.profile.showDebug then
                        --self:out(value..":  "..SlotLink.." "..SlotAppraisal)
                --end
        end
                
        --if self.db.profile.showDebug then
                --self:out("Inventory is worth........."..money)
        --end
        
        return money
end

function self:GetPriceData(link) --Tested with AucAdvanced r3164
        --sell, buy, buyout
        if not link then
                return 0
        end
        if AucAdvanced and Informant then
                local itemid = tonumber(link:match("item:(%d+)"))
                local midpoint, seen = AucAdvanced.Modules.Util.Appraiser.GetPrice(link)

                local avgBuy = 0
                if (midpoint) then
                        avgBuy = math.floor(midpoint+.5)
                end
                --DEFAULT_CHAT_FRAME:AddMessage(itemid.." "..avgBuy.." -> "..(math.floor(midpoint+.5) or "nil").." "..tellme);
                
                local venddata = Informant.GetItem(itemid)
                if venddata then
                        if avgBuy == 0 then
                                if venddata.sell == nil then
                                        return 0
                                else
                                        return venddata.sell
                                end
                        else
                                return avgBuy
                        end
                else
                        return avgBuy
                end
        else
                return 0
        end
end

-- ----------------------------
function self:ZoneMoney(event) -- calculate previous zone data nad returns variables to 0 for next zone
        local realzone = GetRealZoneText()
        local subzone = GetSubZoneText()
        local zone = GetZoneText()
        local dontsave = false
        local dontsavereason = ""
        area = "Unknown"
        
        if realzone == zone then
                if "" == subzone then
                        area = realzone
                else
                        area = realzone.." - "..subzone
                end
        else
                if "" == subzone then
                        area = realzone.." - "..zone
                elseif "" == zone then
                        area = realzone.." - "..subzone
                else
                        if  realzone == subzone then
                                area = realzone.." - "..zone
                        else
                                area = realzone.." - "..zone.." - "..subzone
                        end
                end
        end
        
        if zoneAreaOld == "The Real World" then --this seems to be the best place to set session defaults
                self:ResetSession()
                dontsave = true
                dontsavereason = dontsavereason.." and you just logged in "
        end
        
        local inInstance, instanceType = IsInInstance()
        if self.db.profile.instances and inInstance == 1 then --This section is to make sure we count instances together, Deadmines is one place, Give it one output.
                -- Personally checked Deadmines, Blackfathom Deeps, Shadowfang Keep
                -- if you're reading this, go ahead and tell me some more of these sort of areas, I can't even think of the name of every instance and with only a 54 human it's going to take me a while to visit them all
                local instancezones = {
                        ["Deadmines"] = {
                                ["Goblin Foundry"] = true,
                                ["Mast Room"] = true,
                                ["Ironclad Cove"] = true
                        },
                        ["Blackfathom Deeps"] = {
                                ["The Drowned Sacellum"] = true,
                                ["The Pool of Ask`ar"] = true,
                                ["Moonshrine Ruins"] = true,
                                ["The Forgotten Pool"] = true,
                                ["Moonshrine Sanctum"] = true,
                                ["Aku`mai`s Lair"] = true
                        }
                }
                
                local localdontsave = false
                for instancezone,instancezonearea in pairs(instancezones) do
                        for innerzone,_ in pairs(instancezonearea) do
                                if (subzone == innerzone) or (zone == innerzone) then
                                        localdontsave = true
                                        localinstancezone = instancezone
                                end
                        end
                end
                if localdontsave then
                        dontsave = true
                        dontsavereason = dontsavereason.." and you're still in "..localinstancezone.." "
                end
                localdontsave = nil
                localinstancezone = nil
        end
        -------------------
        
        -- When suppressing zone changes you have to suppress coming out of them too.
        if area == zoneAreaOld then
                dontsave = true
                dontsavereason = dontsavereason.." and you're in the same zone "
        end
        -------------------
        local money, bagvalue, invvalue, keyvalue, durvalue, totalvalue = self:AppraiseEverything()

        local entered = time()
        local inzone = entered - zoneTimeOld
        
        local bagprofit = bagvalue - zoneBagOld
        local hourlybagprofit = ((bagprofit / inzone) * 3600)
        
        local durprofit = durvalue - zoneDurOld
        local hourlydurprofit = ((durprofit / inzone) * 3600)
        
        local keyprofit = keyvalue - zoneKeyOld
        local hourlykeyprofit = ((keyprofit / inzone) * 3600)
        
        local invprofit = invvalue - zoneInvOld
        local hourlyinvprofit = ((invprofit / inzone) * 3600)
        
        local profit = money - zoneGoldOld
        local hourlyprofit = ((profit / inzone) * 3600)
        
        local total = totalvalue - zoneTotalOld
        local hourlytotalprofit = ((total / inzone) * 3600)
        
    --self:PrettyMoney(copper),
        
        -- Show our debug info
        if self.db.profile.showDebug then
                --self:out(event);
                self:out("----------------------------------------------------------------------------------")
                self:out("Now Entering: "..area)
                self:out("Just left: "..zoneAreaOld)
                self:out("Entered at: "..date("%c", entered).."  Left at: "..date("%c", zoneTimeOld))
                self:out("Time in zone: "..SecondsToTime(inzone))
                --
                self:out("Gold         Starting: "..zoneGoldOld.."  Ending: "..money.."  Profit: "..profit)
                self:out("Bag          Starting: "..zoneBagOld.."  Ending: "..bagvalue.."  Profit: "..bagprofit)
                self:out("Repair       Starting: "..zoneDurOld.."  Ending: "..durvalue.."  Profit: "..durprofit)
                self:out("Key          Starting: "..zoneKeyOld.."  Ending: "..keyvalue.."  Profit: "..keyprofit)
                self:out("Inventory    Starting: "..zoneInvOld.."  Ending: "..invvalue.."  Profit: "..invprofit)
                self:out("Total        Starting: "..zoneTotalOld.."  Ending: "..totalvalue.."  Profit: "..total)
                self:out("Hourly Profit:  "..hourlytotalprofit)
                self:out("----------------------------------------------------------------------------------")
        end
        -- ----------------------
        
        -- More times we don't want to save
        if UnitOnTaxi("player") then
                dontsave = true
                dontsavereason = dontsavereason.." and you're flying "
        end
        
        if UnitIsDeadOrGhost("player") then
                dontsave = true
                dontsavereason = dontsavereason.." and you're dead "
        end

        if inzone <= self.db.profile.minInZone then
                dontsave = true
                dontsavereason = dontsavereason.." and not in zone long enough ("..inzone..") "
        end
        
        if total == 0 then
                dontsave = true
                dontsavereason = dontsavereason.." and no change"
        end
        if self.db.profile.ignoremules and UnitLevel("player") == 1 then
                dontsave = true
                dontsavereason = dontsavereason.." and you're a mule "
        end
        -- -------------
        
        if dontsave then
                if zoneAreaOld == "The Real World" then
                        self:ResetZone(area, entered, money, keyvalue, invvalue, bagvalue, durvalue, totalvalue)
                end
                if strsub(dontsavereason, 0, 4) == " and" then
                        dontsavereason = strsub(dontsavereason, 5)
                end
                if self.db.profile.showDebug then
                        self:out("Not Saving Data ("..dontsavereason.." )")
                end
        else
                self:SaveZoneData(profit, bagprofit, durprofit, invprofit, total, inzone, entered)
                self:ResetZone(area, entered, money, keyvalue, invvalue, bagvalue, durvalue, totalvalue)
        end
end

function self:SaveZoneData(profit, bagprofit, durprofit, invprofit, total, inzone, entered)
        if self.db.profile.showDebug then
                self:out("Saving Zone Data")
        end
        
        --inInstance, instanceType = IsInInstance()
        --difficulty = GetInstanceDifficulty() --      1 normal     2 heroic     3 epic
        --_,effectiveArmor,_,_,_ = UnitArmor("player");
        --hasMainHandEnchant, _, _, hasOffHandEnchant, _, _ = GetWeaponEnchantInfo() --will return if weps are enchanted, not names, only for things like sharpening stones.
        -- This is everything we're going to save, I can't think of anything else that would be useful.
        newdata = {
                ["inparty"] = GetNumPartyMembers(),
                ["name"] = UnitName("player"),
                ["level"] = UnitLevel("player"),
                ["class"] = UnitClass("player"),
                ["armor"] = effectiveArmor,
                ["health"] = UnitHealthMax("player"),
                ["mana"] = UnitManaMax("player"),
                ["powertype"] = UnitPowerType("player"),
                ["race"] = UnitRace("player"),
                ["rangecrit"] = GetRangedCritChance(),
                ["crit"] = GetCritChance(),
                ["dodge"] = GetDodgeChance(),
                ["parry"] = GetParryChance(),
                ["block"] = GetBlockChance(),
                ["bagprofit"] = bagprofit,
                ["repair"] = durprofit,
                ["profit"] = profit,
                ["invprofit"] = invprofit;
                ["total"] = total,
                ["inzone"] = inzone
        }

        if self.db.realm ~= nil then
                if self.db.realm[tostring(zoneAreaOld)] ~= nil then
                        self.db.realm[tostring(zoneAreaOld)][tostring(entered)] = newdata
                else
                        self.db.realm[tostring(zoneAreaOld)] = {
                                [tostring(entered)] = newdata
                        }
                end
        else
                self.db.realm = {
                        [tostring(zoneAreaOld)] = {
                                [tostring(entered)] = newdata
                        }
                }
        end
end

function self:SaveSession()

end

-- ------------Workhorses
function self:PrettyDate(timestamp) -- WoW doesn't allow the time format I want, This makes it.
        local prettydate = strlower(date("%I:%M%p", timestamp)) --08:32am

        if strsub(prettydate, 0, 1) == "0" then --8:32am
                prettydate = strsub(prettydate, 2)
        end

        return prettydate
end

function self:out(chat, errorframe) --this is my lovely output function, DEFAULT_CHAT_FRAME wastes file space.
        if errorframe ~= nil then
                UIErrorsFrame:AddMessage(errorframe, 1.0, 1.0, 0, 1, 10)
        end
        if chat ~= nil then
                DEFAULT_CHAT_FRAME:AddMessage(chat)
        end
end

function self:showZonesToChat() --this is never called, I'm just using it to view the table.
    DEFAULT_CHAT_FRAME:AddMessage("self.db.realm = {");
    for level1, zone in pairs(self.db.realm) do
                if level1 ~= "The Real World" and level1 ~= "currentProfile" and level1 ~= "profiles" then
                        if type(zone) == "table" then
                                DEFAULT_CHAT_FRAME:AddMessage(">['"..level1.."'] = {");
                                for level2, day in pairs(zone) do
                                        if type(day) == "table" then
                                                DEFAULT_CHAT_FRAME:AddMessage(">>['"..level2.."'] = { "..day["level"].." "..day["race"].." "..day["class"]..", "..abacus:FormatMoneyFull(day["total"], true)..",  "..SecondsToTime(day["inzone"])..", "..abacus:FormatMoneyFull(((day["total"] / day["inzone"]) * 3600), true).."/h }");
                                        elseif type(day) == "string" then
                                                DEFAULT_CHAT_FRAME:AddMessage(">>['"..level2.."'] = '"..day.."'");  
                                        end
                                end
                                DEFAULT_CHAT_FRAME:AddMessage(">}"); 
                        elseif type(zone) == "string" then
                                DEFAULT_CHAT_FRAME:AddMessage(">['"..level1.."'] = '"..zone.."'");  
                        end
                end
    end
    DEFAULT_CHAT_FRAME:AddMessage("}");
end

function self:SetFontSize(size) -- i dunno why I need this, But it cries when I delete it.

        self.fontSize = size

        self.iconFrame:SetWidth(size)
        self.iconFrame:SetHeight(size)

        self:UpdateText()
end

function self:SendData()
        local data = "Example"
        local loops = GetNumFriends()
        for a = 1,loops do
                name,level,class,_,connected,_,_,_ = GetFriendInfo(a);
                if not connected then
                        --self:out("Offline: "..name);
                else
                        --self:out(name.." "..level.." "..class.." -> "..data);
                        --SendAddonMessage(self, data, "WHISPER", name)
                end
        end
end

function self:GetData()
        --self:out(arg1.." , "..arg2.." , "..arg3.." , "..arg4)
        if arg1 == self then
                if arg3 == "WHISPER" then
                        --self:out(arg4.." sent: "..arg2)
                end
        end
end

Compare with Previous | Blame