Skip to content

Chat Window

Hello,

So I found some coding for a chat window, decided to try it out and realized it needs a bit of work. However I can't seem to get the tabs to go away. I was hoping someone might explain what I am doing wrong.

local font_size = 8
local fontx,fonty = calcFontSize(font_size)

local chatWidth = 650
local chatHeight = 335

local tabWidth = 50
local tabHeight = 28

local chatWrap = math.floor((shield.settings.ui.chatwidth - tabWidth) / fontx)

chatCurrent = ""

cgag = {}
cgag.chatAll = cgag.chatAll or false
cgag.chatCity = cgag.chatCity or false
cgag.chatTells = cgag.chatTells or false
cgag.chatGuild = cgag.chatGuild or false
cgag.chatWeb = cgag.chatRing or false
cgag.chatShouts = cgag.chatShouts or false
cgag.chatMarket = cgag.chatMarket or false
cgag.chatSay = cgag.chatSay or false
cgag.chatClans = cgagChatClans or false
cgag.chatStatus = cgagChatClans or false

function initChat()
    chat_window = Geyser.Container:new({
        name = "chat_window",
        x = (-70 - chatWidth), y = 0,
        width = chatWidth, height = chatHeight,
    }, layout)

    local tabs = { "All", "Say", "Tells", "City", "Ring", "Guild", "Market", "Shouts", "Clans", "Status" }

    chatlabels = chatlabels or {}

    chat_label_container = Geyser.Container:new({
        name = "chat_label_container",
        x = 0, y = 0,
        width = tabWidth, height = chatHeight,
    }, chat_window )

    for i,v in ipairs(tabs) do
        local tabname, posX, posY

        tabname = "button" .. string.title(v)
        posX = 630
        posY = (i - 1) * tabHeight

        chatlabels[tabname] = Geyser.Label:new({ name = tabname }, chat_label_container)
        chatlabels[tabname]:move( posX .. "px", posY .. "px" )
        chatlabels[tabname]:resize(tabWidth, tabHeight)
        chatlabels[tabname]:setColor( 0,155,0, 255 )
        chatlabels[tabname]:setFontSize(9)
        chatlabels[tabname]:echo("<center><font color='black'>" .. v .. "</font></center>")
        chatlabels[tabname]:setClickCallback("chatSwapTab", "chat" .. v )
    end

    chatconsoles = chatconsoles or {}

    guiChatConsoles = Geyser.Container:new({ name = "guiChatLabels" }, chat_label_container )
    guiChatConsoles:move(tabWidth, 0)
    guiChatConsoles:resize(chatWidth, chatHeight)

    for i,v in ipairs(tabs) do
        local tabname = "chat" .. string.title(v)

        chatconsoles[tabname] = Geyser.MiniConsole:new({ name = tabname, }, guiChatConsoles )
        chatconsoles[tabname]:move(0,0)
        chatconsoles[tabname]:resize(chatWidth - tabWidth, chatHeight)
        chatconsoles[tabname]:setColor(0,0,0)
        chatconsoles[tabname]:setFontSize(font_size)
        chatconsoles[tabname]:setWrap(chatWrap)
        chatconsoles[tabname]:hide()
    end

    chatconsoles.chatAll:show()
    chatlabels.buttonAll:setColor(0,255,0, 255 )
    chatCurrent = "chatAll"
end

function chatSwapTab(channel)
    local str
    if chatCurrent == "none" then
        chatconsoles[channel]:show()
        str = string.gsub(channel, "chat", "button")
        chatlabels[str]:setColor( 0,255,0, 255 )
        chatCurrent = channel
    elseif chatCurrent == channel then
        chatconsoles[channel]:hide()
        str = string.gsub(chatCurrent, "chat", "button")
        chatlabels[str]:setColor( 0,155,0, 255 )
        chatCurrent = "none"
    else
        chatconsoles[chatCurrent]:hide()
        str = string.gsub(chatCurrent, "chat", "button")
        chatlabels[str]:setColor( 0,155,0, 255 )

        chatconsoles[channel]:show()
        str = string.gsub(channel, "chat", "button")
        chatlabels[str]:setColor( 0,255,0, 255 )
        chatCurrent = channel
    end
end

function echoChat(channel)
    local str = "chat" .. string.title(channel) or "chatAll"
    selectString(line,1)
    local er,eg,eb = getBgColor()
    local tflag = false
    if er == 0 and eg == 0 and eb == 0 then
        setBgColor(25,25,25)
        tflag = true
    end
    copy()
    appendBuffer("chatAll")
    if str ~= "chatAll" then appendBuffer(str) end
    if tflag then
        setBgColor(0,0,0)
    end
    if cgag[str] then deleteFull() end
    str = "button" .. string.title(channel)
    chatlabels[str]:flash(0.5)
end

initChat()

I went and took out the tabwidth and tabheight...I took out all references to tab...but it doesn't seem to register that portion of the code being gone. If anyone can help me clean this up, I would greatly appreciate it. I basically just want a single window that captures all my tells, says, and other channels so I don't keep missing things.

Thanks

Comments

  • Is that lua/Mudlet? I have a link for a chatwindow that works pretty well, just takes a few triggers to get going. Unfortuneately im not skilled enough with lua to troubleshoot what you got there. But if you want the link-http://forums.mudlet.org/viewtopic.php?f=6&t=3163
  • IniarIniar Australia
    Here's an interesting thing about code vs UI. If the code doesn't suck and you have enough resources to spare, recoding is a waste of your time. See:

    chatlabels[tabname]:resize(tabWidth, tabHeight)

    This line tells the tabs what -size- to be. What about a size of 0? Sure! But see how the author let's you set the height for -all- the tabs in one swift move:

    local tabHeight = 28

    Becomes

    local tabHeight = 0

    Hope that helps.
    wit beyond measure is a Sidhe's greatest treasure
Sign In or Register to comment.