lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

[/] [branches/] [3.21/] [KragenBars/] [ItemMultiSlot.lua] - Rev 72

Compare with Previous | Blame | View Log

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

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

function ItemMultiSlot: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.totallayers = 1;
        self.currentshortcut = { };
        self.currentshortcut[1] = 1;
        self.currentlayer = 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:SetOpacity( settings.opacity *.5 );
                        self:SetActive( true );
                else
                    self:SetActive( false );
                end
        end

        -- set properties
        self:SetParent( parent );
        self:SetVisible(true);
        self:SetPosition( (x - 1) * 35, (y - 1) * 35 );
        self:SetSize(35, 35);
        self:SetActive( 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
                                
                                if (not pcall(function() self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].type, self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].data ) ); end)) then
                                        self:CleanSlots(self.currentlayer);                             
                                end
                                
                    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
                                
                                pcall(function() self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].type, self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].data ) );end);
                    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
        
        -- on dragdrop reset the hex (preventing drag drops)
        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 ItemMultiSlot:SetActive( active )
        self.active = active;
        if ( self.active and (self.totallayers > 1 or self.totalshortcuts[1] ~= 0) and ( ( vars.player:IsInCombat() and self.incombat ) or ( not vars.player:IsInCombat() and self.outcombat ) ) ) then
                pcall(function() self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].type, self.shortcuts[self.currentlayer][self.currentshortcut[self.currentlayer]].data ) );end);              
                
                if (self.hover) then
                        self:SetOpacity(settings.opacity * .5);
                else
                        self:SetOpacity(settings.opacity);
                end             
        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 ItemMultiSlot: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 ItemMultiSlot:ResetQuickslot()
        self:SetIndex(self.currentshortcut[self.currentlayer], self.currentlayer);
end

-- SET HOVER (Set the hover state)
function ItemMultiSlot: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 ItemMultiSlot:SetCombat( incombat, outcombat )
        self.incombat   = incombat;
        self.outcombat  = outcombat;
        self:SetActive(self.active);
end

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

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

        if (data.parent == nil) then 
                self:SetParent(limbo);
        else
                self:SetParent(data.parent); 
        end
        
        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 ItemMultiSlot: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);
    
        if (not ref.blank) then
                if (self.parent ~= nil) then
                        ref:SetPosition( (self.x - 1) * 35, (self.y - 1) * 35 );
                        ref:SetParent(self.parent);
                else
                        ref:SetParent(limbo);
                end

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

end

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

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

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

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

-- START TIMER (Starts the timer, bol is true for Early Warnings and false for Skill Hacks)
function ItemMultiSlot: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 ItemMultiSlot:RotateBar()
        local newx = self.y;
        local newy = self.x;

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

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

function ItemMultiSlot:Refresh(active)
        if (active == nil) then
                active = self.active;
        end
        self:SetActive(active);
        self:SetIndex(self.currentshortcut[self.currentlayer], self.currentlayer);
end

function ItemMultiSlot:CleanSlots(layer)
        local counter = 0;
        for k,v in pairs (self.shortcuts[layer]) do
                if (pcall(function() self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( v.type, v.data ) );end)) then
                        counter = counter + 1;
                        self.shortcuts[layer][counter] = v;
                end
        end
        self.totalshortcuts[layer] = counter;
        if (self.currentshortcut[layer] > self.totalshortcuts[layer]) then
                self.currentshortcut[layer] = 1;
        end
        self:Refresh();
end



Compare with Previous | Blame


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


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