diff --git a/gamemode/engine/core/client/cl_hud.lua b/gamemode/engine/core/client/cl_hud.lua index 0e089ec..4523494 100644 --- a/gamemode/engine/core/client/cl_hud.lua +++ b/gamemode/engine/core/client/cl_hud.lua @@ -20,16 +20,14 @@ local radius = 1.05 * scale local padding = 5 * scale local sw, sh = ScrW(), ScrH() -local client = LocalPlayer() - local function SetAlpha( color, alpha ) return Color( color.r, color.g, color.b, alpha ) end local function renderStatHUD() - local hp = client:Health() + local hp = LocalPlayer():Health() local lasthp = hp - local maxhp = client:GetMaxHealth() + local maxhp = LocalPlayer():GetMaxHealth() -- Health border surface.SetDrawColor( 0, 0, 0, 200 ) @@ -55,47 +53,76 @@ local function renderStatHUD() end local function renderItemInfoHUD() - local trace = client:GetEyeTraceNoCursor() - if( trace.Entity:GetClass() == "q_item" ) then - local distance = client:GetPos():Distance( trace.Entity:GetPos() ) - local distFrac = Lerp( distance/Quantum.ItemInfoDisplayMaxDistance, 1, 0 ) - - if( distance <= Quantum.ItemInfoDisplayMaxDistance ) then - local item = Quantum.Item.Get( trace.Entity:GetNWString( "q_item_id" ) ) || { name="ERROR" } - local amount = trace.Entity:GetNWInt( "q_item_amount" ) || 1 - - local pos = trace.Entity:GetPos() - pos.z = pos.z + 20 - - local screenPos = pos:ToScreen() - - local txtPadding = 20 * scale - local itemAmountTxt = "" - if( amount > 1 ) then itemAmountTxt = amount .. "x " end + local trace = LocalPlayer():GetEyeTraceNoCursor() + local entsNear = ents.FindInSphere( LocalPlayer():GetPos(), Quantum.ItemInfoDisplayMaxDistance ) + + for i, ent in pairs( entsNear ) do + if( ent:GetClass() == "q_item" ) then + local distance = LocalPlayer():GetPos():Distance( ent:GetPos() ) + local distFrac = Lerp( distance/Quantum.ItemInfoDisplayMaxDistance, 1, 0 ) + + if( distance <= Quantum.ItemInfoDisplayMaxDistance ) then + local item = Quantum.Item.Get( ent:GetNWString( "q_item_id" ) ) || { name = "", rarity = { txt = "", color = Color( 0, 0, 0, 0 ) } } + local amount = ent:GetNWInt( "q_item_amount" ) || 1 + + local pos = ent:GetPos() + pos.z = pos.z + 20 + + local screenPos = pos:ToScreen() + + local txtPadding = 20 * scale + local itemAmountTxt = "" + if( amount > 1 ) then itemAmountTxt = amount .. "x " end + + local alphaFrac = distFrac + + + draw.SimpleText( itemAmountTxt .. item.name, "q_item_hud_title", screenPos.x, screenPos.y, SetAlpha( item.rarity.color, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + draw.SimpleText( "Rarity: " .. item.rarity.txt, "q_item_hud_rarity", screenPos.x, screenPos.y + txtPadding, SetAlpha( item.rarity.color, 255 *alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + if( item.soulbound ) then + draw.SimpleText( "Soulbound", "q_item_hud_soulbound", screenPos.x, screenPos.y + txtPadding*2, Color( 235, 64, 52, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + end + end + end + end +end - local alphaFrac = distFrac +local showRarities = { + [Quantum.Rarity.Rare] = true, + [Quantum.Rarity.Epic] = true, + [Quantum.Rarity.Legendary] = true +} +local function renderHaloAroundItems() + for i, item in pairs( ents.FindByClass( "q_item" ) ) do + local itemid = item:GetNWString( "q_item_id" ) + local itemTbl = Quantum.Item.Get(itemid) || { rarity = Quantum.Rarity.Rare } - draw.SimpleText( itemAmountTxt .. item.name, "q_item_hud_title", screenPos.x, screenPos.y, SetAlpha( item.rarity.color, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) - draw.SimpleText( "Rarity: " .. item.rarity.txt, "q_item_hud_rarity", screenPos.x, screenPos.y + txtPadding, SetAlpha( item.rarity.color, 255 *alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) - if( item.soulbound ) then - draw.SimpleText( "Soulbound", "q_item_hud_soulbound", screenPos.x, screenPos.y + txtPadding*2, Color( 235, 64, 52, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) + if( itemTbl != nil ) then + if( showRarities[itemTbl.rarity] ) then + halo.Add( { item }, SetAlpha( itemTbl.rarity.color, 255 ), 0, 0, 2, true, false ) end end end end +hook.Add( "PreDrawHalos", "Quantum_Item_Halos", function() + renderHaloAroundItems() +end) + function GM:HUDPaint() - if( !Quantum.Client.IsInMenu ) then - if( !client:Alive() ) then - surface.SetDrawColor( 0, 0, 0, 255 ) - surface.DrawRect( 0, 0, sw, sh ) - end - - if( Quantum.Client.Config.EnableHUD ) then - if( client:Alive() ) then - renderStatHUD() - renderItemInfoHUD() + if( LocalPlayer():IsValid() ) then + if( !Quantum.Client.IsInMenu ) then + if( !LocalPlayer():Alive() ) then + surface.SetDrawColor( 0, 0, 0, 255 ) + surface.DrawRect( 0, 0, sw, sh ) + end + + if( Quantum.Client.Config.EnableHUD ) then + if( LocalPlayer():Alive() ) then + renderStatHUD() + renderItemInfoHUD() + end end end end diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index 034bde8..dc09552 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -145,7 +145,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 = Quantum.Item.Get( items[ii][1] ) -- get the items info through its id itempanels[ii].item.amount = items[ii][2] || 1 -- get the amount end @@ -292,10 +292,27 @@ hook.Add("ScoreboardShow", "Quantum_Menu_CharInfo_Open", function() -- InventoryStartTime = nil -- end -- open the menu - menu.open() + -- menu.open() return false end) +local startTime + +hook.Add( "Think", "Quantum_Menu_CharInfo_Think", function() + if( !Quantum.Client.IsInMenu ) then + if( input.IsButtonDown( Quantum.Bind.OpenInventory ) ) then + startTime = startTime || CurTime() + + if( CurTime() - startTime >= Quantum.InventoryOpenDelay ) then + startTime = nil + menu.open() + end + else + startTime = nil + end + end +end) + return menu \ No newline at end of file diff --git a/gamemode/engine/lib/sh_items.lua b/gamemode/engine/lib/sh_items.lua index 7f07c32..3b0ab5f 100644 --- a/gamemode/engine/lib/sh_items.lua +++ b/gamemode/engine/lib/sh_items.lua @@ -55,7 +55,7 @@ if SERVER then end end - function Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount ) -- + function Quantum.Server.Item.SpawnItemAtPlayer( pl, itemid, amount ) -- Quantum.Server.Item.SpawnItemAtPlayer( Entity(1), "test2", 5 ) Quantum.Server.Item.SpawnItem( pl:GetPos() + ( pl:GetForward() * 40 ) + Vector( 0, 0, 40 ), itemid, amount ) end end \ No newline at end of file diff --git a/gamemode/settings/sh_items.lua b/gamemode/settings/sh_items.lua index f973932..b14abbd 100644 --- a/gamemode/settings/sh_items.lua +++ b/gamemode/settings/sh_items.lua @@ -38,4 +38,14 @@ Quantum.Item.Create( "bomb", { soulbound = false, equipable = false, rarity = Quantum.Rarity.Epic +} ) + +Quantum.Item.Create( "potatoe", { + name = "Legendary Potatoe", + desc = "The most legendary potatoe in existance. Don't eat it!", + model = "models/props_phx/misc/potato.mdl", + stack = 1, + soulbound = false, + equipable = false, + rarity = Quantum.Rarity.Legendary } ) \ No newline at end of file diff --git a/gamemode/settings/sh_settings.lua b/gamemode/settings/sh_settings.lua index f84fc8c..4f80547 100644 --- a/gamemode/settings/sh_settings.lua +++ b/gamemode/settings/sh_settings.lua @@ -18,6 +18,7 @@ Quantum.Inventory = { MaxStackSize = 20 -- NOTE: MAX MaxStackSize=99 } +Quantum.InventoryOpenDelay = 0.35 Quantum.ItemPickupTime = 0.5 -- seconds Quantum.ItemInfoDisplayMaxDistance = 200 @@ -35,6 +36,10 @@ Quantum.Rarity = { Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 40 ) } } +Quantum.Bind = { + OpenInventory = KEY_TAB +} + Quantum.Models = { NPC = {}, Player = {