Skip to content

Commit

Permalink
fix(icons): Make sure that UniqueIDs are generated for Lua defined it…
Browse files Browse the repository at this point in the history
…ems. Fixes an LUA error
  • Loading branch information
ValentinFunk committed Apr 28, 2017
1 parent d6f08d4 commit d58728f
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 94 deletions.
8 changes: 8 additions & 0 deletions lua/kinv/shared/sh_z_itemloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ local function loadItem( filepath, filename )
KInventory.Items[className].static.isBase = true
else
KInventory.Items[className].static.isBase = false

-- Give file generated things an uuid for static icons
local disallowed = {"/", "\\", ".", " "}
local uid = filepath
for k, v in pairs(disallowed) do
uid = string.Replace(uid, v, "_")
end
KInventory.Items[className].static.UUID = uid
end

KLogf( 4, " -> Item %s (Base: %s) loaded!", className, baseItem.className or "No Base" )
Expand Down
34 changes: 34 additions & 0 deletions lua/ps2/client/cl_dpointshophaticon.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local PANEL = {}

function PANEL:Init( )
end

function PANEL:PerformLayout()
self.BaseClass.PerformLayout(self)

self.Label:SetWide(self:GetWide())
self.Label:SetPos(0, self:GetTall() - 25)
self.Label:SetTall(25)
end

function PANEL:SetItemClass( itemClass )
self.BaseClass.SetItemClass( self, itemClass )

if itemClass.iconInfo.inv.useMaterialIcon then
self.image:SetImage( itemClass.iconInfo.inv.iconMaterial )
end
end

function PANEL:SetItem( item )
self:SetItemClass( item.class )
end

function PANEL:OnSelected( )
hook.Run( "PACItemSelected", self.itemClass )
end

function PANEL:OnDeselected( )
hook.Run( "PACItemDeSelected", self.itemClass )
end

derma.DefineControl( "DPointshopHatIcon", "", PANEL, "DCsgoItemIcon" )
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
--[[
Base for CSGO Style item icons (prerendered)
]]--
local PANEL = {}

function PANEL:Init( )
Expand All @@ -14,42 +17,26 @@ function PANEL:Init( )
end

function PANEL:PerformLayout()
self.BaseClass.PerformLayout(self)
DPointshopItemIcon.PerformLayout(self)

self.Label:SetWide(self:GetWide())
self.Label:SetPos(0, self:GetTall() - 25)
self.Label:SetTall(25)
end

function PANEL:SetItemClass( itemClass )
self.BaseClass.SetItemClass( self, itemClass )

if itemClass.iconInfo.inv.useMaterialIcon then
self.image:SetSize( 64, 64 )
self.image:SetImage( itemClass.iconInfo.inv.iconMaterial )
else
Pointshop2.RequestIcon(itemClass, self):Then(function(icon)
if IsValid(self) then
self.image:SetMaterial(icon)
end
end)
end
DPointshopItemIcon.SetItemClass( self, itemClass )
Pointshop2.RequestIcon(itemClass, self):Then(function(icon)
if IsValid(self) then
self.image:SetMaterial(icon)
end
end)
end

function PANEL:SetItem( item )
self:SetItemClass( item.class )
end

function PANEL:OnSelected( )
self.image.forceRender = true
hook.Run( "PACItemSelected", self.itemClass )
end

function PANEL:OnDeselected( )
self.image.forceRender = false
hook.Run( "PACItemDeSelected", self.itemClass )
end

local function drawOutlinedBox( x, y, w, h, thickness, clr )
surface.SetDrawColor( clr )
for i=0, thickness - 1 do
Expand All @@ -58,7 +45,7 @@ local function drawOutlinedBox( x, y, w, h, thickness, clr )
end

function PANEL:PaintOver(w, h)
self.BaseClass.PaintOver(self, w, h)
DPointshopItemIcon.PaintOver(self, w, h)

self.Label:SetPaintedManually(true)
self.Label:PaintManual()
Expand All @@ -69,16 +56,4 @@ function PANEL:PaintOver(w, h)
end
end

derma.DefineControl( "DPointshopHatIcon", "", PANEL, "DPointshopItemIcon" )

local PANEL = {}

function PANEL:OnSelected( )
hook.Run( "PACItemSelected", self.itemClass )
end

function PANEL:OnDeselected( )
hook.Run( "PACItemDeSelected", self.itemClass )
end

derma.DefineControl( "DPointshopSimpleHatIcon", "", PANEL, "DPointshopSimpleItemIcon" )
derma.DefineControl( "DCsgoItemIcon", "", PANEL, "DPointshopItemIcon" )
File renamed without changes.
66 changes: 66 additions & 0 deletions lua/ps2/client/icons/cl_haticon_prerender.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
--[[
Provides a renderer for Hat Icons.
]]--

local plyModel = hook.Run( "PS2_GetPreviewModel" ) or "models/player/alyx.mdl"
local entity = ClientsideModel( plyModel, RENDER_GROUP_OPAQUE_ENTITY )
pac.SetupENT( entity )
entity:SetNoDraw(true)
entity:SetIK( false )
local colAmbientLight = Color( 50, 50, 50 )
local colColor = Color( 255, 255, 255, 255 )
local directionalLight = {
[BOX_TOP] = Color(255, 255, 255),
[BOX_FRONT] = Color(255, 255, 255)
}
local function PaintHatIcon(itemClass)
local outfit = itemClass.getOutfitForModel(plyModel)
pac.SetupENT( entity )
entity:AttachPACPart(outfit)
entity:FrameAdvance( 100 )


local viewInfo = itemClass.iconInfo.shop.iconViewInfo
for i = 1, 100 do
pac.Think()
end

cam.Start3D( viewInfo.origin, viewInfo.angles, viewInfo.fov - 20, 0, 0, 512, 512, 5, 4096 )
cam.IgnoreZ( true )
render.SuppressEngineLighting( true )
render.SetLightingOrigin( entity:GetPos() )
render.ResetModelLighting( colAmbientLight.r/255, colAmbientLight.g/255, colAmbientLight.b/255 )
render.SetColorModulation( colColor.r/255, colColor.g/255, colColor.b/255 )
render.SetBlend( 1 )

for i=0, 6 do
local col = directionalLight[ i ]
if ( col ) then
render.SetModelLighting( i, col.r/255, col.g/255, col.b/255 )
end
end

pac.FlashlightDisable( true )
pac.ForceRendering( true )
pac.RenderOverride( entity, "opaque" )
pac.RenderOverride( entity, "translucent", true )
entity:DrawModel( )
pac.RenderOverride( entity, "translucent", true )
pac.ForceRendering( false )
pac.FlashlightDisable( false )

cam.IgnoreZ( false )
render.SuppressEngineLighting( false )
cam.End3D( )

entity:RemovePACPart(outfit)
end


local HatRendererMixin = {}
function HatRendererMixin:included( klass )
klass.static.PaintIcon = function(cls)
PaintHatIcon(cls)
end
end
Pointshop2.RegisterItemClassMixin( "base_hat", HatRendererMixin )
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,58 +1,3 @@
local plyModel = hook.Run( "PS2_GsetPreviewModel" ) or "models/player/alyx.mdl"
local entity = ClientsideModel( plyModel, RENDER_GROUP_OPAQUE_ENTITY )
pac.SetupENT( entity )
entity:SetNoDraw(true)
entity:SetIK( false )
local colAmbientLight = Color( 50, 50, 50 )
local colColor = Color( 255, 255, 255, 255 )
local directionalLight = {
[BOX_TOP] = Color(255, 255, 255),
[BOX_FRONT] = Color(255, 255, 255)
}
local function paintActual(itemClass)
local outfit = itemClass.getOutfitForModel(plyModel)
pac.SetupENT( entity )
entity:AttachPACPart(outfit)
entity:FrameAdvance( 100 )


local viewInfo = itemClass.iconInfo.shop.iconViewInfo
for i = 1, 100 do
pac.Think()
end

cam.Start3D( viewInfo.origin, viewInfo.angles, viewInfo.fov - 20, 0, 0, 512, 512, 5, 4096 )
cam.IgnoreZ( true )
render.SuppressEngineLighting( true )
render.SetLightingOrigin( entity:GetPos() )
render.ResetModelLighting( colAmbientLight.r/255, colAmbientLight.g/255, colAmbientLight.b/255 )
render.SetColorModulation( colColor.r/255, colColor.g/255, colColor.b/255 )
render.SetBlend( 1 )

for i=0, 6 do
local col = directionalLight[ i ]
if ( col ) then
render.SetModelLighting( i, col.r/255, col.g/255, col.b/255 )
end
end

pac.FlashlightDisable( true )
pac.ForceRendering( true )
pac.RenderOverride( entity, "opaque" )
pac.RenderOverride( entity, "translucent", true )
entity:DrawModel( )
pac.RenderOverride( entity, "translucent", true )
pac.ForceRendering( false )
pac.FlashlightDisable( false )

cam.IgnoreZ( false )
render.SuppressEngineLighting( false )
cam.End3D( )

entity:RemovePACPart(outfit)
end


local mat_BlurX = Material( "pp/blurx" )
local mat_BlurY = Material( "pp/blury" )
local mat_Copy = Material( "pp/copy" )
Expand Down Expand Up @@ -106,7 +51,13 @@ function Pointshop2.RenderModelIcon(itemClass)
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial(csgoBg)
surface.DrawTexturedRect(0, 0, 512, 512)
paintActual(itemClass)
if not itemClass.PaintIcon then
KLogf(1, "Item class %s(%s) is missing a PaintIcon", itemClass.name, itemClass.PrintName)
elseif Pointshop2.DbgOverrideIcon then
Pointshop2.DbgOverrideIcon(itemClass)
else
itemClass:PaintIcon()
end
blur(rt, 100, 100, 512, 512, 2, 2, 25)

cam.IgnoreZ(true)
Expand All @@ -122,4 +73,4 @@ function Pointshop2.RenderModelIcon(itemClass)

mat:SetTexture( "$basetexture", rt )
return mat
end
end
11 changes: 11 additions & 0 deletions lua/ps2/modules/pointshop2/hat/cl_dpointshopsimplehaticon.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local PANEL = {}

function PANEL:OnSelected( )
hook.Run( "PACItemSelected", self.itemClass )
end

function PANEL:OnDeselected( )
hook.Run( "PACItemDeSelected", self.itemClass )
end

derma.DefineControl( "DPointshopSimpleHatIcon", "", PANEL, "DPointshopSimpleItemIcon" )

0 comments on commit d58728f

Please sign in to comment.