From 2b87f3b849c604f3e4854dbb83e8b01c556b47c2 Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Mon, 30 Dec 2019 20:38:46 +0100 Subject: [PATCH] Began custom tooltip functions & other major stuff --- gamemode/engine/core/client/cl_hud.lua | 7 +++ gamemode/engine/derma/cl_menu.lua | 3 +- .../engine/derma/lib/cl_menu_iteminfo.lua | 45 +++++++++++++++++++ gamemode/engine/derma/lib/cl_menu_theme.lua | 10 ++++- gamemode/engine/derma/menus/menu_charinfo.lua | 34 ++++++++++++-- 5 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 gamemode/engine/derma/lib/cl_menu_iteminfo.lua diff --git a/gamemode/engine/core/client/cl_hud.lua b/gamemode/engine/core/client/cl_hud.lua index 0353511..e47e9e9 100644 --- a/gamemode/engine/core/client/cl_hud.lua +++ b/gamemode/engine/core/client/cl_hud.lua @@ -55,7 +55,14 @@ function GM:HUDPaint() end end end +end +function GM:Think() + if( Quantum.Client.IsInMenu ) then + if( gui.IsGameUIVisible() ) then -- hides the main menu for the player + gui.HideGameUI() + end + end end hook.Add( "RenderScreenspaceEffects", "Quantum_HUD_RenderLowHealth", function() diff --git a/gamemode/engine/derma/cl_menu.lua b/gamemode/engine/derma/cl_menu.lua index 024bc49..296a018 100644 --- a/gamemode/engine/derma/cl_menu.lua +++ b/gamemode/engine/derma/cl_menu.lua @@ -13,7 +13,8 @@ local libs = { ["theme"] = GM.FolderName .. "/gamemode/engine/derma/lib/cl_menu_theme.lua", ["dialogue"] = GM.FolderName .. "/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua", ["sure"] = GM.FolderName .. "/gamemode/engine/derma/lib/cl_menu_areusure.lua", - ["fade"] = GM.FolderName .. "/gamemode/engine/derma/lib/cl_menu_fade.lua" + ["fade"] = GM.FolderName .. "/gamemode/engine/derma/lib/cl_menu_fade.lua", + ["iteminfo"] = GM.FolderName .. "/gamemode/engine/derma/lib/cl_menu_iteminfo.lua" } Quantum.Client.Menu.GetAPI = function( lib ) return include( libs[lib] ) end diff --git a/gamemode/engine/derma/lib/cl_menu_iteminfo.lua b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua new file mode 100644 index 0000000..a0559fd --- /dev/null +++ b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua @@ -0,0 +1,45 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +local iteminfo = {} + +local scale = Quantum.Client.ResolutionScale +local padding = math.Round( 10 * scale ) +local padding_s = math.Round( 4 * scale ) + +local theme = Quantum.Client.Menu.GetAPI( "theme" ) + +function iteminfo.givetooltip( p ) + local item = p:GetParent().item + local parWidth, parHeight = p:GetParent():GetSize() + local amountStr = "" + + local tooltip = vgui.Create( "DPanel" ) + tooltip:SetSize( 100 * scale, 80 * scale ) + tooltip:SetVisible( false ) + tooltip.Paint = function( self ) + theme.itemtooltip( self, item ) + end + + if( item.amount > 1 ) then amountStr = "x" .. tostring( item.amount ) end + + p.ItemInfoPanel = tooltip -- set the tooltip + + p.Think = function( self ) + self.ItemInfoPanel:SetVisible( self:IsHovered() ) + if( self:IsHovered() ) then + self.ItemInfoPanel:SetPos( gui.MouseX(), gui.MouseY() - ( parHeight + padding )*2 ) + end + end + + --p:SetToolTip( item.name .. " " .. amountStr .. "\n\n" .. item.desc ) + --p:SetTooltipPanel( tooltip ) + --p.pnlTooltipPanel = tooltip -- overwrite the default tooltip + --p.strTooltipText = "" +end + +return iteminfo \ No newline at end of file diff --git a/gamemode/engine/derma/lib/cl_menu_theme.lua b/gamemode/engine/derma/lib/cl_menu_theme.lua index 476a285..362f8ea 100644 --- a/gamemode/engine/derma/lib/cl_menu_theme.lua +++ b/gamemode/engine/derma/lib/cl_menu_theme.lua @@ -137,14 +137,22 @@ end function theme.itempanel( p, rarecolor ) local w, h = p:GetSize() + local icon = p.icon || p + surface.SetDrawColor( rarecolor || Color( 0, 0, 0, 120 ) ) surface.DrawRect( 0, 0, w, h ) - if( p:IsHovered() ) then + if( icon:IsHovered() ) then theme.borderpanel( p, Color( 116, 185, 255, 90 ) ) else theme.borderpanel( p, Color( 255, 255, 255, 200 ) ) end end +function theme.itemtooltip( p, item ) + local w, h = p:GetSize() + surface.SetDrawColor( Color( 0, 0, 0, 255 ) ) + surface.DrawRect( 0, 0, w, h ) +end + return theme \ No newline at end of file diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index ffee61d..f05bc5e 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -8,8 +8,8 @@ local menu = {} local snm = Quantum.Client.Menu.GetAPI( "net" ) -local page = Quantum.Client.Menu.GetAPI( "page" ) local theme = Quantum.Client.Menu.GetAPI( "theme" ) +local iteminfo = Quantum.Client.Menu.GetAPI( "iteminfo" ) local resScale = Quantum.Client.ResolutionScale local sw, sh = ScrW(), ScrH() @@ -113,7 +113,10 @@ function menu.open( dt ) itempanels[ii] = vgui.Create( "DPanel", itemframe ) itempanels[ii].index = ii -- set the vars - if( items[ii] ) then itempanels[ii].item = Quantum.Item.Get( items[ii][1] ) end -- get the items info through its id + if( items[ii] ) then + itempanels[ii].item = Quantum.Item.Get( items[ii][1] ) -- get the items info through its id + itempanels[ii].item.amount = Quantum.Item.Get( items[ii][2] ) || 1 -- get the amount + end itempanels[ii]:SetSize( itemWidth, itemHeight ) if( count >= maxW ) then @@ -133,16 +136,39 @@ function menu.open( dt ) if( itempanels[ii].item == nil ) then -- get the items rarity color itempanels[ii].itemcolor = Quantum.Rarity.None.color - print( ii, "is nil", itemcolor ) else itempanels[ii].itemcolor = itempanels[ii].item.rarity.color - print( ii, "is an item", itemcolor ) end itempanels[ii].Paint = function( self ) theme.itempanel( self, self.itemcolor ) end + ---- Create the model icon for the item panel ---- + if( itempanels[ii].item != nil && itempanels[ii].item.model != nil ) then + itempanels[ii].icon = vgui.Create( "DModelPanel", itempanels[ii] ) + itempanels[ii].icon:SetSize( itempanels[ii]:GetSize() ) + itempanels[ii].icon:SetPos( 0, 0 ) + itempanels[ii].icon:SetModel( itempanels[ii].item.model ) + itempanels[ii].icon:SetFOV( 45 ) + + -- get the dimensions of the models entity + local mn, mx = itempanels[ii].icon.Entity:GetRenderBounds() + local size = 0 + + -- calculate the vector axises so that the view doesn't go outside of the models renderbounds -- + size = math.max( size, math.abs( mn.x ) + math.abs( mx.x ) ) + size = math.max( size, math.abs( mn.y ) + math.abs( mx.y ) ) + size = math.max( size, math.abs( mn.z ) + math.abs( mx.z ) ) + + -- Apply the new "data" -- + itempanels[ii].icon:SetCamPos( Vector( size/2, size, size ) ) + itempanels[ii].icon:SetLookAt( ( mn + mx )/2 ) + + iteminfo.givetooltip( itempanels[ii].icon ) -- give the item a tooltip + + end + end