local ev = require "samp.events"
local imgui = require 'mimgui'
local faicons = require('fAwesome6')
local ffi = require("ffi")
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
require "lib.moonloader"
local renderWindow, new = imgui.new.bool(false), imgui.new
local chatlog = {}
local MAX_CHATLOG_LENGTH = 100
local ui = {
render = false,
}
function main()
if not isSampfuncsLoaded() or not isSampLoaded() then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("chatlog", function()
renderWindow[0] = not renderWindow[0]
end)
while true do
wait(0)
end
end
imgui.OnInitialize(function ()
imgui.GetIO().IniFilename = nil
local config = imgui.ImFontConfig()
config.MergeMode = true
config.PixelSnapH = true
iconRanges = imgui.new.ImWchar[3](faicons.min_range, faicons.max_range, 0)
imgui.GetIO().Fonts:AddFontFromMemoryCompressedBase85TTF(faicons.get_font_data_base85('solid'), 14, config, iconRanges)
end)
imgui.OnFrame(
function() return renderWindow[0] end,
function()
local resX, resY = getScreenResolution()
local sizeX, sizeY = 590, 405
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2, resY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
imgui.Begin(u8("Chatlog"), renderWindow, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize)
imgui.BeginTabBar("tabbar")
if imgui.BeginTabItem(u8("Чатлог")) then
imgui.Spacing()
imgui.Spacing()
if imgui.BeginChild("chatlog", imgui.ImVec2(-1, -1), true) then
imgui.Columns(2)
for k, msg in ipairs(chatlog) do
imgui.Separator()
imgui.SetColumnWidth(-1, imgui.GetWindowWidth() * 0.9)
imgui.TextWrapped(u8(msg))
imgui.Spacing()
imgui.NextColumn()
imgui.SetCursorPosX(imgui.GetCursorPosX() + 10)
if imgui.Button(faicons("copy") .. "##" .. k) then
setClipboardText(u8(msg))
end
imgui.NextColumn()
end
imgui.Columns(1)
imgui.EndChild()
end
imgui.EndTabItem()
end
imgui.EndTabBar()
imgui.End()
end
)
function ev.onServerMessage(c, text)
if #chatlog == MAX_CHATLOG_LENGTH then
table.remove(chatlog, MAX_CHATLOG_LENGTH)
end
table.insert(chatlog, 1, bit.tohex(c) .. ":" .. text)
end