Advertisement
Guest User

Demonnic Tabbed Chat Code

a guest
Apr 4th, 2020
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.38 KB | None | 0 0
  1. --[[
  2. If the label callbacks ever decide to start taking a function which is part of a table, 0then this will change.
  3. Or if it's modified to take actual functions. Anonymouse function clickcallback would be awfully nice.
  4. ]]
  5.  
  6. function demonnicChatSwitch(chat)
  7.   local r = demonnic.chat.config.inactiveColors.r
  8.   local g = demonnic.chat.config.inactiveColors.g
  9.   local b = demonnic.chat.config.inactiveColors.b
  10.   local newr = demonnic.chat.config.activeColors.r
  11.   local newg = demonnic.chat.config.activeColors.g
  12.   local newb = demonnic.chat.config.activeColors.b
  13.   local oldchat = demonnic.chat.currentTab
  14.   if demonnic.chat.currentTab ~= chat then
  15.     demonnic.chat.windows[oldchat]:hide()
  16.     demonnic.chat.tabs[oldchat]:setColor(r,g,b)
  17.     demonnic.chat.tabs[oldchat]:echo(oldchat, demonnic.chat.config.inactiveTabText, "c")
  18.     if demonnic.chat.config.blink and demonnic.chat.tabsToBlink[chat] then
  19.       demonnic.chat.tabsToBlink[chat] = nil
  20.     end
  21.     if demonnic.chat.config.blink and chat == demonnic.chat.config.Alltab then
  22.       demonnic.chat.tabsToBlink = {}
  23.     end
  24.   end
  25.   demonnic.chat.tabs[chat]:setColor(newr,newg,newb)
  26.   demonnic.chat.tabs[chat]:echo(chat, demonnic.chat.config.activeTabText, "c")
  27.   demonnic.chat.windows[chat]:show()
  28.   demonnic.chat.currentTab = chat  
  29. end
  30.  
  31. function demonnic.chat:resetUI()
  32.   demonnic.chat.container = demonnic.chat.useContainer or Geyser.Container:new(demonnic.chat[demonnic.chat.config.location]())
  33.   demonnic.chat.tabBox = Geyser.HBox:new({
  34.     x=0,
  35.     y=0,
  36.     width = "100%",
  37.     height = "25px",
  38.     name = "DemonChatTabs",
  39.   },demonnic.chat.container)
  40.  
  41. end
  42.  
  43. function demonnic.chat:create()
  44.   --reset the UI
  45.   demonnic.chat:resetUI()
  46.   --Set some variables locally to increase readability
  47.   local r = demonnic.chat.config.inactiveColors.r
  48.   local g = demonnic.chat.config.inactiveColors.g
  49.   local b = demonnic.chat.config.inactiveColors.b
  50.   local winr = demonnic.chat.config.windowColors.r
  51.   local wing = demonnic.chat.config.windowColors.g
  52.   local winb = demonnic.chat.config.windowColors.b
  53.  
  54.   --iterate the table of channels and create some windows and tabs
  55.   for i,tab in ipairs(demonnic.chat.config.channels) do
  56.     demonnic.chat.tabs[tab] = Geyser.Label:new({
  57.       name=string.format("tab%s", tab),
  58.     }, demonnic.chat.tabBox)
  59.     demonnic.chat.tabs[tab]:echo(tab, demonnic.chat.config.inactiveTabText, "c")
  60.     demonnic.chat.tabs[tab]:setColor(r,g,b)
  61.     demonnic.chat.tabs[tab]:setClickCallback("demonnicChatSwitch", tab)
  62.     demonnic.chat.windows[tab] = Geyser.MiniConsole:new({
  63. --      fontSize = demonnic.chat.config.fontSize,
  64.       x = 0,
  65.       y = 25,
  66.       height = "100%",
  67.       width = "100%",
  68.       name = string.format("win%s", tab),
  69.     }, demonnic.chat.container)
  70.     demonnic.chat.windows[tab]:setFontSize(demonnic.chat.config.fontSize)
  71.     demonnic.chat.windows[tab]:setColor(winr,wing,winb)
  72.     demonnic.chat.windows[tab]:setWrap(demonnic.chat.config.width)
  73.     demonnic.chat.windows[tab]:hide()
  74.   end
  75.   if demonnic.chat.config.Maptab and demonnic.chat.config.Maptab ~= "" then
  76.     demonnic.chat.mapWindow = Geyser.Mapper:new({
  77.       x = 0,
  78.       y = 0,
  79.       height = "100%",
  80.       width = "100%",
  81.     }, demonnic.chat.windows[demonnic.chat.config.Maptab])
  82.     demonnic.chat.windows[demonnic.chat.config.Maptab]:hide()
  83.   end
  84.   local showme = demonnic.chat.config.Alltab or demonnic.chat.config.channels[1]
  85.   demonnicChatSwitch(showme)
  86.   --start the blink timers, if enabled
  87.   if demonnic.chat.config.blink and not demonnic.chat.blinkTimerOn then
  88.     demonnic.chat:blink()
  89.   end
  90. end
  91.  
  92. function demonnic.chat:append(chat)
  93.   local r = demonnic.chat.config.windowColors.r
  94.   local g = demonnic.chat.config.windowColors.g
  95.   local b = demonnic.chat.config.windowColors.b
  96.   selectCurrentLine()
  97.   local ofr,ofg,ofb = getFgColor()
  98.   local obr,obg,obb = getBgColor()
  99.   if demonnic.chat.config.preserveBackground then
  100.     setBgColor(r,g,b)
  101.   end
  102.   copy()
  103.   if demonnic.chat.config.timestamp then
  104.     local timestamp = getTime(true, demonnic.chat.config.timestamp)
  105.     local tsfg = {}
  106.     local tsbg = {}
  107.     local colorLeader = ""
  108.     if demonnic.chat.config.timestampCustomColor then
  109.       if type(demonnic.chat.config.timestampFG) == "string" then
  110.         tsfg = color_table[demonnic.chat.config.timestampFG]
  111.       else
  112.         tsfg = demonnic.chat.config.timestampFG
  113.       end
  114.       if type(demonnic.chat.config.timestampBG) == "string" then
  115.         tsbg = color_table[demonnic.chat.config.timestampBG]
  116.       else
  117.         tsbg = demonnic.chat.config.timestampBG
  118.       end
  119.       colorLeader = string.format("<%s,%s,%s:%s,%s,%s>",tsfg[1],tsfg[2],tsfg[3],tsbg[1],tsbg[2],tsbg[3])
  120.     else
  121.       colorLeader = string.format("<%s,%s,%s:%s,%s,%s>",ofr,ofg,ofb,obr,obg,obb)
  122.     end
  123.     local fullstamp = string.format("%s%s",colorLeader,timestamp)
  124.       demonnic.chat.windows[chat]:decho(fullstamp)
  125.       demonnic.chat.windows[chat]:echo(" ")
  126.       if demonnic.chat.config.Alltab then
  127.         demonnic.chat.windows[demonnic.chat.config.Alltab]:decho(fullstamp)
  128.         demonnic.chat.windows[demonnic.chat.config.Alltab]:echo(" ")
  129.       end
  130.   end
  131.   demonnic.chat.windows[chat]:append()
  132.   if ((demonnic.chat.config.gagChat[chat] ~= nil and demonic.chat.config.gagChat[chat]) or
  133.       (demonnic.chat.config.gagChat[chat] == nil and demonic.chat.config.gagChat)) then
  134.     deleteLine()
  135.     tempLineTrigger(1,1, [[if isPrompt() then deleteLine() end]])
  136.   end
  137.   if demonnic.chat.config.Alltab then appendBuffer(string.format("win%s", demonnic.chat.config.Alltab)) end
  138.   if demonnic.chat.config.blink and chat ~= demonnic.chat.currentTab then
  139.     if (demonnic.chat.config.Alltab == demonnic.chat.currentTab) and not demonnic.chat.config.blinkOnAll then
  140.       return
  141.     else
  142.       demonnic.chat.tabsToBlink[chat] = true
  143.     end
  144.   end
  145. end
  146.  
  147.  
  148.  
  149. function demonnic.chat:blink()
  150.   if demonnic.chat.blinkID then killTimer(demonnic.chat.blinkID) end
  151.   if not demonnic.chat.config.blink then
  152.     demonnic.chat.blinkTimerOn = false
  153.     return
  154.   end
  155.   if not demonnic.chat.container.hidden then
  156.     for tab,_ in pairs(demonnic.chat.tabsToBlink) do
  157.       demonnic.chat.tabs[tab]:flash()
  158.     end
  159.   end
  160.   demonnic.chat.blinkID = tempTimer(demonnic.chat.config.blinkTime, function () demonnic.chat:blink() end)
  161. end
  162.  
  163. function demonnic.chat:topright()
  164.   return {
  165.     fontSize = demonnic.chat.config.fontSize,
  166.     x=string.format("-%sc",demonnic.chat.config.width + 2),
  167.     y=0,
  168.     width="-15px",
  169.     height=string.format("%ic", demonnic.chat.config.lines + 2),
  170.   }
  171. end
  172.  
  173. function demonnic.chat:topleft()
  174.   return {
  175.     fontSize = demonnic.chat.config.fontSize,
  176.     x=0,
  177.     y=0,
  178.     width=string.format("%sc",demonnic.chat.config.width),
  179.     height=string.format("%ic", demonnic.chat.config.lines + 2),
  180.   }
  181. end
  182.  
  183. function demonnic.chat:bottomright()
  184.   return {
  185.     fontSize = demonnic.chat.config.fontSize,
  186.     x=string.format("-%sc",demonnic.chat.config.width + 2),
  187.     y=string.format("-%sc",demonnic.chat.config.lines + 2),
  188.     width="-15px",
  189.     height=string.format("%ic", demonnic.chat.config.lines + 2),
  190.   }
  191. end
  192.  
  193. function demonnic.chat:bottomleft()
  194.   return {
  195.     fontSize = demonnic.chat.config.fontSize,
  196.     x=0,
  197.     y=string.format("-%sc",demonnic.chat.config.lines + 2),
  198.     width=string.format("%sc",demonnic.chat.config.width),
  199.     height=string.format("%ic", demonnic.chat.config.lines + 2),
  200.   }
  201. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement