diff --git a/lua/msd/sh_config.lua b/lua/msd/sh_config.lua index 1d1c1b6..43bcc67 100644 --- a/lua/msd/sh_config.lua +++ b/lua/msd/sh_config.lua @@ -73,32 +73,42 @@ end --──────────────────────────────────-- ------------- CFG Saving ------------- --──────────────────────────────────-- -net.Receive("MSD.GetConfigData", function(l, ply) - if CLIENT then - local config = net.ReadTable() - MSD.Config = config - else - net.Start("MSD.GetConfigData") +local function SendConfig(ply) + net.Start("MSD.GetConfigData") net.WriteTable(MSD.Config) - net.Send(ply) - end -end) + net.Send(ply) +end -MSD.SaveConfig = function() - if CLIENT then +if CLIENT then + net.Receive("MSD.GetConfigData", function() + MSD.Config = net.ReadTable() + end) +else + local Received = {} + + net.Receive("MSD.GetConfigData", function(l, ply) + if Received[ply] then return end + Received[ply] = true + + SendConfig(ply) + end) +end + +if CLIENT then + MSD.SaveConfig = function() local json_data = util.TableToJSON(MSD.Config, false) local cd = util.Compress(json_data) local bn = string.len(cd) + net.Start("MSD.SaveConfig") net.WriteInt(bn, 32) net.WriteData(cd, bn) net.SendToServer() - else - net.Start("MSD.GetConfigData") - net.WriteTable(MSD.Config) - net.Broadcast() - json_table = util.TableToJSON(MSD.Config, true) - file.Write("msd_data/config.txt", json_table) + end +else + MSD.SaveConfig = function() + SendConfig(ply) + file.Write("msd_data/config.txt", util.TableToJSON(MSD.Config, true)) end end @@ -106,26 +116,28 @@ function MSD.LoadConfig() if CLIENT then net.Start("MSD.GetConfigData") net.SendToServer() - end - - if SERVER then - net.Receive("MSD.SaveConfig", function(l, ply) - if MSD.cfgLastChange and MSD.cfgLastChange > CurTime() then return end - MSD.cfgLastChange = CurTime() + 1 - if not ply:IsSuperAdmin() then return end - local bytes_number = net.ReadInt(32) - local compressed_data = net.ReadData(bytes_number) + else + local function SaveConfig() + local compressed_data = net.ReadData(net.ReadInt(32)) local json_data = util.Decompress(compressed_data) local config = util.JSONToTable(json_data) MSD.Config = config MSD.SaveConfig() + end + + net.Receive("MSD.SaveConfig", function(l, ply) + if ply:IsSuperAdmin() == false then return end + + if timer.Exists("MSD.SaveConfig") then + timer.Create("MSD.SaveConfig", 1, 2, SaveConfig) + else + timer.Create("MSD.SaveConfig", 1, 2, function() end) + SaveConfig() + end end) - if not file.Exists("msd_data/config.txt", "DATA") then - json_table = util.TableToJSON(MSD.Config, true) - file.Write("msd_data/config.txt", json_table) - else + if file.Exists("msd_data/config.txt", "DATA") then local config = util.JSONToTable(file.Read("msd_data/config.txt", "DATA")) for k, v in pairs(config) do @@ -133,11 +145,14 @@ function MSD.LoadConfig() MSD.Config[k] = v end end - if #player.GetAll() > 0 then + + if #player.GetHumans() > 0 then net.Start("MSD.GetConfigData") - net.WriteTable(MSD.Config) + net.WriteTable(MSD.Config) net.Broadcast() end + else + file.Write("msd_data/config.txt", util.TableToJSON(MSD.Config, true)) end end end @@ -154,4 +169,4 @@ end if GAMEMODE then MSD.LoadConfig() -end \ No newline at end of file +end diff --git a/lua/msd/ui/elements.lua b/lua/msd/ui/elements.lua index e075d19..1bcc7f2 100644 --- a/lua/msd/ui/elements.lua +++ b/lua/msd/ui/elements.lua @@ -1,5 +1,5 @@ function MSD.WorkSpacePanel(parent, title, wd, hd, a_ignore) - if not wd or not hd then + if not (wd and hd) then wd, hd = 1.1, 1.3 end @@ -21,9 +21,10 @@ function MSD.WorkSpacePanel(parent, title, wd, hd, a_ignore) end) end - panel.PerformLayout = function(self) - local children = self:GetChildren() + + panel.PerformLayout = function(self) + local children = self:GetChildren() for k, v in pairs(children) do v:InvalidateLayout() end @@ -78,11 +79,7 @@ function MSD.IconButton(parent, mat, x, y, s, color, color2, func) button.mat = mat button.Paint = function(self, w, h) - if self.hover or self.hovered then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, (self.hover or self.hovered) and 1 or 0) MSD.DrawTexturedRect(0, 0, w, h, self.mat, MSD.ColorAlpha(color or MSD.Text.l, 255 - self.alpha * 255)) @@ -105,7 +102,7 @@ function MSD.IconButton(parent, mat, x, y, s, color, color2, func) button.DoRightClick = func - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -136,22 +133,21 @@ function MSD.IconButtonText(parent, text, mat, x, y, s, color, color2, func) button.mat = mat button.Paint = function(self, w, h) - if self.hover or self.hovered then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, (self.hover or self.hovered) and 1 or 0) - MSD.DrawTexturedRect(w / 2 - s / 2, 0, s, s, self.mat, MSD.ColorAlpha(color or MSD.Text.d, 255 - self.alpha * 255)) + MSD.DrawTexturedRect(w * 0.5 - s * 0.5, 0, s, s, self.mat, MSD.ColorAlpha(color or MSD.Text.d, 255 - self.alpha * 255)) if self.alpha > 0 then - MSD.DrawTexturedRect(w / 2 - s / 2, 0, s, s, self.mat, MSD.ColorAlpha(color2 or MSD.Config.MainColor["p"], self.alpha * 255)) + MSD.DrawTexturedRect(w * 0.5 - s * 0.5, 0, s, s, self.mat, MSD.ColorAlpha(color2 or MSD.Config.MainColor["p"], self.alpha * 255)) end - draw.DrawText(MSD.TextWrap(self:GetText(), "MSDFont.16", w - 4), "MSDFont.16", w / 2, s, color or MSD.Text.d, TEXT_ALIGN_CENTER) + draw.DrawText(self.Text, "MSDFont.16", w * 0.5, s, color or MSD.Text.d, TEXT_ALIGN_CENTER) return true end + button.PerformLayout = function(self, w) + self.Text = MSD.TextWrap(self:GetText(), "MSDFont.16", w - 4) + end button.DoClick = func @@ -165,7 +161,7 @@ function MSD.IconButtonText(parent, text, mat, x, y, s, color, color2, func) button.DoRightClick = func - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -187,11 +183,7 @@ function MSD.IconButtonBG(parent, mat, x, y, s, color, color2, func) button.mat = mat button.Paint = function(self, w, h) - if self.hover or self.hovered then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, (self.hover or self.hovered) and 1 or 0) draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.Theme.d) @@ -199,7 +191,7 @@ function MSD.IconButtonBG(parent, mat, x, y, s, color, color2, func) draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.ColorAlpha(MSD.Config.MainColor["p"], 255 * self.alpha)) end - MSD.DrawTexturedRect(w / 2 - 12, h / 2 - 12, 24, 24, self.mat, color_white) + MSD.DrawTexturedRect(w * 0.5 - 12, h * 0.5 - 12, 24, 24, self.mat, color_white) return true end @@ -243,17 +235,13 @@ function MSD.MenuButton(parent, mat, x, y, sw, sh, text, func, rfunc, small) draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.Theme["d"]) end - if self.hover then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, self.hover and 1 or 0) local rf = MSD.Config.Rounded if self.alpha > 0.01 then draw.RoundedBox(rf, rf, rf, math.max((w - rf * 2) * self.alpha, icon_size + 12 - rf), h - rf * 2, MSD.ColorAlpha(MSD.Config.MainColor["p"], 255 * self.alpha)) end - MSD.DrawTexturedRect(small and h / 2 - rf or 10, small and h / 2 - rf or 10, icon_size, icon_size, self.mat, color_white) + MSD.DrawTexturedRect(small and h * 0.5 - rf or 10, small and h * 0.5 - rf or 10, icon_size, icon_size, self.mat, color_white) draw.DrawText(text, "MSDFont.22", 55, 12, color_white, TEXT_ALIGN_LEFT) return true @@ -309,17 +297,13 @@ function MSD.MenuButtonTop(parent, mat, x, y, sw, sh, text, func, rfunc, small) draw.RoundedBox(rf, 0, 0, w, h, MSD.Theme["d"]) end - if self.hover then - self.alpha = Lerp(FrameTime() * 7, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 7, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 7, self.alpha, self.hover and 1 or 0) if self.alpha > 0.01 then draw.RoundedBoxEx(rf, rf, h - 5, w - rf * 2, 5 + rf, MSD.ColorAlpha(MSD.Config.MainColor["p"], 255 * self.alpha), true, true, false, false) end - MSD.DrawTexturedRect(small and h / 2 - rf or 10, small and h / 2 - rf or 10, icon_size, icon_size, self.mat, color_white) + MSD.DrawTexturedRect(small and h * 0.5 - rf or 10, small and h * 0.5 - rf or 10, icon_size, icon_size, self.mat, color_white) draw.DrawText(text, "MSDFont.22", 55, 12, color_white, TEXT_ALIGN_LEFT) return true @@ -356,7 +340,7 @@ function MSD.Header(parent, text, back, icon, align) panel.Paint = function(self, w, h) draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.Theme["l"]) - draw.DrawText(text, "MSDFont.25", align and 50 or w / 2, 12, color_white, align and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) + draw.DrawText(text, "MSDFont.25", align and 50 or w * 0.5, 12, color_white, align and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) end parent:AddItem(panel) @@ -380,7 +364,7 @@ function MSD.InfoHeader(parent, text, wd) panel.Paint = function(self, w, h) draw.RoundedBox(MSD.Config.Rounded, 0, 0, w, h, MSD.Theme["l"]) - draw.DrawText(text, "MSDFont.20", 5, h / 2 - 11, color_white, TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.20", 5, h * 0.5 - 11, color_white, TEXT_ALIGN_LEFT) end parent:AddItem(panel) @@ -399,8 +383,11 @@ function MSD.InfoText(parent, text) } panel.Paint = function(self, w, h) + draw.DrawText(self.Text, "MSDFont.18", 5, 5, MSD.Text.d, TEXT_ALIGN_LEFT) + end + panel.PerformLayout = function(self, w, h) local ts, _, th = MSD.TextWrap(text, "MSDFont.18", w - 10) - draw.DrawText(ts, "MSDFont.18", 5, 5, MSD.Text.d, TEXT_ALIGN_LEFT) + self.Text = ts if th > h then self.StaticScale.fixed_h = th + 10 @@ -439,18 +426,14 @@ function MSD.TextEntry(parent, x, y, w, h, text, label, value, func, auto_update Entry:SetDrawLanguageID(false) Entry.Paint = function(self, wd, hd) - if self:HasFocus() then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 255) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, self:HasFocus() and 255 or 0) local rf = MSD.Config.Rounded draw.RoundedBox(rf, 0, 0, wd, hd, MSD.Theme["l"]) draw.RoundedBox(0, rf, hd - 1, wd - rf * 2, 1, MSD.ColorAlpha(MSD.Text["n"], 255 - self.alpha)) draw.RoundedBox(0, rf, hd - 1, wd - rf * 2, 1, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha)) if self:GetValue() == "" then - draw.SimpleText(text, "MSDFont.22", 3, multi and 1 or hd / 2 - 10, MSD.ColorAlpha(MSD.Text["d"], 120), TEXT_ALIGN_LEFT) + draw.SimpleText(text, "MSDFont.22", 3, multi and 1 or hd * 0.5 - 10, MSD.ColorAlpha(MSD.Text["d"], 120), TEXT_ALIGN_LEFT) end if label and not self.error then @@ -486,7 +469,7 @@ function MSD.TextEntry(parent, x, y, w, h, text, label, value, func, auto_update end end - if not x or not y then + if not (x and y) then parent:AddItem(Entry) end @@ -515,7 +498,7 @@ function MSD.VectorDisplay(parent, x, y, w, h, text, vector, func) draw.SimpleText(text, "MSDFont.16", 3, 0, MSD.ColorAlpha(MSD.Text["d"], 120), TEXT_ALIGN_LEFT) end - draw.SimpleText("x: " .. self.vector.x .. " y: " .. self.vector.y .. " z: " .. self.vector.z, "MSDFont.22", 3, h / 2 - 10, MSD.Text["d"], TEXT_ALIGN_LEFT) + draw.SimpleText("x: " .. self.vector.x .. " y: " .. self.vector.y .. " z: " .. self.vector.z, "MSDFont.22", 3, h * 0.5 - 10, MSD.Text["d"], TEXT_ALIGN_LEFT) end Entry.DoClick = function(self) @@ -569,7 +552,7 @@ function MSD.VectorDisplay(parent, x, y, w, h, text, vector, func) end, true, nil, false, true) end - if not x or not y then + if not (x and y) then parent:AddItem(Entry) end @@ -599,7 +582,7 @@ function MSD.AngleDisplay(parent, x, y, w, h, text, angle, func) draw.SimpleText(text, "MSDFont.16", 3, 0, MSD.ColorAlpha(MSD.Text["d"], 120), TEXT_ALIGN_LEFT) end - draw.SimpleText("p: " .. self.angle.p .. " y: " .. self.angle.y .. " r: " .. self.angle.r, "MSDFont.22", 3, h / 2 - 10, MSD.Text["d"], TEXT_ALIGN_LEFT) + draw.SimpleText("p: " .. self.angle.p .. " y: " .. self.angle.y .. " r: " .. self.angle.r, "MSDFont.22", 3, h * 0.5 - 10, MSD.Text["d"], TEXT_ALIGN_LEFT) end Entry.DoClick = function(self) @@ -653,7 +636,7 @@ function MSD.AngleDisplay(parent, x, y, w, h, text, angle, func) end, true, nil, false, true) end - if not x or not y then + if not (x and y) then parent:AddItem(Entry) end @@ -685,11 +668,7 @@ function MSD.ColorSelectBut(parent, x, y, w, h, color, func) button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, color) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) return true end @@ -706,7 +685,7 @@ function MSD.ColorSelectBut(parent, x, y, w, h, color, func) func(self) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -745,10 +724,10 @@ function MSD.Binder(parent, x, y, w, h, text, var, func) self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) end - draw.DrawText(text, "MSDFont.22", 5, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(text, "MSDFont.22", 5, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(string.upper(self:GetText()), "MSDFont.22", wd - wd / 3 / 2, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_CENTER) - draw.DrawText(string.upper(self:GetText()), "MSDFont.22", wd - wd / 3 / 2, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_CENTER) + draw.DrawText(text, "MSDFont.22", 5, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.22", 5, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(string.upper(self:GetText()), "MSDFont.22", wd - wd / 3 * 0.5, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_CENTER) + draw.DrawText(string.upper(self:GetText()), "MSDFont.22", wd - wd / 3 * 0.5, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_CENTER) draw.RoundedBox(0, rf, hd - 1, (wd / 3) * 2 - 5 - rf, 1, MSD.ColorAlpha(MSD.Text["n"], 255 - self.alpha * 255)) draw.RoundedBox(0, rf, hd - 1, (wd / 3) * 2 - 5 - rf, 1, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255)) draw.RoundedBox(0, wd - wd / 3, hd - 1, wd / 3 - rf, 1, MSD.ColorAlpha(MSD.Text["n"], 255 - self.alpha * 255)) @@ -773,7 +752,7 @@ function MSD.Binder(parent, x, y, w, h, text, var, func) end end - if not x or not y then + if not (x and y) then parent:AddItem(binder) end end @@ -801,20 +780,18 @@ function MSD.ButtonScr(parent, x, y, w, h, text, func, al_left) button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(MSD.TextWrap(self:GetText(), "MSDFont.18", w - 20), "MSDFont.18", al_left and 5 or wd / 2, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) - draw.DrawText(MSD.TextWrap(self:GetText(), "MSDFont.18", w - 20), "MSDFont.18", al_left and 5 or wd / 2, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) + draw.DrawText(self.Text, "MSDFont.18", al_left and 5 or wd * 0.5, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) + draw.DrawText(self.Text, "MSDFont.18", al_left and 5 or wd * 0.5, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) draw.RoundedBox(MSD.Config.Rounded, 0, hd - 1, wd, 1, MSD.ColorAlpha(MSD.Text["l"], 255 - self.alpha * 255)) draw.RoundedBox(MSD.Config.Rounded, 0, hd - 1, wd, 1, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255)) return true end + button.PerformLayout = function(self, w) + self.Text = MSD.TextWrap(self:GetText(), "MSDFont.18", w - 20) + end button.OnCursorEntered = function(self) self.hover = true @@ -828,7 +805,7 @@ function MSD.ButtonScr(parent, x, y, w, h, text, func, al_left) func(self) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -859,15 +836,10 @@ function MSD.Button(parent, x, y, w, h, text, func, al_left) button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(self:GetText(), "MSDFont.22", al_left and 5 or wd / 2, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) - draw.DrawText(self:GetText(), "MSDFont.22", al_left and 5 or wd / 2, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) + draw.DrawText(self:GetText(), "MSDFont.22", al_left and 5 or wd * 0.5, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) + draw.DrawText(self:GetText(), "MSDFont.22", al_left and 5 or wd * 0.5, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), al_left and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(MSD.Text["n"], 255 - self.alpha * 255)) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255)) @@ -886,7 +858,7 @@ function MSD.Button(parent, x, y, w, h, text, func, al_left) func(self) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -919,9 +891,9 @@ function MSD.ButtonSimple(parent, x, y, w, h, text, fsize, func) end if (self.hover or self.hovered) and not self.disabled then - draw.DrawText(self:GetText(), "MSDFont." .. fsize, 5, hd / 2 - fsize / 2, MSD.Config.MainColor["p"], TEXT_ALIGN_LEFT) + draw.DrawText(self:GetText(), "MSDFont." .. fsize, 5, hd * 0.5 - fsize * 0.5, MSD.Config.MainColor["p"], TEXT_ALIGN_LEFT) else - draw.DrawText(self:GetText(), "MSDFont." .. fsize, 5, hd / 2 - fsize / 2, self.disabled and MSD.Text["n"] or MSD.Text["s"], TEXT_ALIGN_LEFT) + draw.DrawText(self:GetText(), "MSDFont." .. fsize, 5, hd * 0.5 - fsize * 0.5, self.disabled and MSD.Text["n"] or MSD.Text["s"], TEXT_ALIGN_LEFT) end return true end @@ -938,7 +910,7 @@ function MSD.ButtonSimple(parent, x, y, w, h, text, fsize, func) func(self) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -971,11 +943,7 @@ function MSD.NumberWang(parent, x, y, w, h, min, max, val, label, func) button:SetMax(max) button.Paint = function(self, wd, hd) - if self:HasFocus() then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 255) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, self:HasFocus() and 255 or 0) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(MSD.Text["n"], 255 - self.alpha)) @@ -998,7 +966,7 @@ function MSD.NumberWang(parent, x, y, w, h, min, max, val, label, func) func(self) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1031,19 +999,14 @@ function MSD.ButtonIcon(parent, x, y, w, h, text, icon, func, func2, color, colo draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) if drawf then drawf(self, wd, hd) end + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(self:GetText(), "MSDFont.22", 48, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(self:GetText(), "MSDFont.22", 48, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self:GetText(), "MSDFont.22", 48, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self:GetText(), "MSDFont.22", 48, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(color or MSD.Text["n"], 255 - self.alpha * 255)) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(color2 or MSD.Config.MainColor["p"], self.alpha * 255)) - MSD.DrawTexturedRect(12, hd / 2 - 12, 24, 24, icon, MSD.ColorAlpha(color or MSD.Text["l"], 255 - self.alpha * 255)) - MSD.DrawTexturedRect(12, hd / 2 - 12, 24, 24, icon, MSD.ColorAlpha(color2 or MSD.Config.MainColor["p"], self.alpha * 255)) + MSD.DrawTexturedRect(12, hd * 0.5 - 12, 24, 24, icon, MSD.ColorAlpha(color or MSD.Text["l"], 255 - self.alpha * 255)) + MSD.DrawTexturedRect(12, hd * 0.5 - 12, 24, 24, icon, MSD.ColorAlpha(color2 or MSD.Config.MainColor["p"], self.alpha * 255)) return true end @@ -1068,7 +1031,7 @@ function MSD.ButtonIcon(parent, x, y, w, h, text, icon, func, func2, color, colo end end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1100,20 +1063,15 @@ function MSD.ButtonIconText(parent, x, y, w, h, text, text2, icon, func, func2, button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(self.text, "MSDFont.22", wd - 5, hd / 2 - 11, self.disabled and MSD.Text["n"] or MSD.Text["s"], TEXT_ALIGN_RIGHT) - draw.DrawText(self:GetText(), "MSDFont.22", 48, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(self:GetText(), "MSDFont.22", 48, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self.text, "MSDFont.22", wd - 5, hd * 0.5 - 11, self.disabled and MSD.Text["n"] or MSD.Text["s"], TEXT_ALIGN_RIGHT) + draw.DrawText(self:GetText(), "MSDFont.22", 48, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self:GetText(), "MSDFont.22", 48, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(color or MSD.Text["n"], 255 - self.alpha * 255)) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255)) - MSD.DrawTexturedRect(12, hd / 2 - 12, 24, 24, icon, MSD.ColorAlpha(color or MSD.Text["l"], 255 - self.alpha * 255)) - MSD.DrawTexturedRect(12, hd / 2 - 12, 24, 24, icon, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255)) + MSD.DrawTexturedRect(12, hd * 0.5 - 12, 24, 24, icon, MSD.ColorAlpha(color or MSD.Text["l"], 255 - self.alpha * 255)) + MSD.DrawTexturedRect(12, hd * 0.5 - 12, 24, 24, icon, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255)) return true end @@ -1138,7 +1096,7 @@ function MSD.ButtonIconText(parent, x, y, w, h, text, text2, icon, func, func2, end end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1172,23 +1130,18 @@ function MSD.VolumeSlider(parent, x, y, w, h, text, var, func, cl) button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(text, "MSDFont.22", 3, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(text, "MSDFont.22", 3, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.22", 3, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.22", 3, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) self.var = Lerp(FrameTime() * 7, self.var, self.value) - draw.RoundedBox(MSD.Config.Rounded, wd - wd / 2 + 10, hd / 2 - 10, wd / 2 - 20, 20, MSD.Theme["d"]) + draw.RoundedBox(MSD.Config.Rounded, wd - wd * 0.5 + 10, hd * 0.5 - 10, wd * 0.5 - 20, 20, MSD.Theme["d"]) if self.disabled then - draw.DrawText(MSD.GetPhrase("disabled"), "MSDFont.16", wd - (wd / 2) / 2, hd / 2 - 8, MSD.Text["n"], TEXT_ALIGN_CENTER) + draw.DrawText(MSD.GetPhrase("disabled"), "MSDFont.16", wd - (wd * 0.5) * 0.5, hd * 0.5 - 8, MSD.Text["n"], TEXT_ALIGN_CENTER) else - draw.RoundedBox(MSD.Config.Rounded, wd - wd / 2 + 10, hd / 2 - 10, math.max((wd / 2 - 19) * self.var, 16), 20, cl or MSD.Config.MainColor["p"]) - draw.DrawText(math.Round(self.value * 100) .. "%", "MSDFont.16", wd - (wd / 2) / 2, hd / 2 - 8, MSD.Text["s"], TEXT_ALIGN_CENTER) + draw.RoundedBox(MSD.Config.Rounded, wd - wd * 0.5 + 10, hd * 0.5 - 10, math.max((wd * 0.5 - 19) * self.var, 16), 20, cl or MSD.Config.MainColor["p"]) + draw.DrawText(math.Round(self.value * 100) .. "%", "MSDFont.16", wd - (wd * 0.5) * 0.5, hd * 0.5 - 8, MSD.Text["s"], TEXT_ALIGN_CENTER) end end @@ -1206,13 +1159,13 @@ function MSD.VolumeSlider(parent, x, y, w, h, text, var, func, cl) local mx, my = gui.MousePos() mx, my = self:ScreenToLocal(mx, my) - if mx < wd - wd / 2 + 10 then + if mx < wd - wd * 0.5 + 10 then self.value = 0 elseif mx > wd - 10 then self.value = 1 else - mx = mx - ((wd - wd / 2) + 10) - mx = mx / ((wd / 2) - 20) + mx = mx - ((wd - wd * 0.5) + 10) + mx = mx / ((wd * 0.5) - 20) self.value = mx end @@ -1220,7 +1173,7 @@ function MSD.VolumeSlider(parent, x, y, w, h, text, var, func, cl) func(self, self.value) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1254,23 +1207,18 @@ function MSD.VolumeScale(parent, x, y, w, h, text, var, func, cl) button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(text, "MSDFont.22", 3, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(text, "MSDFont.22", 3, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.22", 3, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.22", 3, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) self.var = Lerp(FrameTime() * 7, self.var, self.value) - draw.RoundedBox(MSD.Config.Rounded, wd - wd / 2 + 10, hd / 2 - 10, wd / 2 - 20, 20, MSD.Theme["d"]) + draw.RoundedBox(MSD.Config.Rounded, wd - wd * 0.5 + 10, hd * 0.5 - 10, wd * 0.5 - 20, 20, MSD.Theme["d"]) if self.disabled then - draw.DrawText(MSD.GetPhrase("disabled"), "MSDFont.16", wd - (wd / 2) / 2, hd / 2 - 8, MSD.Text["n"], TEXT_ALIGN_CENTER) + draw.DrawText(MSD.GetPhrase("disabled"), "MSDFont.16", wd - (wd * 0.5) * 0.5, hd * 0.5 - 8, MSD.Text["n"], TEXT_ALIGN_CENTER) else - draw.RoundedBox(MSD.Config.Rounded, wd - wd / 2 + 10, hd / 2 - 10, (wd / 2 - 19) * ( self.var / 2), 20, cl or MSD.Config.MainColor["p"]) - draw.DrawText(math.Round(self.value * 100) .. "%", "MSDFont.16", wd - (wd / 2) / 2, hd / 2 - 8, MSD.Text["s"], TEXT_ALIGN_CENTER) + draw.RoundedBox(MSD.Config.Rounded, wd - wd * 0.5 + 10, hd * 0.5 - 10, (wd * 0.5 - 19) * ( self.var * 0.5), 20, cl or MSD.Config.MainColor["p"]) + draw.DrawText(math.Round(self.value * 100) .. "%", "MSDFont.16", wd - (wd * 0.5) * 0.5, hd * 0.5 - 8, MSD.Text["s"], TEXT_ALIGN_CENTER) end end @@ -1288,13 +1236,13 @@ function MSD.VolumeScale(parent, x, y, w, h, text, var, func, cl) local mx, my = gui.MousePos() mx, my = self:ScreenToLocal(mx, my) - if mx < wd - wd / 2 + 10 then + if mx < wd - wd * 0.5 + 10 then self.value = 1 elseif mx > wd - 10 then self.value = 2 else - mx = mx - ((wd - wd / 2) + 10) - mx = mx / ((wd / 2) - 20) * 2 + mx = mx - ((wd - wd * 0.5) + 10) + mx = mx / ((wd * 0.5) - 20) * 2 self.value = math.Clamp(mx, 0.01, 2) end @@ -1302,7 +1250,7 @@ function MSD.VolumeScale(parent, x, y, w, h, text, var, func, cl) func(self, self.value) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1336,15 +1284,10 @@ function MSD.BoolSlider(parent, x, y, w, h, text, var, func) button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(text, "MSDFont.22", 3, hd / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(text, "MSDFont.22", 3, hd / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.22", 3, hd * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(text, "MSDFont.22", 3, hd * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) if self.var then self.pos = Lerp(0.1, self.pos, 1) @@ -1352,15 +1295,15 @@ function MSD.BoolSlider(parent, x, y, w, h, text, var, func) self.pos = Lerp(0.1, self.pos, 0) end - draw.RoundedBox(MSD.Config.Rounded, wd - 75, hd / 2 - 10, 68, 20, MSD.Theme["d"]) + draw.RoundedBox(MSD.Config.Rounded, wd - 75, hd * 0.5 - 10, 68, 20, MSD.Theme["d"]) if self.disabled then - draw.DrawText(MSD.GetPhrase("disabled"), "MSDFont.16", wd - 40, hd / 2 - 8, MSD.Text["n"], TEXT_ALIGN_CENTER) + draw.DrawText(MSD.GetPhrase("disabled"), "MSDFont.16", wd - 40, hd * 0.5 - 8, MSD.Text["n"], TEXT_ALIGN_CENTER) else - draw.DrawText(MSD.GetPhrase("off"), "MSDFont.16", wd - 25, hd / 2 - 8, MSD.ColorAlpha(MSD.Text["s"], 255 - self.pos * 255), TEXT_ALIGN_CENTER) - draw.DrawText(MSD.GetPhrase("on"), "MSDFont.16", wd - 60, hd / 2 - 8, MSD.ColorAlpha(MSD.Text["s"], self.pos * 255), TEXT_ALIGN_CENTER) - draw.RoundedBox(MSD.Config.Rounded, wd - 75 + self.pos * 35, hd / 2 - 10, 34, 20, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.pos * 255)) - draw.RoundedBox(MSD.Config.Rounded, wd - 75 + self.pos * 35, hd / 2 - 10, 34, 20, MSD.ColorAlpha(MSD.Text["n"], 255 - self.pos * 255)) + draw.DrawText(MSD.GetPhrase("off"), "MSDFont.16", wd - 25, hd * 0.5 - 8, MSD.ColorAlpha(MSD.Text["s"], 255 - self.pos * 255), TEXT_ALIGN_CENTER) + draw.DrawText(MSD.GetPhrase("on"), "MSDFont.16", wd - 60, hd * 0.5 - 8, MSD.ColorAlpha(MSD.Text["s"], self.pos * 255), TEXT_ALIGN_CENTER) + draw.RoundedBox(MSD.Config.Rounded, wd - 75 + self.pos * 35, hd * 0.5 - 10, 34, 20, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.pos * 255)) + draw.RoundedBox(MSD.Config.Rounded, wd - 75 + self.pos * 35, hd * 0.5 - 10, 34, 20, MSD.ColorAlpha(MSD.Text["n"], 255 - self.pos * 255)) end end @@ -1378,7 +1321,7 @@ function MSD.BoolSlider(parent, x, y, w, h, text, var, func) func(self, self.var) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1412,15 +1355,10 @@ function MSD.DTextSlider(parent, x, y, w, h, text1, text2, var, func) button.Paint = function(self, wd, hd) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end - - draw.DrawText(self.var and text1 or text2, "MSDFont.22", 3, hd / 2 - 10, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(self.var and text1 or text2, "MSDFont.22", 3, hd / 2 - 10, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self.var and text1 or text2, "MSDFont.22", 3, hd * 0.5 - 10, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self.var and text1 or text2, "MSDFont.22", 3, hd * 0.5 - 10, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) if self.var then self.pos = Lerp(0.1, self.pos, 1) @@ -1428,8 +1366,8 @@ function MSD.DTextSlider(parent, x, y, w, h, text1, text2, var, func) self.pos = Lerp(0.1, self.pos, 0) end - draw.RoundedBox(MSD.Config.Rounded, wd - 75, hd / 2 - 10, 68, 20, MSD.Theme["d"]) - draw.RoundedBox(MSD.Config.Rounded, wd - 75 + self.pos * 35, hd / 2 - 10, 34, 20, MSD.Config.MainColor["p"]) + draw.RoundedBox(MSD.Config.Rounded, wd - 75, hd * 0.5 - 10, 68, 20, MSD.Theme["d"]) + draw.RoundedBox(MSD.Config.Rounded, wd - 75 + self.pos * 35, hd * 0.5 - 10, 34, 20, MSD.Config.MainColor["p"]) end button.OnCursorEntered = function(self) @@ -1446,7 +1384,7 @@ function MSD.DTextSlider(parent, x, y, w, h, text1, text2, var, func) func(self, self.var) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1479,16 +1417,12 @@ function MSD.ComboBox(parent, x, y, w, h, label, val) ComboBox:SetTextColor(MSD.Text["s"]) ComboBox.Paint = function(self, wd, hd) - if ( self:IsMenuOpen() or self.pressed ) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 255) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, (( self:IsMenuOpen() or self.pressed ) and not self.disabled) and 255 or 0) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["l"]) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha)) draw.RoundedBox(0, MSD.Config.Rounded, hd - 1, wd - MSD.Config.Rounded * 2, 1, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha)) - draw.SimpleText(self:GetText(), "MSDFont.22", 3, hd / 2 - 10, self.disabled and MSD.Text["n"] or MSD.Text["d"], TEXT_ALIGN_LEFT) + draw.SimpleText(self:GetText(), "MSDFont.22", 3, hd * 0.5 - 10, self.disabled and MSD.Text["n"] or MSD.Text["d"], TEXT_ALIGN_LEFT) if label and not self.error then draw.SimpleText(label, "MSDFont.16", 3, 0, MSD.ColorAlpha(MSD.Text["d"], 120), TEXT_ALIGN_LEFT) @@ -1528,7 +1462,7 @@ function MSD.ComboBox(parent, x, y, w, h, label, val) self.Menu:Open(mx, my, false, self) end - if not x or not y then + if not (x and y) then parent:AddItem(ComboBox) end @@ -1559,22 +1493,18 @@ function MSD.BigButton(parent, x, y, w, h, text, icon, func, color, text2, func2 button.color_idle = color_white button.Paint = function(self, wd, hd) - if self.hover and not self.disable then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, (self.hover and not self.disable) and 1 or 0) draw.RoundedBox(MSD.Config.Rounded, 0, 0, wd, hd, MSD.Theme["d"]) if func3 then func3(self, wd, hd) end - MSD.DrawTexturedRect(wd / 2 - 24, hd / 2 - 36, 48, 48, icon, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255)) - draw.DrawText(text, "MSDFont.25", wd / 2, hd / 2 + 10, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255), TEXT_ALIGN_CENTER) + MSD.DrawTexturedRect(wd * 0.5 - 24, hd * 0.5 - 36, 48, 48, icon, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255)) + draw.DrawText(text, "MSDFont.25", wd * 0.5, hd * 0.5 + 10, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255), TEXT_ALIGN_CENTER) if self.alpha > 0.01 then - MSD.DrawTexturedRect(wd / 2 - 24, hd / 2 - 36, 48, 48, icon, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255)) - draw.DrawText(text, "MSDFont.25", wd / 2, hd / 2 + 10, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_CENTER) + MSD.DrawTexturedRect(wd * 0.5 - 24, hd * 0.5 - 36, 48, 48, icon, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255)) + draw.DrawText(text, "MSDFont.25", wd * 0.5, hd * 0.5 + 10, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_CENTER) end if text2 then @@ -1582,7 +1512,7 @@ function MSD.BigButton(parent, x, y, w, h, text, icon, func, color, text2, func2 end if text3 then - draw.DrawText(text3, "MSDFont.20", wd / 2, hd - 20, MSD.Text.n, TEXT_ALIGN_CENTER) + draw.DrawText(text3, "MSDFont.20", wd * 0.5, hd - 20, MSD.Text.n, TEXT_ALIGN_CENTER) end end @@ -1604,7 +1534,7 @@ function MSD.BigButton(parent, x, y, w, h, text, icon, func, color, text2, func2 func2(self) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1636,14 +1566,10 @@ function MSD.ColorSelector(parent, x, y, w, h, text, color, func, alpha_chl) button.Paint = function(self, sw, sh) draw.RoundedBox(MSD.Config.Rounded, 0, 0, sw, sh, MSD.Theme["l"]) - if (self.hover or self.hovered) and not self.disabled then - self.alpha = Lerp(FrameTime() * 5, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 5, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 5, self.alpha, ((self.hover or self.hovered) and not self.disabled) and 1 or 0) - draw.DrawText(self:GetText(), "MSDFont.22", 5, h / 2 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) - draw.DrawText(self:GetText(), "MSDFont.22", 5, h / 2 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self:GetText(), "MSDFont.22", 5, h * 0.5 - 11, MSD.ColorAlpha(MSD.Config.MainColor["p"], self.alpha * 255), TEXT_ALIGN_LEFT) + draw.DrawText(self:GetText(), "MSDFont.22", 5, h * 0.5 - 11, MSD.ColorAlpha(self.disabled and MSD.Text["n"] or MSD.Text["s"], 255 - self.alpha * 255), TEXT_ALIGN_LEFT) if not self.disabled then draw.RoundedBox(MSD.Config.Rounded, sw - sw / 8, 0, sw / 8, h-1, button.color) end @@ -1728,7 +1654,7 @@ function MSD.ColorSelector(parent, x, y, w, h, text, color, func, alpha_chl) self.AlphaBar = vgui.Create( "DAlphaBar", self.cpanel) self.AlphaBar:SetPos( 30, 5 ) self.AlphaBar:SetSize( 20, 190 ) - self.AlphaBar:SetValue( button.color.a / 255 ) + self.AlphaBar:SetValue( button.color.a * 0.555 ) self.AlphaBar.OnChange = function(pn, al) button.color.a = al * 255 UpdateColors(button.color) @@ -1773,14 +1699,14 @@ function MSD.ColorSelector(parent, x, y, w, h, text, color, func, alpha_chl) if not ignore[self.red] then self.red:SetText(col.r) end if not ignore[self.green] then self.green:SetText(col.g) end if not ignore[self.blue] then self.blue:SetText(col.b) end - if self.AlphaBar and not ignore[self.AlphaBar] then self.AlphaBar:SetValue( col.a / 255 ) end + if self.AlphaBar and not ignore[self.AlphaBar] then self.AlphaBar:SetValue( col.a * 0.555 ) end UpdateColors(col) end SetColors(self.color, {}) end - if not x or not y then + if not (x and y) then parent:AddItem(button) end @@ -1900,26 +1826,27 @@ function MSD.NPCModelFrame(parent, x, y, w, h, model, anim) end end - if not x or not y then + if not (x and y) then parent:AddItem(icon) end return icon end +local static = {static = true} function MSD.BigModelButton(parent, x, y, wd, hd, text, icon, func, text2, tr, color, func2) local pnl = vgui.Create("DPanel") if x and y then pnl:SetParent(parent) pnl:SetPos(x, y) end - if x == "static" then + if static[x] then -- прикольная группа была раньше кста pnl.StaticScale = { w = wd, fixed_h = hd, minw = 150, minh = hd } else pnl:SetSize(wd, hd) end pnl.Paint = function() - if not IsValid(pnl.Icon.Entity) then return end + if pnl.Icon.Entity == NULL then return end local ent_color = pnl.Icon:GetColor() ent_color.a = pnl:GetAlpha() end @@ -1939,9 +1866,7 @@ function MSD.BigModelButton(parent, x, y, wd, hd, text, icon, func, text2, tr, c pnl.Icon = vgui.Create("DModelPanel", pnl) pnl.Icon:SetModel("") pnl.Icon:SetMouseInputEnabled(false) - function pnl.Icon:LayoutEntity(Entity) - return - end + function pnl.Icon:LayoutEntity(Entity) end local button = vgui.Create("DButton", pnl) button:SetText("") @@ -1949,25 +1874,22 @@ function MSD.BigModelButton(parent, x, y, wd, hd, text, icon, func, text2, tr, c button.color_idle = color_white button.text = text button.Paint = function(self, w, h) - if self.hover and not self.disable then - self.alpha = Lerp(FrameTime() * 7, self.alpha, 1) - else - self.alpha = Lerp(FrameTime() * 7, self.alpha, 0) - end + self.alpha = Lerp(FrameTime() * 7, self.alpha, (self.hover and not self.disable) and 1 or 0) + local mida = pnl.Iconmdl and not tr draw.RoundedBox(0, 0, 0, w, h, MSD.Theme["d"]) if not pnl.Iconmdl then - MSD.DrawTexturedRect(w / 2 - 24, h / 2 - 36, 48, 48, icon, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255)) + MSD.DrawTexturedRect(w * 0.5 - 24, h * 0.5 - 36, 48, 48, icon, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255)) else draw.RoundedBox(0, 0, 0, w * self.alpha, h, MSD.Theme["l"]) end - draw.DrawText(button.text, "MSDFont.25", w / 2, mida and h / 2 - 12 or h - 30, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255), mida and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) - if text2 then draw.DrawText(text2, "MSDFont.21", w / 2, h / 2 + 12 , self.color_idle, TEXT_ALIGN_LEFT) end + draw.DrawText(button.text, "MSDFont.25", w * 0.5, mida and h * 0.5 - 12 or h - 30, MSD.ColorAlpha(self.color_idle, 255 - self.alpha * 255), mida and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) + if text2 then draw.DrawText(text2, "MSDFont.21", w * 0.5, h * 0.5 + 12 , self.color_idle, TEXT_ALIGN_LEFT) end if self.alpha > 0.01 then - if not pnl.Iconmdl then MSD.DrawTexturedRect(w / 2 - 24, h / 2 - 36, 48, 48, icon, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255)) end - draw.DrawText(button.text, "MSDFont.25", w / 2, mida and h / 2 - 12 or h - 30, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255), mida and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) + if not pnl.Iconmdl then MSD.DrawTexturedRect(w * 0.5 - 24, h * 0.5 - 36, 48, 48, icon, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255)) end + draw.DrawText(button.text, "MSDFont.25", w * 0.5, mida and h * 0.5 - 12 or h - 30, MSD.ColorAlpha(color or MSD.Config.MainColor["p"], self.alpha * 255), mida and TEXT_ALIGN_LEFT or TEXT_ALIGN_CENTER) end end button.OnCursorEntered = function(self) self.hover = true end @@ -1978,12 +1900,12 @@ function MSD.BigModelButton(parent, x, y, wd, hd, text, icon, func, text2, tr, c function pnl:PerformLayout() self.button:StretchToParent( 0, 0, 0, 0 ) local mida = pnl.Iconmdl and not tr - if not mida then - self.Icon:StretchToParent( 5, 5, 5, 5 ) + if mida then + self.Icon:StretchToParent( 5, 5, self:GetWide() * 0.5, 5 ) else - self.Icon:StretchToParent( 5, 5, self:GetWide() / 2, 5 ) + self.Icon:StretchToParent( 5, 5, 5, 5 ) end end - if not x or not y then parent:AddItem(pnl) end + if not (x and y) then parent:AddItem(pnl) end return pnl -end \ No newline at end of file +end