lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

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

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

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

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

function ItemSlot:Constructor ( parent, x, y, active, type, data )
        KragenPlugs.Utils.Extensions.SimpleWindow.Constructor( self );
        
        -- declare variables
        self.parent     = parent;
    self.x              = x;
        self.y          = y;
        self.active     = active;
        self.type               = type;
        self.data               = data;
        self.effectid   = 0;
        self.state      = false;
        self.hover              = false;
        self.incombat   = true;
        self.outcombat  = true;
        
        -- QUICKSLOT
        self.quickslot = Turbine.UI.Lotro.Quickslot();
        self.quickslot:SetParent(self);
        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:SetPosition( (x - 1) * 35, (y - 1) * 35 );
        self:SetState( false, active, 0 );
        self:SetVisible(true);
        self:SetFadeSpeed(.3);
        self:SetActive(self.active);
        
        -- COLOR BAND
        self.border = Turbine.UI.Window();
        self.bordervisible = true;
        self.border:SetSize(36, 36);
        self.border:SetPosition(self:PointToScreen(1, 1));
        self.border:SetZOrder(-10);
        self.border:SetVisible(false);
        
        -- EVENTS
        -- hover mouse enter event
        self.quickslot.MouseEnter = function(sender,args)
        if (self.hover and self.active) then
                        self:SetOpacity(settings.opacity);
                end
        end

        -- hover mouse leave event
        self.quickslot.MouseLeave = function(sender,args)
            if (self.hover and self.active) 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 ItemSlot:SetActive( active )
        self.active = active;
        if ( self.active and self.data ~= "" and ( ( vars.player:IsInCombat() and self.incombat ) or ( not vars.player:IsInCombat() and self.outcombat ) ) ) then
                self:ResetQuickslot();
        else
        self:SetOpacity(0);
        if (self.quickslot ~= nil and self.quickslot:GetShortcut():GetData() ~= "") then            
                    self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Undefined, "" ) );
                end
        end


end

-- SET STATE (To be used to track the effect state of buffs/debuffs)
function ItemSlot: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

function ItemSlot:SetQuickslot(active, type, data)
        if (active) then
                self.type = type;
                self.data = data;
                self.active = active;
        else
                self.type = Turbine.UI.Lotro.ShortcutType.Undefined;
                self.data = "";
                self.active = active;
        end
        
        self:ResetQuickslot();
end

-- RESET QUICKSLOT SHORTCUT AND CHECK LEVEL
function ItemSlot:ResetQuickslot()
        if ( self.active and self.type ~= 0 and self.data ~= "") then
            if pcall(function() self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( self.type, self.data ) ); end) then
                    if (self.hover) then
                                self:SetOpacity(settings.opacity * .5);
                        else
                                self:SetOpacity(settings.opacity);
                        end
                else
                    self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Undefined, "" ) );
                end
        else    
                self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Undefined, "" ) );
                self:SetOpacity(0);
        end     
end

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

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

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

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

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

    self:SetPosition( (newx - 1) * 35, (newy - 1) * 35 );
    self.border:SetPosition(self:PointToScreen(1, 1));
    self:SetParent(newparent);
    ref:SetPosition( (self.x - 1) * 35, (self.y - 1) * 35 );
    ref.border:SetPosition(ref:PointToScreen(1, 1));
    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

-- UPDATE THE WINDOW STATE
function ItemSlot:Refresh()
        self:SetActive( self.active );
end

-- START TIMER (Starts the timer, bol is true for Early Warnings and false for Skill Hacks)
function ItemSlot: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 ItemSlot: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 ItemSlot:SetColor(color)
        if (color == "purple") then
        self.border:SetBackColor(Turbine.UI.Color(.8, .0, 1));
        self.border:SetVisible(self.active and self.bordervisible);

    elseif (color == "red") then
        self.border:SetBackColor(Turbine.UI.Color(1, .0, 0));
        self.border:SetVisible(self.active and self.bordervisible);

        elseif (color == nil) then
                self.border:SetVisible(false);
        end
end

function ItemSlot:RefreshBorders()
        if (not self.parent.parent:IsVisible()) then
                self.bordervisible = false;
                self.border:SetVisible(false);
        else
                self.border:SetVisible(true);
        end
end

Go to most recent revision | Compare with Previous | Blame


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


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