WoWInterface SVN PersonalTrainer

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

Compare with Previous | Blame | View Log

-- UI Mod Declaration
PT = LibStub("AceAddon-3.0"):NewAddon("PersonalTrainer", "AceConsole-3.0", "AceEvent-3.0");

-- Ace Components
local AceDB = LibStub("AceDB-3.0");
local AceConfig = LibStub("AceConfigDialog-3.0");

-- Core Functions
function PT:OnInitialize()
        -- Generics
        PT.Version = GetAddOnMetadata("PersonalTrainer", "Version");

        PT.db = AceDB:New("PT_Vars");
        PT.db:RegisterDefaults({
                global = {
                        debug = false;
                },
                class = {
                        Skills = {}
                }
        });
        
        PT.IsScanning = false
        PT.OldFilter = { Avail = 0, Unavail = 0, Used = 0 }
        
        self:RegisterEvent("TRAINER_SHOW");
        self:RegisterEvent("TRAINER_UPDATE");
end

function PT:OnEnable()
        self:Print("Loaded [ "..PT.Version.." ]");
end

function PT:OnDisable()
        
end

-- Skill Parsing & Storing
function PT:TRAINER_SHOW()
        if (not IsTradeskillTrainer()) then
                self:Print("DEBUG: Trainer was a skill trainer.");
                PT:ScanSkillTrees();
        else
                self:Print("DEBUG: Trainer was a tradeskill trainer.");
        end
end

function PT:TRAINER_UPDATE()
        --PT:UpdateSkillTrees();
end

function PT:ScanSkillTrees()
        -- Save Old Filter Settings
        local set = {}
        
        -- Turn All On
        SetTrainerServiceTypeFilter("available", 1);
        SetTrainerServiceTypeFilter("unavailable", 1);
        SetTrainerServiceTypeFilter("used", 1);

        -- Expand All Categories
        for i = 1,GetNumTrainerServices() do
                _,_, category = GetTrainerServiceInfo(i);
                
                if (category == nil) then
                        break;
                end
                
                if (category == "header") then
                        ExpandTrainerSkillLine(i);
                end
        end
        
        -- Scan
        PT.db.class.Skills = {}
        for i = 1,GetNumTrainerServices() do
                local Service = PT:GetServiceInfo(i);
                
                if (Service.Name == nil) then
                        break;
                end
                
                local Entry = {}
                Entry.ID = Service.SpellID;
                Entry.Cost = Service.Cost;
                Entry.Level = Service.Level;
                Entry.Icon = Service.Icon;
                
                table.insert(PT.db.class.Skills, Entry);
        end
        
        -- Sort By Level
        table.sort(PT.db.class.Skills, PT_SortSkillsByLevel);
        
        -- Reset Filter Options
        SetTrainerServiceTypeFilter("available", 1);
        SetTrainerServiceTypeFilter("unavailable", 1);
        SetTrainerServiceTypeFilter("used", 0);
end

function PT_SortSkillsByLevel(a,b)
        if (a.Level ~= nil and b.Level ~= nil) then
                return a.Level<b.Level;
        else
                return a==b;
        end
end

function PT:UpdateSkillTrees()
        --[[local numServices = GetNumTrainerServices();
        
        for i = 1,numServices do
                local Service = PT:GetServiceInfo(i);
                
                if (Service.Name == nil) then
                        break;
                end
                
                self:Print(Service.LongName..", "..Service.Category..", "..Service.Expanded..", "..Service.Link);
        end]]
        
        for i = 1,GetNumSkillLines() do
                
        end
end     

function PT:GetServiceInfo(index)
        local Service = {}
        
        local nm, rnk, cat, ex = GetTrainerServiceInfo(index);
        
        if (rnk ~= "") then
                Service.LongName = nm.." ("..rnk..")"
        else
                Service.LongName = nm;
        end
        
        -- Trainer Info
        Service.Name = nm;
        Service.Rank = rnk;
        Service.Category = cat
        Service.Expanded = ex
        
        -- Cost
        local cst, tcst, _ = GetTrainerServiceCost(index);
        Service.Cost = cst;
        Service.CostText = ""..cst..""; --TODO: Update
        
        -- Level
        Service.Level = GetTrainerServiceLevelReq(index);
        
        -- Spell Info
        local lnk = GetSpellLink(Service.Name, Service.Rank);
        Service.Link = lnk
        if(lnk ~= nil) then
                Service.SpellID = lnk:match("spell:(%d+)");
                local _,_,ico = GetSpellInfo(Service.SpellID);
                Service.Icon = ico
        else
                Service.Icon = GetSpellTexture(Service.Name);
        end

        return Service;
end

Compare with Previous | Blame