Thread Tools Display Modes
06-28-24, 06:22 PM   #1
indiaum
A Murloc Raider
Join Date: Nov 2023
Posts: 9
SetPropagateKeyboardInput and ACE3

Hi,

I'm still trying to learn how to build an addon and I chose a "Keybind Trainer" as subject.

Basically it reads the actions bars (actionbar1 and actionmultibar1 to 6, command and slots pre-defined on a auxiliary table ) and grab the textures and keybinds.

After that, it displays a big texture on the middle of the screen and check for the next keypress or two, showing the score "correct/total".

I used SetPropagateKeyboardInput(false) so the player doesn't move while the addon is on screen.

Since my focus was to grasp the basics (far from it yet) I've gave the complete *poop* about style. So now I was trying to use ACE3 since, I believe, it gives a much cleaner visual to the code, but I can't figure out how to use SetPropagateKeyboardInput(false) with it.

I'm going to try to create a "normal" frame inside the NewAddon created from ACE3. Am I too far from the correct path?

Any advice will be appreciated. Thanks again for the attention!
  Reply With Quote
06-28-24, 09:58 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,972
If you create a frame using the "Button" widget then user won't be able to click on the screen as that will intercept the clicks.
Lua Code:
  1. local f = CreateFrame("Button", "indiaumAddonFrame", UIParent, "BasicFrameTemplateWithInset")
  2. f:SetSize(200, 200)
  3. f:SetPoint("CENTER")

The BasicFrameTemplateWithInset is a predefined frame layout.

You could then size that however and use that as the base for any other widgets. It's not the only template and you could of course create your own frame layout.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-28-24 at 10:01 PM.
  Reply With Quote
06-28-24, 10:22 PM   #3
indiaum
A Murloc Raider
Join Date: Nov 2023
Posts: 9
Originally Posted by Fizzlemizz View Post
If you create a frame using the "Button" widget then user won't be able to click on the screen as that will intercept the clicks.
Lua Code:
  1. local f = CreateFrame("Button", "indiaumAddonFrame", UIParent, "BasicFrameTemplateWithInset")
  2. f:SetSize(200, 200)
  3. f:SetPoint("CENTER")

The BasicFrameTemplateWithInset is a predefined frame layout.

You could then size that however and use that as the base for any other widgets. It's not the only template and you could of course create your own frame layout.
Thank you for the help! I really appreciate it.

I tried your suggestion, but simply creating the button didn't stop the propagation of clicks and mouse actions. The character still used the skills as I pressed them. If I do this:

Code:
----------------------------------------------------------------------------------
---- Namespaces
local addonName, addonTable = ...
local addon = {}
addonTable.addon = addon


----------------------------------------------------------------------------------
---- Frames
-- Main Frame
addon.f = CreateFrame("Frame", "MainFrame", UIParent, "UIPanelDialogTemplate")
addon.f:SetSize(800, 600);
addon.f:SetPoint("CENTER");
addon.f:SetScript("OnKeyDown", function(self, button) print(button) end)
addon.f:SetScript("OnMouseDown", function(self, button) print(button) end)
addon.f:SetScript("OnMouseWheel", function(self, button) print(button) end)
My character stood still and I could see the keypresses on message chat. I thought that the "SetPropagateKeyboardInput(false)" was reponsible, but it's this what I was looking for:

Code:
addon.f:SetScript("OnKeyDown", function(self, button) print(button) end)
addon.f:SetScript("OnMouseDown", function(self, button) print(button) end)
addon.f:SetScript("OnMouseWheel", function(self, button) print(button) end)
Now I need to understand what to do so my addon doesn't pops up automatically when I log or reload. I still don't grasp the whole picture about an addon structure and flow, most addons that I tried to take a look, was using ACE3 which abstract most things and makes it even harder for me to understand.
  Reply With Quote
06-29-24, 10:28 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,972
Completely mis-read what you were wanting to do .

How your addons works mostly depends on what it's intended to do.

If it's just an interface for the user to change some things then you could use a slash command (/xxx) or minimap button to open it or, add it to the games interface menu.

Some addons just move some of the game frames (not so much these days with Edit Mode) and some just hook one or more game functions to change standard behaviour (like adding to a text display etc.)

Other addons work by "reacting" to game events. They have a frame or frames that register to listen for specific events that happen in-game and then do what's required when notified one of the events has occured.

Most larger addons will include more than one of these.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-29-24, 12:51 PM   #5
indiaum
A Murloc Raider
Join Date: Nov 2023
Posts: 9
Originally Posted by Fizzlemizz View Post
Completely mis-read what you were wanting to do .

How your addons works mostly depends on what it's intended to do.

If it's just an interface for the user to change some things then you could use a slash command (/xxx) or minimap button to open it or, add it to the games interface menu.

Some addons just move some of the game frames (not so much these days with Edit Mode) and some just hook one or more game functions to change standard behaviour (like adding to a text display etc.)

Other addons work by "reacting" to game events. They have a frame or frames that register to listen for specific events that happen in-game and then do what's required when notified one of the events has occured.

Most larger addons will include more than one of these.
Thanks for the info!

You probably misread because of my english, sorry!

I did it this way, is it ok or am i doing some sort of bad practice?

Core.lua
Code:
----------------------------------------------------------------------------------
---- Namespaces
local addonName, addonTable = ...
local addon = {}

addonTable.addon = addon

----------------------------------------------------------------------------------
---- Addon initialization
local events = CreateFrame("Frame")
events:RegisterEvent("ADDON_LOADED")
events:SetScript("OnEvent", function(self, event, name, ...) 
    if name == addonName then
        SLASH_KeybindTrainer1 = "/kt"
        SlashCmdList.KeybindTrainer = addon.Run
    end
end)
events:Hide()
Engine.lua
Code:
----------------------------------------------------------------------------------
---- Namespaces
local addonName, addonTable = ...
addon = addonTable.addon

----------------------------------------------------------------------------------
---- Functions that compose the addon
function addon:Run()
    ----------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------------------
    -- Main Frame
    --------------------------------------------------------------------------------------------------------
    addon.f = CreateFrame("Frame", "MainWindow", UIParent, "UIPanelDialogTemplate")
    addon.f:SetSize(800, 600);
    addon.f:SetPoint("CENTER");
    addon.f:SetScript("OnKeyDown", function(self, button) print(button) end)
    addon.f:SetScript("OnMouseDown", function(self, button) print(button) end)
    addon.f:SetScript("OnMouseWheel", function(self, button) print(button) end)

end
  Reply With Quote
06-29-24, 01:49 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,972
Lua Code:
  1. SLASH_KeybindTrainer1 = "/kt"
  2. SlashCmdList.KeybindTrainer = addon.Run
The slash command doesn't need to be in an event handler as the default game UI is loaded before addons so everything is in place to create it when the file loads rather than this event which fires after the file has loaded (but the event is ok also if that's what you prefer).

Lua Code:
  1. local addonName, addonTable = ...
  2. local addon = {}
  3. addonTable.addon = addon

At this point, creating the addon table is possibly redunant as you could just add the created frame directly to addonTable and maybe just create sub-tables for distinct groups of information.

But once again, it's whatever you prefer.

and, just for less typing you could:
Lua Code:
  1. local f = CreateFrame("Frame", "MainWindow", UIParent, "UIPanelDialogTemplate")
  2. addonTable.f = f
  3. f:SetSize(800, 600);
  4. f:SetPoint("CENTER");
  5. f:SetScript("OnKeyDown", function(self, button) print(button) end)
  6. f:SetScript("OnMouseDown", function(self, button) print(button) end)
  7. f:SetScript("OnMouseWheel", function(self, button) print(button) end)

You would still be able to access the frame using something like
Code:
addonTable.f:Hide()
if you needed to.
And again, it's whatever you prefer.

As for events, the PLAYER_LOGIN event only fires once after all initial (non Load-On-Demand) addons have been loaded and before the first PLAYER_ENTERING_WORLD event so it's a handy event to do initialisation for anything that doesn't need to be returned by the server. You don't need to check for name == addonName and all the initial addons SavedVariables are loaded.

Have fun!
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-29-24 at 02:01 PM.
  Reply With Quote
06-29-24, 02:24 PM   #7
indiaum
A Murloc Raider
Join Date: Nov 2023
Posts: 9
Originally Posted by Fizzlemizz View Post
Lua Code:
  1. SLASH_KeybindTrainer1 = "/kt"
  2. SlashCmdList.KeybindTrainer = addon.Run
The slash command doesn't need to be in an event handler as the default game UI is loaded before addons so everything is in place to create it when the file loads rather than this event which fires after the file has loaded (but the event is ok also if that's what you prefer).

Lua Code:
  1. local addonName, addonTable = ...
  2. local addon = {}
  3. addonTable.addon = addon

At this point, creating the addon table is possibly redunant as you could just add the created frame directly to addonTable and maybe just create sub-tables for distinct groups of information.

But once again, it's whatever you prefer.

and, just for less typing you could:
Lua Code:
  1. local f = CreateFrame("Frame", "MainWindow", UIParent, "UIPanelDialogTemplate")
  2. addonTable.f = f
  3. f:SetSize(800, 600);
  4. f:SetPoint("CENTER");
  5. f:SetScript("OnKeyDown", function(self, button) print(button) end)
  6. f:SetScript("OnMouseDown", function(self, button) print(button) end)
  7. f:SetScript("OnMouseWheel", function(self, button) print(button) end)

You would still be able to access the frame using something like
Code:
addonTable.f:Hide()
if you needed to.
And again, it's whatever you prefer.

As for events, the PLAYER_LOGIN event only fires once after all initial (non Load-On-Demand) addons have been loaded and before the first PLAYER_ENTERING_WORLD event so it's a handy event to do initialisation for anything that doesn't need to be returned by the server. You don't need to check for name == addonName and all the initial addons SavedVariables are loaded.

Have fun!
Man! Thank you very much for all these advice, you don't believe how many questions i had that you answered whith them! I really appreciate it!

Have a nice day!
  Reply With Quote

WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » SetPropagateKeyboardInput and ACE3


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off