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;
self.bordervisible = false;
self.edit = false;
self.swap = 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
-- 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);
-- 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.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
-- 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
altCheck.Add(self.OnAlt);
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
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();
--if (args.DragDropInfo:GetShortcut():GetItem() == nil) then
KragenBars:SwapSlots(self, args.DragDropInfo:GetShortcut():GetData(), args.DragDropInfo:GetShortcut():GetType());
--else
--KragenBars:SwapSlots(self, args.DragDropInfo:GetShortcut():GetItem():GetName(), true);
--end
end
end
-- SET ACTIVE (To be used in place of SetVisible)
function SkillSlot:SetActive( active )
self.active = active;
if (not self.edit) then
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.border:SetVisible(self.bordervisible);
self:ResetQuickslot();
else
self:SetOpacity(0);
self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Undefined, "" ) );
self.border:SetVisible(false);
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()
local highlevel = 0;
if (self.active or self.edit) then
if (type(self.level) == "table") then
for k,v in pairs(self.level) do
if (v > highlevel and vars.playerlevel >= v) then
self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( 6.000000, self.hex[k] ) );
highlevel = v;
end
end
end
if (highlevel == 0) then
self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Undefined, "" ) );
self:SetOpacity(0);
end
end
end
function SkillSlot:CheckShortcut(code)
local retval = false;
if (self.swap) then
if(type(self.hex) == "table") then
for k,v in pairs(self.hex) do
if (v == code) then
retval = true;
end
end
else
if (self.hex == code) then
retval = true;
end
end
end
return retval;
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);
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 SKILLSLOT (REF)
function SkillSlot: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 SkillSlot:SetSwap(bol)
self.swap = bol;
end
-- UPDATE THE WINDOW STATE
function SkillSlot:Refresh()
self:SetActive( self.active );
self:RefreshBorders();
if (self.edit) then
self:SetOpacity(1);
end
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, alpha)
if (alpha == nil) then alpha = 1; end
if (color == "purple") then
self.bordervisible = true;
self.border:SetBackColor(Turbine.UI.Color(alpha, .8, .0, 1));
self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1] and self.parent ~= nil and self.parent ~= limbo and self.parent.parent:IsVisible());
elseif (color == "red") then
self.bordervisible = true;
self.border:SetBackColor(Turbine.UI.Color(alpha, .8, 0, 0));
self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1] and self.parent ~= nil and self.parent ~= limbo and self.parent.parent:IsVisible());
elseif (color == "green") then
self.bordervisible = true;
self.border:SetBackColor(Turbine.UI.Color(alpha, .1, 1, .1));
self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1] and self.parent ~= nil and self.parent ~= limbo and self.parent.parent:IsVisible());
elseif (color == "yellow") then
self.bordervisible = true;
self.border:SetBackColor(Turbine.UI.Color(alpha, 1, 1, 0));
self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1] and self.parent ~= nil and self.parent ~= limbo and self.parent.parent:IsVisible());
elseif (color == nil) then
self.border:SetBackColor(Turbine.UI.Color(0, 0, 0, 0));
self.bordervisible = false;
self.border:SetVisible(false);
end
end
function SkillSlot:RefreshBorders()
self.border:SetVisible(self.active and self.bordervisible and vars.playerlevel >= self.level[1] and self.parent ~= nil and self.parent ~= limbo and self.parent.parent:IsVisible());
end