--Options box
--*************
--Register a slash command
shellCommand = Turbine.ShellCommand()
function shellCommand:Execute(command, i)
ShowOption(tonumber(i)or 1)
end
Turbine.Shell.AddCommand('BW,BuffWatch', shellCommand)
--Part 1: Create an option box that will open a given conifugration. Worry about editing later.
Option={}
--Set the top left. This is NOT saved on exiting the game - not worth it.
Option.x=100
Option.y=100
function ShowOption(i)
--Trap zero categories
if #RemindMe==0 then
RemindMe[1]={}
RemindMe[1].bufflist={"Set Buffs"}
RemindMe[1].reminder= "New Category"
RemindMe[1].AndOr="or"
end
if i==0 then i=1 end --Just to trap awkward people who put /bw 0...
--Trap an incorrect number
if i>#RemindMe then
Turbine.Shell.WriteLine("There are only "..#RemindMe.." categories")
return
end
--Make the window
Option.Window = Turbine.UI.Lotro.GoldWindow();
Option.Window:SetPosition( Option.x, Option.y );
Option.Window:SetSize( 400, 540 );
Option.Window:SetText( "Buffwatch version "..verno);
Option.Window:SetVisible( true );
Option.Window:SetZOrder(1000)
--Master listbox
--****************
Option.ListBox = Turbine.UI.ListBox();
Option.ListBox:SetParent( Option.Window );
Option.ListBox:SetPosition( 20, 40 );
Option.ListBox:SetSize( 360, 760);
Option.ListBox:SetMaxItemsPerLine(1)
Option.ListBox:SetOrientation( Turbine.UI.Orientation.Horizontal );
--First title
Option.MasterTitle=optionlabel(360,"Category "..i)
Option.ListBox:AddItem(Option.MasterTitle)
--Textbox to hold data
Option.Category=optiontextbox(360,RemindMe[i].reminder)
Option.ListBox:AddItem(Option.Category)
--Sub Title
Option.SubTitle=optionlabel(360,"Watch for...")
Option.ListBox:AddItem(Option.SubTitle)
--Child Listbox
--**************
Option.Child = Turbine.UI.ListBox();
Option.Child:SetSize( 360, 310);
Option.Child:SetMaxItemsPerLine(1)
Option.Child:SetOrientation( Turbine.UI.Orientation.Horizontal );
--Fill the child with the contents of the Buffs. Maximum 10
Option.Buffs={}
local BuffsToWatch=10
for j=1, BuffsToWatch do
if j<=table.getn(RemindMe[i].bufflist) then
Option.Buffs[j]=optiontextbox(360,RemindMe[i].bufflist[j])
else
Option.Buffs[j]=optiontextbox(360,"")
end
--Add to Listbox
Option.Child:AddItem(Option.Buffs[j])
end
Option.ListBox:AddItem(Option.Child)
--And/Or Option
Option.AndOr=Turbine.UI.Lotro.CheckBox()
Option.AndOr:SetChecked(RemindMe[i].AndOr~="or")
Option.AndOr:SetText(" If checked I need ALL the buffs in this category.")
Option.AndOr:SetFont(Turbine.UI.Lotro.Font.Verdana10)
Option.AndOr:SetSize(360,40)
Option.ListBox:AddItem(Option.AndOr)
--Button Listbox
--****************
Option.ButtonBox = Turbine.UI.ListBox();
Option.ButtonBox:SetSize( 360, 60);
Option.ButtonBox:SetMaxItemsPerLine(2)
Option.ButtonBox:SetOrientation( Turbine.UI.Orientation.Horizontal );
--Button to register changes
--****************************
--Apply Button
Option.Apply = Turbine.UI.Lotro.GoldButton()
Option.Apply:SetSize(180,30)
Option.Apply:SetText("Apply")
Option.Apply.Click= function (sender, args)
--Apply these changes to the file...
--And/Or
if (Option.AndOr:IsChecked()==true) then
Turbine.Shell.WriteLine(" Set as an And category - be warned that this is very much a beta facility.")
RemindMe[i].AndOr="and"
else
RemindMe[i].AndOr="or"
end
--Category title
if Option.Category:GetText() ~="" then
--Changed Title? Might be - save it anyway
RemindMe[i].reminder=Option.Category:GetText()
--Buffs to watch
local q=1 --q keeps track of position and saves many, many problems.
for j=1 , 10 do
if Option.Buffs[j]:GetText() ~="" then
RemindMe[i].bufflist[q]=Option.Buffs[j]:GetText()
q=q+1
else
--If there is no text remove that item
table.remove (RemindMe[i].bufflist,j) -- This will reduce the length of the table by 1
end
end
else
--Deleted the category, oh you devil you!
table.remove (RemindMe,i)
end
--Rebuild the table
BuildTable()
--And run the scanner so current buffs register
scanner()
--Close the window
Option.Window:Close()
--Save the new setup!
Turbine.PluginData.Save( Turbine.DataScope.Character, "BuffWatch", RemindMe );
end
--Cancel Button
Option.Cancel = Turbine.UI.Lotro.GoldButton()
Option.Cancel:SetSize(180,30)
Option.Cancel:SetText("Cancel")
Option.Cancel.Click=function(sender,args)
--Cancelled - close that window!
Option.Window:Close()
BuildTable()
scanner()
end
--"Next" or "Add" Button
Option.Next = Turbine.UI.Lotro.Button()
Option.Next:SetSize(180,30)
Option.Next:SetVisible(true)
if (i==Need) and i<10 then
Option.Next:SetText("New Category")
Option.Next.Click=function(sender,args)
if Option.Category:GetText()=="New Category" then Turbine.Shell.WriteLine("This is a new category. Please use this one first!") return end --Stops just adding categories
if Option.Category:GetText()~=RemindMe[i].reminder then Turbine.Shell.WriteLine("Please apply changes to this category first") return end --Nearly stops you adding a new category without changing this one. Not quite, but close enough for me.
RemindMe[i+1]={}
RemindMe[i+1].reminder="New Category"
RemindMe[i+1].bufflist={}
RemindMe[i+1].bufflist[1]=""
RemindMe[i+1].AndOr="or"
BuildTable()
ShowOption(i+1)
return
end
elseif i<Need then
Option.Next:SetText("Next Category")
Option.Next.Click=function(sender,args)
if Option.Category:GetText()~=RemindMe[i].reminder then Turbine.Shell.WriteLine("Please apply changes to this category first") return end --Nearly stops you moving to the next category without changing this one. Not quite, but close enough for me.
--Go to next Buff category
ShowOption(i+1)
end
elseif i==10 then
Option.Next:SetVisible(false)
end
--"Previous" Button
Option.Previous = Turbine.UI.Lotro.Button()
Option.Previous:SetSize(180,30)
if i==1 then
Option.Previous:SetVisible(false)
else
Option.Previous:SetVisible(true)
Option.Previous:SetText("Previous Category")
Option.Previous.Click=function(sender,args)
if Option.Category:GetText()~=RemindMe[i].reminder then Turbine.Shell.WriteLine("Please apply changes to this category first") return end --Nearly stops you moving to the next category without changing this one. Not quite, but close enough for me.
--Go to Previous Buff category
ShowOption(i-1)
end
end
Option.ButtonBox:AddItem(Option.Apply)
Option.ButtonBox:AddItem(Option.Cancel)
Option.ButtonBox:AddItem(Option.Previous)
Option.ButtonBox:AddItem(Option.Next)
Option.ListBox:AddItem(Option.ButtonBox)
--Store the location on closing
Option.Window.PositionChanged=function(sender,args)
Option.x,Option.y=Option.Window:GetPosition()
end
end
optionlabel=class(Turbine.UI.Label)
function optionlabel:Constructor(width,text)
Turbine.UI.Label.Constructor(self)
self:SetSize( width, 20 );
self:SetFont(Turbine.UI.Lotro.Font.TrajanPro16)
self:SetText( text);
end
optiontextbox=class(Turbine.UI.Lotro.TextBox)
function optiontextbox:Constructor(width,text)
Turbine.UI.Lotro.TextBox.Constructor(self)
self:SetSize(width,30)
self:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleCenter)
self:SetFont(Turbine.UI.Lotro.Font.Verdana23)
self:SetText(text)
end