View Single Post
02-25-19, 11:19 AM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
This is done by the game where each of your "sub-frame" unit buttons is created by inheriting from the SecureUnitButtonTemplate. Once you've done that, when you click on a unit, the game will make it your target.

The basics of creating a unit button is:

Lua Code:
  1. --Create the unit button:
  2. local f = CreateFrame("Button", "wille480PlayerFrame", UIParent, "SecureUnitButtonTemplate")
  3.  
  4. -- Tell it which unit to represent (in this case "player":
  5. f:SetAttribute("unit", "player")
  6.  
  7. -- Tell the game to "look after it"
  8. RegisterUnitWatch(f)
  9.  
  10. -- Tell it to show the unit's vehicle when the unit is in one:
  11. f:SetAttribute("toggleForVehicle", true)
  12.  
  13. -- Give it the standard click actions:
  14. f:RegisterForClicks("AnyUp")
  15. f:SetAttribute("*type1", "target") -- Target unit on left click
  16. f:SetAttribute("*type2", "togglemenu") -- Toggle units menu on left click
  17. f:SetAttribute("*type3", "assist") -- On middle click, target the target of the clicked unit
  18.  
  19. -- Make it visible for testing purposes:
  20. f:SetPoint("CENTER")
  21. f:SetSize(100, 100)
  22. f:SetBackdrop({ bgFile = "Interface\\BUTTONS\\WHITE8X8" })
  23. f:SetBackdropColor(0.3, 0.3, 0.3, 0.6)
  24.  
  25. -- Then add other objects (such as font strings and status bars), register events (such as UNIT_HEALTH), and add scripts to update the objects in response to the events.

Obviously it needs other "plumbing like health/power bars/texts etc. but that is all up to you as to what you add/leave out from each unit.

If you are looking for a simple (as can be) example of putting this together into a raid frame type configuration using secure group templates , take a loot at ShotGlass
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-25-19 at 11:56 AM.
  Reply With Quote