Text, Icons, and Frames?

I want to place text immediately below a unit’s (player, target, pet, etc.,) picture portrait. For example, the text may be a timer, or the distance from and direction to some object. So, the text has to be constantly updated as game conditions dictate. Also, I want to be able to drag the icon + text and drop it in a convenient place on the screen. Here’s an illustration:

 [PORTRAIT]
string of text

I hope this makes sense.

have you tried the Weak Auras addon?

Expanding on the previous example (how you update the text would depend on what exactly you want to display so…). It might be a lot easier to tell us what outcome you are trying to achieve rather than drip feeding questions.

local Player3D = CreateFrame("PlayerModel", "FizzlePlayer3D", UIParent)
Player3D:SetSize(100, 100)
Player3D:SetUnit("player")
Player3D:SetPoint("CENTER", -200, 0)
Player3D:SetPortraitZoom(1)
Player3D:EnableMouse(true)
Player3D:SetMovable (true)
Player3D:RegisterForDrag("LeftButton")
Player3D:SetUserPlaced(true)
Player3D:SetScript("OnEvent", function(self)
	self:SetUnit("player")
end)
Player3D:SetScript("OnDragStart", function(self)
	self:StartMoving()
end)
Player3D:SetScript("OnDragStop", function(self)
	self:StopMovingOrSizing()
end)
Player3D.Text = Player3D:CreateFontString()
Player3D.Text:SetFontObject(GameFontNormalLarge)
Player3D.Text:SetJustifyH("CENTER")
Player3D.Text:SetJustifyV("CENTER")
Player3D.Text:SetPoint("TOP", Player3D, "BOTTOM", 0, -5)
Player3D.Text:SetText("Some Text To Diaplsy")

Note that this portion will only work outside of instances, as the coordinates functions are protected in instances and unavailable to addons to prevent exactly this application.

You can still do it, but in any instance, it won’t return any values for player coordinates.

OK, Fizzlemizz, you asked for it :wink:

FYI, I enjoy coding and do it for fun. To date I’ve written (with help from members of this forum, especially Fizzlemizz, Ketho, Elvenbane, and others ) a combat assessment addon and a bag management addon - none of which have been, or are intended to be, released to the community. There are better, more functional, and sophisticated versions of these addons. I do this for fun and to learn more about how WoW works. That having been said, I’m now having fun prototyping a threat assessment addon.

Here, then, is a high-level functional description of my current project:

Assume a party of 2 to 5 players each of which are represented by a player portrait. Currently, the addon stacks the portraits vertically within a single, movable, enclosing frame. Thus, when the enclosing frame is moved, all the portraits are moved simultaneously while maintaining their relative positions. Below each player’s portrait will be the % threat directed at that player. Moreover, the portraits are positioned such that the addon can dynamically order them according the amount of threat directed at the player. The player with the highest threat will have his/her portrait at the top of the stack AND possibly highlighted in some way.

The difficulties I’m having with this addon arise from my lack of experience developing graphics software (I’m a retired Kernel guy - Linux, Windows). Specifically, I would like to have the enclosing frame invisible. However, it’s not immediately clear to me how to accomplish this. Maybe there’s a better way to group the player portraits. Perhaps I should use multiple frames, regions, or layers. For example, I could have the portraits in one frame, the threat text in another, etc.

One final thought: an easier way to implement this might be just to write an addon that uses unit frames (using a threat bar instead of a health bar). But I decided that it didn’t really float my boat. First, unit frames take up too much real estate and second unit frames are not (in my view) visually compelling. I want an addon that is visually representative of the player’s threat context. An addon that does not require a player to read text. For example, Weak Auras and Tell Me When are addons that can be configured to represent combat state 100% visually. For me, an icon jumping to the top of the boss’s threat table with an accompanying sound seems to me to be a visually elegant way to notify the player(s) that s*t may be in the offing.

Hopes this clarifies.

When a region or frame is anchored to another with SetPoint, it will stay attached and move whenever its “relativeTo” frame/region moves.
https://wow.gamepedia.com/API_Region_SetPoint

This is a very basic example from what you describe that should help get you started:

local BUTTON_WIDTH = 200
local BUTTON_HEIGHT = 40
local NUM_BUTTONS = 4

-- frame "factory" returns a frame with elements Portrait, Name and Threat
local function createUnitButton(parent)

  local button = CreateFrame("Button",nil,parent,"TooltipBackdropTemplate")
  button:SetBackdropBorderColor(0.5,0.5,0.5)

  button.Portrait = button:CreateTexture(nil,"ARTWORK")
  button.Portrait:SetSize(BUTTON_HEIGHT-8,BUTTON_HEIGHT-8)
  button.Portrait:SetPoint("LEFT",4,0)

  button.Name = button:CreateFontString(nil,"ARTWORK", "GameFontNormal")
  button.Name:SetPoint("TOPLEFT",button.Portrait,"TOPRIGHT",4,-4)
  button.Name:SetPoint("BOTTOMRIGHT",button,"RIGHT",-4,0)
  button.Name:SetJustifyH("LEFT")

  button.Threat = button:CreateFontString(nil,"ARTWORK","GameFontHighlight")
  button.Threat:SetPoint("TOPLEFT",button.Portrait,"RIGHT",4,0)
  button.Threat:SetPoint("BOTTOMRIGHT",-4,4)
  button.Threat:SetJustifyH("LEFT")

  return button
end

-- updates the portrait, name and threat to the given unit
-- (this is for demo purposes; it'd be better to only update portrait and
-- name when the unit changes, and a separate function to update threat)
local function updateUnitButton(button,unit)
  SetPortraitTexture(button.Portrait,unit)
  button.Name:SetText(UnitName(unit))
  button.Threat:SetText("100% Threat")
end

-- creates parent frame with a standard-looking template
local f = CreateFrame("Frame", nil, UIParent, "BasicFrameTemplate")
f:SetSize(BUTTON_WIDTH+10,BUTTON_HEIGHT*NUM_BUTTONS+28)
f:SetPoint("CENTER")
f.TitleText:SetText("Demo")

-- make parent frame movable
f:SetMovable(true)
f:SetScript("OnMouseDown",f.StartMoving)
f:SetScript("OnMouseUp",f.StopMovingOrSizing)

-- create and position 3 unitbuttons anchored to the parent
f.unitButtons = {}
for i=1,NUM_BUTTONS do
  f.unitButtons[i] = createUnitButton(f)
  f.unitButtons[i]:SetSize(BUTTON_WIDTH,BUTTON_HEIGHT)
  f.unitButtons[i]:SetPoint("TOPLEFT",5,-((i-1)*BUTTON_HEIGHT)-24)
  updateUnitButton(f.unitButtons[i],"player")
end  

https://i.imgur.com/t7Z2tjA.png

No problem at all :rofl:

(thanks Gello)

See, this is exactly why I have these noob problems. I never even thought of using a button frame.