lotrointerface.com
Search Downloads

LoTROInterface SVN BuffWatch

[/] [trunk/] [JackdawPlugins/] [BuffWatch/] [Functions.Lua] - Rev 10

Compare with Previous | Blame | View Log

import "Deusdictum.UI.Dragbar"
--Part 4:       The scanner

function scanner()
                        --I really, really should change this so it only looks at the last buff applied but... this is actually problematic.
                        --There is no apparent way to get the name of a buff as it is lost, and the performance gain of scanning for a buff as it is gained is not worth it
                        --given that effects.removed triggers even when an effect is added - but not always or that is the only trigger I would use!                    
                        ScanAll()
                        DisplayTable()
end

function ScanAll()
--Scan all the effects on the character
        local n=effects:GetCount() -- How many effects are currently on the character
        --Reset gotbuff[]
        gotbuff={} for i=1, Need do gotbuff[i]=0 end
        --Set the gotbuff table where the buff matches
        for i = 1,n do
                effectname=effects:Get(i):GetName()
                --Now, is this name in the list?
                local bufffound = Scan(effectname)
                if bufffound~=0 then
                        if RemindMe[bufffound].AndOr=="or" then 
                                gotbuff[bufffound]=1
                        else
                                gotbuff[bufffound]=gotbuff[bufffound]+1
                        end
                end
        end
end

function Scan(Name)
        --Scans through the RemindMe.bufflist list looking for Name in any place in the table
        for i=1, table.getn(RemindMe) do
                local found=SearchTable(RemindMe[i].bufflist,Name)
                if found>0 then return i end
        end
        return 0
end

function DisplayTable()
        local g=totalbuff()
        if g==Need then Reminder.window:SetVisible(false) return end -- We have all the buffs. GO HOME! 
        
        BuffsNeeded=Need-g -- How many buffs do we need then?
        
        Reminder.window:SetSize(150,20*BuffsNeeded)
        Reminder.window:SetVisible(true)
        Reminder.listbox:SetSize( 150, 20*BuffsNeeded); -- I think this actually re-sets the listbox. Which is fine by me!
        for i=1,Need do
                if RemindMe[i].AndOr=="or" then
                        --Just need a '1' to have the buff.
                        if gotbuff[i]~=1 then --we don't have this buff
                                pcall( function() Reminder.listbox:AddItem(Reminder.label[i]) end)
                        else
                                pcall( function() Reminder.listbox:RemoveItem(Reminder.label[i]) end)--This line throws an error, BUT if it isn't here it causes the effects to become out-of-sync. So, changed to a pcall
                        end
                        --Otherwise this must be an "and" category - only add if we have ALL the buffs.
                elseif gotbuff[i]~=#RemindMe[i].bufflist then
                        pcall( function() Reminder.listbox:AddItem(Reminder.label[i]) end)
                else
                        pcall( function() Reminder.listbox:RemoveItem(Reminder.label[i]) end)--This line throws an error, BUT if it isn't here it causes the effects to become out-of-sync. So, changed to a pcall
                end
                Reminder.label[i].MouseEnter=function (sender,args)
                                ShowTooltip(i)
                end
                Reminder.label[i].MouseLeave=function (sender,args)
                                HideTooltip()
                end
        end
end
--Create a frame to hold the reminders: A Window>Listbox
function BuildTable()
        
        Need=table.getn(RemindMe)                       -- this is how many buffs we are looking for
        
        gotbuff={} for i=1, Need do gotbuff[i]=0 end    --set up a variable tohold a flag for if we have the buff in that category
        BuffsNeeded=Need*20                                     -- Full height on first run.
        
        Reminder={}
        
        Reminder.window= Turbine.UI.Window()
        Reminder.window:SetPosition(RemindMe.x,RemindMe.y)
        Reminder.window:SetSize(150,20*BuffsNeeded)
        Reminder.window:SetVisible(true)
        Reminder.window:SetOpacity(0.5)
        Reminder.window:SetBackColor (Turbine.UI.Color(0, 0, 0, 0))
        
        Reminder.window.DragBar = Deusdictum.UI.DragBar( Reminder.window, "Buff Watch")

        Reminder.listbox=Turbine.UI.ListBox();
                  Reminder.listbox:SetParent( Reminder.window );
                  Reminder.listbox:SetBackColor( Turbine.UI.Color( 0, 0, 0,0 ) );
                  Reminder.listbox:SetPosition( 0, 0 );
                  Reminder.listbox:SetSize( 150, 20*BuffsNeeded);
                  Reminder.listbox:SetMaxItemsPerLine(1)
                  Reminder.listbox:SetOrientation( Turbine.UI.Orientation.Horizontal );   

        Reminder.label={}
        for i=1,Need do
                        Reminder.label[i]=Turbine.UI.Label()
                        Reminder.label[i]:SetFont(Turbine.UI.Lotro.Font.Verdana20)
                        Reminder.label[i]:SetSize( 150, 20 );
                        Reminder.label[i]:SetBackColor( Turbine.UI.Color( 1,1-(i/Need),0,0 ) );
                        Reminder.label[i]:SetText(RemindMe[i].reminder);
                        Reminder.label[i]:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter );
                        Reminder.label[i]:SetOutlineColor( Turbine.UI.Color( 1, 0, 0,0 ) );
                        Reminder.label[i]:SetFontStyle( Turbine.UI.FontStyle.Outline )
                        Reminder.label[i].MouseClick= function (sender, args)
                                Reminder.window:SetVisible(false)
                        end
                        Reminder.listbox:AddItem(Reminder.label[i])
        end
        --Register to save position when moved.
        --Will also save settings.
        Reminder.window.PositionChanged=function(sender, args)
                RemindMe.x,RemindMe.y=Reminder.window:GetPosition()
                Turbine.PluginData.Save( Turbine.DataScope.Character, "BuffWatch", RemindMe );
        end
end

--totalbuff()=sum gotbuff[]
function totalbuff()
        local a=0
                for i=1, Need do
                        --If this is an "or" category then just add the number in gotbuff
                        if RemindMe[i].AndOr=="or" then
                                a=a+gotbuff[i]
                        --Otherwise this must be an "and" category - only add if we have ALL the buffs.
                        elseif gotbuff[i]==#RemindMe[i].bufflist then
                                a=a+1
                        end
                end
        return a
end

function SearchTable(InputTable,SearchString)
--Will search the string for given results in a table. If found returns the row reference. So, for example I could look for "ore" in any items name. Used below.
--BE AWARE! CASE SENSITIVE!
        for i = 1, # InputTable do
                found,foo=string.find(SearchString,InputTable[i],1,true)
                if found ~=nil then
                        return i
                end
        end
        return 0
end

--Tooltip functions
function ShowTooltip(i)
        Tooltip= Turbine.UI.Window()
        local x,y=Turbine.UI.Display.GetMousePosition()
        local height=(#RemindMe[i].bufflist+3)*12 -- this is approximate!
        --Position tooltip - want it to switch sides!
        if RemindMe.x<(Turbine.UI.Display.GetWidth()/2)-75 then
                x=RemindMe.x+150
        else
                x=RemindMe.x-150
        end
        
        Tooltip:SetPosition(x,y)
        Tooltip:SetSize(150,height)
        Tooltip:SetVisible(true)
        Tooltip:SetOpacity(0.8)
        Tooltip:SetBackColor (Turbine.UI.Color(0.8, 0, 0, 0))
        Tooltiplabel=Turbine.UI.Label()
        Tooltiplabel:SetParent(Tooltip)
        Tooltiplabel:SetPosition(0,0)
        Tooltiplabel:SetSize( 150, height );
        Tooltiplabel:SetFont(Turbine.UI.Lotro.Font.Arial12)
        local Bufflist=table.concat(RemindMe[i].bufflist,"\n")
        local message=""
        if RemindMe[i].AndOr=="or" then
                message="Any of these Buffs needed for category '"..RemindMe[i].reminder.."' to vanish; ".."\n".. Bufflist
        else
                message="All of these Buffs needed for category '"..RemindMe[i].reminder.."' to vanish; ".."\n".. Bufflist
        end
        Tooltiplabel:SetText( message)
end
        
function HideTooltip()
        --Actually - delete it!
        Tooltip:SetVisible(false)
        Tooltip=nil
end

--Thanks Pengoros...
function AddCallback(object, event, callback)
    if (object[event] == nil) then
        object[event] = callback;
    else
        if (type(object[event]) == "table") then
            table.insert(object[event], callback);
        else
            object[event] = {object[event], callback};
        end
    end
    return callback;
end

Compare with Previous | Blame


All times are GMT -5. The time now is 06:02 PM.


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