+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Junior Member Online status: Polymnie is offline Reputation: Polymnie the Neophyte Polymnie the Neophyte Polymnie the Neophyte Polymnie the Neophyte Polymnie the Neophyte Polymnie the Neophyte
    Join Date
    May 2011
    Posts
    34

    [Plugin] HalfIgnore

    If you've ever wondered if /glff is silent or if you've simply ignored everyone, or if you wonder why people seem to be talking to themselves, this plugin may help. For minor annoyances, rather than a full "/ignore jerkname", you can "/halfignore jerkname" and their posts will be blanked out until you choose to mouse over them.

    How to use
    "/halfignore" - list the names currently being half-ignored
    "/halfignore jerkname" - toggles whether jerkname is being half-ignored

    Six-legged chitinous features
    1. Requires the use of a new window, separate from the default chat tabs.
    2. The window is incredibly bare-bones and configuration is hard-coded. Sorry!
    3. Item-links appear through the masking.
    4. Item-links don't give a tooltip on mouse-over, but do when clicked.
    5. Player-names don't appear in green, but can still be right-clicked for the invite/inspect menu.
    6. Although the scrollbar behaviour is mostly correct, too many messages at once will cause a scroll.

    Thanks
    1. Evendale and Garan for advice, and bits of code swiped from their plugins.
    2. Riddermark /glff for being sufficiently annoying to warrant this plugin and giving me numerous test-cases.

    Updates
    2012/05/10 Fixed one of the attribution methods that bugged when quotations are posted.

    Code:
    import "Turbine.UI.Lotro"
    
    -- configuration
    local WindowLeft = 1
    local WindowTop = 500
    local WindowWidth = 320
    local WindowHeight = 208
    local ScrollbarWidth = 4
    local font = Turbine.UI.Lotro.Font.Verdana16
    
    local ColorTable = {}  -- Any chat channel not given a color is ignored.
    --ColorTable[Turbine.ChatType.Trade] = Turbine.UI.Color(0.824, 0.824, 0.824)
    --ColorTable[Turbine.ChatType.LFF] = Turbine.UI.Color(0.824, 0.824, 0.824)
    --ColorTable[Turbine.ChatType.Advice] = Turbine.UI.Color(0.824, 0.824, 0.824)
    --ColorTable[Turbine.ChatType.OOC] = Turbine.UI.Color(0.824, 0.824, 0.824)
    --ColorTable[Turbine.ChatType.Regional] = Turbine.UI.Color(0.824, 0.824, 0.824)  -- "stealthed enemy" notifications are on this channel
    --ColorTable[Turbine.ChatType.Roleplay] = Turbine.UI.Color(0.824, 0.824, 0.824)
    ColorTable[Turbine.ChatType.UserChat1] = Turbine.UI.Color(0.824, 0.824, 0.824)
    ColorTable[Turbine.ChatType.UserChat2] = Turbine.UI.Color(0.824, 0.824, 0.824)
    ColorTable[Turbine.ChatType.UserChat3] = Turbine.UI.Color(0.824, 0.824, 0.824)
    ColorTable[Turbine.ChatType.UserChat4] = Turbine.UI.Color(0.824, 0.824, 0.824)
    
    
    -- retrieve saved data
    local IgnoreTable = Turbine.PluginData.Load(Turbine.DataScope.Server, "HalfIgnore") -- saved per server, not per character
    if not IgnoreTable then
    	IgnoreTable = {}
    end
    
    -------------------------------------------------------------------------------
    -- event handling boilerplate
    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
    
    function RemoveCallback(object, event, callback)
        if (object[event] == callback) then
            object[event] = nil
        else
            if (type(object[event]) == "table") then
                local size = table.getn(object[event])
                for i = 1, size do
                    if (object[event][i] == callback) then
                        table.remove(object[event], i)
                        break
                    end
                end
            end
        end
    end
    -------------------------------------------------------------------------------
    TestHeightWindow = Turbine.UI.Window()
    --TestHeightWindow:SetVisible(true)
    TestHeightLabel = Turbine.UI.Label()
    TestHeightLabel:SetParent(TestHeightWindow)
    TestHeightLabel:SetFont(font)
    TestHeightLabel:SetBackColor(Turbine.UI.Color(0.1, 0, 0, 0))
    TestHeightLabel:SetSize(WindowWidth, 0) -- fixes first-test bug
    TestHeightScrollBar = Turbine.UI.Lotro.ScrollBar() -- don't use Turbine.UI.Scrollbar
    TestHeightScrollBar:SetParent(TestHeightWindow)
    TestHeightScrollBar:SetOrientation(Turbine.UI.Orientation.Vertical)
    TestHeightLabel:SetVerticalScrollBar(TestHeightScrollBar)
    
    function TestHeight(message)  -- Most lines will be 16 (Verdana16), but item-links are 12ish.  Thus, 4 is a good test increment.
    	TestHeightLabel:SetText(message)
    	local attempt = 12
    	repeat
    		attempt = attempt + 4
    		TestHeightWindow:SetSize(WindowWidth - ScrollbarWidth, attempt)
    		TestHeightLabel:SetSize(WindowWidth - ScrollbarWidth, attempt)
    	until attempt > 320 or not TestHeightScrollBar:IsVisible()
    --	Turbine.Shell.WriteLine("debug height: "..attempt)
    	return attempt
    end
    -------------------------------------------------------------------------------
    HalfIgnoreWindow = Turbine.UI.Window()
    HalfIgnoreWindow:SetSize(WindowWidth, WindowHeight)
    HalfIgnoreWindow:SetPosition(WindowLeft, WindowTop)
    HalfIgnoreWindow:SetVisible(true)
    HalfIgnoreWindow:SetMouseVisible(false)
    HalfIgnoreWindow:SetBackColor(Turbine.UI.Color(0.1, 0, 0, 0))
    
    HalfIgnoreListBox = Turbine.UI.ListBox()
    HalfIgnoreListBox:SetParent(HalfIgnoreWindow)
    HalfIgnoreListBox:SetMouseVisible(false)
    HalfIgnoreListBox:SetSize(WindowWidth - ScrollbarWidth, WindowHeight)
    
    HalfIgnoreScrollBar = Turbine.UI.Lotro.ScrollBar()
    HalfIgnoreScrollBar:SetParent(HalfIgnoreWindow)
    HalfIgnoreScrollBar:SetOrientation(Turbine.UI.Orientation.Vertical)
    HalfIgnoreScrollBar:SetPosition(WindowWidth - ScrollbarWidth, 0)
    HalfIgnoreScrollBar:SetSize(ScrollbarWidth, WindowHeight)
    HalfIgnoreListBox:SetVerticalScrollBar(HalfIgnoreScrollBar)
    
    function HideLabel(label)
    	label:SetForeColor(Turbine.UI.Color(0, 0, 0, 0))
    	label:SetBackColor(Turbine.UI.Color(0.2, 0, 0, 0))
    	label.MouseEnter = function(sender, args)
    		label:SetForeColor(ColorTable[label.ChatType])
    	end
    	label.MouseLeave = function(sender, args)
    		label:SetForeColor(Turbine.UI.Color(0, 0, 0, 0))
    	end
    end
    
    function ShowLabel(label)
    	label:SetForeColor(ColorTable[label.ChatType])
    	label:SetBackColor(Turbine.UI.Color(0.1, 0, 0, 0))
    	label.MouseEnter = nil
    	label.MouseLeave = nil
    end
    
    function UpdateLabel(label)  -- brute force, I don't bother checking if a label is already correctly hidden/unhidden
    	if IgnoreTable[string.match(label:GetText(), "^%d%d:%d%d %[[^%[]+%] ([^:]+): ")] then -- note the timestamp and lack of /Select tags
    --	if IgnoreTable[label.Author] then --when using alternate method mentioned below
    		HideLabel(label)
    	else
    		ShowLabel(label)
    	end
    end
    
    function UpdateAllLabels()
    	for i = 1, HalfIgnoreListBox:GetItemCount() do
    		UpdateLabel(HalfIgnoreListBox:GetItem(i))
    	end
    end
    
    function MakeLabel(message, ChatType)
    	local NewLabel = Turbine.UI.Label()
    	NewLabel:SetFont(font)
    	local date = Turbine.Engine.GetDate() -- I like timestamps.  If you don't, you'll need to change the string.match in UpdateLabel() too.
    	local line = string.format("%02d:%02d %s", date.Hour, date.Minute, message)
    	NewLabel:SetSize(WindowWidth - ScrollbarWidth, TestHeight(line))
    	NewLabel:SetText(line)
    	NewLabel.ChatType = ChatType  -- colour information tag.  I could use Get()s and Set()s, but it's not worth the effort.
    
    -- alternate method of tracking who wrote a message
    -- uses string.match now rather than later, but takes more memory
    --	id, name = string.match(message, "^%[.+%] <Select:IID:0x(%x+)>(.+)<\\Select>: ")
    --	if id and name then
    --		NewLabel.Author = name
    --	end
    	UpdateLabel(NewLabel)
    
    	HalfIgnoreListBox:AddItem(NewLabel)
    
    	local count = HalfIgnoreListBox:GetItemCount()
    	if count > 1 then
    		local PreviousItem = HalfIgnoreListBox:GetItem(count - 1)
    		if PreviousItem:GetTop() + PreviousItem:GetHeight() <= WindowHeight then
    			HalfIgnoreListBox:SetSelectedIndex(count)
    		end
    	end
    end
    
    function ProcessChat(sender, args)
    	if args.Message and ColorTable[args.ChatType] then
    		MakeLabel(string.gsub(args.Message, "\n$", ""), args.ChatType)  -- strip trailing newline
    	end
    end
    AddCallback(Turbine.Chat, "Received", ProcessChat)
    
    -- command-line processing
    CommandLine = Turbine.ShellCommand()
    CommandLine.Execute = function(sender, cmd, args)
    	local proper = string.gsub(args, "^(%l)", string.upper)  -- uppercase the first letter of names
    	if proper == "" then
    		local line = "Hidden:"
    		for k, v in pairs(IgnoreTable) do
    			line = line.." '"..k.."'"
    		end
    		Turbine.Shell.WriteLine(line)
    	elseif IgnoreTable[proper] then
    		IgnoreTable[proper] = nil
    		Turbine.Shell.WriteLine("Revealing: "..proper)
    	else
    		IgnoreTable[proper] = true
    		Turbine.Shell.WriteLine("Hiding: "..proper)
    	end
    	UpdateAllLabels()
    end
    Turbine.Shell.AddCommand("HalfIgnore", CommandLine)
    
    -- create a dummy window, and update until loaded, at which point set loaded=true and set the unload commands.
    local loaded = false
    tmpWindow = Turbine.UI.Window()
    tmpWindow.Update = function()
    	if Plugins["HalfIgnore"] ~= nil and not loaded then
    		loaded = true
    		Plugins["HalfIgnore"].Unload = function(self, sender, args)
    			RemoveCallback(Turbine.Chat, "Received", ProcessChat)
    			Turbine.Shell.RemoveCommand(CommandLine)
    			Turbine.PluginData.Save(Turbine.DataScope.Server, "HalfIgnore", IgnoreTable)
    		end
    		tmpWindow:SetWantsUpdates(false)
    		Turbine.Shell.WriteLine("HalfIgnore plugin loaded. ".._VERSION)
    	end
    end
    tmpWindow:SetWantsUpdates(true)
    Last edited by Polymnie; May 10 2012 at 10:10 AM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts