lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

[/] [branches/] [3.12/] [KragenBars/] [SkillMultiSlot.lua] - Rev 40

Compare with Previous | Blame | View Log

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

SkillMultiSlot = class ( KragenPlugs.Utils.Extensions.SimpleWindow );

function SkillMultiSlot:Constructor ( parent, x, y, active )
        KragenPlugs.Utils.Extensions.SimpleWindow.Constructor( self );

        -- declare variables
        self.parent = parent;
        self.x = x;
        self.y = y;
        self.active = active;
    self.hover = false;
        self.lock = false;
        self.effectid = 0;
        self.state = false;
        self.incombat   = true;
        self.outcombat  = true;

        -- SHORTCUTS
        self.shortcuts = { };
        self.shortcuts[1] = { };
        self.totalshortcuts = { };
        self.totalshortcuts[1] = 0;
        self.currentshortcut = { };
        self.currentshortcut[1] = 1;
        self.currentlayer = 1;
        self.totallayers = 1;

        -- QUICKSLOT
        self.quickslot = Turbine.UI.Lotro.Quickslot();
        self.quickslot:SetParent(self);
        self.quickslot:SetSize(35,35);
        self.quickslot:SetVisible(true);
        
        -- TIMER
        self.timer = Timer();
        self.timerOn = true;
        self.timerEnd = true;

        -- TIMER EVENT
        self.timer.TimerElapsed = function ()
        if (self.timerEnd) then
                        self:SetHover( true );
                        self:SetActive( true );
                else
                    self:SetActive( false );
                end
        end

        -- set properties
        self:SetParent( parent );
        self:SetPosition( (x - 1) * 35, (y - 1) * 35 );
        self:SetSize(35, 35);
        self:SetVisible(true);
        self:SetActive( self.active );
        self:SetFadeSpeed(.3);
        
    -- EVENTS
    -- scrolling event
        self.quickslot.MouseWheel = function(sender,args)
            --if ( self:IsAltKeyDown()) then
            --self:LockScroll(not self.lock);
                --else
                if (not self.lock or self:IsControlKeyDown()) then
                        if (self.totallayers == 1 or self.IsAltKeyDown()) then
                                self.currentshortcut[self.currentlayer] = self.currentshortcut[self.currentlayer] + (args.Direction * -1);
                                if (self.currentshortcut[self.currentlayer] > self.totalshortcuts[self.currentlayer]) then
                                self.currentshortcut[self.currentlayer] = 1;
                                elseif (self.currentshortcut[self.currentlayer] == 0) then
                                self.currentshortcut[self.currentlayer] = self.totalshortcuts[self.currentlayer];
                                end
                        self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].hex ) );
                    else
                        self.currentlayer = self.currentlayer + (args.Direction * -1);
                        if (self.currentlayer > self.totallayers) then
                                        self.currentlayer = 1;
                                elseif (self.currentlayer == 0) then
                                        self.currentlayer = self.totallayers;
                                end
                                
                        if (self.totalshortcuts[self.currentlayer] == nil) then
                                        local counter = 1;
                                while (self.totalshortcuts[self.currentlayer] == nil and counter < self.totallayers) do
                                        self.currentlayer = self.currentlayer + (args.Direction * -1);
                                        if (self.currentlayer > self.totallayers) then
                                                        self.currentlayer = 1;
                                                elseif (self.currentlayer == 0) then
                                                        self.currentlayer = self.totallayers;
                                                end
                                                counter = counter + 1;
                                        end
                                end
                                
                                self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].hex ) );
                    end
           end
        end
        
        -- hover mouse enter event
        self.quickslot.MouseEnter = function(sender,args)
        if (self.hover and self.active and (self.totallayers > 1 or self.totalshortcuts[1] ~= 0)) then
                        self:SetOpacity(settings.opacity);
                end
        end
        
        -- hover mouse leave event
        self.quickslot.MouseLeave = function(sender,args)
            if (self.hover and self.active and (self.totallayers > 1 or self.totalshortcuts[1] ~= 0)) then
                        self:SetOpacity(settings.opacity * .5);
                end
        end
        
        -- swap positions when skill is dropped on the skill slot
        self.quickslot.DragDrop = function(sender, args)
            self:ResetQuickslot();
        KragenBars:SwapSlots(self, args.DragDropInfo:GetShortcut():GetData());
        end

end

-- SET ACTIVE (To be used in place of SetVisible)
function SkillMultiSlot:SetActive( active )
        self.active = active;
        if ( self.active and self.totalshortcuts[1] ~= 0 and ( ( vars.player:IsInCombat() and self.incombat ) or ( not vars.player:IsInCombat() and self.outcombat ) ) ) then
                if (self.hover) then
                        self:SetOpacity(settings.opacity * .5);
                else
                        self:SetOpacity(settings.opacity);
                end
                self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].hex ) );            
        else
        self:SetOpacity(0);
        self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Undefined, "" ) );
        end
end

-- SET STATE (To be used to track the effect state of buffs/debuffs)
function SkillMultiSlot:SetState( state, visible, id )
    -- update state and effect id
        if ( state ) then
                self.state = true;
                self.effectid = id;
        else
                if ( id == self.effectid ) then
                    self.state = false;
                        self.effectid = 0;
                end

        end

    -- update visibility
        if (self.effectid == 0 or state) then
        self:SetActive(visible);
        end
end

-- RESET QUICKSLOT SHORTCUT
function SkillMultiSlot:ResetQuickslot()
        self:SetIndex(self.currentshortcut[self.currentlayer], self.currentlayer);
end

-- SET HOVER (Set the hover state)
function SkillMultiSlot:SetHover(bol)
        self.hover = bol;
        if (self.active and (self.totallayers > 1 or self.totalshortcuts[1] ~= 0)) then
                if (bol) then
                        self:SetOpacity(settings.opacity * .5);
                else
                    self:SetOpacity(settings.opacity);
                end
        end
end

-- SET COMBAT (Sets the combat visibility variables)
function SkillMultiSlot:SetCombat( incombat, outcombat )
        self.incombat   = incombat;
        self.outcombat  = outcombat;
        self:SetActive(self.active);
end

-- REFRESH COMBAT (Refresh Visibility for combat changes)
function SkillMultiSlot:RefreshCombat()
        self:SetActive( self.active );
end

-- LOAD POSITION, RECALL SAVED POSITION AND PARENT
function SkillMultiSlot:LoadPosition(data)
        self.x = data.pos[1];
        self.y = data.pos[2];
        self:SetPosition( (self.x - 1) * 35, (self.y - 1) * 35 );

        self:SetParent(data.parent);
        self.parent = data.parent;

        self:LockScroll(data.lock);
        
        for k,v in pairs(data.current) do
                self.currentshortcut[k] = v;
        end

        self:SetIndex(data.current[data.layer], data.layer);
end

-- SWAP POSITION WITH ANOTHER ItemSlot (REF)
function SkillMultiSlot:SwapPosition(ref)
        local newx = ref.x;
        local newy = ref.y;
        local newparent = ref.parent;

    self:SetPosition( (newx - 1) * 35, (newy - 1) * 35 );
    self:SetParent(newparent);
    ref:SetPosition( (self.x - 1) * 35, (self.y - 1) * 35 );
    ref:SetParent(self.parent);

        ref.x = self.x;
        ref.y = self.y;
        ref.parent = self.parent;
        self.x = newx;
        self.y = newy;
        self.parent = newparent;

end

-- ADD SHORTCUT: ADD A SKILL TO THE MULTI SLOT
function SkillMultiSlot:AddShortCut(name, level, hex, layer)
        if (layer == nil) then
                layer = 1;
        end
        if (layer > self.totallayers) then
                self.totallayers = layer;
                self.totalshortcuts[layer] = 0;
                self.currentshortcut[layer] = 1;
                self.shortcuts[layer] = { };
        end
        self.totalshortcuts[layer] = self.totalshortcuts[layer] + 1;
        self.shortcuts[layer][self.totalshortcuts[layer]] = { ["level"] = level, ["hex"] = hex };
        
        if (self.totalshortcuts[layer] == 1 and self.totallayers == 1) then
     self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.shortcuts[1][1].hex ) );
        end
end

-- SET INDEX: Set the currently visible skillslot
function SkillMultiSlot:SetIndex(int, layer)
        if (layer == nil) then
                layer = 1;
        end
        if (self.totalshortcuts[layer] ~= 0) then               
                if (int > 0 and int <= self.totalshortcuts[layer] and vars.playerlevel >= self.shortcuts[layer][int].level) then
                    self.currentshortcut[layer] = int;
                self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.shortcuts[layer][int].hex ) );
                else
                        self.currentshortcut[layer] = 1;
                self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.shortcuts[layer][1].hex ) );
                end
        else
                self:SetActive(false);
        end
end

-- LEVEL CHECK: Removing the skills that are beyond the players level
function SkillMultiSlot:LevelCheck()
        local check = false;
        for layer = 1, self.totallayers do
                if (self.totalshortcuts[layer] ~= nil) then
                    for i = 1, self.totalshortcuts[layer] do
                                if (self.shortcuts[layer][i].level > vars.playerlevel) then
                                        self.totalshortcuts[layer] = self.totalshortcuts[layer] - 1;
                                end
                                if (self.totalshortcuts[layer] == 0) then
                                    check = false;
                                else
                                    check = true;
                                end
                        end
                end
        end
        if (not check) then
                self:SetActive(false);
                self:SetActive(true);
        end
        if (self.savedcurrentshortcut ~= nil) then
                for k,v in pairs(self.savedcurrentshortcut) do
                        if (self.totalshortcuts[k] ~= nil and v <= self.totalshortcuts[k]) then
                                self.currentshortcut[k] = v;
                        else
                                self.currentshortcut[k] = 1;
                        end
                end 
                if (self.shortcuts[self.savedcurrentlayer][self.currentshortcut[self.savedcurrentlayer]] ~= nil) then
                        self.currentlayer = self.savedcurrentlayer;
                else
                        self.currentlayer = 1;
                end
        end
        self:SetIndex(self.currentshortcut[self.currentlayer], self.currentlayer);
        self:SetOpacity(settings.opacity);
end

-- CLEAR: WIPE ALL SHORTCUTS
function SkillMultiSlot:Clear()
        self.savedcurrentshortcut = self.currentshortcut;
        self.savedcurrentlayer = self.currentlayer;
        
        self.shortcuts = { };
        self.shortcuts[1] = { };
        self.totalshortcuts = { };
        self.totalshortcuts[1] = 0;
        self.totallayers = 1;
        self.currentshortcut = { };
        self.currentshortcut[1] = 1;
        self.currentlayer = 1;
end

-- LOCK SCROLL (Locks multi so ctrl must be held down to advance)
function SkillMultiSlot:LockScroll(bol)
        --self.lock = bol;
end

-- START TIMER (Starts the timer, bol is true for Early Warnings and false for Skill Hacks)
function SkillMultiSlot:StartTimer(duration, bol)
        self.timer:Stop();
        self.timer:SetInterval(duration);
        self.timer:Start();
        self.timerEnd = bol;
end

-- ROTATE BAR: SWAP THE SLOTS X AND Y POSITION
function SkillMultiSlot:RotateBar()
        local newx = self.y;
        local newy = self.x;

        self:SetPosition( (newx - 1) * 35, (newy - 1) * 35 );

        self.x = newx;
        self.y = newy;
end

Compare with Previous | Blame


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


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