lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

[/] [branches/] [3.0.0/] [KragenPlugs/] [KragenBars/] [ClassBar.lua] - Rev 40

Go to most recent revision | Compare with Previous | Blame | View Log

import "Turbine.UI";
import "Turbine.UI.Lotro";
import "Turbine.Gameplay";
import "KragenPlugs.Utils";
import "KragenPlugs.KragenBars";

ClassBar = class( );

function ClassBar:Constructor()
        
        -- inialize the setupWindow
        self.setup = SetupWindow();
        self.setupbb = self.setup.setupbb;
        self.setupf = self.setup.setupf;
        self.setupqs = self.setup.setupqs;
        
        -- inialize tables
        self.windows = { };
        self.bars = { };
        self.skills = { };
        self.multi = { };
        
        self.setup:SetWantsKeyEvents(true);
        
        self.setup.KeyDown = function(sender, args)
        if args.Action == 0x100000B3 then
                        self.setup:SetWantsUpdates(true);
                end
        end
        
        self.setup.Update = function(sender, args)
        for k,v in pairs(self.skills) do
                        v:RefreshBorders();
                end
                self.setup:SetWantsUpdates(false);
        end
        
        -- Combat Event
        AddCallback(vars.player, "InCombatChanged", function(sender, args)
                KragenBars:CombatChange(vars.player:IsInCombat());
        end);
        
        -- Effect Events
    AddCallback(vars.effects, "EffectAdded", function(sender, args)
                KragenBars:AddEffect( args.Index );
        end);

        AddCallback(vars.effects, "EffectRemoved", function(sender, args)
                if (args.Effect ~= nil) then
                        KragenBars:RemoveEffect( args.Effect );
                end
        end);
        
end

-- Index and Position Bars
function ClassBar:InitBars()
        for k,v in pairs(self.bars) do
                v.index = k;
        end
        
        if(settings.skilldata ~=nil) then
                for k,v in pairs(self.skills) do
                        if (settings.skilldata[k] ~= nil) then
                            local data = settings.skilldata[k];
                            data.parent = self.bars[settings.skilldata[k].parent]
                                v:LoadPosition(data);
                        end
                end
        end
        
        if(settings.multidata ~=nil) then
                for k,v in pairs(self.multi) do
                        if (settings.multidata[k] ~= nil) then
                                local data = settings.multidata[k];
                            data.parent = self.bars[settings.multidata[k].parent]
                                v:LoadPosition(data);
                        end
                end
        end
        
        for k,v in pairs(self.windows) do
                v:SetVisible(v.active);
        end
        
        for k,v in pairs(self.skills) do
                v:RefreshBorders();
        end
        
        for i = 1, vars.effects:GetCount() do
                self:AddEffect(i);
        end
end

-- Swap Slots
function ClassBar:SwapSlots(ref, code)
        
        local swap = nil;
        local swaptype = 1;
        if (not settings.lockslots) then
                for k,v in pairs(self.skills) do
                        if (v.quickslot:GetShortcut():GetData() == code ) then
                            if ((ref:GetParent() == v:GetParent() or (not ref:GetParent().exclusive and not v:GetParent().exclusive)) and (ref:GetParent() == ref.parent and v:GetParent() == v.parent)) then
                                        swap = v;
                                        swaptype = 1;
                                end
                        end
                end
                for k,v in pairs(self.multi) do
                        if (v.quickslot:GetShortcut():GetData() == code ) then
                                if ((ref:GetParent() == v:GetParent() or (not ref:GetParent().exclusive and not v:GetParent().exclusive)) and (ref:GetParent() == ref.parent and v:GetParent() == v.parent)) then
                                        swap = v;
                                        swaptype = 2;
                                end
                        end
                end
        end
        if (swap ~= nil) then
            if (swaptype == 1) then
                        ref:SwapPosition(swap);
                else
                        swap:SwapPosition(ref);
                end
        end
        ref:ResetQuickslot();
end

-- Rotate Window
function ClassBar:RotateWindow(ref)
        local rotatebar = { };
        local counter=1
        for k,v in pairs(self.bars) do
                if(v:GetParent() == ref) then
                        v:RotateBar();
                        rotatebar[counter] = v;
                        counter = counter + 1;
                end
        end
        
        for k,v in pairs(self.skills) do
                for i=1, counter do
                        if(v:GetParent() == rotatebar[i]) then
                                v:RotateBar();
                        end
                end
        end
        
        for k,v in pairs(self.multi) do
                for i=1, counter do
                        if(v:GetParent() == rotatebar[i]) then
                                v:RotateBar();
                        end
                end
        end
end

-- Save Settings
function ClassBar:SaveSettings()
        for k,v in pairs(self.windows) do
            self.settings[k].x, self.settings[k].y = self.windows[k]:GetPosition();
                self.settings[k].rotate = self.windows[k].rotate;
        end
    
    local skilldata = { };
    for k,v in pairs(self.skills) do
                skilldata[k] = { pos = {v.x, v.y}, parent = v.parent.index };
        end
        
        local multidata = { };
        for k,v in pairs(self.multi) do
                multidata[k] = { current = v.currentshortcut, layer = v.currentlayer, lock = v.lock, pos = { v.x, v.y }, parent = v.parent.index };
        end
        
        for k,v in pairs(self.windows) do
                v:SetVisible(v.active);
        end

        Turbine.Shell.WriteLine("KragenBars: " .. settings.class .. " Bars settings saved successfully.");

        settings.multidata = multidata;
        settings.skilldata = skilldata;
        settings.classinfo = self.settings;
        SaveSettings();
end

-- Refresh Player Level and Window and Skill States
function ClassBar:RefreshBars()
        -- Refresh Player Level
        vars.playerlevel = vars.player:GetLevel();
        
        -- Refresh Windows
        for k,v in pairs(self.windows) do
        self.windows[k]:Refresh(self.settings[k].active);
        end
        
        -- Refresh Skills
        for k,v in pairs(self.skills) do
                self.skills[k]:Refresh();
        end
end

function ClassBar:DefaultPosition()
    -- Refresh Windows
        for k,v in pairs(self.windows) do
        self.windows[k]:DefaultPosition();
        end
end

function ClassBar:RecalculateBorders()
        -- Refresh Skills
        for k,v in pairs(self.skills) do
                v.border:SetPosition(v:PointToScreen(1, 1));
        end
end

function ClassBar:CombatChange(combat)
        for k,v in pairs(self.skills) do
                self.skills[k]:RefreshCombat();
        end
        
        for k,v in pairs(self.multi) do
                self.multi[k]:RefreshCombat();
        end
end

Go to most recent revision | Compare with Previous | Blame


All times are GMT -5. The time now is 01:01 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui