Added custom tooltip to items

master
AlmTech Software 5 years ago
parent 2b87f3b849
commit 77529575ca
  1. 24
      gamemode/engine/core/client/cl_fonts.lua
  2. 2
      gamemode/engine/core/sh_player_binds.lua
  3. 60
      gamemode/engine/derma/lib/cl_menu_iteminfo.lua
  4. 15
      gamemode/engine/derma/lib/cl_menu_theme.lua
  5. 19
      gamemode/engine/derma/menus/menu_charinfo.lua
  6. 16
      gamemode/settings/sh_items.lua
  7. 3
      gamemode/settings/sh_settings.lua

@ -89,4 +89,28 @@ surface.CreateFont( "q_money", {
font = "Cambria Bold",
size = 42 * Quantum.Client.ResolutionScale,
antialias = true
})
surface.CreateFont( "q_tooltip_title", {
font = "Cambria Bold",
size = 24 * Quantum.Client.ResolutionScale,
antialias = true
})
surface.CreateFont( "q_tooltip_desc", {
font = "Cambria",
size = 20 * Quantum.Client.ResolutionScale,
antialias = true
})
surface.CreateFont( "q_tooltip_rarity", {
font = "Cambria",
size = 18 * Quantum.Client.ResolutionScale,
antialias = true
})
surface.CreateFont( "q_item_amount", {
font = "Cambria Bold",
size = 22 * Quantum.Client.ResolutionScale,
antialias = true
})

@ -18,7 +18,7 @@ if SERVER then
name = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).name,
money = Quantum.Server.Char.getBasicCharInfo( Quantum.Server.Char.GetCurrentCharacter( pl ) ).money
}, items = { [1] = {"test", 1} } })
}, items = { [1] = {"test", 1}, [2] = {"test2", Quantum.Inventory.MaxStackSize} } })
end
}

@ -13,33 +13,69 @@ local padding_s = math.Round( 4 * scale )
local theme = Quantum.Client.Menu.GetAPI( "theme" )
function iteminfo.givetooltip( p )
function iteminfo.givetooltip( p, page )
local item = p:GetParent().item
local parWidth, parHeight = p:GetParent():GetSize()
local amountStr = ""
local tooltip = vgui.Create( "DPanel" )
tooltip:SetSize( 100 * scale, 80 * scale )
local tooltip = vgui.Create( "DPanel", page )
tooltip:SetSize( 100 * scale, 80 * scale ) -- placeholder size
tooltip.w, tooltip.h = tooltip:GetSize()
tooltip.item = item
tooltip:SetVisible( false )
tooltip.Paint = function( self )
theme.itemtooltip( self, item )
end
if( item.amount > 1 ) then amountStr = "x" .. tostring( item.amount ) end
function tooltip:CreateInfo()
local pw, ph = self:GetSize()
local amountStr = ""
if( self.item.amount > 1 ) then amountStr = " (x" .. tostring( self.item.amount ) .. ")" end
p.ItemInfoPanel = tooltip -- set the tooltip
local title = vgui.Create( "DLabel", self ) -- title label of the item
title:SetText( self.item.name .. amountStr || "ERROR TITLE" )
title:SetFont( "q_tooltip_title" )
title:SetTextColor( theme.color.setalpha( self.item.rarity.color || Color( 255, 255, 255, 255 ), 255 ) )
title:SizeToContents()
title.w, title.h = title:GetSize()
title:SetPos( padding_s, padding_s )
title.x, title.y = title:GetPos()
local rare = vgui.Create( "DLabel", self )
rare:SetText( self.item.rarity.txt || "ERROR RARITY" )
rare:SetFont( "q_tooltip_rarity" )
rare:SetTextColor( theme.color.setalpha( self.item.rarity.color || Color( 255, 255, 255, 255 ), 255 ) )
rare:SizeToContents()
rare.w, rare.h = rare:GetSize()
rare:SetPos( title.x, title.y + title.h + padding_s )
rare.x, rare.y = rare:GetPos()
local desc = vgui.Create( "DLabel", self )
desc:SetText( self.item.desc || "ERROR DESC" )
desc:SetFont( "q_tooltip_desc" )
desc:SetTextColor( Color( 205, 205, 205, 255 ) )
desc:SizeToContents()
desc.w, desc.h = desc:GetSize()
desc:SetPos( title.x, rare.y + rare.h + padding_s )
-- Correct the tooltips size so its content fits inside of it
self:SizeToChildren( true, true )
self.w, self.h = self:GetSize()
self:SetSize( self.w + padding_s, self.h + padding_s )
self.w, self.h = self:GetSize()
end
p.ItemTooltipPanel = tooltip -- set the tooltip
p.Think = function( self )
self.ItemInfoPanel:SetVisible( self:IsHovered() )
self.ItemTooltipPanel:SetVisible( self:IsHovered() )
if( self:IsHovered() ) then
self.ItemInfoPanel:SetPos( gui.MouseX(), gui.MouseY() - ( parHeight + padding )*2 )
self.ItemTooltipPanel:SetPos( gui.MouseX() - tooltip.w/2, gui.MouseY() - ( tooltip.h + padding ) )
end
end
--p:SetToolTip( item.name .. " " .. amountStr .. "\n\n" .. item.desc )
--p:SetTooltipPanel( tooltip )
--p.pnlTooltipPanel = tooltip -- overwrite the default tooltip
--p.strTooltipText = ""
return tooltip
end
return iteminfo

@ -151,8 +151,21 @@ end
function theme.itemtooltip( p, item )
local w, h = p:GetSize()
surface.SetDrawColor( Color( 0, 0, 0, 255 ) )
theme.renderblur( p, 4, 5 )
surface.SetDrawColor( Color( 20, 20, 20, 190 ) )
surface.DrawRect( 0, 0, w, h )
theme.borderpanel( p, Color( 205, 205, 205, 200 ) )
end
---- Color Manipulation ----
theme.color = {}
function theme.color.setalpha( color, alpha )
return Color( color.r, color.g, color.b, alpha )
end
return theme

@ -115,7 +115,7 @@ function menu.open( dt )
itempanels[ii].index = ii -- set the vars
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
itempanels[ii].item.amount = items[ii][2] || 1 -- get the amount
end
itempanels[ii]:SetSize( itemWidth, itemHeight )
@ -148,6 +148,7 @@ function menu.open( dt )
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.w, itempanels[ii].icon.h = itempanels[ii].icon:GetSize()
itempanels[ii].icon:SetPos( 0, 0 )
itempanels[ii].icon:SetModel( itempanels[ii].item.model )
itempanels[ii].icon:SetFOV( 45 )
@ -165,7 +166,21 @@ function menu.open( dt )
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
---- Amount Text ----
if( itempanels[ii].item.amount > 1 ) then
itempanels[ii].icon.amountpanel = vgui.Create( "DLabel", itempanels[ii].icon )
itempanels[ii].icon.amountpanel:SetText( tostring( itempanels[ii].item.amount ) )
itempanels[ii].icon.amountpanel:SetTextColor( Color( 205, 205, 205, 255 ) )
itempanels[ii].icon.amountpanel:SetFont( "q_item_amount" )
itempanels[ii].icon.amountpanel:SizeToContents()
itempanels[ii].icon.amountpanel.w, itempanels[ii].icon.amountpanel.h = itempanels[ii].icon.amountpanel:GetSize()
itempanels[ii].icon.amountpanel:SetPos( ( itempanels[ii].icon.w - itempanels[ii].icon.amountpanel.w ) - padding_s, itempanels[ii].icon.h - itempanels[ii].icon.amountpanel.h )
end
---- Tooltip ----
itempanels[ii].icon.tooltip = iteminfo.givetooltip( itempanels[ii].icon, f ) -- give the item a tooltip
itempanels[ii].icon.tooltip:CreateInfo() -- create the labels for the tooltip & such
----
end

@ -14,5 +14,19 @@ Quantum.Item.Create( "test", {
equipable = false,
rarity = Quantum.Rarity.Legendary,
usefunction = function() print( "Test!" ) end,
consumefunction = function() print( "Test 2!" ) end,
consumefunction = function() print( "Test 2!" ) end
} )
Quantum.Item.Create( "test2", {
name = "Trash Item Test",
desc = "This is literall trash\nLine breaker test :D\n\nTest",
model = "models/props_phx/gears/bevel12.mdl",
stack = true,
soulbound = true,
equipable = false,
rarity = Quantum.Rarity.Trash,
consumefunction = function( user )
user:Kill()
user:PrintChat( "You consumed trash and died!" )
end
} )

@ -14,7 +14,8 @@ Quantum.WorkshopLink = "https://steamcommunity.com/sharedfiles/filedetails/?id=1
Quantum.Inventory = {
Height = 10, -- NOTE: MAX HEIGHT=12
Width = 16 -- NOTE: MAX WIDTH=18
Width = 16, -- NOTE: MAX WIDTH=18
MaxStackSize = 99 -- NOTE: MAX MaxStackSize=99
}
Quantum.Money = {

Loading…
Cancel
Save