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;
self.edit = false;
self.swap = true;
self.altfuncid = 0;
-- 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);
self.quickslot:SetUseOnRightClick(not settings.advanceonclick);
-- 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
self.quickslot.MouseClick = function(sender, args)
if (settings.advanceonclick and args.Button == Turbine.UI.MouseButton.Right) then
self.quickslot:MouseWheel({Direction = -1});
end
end
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 and (self.totallayers > 1 or self.totalshortcuts[1] ~= 0)) 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 (self.totallayers > 1 or self.totalshortcuts[1] ~= 0)) 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
-- on dragdrop reset the hex (preventing drag drops)
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 ItemMultiSlot:SetActive( active )
self.active = active;
if (not self.edit) then
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
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 );
self.currentlayer = data.layer;
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;
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;
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: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);
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;
end
self.x = newx;
self.y = newy;
self.parent = newparent;
end
function ItemMultiSlot:SetSwap(bol)
self.swap = bol;
end
-- UPDATE THE WINDOW STATE
function ItemMultiSlot:Refresh()
self:SetActive( self.active );
if (self.edit) then
self:SetOpacity(1);
end
end
-- ADD SHORTCUT: ADD A SKILL TO THE MULTI SLOT
function ItemMultiSlot:AddShortCut(name, properties, layer)
if (layer == nil) then
layer = 1;
end
if (properties.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( properties.type, properties.data ) ); end) then
self.totalshortcuts[layer] = self.totalshortcuts[layer] + 1;
self.shortcuts[layer][self.totalshortcuts[layer]] = { ["type"] = properties.type, ["data"] = properties.data };
end
end
end
function ItemMultiSlot:CheckShortcut(code)
local retval = false;
if (self.swap) then
for k,v in pairs(self.shortcuts) do
for key, value in pairs(v) do
if (value.data == code) then
retval = true;
end
end
end
end
return retval;
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;
if (self.active or self.edit) then
pcall(function() self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( self.shortcuts[layer][int].type, self.shortcuts[layer][int].data ) );end);
end
else
self.currentshortcut[layer] = 1;
if (self.active or self.edit) then
pcall(function() self.quickslot:SetShortcut( Turbine.UI.Lotro.Shortcut( self.shortcuts[layer][1].type, self.shortcuts[layer][1].data ) );end);
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);
self.quickslot:SetUseOnRightClick(not settings.advanceonclick);
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