From a24c763b75e211e73254b2e260b3ad522a3787bb Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Sun, 2 Feb 2020 19:31:15 +0100 Subject: [PATCH] HUD update & effects bug fixes & added item effects --- gamemode/engine/core/client/cl_hud.lua | 20 ++++++++--- .../engine/derma/lib/cl_menu_iteminfo.lua | 25 +++++++++++-- gamemode/engine/derma/menus/menu_crafting.lua | 22 +++++++++--- gamemode/settings/sh_effects.lua | 36 +++++++++++++++++++ gamemode/settings/sh_items.lua | 6 ++-- 5 files changed, 95 insertions(+), 14 deletions(-) diff --git a/gamemode/engine/core/client/cl_hud.lua b/gamemode/engine/core/client/cl_hud.lua index deb8177..f371550 100644 --- a/gamemode/engine/core/client/cl_hud.lua +++ b/gamemode/engine/core/client/cl_hud.lua @@ -19,6 +19,7 @@ local scale = Quantum.Client.ResolutionScale local barW, barH = 400 * scale, 25 * scale local radius = 1.05 * scale local padding = 5 * scale +local padding_s = padding/2 local sw, sh = ScrW(), ScrH() local function SetAlpha( color, alpha ) @@ -30,18 +31,29 @@ local function renderStatHUD() local lasthp = hp local maxhp = LocalPlayer():GetMaxHealth() + local armor = LocalPlayer():Armor() + local maxarmor = 200 + -- Health border - surface.SetDrawColor( 0, 0, 0, 200 ) + surface.SetDrawColor( 20, 20, 20, 200 ) surface.DrawRect( sw/2 - barW/2, sh*0.9, barW, barH ) + -- Border bars + surface.SetDrawColor( 52, 180, 235, 200, 220 ) + + local armorWidth = math.Clamp( (barW - padding_s) * armor/maxarmor, 0, barW - padding_s ) + surface.DrawRect( ( sw/2 - armorWidth/2 ), (sh*0.9) + padding_s/2, armorWidth, barH - padding_s ) + -- Health bar - surface.SetDrawColor( 168, 62, 50, 255 ) - surface.DrawRect( ( sw/2 - barW/2 ) + padding/2, (sh*0.9) + padding/2, math.Clamp( (barW - padding) * hp/maxhp, 0, barW - padding ), barH - padding ) + surface.SetDrawColor( 168, 62, 50, 255 ) + + local healthWidth = math.Clamp( (barW - padding) * hp/maxhp, 0, barW - padding ) + surface.DrawRect( ( sw/2 - healthWidth/2 ), (sh*0.9) + padding/2, healthWidth, barH - padding ) -- Health Text surface.SetFont( "q_HUD" ) surface.SetTextColor( 255, 255, 255, 255 ) - local hptxt = tostring( 100 * (hp/maxhp) .. "%" ) + local hptxt = tostring( hp ) local txtW, txtH = surface.GetTextSize( hptxt ) surface.SetTextPos( ( ( sw/2 - txtW/2 ) + padding/2 ), ( ( sh*0.9 - txtH/3 ) ) ) surface.DrawText( hptxt ) diff --git a/gamemode/engine/derma/lib/cl_menu_iteminfo.lua b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua index 6aae74e..ce8d9cd 100644 --- a/gamemode/engine/derma/lib/cl_menu_iteminfo.lua +++ b/gamemode/engine/derma/lib/cl_menu_iteminfo.lua @@ -192,7 +192,6 @@ function iteminfo.giveoptions( p, page ) if( item.equipslot != nil ) then -- Equip if( page.equippanels[item.equipslot].GetCurrentEquipedIndex() != index ) then - print( "TRUE", page.equippanels[item.equipslot].GetCurrentEquipedIndex(), index ) op.equip = vgui.Create( "DButton", options ) op.equip:SetText( "Equip (" .. Quantum.EquipSlotsNames[item.equipslot] .. ")" ) op.equip:SetFont( "q_item_option_button" ) @@ -454,7 +453,7 @@ function iteminfo.givetooltip( p, page, addW ) use:SetPos( title.x, yposBase ) use.x, use.y = use:GetPos() - yposBase = yposBase + use.y + padding_s + yposBase = yposBase + use.h + padding_s end end @@ -472,7 +471,27 @@ function iteminfo.givetooltip( p, page, addW ) eat:SetPos( title.x, yposBase ) eat.x, eat.y = eat:GetPos() - yposBase = yposBase + eat.y + padding_s + yposBase = yposBase + eat.h + padding_s + end + end + + if( self.item.equipeffect != nil ) then + + if( self.item.equipslot != nil ) then + local effectTbl = Quantum.Effect.Get( self.item.equipeffect ) + + if( effectTbl.desc != nil ) then + local equipDesc = vgui.Create( "DLabel", self ) + equipDesc:SetText( "Equip: " .. effectTbl.desc || "ERROR DESC EQUIP" ) + equipDesc:SetFont( "q_tooltip_desc" ) + equipDesc:SetTextColor( Color( 18, 224, 66, 255 ) ) + equipDesc:SizeToContents() + equipDesc.w, equipDesc.h = equipDesc:GetSize() + equipDesc:SetPos( title.x, yposBase ) + equipDesc.x, equipDesc.y = equipDesc:GetPos() + + yposBase = yposBase + equipDesc.h + padding_s + end end end diff --git a/gamemode/engine/derma/menus/menu_crafting.lua b/gamemode/engine/derma/menus/menu_crafting.lua index 58a323a..1db741e 100644 --- a/gamemode/engine/derma/menus/menu_crafting.lua +++ b/gamemode/engine/derma/menus/menu_crafting.lua @@ -325,6 +325,7 @@ function menu.open( dt ) resBars[resID].cont.title.x, resBars[resID].cont.title.y = resBars[resID].cont.title:GetPos() resBars[resID].cont.craft = vgui.Create( "DButton", resBars[resID].cont ) + resBars[resID].cont.craft.enabled = true resBars[resID].cont.craft:SetText( "Create Item" ) resBars[resID].cont.craft:SetFont( "q_button_m" ) resBars[resID].cont.craft:SetTextColor( Color( 255, 255, 255 ) ) @@ -332,12 +333,20 @@ function menu.open( dt ) resBars[resID].cont.craft.w, resBars[resID].cont.craft.h = resBars[resID].cont.craft:GetSize() resBars[resID].cont.craft:SetPos( resBars[resID].cont.title.x, resBars[resID].cont.title.y + resBars[resID].cont.craft.h + padding ) resBars[resID].cont.craft.Paint = function( self ) - theme.sharpblurrbutton( self ) + if( self.enabled ) then + theme.sharpblurrbutton( self, Color( 110, 255, 110, 120 ) ) + else + theme.sharpblurrbutton( self, Color( 255, 110, 110, 120 ) ) + end end resBars[resID].cont.craft.DoClick = function( self ) - surface.PlaySound( "UI/buttonclick.wav" ) - f:Close() - -- SEND NET CRAFT HERE -- + if( self.enabled ) then + surface.PlaySound( "UI/buttonclick.wav" ) + f:Close() + -- SEND NET CRAFT HERE -- + else + surface.PlaySound( "common/wpn_denyselect.wav" ) + end end resBars[resID].cont.craft.OnCursorEntered = function() surface.PlaySound( "UI/buttonrollover.wav" ) end @@ -378,7 +387,7 @@ function menu.open( dt ) count = count + 1 itemPanels[count] = vgui.Create( "DPanel", resBars[resID].cont.reagents ) - itemPanels[count]:SetSize( 600 * resScale, itemHeight*regScale + padding*2 ) + itemPanels[count]:SetSize( 750 * resScale, itemHeight*regScale + padding*2 ) itemPanels[count].w, itemPanels[count].h = itemPanels[count]:GetSize() -- itemPanels[count]:SetPos( resBars[resID].cont.reagentsTXT.x + padding, itemPanels[count].h*(count-1) + padding*(count-1) ) itemPanels[count].Paint = function( self, w, h ) @@ -406,6 +415,9 @@ function menu.open( dt ) itemamount:SetTextColor( Color( 255, 255, 255, 220 ) ) else itemamount:SetTextColor( Color( 255, 155, 155, 220 ) ) + if( resBars[resID].cont.craft.enabled == true ) then + resBars[resID].cont.craft.enabled = false + end end itemamount:SizeToContents() itemamount.w, itemamount.h = itemamount:GetSize() diff --git a/gamemode/settings/sh_effects.lua b/gamemode/settings/sh_effects.lua index ec33031..34705c0 100644 --- a/gamemode/settings/sh_effects.lua +++ b/gamemode/settings/sh_effects.lua @@ -19,6 +19,30 @@ Quantum.Effect.Create( "eat_potatoe", { end } ) +Quantum.Effect.Create( "equip_potatoe", { + title = "Potatoe Powers", + desc = "Increases your max health by 100 and\nheales you with 5 health every second.", + rarity = Quantum.Rarity.Legendary, + startfunc = function( pl ) + pl:SetMaxHealth( pl:GetMaxHealth() + 100 ) + + pl.runtimeEffect_timerActive_equip_potatoe = false + end, + runtimefunc = function( pl ) + if( !pl.runtimeEffect_timerActive_equip_potatoe ) then + pl.runtimeEffect_timerActive_equip_potatoe = true + timer.Simple( 1, function() + pl:SetHealth( math.Clamp( pl:Health() + 5, 1, pl:GetMaxHealth() ) ) + pl.runtimeEffect_timerActive_equip_potatoe = false + end) + end + end, + stopfunc = function( pl ) + pl:SetMaxHealth( math.Clamp( pl:GetMaxHealth() - 100, 1, pl:GetMaxHealth() ) ) + pl.runtimeEffect_timerActive_equip_potatoe = nil + end +} ) + Quantum.Effect.Create( "eat_trash", { title = "Bad Health", desc = "You die.", @@ -26,4 +50,16 @@ Quantum.Effect.Create( "eat_trash", { startfunc = function( pl ) pl:Kill() end +} ) + +Quantum.Effect.Create( "test_chest", { + title = "Protective Shield", + desc = "You gain 100 armor while the chestpiece is on.", + rarity = Quantum.Rarity.Rare, + startfunc = function( pl ) + pl:SetArmor( 100 ) + end, + stopfunc = function( pl ) + pl:SetArmor( 0 ) + end } ) \ No newline at end of file diff --git a/gamemode/settings/sh_items.lua b/gamemode/settings/sh_items.lua index b95882d..153a804 100644 --- a/gamemode/settings/sh_items.lua +++ b/gamemode/settings/sh_items.lua @@ -11,7 +11,8 @@ Quantum.Item.Create( "test", { model = "models/props_phx/gears/bevel12.mdl", soulbound = true, rarity = Quantum.Rarity.Rare, - equipslot = Quantum.EquipSlots.Chest + equipslot = Quantum.EquipSlots.Chest, + equipeffect = "test_chest" } ) Quantum.Item.Create( "test2", { @@ -42,7 +43,8 @@ Quantum.Item.Create( "potatoe", { soulbound = false, rarity = Quantum.Rarity.Legendary, equipslot = Quantum.EquipSlots.Head, - consumeeffect = "eat_potatoe" + consumeeffect = "eat_potatoe", + equipeffect = "equip_potatoe" } ) -- weapon_gta_sa_jetpack.lua