Spellbook Mouseover Highlight Implementation #25


  • Enhancement
Closed
  • Ferodra created this issue May 6, 2020

    Title says it all, here's my implementation for this feature.

    It probably could need some improvement as it's pretty dirty code, but it gets the job done.

     

     

    -- Separate new action highlight cache
    lib.NEW_ACTION_HIGHLIGHT_MARKS = {}
    
    function ClearNewActionHighlight(action, preventIdenticalActionsFromClearing, value)
    	if action then
    		lib.ACTION_HIGHLIGHT_MARKS[action] = value
    		lib.NEW_ACTION_HIGHLIGHT_MARKS[action] = nil
    	end
    
    	for button in next, ButtonRegistry do
    		if button._state_type == "action" and (action == tonumber(button._state_action) or action == button.SpellID) then
    			UpdateNewAction(button)
    		end
    	end
    	
    	if preventIdenticalActionsFromClearing or not action then
    		return
    	end
    
    	-- iterate through actions and unmark all that are the same type
    	local unmarkedType, unmarkedID = GetActionInfo(action)
    	for actionKey, markValue in pairs(lib.ACTION_HIGHLIGHT_MARKS) do
    		if markValue then
    			local actionType, actionID = GetActionInfo(actionKey)
    			if actionType == unmarkedType and actionID == unmarkedID then
    				ClearNewActionHighlight(actionKey, true, value)
    			end
    		end
    	end
    end
    
    local function MarkNewAction(action)
    	lib.ACTION_HIGHLIGHT_MARKS[action] = true
    	-- New Actions are cached separately to avoid accidentally overriding them
    	lib.NEW_ACTION_HIGHLIGHT_MARKS[action] = true
    	
    	for button in next, ButtonRegistry do
    		if button._state_type == "action" and action == tonumber(button._state_action) then
    			UpdateNewAction(button)
    		end
    	end
    end
    
    -- Highlights Actionbuttons by Spell ID
    -- Also checks if the button spell is an action with the same name. This is for spells that have different IDs, but essentially are the same.
    local function MarkSpell(spellID)
    	lib.ACTION_HIGHLIGHT_MARKS[spellID] = true
    	
    	local SpellName = GetSpellInfo(spellID)
    	local ButtonSpellName, ButtonSpellID
    	for button in next, ButtonRegistry do
    		ButtonSpellID = button:GetSpellId()
    		ButtonSpellName = GetSpellInfo(ButtonSpellID)
    		
    		if Spell and button._state_type == "action" then
    			if (spellID == tonumber(ButtonSpellID)) then
    				button.SpellID = ButtonSpellID
    			elseif SpellName == ButtonSpellName then
    				lib.ACTION_HIGHLIGHT_MARKS[spellID] = nil
    				lib.ACTION_HIGHLIGHT_MARKS[SpellName] = true
    				
    				button.SpellName = ButtonSpellName
    			end
    			
    			UpdateNewAction(button)
    		else
    			button.SpellID = nil
    			button.SpellName = nil
    		end
    	end
    end
    
    -- Clears all hovering highlights
    local function ClearMarkSpell()
    	-- Leave new action highlights alone
    	for k,v in pairs(lib.ACTION_HIGHLIGHT_MARKS) do
    		if not lib.NEW_ACTION_HIGHLIGHT_MARKS[k] then
    			lib.ACTION_HIGHLIGHT_MARKS[k] = nil
    		end
    	end
    	
    	for Button in next, ButtonRegistry do
    		if Button then
    			Button.SpellID = nil
    			UpdateNewAction(Button)
    		end
    	end
    end
    
    hooksecurefunc("UpdateOnBarHighlightMarksBySpell", MarkSpell)
    hooksecurefunc("ClearOnBarHighlightMarks", ClearMarkSpell)
    
    hooksecurefunc("MarkNewActionHighlight", MarkNewAction)
    hooksecurefunc("ClearNewActionHighlight", function(action, preventIdenticalActionsFromClearing)
    	ClearNewActionHighlight(action, preventIdenticalActionsFromClearing, nil)
    end)
    
    function UpdateNewAction(self)
    	-- special handling for "New Action" markers
    	if self.NewActionTexture then
    		if self._state_type == "action" and (lib.ACTION_HIGHLIGHT_MARKS[self._state_action] or lib.ACTION_HIGHLIGHT_MARKS[self.SpellID] or lib.ACTION_HIGHLIGHT_MARKS[self.SpellName]) then
    			self.NewActionTexture:Show()
    		else
    			self.NewActionTexture:Hide()
    		end
    	end
    end

     

  • Ferodra added a tag Enhancement May 6, 2020
  • Ferodra edited description May 6, 2020
  • Ferodra edited description May 6, 2020
  • Ferodra edited description May 6, 2020
  • nevcairiel closed issue Aug 28, 2020
  • nevcairiel posted a comment Aug 28, 2020

    Implemented independently and simplified for the next alpha version, since there can be only one spell currently being highlighted.


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