Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local imgui = require("imgui")
- local encoding = require("encoding")
- local u8 = encoding.UTF8
- local key = require 'vkeys'
- encoding.default = "CP1251"
- local inicfg = require 'inicfg'
- local test = 1
- local mainIni = inicfg.load({
- settings =
- {
- auto_fuel = true,
- auto_load = true,
- tag_use = true,
- auto_message = true,
- stats = true,
- heal_car = true,
- },
- main =
- {
- tag = "ув",
- norm = 5000,
- car_load = 15000,
- mission = 0,
- }
- })
- local main_window, support_user = imgui.ImBool(true), imgui.ImBool(true)
- local width, heigth = getScreenResolution()
- local tag, norm, car_load, mission = imgui.ImBuffer(tostring(mainIni.main.tag, 256)), imgui.ImBuffer(tostring(mainIni.main.norm, 256)), imgui.ImBuffer(tostring(mainIni.main.car_load, 256)), imgui.ImBuffer(tostring(mainIni.main.mission, 256))
- local logo = imgui.CreateTextureFromFile(getWorkingDirectory() .. '\\config\\logo\\trucker_logo.png')
- function main()
- if not isSampLoaded() or not isSampfuncsLoaded() then error("Smart Doc needs SA:MP and SAMPFUNCS!") end
- while not isSampAvailable() do wait(100) end
- imgui.Process = true
- my_nick = string.match(sampGetPlayerNickname(select(2,sampGetPlayerIdByCharHandle(playerPed))), "(%w+)_%w+")
- sampAddChatMessage(my_nick, -1)
- while true do
- wait(0)
- if wasKeyPressed(key.VK_G) then
- support_user.v = not support_user.v
- imgui.ShowCursor = support_user.v
- end
- if isKeyDown(key.VK_F) then
- qurents_norm = qurents_norm + 3
- while isKeyDown(key.VK_F) do wait(100) end
- end
- if isKeyDown(key.VK_C) then
- sampAddChatMessage(m_tag .. m_norm .. m_car_load .. m_mission, -1)
- end
- imgui.ShowCursor = support_user.v
- end
- end
- function imgui.OnDrawFrame()
- if main_window.v then
- imgui.SetNextWindowPos(imgui.ImVec2(width*0.300, heigth*0.85), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
- imgui.SetNextWindowSize(imgui.ImVec2(250, 400), imgui.Cond.FirstUseEver)
- imgui.PushStyleColor(3, imgui.ImVec4(0.0, 0.0, 0.0, 0.5))
- if imgui.Begin("Trucker Assistant", _, imgui.WindowFlags.NoCollapse) then
- imgui.NewLine(); imgui.NewLine()
- imgui.SetCursorPos(imgui.ImVec2(250/2, 0))
- imgui.Image(logo, imgui.ImVec2(128, 128))
- imgui.Separator()
- imgui.Text(u8"Успешное выполнение нормы")
- imgui.TextWrapped(u8(my_nick .. ", Вы успешно выполнили ежедневную норму, используйте кнопки выбора, чтобы продолжить действия"))
- if imgui.Button(u8("Оповестить в рацию")) then
- end
- imgui.SameLine()
- if imgui.Button(u8("Закрыть данное окно")) then
- end
- --imgui.ProgressBar(qurents_norm/norm, imgui.ImVec2(imgui.GetWindowWidth() - 17.5, 0.0), u8(string.format("%i м / %i м", qurents_norm, norm)))
- imgui.End()
- imgui.PopStyleColor()
- end
- end
- if support_user.v then
- imgui.SetNextWindowPos(imgui.ImVec2(width/2, heigth/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
- imgui.SetNextWindowSize(imgui.ImVec2(800, 450), imgui.Cond.FirstUseEver)
- imgui.Begin(u8("Trucker Assistant | Главное меню"), support_user, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize)
- imgui.BeginChild('menu', imgui.ImVec2(150, 0), true)
- if not selected then selected = 1 end
- if imgui.Selectable(u8('Главная'), selected == 1) then selected = 1 end
- if imgui.Selectable(u8('Статистика'), selected == 2) then selected = 2 end
- if imgui.Selectable(u8('Настройки'), selected == 3) then selected = 3 end
- if imgui.Selectable(u8('Дополнительно'), selected == 4) then selected = 4 end
- imgui.EndChild()
- imgui.SameLine()
- imgui.BeginChild('center', imgui.ImVec2(0, 0), true)
- if selected == 1 then
- imgui.Text(u8"Основные настройки")
- imgui.BulletText(my_nick .. u8", на данной странице Вы можете настроить основные параметры «Trucker Assistant»")
- imgui.Separator()
- --
- imgui.Text(u8"Ваш ТЭГ:") imgui.TextQuestion(u8"Будет отображаться в начале сообщения «/tr»")
- imgui.SameLine(350)
- imgui.Text(u8"Суточная норма:") imgui.TextQuestion(u8"Установите норму, которую Вам нужно выполнить за день.")
- imgui.PushItemWidth(200) local save = imgui.InputText("##tag", tag) if save then mainIni.main.tag = u8:decode(tag.v) end imgui.PopItemWidth()
- imgui.SameLine(350)
- imgui.PushItemWidth(200) local save = imgui.InputText("##norm", norm, imgui.InputTextFlags.CharsDecimal) if save then mainIni.main.norm = norm.v end imgui.PopItemWidth()
- imgui.Text(u8"Загрузка груза:") imgui.TextQuestion(u8"Введите число, которое будет устанавливаться при загрузке")
- imgui.SameLine(350)
- imgui.Text(u8"Цель:") imgui.TextQuestion(u8"Установите цель, которую будите достигать.")
- imgui.PushItemWidth(200) local save = imgui.InputText("##car_load", car_load, imgui.InputTextFlags.CharsDecimal) if save then mainIni.main.car_load = car_load.v end imgui.PopItemWidth()
- imgui.SameLine(350)
- imgui.PushItemWidth(200) local save = imgui.InputText("##mission", mission, imgui.InputTextFlags.CharsDecimal) if save then mainIni.main.mission = mission.v end imgui.PopItemWidth()
- elseif selected == 2 then
- imgui.Text(u8"Статистика")
- imgui.BulletText(my_nick .. u8", Вы можете посмотреть полную статистику Вашей работы.")
- imgui.Separator()
- imgui.NewLine()
- imgui.Text(u8"Статистика рейсов:") imgui.TextQuestion(u8"На диаграмме Вы можете посмотреть статистику Вашей работы")
- local flightDiagram = {
- {
- v = 100,
- name = 'Выполнено рейсов',
- color = 0xFFFFFFFF
- },
- {
- v = 26,
- name = 'Осталось выполнить',
- color = 0xFF5ac7a2
- },
- }
- imgui.RoundDiagram(flightDiagram, 60, 50)
- imgui.Text(u8"Выполнение цели:") imgui.TextQuestion(u8"На диаграмме Вы можете посмотреть статистику выполнения цели")
- local flightDiagram = {
- {
- v = 100,
- name = 'Выполнено рейсов',
- color = 0xFFFFFFFF
- },
- {
- v = 43,
- name = 'Осталось выполнить',
- color = 0xFF5ac7a2
- },
- }
- imgui.RoundDiagram(flightDiagram, 60, 50)
- elseif selected == 3 then
- imgui.Text(u8"Настройки")
- imgui.BulletText(my_nick .. u8", на данной странице Вы можете полностью настроить функционал скрипта под себя")
- imgui.Separator()
- imgui.NewLine()
- if imgui.Checkbox(u8'Автоматическая загрузка/выгрузка', imgui.ImBool(mainIni.settings.auto_load)) then mainIni.settings.auto_load = not mainIni.settings.auto_load end
- imgui.SameLine(350)
- if imgui.Checkbox(u8'Автоматический доклад в рацию', imgui.ImBool(mainIni.settings.auto_message)) then mainIni.settings.auto_message = not mainIni.settings.auto_message end
- if imgui.Checkbox(u8'Показывать статистику работы', imgui.ImBool(mainIni.settings.stats)) then mainIni.settings.stats = not mainIni.settings.stats end
- imgui.SameLine(350)
- if imgui.Checkbox(u8'Оповещение об окончании топлива', imgui.ImBool(mainIni.settings.auto_fuel)) then mainIni.settings.auto_fuel = not mainIni.settings.auto_fuel end
- if imgui.Checkbox(u8'Уведомлять о прочности автомобиля', imgui.ImBool(mainIni.settings.heal_car)) then mainIni.settings.heal_car = not mainIni.settings.heal_car end
- if imgui.Checkbox(u8'Использовать ТЭГ', imgui.ImBool(mainIni.settings.tag_use)) then mainIni.settings.tag_use = not mainIni.settings.tag_use end
- end
- imgui.EndChild()
- imgui.End()
- end
- end
- -- addEventHandler("onWindowMessage", function (msg, wparam, lparam)
- -- if msg == wm.WM_KEYDOWN or msg == wm.WM_SYSKEYDOWN then
- -- if wparam == key.VK_ESCAPE and support_user.v then
- -- if hk.edit then hk.edit = false
- -- else support_user.v = false end
- -- consumeWindowMessage(true, true)
- -- end
- -- end
- -- end)
- function imgui.RoundDiagram(valTable, radius, segments)
- local draw_list = imgui.GetWindowDrawList()
- local default = imgui.GetStyle().AntiAliasedShapes
- imgui.GetStyle().AntiAliasedShapes = false
- local center = imgui.ImVec2(imgui.GetCursorScreenPos().x + radius, imgui.GetCursorScreenPos().y + radius)
- local function round(num)
- if num >= 0 then
- if select(2, math.modf(num)) >= 0.5 then
- return math.ceil(num)
- else
- return math.floor(num)
- end
- else
- if select(2, math.modf(num)) >= 0.5 then
- return math.floor(num)
- else
- return math.ceil(num)
- end
- end
- end
- local sum = 0
- local q = {}
- for k, v in ipairs(valTable) do
- sum = sum + v.v
- end
- for k, v in ipairs(valTable) do
- if k > 1 then
- q[k] = q[k-1] + round(valTable[k].v/sum*segments)
- else
- q[k] = round(valTable[k].v/sum*segments)
- end
- end
- local current = 1
- local count = 1
- local theta = 0
- local step = 2*math.pi/segments
- for i = 1, segments do -- theta < 2*math.pi
- if q[current] < count then
- current = current + 1
- end
- draw_list:AddTriangleFilled(center, imgui.ImVec2(center.x + radius*math.cos(theta), center.y + radius*math.sin(theta)), imgui.ImVec2(center.x + radius*math.cos(theta+step), center.y + radius*math.sin(theta+step)), valTable[current].color)
- theta = theta + step
- count = count + 1
- end
- local fontsize = imgui.GetFontSize()
- local indented = 2*(radius + imgui.GetStyle().ItemSpacing.x)
- imgui.Indent(indented)
- imgui.SameLine(0)
- imgui.NewLine() -- awful fix for first line padding
- imgui.SetCursorScreenPos(imgui.ImVec2(imgui.GetCursorScreenPos().x, center.y - imgui.GetTextLineHeight() * #valTable / 2))
- for k, v in ipairs(valTable) do
- draw_list:AddRectFilled(imgui.ImVec2(imgui.GetCursorScreenPos().x, imgui.GetCursorScreenPos().y), imgui.ImVec2(imgui.GetCursorScreenPos().x + fontsize, imgui.GetCursorScreenPos().y + fontsize), v.color)
- imgui.SetCursorPosX(imgui.GetCursorPosX() + fontsize*1.3)
- imgui.Text(u8(v.name .. ' - ' .. v.v .. ' (' .. string.format('%.2f', v.v/sum*100) .. '%)'))
- end
- imgui.Unindent(indented)
- imgui.SetCursorScreenPos(imgui.ImVec2(imgui.GetCursorScreenPos().x, center.y + radius + imgui.GetTextLineHeight()))
- imgui.GetStyle().AntiAliasedShapes = default
- end
- function imgui.TextQuestion(text)
- imgui.SameLine(nil, 0)
- imgui.TextDisabled(" (?)")
- if imgui.IsItemHovered() then
- imgui.BeginTooltip()
- imgui.PushTextWrapPos(450)
- imgui.TextUnformatted(text)
- imgui.PopTextWrapPos()
- imgui.EndTooltip()
- end
- end
- function imgui.TextColoredRGB(text)
- local style = imgui.GetStyle()
- local colors = style.Colors
- local ImVec4 = imgui.ImVec4
- local explode_argb = function(argb)
- local a = bit.band(bit.rshift(argb, 24), 0xFF)
- local r = bit.band(bit.rshift(argb, 16), 0xFF)
- local g = bit.band(bit.rshift(argb, 8), 0xFF)
- local b = bit.band(argb, 0xFF)
- return a, r, g, b
- end
- local getcolor = function(color)
- if color:sub(1, 6):upper() == 'SSSSSS' then
- local r, g, b = colors[1].x, colors[1].y, colors[1].z
- local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
- return ImVec4(r, g, b, a / 255)
- end
- local color = type(color) == 'string' and tonumber(color, 16) or color
- if type(color) ~= 'number' then return end
- local r, g, b, a = explode_argb(color)
- return imgui.ImColor(r, g, b, a):GetVec4()
- end
- local render_text = function(text_)
- for w in text_:gmatch('[^\r\n]+') do
- local text, colors_, m = {}, {}, 1
- w = w:gsub('{(......)}', '{%1FF}')
- while w:find('{........}') do
- local n, k = w:find('{........}')
- local color = getcolor(w:sub(n + 1, k - 1))
- if color then
- text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
- colors_[#colors_ + 1] = color
- m = n
- end
- w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
- end
- if text[0] then
- for i = 0, #text do
- imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
- imgui.SameLine(nil, 0)
- end
- imgui.NewLine()
- else imgui.Text(u8(w)) end
- end
- end
- render_text(text)
- end
- function onScriptTerminate(scr)
- if scr == script.this then
- inicfg.save(mainIni)
- end
- end
- function apply_custom_style()
- local style = imgui.GetStyle()
- local colors = style.Colors
- local clr = imgui.Col
- local ImVec4 = imgui.ImVec4
- style.WindowRounding = 6
- style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
- style.ChildWindowRounding = 1.5
- style.FrameRounding = 3.0
- style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
- style.ScrollbarSize = 13.0
- style.ScrollbarRounding = 2
- style.GrabMinSize = 8.0
- style.GrabRounding = 1.0
- -- style.Alpha =
- style.WindowPadding = imgui.ImVec2(4.0, 4.0)
- -- style.WindowMinSize =
- style.FramePadding = imgui.ImVec2(2.5, 3.5)
- -- style.ItemInnerSpacing =
- -- style.TouchExtraPadding =
- -- style.IndentSpacing =
- -- style.ColumnsMinSpacing = ?
- style.ButtonTextAlign = imgui.ImVec2(0.02, 0.4)
- -- style.DisplayWindowPadding =
- -- style.DisplaySafeAreaPadding =
- -- style.AntiAliasedLines =
- -- style.AntiAliasedShapes =
- -- style.CurveTessellationTol =
- 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] = imgui.ImColor(0, 0, 0, 227):GetVec4()
- colors[clr.ChildWindowBg] = 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] = imgui.ImColor(40, 142, 110, 90):GetVec4()
- colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
- colors[clr.FrameBg] = imgui.ImColor(40, 142, 110, 113):GetVec4()
- colors[clr.FrameBgHovered] = imgui.ImColor(40, 142, 110, 164):GetVec4()
- colors[clr.FrameBgActive] = imgui.ImColor(40, 142, 110, 255):GetVec4()
- colors[clr.TitleBg] = imgui.ImColor(40, 142, 110, 236):GetVec4()
- colors[clr.TitleBgActive] = imgui.ImColor(40, 142, 110, 236):GetVec4()
- colors[clr.TitleBgCollapsed] = ImVec4(0.05, 0.05, 0.05, 0.79)
- 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] = imgui.ImColor(40, 142, 110, 236):GetVec4()
- 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.CheckMark] = ImVec4(1.00, 1.00, 1.00, 1.00)
- colors[clr.SliderGrab] = ImVec4(0.28, 0.28, 0.28, 1.00)
- colors[clr.SliderGrabActive] = ImVec4(0.35, 0.35, 0.35, 1.00)
- colors[clr.Button] = imgui.ImColor(40, 142, 110, 255):GetVec4()
- colors[clr.ButtonHovered] = imgui.ImColor(35, 121, 93, 174):GetVec4()
- colors[clr.ButtonActive] = imgui.ImColor(44, 154, 119, 255):GetVec4()
- colors[clr.Header] = imgui.ImColor(40, 142, 110, 255):GetVec4()
- colors[clr.HeaderHovered] = ImVec4(0.34, 0.34, 0.35, 0.89)
- colors[clr.HeaderActive] = ImVec4(0.12, 0.12, 0.12, 0.94)
- 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] = imgui.ImColor(40, 142, 110, 255):GetVec4()
- colors[clr.ResizeGripHovered] = imgui.ImColor(35, 121, 93, 174):GetVec4()
- colors[clr.ResizeGripActive] = imgui.ImColor(44, 154, 119, 255):GetVec4()
- 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.TextSelectedBg] = ImVec4(0.26, 0.59, 0.98, 0.35)
- colors[clr.ModalWindowDarkening] = ImVec4(0.10, 0.10, 0.10, 0.35)
- end
- apply_custom_style()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement