Skip to content

Commit

Permalink
feat: allow creating items by rightclicking categories in the managem…
Browse files Browse the repository at this point in the history
…ent tab
  • Loading branch information
ValentinFunk committed Jan 15, 2018
1 parent ee3cab2 commit 8ff8b90
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function PANEL:SaveItem( saveTable )
saveTable.baseClass = self.itembase

saveTable.persistenceId = self.persistenceId
saveTable.targetCategoryId = self.targetCategoryId
end

/*
Expand All @@ -205,4 +206,8 @@ function PANEL:EditItem( persistence, itemClass )
self.pricePremium:SetPrice( persistence.pricePremium )
end

function PANEL:SetTargetCategoryId( categoryId )
self.targetCategoryId = categoryId
end

vgui.Register( "DItemCreator", PANEL, "DFrame" )
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function PANEL:OnCompleted( )
self.stepsPanel:GoToStep( stepNum )
return Derma_Message( err, "Error" )
end
saveTable.targetCategoryId = self.targetCategoryId
Pointshop2View:getInstance( ):createPointshopItem( saveTable )
self:Close( )

Expand All @@ -83,6 +84,10 @@ function PANEL:OnCompleted( )
end
end

function PANEL:SetTargetCategoryId( categoryId )
self.targetCategoryId = categoryId
end

function PANEL:SetItemBase( itembase )
self.itembase = itembase
self.basicSettingsPanel:SetItemBase( itembase )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,44 @@ function SetupCategoryNode( node, pnlContent, noEdit, rightClickNodeFunction, ri
node.DoRightClick = function( self )
local menu = DermaMenu()
menu:SetSkin( self:GetSkin( ).Name )
local btn =menu:AddOption( "Edit", function()
local subMenu = menu:AddSubMenu( "Create Item Here")
subMenu:SetDisabled(not self.categoryInfo)

for k, mod in pairs( Pointshop2.Modules ) do
if not mod.Blueprints or #mod.Blueprints == 0 then
continue
end

for _, itemInfo in pairs( mod.Blueprints ) do
local iconButton = subMenu:AddOption( itemInfo.label, function()
self:InternalDoClick();
if not self.categoryInfo then
Derma_Message('Please press the save button before adding items.', 'Error')
return
end

local creator = vgui.Create( itemInfo.creator )
creator:MakePopup( )
creator:SetItemBase( itemInfo.base )
creator:SetSkin( Pointshop2.Config.DermaSkin )
creator:InvalidateLayout( true )
creator:Center( )
creator:SetTargetCategoryId( self.categoryInfo.self.id )
end)
iconButton:SetTooltip( itemInfo.tooltip )
iconButton:SetImage( itemInfo.icon )
iconButton.m_Image:SetMaterial( Material( itemInfo.icon, "noclamp smooth" ) )
iconButton.m_Image:SetSize( 16, 16 )
end
subMenu:AddSpacer()
end
subMenu:SetSkin( self:GetSkin( ).Name )
-- subMenu:SetImage( "pointshop2/wizard.png" )
-- subMenu.m_Image:SetSize( 16, 16 )

menu:AddSpacer()

local btn = menu:AddOption( "Edit", function()
self:InternalDoClick();
hook.Run( "PS2_OpenToolbox" )
hook.Run( "PS2_ToolboxFocus" )
Expand Down
16 changes: 14 additions & 2 deletions lua/ps2/server/sv_pointshopcontroller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,23 @@ function Pointshop2Controller:saveModuleItem( ply, saveTable )
return self:reportError( "Pointshop2View", ply, "Error saving item", 1, "Invalid Baseclass " .. saveTable.baseClass )
end

local targetCategoryId = saveTable.targetCategoryId
saveTable.targetCategoryId = nil --delete key

--If persistenceId != nil update existing
local isUpdate = saveTable.persistenceId != nil
class.getPersistence( ).createOrUpdateFromSaveTable( saveTable, isUpdate )
:Then(function(saved)
if targetCategoryId then
local mapping = Pointshop2.ItemMapping:new()
mapping.categoryId = targetCategoryId
mapping.itemClass = tostring(saved.itemPersistenceId)
return mapping:save():Then(function() return saved end)
end
return saved
end)
:Then( function( saved )
KLogf( 4, "[Pointshop2] Saved item %s", saveTable.name )
KLogf( 4, "[Pointshop2] Saved item %s category %s", saveTable.name, targetCategoryId or 'none' )
-- Use shortcut path for updates, do a full reload on newly created items
if isUpdate then
local outfitsChanged = saveTable.baseClass == "base_hat" and saveTable.outfitsChanged
Expand All @@ -608,7 +620,7 @@ function Pointshop2Controller:saveModuleItem( ply, saveTable )
local outfitsChanged = class == KInventory.Items.base_hat or subclassOf( KInventory.Items.base_hat, itemClass )
return self:moduleItemsChanged( outfitsChanged )
end
end, function( errid, err )
end):Fail(function( errid, err )
self:reportError( "Pointshop2View", ply, "Error saving item", errid, err )
end )
end
Expand Down

0 comments on commit 8ff8b90

Please sign in to comment.