Suggestion: Close gap in 3d portrait background #1211


Open
  • transitbus created this issue Jul 28, 2017

    When setting the background to have a 3D portrait, there is an unavoidable gap or padding you have hard coded for the portrait. Currently it is 2 and -2 but this leaves a noticeable padding around the edges of the portraits.

     

    Modules\Background\\Background.lua

     

    Line 63 and 64 are set at for the setpoint

     

    portrait:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2)
    portrait:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)

     

    Edit: See comment below for suggestion code that allows user input via a slider to change the border setpoint padding from 0 to a max of 2 (the current hard coded amount). It defaults to 2

     

     

    Current 3D portrait padding:

     

     

    Padding set to 0

     

     

     

     

     

    I can always edit this manually if its not something you want so no big deal ;)

  • transitbus edited description Jul 28, 2017
  • transitbus edited description Aug 2, 2017
  • transitbus posted a comment Aug 3, 2017

    I modified it to be an option in the Layout Editor > Other> background tab

     

    It allows a slider from 0 to 2 in increments of 1. This way it gives control over any unit frame that has background enabled and allows visual control over how the 3D portrait shows (if enabled)

     

    Localizations are already there for padding so that won't need to be touched. No clue how to add alignment options for ace option table elements or if you even can (spacing doesn't seem to be an option ). Been a while since I look at that so I can't remember at all. I guess the good thing is it dynamically adjust based on how you draw out the size of the options window by pulling it - the below image is me with the options window slightly stretched on my monitor

     

     

    _________________________________________________________________

     

    after line 13 added

     

    color = { 0, 0, 0, 0.5 },
    padding = 2,

     

    after line 47 added

     

    local padding = layout_db.padding

     

    line 63 and 64 changed to

     

    portrait:SetPoint("TOPLEFT", frame, "TOPLEFT", -padding, padding)
    portrait:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -padding, padding)

     

    after line 171 added

     

    , 'padding', {
    type = 'range',
    name = L["Padding"],
    desc = L["How far the border should be from the frame."],
    get = function(info)
    return PitBull4.Options.GetLayoutDB(self).padding
    end,
    set = function(info, value)
    PitBull4.Options.GetLayoutDB(self).padding = value

    for frame in PitBull4:IterateFrames() do
    if self:GetLayoutDB(frame).enabled then
    self:Clear(frame)
    self:Update(frame)
    end
    end
    end,
    min = 0,
    max = 2,
    step = 1,
    }

     

    ___________________________________________________________________________________

     

    Complete background.lua modified:

     

    local PitBull4 = _G.PitBull4
    local L = PitBull4.L
    
    local PitBull4_Background = PitBull4:NewModule("Background", "AceEvent-3.0")
    
    PitBull4_Background:SetModuleType("custom")
    PitBull4_Background:SetName(L["Background"])
    PitBull4_Background:SetDescription(L["Show a flat background for your unit frames."])
    PitBull4_Background:SetDefaults({
    	portrait = false,
    	fallback_style = "three_dimensional",
    	color = { 0, 0, 0, 0.5 },
    	padding = 2,
    })
    
    local guid_demanding_update = nil
    
    function PitBull4_Background:OnEnable()
    	self:RegisterEvent("UNIT_PORTRAIT_UPDATE")
    end
    
    function PitBull4_Background:UNIT_PORTRAIT_UPDATE(event, unit)
    	if not unit then return end
    	local guid = UnitGUID(unit)
    	guid_demanding_update = guid
    	self:UpdateForGUID(guid)
    	guid_demanding_update = nil
    end
    
    -- this is here to allow it to be overridden, e.g., aggro module
    function PitBull4_Background:GetColor(frame)
    	return unpack(PitBull4_Background:GetLayoutDB(frame).color)
    end
    
    function PitBull4_Background:UpdateFrame(frame)
    	local background = frame.Background
    	if not background then
    		background = PitBull4.Controls.MakeTexture(frame, "BACKGROUND")
    		frame.Background = background
    		background:SetAllPoints(frame)
    	end
    
    	background:Show()
    	background:SetColorTexture(self:GetColor(frame))
    
    	-- 3D Portrait
    	local layout_db = self:GetLayoutDB(frame)
    	local padding = layout_db.padding
    	if not layout_db.portrait then
    		return false
    	end
    
    	local unit = frame.unit
    	local falling_back = false
    	if not unit or not UnitExists(unit) or not UnitIsConnected(unit) or not UnitIsVisible(unit) then
    		falling_back = true
    	end
    
    	local portrait = frame.PortraitBG
    	local created = not portrait
    	if created then
    		portrait = PitBull4.Controls.MakePlayerModel(frame)
    		portrait:SetFrameLevel(frame:GetFrameLevel()) -- don't go above bars and indicators
    		portrait:SetPoint("TOPLEFT", frame, "TOPLEFT", -padding, padding)
    		portrait:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -padding, padding)
    		frame.PortraitBG = portrait
    	end
    
    	if portrait.guid == frame.guid and guid_demanding_update ~= frame.guid then
    		portrait:Show()
    		return false
    	end
    
    	portrait.guid = frame.guid
    	portrait:ClearModel()
    	if not falling_back then
    		portrait:SetUnit(frame.unit)
    		portrait:SetPortraitZoom(1)
    		portrait:SetPosition(0, 0, 0)
    	elseif layout_db.fallback_style == "three_dimensional" then
    		portrait:SetModelScale(1)
    		portrait:SetModel([[Interface\Buttons\talktomequestionmark.mdx]])
    		portrait:SetPosition(-0.55, 0, 0)
    	end
    	portrait:Show()
    
    	return created
    end
    
    function PitBull4_Background:ClearFrame(frame)
    	if frame.Background then
    		frame.Background = frame.Background:Delete()
    	end
    
    	if frame.PortraitBG then
    		local portrait = frame.PortraitBG
    		portrait.guid = nil
    		frame.PortraitBG = portrait:Delete()
    
    		return true
    	end
    
    	return false
    end
    
    function PitBull4_Background:OnHide(frame)
    	local background = frame.Background
    	if background then
    		background:Hide()
    	end
    
    	local portrait = frame.PortraitBG
    	if portrait then
    		portrait.guid = frame.guid
    		portrait:Hide()
    	end
    end
    
    PitBull4_Background:SetLayoutOptionsFunction(function(self)
    	return 'color', {
    		type = 'color',
    		name = L["Color"],
    		desc = L["Color that the background should be."],
    		hasAlpha = true,
    		get = function(info)
    			return unpack(PitBull4.Options.GetLayoutDB(self).color)
    		end,
    		set = function(info, r, g, b, a)
    			local color = PitBull4.Options.GetLayoutDB(self).color
    			color[1], color[2], color[3], color[4] = r, g, b, a
    
    			PitBull4.Options.UpdateFrames()
    		end,
    	}, 'portrait', {
    		type = 'toggle',
    		name = L["Portrait"],
    		desc = L["Show a portrait of the unit."],
    		get = function(info)
    			return PitBull4.Options.GetLayoutDB(self).portrait
    		end,
    		set = function(info, value)
    			PitBull4.Options.GetLayoutDB(self).portrait = value
    
    			for frame in PitBull4:IterateFrames() do
    				if self:GetLayoutDB(frame).enabled then
    					self:Clear(frame)
    					self:Update(frame)
    				end
    			end
    		end,
    	}, 'fallback_style', {
    		type = 'select',
    		name = L["Fallback style"],
    		desc = L["Set the portrait style for when the normal style can't be shown, such as if they are out of visibility."],
    		get = function(info)
    			return PitBull4.Options.GetLayoutDB(self).fallback_style
    		end,
    		set = function(info, value)
    			PitBull4.Options.GetLayoutDB(self).fallback_style = value
    
    			for frame in PitBull4:IterateFrames() do
    				if self:GetLayoutDB(frame).portrait then
    					self:Clear(frame)
    					self:Update(frame)
    				end
    			end
    		end,
    		values = {
    			["three_dimensional"] = L["3D question mark"],
    			["blank"] = L["Blank"],
    		},
    	}, 'padding', {
    		type = 'range',
    		name = L["Padding"],
    		desc = L["How far the border should be from the frame."],
    		get = function(info)
    			return PitBull4.Options.GetLayoutDB(self).padding
    		end,
    		set = function(info, value)
    			PitBull4.Options.GetLayoutDB(self).padding = value
    
    			for frame in PitBull4:IterateFrames() do
    				if self:GetLayoutDB(frame).enabled then
    					self:Clear(frame)
    					self:Update(frame)
    				end
    			end
    		end,
    		min = 0,
    		max = 2,
    		step = 1,
    	}
    end)

    Edited Aug 3, 2017
  • transitbus edited description Aug 3, 2017

To post a comment, please login or register a new account.