diff --git a/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator.lua b/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator.lua index 4b378ef8..02f574e8 100644 --- a/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator.lua +++ b/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator.lua @@ -189,6 +189,7 @@ function PANEL:SaveItem( saveTable ) saveTable.baseClass = self.itembase saveTable.persistenceId = self.persistenceId + saveTable.targetCategoryId = self.targetCategoryId end /* @@ -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" ) \ No newline at end of file diff --git a/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator_steps.lua b/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator_steps.lua index 41bf9409..f4392585 100644 --- a/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator_steps.lua +++ b/lua/ps2/client/tabs/management_tab/create_item/cl_ditemcreator_steps.lua @@ -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( ) @@ -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 ) diff --git a/lua/ps2/client/tabs/management_tab/manage_items/content/cl_pointshop2content.lua b/lua/ps2/client/tabs/management_tab/manage_items/content/cl_pointshop2content.lua index 8d4cb985..7bb57a9d 100644 --- a/lua/ps2/client/tabs/management_tab/manage_items/content/cl_pointshop2content.lua +++ b/lua/ps2/client/tabs/management_tab/manage_items/content/cl_pointshop2content.lua @@ -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" ) diff --git a/lua/ps2/server/sv_pointshopcontroller.lua b/lua/ps2/server/sv_pointshopcontroller.lua index 551dc422..c5322623 100644 --- a/lua/ps2/server/sv_pointshopcontroller.lua +++ b/lua/ps2/server/sv_pointshopcontroller.lua @@ -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 @@ -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