From 20b13e7b5a44afdd79d7a944cac9b02c80f9aaa7 Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Sat, 18 Jan 2020 00:21:41 +0100 Subject: [PATCH] Crafting UI progress --- gamemode/engine/derma/lib/cl_menu_theme.lua | 2 +- gamemode/engine/derma/menus/menu_charinfo.lua | 2 +- gamemode/engine/derma/menus/menu_crafting.lua | 142 ++++++++++++++++++ gamemode/engine/lib/sh_station.lua | 4 + 4 files changed, 148 insertions(+), 2 deletions(-) diff --git a/gamemode/engine/derma/lib/cl_menu_theme.lua b/gamemode/engine/derma/lib/cl_menu_theme.lua index 3d337a0..57aa86a 100644 --- a/gamemode/engine/derma/lib/cl_menu_theme.lua +++ b/gamemode/engine/derma/lib/cl_menu_theme.lua @@ -82,7 +82,7 @@ function theme.sharpbutton( b, inClr ) if( !b:IsHovered() ) then surface.SetDrawColor( 205, 205, 205, 255 ) else - surface.SetDrawColor( 120, 120, 120, 255 ) + surface.SetDrawColor( 116, 185, 255, 255 ) end surface.DrawOutlinedRect( 0, 0, w, h ) diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index 31e2595..6230afe 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -209,7 +209,7 @@ function menu.open( dt ) bar.Paint = function( self ) theme.blurpanel( self ) end bar.DoClick = function( self ) f:Close() end - -- Inventory button -- + -- Inventory title -- title = vgui.Create( "DLabel", bar ) title:SetText( "Inventory" ) title:SetFont( "q_header_s" ) diff --git a/gamemode/engine/derma/menus/menu_crafting.lua b/gamemode/engine/derma/menus/menu_crafting.lua index dce0496..c1c2701 100644 --- a/gamemode/engine/derma/menus/menu_crafting.lua +++ b/gamemode/engine/derma/menus/menu_crafting.lua @@ -18,13 +18,92 @@ local padding_s = 4 * resScale local itemWidth, itemHeight = 65 * resScale, 65 * resScale +local function configureCamLookPos( icon ) + local mn, mx = icon.Entity:GetRenderBounds() + local size = 0 + + 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 ) ) + icon:SetCamPos( Vector( size/2, size, size ) ) + icon:SetLookAt( ( mn + mx )/2 ) +end + +local function createItemAmountLabel( icon, item ) + icon.amountpanel = vgui.Create( "DLabel", icon ) + icon.amountpanel:SetText( tostring( item.amount ) ) + icon.amountpanel:SetTextColor( Color( 205, 205, 205, 255 ) ) + icon.amountpanel:SetFont( "q_item_amount" ) + icon.amountpanel:SizeToContents() + icon.amountpanel.w, icon.amountpanel.h = icon.amountpanel:GetSize() + icon.amountpanel:SetPos( ( icon.w - icon.amountpanel.w ) - padding_s, icon.h - icon.amountpanel.h ) + return icon.amountpanel +end + +local function createItemPanel( x, y, scale, parent, frame ) + local p = vgui.Create( "DPanel", parent ) + p:SetSize( itemWidth * scale, itemHeight * scale ) + p.w, p.h = p:GetSize() + p:SetPos( x - p.w/2, y - p.h/2 ) + p.x, p.y = p:GetPos() + + p.Paint = function( self ) + theme.itempanel( self, self.itemcolor, true ) + end + + function p.SetItem( itemid ) + + if( itemid != nil ) then + + local itemTbl = Quantum.Item.Get( itemid ) + + p.itemid = itemid -- give it its equipped item + p.itemcolor = itemTbl.rarity.color -- give it its color + + p.item = itemTbl + p.item.amount = 1 + + if( IsValid( p.icon.tooltip ) ) then + p.icon.tooltip:Remove() -- remove the old + end + + p.icon.tooltip = iteminfo.givetooltip( p.icon, frame ) -- create a new + p.icon.tooltip:CreateInfo() + + p.icon:SetVisible( true ) + p.icon:SetModel( itemTbl.model ) + configureCamLookPos( p.icon ) + else + p.icon:SetVisible( false ) -- hide it if there is no item + if( IsValid( p.icon.tooltip ) ) then + p.icon.tooltip:Remove() + end + p.itemid = nil -- remove its item id + p.itemcolor = nil -- remove the background color + end + end + + p.icon = vgui.Create( "DModelPanel", p ) + p.icon:SetSize( p:GetSize() ) + p.icon.w, p.icon.h = p.icon:GetSize() + p.icon:SetPos( 0, 0 ) + p.icon:SetFOV( 45 ) + + return p +end + function menu.open( dt ) local station local stationEnt + + local recipes + local stationTbl if( dt != nil ) then if( dt.cont != nil ) then station = dt.cont.station + stationTbl = Quantum.Station.Get( station ) + recipes = Quantum.Station.GetRecipes( station ) stationEnt = dt.cont.stationEnt end end @@ -81,6 +160,69 @@ function menu.open( dt ) Quantum.Client.CurMenu = f + -- Title -- + local bar = vgui.Create( "DPanel", f ) + bar:SetSize( f.w, padding*5 ) + bar.w, bar.h = bar:GetSize() + bar:SetPos( 0, 0 ) + bar.Paint = function( self ) theme.blurpanel( self ) end + bar.DoClick = function( self ) f:Close() end + + -- Inventory title -- + title = vgui.Create( "DLabel", bar ) + title:SetText( stationTbl.name || "ERROR name=nil" ) + title:SetFont( "q_header_s" ) + title:SetTextColor( Color( 255, 255, 255, 255 ) ) + title.Paint = function( self ) + theme.pagetext( self ) + end + + title:SizeToContents() + title.w, title.h = title:GetSize() + title:SetPos( bar.w/2 - title.w/2, bar.h/2 - title.h/2 ) + + ---- recipe list ---- + + local list = vgui.Create( "DPanel", f ) + list:SetSize( 400 * resScale, f.h - bar.h ) + list.w, list.h = list:GetSize() + list:SetPos( 0, bar.h ) + list.Paint = function( self ) + theme.blurpanel( self ) + end + + local scroll = vgui.Create( "DScrollPanel", list ) + scroll:SetSize( list.w, list.h ) + + local vbar = scroll:GetVBar() + function vbar:Paint() theme.borderpanel( vbar, Color( 200, 200, 200, 200 ) ) end + + local btnColors = Color( 100, 100, 100, 50 ) + + vbar.btnUp:SetText( "▲" ) -- up + vbar.btnUp:SetTextColor( Color( 255, 255, 255, 200 ) ) + function vbar.btnUp:Paint() theme.sharpblurrbutton( vbar.btnUp, btnColors) end + + vbar.btnDown:SetText( "▼" ) -- down + vbar.btnDown:SetTextColor( Color( 255, 255, 255, 200 ) ) + function vbar.btnDown:Paint() theme.sharpblurrbutton( vbar.btnDown, btnColors ) end + + -- grip + function vbar.btnGrip:Paint() theme.sharpbutton( vbar.btnGrip, btnColors ) end + + local cont = vgui.Create( "DPanel", f ) + cont:SetSize( f.w - list.w, f.h - bar.h ) + cont:SetPos( list.w, bar.h ) + cont.Paint = function( self ) + theme.blurpanel( self, Color( 255, 255, 255, 1 ) ) + end + + for i=1, 10 do ---- ADD CRAFT SELECT PANELS HERE + local p = createItemPanel( 200, 200*(i-1), 1.25, scroll, f ) + p.SetItem( "potatoe" ) + end + + end end diff --git a/gamemode/engine/lib/sh_station.lua b/gamemode/engine/lib/sh_station.lua index f3e9223..5235a2c 100644 --- a/gamemode/engine/lib/sh_station.lua +++ b/gamemode/engine/lib/sh_station.lua @@ -27,6 +27,10 @@ function Quantum.Station.Get( id ) return Quantum.Stations[id] end +function Quantum.Station.GetRecipes( id ) + return Quantum.Stations[id].recipes +end + if SERVER then Quantum.Server.Station = {}