import "Turbine.UI";
import "Turbine.UI.Lotro";
import "KragenPlugs.Utils";
import "KragenPlugs.Utils.Extensions";
import "KragenPlugs.KragenBars";
KBButton = class ( Turbine.UI.Window );
function KBButton:Constructor ( x, y )
Turbine.UI.Window.Constructor( self );
self.drag = false;
self.moved = false;
self.dragStartX = 0;
self.dragStartY = 0;
local displayWidth = Turbine.UI.Display:GetWidth();
local displayHeight = Turbine.UI.Display:GetHeight();
self:SetSize( 40, 39 );
self:SetPosition(x, y);
self:SetOpacity( 1 );
self:SetVisible(true);
self:SetMouseVisible(true);
self:SetBackground( "KragenPlugs/Kragenbars/Resources/"..settings.class..".tga" );
self:SetBackColorBlendMode( Turbine.UI.BlendMode.Overlay );
self.MouseClick = function( sender, args )
if (not self.moved) then
if( args.Button == Turbine.UI.MouseButton.Left) then
if(KragenBars.setup:IsVisible()) then
KragenBars:SetupClosing();
KragenBars.setup.Close(KragenBars.setup);
else
KragenBars:ShowSetup();
end
elseif( args.Button == Turbine.UI.MouseButton.Right ) then
local contextMenu = Turbine.UI.ContextMenu()
local contextMenuItems = contextMenu:GetItems();
local menuItem = Turbine.UI.MenuItem( "Lock Quickslots" );
menuItem:SetChecked( settings.lockslots );
menuItem.Click = function(sender, args)
settings.lockslots = not settings.lockslots;
end
contextMenuItems:Add( menuItem );
local menuItem = Turbine.UI.MenuItem( "Windows Snap to Grid" );
menuItem:SetChecked( settings.snaptogrid );
menuItem.Click = function(sender, args)
settings.snaptogrid = not settings.snaptogrid;
end
contextMenuItems:Add( menuItem );
local menuItem = Turbine.UI.MenuItem( "RClk to Adv Multi Slots" );
menuItem:SetChecked( settings.advanceonclick );
menuItem.Click = function(sender, args)
settings.advanceonclick = not settings.advanceonclick;
KragenBars:Refresh();
end
contextMenuItems:Add( menuItem );
if (settings.classinfo.preconf ~= nil and settings.classinfo.userconf ~= nil) then
local check = false;
local subMenu = Turbine.UI.MenuItem( "Button Bars" );
local subMenuItems = subMenu:GetItems();
for k, v in pairs(settings.classinfo.preconf) do
local menuItem = Turbine.UI.MenuItem( v.name );
menuItem:SetChecked( v.active );
menuItem.Click = function(sender, args)
v.active = not v.active;
KragenBars.windows[k]:Refresh(v.active);
end
subMenuItems:Insert( v.id, menuItem );
check = true;
end
for k, v in pairs(settings.classinfo.userconf) do
local menuItem = Turbine.UI.MenuItem( v.name );
menuItem:SetChecked( v.active );
menuItem.Click = function(sender, args)
v.active = not v.active;
KragenBars.windows[k]:Refresh(v.active);
end
subMenuItems:Insert( v.id, menuItem );
check = true;
end
if (check) then contextMenuItems:Add(subMenu); end
end
if (settings.classinfo.traits ~= nil) then
local check = false;
local subMenu = Turbine.UI.MenuItem( "Traits" );
local subMenuItems = subMenu:GetItems();
for k, v in pairs(settings.classinfo.traits) do
local menuItem = Turbine.UI.MenuItem( v.name );
menuItem:SetChecked( v.active );
menuItem.Click = function(sender, args)
v.active = not v.active;
KragenBars:Refresh();
end
subMenuItems:Insert( v.id, menuItem );
check = true;
end
if (check) then contextMenuItems:Add(subMenu); end
end
if (settings.classinfo.features ~= nil) then
local check = false;
local subMenu = Turbine.UI.MenuItem( "Features" );
local subMenuItems = subMenu:GetItems();
for k, v in pairs(settings.classinfo.features) do
local menuItem = Turbine.UI.MenuItem( v.name );
menuItem:SetChecked( v.active );
menuItem.Click = function(sender, args)
v.active = not v.active;
KragenBars:Refresh();
end
subMenuItems:Insert( v.id, menuItem );
check = true;
end
if (check) then contextMenuItems:Add(subMenu); end
end
if (settings.classinfo.defaults ~= nil) then
local check = false;
local subMenu = Turbine.UI.MenuItem( "Defaults" );
local subMenuItems = subMenu:GetItems();
for k, v in pairs(settings.classinfo.defaults) do
local subMenu2 = Turbine.UI.MenuItem( v.name );
local subMenu2Items = subMenu2:GetItems();
for key, value in pairs (v.list) do
local menuItem = Turbine.UI.MenuItem( value );
menuItem:SetChecked( key == v.selected );
menuItem.Click = function(sender, args)
v.selected = key;
KragenBars:Refresh();
end
subMenu2Items:Insert( key, menuItem );
end
subMenuItems:Insert(v.id, subMenu2);
check = true;
end
if (check) then contextMenuItems:Add(subMenu); end
end
local menuItem = Turbine.UI.MenuItem( "Refresh Level" );
menuItem.Click = function(sender, args)
KragenBars:Refresh();
end
contextMenuItems:Add( menuItem );
local menuItem = Turbine.UI.MenuItem( "Default Bar Positions" );
menuItem.Click = function(sender, args)
KragenBars:DefaultPosition();
end
contextMenuItems:Add( menuItem );
contextMenu:ShowMenu();
end
end
end
self.MouseDown = function( sender, args)
self.drag = true;
self.moved = false;
self.dragStartX = args.X;
self.dragStartY = args.Y;
end
self.MouseMove = function( sender, args)
if (self.drag) then
local left, top = self:GetPosition();
self:SetPosition( math.min( math.max( left + ( args.X - self.dragStartX ), 0 ), Turbine.UI.Display:GetWidth() - self:GetWidth() )
, math.min( math.max( top + ( args.Y - self.dragStartY ), 0 ), Turbine.UI.Display:GetHeight() - self:GetHeight()) );
local newx, newy = self:GetPosition();
if (self.dragStartX ~= newx or self.dragStartY ~= newy) then
self.moved = true;
end
end
end
self.MouseUp = function( sender, args )
self.drag = false;
settings.kbbutton = { };
settings.kbbutton.x, settings.kbbutton.y = self:GetPosition();
end
end