require('lib.moonloader')
require('encoding').default = 'CP1251'
local u8 = require('encoding').UTF8
local imgui = require 'mimgui'
local inicfg = require 'inicfg'
local ffi = require 'ffi'
local new = imgui.new
local str = ffi.string
local settings = inicfg.load({
setting = {
nickname = '',
keep_window_open = false,
show_time = true,
show_id = true,
show_passport = true,
show_jobprogress = true,
show_members = true,
show_stats = true
}}, 'FrapsHelper.ini')
local mainWindowState = imgui.new.bool(false)
local buttonsWindowState = imgui.new.bool(false)
local nicknameInput = new.char[256](u8(settings.setting.nickname))
local keepWindowOpenCheckbox = new.bool(settings.setting.keep_window_open)
local showTimeCheckbox = new.bool(settings.setting.show_time)
local showIdCheckbox = new.bool(settings.setting.show_id)
local showPassportCheckbox = new.bool(settings.setting.show_passport)
local showJobprogressCheckbox = new.bool(settings.setting.show_jobprogress)
local showMembersCheckbox = new.bool(settings.setting.show_members)
local showStatsCheckbox = new.bool(settings.setting.show_stats)
function imgui.ColSeparator(hex, trans)
local r, g, b = tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
local a = trans and math.min(math.max(trans, 0), 100) or 100
imgui.PushStyleColor(imgui.Col.Separator, imgui.ImVec4(r/255, g/255, b/255, a/100))
imgui.Separator()
imgui.PopStyleColor(1)
end
function imgui.ColoredButton(text, hex, trans, size)
local r, g, b = tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
local a = trans and math.min(math.max(trans, 0), 100) or 60
imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(r/255, g/255, b/255, a/100))
imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(r/255, g/255, b/255, a/100))
imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(r/255, g/255, b/255, a/100))
local button = imgui.Button(text, size)
imgui.PopStyleColor(3)
return button
end
imgui.OnFrame(function() return mainWindowState[0] end, function()
imgui.SetNextWindowPos(imgui.ImVec2(500, 500), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(300, 300))
imgui.Begin('Fraps Helper Settings', mainWindowState)
imgui.Text(u8'Ваш ник:')
if imgui.InputText('##Nickname', nicknameInput, 256) then
settings.setting.nickname = u8:decode(str(nicknameInput))
inicfg.save(settings, 'FrapsHelper.ini')
end
imgui.SameLine()
if imgui.Button(u8'Очистить') then
imgui.StrCopy(nicknameInput, '')
settings.setting.nickname = ''
inicfg.save(settings, 'FrapsHelper.ini')
end
if imgui.Checkbox(u8'Сохранять окно кнопок открытым', keepWindowOpenCheckbox) then
settings.setting.keep_window_open = keepWindowOpenCheckbox[0]
inicfg.save(settings, 'FrapsHelper.ini')
end
imgui.Separator()
imgui.Text(u8'Показать/скрыть кнопки:')
if imgui.Checkbox(u8'Time', showTimeCheckbox) then
settings.setting.show_time = showTimeCheckbox[0]
inicfg.save(settings, 'FrapsHelper.ini')
end
if imgui.Checkbox(u8'ID', showIdCheckbox) then
settings.setting.show_id = showIdCheckbox[0]
inicfg.save(settings, 'FrapsHelper.ini')
end
if imgui.Checkbox(u8'Passport', showPassportCheckbox) then
settings.setting.show_passport = showPassportCheckbox[0]
inicfg.save(settings, 'FrapsHelper.ini')
end
if imgui.Checkbox(u8'Jobprogress', showJobprogressCheckbox) then
settings.setting.show_jobprogress = showJobprogressCheckbox[0]
inicfg.save(settings, 'FrapsHelper.ini')
end
if imgui.Checkbox(u8'Members', showMembersCheckbox) then
settings.setting.show_members = showMembersCheckbox[0]
inicfg.save(settings, 'FrapsHelper.ini')
end
if imgui.Checkbox(u8'Stats', showStatsCheckbox) then
settings.setting.show_stats = showStatsCheckbox[0]
inicfg.save(settings, 'FrapsHelper.ini')
end
imgui.End()
end)
imgui.OnFrame(function() return buttonsWindowState[0] end, function()
local displaySize = imgui.GetIO().DisplaySize
imgui.SetNextWindowPos(imgui.ImVec2(displaySize.x / 8.5, displaySize.y / 2), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(300, 400))
imgui.Begin('Fraps Helper Buttons', buttonsWindowState, imgui.WindowFlags.NoDecoration)
if imgui.ColoredButton(u8'Настройки', 'FFA500', 70, imgui.ImVec2(280, 30)) then
mainWindowState[0] = not mainWindowState[0]
end
imgui.ColSeparator('7BFF00', 100)
imgui.TextColored(imgui.ImVec4(1, 0, 0, 1), u8'TG Author: @Diego_skuf')
imgui.ColSeparator('7BFF00', 100)
if showTimeCheckbox[0] and imgui.ColoredButton(u8'/time', '80FF00', 50, imgui.ImVec2(150, 50)) then
sampSendChat("/time")
end
imgui.SameLine()
if showIdCheckbox[0] and imgui.ColoredButton(u8"/id", "80FF00", 50, imgui.ImVec2(150, 50)) then
local nickname = u8:decode(str(nicknameInput))
if nickname and nickname ~= '' then
sampSendChat("/id " .. nickname)
else
sampSendChat("/id " .. select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
end
end
imgui.ColSeparator('7BFF00', 100)
if showPassportCheckbox[0] and imgui.ColoredButton(u8"Passport My", '80FF00', 50, imgui.ImVec2(150, 50)) then
local nickname = u8:decode(str(nicknameInput))
if nickname and nickname ~= '' then
sampSendChat("/showpass " .. nickname)
else
sampSendChat("/showpass")
end
end
imgui.SameLine()
if showJobprogressCheckbox[0] and imgui.ColoredButton(u8"Успеваемость", '80FF00', 50, imgui.ImVec2(150, 50)) then
sampSendChat("/jobprogress")
end
imgui.ColSeparator('7BFF00', 100)
if showMembersCheckbox[0] and imgui.ColoredButton(u8"Мемберс", '80FF00', 50, imgui.ImVec2(150, 50)) then
sampSendChat("/members")
end
imgui.SameLine()
if showStatsCheckbox[0] and imgui.ColoredButton(u8"Статс", '80FF00', 50, imgui.ImVec2(150, 50)) then
sampSendChat("/stats")
end
imgui.ColSeparator('7BFF00', 100)
imgui.End()
end)
function main()
sampRegisterChatCommand('fraps', function()
mainWindowState[0] = not mainWindowState[0]
end)
sampRegisterChatCommand('frapsbuttons', function()
buttonsWindowState[0] = not buttonsWindowState[0]
end)
if settings.setting.keep_window_open then
buttonsWindowState[0] = true
end
while true do
wait(0)
end
end