local imgui = require 'mimgui'
local encoding = require 'encoding'
local keys = require 'vkeys'
local ffi = require 'ffi'
local sampev = require 'lib.samp.events'
require 'lib.moonloader'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local new, str, sizeof = imgui.new, ffi.string, ffi.sizeof
local renderWindow = new.bool(false)
local ImBuffer = {
checkBox = {
disabled = new.bool(false),
enabled = new.bool(true)
},
text = new.char[255]
}
local adInput = new.char[256]('')
local adNick = ''
local adPrice = ''
local adText = ''
local confirm = false
local block = false
imgui.OnInitialize(function() imgui.DarkTheme(); imgui.GetIO().IniFilename = nil; end)
local newFrame = imgui.OnFrame(
function() return renderWindow[0] end,
function(player)
local resX, resY = getScreenResolution()
local sizeX, sizeY = 700, 340
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'Публикация oбъявления | LSN Helper by Martin Sonnet aka kyrtion', nil, imgui.WindowFlags.NoMove + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.AlwaysAutoResize)
imgui.SetCursorPos(imgui.ImVec2(20, 40)); imgui.TextColoredRGB('Отправитель:'); imgui.SameLine((sizeX - 15) / 2 + 10); --[[imgui.SetCursorPos(imgui.ImVec2(20, 160));]] imgui.TextColoredRGB('Цена:')
imgui.SetCursorPos(imgui.ImVec2(20, 60)); --adNick = 'Martin Sonnet'; bl = ' {FF0000}(состоит в чёрном списке)'; bl_rb = 'ЧС '; adPrice = '51$'
imgui.BeginChild('ChildWindows1', imgui.ImVec2(sizeX - 372, 25), true)
imgui.TextColoredRGB('{FFFFFF}' .. adNick--[[.. bl]])
imgui.EndChild()
imgui.SameLine((sizeX - 15) / 2 + 10);
--imgui.SetCursorPos(imgui.ImVec2(20, 180))
imgui.BeginChild('ChildWindows2', imgui.ImVec2(sizeX - 372, 25), true)
imgui.TextColoredRGB(adPrice)
imgui.EndChild()
imgui.SetCursorPos(imgui.ImVec2(20, 100)); imgui.TextColoredRGB('Текст:')
imgui.SetCursorPos(imgui.ImVec2(20, 120))
--adText = 'Внимание! Акции и скидки на весь ассортимент в лучшем магазине одежды Лос Сантоса! GPS 9-29!'
imgui.BeginChild('ChildWindows3', imgui.ImVec2(sizeX - 40, 25), true)
imgui.TextColoredRGB(adText)
imgui.EndChild()
imgui.SetCursorPos(imgui.ImVec2(20, 180))
imgui.TextColoredRGB('Введите новый текст для этого объявления или оставьте поле пустым если его редактирование не нужно.')
imgui.SetCursorPos(imgui.ImVec2(20, 195))
imgui.TextColoredRGB('Вы так-же можете отклонить объявление с написанной в поле причиной и нажав после кнопку "Отклонить".')
imgui.SetCursorPos(imgui.ImVec2(20, sizeY - 110))
imgui.PushItemWidth(sizeX - 40);
--[[imgui.SetKeyboardFocusHere(-1);]]
--adText = 'ф23ывфывяс'
imgui.StrCopy(adInput, u8(adText))
-- imgui.InputText(u8'', adInput, sizeof(adInput))
-- adInput = new.char[256](u8(adText))
imgui.InputText(u8'', adInput, sizeof(adInput))
imgui.SetCursorPos(imgui.ImVec2(5, sizeY - 60))
if imgui.Button(u8'Передать в /rb', imgui.ImVec2((sizeX - 15) / 2 , 25)) then
sampAddChatMessage("[79] sampSendChat('/rb '.. adNick .. ' (' .. adPrice .. '): '.. adText)", -1)
sampSendChat('/rb '.. adNick .. ' (' .. adPrice .. '): '.. adText)
end
imgui.SameLine((sizeX - 15) / 2 + 10)
if imgui.Button(u8'Поиск (скоро)', imgui.ImVec2((sizeX - 15) / 2 , 25)) then
sampAddChatMessage('Скоро', -1)
end
if imgui.Button(u8'Опубликовать', imgui.ImVec2((sizeX - 15) / 2 , 25)) then
if (u8:decode(str(adInput))) == (nil or '') then
sampAddChatMessage('Вы ничего не ввели в поле ввода', -1)
else
sampAddChatMessage('Редактировано: '..(u8:decode(str(adInput))), -1)
sampSendDialogResponse(1536,0,0,(u8:decode(str(adInput))))
sampAddChatMessage('[93] sampSendDialogResponse(1536,0,0,(u8:decode(str(adInput))))', -1)
renderWindow[0] = false
adNick, adPrice, adText = ''
end
end
imgui.SameLine((sizeX - 15) / 2 + 10)
if imgui.Button(u8'Отклонить', imgui.ImVec2((sizeX - 15) / 2 , 25)) then
if (u8:decode(str(adInput))) == (nil or '') then
sampAddChatMessage('Вы ничего не ввели в поле ввода', -1)
else
sampAddChatMessage('Отклонило: '..(u8:decode(str(adInput))), -1)
sampSendDialogResponse(1536,1,0,(u8:decode(str(adInput))))
sampAddChatMessage('[98] sampSendDialogResponse(1536,1,0,(u8:decode(str(adInput))))', -1)
renderWindow[0] = false
adNick, adPrice, adText = ''
end
end
imgui.End()
end
)
function main()
while not isSampAvailable() do wait(0) end
sampRegisterChatCommand('dia', dia)
while true do
wait(0)
end
end
function dia(arg0)
renderWindow[0] = not renderWindow[0]
adText = arg0
end
function onWindowMessage(msg, wparam, lparam)
if msg == 0x100 or msg == 0x101 then
if (wparam == (keys.VK_ESCAPE) and (renderWindow[0]--[[ or win_2.v]])) and not isPauseMenuActive() and not sampIsChatInputActive() and not isSampfuncsConsoleActive() then
consumeWindowMessage(true, false)
if msg == 0x101 then
if renderWindow[0] then
renderWindow[0] = not renderWindow[0]
sampAddChatMessage('[122] Pressed ESC and Exiting renderWindow[0]', -1)
--win_1.v = true
--[[else
sampAddChatMessage('asd', -1)
renderWindow[0] = true]]
end
end
end
end
end
function sampev.onShowDialog(id, style, title, button1, button2, text)
if id == 1536 and title == '{6333FF}Публикация объявления' then
adNick = ( text:match('%{ffffff%}Отправитель%: %{7FFF00%}(.*)%{ffffff%}') ):gsub("\n", "")
adText = ( text:match('%{ffffff%}Текст%:%{7FFF00%} (.*)%{ffffff%}') ):gsub("\n", "")
adPrice = ( text:match('%{ffffff%}Цена%:%{7FFF00%} (.*)%{FFFFFF%}') ):gsub("\n", "")
renderWindow[0] = true
return false
elseif id == 1537 and title == '{6333FF}Публикация объявления: {ffffff}Подтверждение' and confirm then
sampSendDialogResponse(id,0,0,0)
return false
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.ImVec4(r/255, g/255, b/255, a/255)
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 imgui.DarkTheme()
imgui.SwitchContext()
--==[ STYLE ]==--
imgui.GetStyle().WindowPadding = imgui.ImVec2(5, 5)
imgui.GetStyle().FramePadding = imgui.ImVec2(5, 5)
imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 5)
imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(2, 2)
imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(0, 0)
imgui.GetStyle().IndentSpacing = 0
imgui.GetStyle().ScrollbarSize = 10
imgui.GetStyle().GrabMinSize = 10
--==[ BORDER ]==--
imgui.GetStyle().WindowBorderSize = 1
imgui.GetStyle().ChildBorderSize = 1
imgui.GetStyle().PopupBorderSize = 1
imgui.GetStyle().FrameBorderSize = 1
imgui.GetStyle().TabBorderSize = 1
--==[ ROUNDING ]==--
imgui.GetStyle().WindowRounding = 5
imgui.GetStyle().ChildRounding = 5
imgui.GetStyle().FrameRounding = 5
imgui.GetStyle().PopupRounding = 5
imgui.GetStyle().ScrollbarRounding = 5
imgui.GetStyle().GrabRounding = 5
imgui.GetStyle().TabRounding = 5
--==[ ALIGN ]==--
imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
imgui.GetStyle().ButtonTextAlign = imgui.ImVec2(0.5, 0.5)
imgui.GetStyle().SelectableTextAlign = imgui.ImVec2(0.5, 0.5)
--==[ COLORS ]==--
imgui.GetStyle().Colors[imgui.Col.Text] = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.TextDisabled] = imgui.ImVec4(0.50, 0.50, 0.50, 1.00)
imgui.GetStyle().Colors[imgui.Col.WindowBg] = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
imgui.GetStyle().Colors[imgui.Col.ChildBg] = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
imgui.GetStyle().Colors[imgui.Col.PopupBg] = imgui.ImVec4(0.07, 0.07, 0.07, 1.00)
imgui.GetStyle().Colors[imgui.Col.Border] = imgui.ImVec4(0.25, 0.25, 0.26, 0.54)
imgui.GetStyle().Colors[imgui.Col.BorderShadow] = imgui.ImVec4(0.00, 0.00, 0.00, 0.00)
imgui.GetStyle().Colors[imgui.Col.FrameBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.FrameBgHovered] = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.FrameBgActive] = imgui.ImVec4(0.25, 0.25, 0.26, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBgActive] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.MenuBarBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarBg] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab] = imgui.ImVec4(0.00, 0.00, 0.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered] = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive] = imgui.ImVec4(0.51, 0.51, 0.51, 1.00)
imgui.GetStyle().Colors[imgui.Col.CheckMark] = imgui.ImVec4(1.00, 1.00, 1.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.SliderGrab] = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.SliderGrabActive] = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.Button] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ButtonHovered] = imgui.ImVec4(0.21, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.ButtonActive] = imgui.ImVec4(0.41, 0.41, 0.41, 1.00)
imgui.GetStyle().Colors[imgui.Col.Header] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.HeaderHovered] = imgui.ImVec4(0.20, 0.20, 0.20, 1.00)
imgui.GetStyle().Colors[imgui.Col.HeaderActive] = imgui.ImVec4(0.47, 0.47, 0.47, 1.00)
imgui.GetStyle().Colors[imgui.Col.Separator] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.SeparatorHovered] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.SeparatorActive] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.ResizeGrip] = imgui.ImVec4(1.00, 1.00, 1.00, 0.25)
imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered] = imgui.ImVec4(1.00, 1.00, 1.00, 0.67)
imgui.GetStyle().Colors[imgui.Col.ResizeGripActive] = imgui.ImVec4(1.00, 1.00, 1.00, 0.95)
imgui.GetStyle().Colors[imgui.Col.Tab] = imgui.ImVec4(0.12, 0.12, 0.12, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabHovered] = imgui.ImVec4(0.28, 0.28, 0.28, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabActive] = imgui.ImVec4(0.30, 0.30, 0.30, 1.00)
imgui.GetStyle().Colors[imgui.Col.TabUnfocused] = imgui.ImVec4(0.07, 0.10, 0.15, 0.97)
imgui.GetStyle().Colors[imgui.Col.TabUnfocusedActive] = imgui.ImVec4(0.14, 0.26, 0.42, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotLines] = imgui.ImVec4(0.61, 0.61, 0.61, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered] = imgui.ImVec4(1.00, 0.43, 0.35, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotHistogram] = imgui.ImVec4(0.90, 0.70, 0.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered] = imgui.ImVec4(1.00, 0.60, 0.00, 1.00)
imgui.GetStyle().Colors[imgui.Col.TextSelectedBg] = imgui.ImVec4(1.00, 0.00, 0.00, 0.35)
imgui.GetStyle().Colors[imgui.Col.DragDropTarget] = imgui.ImVec4(1.00, 1.00, 0.00, 0.90)
imgui.GetStyle().Colors[imgui.Col.NavHighlight] = imgui.ImVec4(0.26, 0.59, 0.98, 1.00)
imgui.GetStyle().Colors[imgui.Col.NavWindowingHighlight] = imgui.ImVec4(1.00, 1.00, 1.00, 0.70)
imgui.GetStyle().Colors[imgui.Col.NavWindowingDimBg] = imgui.ImVec4(0.80, 0.80, 0.80, 0.20)
imgui.GetStyle().Colors[imgui.Col.ModalWindowDimBg] = imgui.ImVec4(0.00, 0.00, 0.00, 0.70)
end