helix icon indicating copy to clipboard operation
helix copied to clipboard

DPanel to DScrollPanel for new vars setup

Open lechu2375 opened this issue 4 years ago • 3 comments

lechu2375 avatar Feb 25 '21 16:02 lechu2375

@lechu2375 Would you mind providing some test cases to ensure this works?

ZeMysticalTaco avatar Jul 04 '21 08:07 ZeMysticalTaco

Idk if this will work for you.

ix.char.RegisterVar("headmodel", {
		field = "headmodel",
		fieldType = ix.type.string,
		default = "models/player/headse/male_caucasian.mdl",
		index = 3,
		OnSet = function(character,value)
			local client = character:GetPlayer()
            
            /*
            if(IsValid(client))then
			    if(client.head)then
                    client.head:SetModel(value)
                end
            end*/

			character.vars.headmodel = value
            client:LoadBody()
		end,
		OnGet = function(character, default)
			return character.vars.headmodel or default
		end,
		OnDisplay = function(self, container, payload)
			payload:Set("headmodel",self.default)
            local charmenu = container:GetParent():GetParent()
            charmenu.factionModel:SetModel("models/player/headse/male_caucasian.mdl")
            charmenu.descriptionModel:SetModel("models/player/headse/male_caucasian.mdl")
            charmenu.attributesModel:SetModel("models/player/headse/male_caucasian.mdl")

			//print(PrintTable(charmenu.descriptionModel.Entity:GetColor()))

			local scroll = container:Add("DScrollPanel")
			scroll:Dock(TOP) -- TODO: don't fill so we can allow other panels
            scroll:SetHeight(container:GetTall()*.5)
			scroll.Paint = function(panel, width, height)
				derma.SkinFunc("DrawImportantBackground", 0, 0, width, height, Color(255, 255, 255, 25))
			end

			local layout = scroll:Add("DIconLayout")
			layout:Dock(FILL)
			layout:SetSpaceX(2)
			layout:SetSpaceY(2)


				for k, v in pairs(aviableHeads) do
					local icon = layout:Add("SpawnIcon")
					icon:SetSize(128, 256)
					icon:InvalidateLayout(true)
					icon.DoClick = function(this)
                        charmenu.factionModel:SetModel(k)
                        charmenu.descriptionModel:SetModel(k)
                        charmenu.attributesModel:SetModel(k)
						payload:Set("headmodel", k)

					end
					icon.PaintOver = function(this, w, h)
						if (payload.headmodel == k) then
							local color = ix.config.Get("color", color_white)

							surface.SetDrawColor(color.r, color.g, color.b, 200)

							for i = 1, 3 do
								local i2 = i * 2
								surface.DrawOutlinedRect(i, i, w - i2, h - i2)
							end
						end
					end
					icon:SetModel(k)
				end
				//scroll:SizeToContentsY()

			return scroll
		end,
		OnValidate = function(self, value, payload, client)

			if (!payload.headmodel) then
				return false, "needHeadModel"
			end
		end,
		OnAdjust = function(self, client, data, value, newData)
            
		end,
		ShouldDisplay = function(self, container, payload)
			return true
		end
	}) 

lechu2375 avatar Jul 04 '21 15:07 lechu2375

But im 100% sure that this DScrollPanel is better than DPanel, Just make few charvars setup and you will see

lechu2375 avatar Jul 04 '21 15:07 lechu2375