local imgui = assert(select(2, pcall(require, 'mimgui')), "Lib mimgui not found")
local encoding = require 'encoding'
local inicfg = require 'inicfg'
math.randomseed(os.time())
local new = imgui.new
local vec2 = imgui.ImVec2
encoding.default = 'CP1251'
u8 = encoding.UTF8
local menu = new.bool(false)
local watch = new.bool(true)
local divisions = { minute = new.bool(true), hour = new.bool(true) }
local digital = new.bool(true)
local pi_two = math.pi*2
local h_r_c = 0.0333333333333333
local m_r_c = 0.1666666666666667
local ex, ey = getScreenResolution()
local sx, sy, radius = ex - 140, ey / 2 + 120, new.int(120)
function msg(text)
return sampAddChatMessage("[Watch]: {FFFFFF}"..text, join_argb(255, math.random(255), math.random(255), math.random(255)))
end
imgui.OnInitialize(function()
imgui.GetIO().IniFilename = nil
local defGlyph = imgui.GetIO().Fonts.ConfigData.Data[0].GlyphRanges
imgui.GetIO().Fonts:Clear()
local config = imgui.ImFontConfig()
config.GlyphExtraSpacing.x = 0.1
config.SizePixels = 24.0
imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\arialbd.ttf', config.SizePixels, config, defGlyph)
apply_custom_style()
end)
imgui.OnFrame(function() return menu[0] end, function()
imgui.SetNextWindowPos(imgui.ImVec2(ex / 2, ey / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
if imgui.Begin(u8'Настройки часов', menu, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.AlwaysAutoResize) then
local move_text = imgui.CalcTextSize(u8'Вы можете двигать часы при помощи курсора')
imgui.SetCursorPosX(150 - move_text.x / 2)
imgui.Text(u8'Вы можете двигать часы при помощи курсора')
imgui.Separator()
imgui.SetCursorPosX(5)
if imgui.Checkbox(u8"Часы", watch) then save() end
imgui.SetCursorPosX(5)
imgui.SliderInt(u8'Размер часов', radius, 100, 300)
imgui.SetCursorPosX(5)
if imgui.Checkbox(u8"Часовые деления", divisions.hour) then save() end
if divisions.hour then
imgui.SetCursorPosX(5)
if imgui.Checkbox(u8"Минутные деления", divisions.minute) then save() end
end
imgui.SetCursorPosX(5)
if imgui.Checkbox(u8"Цифровые часы", digital) then save() end
imgui.End()
end
end)
imgui.OnFrame(function() return watch[0] end, function()
local dl = imgui.GetBackgroundDrawList()
local center = vec2(sx, sy)
dl:AddCircleFilled(center, radius[0] + 0.5, join_argb(127, rainbow(0.6)), radius[0] * 2.4)
if divisions.hour[0] then
for rot = 0, 360, 30 do dl:AddLine(center + getPointOnCircle(radius[0], rot, 360), center + getPointOnCircle(radius[0] - (radius[0] / 5), rot, 360), 0xFFFFFFFF, 2) end
if divisions.minute[0] then
for rot = 0, 360, 6 do
local cos_, sin_, broken = math.cos(math.rad(rot)), math.sin(math.rad(rot)), false
for i = 0, 360, 30 do if cos_ == math.cos(math.rad(i)) and sin_ == math.sin(math.rad(i)) then broken = true end break end
if not broken then
dl:AddLine(center + getPointOnCircle(radius[0], rot, 360), center + getPointOnCircle(radius[0] - (radius[0] / 8), rot, 360), 0xFFFFFFFF, 2)
end
end
end
end
local time = os.date("*t")
dl:AddLine(vec2(sx, sy), vec2(sx + math.cos(math.rad(time.hour / h_r_c - 90)) * (radius[0] / 2.5), sy + math.sin(math.rad(time.hour / h_r_c - 90)) * (radius[0] / 2.5)), 0xFFFFFFFF, 2)
dl:AddLine(vec2(sx, sy), vec2(sx + math.cos(math.rad(time.min / m_r_c - 90)) * (radius[0] / 1.5), sy + math.sin(math.rad(time.min / m_r_c - 90)) * (radius[0] / 1.5)), 0xFFFFFFFF, 2)
dl:AddLine(vec2(sx, sy), vec2(sx + math.cos(math.rad(time.sec / m_r_c - 90)) * (radius[0] / 1.5), sy + math.sin(math.rad(time.sec / m_r_c - 90)) * (radius[0] / 1.5)), 0xFFFFFFFF, 2)
if digital[0] then
local time_str = os.date("%H:%M")
dl:AddText(vec2(sx - imgui.CalcTextSize(time_str).x / 2 - 1, sy + radius[0] + 5), 0xFF000000, time_str)
dl:AddText(vec2(sx - imgui.CalcTextSize(time_str).x / 2 + 1, sy + radius[0] + 5), 0xFF000000, time_str)
dl:AddText(vec2(sx - imgui.CalcTextSize(time_str).x / 2, sy + radius[0] + 4), 0xFF000000, time_str)
dl:AddText(vec2(sx - imgui.CalcTextSize(time_str).x / 2, sy + radius[0] + 6), 0xFF000000, time_str)
dl:AddText(vec2(sx - imgui.CalcTextSize(time_str).x / 2, sy + radius[0] + 5), 0xFFFFFFFF, time_str)
end
if menu[0] then
local cx, cy = getCursorPos()
if cx > sx - radius[0] and cy > sy - radius[0] and cx < sx + radius[0] and cy < sy + radius[0] then
if isKeyDown(0x01) then
local cx, cy = getCursorPos()
sx, sy = cx, cy
end
end
end
end).HideCursor = true
function getPointOnCircle(cradius, point, max_points)
local a = 0 + (point / max_points) * (pi_two - 0)
return vec2(math.cos(a) * cradius, math.sin(a) * cradius)
end
function save()
local saves = inicfg.save({
main = {
watch = watch[0],
divisions_minute = divisions.minute[0],
divisions_hour = divisions.hour[0],
digital = digital[0],
posX = sx,
posY = sy}
}, 'watch.ini')
if not saves then
msg('Не удалось сохранить по не известной причине')
end
end
function main()
repeat wait(0) until isSampAvailable()
msg('Загружен')
msg('Меню настроек: /watch')
local inik = inicfg.load(nil, 'watch.ini')
if inik ~= nil then
watch[0] = inik.main.watch
divisions.minute[0] = inik.main.divisions_minute
divisions.hour[0] = inik.main.divisions_hour
digital[0] = inik.main.digital
sx = inik.main.posX
sy = inik.main.posY
else
msg('INI файл не найден, он создан автоматически')
save()
end
sampRegisterChatCommand('watch', function() menu[0] = not menu[0] end)
wait(-1)
end
function join_argb(a, r, g, b)
local argb = b
argb = bit.bor(argb, bit.lshift(g, 8))
argb = bit.bor(argb, bit.lshift(r, 16))
argb = bit.bor(argb, bit.lshift(a, 24))
return argb
end
function rainbow(speed)
local r = math.floor(math.sin(os.clock() * speed) * 127 + 128)
local g = math.floor(math.sin(os.clock() * speed + 2) * 127 + 128)
local b = math.floor(math.sin(os.clock() * speed + 4) * 127 + 128)
return r, g, b
end
function apply_custom_style()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
style.WindowRounding = 2.0
style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
style.ChildRounding = 2.0
style.FrameRounding = 2.0
style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
style.ScrollbarSize = 13.0
style.ScrollbarRounding = 0
style.GrabMinSize = 8.0
style.GrabRounding = 1.0
colors[clr.FrameBg] = ImVec4(0.16, 0.29, 0.48, 0.54)
colors[clr.FrameBgHovered] = ImVec4(0.26, 0.59, 0.98, 0.40)
colors[clr.FrameBgActive] = ImVec4(0.26, 0.59, 0.98, 0.67)
colors[clr.TitleBg] = ImVec4(0.04, 0.04, 0.04, 1.00)
colors[clr.TitleBgActive] = ImVec4(0.16, 0.29, 0.48, 1.00)
colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
colors[clr.CheckMark] = ImVec4(0.26, 0.59, 0.98, 1.00)
colors[clr.SliderGrab] = ImVec4(0.24, 0.52, 0.88, 1.00)
colors[clr.SliderGrabActive] = ImVec4(0.26, 0.59, 0.98, 1.00)
colors[clr.Button] = ImVec4(0.26, 0.59, 0.98, 0.40)
colors[clr.ButtonHovered] = ImVec4(0.26, 0.59, 0.98, 1.00)
colors[clr.ButtonActive] = ImVec4(0.06, 0.53, 0.98, 1.00)
colors[clr.Header] = ImVec4(0.26, 0.59, 0.98, 0.31)
colors[clr.HeaderHovered] = ImVec4(0.26, 0.59, 0.98, 0.80)
colors[clr.HeaderActive] = ImVec4(0.26, 0.59, 0.98, 1.00)
colors[clr.Separator] = colors[clr.Border]
colors[clr.SeparatorHovered] = ImVec4(0.26, 0.59, 0.98, 0.78)
colors[clr.SeparatorActive] = ImVec4(0.26, 0.59, 0.98, 1.00)
colors[clr.ResizeGrip] = ImVec4(0.26, 0.59, 0.98, 0.25)
colors[clr.ResizeGripHovered] = ImVec4(0.26, 0.59, 0.98, 0.67)
colors[clr.ResizeGripActive] = ImVec4(0.26, 0.59, 0.98, 0.95)
colors[clr.TextSelectedBg] = ImVec4(0.26, 0.59, 0.98, 0.35)
colors[clr.Text] = ImVec4(1.00, 1.00, 1.00, 1.00)
colors[clr.TextDisabled] = ImVec4(0.50, 0.50, 0.50, 1.00)
colors[clr.WindowBg] = ImVec4(0.06, 0.06, 0.06, 0.94)
colors[clr.ChildBg] = ImVec4(1.00, 1.00, 1.00, 0.00)
colors[clr.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94)
--colors[clr.ComboBg] = colors[clr.PopupBg]
colors[clr.Border] = ImVec4(0.43, 0.43, 0.50, 0.50)
colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
colors[clr.MenuBarBg] = ImVec4(0.14, 0.14, 0.14, 1.00)
colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.53)
colors[clr.ScrollbarGrab] = ImVec4(0.31, 0.31, 0.31, 1.00)
colors[clr.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
colors[clr.ScrollbarGrabActive] = ImVec4(0.51, 0.51, 0.51, 1.00)
--colors[clr.CloseButton] = ImVec4(0.41, 0.41, 0.41, 0.50)
--colors[clr.CloseButtonHovered] = ImVec4(0.98, 0.39, 0.36, 1.00)
--colors[clr.CloseButtonActive] = ImVec4(0.98, 0.39, 0.36, 1.00)
colors[clr.PlotLines] = ImVec4(0.61, 0.61, 0.61, 1.00)
colors[clr.PlotLinesHovered] = ImVec4(1.00, 0.43, 0.35, 1.00)
colors[clr.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
--colors[clr.ModalWindowDarkening] = ImVec4(0.80, 0.80, 0.80, 0.35)
end