lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

[/] [trunk/] [KragenPlugs/] [KragenBars/] [ItemSlot.lua] - Rev 118

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, properties )
        KragenPlugs.Utils.Extensions.SimpleWindow.Constructor( self );
        
        -- declare variables
        self.parent     = parent;
    self.x              = x;
        self.y          = y;
        self.active     = active;
        self.type               = properties.type;
        self.data               = properties.data;
        self.effectid   = 0;
        self.state      = false;
        self.hover              = false;
        self.incombat   = true;
        self.outcombat  = true;
        self.edit               = false;
        self.swap               = true;
        self.altfuncid = 0;
        
        -- 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:SetPosition( (x - 1) * 35, (y - 1) * 35 );
        self:SetSize(35,35);
        self:SetVisible(true);
        self:SetFadeSpeed(.3);
        self:SetActive(self.active);
        self:SetQuickslot(properties);
        
        -- 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
        self.OnAlt = function(bol)
                if (bol) then
                        self:SetOpacity(1);
                        self.edit = true;
                        self:ResetQuickslot();
                else
                        if (not KragenBars.edit) then
                                self.edit = false;
                                self:Refresh();
                        end
                end
        end
        
        -- hover mouse enter event
        self.quickslot.MouseEnter = function(sender,args)
        if (self.hover and self.active) then
                        self:SetOpacity(settings.opacity);
                end
                altCheck.Add(self.OnAlt);
        end

        -- hover mouse leave event
        self.quickslot.MouseLeave = function(sender,args)
            if (self.hover and self.active) then
                        self:SetOpacity(settings.opacity * .5);
                end
                altCheck.Clear();
        end
        
        self.clicked = false;
        self.quickslot.MouseDown = function(sender, args)
                self.clicked = true;
                
        end
        
        self.quickslot.DragLeave = function(sender, args)
                if (not settings.lockslots and self.clicked) then
                        self.clicked = false;
                        if (self:IsAltKeyDown()) then
                                self:SetParent(limbo);
                                self.parent = nil;
                                self:SetPosition(0,0);
                                self.x = 1;
                                self.y = 1;
                        end
                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(), args.DragDropInfo:GetShortcut():GetType());
        end

end

-- SET ACTIVE (To be used in place of SetVisible)
function ItemSlot:SetActive( active )
        self.active = active;
        if (not self.edit) then
                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


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(prop)
        if (prop.active and prop.data ~= "" and prop.type ~= 0) then
                self.type = prop.type;
                self.data = prop.data;
        else
                self.type = Turbine.UI.Lotro.ShortcutType.Undefined;
                self.data = "";
        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 (self.active or self.edit) 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
                        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

function ItemSlot:CheckShortcut(code)
        local retval = false;
        if (self.data == code and self.swap) then
                retval = true;
        end
        return retval;
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));

        if (data.parent == nil) then 
                self:SetParent(limbo);
                self.parent = nil;
                self:SetPosition(0,0);
                self.x = 1;
                self.y = 1;
        else
                self:SetParent(data.parent); 
        end
        
        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;
        
        if (self.parent ~= ref.parent) then
                if (self.parent ~= nil and self.parent.ChangeSkill ~= nil) then self.parent:ChangeSkill(self, ref); end
                if (ref.parent ~= nil and ref.parent.ChangeSkill ~= nil) then ref.parent:ChangeSkill(ref, self); end
        end
        
    self:SetPosition( (newx - 1) * 35, (newy - 1) * 35 );
        self.border:SetPosition(self:PointToScreen(1, 1));
        self:SetParent(newparent);
        self:SetParent(newparent);
        
        if (not ref.blank) then
                if (self.parent ~= nil) then
                        ref:SetPosition( (self.x - 1) * 35, (self.y - 1) * 35 );
                        ref.border:SetPosition(ref:PointToScreen(1, 1));                
                        ref:SetParent(self.parent);
                else
                        ref:SetParent(limbo);
                        ref.parent = nil;
                        ref:SetPosition(0,0);
                        ref.x = 1;
                        ref.y = 1;
                end

                ref.x = self.x;
                ref.y = self.y;
                ref.parent = self.parent;
                ref:SetActive(ref.active);
        end
        
        self.x = newx;
        self.y = newy;
        self.parent = newparent;
        self:SetActive(self.active);

end

function ItemSlot:SetSwap(bol)
        self.swap = bol;
end

-- UPDATE THE WINDOW STATE
function ItemSlot:Refresh()
        self:SetActive( self.active );
        self:RefreshBorders();
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 (self.parent == nil or self.parent == limbo or not self.parent.parent:IsVisible()) then
                self.bordervisible = false;
                self.border:SetVisible(false);
        else
                self.border:SetVisible(true);
        end
end

Compare with Previous | Blame


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


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