• Extending The Equipment Shop (more per row)
    2 replies, posted
Hi, As I've added add-ons to my server there is a big scroll bar, is there any way I could make it so the point shop where you select the items you want to buy have more than two items per row. Have seen this on other servers and It looks and works really nicely. Thank You! (If you could just provide the code or paste your version of "cl_equip" I would be very grateful!) [CODE]---- Traitor equipment menu local GetTranslation = LANG.GetTranslation local GetPTranslation = LANG.GetParamTranslation -- Buyable weapons are loaded automatically. Buyable items are defined in -- equip_items_shd.lua local Equipment = nil function GetEquipmentForRole(role) -- need to build equipment cache? if not Equipment then -- start with all the non-weapon goodies local tbl = table.Copy(EquipmentItems) -- find buyable weapons to load info from for k, v in pairs(weapons.GetList()) do if v and v.CanBuy then local data = v.EquipMenuData or {} local base = { id = WEPS.GetClass(v), name = v.PrintName or "Unnamed", limited = v.LimitedStock, kind = v.Kind or WEAPON_NONE, slot = (v.Slot or 0) + 1, material = v.Icon or "VGUI/ttt/icon_id", -- the below should be specified in EquipMenuData, in which case -- these values are overwritten type = "Type not specified", model = "models/weapons/w_bugbait.mdl", desc = "No description specified." }; -- Force material to nil so that model key is used when we are -- explicitly told to do so (ie. material is false rather than nil). if data.modelicon then base.material = nil end table.Merge(base, data) -- add this buyable weapon to all relevant equipment tables for _, r in pairs(v.CanBuy) do table.insert(tbl[r], base) end end end -- mark custom items for r, is in pairs(tbl) do for _, i in pairs(is) do if i and i.id then i.custom = not table.HasValue(DefaultEquipment[r], i.id) end end end Equipment = tbl end return Equipment and Equipment[role] or {} end local function ItemIsWeapon(item) return not tonumber(item.id) end local function CanCarryWeapon(item) return LocalPlayer():CanCarryType(item.kind) end local color_bad = Color(220, 60, 60, 255) local color_good = Color(0, 200, 0, 255) -- Creates tabel of labels showing the status of ordering prerequisites local function PreqLabels(parent, x, y) local tbl = {} tbl.credits = vgui.Create("DLabel", parent) tbl.credits:SetToolTip(GetTranslation("equip_help_cost")) tbl.credits:SetPos(x, y) tbl.credits.Check = function(s, sel) local credits = LocalPlayer():GetCredits() return credits > 0, GetPTranslation("equip_cost", {num = credits}) end tbl.owned = vgui.Create("DLabel", parent) tbl.owned:SetToolTip(GetTranslation("equip_help_carry")) tbl.owned:CopyPos(tbl.credits) tbl.owned:MoveBelow(tbl.credits, y) tbl.owned.Check = function(s, sel) if ItemIsWeapon(sel) and (not CanCarryWeapon(sel)) then return false, GetPTranslation("equip_carry_slot", {slot = sel.slot}) elseif (not ItemIsWeapon(sel)) and LocalPlayer():HasEquipmentItem(sel.id) then return false, GetTranslation("equip_carry_own") else return true, GetTranslation("equip_carry") end end tbl.bought = vgui.Create("DLabel", parent) tbl.bought:SetToolTip(GetTranslation("equip_help_stock")) tbl.bought:CopyPos(tbl.owned) tbl.bought:MoveBelow(tbl.owned, y) tbl.bought.Check = function(s, sel) if sel.limited and LocalPlayer():HasBought(tostring(sel.id)) then return false, GetTranslation("equip_stock_deny") else return true, GetTranslation("equip_stock_ok") end end for k, pnl in pairs(tbl) do pnl:SetFont("TabLarge") end return function(selected) local allow = true for k, pnl in pairs(tbl) do local result, text = pnl:Check(selected) pnl:SetTextColor(result and color_good or color_bad) pnl:SetText(text) pnl:SizeToContents() allow = allow and result end return allow end end -- quick, very basic override of DPanelSelect local PANEL = {} local function DrawSelectedEquipment(pnl) surface.SetDrawColor(255, 200, 0, 255) surface.DrawOutlinedRect(0, 0, pnl:GetWide(), pnl:GetTall()) end function PANEL:SelectPanel(pnl) self.BaseClass.SelectPanel(self, pnl) if pnl then pnl.PaintOver = DrawSelectedEquipment end end vgui.Register("EquipSelect", PANEL, "DPanelSelect") local SafeTranslate = LANG.TryTranslation local color_darkened = Color(255,255,255, 80) -- TODO: make set of global role colour defs, these are same as wepswitch local color_slot = { [ROLE_TRAITOR] = Color(180, 50, 40, 255), [ROLE_DETECTIVE] = Color(50, 60, 180, 255) }; local eqframe = nil local function TraitorMenuPopup() local ply = LocalPlayer() if not IsValid(ply) or not ply:IsActiveSpecial() then return end -- Close any existing traitor menu if eqframe and ValidPanel(eqframe) then eqframe:Close() end local credits = ply:GetCredits() local can_order = credits > 0 local dframe = vgui.Create("DFrame") --buy window size local w, h = 500, 400 dframe:SetSize(w, h) dframe:Center() dframe:SetTitle(GetTranslation("equip_title")) dframe:SetVisible(true) dframe:ShowCloseButton(true) dframe:SetMouseInputEnabled(true) dframe:SetDeleteOnClose(true) local m = 5 local dsheet = vgui.Create("DPropertySheet", dframe) -- Add a callback when switching tabs local oldfunc = dsheet.SetActiveTab dsheet.SetActiveTab = function(self, new) if self.m_pActiveTab != new and self.OnTabChanged then self:OnTabChanged(self.m_pActiveTab, new) end oldfunc(self, new) end dsheet:SetPos(0,0) dsheet:StretchToParent(m,m + 25,m,m) local padding = dsheet:GetPadding() local dequip = vgui.Create("DPanel", dsheet) dequip:SetPaintBackground(false) dequip:StretchToParent(padding,padding,padding,padding) -- Determine if we already have equipment local owned_ids = {} for _, wep in pairs(ply:GetWeapons()) do if IsValid(wep) and wep:IsEquipment() then table.insert(owned_ids, wep:GetClass()) end end -- Stick to one value for no equipment if #owned_ids == 0 then owned_ids = nil end --- Construct icon listing local dlist = vgui.Create("EquipSelect", dequip) dlist:SetPos(0,0) --equiplist size dlist:SetSize(154, h - 75) dlist:EnableVerticalScrollbar(true) dlist:EnableHorizontal(true) dlist:SetPadding(4) local items = GetEquipmentForRole(ply:GetRole()) local to_select = nil for k, item in pairs(items) do local ic = nil -- Create icon panel if item.material then if item.custom then -- Custom marker icon ic = vgui.Create("LayeredIcon", dlist) local marker = vgui.Create("DImage") marker:SetImage("VGUI/ttt/custom_marker") marker.PerformLayout = function(s) s:AlignBottom(2) s:AlignRight(
There was a somewhat good one out there, lemme find it for you.
"(If you could just provide the code or paste your version of "cl_equip" I would be very grateful!)" This isn't the place to ask for code. This is the place where we help developers fix their code.
Sorry, you need to Log In to post a reply to this thread.