Initial commit

This commit is contained in:
pavetr
2026-03-15 14:54:49 +03:00
commit 64f8029c06
4027 changed files with 254888 additions and 0 deletions

View File

@@ -0,0 +1,423 @@
MSD.Icons48 = {
cross = Material("msd/icons/cross.png", "smooth"),
cog = Material("msd/icons/cog.png", "smooth"),
eye = Material("msd/icons/eye.png", "smooth"),
box = Material("mqs/map_markers/b5.png", "smooth"),
box_open = Material("mqs/icons/box_open.png", "smooth"),
layers = Material("msd/icons/layers.png", "smooth"),
layers_plus = Material("msd/icons/layers-plus.png", "smooth"),
layers_remove = Material("msd/icons/layers-remove.png", "smooth"),
briefcase = Material("msd/icons/briefcase.png", "smooth"),
account = Material("msd/icons/account.png", "smooth"),
account_plus = Material("msd/icons/account-plus.png", "smooth"),
account_edit = Material("msd/icons/account-edit.png", "smooth"),
account_multiple = Material("msd/icons/account-multiple.png", "smooth"),
account_convert = Material("msd/icons/account-convert.png", "smooth"),
arrow_up = Material("msd/icons/arrow_up.png", "smooth"),
arrow_down = Material("msd/icons/arrow_down.png", "smooth"),
folder_open = Material("msd/icons/folder-open.png", "smooth"),
file_document = Material("msd/icons/file-document.png", "smooth"),
menu = Material("msd/icons/menu.png", "smooth"),
dot = Material("msd/icons/dot.png", "smooth"),
pencil = Material("msd/icons/pencil.png", "smooth"),
play = Material("msd/icons/play.png", "smooth"),
plus = Material("msd/icons/plus.png", "smooth"),
back = Material("msd/icons/back.png", "smooth"),
calendar_check = Material("msd/icons/calendar-check.png", "smooth"),
playlist_edit = Material("msd/icons/playlist-edit.png", "smooth"),
seal = Material("msd/icons/seal.png", "smooth"),
save = Material("msd/icons/content-save.png", "smooth"),
copy = Material("msd/icons/content-copy.png", "smooth"),
submit = Material("msd/icons/check-decagram.png", "smooth"),
alert = Material("msd/icons/alert-circle.png", "smooth"),
arrow_down_color = Material("msd/icons/arrow_down_color.png", "smooth"),
face_agent = Material("msd/icons/face-agent.png", "smooth"),
swap = Material("msd/icons/swap.png", "smooth"),
search = Material("mqs/map_markers/c4.png", "smooth"),
tools = Material("mqs/map_markers/t1.png", "smooth"),
human_female = Material("msd/icons/human-female.png", "smooth"),
human_male = Material("msd/icons/human-male.png", "smooth"),
human_female_dance = Material("msd/icons/human-female-dance.png", "smooth"),
hand_peace_variant = Material("msd/icons/hand-peace-variant.png", "smooth"),
key = Material("msd/icons/key-variant.png", "smooth"),
key_arrow_right = Material("msd/icons/key-arrow-right.png", "smooth"),
key_link = Material("msd/icons/key-link.png", "smooth"),
key_plus = Material("msd/icons/key-plus.png", "smooth"),
key_remove = Material("msd/icons/key-remove.png", "smooth"),
key_star = Material("msd/icons/key-star.png", "smooth"),
door = Material("msd/icons/door.png", "smooth"),
car = Material("mqs/map_markers/v1.png", "smooth"),
cancel = Material("msd/icons/cancel.png", "smooth"),
reload = Material("msd/icons/reload.png", "smooth"),
reload_alert = Material("msd/icons/reload-alert.png", "smooth"),
heart = Material("msd/icons/cards-heart.png", "smooth"),
heart_outline = Material("msd/icons/cards-heart-outline.png", "smooth"),
heart_broken = Material("msd/icons/heart-broken.png", "smooth"),
heart_flash = Material("msd/icons/heart-flash.png", "smooth"),
skip_to = Material("msd/icons/debug-step-over.png", "smooth"),
food = Material("msd/icons/food.png", "smooth"),
food_off = Material("msd/icons/food-off-outline.png", "smooth"),
food_outline = Material("msd/icons/food-outline.png", "smooth"),
cash = Material("msd/icons/cash.png", "smooth"),
magazine = Material("msd/icons/magazine-pistol.png", "smooth"),
ammo = Material("mqs/icons/ammo.png", "smooth"),
armor = Material("mqs/map_markers/a1.png", "smooth"),
armor_outline = Material("mqs/map_markers/a2.png", "smooth"),
armor_broken = Material("mqs/map_markers/a4.png", "smooth"),
armor_flash = Material("mqs/map_markers/a5.png", "smooth")
}
MSD.Materials = {
vignette = Material("msd/vignette.png", "smooth"),
gradient = Material("gui/gradient", "smooth"),
gradient_right = Material("msd/gradient_right.png", "smooth"),
}
MSD.PinPoints = {
[0] = Material("mqs/icons/pin.png", "smooth"),
}
local files = file.Find("materials/mqs/map_markers/*", "GAME")
for k, v in pairs(files) do
MSD.PinPoints[k] = Material("mqs/map_markers/" .. v, "smooth")
end
MSD.ColorPresets = {Color(255, 20, 20), Color(255, 115, 0), Color(210, 255, 0), Color(0, 170, 25), Color(0, 155, 255), Color(0, 100, 200), Color(135, 0, 255), Color(255, 0, 100),}
MSD.Theme = {
["d_na"] = Color(25, 25, 26),
["d"] = Color(0, 5, 10, 165),
["m"] = Color(0, 5, 10, 120),
["l"] = Color(0, 5, 10, 85),
}
MSD.Text = {
["a"] = Color(150, 150, 150, 200),
["n"] = Color(150, 150, 150),
["d"] = Color(220, 220, 220),
["s"] = Color(235, 235, 235),
["m"] = Color(245, 245, 245),
["l"] = Color(255, 255, 255),
}
local NewFont = surface.CreateFont
for i = 0, 40 do
NewFont("MSDFont." .. 12 + i, {
font = "AdihausDIN",
extended = true,
size = 12 + i,
weight = 500
})
end
for i = 0, 20 do
NewFont("MSDFontB." .. 16 + i, {
font = "AdihausDIN",
extended = true,
size = 16 + i,
weight = 800
})
end
NewFont("MSDFont.Big", {
font = "AdihausDIN",
extended = true,
size = 45,
weight = 500
})
NewFont("MSDFont.Biger", {
font = "AdihausDIN",
extended = true,
size = 55,
weight = 500
})
function MSD.DrawBG(panel, w, h)
if MSD.Config.Blur then
MSD.Blur(panel, 1, 3, 255, 250 - MSD.Config.BgrColor.r, w, h)
else
draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.Config.BgrColor)
end
end
function MSD.DrawTexturedOutlined(x, y, w, h, mat, color, outlinewidth, ocolor)
if isstring(mat) then
mat = Material(mat)
end
surface.SetMaterial(mat)
surface.SetDrawColor(ocolor)
local steps = ( outlinewidth * 2 ) / 3
if ( steps < 1 ) then steps = 1 end
for _x = -outlinewidth, outlinewidth, steps do
for _y = -outlinewidth, outlinewidth, steps do
surface.DrawTexturedRect(x + _x, y + _y, w, h)
end
end
surface.SetDrawColor(color)
surface.DrawTexturedRect(x, y, w, h)
end
local cached_mat = {}
function MSD.DrawTexturedRect(x, y, w, h, mat, color)
if isstring(mat) then
local crc = util.CRC(mat)
if not cached_mat[crc] then
cached_mat[crc] = Material(mat, "smooth")
end
mat = cached_mat[crc]
end
surface.SetDrawColor(color)
surface.SetMaterial(mat)
surface.DrawTexturedRect(x, y, w, h)
end
function MSD.DrawTexturedRectRotated(rot, x, y, w, h, mat, color)
if isstring(mat) then
local crc = util.CRC(mat)
if not cached_mat[crc] then
cached_mat[crc] = Material(mat, "smooth")
end
mat = cached_mat[crc]
end
surface.SetDrawColor(color)
surface.SetMaterial(mat)
surface.DrawTexturedRectRotated(x, y, w, h, rot)
end
function MSD.ColorAlpha(cl, al)
local new_cl = table.Copy(cl)
new_cl.a = al
return new_cl
end
local blur = Material("pp/blurscreen")
function MSD.Blur(panel, inn, density, alpha, back_alpha, w, h)
local x, y = panel:LocalToScreen(0, 0)
surface.SetDrawColor(255, 255, 255, alpha)
surface.SetMaterial(blur)
for i = 1, 3 do
blur:SetFloat("$blur", (i / inn) * density)
blur:Recompute()
render.UpdateScreenEffectTexture()
if w and h then
render.SetScissorRect(-x, -y, x + w, y + h, true)
surface.DrawTexturedRect(-x, -y, ScrW(), ScrH())
render.SetScissorRect(0, 0, 0, 0, false)
else
surface.DrawTexturedRect(-x, -y, ScrW(), ScrH())
end
end
if back_alpha and back_alpha > 0 then
draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.ColorAlpha(color_black, back_alpha))
end
end
-- subUTF8 functions
local function SubStringGetByteCount(str, index)
local curByte = string.byte(str, index)
local byteCount = 1
if curByte == nil then
byteCount = 0
elseif curByte > 0 and curByte <= 127 then
byteCount = 1
elseif curByte >= 192 and curByte <= 223 then
byteCount = 2
elseif curByte >= 224 and curByte <= 239 then
byteCount = 3
elseif curByte >= 240 and curByte <= 247 then
byteCount = 4
end
return byteCount
end
local function SubStringGetTotalIndex(str)
local curIndex = 0
local i = 1
local lastCount = 1
repeat
lastCount = SubStringGetByteCount(str, i)
i = i + lastCount
curIndex = curIndex + 1
until (lastCount == 0)
return curIndex - 1
end
local function SubStringGetTrueIndex(str, index)
local curIndex = 0
local i = 1
local lastCount = 1
repeat
lastCount = SubStringGetByteCount(str, i)
i = i + lastCount
curIndex = curIndex + 1
until (curIndex >= index)
return i - lastCount
end
function string.subUTF8(str, startIndex, endIndex)
if startIndex < 0 then
startIndex = SubStringGetTotalIndex(str) + startIndex + 1
end
if endIndex ~= nil and endIndex < 0 then
endIndex = SubStringGetTotalIndex(str) + endIndex + 1
end
if endIndex == nil then
return string.sub(str, SubStringGetTrueIndex(str, startIndex))
else
return string.sub(str, SubStringGetTrueIndex(str, startIndex), SubStringGetTrueIndex(str, endIndex + 1) - 1)
end
end
-- Same used in DarkRP, used it here so we can use it with any gamemodes
local function CharWrap(t, w)
local a = 0
t = t:gsub(".", function(c)
a = a + surface.GetTextSize(c)
if a >= w then
a = 0
return "\n" .. c
end
return c
end)
return t, a
end
function MSD.TextWrap(text, font, w)
local total = 0
surface.SetFont(font)
local spaceSize = surface.GetTextSize(' ')
text = text:gsub("(%s?[%S]+)", function(word)
local char = string.subUTF8(word, 1, 1)
if char == "\n" or char == "\t" then
total = 0
end
local wordlen = surface.GetTextSize(word)
total = total + wordlen
if wordlen >= w then
local splitWord, splitPoint = CharWrap(word, w - (total - wordlen))
total = splitPoint
return splitWord
elseif total < w then
return word
end
if char == ' ' then
total = wordlen - spaceSize
return '\n' .. string.subUTF8(word, 2)
end
total = wordlen
return '\n' .. word
end)
local w_end, h_end = surface.GetTextSize(text)
return text, w_end, h_end
end
-- Image Lib
MSD.ImgLib = {}
MSD.ImgLib.Images = {}
MSD.ImgLib.PreCacheStarted = {}
MSD.ImgLib.Avatars = {}
MSD.ImgLib.NoMaterial = Material("msd/icons/file-hidden.png", "smooth noclamp")
function MSD.ImgLib.GetMaterial(url, jpg)
if url == "" then
return MSD.ImgLib.NoMaterial
end
local crc = util.CRC(url) .. ".png"
if jpg then
crc = util.CRC(url) .. ".jpg"
end
if MSD.ImgLib.Images[crc] then return MSD.ImgLib.Images[crc] end
if (file.Exists("msd_imgs/" .. crc, "DATA")) then
MSD.ImgLib.Images[crc] = Material("data/msd_imgs/" .. crc, "smooth noclamp")
return MSD.ImgLib.Images[crc]
else
return MSD.ImgLib.PreCacheMaterial(url, crc, jpg)
end
end
function MSD.ImgLib.PreCacheMaterial(url, crc, jpg)
if not crc then
crc = util.CRC(url) .. ".png"
end
if not file.Exists("msd_imgs", "DATA") then
file.CreateDir("msd_imgs")
end
if not MSD.ImgLib.PreCacheStarted[crc] then
MSD.ImgLib.PreCacheStarted[crc] = true
http.Fetch(url, function(body, size, headers, code)
if not jpg and (body:find("^.PNG")) then
file.Write("msd_imgs/" .. crc, body)
MSD.ImgLib.Images[crc] = Material("data/msd_imgs/" .. crc, "smooth noclamp")
return MSD.ImgLib.Images[crc]
elseif jpg then
file.Write("msd_imgs/" .. crc, body)
MSD.ImgLib.Images[crc] = Material("data/msd_imgs/" .. crc, "smooth noclamp")
else
print("Image is not a PNG, url - " .. url)
end
end, function()
print("Failed to get image, url - " .. url)
end)
end
return MSD.ImgLib.NoMaterial
end
function MSD.ImgLib.GetAvatar(crc)
crc = tostring(crc)
if not MSD.ImgLib.Avatars[crc] then
MSD.ImgLib.Avatars[crc] = ""
http.Fetch("https://macnco.one/steamid/avatar.php?input=" .. crc, function(body, size, headers, code)
MSD.ImgLib.Avatars[crc] = body
end, function()
print("Failed to get link, url - " .. url)
end)
end
return MSD.ImgLib.Avatars[crc] or ""
end

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,338 @@
local ScrW, ScrH = ScrW, ScrH
local Ln = MSD.GetPhrase
local logo = Material("msd/macnco.png", "smooth")
CreateClientConVar("mmd_lastscr", 0, true, false)
function MSD.AdminAccess(ply)
if MQS then
return MQS.IsEditor(ply)
end
if MRS then
return MRS.IsAdministrator(ply)
end
return ply:IsSuperAdmin()
end
function MSD.OpenMenuManager(parrent, mod_open)
if not MSD.AdminAccess(LocalPlayer()) then return end
if IsValid(MSD.SetupMenu) then
if not MSD.SetupMenu:IsVisible() then
MSD.SetupMenu:AlphaTo(255, 0.4)
MSD.SetupMenu:Show()
MSD.SetupMenu:Center()
return
end
if parrent then
MSD.SetupMenu:Center()
return
else
MSD.SetupMenu:Close()
end
end
local pnl_w, pnl_h = ScrW(), ScrH()
pnl_w, pnl_h = pnl_w - pnl_w / 4, pnl_h - pnl_h / 6
local panel, setbut
if parrent then
panel = parrent:Add("MSDSimpleFrame")
else
panel = vgui.Create("MSDSimpleFrame")
panel:MakePopup()
end
panel:SetSize(pnl_w, pnl_h)
panel:Center()
panel:SetAlpha(0)
panel:AlphaTo(255, 0.3)
panel.Paint = function(self, w, h)
MSD.DrawBG(self, w, h)
draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, 50, MSD.Theme["d"])
draw.RoundedBox(MSD.Config.Rounded, 0, 52, w, h - 52, MSD.Theme["l"])
end
panel.clsBut = MSD.IconButton(panel, MSD.Icons48.cross, panel:GetWide() - 34, 10, 25, nil, MSD.Config.MainColor.p, function()
if panel.OnPress then
panel.OnPress()
return
end
panel:AlphaTo(0, 0.4, 0, function()
panel:Close()
end)
end)
function panel:OnClose()
if panel.ModuleSwitch then panel.ModuleSwitch() panel.ModuleSwitch = nil end
MSD.SetupMenu = nil
end
if not parrent then
panel.clsHide = MSD.IconButton(panel, MSD.Icons48.dot, panel:GetWide() - 64, 10, 25, nil, MSD.Config.MainColor.p, function()
if panel.OnPress then
panel.OnPress()
return
end
panel:AlphaTo(0, .4, 0, function()
MSD.SetupMenu:Hide()
end)
end)
end
panel.Menu = vgui.Create("MSDPanelList", panel)
panel.Menu:SetSize(panel:GetWide() / 2, 50)
panel.Menu:SetPos(0, 0)
--panel.Menu:EnableVerticalScrollbar()
panel.Menu:EnableHorizontal(true)
panel.Menu:SetSpacing(2)
panel.Menu.IgnoreVbar = true
panel.Menu.Paint = function() end
panel.Menu.Deselect = function(but)
if not but then return end
but.hovered = true
for k, v in pairs(panel.Menu:GetItems()) do
if v and v:IsValid() and v ~= but then
v.hovered = false
end
end
end
function panel.ReOpenCanvas()
if IsValid(panel.Canvas) then panel.Canvas:Remove() end
panel.Canvas = vgui.Create("DPanel", panel)
panel.Canvas:SetSize(panel:GetWide(), panel:GetTall() - 52)
panel.Canvas:SetPos(0, 52)
panel.Canvas.Paint = function() end
end
local cnv = GetConVar("mmd_lastscr")
function panel.OpenSettings()
cnv:SetInt(-1)
panel.ReOpenCanvas()
panel.Menu.Deselect(setbut)
MSD.OpenSettingsMenu(panel.Canvas, panel)
end
for id, mod in ipairs(MSD.Modules) do
local button = MSD.MenuButtonTop(panel.Menu, mod.icon, nil, nil, "auto", 50, mod.name, function(self)
if panel.ModuleSwitch then panel.ModuleSwitch() panel.ModuleSwitch = nil end
cnv:SetInt(id)
panel.ReOpenCanvas()
panel.Menu.Deselect(self)
mod.menu(panel.Canvas, panel)
end)
if (mod_open and id == mod_open) or (cnv:GetInt() == 0 and id == 1) or cnv:GetInt() == id then
panel.ReOpenCanvas()
panel.Menu.Deselect(button)
mod.menu(panel.Canvas, panel)
end
end
setbut = MSD.MenuButtonTop(panel.Menu, MSD.Icons48.cog, nil, nil, "auto", 50, "", function(self)
panel.OpenSettings()
end)
if cnv:GetInt() == -1 and not mod_open then
panel.OpenSettings()
end
MSD.SetupMenu = panel
return panel
end
function MSD.OpenSettingsMenu(panel)
oldcfg = MSD.Config
panel.Canvas = vgui.Create("MSDPanelList", panel)
panel.Canvas:SetSize(panel:GetWide() / 2 - 5, panel:GetTall())
panel.Canvas:SetPos(panel:GetWide() / 2 + 5, 0)
panel.Canvas:EnableVerticalScrollbar()
panel.Canvas:EnableHorizontal(true)
panel.Canvas:SetSpacing(2)
panel.Canvas.IgnoreVbar = true
panel.Canvas.Paint = function() end
panel.Settings = vgui.Create("MSDPanelList", panel)
panel.Settings:SetSize(panel:GetWide() / 2, panel:GetTall() - 80)
panel.Settings:SetPos(0, 0)
panel.Settings:EnableVerticalScrollbar()
panel.Settings:EnableHorizontal(true)
panel.Settings:SetSpacing(2)
panel.Settings.IgnoreVbar = true
panel.Settings.Paint = function() end
panel.Settings.Update = function()
panel.Settings:Clear()
MSD.Header(panel.Settings, Ln("set_ui"))
local combo = MSD.ComboBox(panel.Settings, "static", nil, 1, 50, "Language:", Ln("none"))
combo.OnSelect = function(self, index, text, data)
MSD.Config.Language = data
panel.Settings.Update()
end
for k, v in pairs(MSD.Language) do
combo:AddChoice(v.lang_name, k)
end
combo:SetValue(Ln("lang_name"))
local sld1
local function sliderCL(cl)
local c = math.Clamp(math.Round(cl * 255), 30, 250)
MSD.Config.BgrColor = Color(c, c, c)
end
MSD.DTextSlider(panel.Settings, "static", nil, 1, 50, Ln("set_ui_blur"), Ln("set_ui_mono"), MSD.Config.Blur, function(self, value)
MSD.Config.Blur = value
if value then
sld1.value = 1
sliderCL(sld1.value)
else
sld1.value = 0.18
sliderCL(sld1.value)
end
end)
sld1 = MSD.VolumeSlider(panel.Settings, "static", nil, 1, 50, Ln("set_ui_brightness"), MSD.Config.BgrColor.r / 255, function(self, var)
sliderCL(var)
end)
MSD.ColorSelector(panel.Settings, "static", nil, 1, 50, Ln("set_ui_color"), MSD.Config.MainColor.p, function(self, color)
MSD.Config.MainColor.p = color
end)
MSD.DTextSlider(panel.Settings, "static", nil, 1, 50, Ln("border_rounded"), Ln("border_square"), MSD.Config.Rounded == 8, function(self, value)
if value then
MSD.Config.Rounded = 8
else
MSD.Config.Rounded = 0
end
end)
if not MSD.HUD then return end
MSD.Header(panel.Settings, Ln("set_hud"))
MSD.BoolSlider(panel.Settings, "static", nil, 1, 50, Ln("custom_icon"), MSD.Config.HUD.ShowIcon, function(self, value)
MSD.Config.HUD.ShowIcon = value
end)
MSD.TextEntry(panel.Settings, "static", nil, 1, 50, Ln("q_icon68"), Ln("e_url") .. ":", MSD.Config.HUD.Icon, function(self, value)
MSD.Config.HUD.Icon = value
end)
MSD.TextEntry(panel.Settings, "static", nil, 1, 50, Ln("e_text"), Ln("e_text") .. ":", MSD.Config.HUD.Text, function(self, value)
MSD.Config.HUD.Text = value
end)
local acombo = MSD.ComboBox(panel.Settings, "static", nil, 1, 50, "", "")
local algm = {
Ln("set_ui_align_left"),
Ln("set_ui_align_center"),
Ln("set_ui_align_right")
}
for i,t in pairs(algm) do
acombo:AddChoice(t, i - 1)
acombo:SetValue(t)
end
acombo.OnSelect = function(self, index, text, data)
MSD.Config.HUD.AlignX = data
end
local sld0, txt1, sld2, txt2
sld0 = MSD.VolumeSlider(panel.Settings, "static", nil, 1.2, 50, Ln("set_ui_offset_h"), MSD.Config.HUD.X, function(self, var)
var = math.Round(var, 3)
MSD.Config.HUD.X = var
txt1:SetText(var * 100)
end)
txt1 = MSD.TextEntry(panel.Settings, "static", nil, 6, 50, "", "", MSD.Config.HUD.X * 100, function(self, value)
value = math.Clamp((tonumber(value) or 0) / 100,0,1)
sld0.value = value
MSD.Config.HUD.X = value
end, true, nil, nil, true)
sld2 = MSD.VolumeSlider(panel.Settings, "static", nil, 1.2, 50, Ln("set_ui_offset_v"), MSD.Config.HUD.Y, function(self, var)
var = math.Round(var, 3)
MSD.Config.HUD.Y = var
txt2:SetText(var * 100)
end)
txt2 = MSD.TextEntry(panel.Settings, "static", nil, 6, 50, "", "", MSD.Config.HUD.Y * 100, function(self, value)
value = math.Clamp((tonumber(value) or 0) / 100,0,1)
sld2.value = value
MSD.Config.HUD.Y = value
end, true, nil, nil, true)
MSD.BoolSlider(panel.Settings, "static", nil, 1, 50, Ln("show_team"), MSD.Config.HUD.ShowGroup, function(self, value)
MSD.Config.HUD.ShowGroup = value
end)
MSD.BoolSlider(panel.Settings, "static", nil, 1, 50, Ln("mrs_hud_follow"), MSD.Config.HUD.Follow, function(self, value)
MSD.Config.HUD.Follow = value
end)
MSD.BoolSlider(panel.Settings, "static", nil, 1, 50, Ln("use_team_colors"), MSD.Config.HUD.TeamColor, function(self, value)
MSD.Config.TeamColor = value
end)
MSD.BoolSlider(panel.Settings, "static", nil, 1, 50, Ln("icon_right"), MSD.Config.HUD.IconRight, function(self, value)
MSD.Config.HUD.IconRight = value
end)
MSD.VolumeSlider(panel.Settings, "static", nil, 1, 50, Ln("icon_size"), (MSD.Config.HUD.IconSize - 24) / 40, function(self, var)
var = math.Round(var, 3)
MSD.Config.HUD.IconSize = math.Clamp(24 + math.Round(var * 40), 24, 64)
end)
MSD.VolumeSlider(panel.Settings, "static", nil, 1, 50, Ln("font_size"), (MSD.Config.HUD.FontSize - 16) / 30, function(self, var)
var = math.Round(var, 3)
MSD.Config.HUD.FontSize = math.Clamp(16 + math.Round(var * 30), 16, 46)
end)
end
panel.Settings.Update()
if LocalPlayer():IsSuperAdmin() then
MSD.BigButton(panel, 0, panel:GetTall() - 80, panel:GetWide() / 4, 80, Ln("upl_changes"), MSD.Icons48.save, function()
MSD.SaveConfig()
panel.Settings.Update()
end)
MSD.BigButton(panel, panel:GetWide() / 4, panel:GetTall() - 80, panel:GetWide() / 4, 80, Ln("res_changes"), MSD.Icons48.cross, function()
MSD.Config = oldcfg
panel.Settings.Update()
end)
end
local pnl = vgui.Create("DPanel")
pnl.StaticScale = {
w = 1,
h = 1,
minw = 150,
minh = 150
}
pnl.Paint = function(self, w, h)
MSD.DrawTexturedRect(w / 2 - 128, h / 2 - 128, 256, 236, logo, MSD.Text["l"])
draw.DrawText("MSD UI version - " .. MSD.Version, "MSDFont.25", w / 2, h / 2 + 130, MSD.Text["l"], TEXT_ALIGN_CENTER)
end
panel.Canvas:AddItem(pnl)
end

View File

@@ -0,0 +1,187 @@
local PANEL = {}
AccessorFunc(PANEL, "m_bIsMenuComponent", "IsMenu", FORCE_BOOL)
AccessorFunc(PANEL, "m_bDraggable", "Draggable", FORCE_BOOL)
AccessorFunc(PANEL, "m_bSizable", "Sizable", FORCE_BOOL)
AccessorFunc(PANEL, "m_bScreenLock", "ScreenLock", FORCE_BOOL)
AccessorFunc(PANEL, "m_bDeleteOnClose", "DeleteOnClose", FORCE_BOOL)
AccessorFunc(PANEL, "m_bPaintShadow", "PaintShadow", FORCE_BOOL)
AccessorFunc(PANEL, "m_iMinWidth", "MinWidth", FORCE_NUMBER)
AccessorFunc(PANEL, "m_iMinHeight", "MinHeight", FORCE_NUMBER)
function PANEL:Init()
self:SetFocusTopLevel(true)
self:SetPaintShadow(true)
self:SetDraggable(true)
self:SetSizable(false)
self:SetScreenLock(false)
self:SetDeleteOnClose(true)
self:SetMinWidth(50)
self:SetMinHeight(50)
self:SetPaintBackgroundEnabled(false)
self:SetPaintBorderEnabled(false)
self.m_fCreateTime = SysTime()
self.WorkSpace = {
x = 0,
y = 52,
w = 0,
h = 0
}
self.WorkComponents = {}
end
function PANEL:Close()
self:SetVisible(false)
if (self:GetDeleteOnClose()) then
self:Remove()
end
self:OnClose()
end
function PANEL:OnClose()
end
function PANEL:Center()
self:InvalidateLayout(true)
self:CenterVertical()
self:CenterHorizontal()
end
function PANEL:IsActive()
if (self:HasFocus()) then return true end
if (vgui.FocusedHasParent(self)) then return true end
return false
end
function PANEL:Think()
local mousex = math.Clamp(gui.MouseX(), 1, ScrW() - 1)
local mousey = math.Clamp(gui.MouseY(), 1, ScrH() - 1)
if (self.Dragging) then
local x = mousex - self.Dragging[1]
local y = mousey - self.Dragging[2]
-- Lock to screen bounds if screenlock is enabled
if (self:GetScreenLock()) then
x = math.Clamp(x, 0, ScrW() - self:GetWide())
y = math.Clamp(y, 0, ScrH() - self:GetTall())
end
self:SetPos(x, y)
end
if (self.Sizing) then
local x = mousex - self.Sizing[1]
local y = mousey - self.Sizing[2]
local px, py = self:GetPos()
if (x < self.m_iMinWidth) then
x = self.m_iMinWidth
elseif (x > ScrW() - px and self:GetScreenLock()) then
x = ScrW() - px
end
if (y < self.m_iMinHeight) then
y = self.m_iMinHeight
elseif (y > ScrH() - py and self:GetScreenLock()) then
y = ScrH() - py
end
self:SetSize(x, y)
self:SetCursor("sizenwse")
return
end
local screenX, screenY = self:LocalToScreen(0, 0)
if (self.Hovered and self.m_bSizable and mousex > (screenX + self:GetWide() - 20) and mousey > (screenY + self:GetTall() - 20)) then
self:SetCursor("sizenwse")
return
end
if (self.Hovered and self:GetDraggable() and mousey < (screenY + 24)) then
self:SetCursor("sizeall")
return
end
self:SetCursor("arrow")
-- Don't allow the frame to go higher than 0
if (self.y < 0) then
self:SetPos(self.x, 0)
end
end
function PANEL:AddToWorkSpace(panel)
panel:SetParent(self)
panel:SetSize(self.WorkSpace.w, self.WorkSpace.h)
panel:SetPos(self.WorkSpace.x, self.WorkSpace.y)
local id = table.insert(self.WorkComponents, panel)
panel.OnRemove = function()
self.WorkComponents[id] = nil
end
end
function PANEL:Paint(w, h)
return true
end
function PANEL:OnMousePressed()
local screenX, screenY = self:LocalToScreen(0, 0)
if (self.m_bSizable and gui.MouseX() > (screenX + self:GetWide() - 20) and gui.MouseY() > (screenY + self:GetTall() - 20)) then
self.Sizing = {gui.MouseX() - self:GetWide(), gui.MouseY() - self:GetTall()}
self:MouseCapture(true)
return
end
if (self:GetDraggable() and gui.MouseY() < (screenY + 24)) then
self.Dragging = {gui.MouseX() - self.x, gui.MouseY() - self.y}
self:MouseCapture(true)
return
end
end
function PANEL:OnMouseReleased()
self.Dragging = nil
self.Sizing = nil
self:MouseCapture(false)
end
function PANEL:PerformLayout()
local Wide = self:GetWide()
local Tall = self:GetTall()
self.WorkSpace = {
x = 0,
y = 52,
w = Wide,
h = Tall - 52
}
if self.WorkComponents and #self.WorkComponents > 0 then
for i = 1, #self.WorkComponents do
local panel = self.WorkComponents[i]
if panel and IsValid(panel) then
panel:SetSize(self.WorkSpace.w, self.WorkSpace.h)
panel:SetPos(self.WorkSpace.x, self.WorkSpace.y)
panel:InvalidateLayout()
end
end
end
end
derma.DefineControl("MSDSimpleFrame", "A simple window for msd", PANEL, "EditablePanel")

View File

@@ -0,0 +1,234 @@
local PANEL = {}
AccessorFunc( PANEL, "m_fAnimSpeed", "AnimSpeed" )
AccessorFunc( PANEL, "Entity", "Entity" )
AccessorFunc( PANEL, "vCamPos", "CamPos" )
AccessorFunc( PANEL, "fFOV", "FOV" )
AccessorFunc( PANEL, "vLookatPos", "LookAt" )
AccessorFunc( PANEL, "aLookAngle", "LookAng" )
AccessorFunc( PANEL, "colAmbientLight", "AmbientLight" )
AccessorFunc( PANEL, "colColor", "Color" )
AccessorFunc( PANEL, "bAnimated", "Animated" )
function PANEL:Init()
self.Entity = nil
self.SubEntitys = {}
self.LastPaint = 0
self.DirectionalLight = {}
self.FarZ = 4096
self.Angles = Angle(0, 0, 0)
self:SetCamPos( Vector(0, 0, 0) )
self:SetLookAt( Vector(-100, 0, -22) )
self:SetFOV( 50 )
self:SetText( "" )
self:SetAnimSpeed( 0.5 )
self:SetAnimated( true )
self:SetAmbientLight( Color( 50, 50, 50 ) )
self:SetDirectionalLight( BOX_TOP, Color( 255, 255, 255 ) )
self:SetDirectionalLight( BOX_FRONT, Color( 255, 255, 255 ) )
self:SetDirectionalLight(BOX_RIGHT, Color(255, 160, 80, 255))
self:SetDirectionalLight(BOX_LEFT, Color(80, 160, 255, 255))
self:SetColor( Color( 255, 255, 255, 255 ) )
end
function PANEL:SetDirectionalLight( iDirection, color )
self.DirectionalLight[ iDirection ] = color
end
function PANEL:SetModel( strModelName )
if ( IsValid( self.Entity ) ) then
self.Entity:Remove()
self.Entity = nil
end
if ( !ClientsideModel ) then return end
self.Entity = ClientsideModel( strModelName, RENDERGROUP_OTHER )
if ( !IsValid( self.Entity ) ) then return end
self.Entity:SetNoDraw( true )
self.Entity:SetIK( false )
local iSeq = self.Entity:LookupSequence( "walk_all" )
if ( iSeq <= 0 ) then iSeq = self.Entity:LookupSequence( "WalkUnarmed_all" ) end
if ( iSeq <= 0 ) then iSeq = self.Entity:LookupSequence( "walk_all_moderate" ) end
if ( iSeq > 0 ) then self.Entity:ResetSequence( iSeq ) end
end
function PANEL:GetModel()
if ( !IsValid( self.Entity ) ) then return end
return self.Entity:GetModel()
end
function PANEL:DrawModel()
local curparent = self
local leftx, topy = self:LocalToScreen( 0, 0 )
local rightx, bottomy = self:LocalToScreen( self:GetWide(), self:GetTall() )
while ( curparent:GetParent() != nil ) do
curparent = curparent:GetParent()
local x1, y1 = curparent:LocalToScreen( 0, 0 )
local x2, y2 = curparent:LocalToScreen( curparent:GetWide(), curparent:GetTall() )
leftx = math.max( leftx, x1 )
topy = math.max( topy, y1 )
rightx = math.min( rightx, x2 )
bottomy = math.min( bottomy, y2 )
previous = curparent
end
render.SetScissorRect( leftx, topy, rightx, bottomy, true )
local ret = self:PreDrawModel( self.Entity )
if ( ret != false ) then
self.Entity:DrawModel()
for k,v in pairs(self.SubEntitys) do
if IsValid(v) then
v:DrawModel()
if v.bone and isnumber(v.bone) then
local pos, ang = MCS.GetBoneOrientation(self.Entity, v.bone, v.pos, v.ang)
ang:RotateAroundAxis(ang:Up(), v.ang.y)
ang:RotateAroundAxis(ang:Right(), v.ang.p)
ang:RotateAroundAxis(ang:Forward(), v.ang.r)
v:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z)
v:SetAngles(ang)
end
end
end
self:PostDrawModel( self.Entity )
end
render.SetScissorRect( 0, 0, 0, 0, false )
end
function PANEL:PreDrawModel( ent )
return true
end
function PANEL:PostDrawModel( ent )
end
function PANEL:DragMousePress()
self.PressX, self.PressY = gui.MousePos()
self.Pressed = true
end
function PANEL:DoDoubleClick()
if self:GetFOV() < 10 then
self:SetFOV(50)
else
self:SetFOV(self:GetFOV() - 5)
end
end
function PANEL:DragMouseRelease()
self.Pressed = false
end
function PANEL:Paint( w, h )
if ( !IsValid( self.Entity ) ) then return end
local x, y = self:LocalToScreen( 0, 0 )
self:LayoutEntity( self.Entity )
local ang = self.aLookAngle
if ( !ang ) then
ang = ( self.vLookatPos - self.vCamPos ):Angle()
end
cam.Start3D( self.vCamPos, ang, self.fFOV, x, y, w, h, 5, self.FarZ )
render.SuppressEngineLighting( true )
render.SetLightingOrigin( self.Entity:GetPos() )
render.ResetModelLighting( self.colAmbientLight.r / 255, self.colAmbientLight.g / 255, self.colAmbientLight.b / 255 )
render.SetColorModulation( self.colColor.r / 255, self.colColor.g / 255, self.colColor.b / 255 )
render.SetBlend( ( self:GetAlpha() / 255 ) * ( self.colColor.a / 255 ) ) -- * surface.GetAlphaMultiplier()
for i = 0, 6 do
local col = self.DirectionalLight[ i ]
if ( col ) then
render.SetModelLighting( i, col.r / 255, col.g / 255, col.b / 255 )
end
end
self:DrawModel()
render.SuppressEngineLighting( false )
cam.End3D()
self.LastPaint = RealTime()
end
function PANEL:RunAnimation()
self.Entity:FrameAdvance( ( RealTime() - self.LastPaint ) * self.m_fAnimSpeed )
end
function PANEL:StartScene( name )
if ( IsValid( self.Scene ) ) then
self.Scene:Remove()
end
self.Scene = ClientsideScene( name, self.Entity )
end
function PANEL:LayoutEntity(ent)
if (self.bAnimated) then
self:RunAnimation()
end
if (self.Pressed) then
local mx = gui.MousePos()
self.Angles = self.Angles - Angle(0, (self.PressX or mx) - mx, 0)
self.PressX, self.PressY = gui.MousePos()
end
ent:SetAngles(self.Angles)
end
function PANEL:OnRemove()
if ( IsValid( self.Entity ) ) then
self.Entity:Remove()
end
for k,v in pairs(self.SubEntitys) do
if IsValid(v) then
v:Remove()
end
end
end
function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )
local ctrl = vgui.Create( ClassName )
ctrl:SetSize( 300, 300 )
ctrl:SetModel( "models/props_junk/PlasticCrate01a.mdl" )
ctrl:GetEntity():SetSkin( 2 )
PropertySheet:AddSheet( ClassName, ctrl, nil, true, true )
end
derma.DefineControl( "MSDModelPanel", "A panel containing a model but more epic", PANEL, "DButton" )

View File

@@ -0,0 +1,186 @@
if SERVER then return end
local tblOpenMenus = {}
function RegisterDermaMenuForClose(dmenu)
table.insert(tblOpenMenus, dmenu)
end
function MSD.MenuOpen(parentmenu, parent, bg)
if (not parentmenu) then
CloseDermaMenus()
end
local dmenu = vgui.Create("MSD.DMenu", parent)
dmenu.ShadowStatic = 0
dmenu.ShadowInt = 1
dmenu.Paint = function(self, w, h)
if bg then
draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.Theme["d_na"])
else
MSD.Blur(self, 1, 2, 255, 55, w, h)
draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.Theme["d"])
end
end
return dmenu
end
function CloseDermaMenus()
for k, dmenu in pairs(tblOpenMenus) do
if (IsValid(dmenu)) then
dmenu:SetVisible(false)
if (dmenu:GetDeleteSelf()) then
dmenu:Remove()
end
end
end
tblOpenMenus = {}
hook.Run("CloseDermaMenus")
end
local function DermaDetectMenuFocus(panel, mousecode)
if (IsValid(panel)) then
if (panel.m_bIsMenuComponent) then return end
return DermaDetectMenuFocus(panel:GetParent(), mousecode)
end
CloseDermaMenus()
end
hook.Add("VGUIMousePressed", "MatDMenuDetectMenuFocus", DermaDetectMenuFocus)
local PANEL = {}
AccessorFunc(PANEL, "m_bBorder", "DrawBorder")
AccessorFunc(PANEL, "m_bDeleteSelf", "DeleteSelf")
AccessorFunc(PANEL, "m_iMinimumWidth", "MinimumWidth")
AccessorFunc(PANEL, "m_bDrawColumn", "DrawColumn")
AccessorFunc(PANEL, "m_iMaxHeight", "MaxHeight")
AccessorFunc(PANEL, "m_pOpenSubMenu", "OpenSubMenu")
function PANEL:Init()
self:SetIsMenu(true)
self:SetDrawBorder(true)
self:SetPaintBackground(true)
self:SetMinimumWidth(100)
self:SetDrawOnTop(true)
self:SetMaxHeight(ScrH() * 0.9)
self:SetDeleteSelf(true)
self:SetPadding(0)
RegisterDermaMenuForClose(self)
end
function PANEL:AddOption(strText, funcFunction, icon, check)
if check and not check() then return end
local pnl = vgui.Create("MSD.DMenuOption", self)
pnl:SetMenu(self)
pnl:SetText(strText)
if icon then
pnl.icon = icon
pnl:SetTextInset(38, 0)
end
if (funcFunction) then
pnl.DoClick = funcFunction
end
self:AddPanel(pnl)
return pnl
end
function PANEL:AddSubMenu(strText, funcFunction)
local pnl = vgui.Create("MSD.DMenuOption", self)
local SubMenu = pnl:AddSubMenu(strText, funcFunction)
pnl:SetText(strText)
if (funcFunction) then
pnl.DoClick = funcFunction
end
self:AddPanel(pnl)
return SubMenu, pnl
end
derma.DefineControl("MSD.DMenu", "A Menu 2", PANEL, "DMenu")
PANEL = {}
AccessorFunc(PANEL, "m_pMenu", "Menu")
AccessorFunc(PANEL, "m_bChecked", "Checked")
AccessorFunc(PANEL, "m_bCheckable", "IsCheckable")
function PANEL:Init()
self:SetContentAlignment(4)
self:SetTextInset(10, 0)
self:SetFont("MSDFont.16")
self:SetTextColor(MSD.Text["s"])
self:SetChecked(false)
self.ChangeCC = true
self.ColorText = MSD.Text["s"]
end
function PANEL:OnCursorEntered()
self.ColorText = MSD.Config.MainColor["p"]
self.ChangeCC = true
if (IsValid(self.ParentMenu)) then
self.ParentMenu:OpenSubMenu(self, self.SubMenu)
return
end
self:GetParent():OpenSubMenu(self, self.SubMenu)
end
function PANEL:OnCursorExited()
self.ColorText = MSD.Text["l"]
self.ChangeCC = true
end
function PANEL:AddSubMenu()
local SubMenu = MSD.MenuOpen(true, self)
SubMenu:SetVisible(false)
SubMenu:SetParent(self)
self:SetSubMenu(SubMenu)
return SubMenu
end
function PANEL:Paint(w, h)
if self.ChangeCC then
self:SetTextColor(self.ColorText)
self.ChangeCC = nil
end
if self.icon then
local ih = h - 6
MSD.DrawTexturedRect(5, 3, ih, ih, self.icon, self.ColorText)
end
end
function PANEL:PerformLayout( w, h )
self:SizeToContents()
self:SetWide( self:GetWide() + 30 )
w = math.max( self:GetParent():GetWide(), self:GetWide() )
self:SetSize( w, self.icon and 30 or 22 )
if ( IsValid( self.SubMenuArrow ) ) then
self.SubMenuArrow:SetSize( 15, 15 )
self.SubMenuArrow:CenterVertical()
self.SubMenuArrow:AlignRight( 4 )
end
DButton.PerformLayout( self, w, h )
end
derma.DefineControl("MSD.DMenuOption", "Menu Option Line 2", PANEL, "DMenuOption")

View File

@@ -0,0 +1,413 @@
local PANEL = {}
AccessorFunc(PANEL, "m_bSizeToContents", "AutoSize")
AccessorFunc(PANEL, "m_bStretchHorizontally", "StretchHorizontally")
AccessorFunc(PANEL, "m_bNoSizing", "NoSizing")
AccessorFunc(PANEL, "m_bSortable", "Sortable")
AccessorFunc(PANEL, "m_fAnimTime", "AnimTime")
AccessorFunc(PANEL, "m_fAnimEase", "AnimEase")
AccessorFunc(PANEL, "m_strDraggableName", "DraggableName")
AccessorFunc(PANEL, "Spacing", "Spacing")
AccessorFunc(PANEL, "Padding", "Padding")
function PANEL:Init()
self:SetDraggableName("GlobalDPanel")
self.pnlCanvas = vgui.Create("DPanel", self)
self.pnlCanvas:SetPaintBackground(false)
self.pnlCanvas.OnMousePressed = function(s, code)
s:GetParent():OnMousePressed(code)
end
self.pnlCanvas.OnChildRemoved = function()
self:OnChildRemoved()
end
self.pnlCanvas:SetMouseInputEnabled(true)
self.pnlCanvas.InvalidateLayout = function()
self:InvalidateLayout()
end
self.pnlCanvas.MasterPanel = self
self.Items = {}
self.YOffset = 0
self.m_fAnimTime = 0
self.m_fAnimEase = -1
self.m_iBuilds = 0
self.IgnoreVbar = true
self:SetSpacing(0)
self:SetPadding(0)
self:EnableHorizontal(false)
self:SetAutoSize(false)
self:SetPaintBackground(true)
self:SetNoSizing(false)
self:SetMouseInputEnabled(true)
self:SetPaintBackgroundEnabled(false)
self:SetPaintBorderEnabled(false)
end
function PANEL:OnModified()
-- Override me
end
function PANEL:SizeToContents()
self:SetSize(self.pnlCanvas:GetSize())
end
function PANEL:GetItems()
return self.Items
end
function PANEL:EnableHorizontal(bHoriz)
self.Horizontal = bHoriz
end
local sdw = Color(0, 0, 0, 70)
function PANEL:EnableVerticalScrollbar()
if (self.VBar) then return end
self.VBar = vgui.Create("DVScrollBar", self)
self.VBar.Paint = function(s, w, h)
draw.RoundedBox(4, 3, 13, 8, h - 24, sdw)
end
self.VBar.btnUp.Paint = function(s, w, h) end
self.VBar.btnDown.Paint = function(s, w, h) end
self.VBar.btnGrip.Paint = function(s, w, h)
draw.RoundedBox(4, 5, 0, 4, h + 22, sdw)
end
end
function PANEL:GetCanvas()
return self.pnlCanvas
end
function PANEL:Clear(nDelete)
for k, panel in pairs(self.Items) do
if (not IsValid(panel)) then continue end
panel:Remove()
if (nDelete) then
panel:SetVisible(false)
end
end
self.Items = {}
end
function PANEL:ClearEX(ex_panel)
if (not IsValid(ex_panel)) then return end
for k, panel in pairs(self.Items) do
if (not IsValid(panel)) then continue end
if (panel ~= ex_panel) then
panel:Remove()
end
end
self.Items = {}
table.insert(self.Items, ex_panel)
end
function PANEL:AddItem(item, strLineState)
if (not IsValid(item)) then return end
item:SetVisible(true)
item:SetParent(self:GetCanvas())
item.m_strLineState = strLineState or item.m_strLineState
table.insert(self.Items, item)
item:SetSelectable(self.m_bSelectionCanvas)
self:InvalidateLayout()
end
function PANEL:InsertBefore(before, insert, strLineState)
table.RemoveByValue(self.Items, insert)
self:AddItem(insert, strLineState)
local key = table.KeyFromValue(self.Items, before)
if (key) then
table.RemoveByValue(self.Items, insert)
table.insert(self.Items, key, insert)
end
end
function PANEL:InsertAfter(before, insert, strLineState)
table.RemoveByValue(self.Items, insert)
self:AddItem(insert, strLineState)
local key = table.KeyFromValue(self.Items, before)
if (key) then
table.RemoveByValue(self.Items, insert)
table.insert(self.Items, key + 1, insert)
end
end
function PANEL:InsertAtTop(insert, strLineState)
table.RemoveByValue(self.Items, insert)
self:AddItem(insert, strLineState)
local key = 1
if (key) then
table.RemoveByValue(self.Items, insert)
table.insert(self.Items, key, insert)
end
end
function PANEL.DropAction(Slot, RcvSlot)
local PanelToMove = Slot.Panel
if (dragndrop.m_MenuData == "copy") then
if (PanelToMove.Copy) then
PanelToMove = Slot.Panel:Copy()
PanelToMove.m_strLineState = Slot.Panel.m_strLineState
else
return
end
end
PanelToMove:SetPos(RcvSlot.Data.pnlCanvas:ScreenToLocal(gui.MouseX() - dragndrop.m_MouseLocalX, gui.MouseY() - dragndrop.m_MouseLocalY))
if (dragndrop.DropPos == 4 or dragndrop.DropPos == 8) then
RcvSlot.Data:InsertBefore(RcvSlot.Panel, PanelToMove)
else
RcvSlot.Data:InsertAfter(RcvSlot.Panel, PanelToMove)
end
end
function PANEL:RemoveItem(item, bDontDelete)
for k, panel in pairs(self.Items) do
if (panel == item) then
self.Items[k] = nil
if (not bDontDelete) then
panel:Remove()
end
self:InvalidateLayout()
end
end
end
function PANEL:CleanList()
for k, panel in pairs(self.Items) do
if (not IsValid(panel) or panel:GetParent() ~= self.pnlCanvas) then
self.Items[k] = nil
end
end
end
function PANEL:HorizontalRebuild(Offset)
local x, y = self.Padding, self.Padding
local l_highest = 0
for k, panel in pairs(self.Items) do
if (panel:IsVisible()) then
if panel.StaticScale then
local w, h
if isstring(panel.StaticScale.w) then
w = tonumber(panel.StaticScale.w)
w = (self.pnlCanvas:GetWide() - (self.pnlCanvas:GetWide() / w)) - (self.Spacing + self.Padding)
elseif panel.StaticScale.w == 1 then
w = self.pnlCanvas:GetWide() / panel.StaticScale.w - (self.Spacing + self.Padding)
else
w = self.pnlCanvas:GetWide() / panel.StaticScale.w - (self.Spacing + self.Padding) / 1.5
end
if panel.StaticScale.fixed_h then
h = panel.StaticScale.fixed_h
elseif panel.StaticScale.h_w then
h = w
elseif panel.StaticScale.h then
if isstring(panel.StaticScale.h) then
h = tonumber(panel.StaticScale.h)
h = (self:GetTall() - (self:GetTall() / h)) - (self.Spacing + self.Spacing / h + self.Padding)
elseif panel.StaticScale.h == 1 then
h = self:GetTall() / panel.StaticScale.h - (self.Spacing + self.Padding)
else
h = self:GetTall() / panel.StaticScale.h - (self.Spacing + self.Padding)
end
end
if panel.StaticScale.minw > w then
w = panel.StaticScale.minw
end
if panel.StaticScale.h and panel.StaticScale.minh > h then
h = panel.StaticScale.minh
end
panel:SetSize(w, h)
end
local OwnLine = (panel.m_strLineState and panel.m_strLineState == "ownline")
local w = panel:GetWide()
local h = panel:GetTall()
local vbar = 0
if (self.VBar and self.VBar.Enabled and not self.IgnoreVbar) then
vbar = 13
end
if (x > self.Padding and (x + w > (self:GetWide() - vbar) or OwnLine)) then
x = self.Padding
y = y + l_highest + self.Spacing
l_highest = h
end
if h > l_highest then
l_highest = h
end
if (self.m_fAnimTime > 0 and self.m_iBuilds > 1) then
panel:MoveTo(x, y, self.m_fAnimTime, 0, self.m_fAnimEase)
else
panel:SetPos(x, y)
end
x = x + w + self.Spacing
Offset = y + l_highest + self.Spacing
if (OwnLine) then
x = self.Padding
y = y + h + self.Spacing
end
end
end
return Offset
end
function PANEL:NormalRebuild(Offset)
for k, panel in pairs(self.Items) do
if (panel:IsVisible()) then
if (self.m_bNoSizing) then
panel:SizeToContents()
if (self.m_fAnimTime > 0 and self.m_iBuilds > 1) then
panel:MoveTo((self:GetCanvas():GetWide() - panel:GetWide()) * 0.5, self.Padding + Offset, self.m_fAnimTime, 0, self.m_fAnimEase)
else
panel:SetPos((self:GetCanvas():GetWide() - panel:GetWide()) * 0.5, self.Padding + Offset)
end
else
panel:SetWide(self:GetCanvas():GetWide() - self.Padding * 2)
if (self.m_fAnimTime > 0 and self.m_iBuilds > 1) then
panel:MoveTo(self.Padding, self.Padding + Offset, self.m_fAnimTime, self.m_fAnimEase)
else
panel:SetPos(self.Padding, self.Padding + Offset)
end
end
panel:InvalidateLayout(true)
Offset = Offset + panel:GetTall() + self.Spacing
end
end
Offset = Offset + self.Padding
return Offset
end
function PANEL:Rebuild()
local Offset = 0
self.m_iBuilds = self.m_iBuilds + 1
self:CleanList()
if (self.Horizontal) then
Offset = self:HorizontalRebuild(Offset)
else
Offset = self:NormalRebuild(Offset)
end
self:GetCanvas():SetTall(Offset + self.Padding - self.Spacing)
if (self.m_bNoSizing and self:GetCanvas():GetTall() < self:GetTall()) then
self:GetCanvas():SetPos(0, (self:GetTall() - self:GetCanvas():GetTall()) * 0.5)
end
end
function PANEL:OnMouseWheeled(dlta)
if (self.VBar) then return self.VBar:OnMouseWheeled(dlta) end
end
function PANEL:Paint(w, h)
derma.SkinHook("Paint", "PanelList", self, w, h)
return true
end
function PANEL:OnVScroll(iOffset)
self.pnlCanvas:SetPos(0, iOffset)
end
function PANEL:PerformLayout()
local Wide = self:GetWide()
local Tall = self.pnlCanvas:GetTall()
local YPos = 0
if (not self.Rebuild) then
debug.Trace()
end
self:Rebuild()
if (self.VBar) then
self.VBar:SetPos(self:GetWide() - 13, 0)
self.VBar:SetSize(13, self:GetTall())
self.VBar:SetUp(self:GetTall(), self.pnlCanvas:GetTall())
YPos = self.VBar:GetOffset()
if not self.IgnoreVbar then
Wide = Wide - 13
end
end
self.pnlCanvas:SetPos(0, YPos)
self.pnlCanvas:SetWide(Wide)
if (self:GetAutoSize()) then
self:SetTall(self.pnlCanvas:GetTall())
self.pnlCanvas:SetPos(0, 0)
end
if (self.VBar and not self:GetAutoSize() and Tall ~= self.pnlCanvas:GetTall()) then
self.VBar:SetScroll(self.VBar:GetScroll())
end
end
function PANEL:OnChildRemoved()
self:CleanList()
self:InvalidateLayout()
end
function PANEL:ScrollToChild(panel)
local _, y = self.pnlCanvas:GetChildPosition(panel)
local _, h = panel:GetSize()
y = y + h * 0.5
y = y - self:GetTall() * 0.5
self.VBar:AnimateTo(y, 0.5, 0, 0.5)
end
function PANEL:SortByMember(key, desc)
desc = desc or true
table.sort(self.Items, function(a, b)
if (desc) then
local ta = a
local tb = b
a = tb
b = ta
end
if (a[key] == nil) then return false end
if (b[key] == nil) then return true end
return a[key] > b[key]
end)
end
derma.DefineControl("MSDPanelList", "Fancy DpanelList", PANEL, "DPanel")