Originally Posted by DashingSplash
Was really surprised to see that
Lua Code:
local prefix = SecureButton_GetModifierPrefix() local binding = GetBindingAction(prefix .. key)
was a thing. Although, I assume I'll get a better understanding of the API with some experience.
|
I didn't really know this either, but given a copy of the UI source code, there's a method to
finding what you're looking for by going to the source of something you want to modify and looking at how it works. If you haven't already, get a copy of the source code and use an editor that allows you to search in the code for the things you're interested in. In this case, it seems likely that Blizzard would at some point implement a utility function that returns the current modifier chain, because it's useful in a lot of cases.
Originally Posted by DashingSplash
The only thing that had to be included in your code was to allow companion, item, and macro functionality. See modified function below. Any input on that?
|
I would actually use a table for this, partly for code clarity, and also because it's easier to modify on a whim.
Lua Code:
local dismountTypes = {
spell = true,
item = true,
companion = true,
macro = false,
}
Lua Code:
if HasAction(action) then
local actionType, spellID = GetActionInfo(action)
if dismountTypes[actionType] and not protectedSkills[spellID] then
Dismount()
elseif actionType == "macro" then
spellID, _ = GetMacroSpell(spellID)
if spellID ~= nil and not protectedSkills[spellID] then
Dismount()
end
end
end
return
Originally Posted by DashingSplash
The only thing I am unsure about is how
Lua Code:
button = stanceButtons[binding] if button and not button:GetChecked() then Dismount() end
works. When and how is the button state set to checked?
|
I'll give you an example of how to track execution path in this case, which I don't think any tutorial brings up. If you look in Bindings.xml, you'll find that e.g. SHAPESHIFTBUTTON1 is calling StanceBar_Select(1). A quick search for this function gives you this result:
Lua Code:
-- Searching 1364 files for "function StanceBar_Select" (case sensitive)
-- UISourceCode\StanceBar.lua:
function StanceBar_Select (id)
StanceBarFrame.lastSelected = id;
CastShapeshiftForm(id);
end
Casting the shapeshift form generates an event that updates the stance bar, which results in the current stance active having its button set to checked.
Lua Code:
function StanceBar_OnEvent(self, event)
if(event == "UPDATE_SHAPESHIFT_COOLDOWN") then
StanceBar_UpdateState();
end
end
function StanceBar_UpdateState ()
...
if ( isActive ) then
StanceBarFrame.lastSelected = button:GetID();
button:SetChecked(true);
else
button:SetChecked(false);
end
...
end