vrtc / chorus (public) (License: CC0) (since 2023-08-12) (hash sha1)
World of Warcraft add-on stub. The overall goal is to create a specialized raid frame.

/src/ChorusUnitButtonTemplate.lua (1d353d5779a87b4f6b955bf4637c999f3454335d) (3963 bytes) (mode 100644) (type blob)

--[[--
@submodule chorus
]]

local Chorus = Chorus

local GameTooltip = GameTooltip
local GameTooltipTextLeft1 = GameTooltipTextLeft1

local TargetFrameDropDown = TargetFrameDropDown
local PlayerFrameDropDown = PlayerFrameDropDown
local FocusFrameDropDown = FocusFrameDropDown
local PartyMemberFrame1DropDown = PartyMemberFrame1DropDown
local PartyMemberFrame2DropDown = PartyMemberFrame2DropDown
local PartyMemberFrame3DropDown = PartyMemberFrame3DropDown
local PartyMemberFrame4DropDown = PartyMemberFrame4DropDown

local ToggleDropDownMenu = ToggleDropDownMenu

local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor
local GameTooltip_UnitColor = GameTooltip_UnitColor
local SecureButton_GetUnit = Chorus.test.SecureButton_GetUnit or SecureButton_GetUnit

local function unitButtonLeaveProcessor()
	assert(GameTooltip ~= nil)

	GameTooltip:FadeOut()
end

local function unitButtonEnterProcessor(unitButton)
	assert(GameTooltip ~= nil)

	local unitDesignation = SecureButton_GetUnit(unitButton)
	if unitDesignation then
		GameTooltip_SetDefaultAnchor(GameTooltip, unitButton);
		GameTooltip:SetUnit(unitDesignation)
		local r, g, b = GameTooltip_UnitColor(unitDesignation);
		GameTooltipTextLeft1:SetTextColor(r, g, b);
	end
end

local function contextMenuToggle(self, unitDesignation, buttonDesignation, buttonType)
	assert(self ~= nil)
	assert(unitDesignation ~= nil)
	assert(buttonDesignation ~= nil)
	assert(buttonType ~= nil)

	local offsetX = self:GetWidth() / 2
	local offsetY = self:GetHeight()
	local contextMenu
	if UnitIsUnit('target', unitDesignation) then
		contextMenu = TargetFrameDropDown
	elseif UnitIsUnit('focus', unitDesignation) then
		contextMenu = FocusFrameDropDown
	elseif UnitIsUnit('player', unitDesignation) then
		contextMenu = PlayerFrameDropDown
	elseif UnitIsUnit('party1', unitDesignation) then
		contextMenu = PartyMemberFrame1DropDown
	elseif UnitIsUnit('party2', unitDesignation) then
		contextMenu = PartyMemberFrame2DropDown
	elseif UnitIsUnit('party3', unitDesignation) then
		contextMenu = PartyMemberFrame3DropDown
	elseif UnitIsUnit('party4', unitDesignation) then
		contextMenu = PartyMemberFrame4DropDown
	else
		contextMenu = TargetFrameDropDown
	end

	assert(contextMenu ~= nil, 'ChorusUnitButtonTemplate.lua: count not determine ' ..
	'appropriate context menu to show for ' .. self:GetName())

	--[[ Not sure what `level` is. Maybe menu nesting? ]]--
	local level = 1
	--[[ Don't know what `value` is. Usually it's nil. ]]--
	local value = nil
	local anchorName = self:GetName() or 'ChorusFrame'
	ToggleDropDownMenu(level, value, contextMenu, anchorName, offsetX, offsetY)
end

--[[--
`ChorusUnitButtonTemplate` handles only the secure, clickable portion of unit
buttons, and *none* of the visuals.

The root template for unit buttons is `ChorusUnitFrameTemplate`.

@see FrameXML/UnitPopup.lua:UnitPopupFrames
@see FrameXML/UIDropDownMenu.lua:function ToggleDropDownMenu

@function unitButtonMain
@tparam frame self this unit button
]]
function Chorus.unitButtonMain(self)
	self:RegisterForClicks('AnyUp')

	--[[ NOTE The menu functions are equivalent of PlayerFrame.menu and
	TargetFrame.menu. It is possible to use them direcctly. THe only
	quirk is that the context menu will be displayed at the display point
	of the native unit frames. Hence, the need to define separate menu
	functions. ]]--

	self.menu = contextMenuToggle

	--[[-- @fixme Selecting "Set focus" option in the context menu for Chorus
	unit button results in permission violation exception (restricted
	execution environment issue).]]

	local focuscastModifier = GetModifiedClick('FOCUSCAST')
	if focuscastModifier and 'NONE' ~= focuscastModifier then
		local key = string.lower(focuscastModifier) .. '-type1'
		self:SetAttribute(key, 'focus')
	end

	--[[ Toggle game tooltip on mouseover. ]]--
	self:SetScript('OnEnter', unitButtonEnterProcessor)
	self:SetScript('OnLeave', unitButtonLeaveProcessor)

	RegisterUnitWatch(self)
end


Mode Type Size Ref File
100644 blob 35 5c40e6e2862d70b5c51c326a13073a4012ac05c7 .gitignore
100644 blob 3606 f73da473168d1897963fd2e32d89841ca0461ec0 README.adoc
040000 tree - 271296b4bafcaa151458a0192fd313641ca9b409 bin
100644 blob 228 c7dd24afa7d5c2375ff60a91c73623a304b808f9 chorus.toc
040000 tree - 99c99c3cbc641f8954a5be291e61681cb5e74629 conf
040000 tree - efa7258757edf7b888ea13c215e14b497fef8a16 doc
100644 blob 2391 1b0ca1bc25f74a34476360e5a8f14e28767b204e makefile
040000 tree - b9d3ea9d61b99ee71b5fcdbc6b18843df20c8c3c src
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/vrtc/chorus

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/vrtc/chorus

Clone this repository using git:
git clone git://git.rocketgit.com/user/vrtc/chorus

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main