Added unequip option to items

master
AlmTech Software 5 years ago
parent 56d397f110
commit f2c110ee73
  1. 15
      gamemode/engine/core/client/cl_character_net.lua
  2. 35
      gamemode/engine/derma/lib/cl_menu_iteminfo.lua
  3. 14
      gamemode/engine/derma/menus/menu_charinfo.lua
  4. 3
      gamemode/engine/lib/server/sv_networking.lua
  5. 7
      gamemode/engine/vars/sh_vars.lua

@ -113,3 +113,18 @@ function Quantum.Client.InventoryNet.EquipItem( index )
end end
end end
end end
function Quantum.Client.InventoryNet.UnequipItem( equipindex )
-- local item = Quantum.Client.Inventory[index]
-- local itemTbl = Quantum.Item.Get( item[1] )
-- if( itemTbl != nil && item[2] > 0 ) then
-- if( itemTbl.equipslot != nil ) then
net.Start( "quantum_item_action" )
Quantum.WriteIntcode( Quantum.IntCode.UNEQUIP_ITEM )
net.WriteInt( equipindex, Quantum.calculateNeededBits( Quantum.Inventory.Size ) )
net.SendToServer()
-- end
-- end
end

@ -189,6 +189,8 @@ function iteminfo.giveoptions( p, page )
if( item.equipslot != nil ) then -- Equip if( item.equipslot != nil ) then -- Equip
if( page.equippanels[item.equipslot].itemindex != index ) then
op.equip = vgui.Create( "DButton", options ) op.equip = vgui.Create( "DButton", options )
op.equip:SetText( "Equip (" .. Quantum.EquipSlotsNames[item.equipslot] .. ")" ) op.equip:SetText( "Equip (" .. Quantum.EquipSlotsNames[item.equipslot] .. ")" )
op.equip:SetFont( "q_item_option_button" ) op.equip:SetFont( "q_item_option_button" )
@ -204,7 +206,7 @@ function iteminfo.giveoptions( p, page )
options.Close() options.Close()
if( page.equippanels[item.equipslot] != nil ) then if( page.equippanels[item.equipslot] != nil ) then
page.equippanels[item.equipslot].SetItem( item.id ) -- set its item page.equippanels[item.equipslot].SetItem( index ) -- set its item
end end
if( page.markedItemPanel[item.equipslot] != nil ) then if( page.markedItemPanel[item.equipslot] != nil ) then
@ -216,6 +218,37 @@ function iteminfo.giveoptions( p, page )
---- EQUIP NET ---- ---- EQUIP NET ----
Quantum.Client.InventoryNet.EquipItem( index ) Quantum.Client.InventoryNet.EquipItem( index )
end end
else
op.equip = vgui.Create( "DButton", options )
op.equip:SetText( "Unequip (" .. Quantum.EquipSlotsNames[item.equipslot] .. ")" )
op.equip:SetFont( "q_item_option_button" )
op.equip:SizeToContents()
op.equip.w, op.equip.h = op.equip:GetSize()
op.equip:SetPos( xbasepos, ypos )
op.equip.x, op.equip.y = op.equip:GetPos()
op.equip.Paint = function( self )
theme.iteminfobutton( self )
end
op.equip.DoClick = function( self )
surface.PlaySound( "UI/buttonclick.wav" )
options.Close()
if( page.equippanels[item.equipslot] != nil ) then
page.equippanels[item.equipslot].SetItem( nil ) -- remove the item from the display
end
if( page.markedItemPanel[item.equipslot] != nil ) then
page.markedItemPanel[item.equipslot]:SetVisible( false ) -- unmark the panel
end
page.markedItemPanel[item.equipslot] = nil -- remove it from the table so its spot is free
---- EQUIP NET ----
Quantum.Client.InventoryNet.UnequipItem( item.equipslot )
end
end
ypos = ypos + op.equip.h + yspacing ypos = ypos + op.equip.h + yspacing
end end

@ -64,12 +64,16 @@ local function createEquipSlotPanel( equiptype, x, y, scale, parent )
theme.itempanel( self, self.itemcolor, true ) theme.itempanel( self, self.itemcolor, true )
end end
function p.SetItem( itemid ) function p.SetItem( itemindex, itemid )
--local itemid = itempanel.item.id local item = Quantum.Client.Inventory[itemindex]
if( item != nil ) then
itemid = itemid || item[1]
local itemTbl = Quantum.Item.Get( itemid ) local itemTbl = Quantum.Item.Get( itemid )
if( itemTbl != nil ) then
--itempanel:Remove()
p.itemid = itemid -- give it its equipped item p.itemid = itemid -- give it its equipped item
p.itemindex = itemindex
p.itemcolor = itemTbl.rarity.color -- give it its color p.itemcolor = itemTbl.rarity.color -- give it its color
p.item = itemTbl p.item = itemTbl
@ -121,7 +125,7 @@ end
local function getItemInSlot( pos ) local function getItemInSlot( pos )
local inv = Quantum.Client.Inventory || {} local inv = Quantum.Client.Inventory || {}
if( inv[pos] != nil ) then if( inv[pos] != nil ) then
return inv[pos][1] return pos, inv[pos][1]
else else
return return
end end

@ -174,6 +174,9 @@ local intcodeFunctions = {
end, end,
[Quantum.IntCode.EQUIP_ITEM] = function( pl, index, itemid, amount ) [Quantum.IntCode.EQUIP_ITEM] = function( pl, index, itemid, amount )
Quantum.Server.Inventory.EquipItem( pl, index ) Quantum.Server.Inventory.EquipItem( pl, index )
end,
[Quantum.IntCode.UNEQUIP_ITEM] = function( pl, equipslot, itemid, amount )
Quantum.Server.Inventory.UnEquipItem( pl, equipslot )
end end
} }

@ -41,9 +41,10 @@ Quantum.IntCode = {
USE_ITEM = 2, USE_ITEM = 2,
EAT_ITEM = 3, EAT_ITEM = 3,
EQUIP_ITEM = 4, EQUIP_ITEM = 4,
DESTROY_ITEM = 5, -- to be added UNEQUIP_ITEM = 5,
UPDATE = 6, DESTROY_ITEM = 6, -- to be added
BIT_SIZE = 4 UPDATE = 7,
BIT_SIZE = 5
} }
function Quantum.calculateNeededBits( n ) return math.ceil( math.log( n, 2 ) ) end function Quantum.calculateNeededBits( n ) return math.ceil( math.log( n, 2 ) ) end

Loading…
Cancel
Save