script_name('iHelper')
script_author('ARONAKICH')
-- info
require "lib.moonloader"
local vk = require 'vkeys'
local inicfg = require 'inicfg'
local imgui_lib = require 'imgui'
local imgui = require 'imgui'
local encoding = require 'encoding'
-- libs
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
local secondary_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)
EXPORTS = {
colorThemes = {"Синяя", "Красная", "Светлая"},
SwitchColorTheme = function(theme)
local style = imgui_lib.GetStyle()
local colors = style.Colors
local clr = imgui_lib.Col
local ImVec4 = imgui_lib.ImVec4
style.WindowRounding = 2
style.WindowTitleAlign = imgui_lib.ImVec2(0.5, 0.5)
style.ChildWindowRounding = 4.0
style.FrameRounding = 3
style.ItemSpacing = imgui_lib.ImVec2(5.0, 4.0)
style.ScrollbarSize = 13.0
style.ScrollbarRounding = 0
style.GrabMinSize = 8.0
style.GrabRounding = 1.0
style.WindowPadding = imgui_lib.ImVec2(4.0, 4.0)
style.FramePadding = imgui_lib.ImVec2(3.5, 3.5)
style.ButtonTextAlign = imgui_lib.ImVec2(0.0, 0.5)
if theme == 1 or theme == nil then
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.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] = 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)
elseif theme == 2 then
colors[clr.FrameBg] = ImVec4(0.48, 0.16, 0.16, 0.54)
colors[clr.FrameBgHovered] = ImVec4(0.98, 0.26, 0.26, 0.40)
colors[clr.FrameBgActive] = ImVec4(0.98, 0.26, 0.26, 0.67)
colors[clr.TitleBg] = ImVec4(0.04, 0.04, 0.04, 1.00)
colors[clr.TitleBgActive] = ImVec4(0.48, 0.16, 0.16, 1.00)
colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
colors[clr.CheckMark] = ImVec4(0.98, 0.26, 0.26, 1.00)
colors[clr.SliderGrab] = ImVec4(0.88, 0.26, 0.24, 1.00)
colors[clr.SliderGrabActive] = ImVec4(0.98, 0.26, 0.26, 1.00)
colors[clr.Button] = ImVec4(0.98, 0.26, 0.26, 0.40)
colors[clr.ButtonHovered] = ImVec4(0.98, 0.26, 0.26, 1.00)
colors[clr.ButtonActive] = ImVec4(0.98, 0.06, 0.06, 1.00)
colors[clr.Header] = ImVec4(0.98, 0.26, 0.26, 0.31)
colors[clr.HeaderHovered] = ImVec4(0.98, 0.26, 0.26, 0.80)
colors[clr.HeaderActive] = ImVec4(0.98, 0.26, 0.26, 1.00)
colors[clr.Separator] = colors[clr.Border]
colors[clr.SeparatorHovered] = ImVec4(0.75, 0.10, 0.10, 0.78)
colors[clr.SeparatorActive] = ImVec4(0.75, 0.10, 0.10, 1.00)
colors[clr.ResizeGrip] = ImVec4(0.98, 0.26, 0.26, 0.25)
colors[clr.ResizeGripHovered] = ImVec4(0.98, 0.26, 0.26, 0.67)
colors[clr.ResizeGripActive] = ImVec4(0.98, 0.26, 0.26, 0.95)
colors[clr.TextSelectedBg] = ImVec4(0.98, 0.26, 0.26, 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.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] = 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)
elseif theme == 3 then
colors[clr.Text] = ImVec4(0.131, 0.131, 0.131, 1.000);
colors[clr.TextDisabled] = ImVec4(0.597, 0.597, 0.597, 1.000);
colors[clr.WindowBg] = ImVec4(0.15, 0.46, 0.00, 1.00);
colors[clr.ChildWindowBg] = ImVec4(1.00, 1.00, 1.00, 1.00);
colors[clr.PopupBg] = ImVec4(0.15, 0.45, 0.00, 1.00);
colors[clr.Border] = ImVec4(1.000, 1.000, 1.000, 0.000);
colors[clr.BorderShadow] = ImVec4(1.000, 1.000, 1.000, 0.000);
colors[clr.FrameBg] = ImVec4(0.19, 0.57, 0.00, 1.00);
colors[clr.FrameBgHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.FrameBgActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.TitleBg] = ImVec4(1.00, 1.00, 1.00, 0.81);
colors[clr.TitleBgActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.TitleBgCollapsed] = ImVec4(1.00, 1.00, 1.00, 0.51);
colors[clr.MenuBarBg] = ImVec4(1.00, 1.00, 1.00, 1.00);
colors[clr.ScrollbarBg] = ImVec4(0.163, 0.497, 0.000, 1.000);
colors[clr.ScrollbarGrab] = ImVec4(1.00, 1.00, 1.00, 1.00);
colors[clr.ScrollbarGrabHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.ScrollbarGrabActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.ComboBg] = ImVec4(0.15, 0.45, 0.00, 1.00);
colors[clr.CheckMark] = ImVec4(0.00, 0.00, 0.00, 1.00);
colors[clr.SliderGrab] = ImVec4(1.00, 1.00, 1.00, 1.00);
colors[clr.SliderGrabActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.Button] = ImVec4(0.19, 0.56, 0.00, 1.00);
colors[clr.ButtonHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.ButtonActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.Header] = ImVec4(0.15, 0.45, 0.00, 1.00);
colors[clr.HeaderHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.HeaderActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.Separator] = ImVec4(0.50, 0.50, 0.50, 1.00);
colors[clr.SeparatorHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.SeparatorActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.ResizeGrip] = ImVec4(0.15, 0.45, 0.00, 1.00);
colors[clr.ResizeGripHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.ResizeGripActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16);
colors[clr.CloseButtonHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.CloseButtonActive] = ImVec4(1.000, 1.000, 1.000, 1.000);
colors[clr.PlotLines] = ImVec4(0.759, 0.759, 0.759, 1.000);
colors[clr.PlotLinesHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.PlotHistogram] = ImVec4(0.23, 0.69, 0.00, 1.00);
colors[clr.PlotHistogramHovered] = ImVec4(0.237, 0.717, 0.000, 1.000);
colors[clr.TextSelectedBg] = ImVec4(0.25, 0.73, 0.00, 1.00);
colors[clr.ModalWindowDarkening] = ImVec4(0.26, 0.26, 0.26, 0.60);
end
end
}
local directIni = "moonloader\\config\\iHelper.ini"
local mainIni = inicfg.load(nil, directIni)
if mainIni == nil then
mainIni = inicfg.load({
config = {
['theme'] = 1,
}
})
inicfg.save(mainIni, directIni)
reloadScripts()
end
selected_item = imgui.ImInt()
selected_item.v = tonumber(mainIni.config.theme) - 1
local navigation = {
current = 1,
list = { u8"Настройки", u8"Основное"}
}
-- settings libs
function main()
if not isSampLoaded() or not isSampfuncsLoaded then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand("ihelper", function() main_window_state.v = not main_window_state.v end)
sampAddChatMessage("[iHelper] {FFFFFF}загружен!", 0xFFFF0000) -- code
sampAddChatMessage("[iHelper] {FFFFFF}команда активации - /ihelper", 0xFFFF0000)
imgui.SwitchContext()
EXPORTS.SwitchColorTheme(mainIni.config.theme)
while true do wait(0)
imgui.Process = main_window_state.v or secondary_window_state.v
end
end
function imgui.OnDrawFrame() -- imgui
local resX, resY = getScreenResolution()
local sizeX, sizeY = 300, 100
if main_window_state.v then
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
imgui.Begin("iHelper / Settings", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove + imgui.WindowFlags.NoCollapse)
-- tabs
for i, title in ipairs(navigation.list) do
if HeaderButton(navigation.current == i, title) then navigation.current = i end
if i ~= #navigation.list then imgui.SameLine(nil, 30) end
end
if navigation.current == 2 then
secondary_window_state.v = true
main_window_state.v = false
end
-- tabs
imgui.End()
end
if secondary_window_state.v then
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
imgui.Begin("iHelper / Main", secondary_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove + imgui.WindowFlags.NoCollapse)
-- tabs
for i, title in ipairs(navigation.list) do
if HeaderButton(navigation.current == i, title) then
navigation.current = i
end
if i ~= #navigation.list then
imgui.SameLine(nil, 30)
end
end
if navigation.current == 1 then
secondary_window_state.v = false
main_window_state.v = true
end
-- tabs
imgui.End()
end
end
HeaderButton = function(bool, str_id)
local DL = imgui.GetWindowDrawList()
local ToU32 = imgui.ColorConvertFloat4ToU32
local result = false
local label = string.gsub(str_id, "##.*$", "")
local duration = { 0.5, 0.3 }
local cols = {
idle = imgui.GetStyle().Colors[imgui.Col.TextDisabled],
hovr = imgui.GetStyle().Colors[imgui.Col.Text],
slct = imgui.GetStyle().Colors[imgui.Col.ButtonActive]
}
if not AI_HEADERBUT then AI_HEADERBUT = {} end
if not AI_HEADERBUT[str_id] then
AI_HEADERBUT[str_id] = {
color = bool and cols.slct or cols.idle,
clock = os.clock() + duration[1],
h = {
state = bool,
alpha = bool and 1.00 or 0.00,
clock = os.clock() + duration[2],
}
}
end
local pool = AI_HEADERBUT[str_id]
local degrade = function(before, after, start_time, duration)
local result = before
local timer = os.clock() - start_time
if timer >= 0.00 then
local offs = {
x = after.x - before.x,
y = after.y - before.y,
z = after.z - before.z,
w = after.w - before.w
}
result.x = result.x + ( (offs.x / duration) * timer )
result.y = result.y + ( (offs.y / duration) * timer )
result.z = result.z + ( (offs.z / duration) * timer )
result.w = result.w + ( (offs.w / duration) * timer )
end
return result
end
local pushFloatTo = function(p1, p2, clock, duration)
local result = p1
local timer = os.clock() - clock
if timer >= 0.00 then
local offs = p2 - p1
result = result + ((offs / duration) * timer)
end
return result
end
local set_alpha = function(color, alpha)
return imgui.ImVec4(color.x, color.y, color.z, alpha or 1.00)
end
imgui.BeginGroup()
local pos = imgui.GetCursorPos()
local p = imgui.GetCursorScreenPos()
imgui.TextColored(pool.color, label)
local s = imgui.GetItemRectSize()
local hovered = imgui.IsItemHovered()
local clicked = imgui.IsItemClicked()
if pool.h.state ~= hovered and not bool then
pool.h.state = hovered
pool.h.clock = os.clock()
end
if clicked then
pool.clock = os.clock()
result = true
end
if os.clock() - pool.clock <= duration[1] then
pool.color = degrade(
imgui.ImVec4(pool.color),
bool and cols.slct or (hovered and cols.hovr or cols.idle),
pool.clock,
duration[1]
)
else
pool.color = bool and cols.slct or (hovered and cols.hovr or cols.idle)
end
if pool.h.clock ~= nil then
if os.clock() - pool.h.clock <= duration[2] then
pool.h.alpha = pushFloatTo(
pool.h.alpha,
pool.h.state and 1.00 or 0.00,
pool.h.clock,
duration[2]
)
else
pool.h.alpha = pool.h.state and 1.00 or 0.00
if not pool.h.state then
pool.h.clock = nil
end
end
local max = s.x / 2
local Y = p.y + s.y + 3
local mid = p.x + max
DL:AddLine(imgui.ImVec2(mid, Y), imgui.ImVec2(mid + (max * pool.h.alpha), Y), ToU32(set_alpha(pool.color, pool.h.alpha)), 3)
DL:AddLine(imgui.ImVec2(mid, Y), imgui.ImVec2(mid - (max * pool.h.alpha), Y), ToU32(set_alpha(pool.color, pool.h.alpha)), 3)
end
imgui.EndGroup()
return result -- tabs
end