From d2a86b2182a833ee62f6d87223ca9d40e34495c0 Mon Sep 17 00:00:00 2001
From: Linventif <linventif@gmail.com>
Date: Sun, 31 Mar 2024 15:50:04 +0200
Subject: [PATCH] add: better color menu

---
 lua/gmod_integration/client/cl__color.lua   | 26 +++++++++++++++++++++
 lua/gmod_integration/client/cl_gui_link.lua | 26 ++++-----------------
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/lua/gmod_integration/client/cl__color.lua b/lua/gmod_integration/client/cl__color.lua
index d29eaf2..083b933 100644
--- a/lua/gmod_integration/client/cl__color.lua
+++ b/lua/gmod_integration/client/cl__color.lua
@@ -20,4 +20,30 @@ local colorTbl = {
 
 function gmInte.getColor(name)
     return colorTbl[name]
+end
+
+function gmInte.applyPaint(element, id)
+    if (element.DoClick) then
+        element:SetTextColor(gmInte.getColor("font"))
+
+        element.Paint = function(self, w, h)
+            local color = gmInte.getColor("primary")
+
+            if (self:IsHovered()) then
+                color = gmInte.getColor("primary-active")
+            end
+
+            draw.RoundedBox(0, 0, 0, w, h, color)
+        end
+    elseif (element.SetTitle) then
+        element.Paint = function(self, w, h)
+            draw.RoundedBox(0, 0, 0, w, h, gmInte.getColor("background"))
+            // first 20px = title bar = primary
+            draw.RoundedBox(0, 0, 0, w, 22, gmInte.getColor("primary"))
+        end
+    end
+end
+
+function gmInte.getFrameName(name)
+    return "Gmod Integration v" .. gmInte.config.version .. " - " .. name
 end
\ No newline at end of file
diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua
index 968e140..6df4ae2 100644
--- a/lua/gmod_integration/client/cl_gui_link.lua
+++ b/lua/gmod_integration/client/cl_gui_link.lua
@@ -6,9 +6,7 @@ function gmInte.openVerifPopup()
     frame:SetDraggable(false)
     frame:ShowCloseButton(false)
     frame:MakePopup()
-    frame.Paint = function(self, w, h)
-        draw.RoundedBox(8, 0, 0, w, h, gmInte.getColor("background"))
-    end
+    gmInte.applyPaint(frame)
 
     local messageLabel = vgui.Create("DLabel", frame)
     messageLabel:Dock(FILL)
@@ -31,15 +29,8 @@ function gmInte.openVerifPopup()
         gui.OpenURL("https://verif.gmod-integration.com")
     end
     button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight())
+    gmInte.applyPaint(button)
     buttonGrid:AddItem(button)
-    button:SetTextColor(Color(255, 255, 255))
-    button.Paint = function(self, w, h)
-        local color = gmInte.getColor("primary")
-        if self:IsHovered() then
-            color = gmInte.getColor("primary-active")
-        end
-        draw.RoundedBox(8, 0, 0, w, h, color)
-    end
 
     local button = vgui.Create("DButton")
     button:SetText("Refresh Verification")
@@ -48,18 +39,11 @@ function gmInte.openVerifPopup()
             gmInte.SendNet("verifyMe")
             frame:Close()
         end,
-        function(err)
-            LocalPlayer():ChatPrint("Failed to refresh verification: " .. err)
+        function(code, body)
+            LocalPlayer():ChatPrint("Failed to refresh verification: " .. code)
         end)
     end
     button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight())
+    gmInte.applyPaint(button)
     buttonGrid:AddItem(button)
-    button:SetTextColor(Color(255, 255, 255))
-    button.Paint = function(self, w, h)
-        local color = gmInte.getColor("primary")
-        if self:IsHovered() then
-            color = gmInte.getColor("primary-active")
-        end
-        draw.RoundedBox(8, 0, 0, w, h, color)
-    end
 end
\ No newline at end of file