YATCO - Yet Another Tabbed Chat Option. This time it blinks

Share your scripts and packages with other Mudlet users.
User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by demonnic »

This has been rewritten. New one can be found here: CLICK

So, I was working with someone in #mudlet-help today who wanted chat tabs, top-right corner, and blinking tabs when new things were sent to the miniconsoles. Now, I've not begun using Geyser yet, so this doesn't make use of that. And the majority of the code is something Oneymus from the IRC channel came up with, I've just modified it a bit to make it blinky. Anyhow, the code (which you can just copypaste into a script object) for those interested:
Code: [show] | [select all] lua
ChatStuff = ChatStuff or {}
ChatStuff.fontSize = ChatStuff.fontSize or 9
ChatStuff.fontWidth, ChatStuff.fontHeight = calcFontSize(ChatStuff.fontSize)
mainWidth, mainHeight = getMainWindowSize()
ChatStuff.width = 400
ChatStuff.height = ChatStuff.fontHeight * 35
ChatStuff.wordwrap = (ChatStuff.width / ChatStuff.fontWidth) - 1
ChatStuff.blinkyTimers = ChatStuff.blinkyTimers or {}
ChatStuff.blinkyColor = ChatStuff.blinkyColor or {}

function ChatStuff.posY()
  return 25 --because the tabs are 25 high
end

function ChatStuff.posX()
  return mainWidth - ChatStuff.width - 15 --the -15 is to keep it from covering the scroll bar
end

function ChatStuff.append(chat)  
  appendBuffer(string.format("chat%s", chat))
  local tab = string.format("tab%s", chat)
  if ChatStuff.blinkyTimers[chat] or ChatStuff.currentTab == chat or chat == "All" then 
    return true
  else
    ChatStuff.blinkyTimers[chat] = tempTimer(0.5, string.format([[ChatStuff.blink("%s")]], chat))
    setBackgroundColor(tab, 100, 100, 100, 125)
    ChatStuff.blinkyColor[chat] = 1
  end
  return true
end

function ChatStuff.blink(chat)
  local tab = string.format("tab%s", chat)
  if ChatStuff.blinkyColor[chat] == 1 then
    setBackgroundColor(tab, 0, 0, 0, 0)
    ChatStuff.blinkyColor[chat] = 0
  else
    setBackgroundColor(tab, 100, 100, 100, 125)
    ChatStuff.blinkyColor[chat] = 1
  end
  ChatStuff.blinkyTimers[chat] = tempTimer(0.5, string.format([[ChatStuff.blink("%s")]], chat))
end

chatTable = {
        "All",
        "City",
        "Guild",
        "Tells",
        "Battle",
        "Market",
        "Misc",
        }
 
ChatStuff.tabWidth, ChatStuff.tabHeight = math.floor( ChatStuff.width / #chatTable  ), 25
ChatStuff.tabPosX, ChatStuff.tabPosY = ChatStuff.posX(), ChatStuff.posY() - 25
 
-- Functions
function ChatStuffCreate()
  local startX = ChatStuff.tabPosX
  for _,v in ipairs( chatTable ) do
    local tab = "tab" .. v
    createLabel( tab, startX, ChatStuff.tabPosY, ChatStuff.tabWidth, ChatStuff.tabHeight, 0 )
    resizeWindow( tab, ChatStuff.tabWidth, ChatStuff.tabHeight )
    setLabelClickCallback( tab, "switchchat", v )
    echo( tab, [[<center><font color="white">]] .. v .. [[</font></center></b></p>]] )
    moveWindow( tab, startX, ChatStuff.tabPosY )
    startX = startX + ChatStuff.tabWidth

    local chat = "chat" .. v
    createMiniConsole( chat, ChatStuff.posX(), ChatStuff.posY(), ChatStuff.width, ChatStuff.height )
    resizeWindow( chat, ChatStuff.width, ChatStuff.height )
    setWindowWrap( chat, ChatStuff.wordwrap )
    setMiniConsoleFontSize( chat, ChatStuff.fontSize )
    setBackgroundColor( chat, 0, 0, 0, 0 )
    moveWindow( chat, ChatStuff.posX(), ChatStuff.posY() )
    hideWindow( chat )
  end
  ChatStuff.currentTab = "none"
  switchchat( "All" )
end
 
function switchchat ( chat )
  local o_c = "chat" .. ChatStuff.currentTab
  local o_t = "tab" .. ChatStuff.currentTab
  local n_c = "chat" .. chat
  local n_t = "tab" .. chat
  if ChatStuff.currentTab ~= chat then
    if ChatStuff.blinkyTimers[chat] then
      killTimer(ChatStuff.blinkyTimers[chat])
      ChatStuff.blinkyTimers[chat] = nil
      ChatStuff.blinkyColor[chat] = nil
    end
    hideWindow( o_c )
    showWindow( n_c )
    ChatStuff.currentTab = chat
    setBackgroundColor( o_t, 0, 0, 0, 0 )
    setBackgroundColor( n_t, 100, 100, 100, 125 )
  end

end

function ChatStuffResize()
  ChatStuff.fontWidth, ChatStuff.fontHeight = calcFontSize(ChatStuff.fontSize)
  mainWidth, mainHeight = getMainWindowSize()
  ChatStuff.height = ChatStuff.fontHeight * 35
  ChatStuff.wordwrap = (ChatStuff.width / ChatStuff.fontWidth) - 1
  ChatStuff.tabWidth, ChatStuff.tabHeight = math.floor( ChatStuff.width / #chatTable), 25
  ChatStuff.tabPosX, ChatStuff.tabPosY = ChatStuff.posX(), ChatStuff.posY() - 25
  ChatStuffCreate()
end 

if not ChatStuff.initialized then
	ChatStuffCreate()
	ChatStuff.initialized = true
end
To use it, you create a trigger for the chat line, and in the script put the following:
Code: [show] | [select all] lua
selectString(line,1)
copy()
ChatStuff.append("All")
ChatStuff.append("Guild")
deselect()
Where "Guild" can be any one of the tabs you have setup. Now, you can setup differing numbers of tabs, and change their names, by editing the chatTable declaration starting on line 44. Remove the ones you don't want, add the ones you do. If you do it after it's created them, you may need to restart Mudlet to keep it from looking funky.

If you want to change where it's positioned, edit the return value of the functions ChatStuff.posX() and ChatStuff.posY() . If you want to change the height, it's specified on line 6 and currently is set for 35 lines tall. Line 5 has the width, currently hardcoded to 400.
If you want to delete the line from the main window, throw a deleteLine() at the end of the trigger's script.

That should cover all of it. Enjoy


edited: I missed 1 line in the trigger code which was kind of important.

syrik
Posts: 90
Joined: Sat Jun 26, 2010 9:57 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by syrik »

What would the trigger look like?

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by demonnic »

I don't know what the chats in your MUD look like, makes it difficult for me to say. In the MUD I play, I'd use a begin of line substring to capture the various channels, as they're clearly marked:

(Shadowdancers):
(Glomdoring):

etc.

If you provide me with what the chats from your MUD look like, I could pretty quickly put together a small trigger package for it, I reckon.

syrik
Posts: 90
Joined: Sat Jun 26, 2010 9:57 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by syrik »

its just like: bob barrates 'hello'
bob chats 'hello'
bob tells you 'hello'
bob bellows 'hello'
bob shouts 'hello'

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by demonnic »

perl regex triggers for those, then... not enough to pin a reliable substring trigger on, I don't think... in which case

^\w+ chats '.*'$
^\w+ tells you '.*'$

etc. Then the script pieces mentioned in my first post should take the lines and push them to the appropriate chat window

syrik
Posts: 90
Joined: Sat Jun 26, 2010 9:57 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by syrik »

ok, I have this:
^\w+ chats '.*'$ (perl regex)

and then in the script part under the trigger:
selectString(line,1)
ChatStuff.append("All")
ChatStuff.append("chat")
deselect()

The tab blinks, but nothing is going into the window.

User avatar
Omit
Posts: 190
Joined: Sun Aug 01, 2010 10:54 pm
Location: Middle Earth
Contact:

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by Omit »

The tab blinks, but nothing is going into the window.
I had the same experiance last night... I thought I was just tired and was missing something.... (maybe that's all it was I will have to test again)

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by demonnic »

I tested this as working myself, and had it working with the guy I wrote it for as well, so far as I know..

also, you'll want to make sure the case matches the way you've put it in the table declaration

If the table has "chat", as one of the line, then the code should work... otherwise, you'll need "Chat" .


What MUD are you playing? I'll have some time tonight, I think, and could log in and make it specific to that MUD.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by demonnic »

If you have any errors in the error console, that would help me figure out what might've gone wrong as well.

Don't try the debug window though, the blinking makes it kind of a pain. Since it changes state every half second.

syrik
Posts: 90
Joined: Sat Jun 26, 2010 9:57 pm

Re: YATCO - Yet Another Tabbed Chat Option. This time it blinks

Post by syrik »

I play wotmud (www.wotmud.org 2222) This looks really nice, so really hope you can get it working!

Post Reply