lotrointerface.com
Search Downloads

LoTROInterface SVN KragenBars

[/] [branches/] [3.20/] [KragenBars/] [SkillSlot.lua] - Rev 52

Compare with Previous | Blame | View Log

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

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

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

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

        -- convert level and hex into a table
        if (type(level) ~= "table") then
                self.level = { level };
                self.hex    = { hex };
        else
            self.level = level;
            self.hex = hex;
        end
        
        -- QUICKSLOT
        self.quickslot = Turbine.UI.Lotro.Quickslot();
        self.quickslot:SetParent(self);
        self.quickslot:SetSize(35, 35);
        self.quickslot:SetZOrder(0);
        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:SetActive( true );
                        self:SetHover( true );
                else
                    self:SetActive( false );
                    self.parent:SetZOrder(-10);
                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);
        
        -- 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(-20);
        self.border:SetVisible(false);
        
        -- EVENTS
        -- hover mouse enter event
        self.quickslot.MouseEnter = function(sender,args)
        if (self.hover and self.active and ( ( vars.player:IsInCombat() and self.incombat ) or ( not vars.player:IsInCombat() and self.outcombat ) )) then
                        self:SetOpacity(settings.opacity);
                end
        end

        -- hover mouse leave event
        self.quickslot.MouseLeave = function(sender,args)
            if (self.hover and self.active and ( ( vars.player:IsInCombat() and self.incombat ) or ( not vars.player:IsInCombat() and self.outcombat ) )) 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 SkillSlot:SetActive( active )
        self.active = active;
        if ( self.active 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: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 SkillSlot: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 AND CHECK LEVEL
function SkillSlot:ResetQuickslot()
        if ( (self.active and self.level[2] ~= nil and vars.playerlevel >= self.level[2])) then
            self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.hex[2] ) );
        elseif ( (self.active and vars.playerlevel >= self.level[1])) then
            self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.hex[1] ) );
        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 SkillSlot:SetHover(bol)
        self.hover = bol;
        
        if (self.active and ( ( vars.player:IsInCombat() and self.incombat ) or ( not vars.player:IsInCombat() and self.outcombat ) )) 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 SkillSlot:SetCombat( incombat, outcombat )
        self.incombat   = incombat;
        self.outcombat  = outcombat;
        self:SetActive(self.active);
end

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

-- LOAD POSITION, RECALL SAVED POSITION AND PARENT
function SkillSlot: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);
        else
                self:SetParent(data.parent); 
        end
        
        self.parent = data.parent;
end

-- SWAP POSITION WITH ANOTHER SKILLSLOT (REF)
function SkillSlot: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);
        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);
                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

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

-- START TIMER
function SkillSlot: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 SkillSlot: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 SkillSlot:SetColor(color)
        if (color == "purple") then
        self.border:SetBackColor(Turbine.UI.Color(.8, .0, 1));
        self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1]);
        
    elseif (color == "red") then
        self.border:SetBackColor(Turbine.UI.Color(1, 0, 0));
        self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1]);
        
    elseif (color == "green") then
        self.border:SetBackColor(Turbine.UI.Color(.1, 1, .1));
        self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1]);
                
        elseif (color == nil) then
                self.border:SetVisible(false);
        end
end

function SkillSlot:RefreshBorders()
        if (self.parent == nil 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 02:42 PM.


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