Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.98 KB | None | 0 0
  1. local imgui = require("imgui")
  2. local encoding = require("encoding")
  3. local u8 = encoding.UTF8
  4. local key = require 'vkeys'
  5. encoding.default = "CP1251"
  6. local inicfg = require 'inicfg'
  7.  
  8. local test = 1
  9. local mainIni = inicfg.load({
  10. settings =
  11. {
  12. auto_fuel = true,
  13. auto_load = true,
  14. tag_use = true,
  15. auto_message = true,
  16. stats = true,
  17. heal_car = true,
  18. },
  19. main =
  20. {
  21. tag = "ув",
  22. norm = 5000,
  23. car_load = 15000,
  24. mission = 0,
  25. }
  26. })
  27.  
  28. local main_window, support_user = imgui.ImBool(true), imgui.ImBool(true)
  29. local width, heigth = getScreenResolution()
  30. 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))
  31. local logo = imgui.CreateTextureFromFile(getWorkingDirectory() .. '\\config\\logo\\trucker_logo.png')
  32.  
  33.  
  34.  
  35. function main()
  36. if not isSampLoaded() or not isSampfuncsLoaded() then error("Smart Doc needs SA:MP and SAMPFUNCS!") end
  37. while not isSampAvailable() do wait(100) end
  38. imgui.Process = true
  39. my_nick = string.match(sampGetPlayerNickname(select(2,sampGetPlayerIdByCharHandle(playerPed))), "(%w+)_%w+")
  40. sampAddChatMessage(my_nick, -1)
  41. while true do
  42. wait(0)
  43. if wasKeyPressed(key.VK_G) then
  44. support_user.v = not support_user.v
  45. imgui.ShowCursor = support_user.v
  46.  
  47. end
  48. if isKeyDown(key.VK_F) then
  49. qurents_norm = qurents_norm + 3
  50. while isKeyDown(key.VK_F) do wait(100) end
  51. end
  52. if isKeyDown(key.VK_C) then
  53. sampAddChatMessage(m_tag .. m_norm .. m_car_load .. m_mission, -1)
  54. end
  55. imgui.ShowCursor = support_user.v
  56. end
  57. end
  58.  
  59.  
  60. function imgui.OnDrawFrame()
  61. if main_window.v then
  62. imgui.SetNextWindowPos(imgui.ImVec2(width*0.300, heigth*0.85), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
  63. imgui.SetNextWindowSize(imgui.ImVec2(250, 400), imgui.Cond.FirstUseEver)
  64. imgui.PushStyleColor(3, imgui.ImVec4(0.0, 0.0, 0.0, 0.5))
  65. if imgui.Begin("Trucker Assistant", _, imgui.WindowFlags.NoCollapse) then
  66. imgui.NewLine(); imgui.NewLine()
  67. imgui.SetCursorPos(imgui.ImVec2(250/2, 0))
  68. imgui.Image(logo, imgui.ImVec2(128, 128))
  69. imgui.Separator()
  70. imgui.Text(u8"Успешное выполнение нормы")
  71. imgui.TextWrapped(u8(my_nick .. ", Вы успешно выполнили ежедневную норму, используйте кнопки выбора, чтобы продолжить действия"))
  72. if imgui.Button(u8("Оповестить в рацию")) then
  73.  
  74. end
  75. imgui.SameLine()
  76. if imgui.Button(u8("Закрыть данное окно")) then
  77.  
  78. end
  79.  
  80. --imgui.ProgressBar(qurents_norm/norm, imgui.ImVec2(imgui.GetWindowWidth() - 17.5, 0.0), u8(string.format("%i м / %i м", qurents_norm, norm)))
  81. imgui.End()
  82. imgui.PopStyleColor()
  83. end
  84. end
  85.  
  86. if support_user.v then
  87. imgui.SetNextWindowPos(imgui.ImVec2(width/2, heigth/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
  88. imgui.SetNextWindowSize(imgui.ImVec2(800, 450), imgui.Cond.FirstUseEver)
  89. imgui.Begin(u8("Trucker Assistant | Главное меню"), support_user, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize)
  90. imgui.BeginChild('menu', imgui.ImVec2(150, 0), true)
  91. if not selected then selected = 1 end
  92. if imgui.Selectable(u8('Главная'), selected == 1) then selected = 1 end
  93. if imgui.Selectable(u8('Статистика'), selected == 2) then selected = 2 end
  94. if imgui.Selectable(u8('Настройки'), selected == 3) then selected = 3 end
  95. if imgui.Selectable(u8('Дополнительно'), selected == 4) then selected = 4 end
  96. imgui.EndChild()
  97. imgui.SameLine()
  98. imgui.BeginChild('center', imgui.ImVec2(0, 0), true)
  99. if selected == 1 then
  100. imgui.Text(u8"Основные настройки")
  101. imgui.BulletText(my_nick .. u8", на данной странице Вы можете настроить основные параметры «Trucker Assistant»")
  102. imgui.Separator()
  103. --
  104. imgui.Text(u8"Ваш ТЭГ:") imgui.TextQuestion(u8"Будет отображаться в начале сообщения «/tr»")
  105. imgui.SameLine(350)
  106. imgui.Text(u8"Суточная норма:") imgui.TextQuestion(u8"Установите норму, которую Вам нужно выполнить за день.")
  107. imgui.PushItemWidth(200) local save = imgui.InputText("##tag", tag) if save then mainIni.main.tag = u8:decode(tag.v) end imgui.PopItemWidth()
  108. imgui.SameLine(350)
  109. imgui.PushItemWidth(200) local save = imgui.InputText("##norm", norm, imgui.InputTextFlags.CharsDecimal) if save then mainIni.main.norm = norm.v end imgui.PopItemWidth()
  110. imgui.Text(u8"Загрузка груза:") imgui.TextQuestion(u8"Введите число, которое будет устанавливаться при загрузке")
  111. imgui.SameLine(350)
  112. imgui.Text(u8"Цель:") imgui.TextQuestion(u8"Установите цель, которую будите достигать.")
  113. 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()
  114. imgui.SameLine(350)
  115. imgui.PushItemWidth(200) local save = imgui.InputText("##mission", mission, imgui.InputTextFlags.CharsDecimal) if save then mainIni.main.mission = mission.v end imgui.PopItemWidth()
  116. elseif selected == 2 then
  117. imgui.Text(u8"Статистика")
  118. imgui.BulletText(my_nick .. u8", Вы можете посмотреть полную статистику Вашей работы.")
  119. imgui.Separator()
  120. imgui.NewLine()
  121. imgui.Text(u8"Статистика рейсов:") imgui.TextQuestion(u8"На диаграмме Вы можете посмотреть статистику Вашей работы")
  122. local flightDiagram = {
  123. {
  124. v = 100,
  125. name = 'Выполнено рейсов',
  126. color = 0xFFFFFFFF
  127. },
  128. {
  129. v = 26,
  130. name = 'Осталось выполнить',
  131. color = 0xFF5ac7a2
  132. },
  133. }
  134. imgui.RoundDiagram(flightDiagram, 60, 50)
  135. imgui.Text(u8"Выполнение цели:") imgui.TextQuestion(u8"На диаграмме Вы можете посмотреть статистику выполнения цели")
  136. local flightDiagram = {
  137. {
  138. v = 100,
  139. name = 'Выполнено рейсов',
  140. color = 0xFFFFFFFF
  141. },
  142. {
  143. v = 43,
  144. name = 'Осталось выполнить',
  145. color = 0xFF5ac7a2
  146. },
  147. }
  148. imgui.RoundDiagram(flightDiagram, 60, 50)
  149. elseif selected == 3 then
  150. imgui.Text(u8"Настройки")
  151. imgui.BulletText(my_nick .. u8", на данной странице Вы можете полностью настроить функционал скрипта под себя")
  152. imgui.Separator()
  153. imgui.NewLine()
  154. if imgui.Checkbox(u8'Автоматическая загрузка/выгрузка', imgui.ImBool(mainIni.settings.auto_load)) then mainIni.settings.auto_load = not mainIni.settings.auto_load end
  155. imgui.SameLine(350)
  156. if imgui.Checkbox(u8'Автоматический доклад в рацию', imgui.ImBool(mainIni.settings.auto_message)) then mainIni.settings.auto_message = not mainIni.settings.auto_message end
  157. if imgui.Checkbox(u8'Показывать статистику работы', imgui.ImBool(mainIni.settings.stats)) then mainIni.settings.stats = not mainIni.settings.stats end
  158. imgui.SameLine(350)
  159. if imgui.Checkbox(u8'Оповещение об окончании топлива', imgui.ImBool(mainIni.settings.auto_fuel)) then mainIni.settings.auto_fuel = not mainIni.settings.auto_fuel end
  160. if imgui.Checkbox(u8'Уведомлять о прочности автомобиля', imgui.ImBool(mainIni.settings.heal_car)) then mainIni.settings.heal_car = not mainIni.settings.heal_car end
  161. if imgui.Checkbox(u8'Использовать ТЭГ', imgui.ImBool(mainIni.settings.tag_use)) then mainIni.settings.tag_use = not mainIni.settings.tag_use end
  162. end
  163. imgui.EndChild()
  164. imgui.End()
  165. end
  166. end
  167.  
  168. -- addEventHandler("onWindowMessage", function (msg, wparam, lparam)
  169. -- if msg == wm.WM_KEYDOWN or msg == wm.WM_SYSKEYDOWN then
  170. -- if wparam == key.VK_ESCAPE and support_user.v then
  171. -- if hk.edit then hk.edit = false
  172. -- else support_user.v = false end
  173. -- consumeWindowMessage(true, true)
  174. -- end
  175. -- end
  176. -- end)
  177.  
  178. function imgui.RoundDiagram(valTable, radius, segments)
  179. local draw_list = imgui.GetWindowDrawList()
  180. local default = imgui.GetStyle().AntiAliasedShapes
  181. imgui.GetStyle().AntiAliasedShapes = false
  182. local center = imgui.ImVec2(imgui.GetCursorScreenPos().x + radius, imgui.GetCursorScreenPos().y + radius)
  183. local function round(num)
  184. if num >= 0 then
  185. if select(2, math.modf(num)) >= 0.5 then
  186. return math.ceil(num)
  187. else
  188. return math.floor(num)
  189. end
  190. else
  191. if select(2, math.modf(num)) >= 0.5 then
  192. return math.floor(num)
  193. else
  194. return math.ceil(num)
  195. end
  196. end
  197. end
  198.  
  199. local sum = 0
  200. local q = {}
  201.  
  202. for k, v in ipairs(valTable) do
  203. sum = sum + v.v
  204. end
  205.  
  206. for k, v in ipairs(valTable) do
  207. if k > 1 then
  208. q[k] = q[k-1] + round(valTable[k].v/sum*segments)
  209. else
  210. q[k] = round(valTable[k].v/sum*segments)
  211. end
  212. end
  213.  
  214. local current = 1
  215. local count = 1
  216. local theta = 0
  217. local step = 2*math.pi/segments
  218.  
  219. for i = 1, segments do -- theta < 2*math.pi
  220. if q[current] < count then
  221. current = current + 1
  222. end
  223. 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)
  224. theta = theta + step
  225. count = count + 1
  226. end
  227.  
  228. local fontsize = imgui.GetFontSize()
  229. local indented = 2*(radius + imgui.GetStyle().ItemSpacing.x)
  230. imgui.Indent(indented)
  231.  
  232. imgui.SameLine(0)
  233. imgui.NewLine() -- awful fix for first line padding
  234. imgui.SetCursorScreenPos(imgui.ImVec2(imgui.GetCursorScreenPos().x, center.y - imgui.GetTextLineHeight() * #valTable / 2))
  235. for k, v in ipairs(valTable) do
  236. draw_list:AddRectFilled(imgui.ImVec2(imgui.GetCursorScreenPos().x, imgui.GetCursorScreenPos().y), imgui.ImVec2(imgui.GetCursorScreenPos().x + fontsize, imgui.GetCursorScreenPos().y + fontsize), v.color)
  237. imgui.SetCursorPosX(imgui.GetCursorPosX() + fontsize*1.3)
  238. imgui.Text(u8(v.name .. ' - ' .. v.v .. ' (' .. string.format('%.2f', v.v/sum*100) .. '%)'))
  239. end
  240. imgui.Unindent(indented)
  241. imgui.SetCursorScreenPos(imgui.ImVec2(imgui.GetCursorScreenPos().x, center.y + radius + imgui.GetTextLineHeight()))
  242. imgui.GetStyle().AntiAliasedShapes = default
  243. end
  244.  
  245. function imgui.TextQuestion(text)
  246. imgui.SameLine(nil, 0)
  247. imgui.TextDisabled(" (?)")
  248. if imgui.IsItemHovered() then
  249. imgui.BeginTooltip()
  250. imgui.PushTextWrapPos(450)
  251. imgui.TextUnformatted(text)
  252. imgui.PopTextWrapPos()
  253. imgui.EndTooltip()
  254. end
  255. end
  256.  
  257. function imgui.TextColoredRGB(text)
  258. local style = imgui.GetStyle()
  259. local colors = style.Colors
  260. local ImVec4 = imgui.ImVec4
  261.  
  262. local explode_argb = function(argb)
  263. local a = bit.band(bit.rshift(argb, 24), 0xFF)
  264. local r = bit.band(bit.rshift(argb, 16), 0xFF)
  265. local g = bit.band(bit.rshift(argb, 8), 0xFF)
  266. local b = bit.band(argb, 0xFF)
  267. return a, r, g, b
  268. end
  269.  
  270. local getcolor = function(color)
  271. if color:sub(1, 6):upper() == 'SSSSSS' then
  272. local r, g, b = colors[1].x, colors[1].y, colors[1].z
  273. local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
  274. return ImVec4(r, g, b, a / 255)
  275. end
  276. local color = type(color) == 'string' and tonumber(color, 16) or color
  277. if type(color) ~= 'number' then return end
  278. local r, g, b, a = explode_argb(color)
  279. return imgui.ImColor(r, g, b, a):GetVec4()
  280. end
  281.  
  282. local render_text = function(text_)
  283. for w in text_:gmatch('[^\r\n]+') do
  284. local text, colors_, m = {}, {}, 1
  285. w = w:gsub('{(......)}', '{%1FF}')
  286. while w:find('{........}') do
  287. local n, k = w:find('{........}')
  288. local color = getcolor(w:sub(n + 1, k - 1))
  289. if color then
  290. text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
  291. colors_[#colors_ + 1] = color
  292. m = n
  293. end
  294. w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
  295. end
  296. if text[0] then
  297. for i = 0, #text do
  298. imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
  299. imgui.SameLine(nil, 0)
  300. end
  301. imgui.NewLine()
  302. else imgui.Text(u8(w)) end
  303. end
  304. end
  305.  
  306. render_text(text)
  307. end
  308.  
  309. function onScriptTerminate(scr)
  310. if scr == script.this then
  311. inicfg.save(mainIni)
  312. end
  313. end
  314.  
  315.  
  316. function apply_custom_style()
  317. local style = imgui.GetStyle()
  318. local colors = style.Colors
  319. local clr = imgui.Col
  320. local ImVec4 = imgui.ImVec4
  321. style.WindowRounding = 6
  322. style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
  323. style.ChildWindowRounding = 1.5
  324. style.FrameRounding = 3.0
  325. style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
  326. style.ScrollbarSize = 13.0
  327. style.ScrollbarRounding = 2
  328. style.GrabMinSize = 8.0
  329. style.GrabRounding = 1.0
  330. -- style.Alpha =
  331. style.WindowPadding = imgui.ImVec2(4.0, 4.0)
  332. -- style.WindowMinSize =
  333. style.FramePadding = imgui.ImVec2(2.5, 3.5)
  334. -- style.ItemInnerSpacing =
  335. -- style.TouchExtraPadding =
  336. -- style.IndentSpacing =
  337. -- style.ColumnsMinSpacing = ?
  338. style.ButtonTextAlign = imgui.ImVec2(0.02, 0.4)
  339. -- style.DisplayWindowPadding =
  340. -- style.DisplaySafeAreaPadding =
  341. -- style.AntiAliasedLines =
  342. -- style.AntiAliasedShapes =
  343. -- style.CurveTessellationTol =
  344. colors[clr.Text] = ImVec4(1.00, 1.00, 1.00, 1.00)
  345. colors[clr.TextDisabled] = ImVec4(0.50, 0.50, 0.50, 1.00)
  346. colors[clr.WindowBg] = imgui.ImColor(0, 0, 0, 227):GetVec4()
  347. colors[clr.ChildWindowBg] = ImVec4(1.00, 1.00, 1.00, 0.00)
  348. colors[clr.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94)
  349. colors[clr.ComboBg] = colors[clr.PopupBg]
  350. colors[clr.Border] = imgui.ImColor(40, 142, 110, 90):GetVec4()
  351. colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
  352. colors[clr.FrameBg] = imgui.ImColor(40, 142, 110, 113):GetVec4()
  353. colors[clr.FrameBgHovered] = imgui.ImColor(40, 142, 110, 164):GetVec4()
  354. colors[clr.FrameBgActive] = imgui.ImColor(40, 142, 110, 255):GetVec4()
  355. colors[clr.TitleBg] = imgui.ImColor(40, 142, 110, 236):GetVec4()
  356. colors[clr.TitleBgActive] = imgui.ImColor(40, 142, 110, 236):GetVec4()
  357. colors[clr.TitleBgCollapsed] = ImVec4(0.05, 0.05, 0.05, 0.79)
  358. colors[clr.MenuBarBg] = ImVec4(0.14, 0.14, 0.14, 1.00)
  359. colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.53)
  360. colors[clr.ScrollbarGrab] = imgui.ImColor(40, 142, 110, 236):GetVec4()
  361. colors[clr.ScrollbarGrabHovered] = ImVec4(0.41, 0.41, 0.41, 1.00)
  362. colors[clr.ScrollbarGrabActive] = ImVec4(0.51, 0.51, 0.51, 1.00)
  363. colors[clr.CheckMark] = ImVec4(1.00, 1.00, 1.00, 1.00)
  364. colors[clr.SliderGrab] = ImVec4(0.28, 0.28, 0.28, 1.00)
  365. colors[clr.SliderGrabActive] = ImVec4(0.35, 0.35, 0.35, 1.00)
  366. colors[clr.Button] = imgui.ImColor(40, 142, 110, 255):GetVec4()
  367. colors[clr.ButtonHovered] = imgui.ImColor(35, 121, 93, 174):GetVec4()
  368. colors[clr.ButtonActive] = imgui.ImColor(44, 154, 119, 255):GetVec4()
  369. colors[clr.Header] = imgui.ImColor(40, 142, 110, 255):GetVec4()
  370. colors[clr.HeaderHovered] = ImVec4(0.34, 0.34, 0.35, 0.89)
  371. colors[clr.HeaderActive] = ImVec4(0.12, 0.12, 0.12, 0.94)
  372. colors[clr.Separator] = colors[clr.Border]
  373. colors[clr.SeparatorHovered] = ImVec4(0.26, 0.59, 0.98, 0.78)
  374. colors[clr.SeparatorActive] = ImVec4(0.26, 0.59, 0.98, 1.00)
  375. colors[clr.ResizeGrip] = imgui.ImColor(40, 142, 110, 255):GetVec4()
  376. colors[clr.ResizeGripHovered] = imgui.ImColor(35, 121, 93, 174):GetVec4()
  377. colors[clr.ResizeGripActive] = imgui.ImColor(44, 154, 119, 255):GetVec4()
  378. colors[clr.CloseButton] = ImVec4(0.41, 0.41, 0.41, 0.50)
  379. colors[clr.CloseButtonHovered] = ImVec4(0.98, 0.39, 0.36, 1.00)
  380. colors[clr.CloseButtonActive] = ImVec4(0.98, 0.39, 0.36, 1.00)
  381. colors[clr.PlotLines] = ImVec4(0.61, 0.61, 0.61, 1.00)
  382. colors[clr.PlotLinesHovered] = ImVec4(1.00, 0.43, 0.35, 1.00)
  383. colors[clr.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
  384. colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
  385. colors[clr.TextSelectedBg] = ImVec4(0.26, 0.59, 0.98, 0.35)
  386. colors[clr.ModalWindowDarkening] = ImVec4(0.10, 0.10, 0.10, 0.35)
  387. end
  388.  
  389. apply_custom_style()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement