WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Record button presses. (https://www.wowinterface.com/forums/showthread.php?t=46939)

Yksrep 07-25-13 11:55 PM

Record button presses.
 
Is it possible to record button presses and then do something.
I mean something like

If
A button pressed and B button pressed
then
C button show.

#See Below for working Code. The easiest way to get it to work is
local button = CreateFrame("CheckButton", "ButtonName", FrameName, "UIPanelButtonTemplate")

Fizzlemizz 07-26-13 12:43 AM

It's certainly possible but a bit more context about what you want to achieve might help you get some more specific information.

Edit: The most basic (rough as guts) is you have a frame with 3 buttons. In the OnClick event for button A and B.

For A:
Code:

  self:GetParent().A_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
    --show button C
    self:GetParent().A_Clicked = nil
    self:GetParent().B_Clicked = nil
  end

For B:
Code:

  self:GetParent().B_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
    --show button C
    self:GetParent().A_Clicked = nil
    self:GetParent().B_Clicked = nil
  end

Very rudimentry and open to refinement depending on requirement.

Dridzt 07-26-13 12:49 AM

If by button presses you mean keyboard key presses, the answer is yes and no.

There is api to detect specific key presses (mainly the CTRL/ALT/SHIFT modifiers) as well you can detect keybound key combinations.

A generic key capturing solution is not trivial because making a frame that traps keyboard events generally means you lose control of the keyboard.

In any case this is a good starting point to explore possibilities: Frame:EnableKeyboard() Be sure to read the 'small print'

Yksrep 07-26-13 02:22 AM

Quote:

Originally Posted by Fizzlemizz (Post 281578)
It's certainly possible but a bit more context about what you want to achieve might help you get some more specific information.

Edit: The most basic (rough as guts) is you have a frame with 3 buttons. In the OnClick event for button A and B.

For A:
Code:

  self:GetParent().A_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
    --show button C
    self:GetParent().A_Clicked = nil
    self:GetParent().B_Clicked = nil
  end

For B:
Code:

  self:GetParent().B_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
    --show button C
    self:GetParent().A_Clicked = nil
    self:GetParent().B_Clicked = nil
  end

Very rudimentry and open to refinement depending on requirement.

Thanks,

A bit more for more context What I am trying to do is once someone selects the type of NPC they want to find (vendor trainer ect), and what City they are looking in (Stormwind, Thunder bluff ect) It will then either set a waypoint to that location Or if there are multiple allow the user to choose the NPC they want to visit.

Yksrep 07-26-13 10:59 PM

If anyone stumbles upon this Post there is the working code.

Code:

--parent frame
local frame = CreateFrame("Frame", "TestFrame", ParentUI)
frame:SetSize(400, 200)
frame:SetPoint("CENTER")
local texture = frame:CreateTexture()
texture:SetAllPoints()
texture:SetTexture(0,0,0,0)
frame.background = texture


local button = CreateFrame("CheckButton", "ButtonA", TestFrame, "UIPanelButtonTemplate")
button:SetText("ButtonA")
button:SetPoint("LEFT",0,0)
button:SetWidth(120)
button:SetHeight(50)
button:SetScript("OnClick",
  function()
    ButtonA:SetChecked()
  end);

local button = CreateFrame("CheckButton", "ButtonB", TestFrame, "UIPanelButtonTemplate")
button:SetText("ButtonB")
button:SetPoint("CENTER",0,0)
button:SetWidth(120)
button:SetHeight(50)
button:SetScript("OnClick",
  function()
    ButtonB:SetChecked()
        if ButtonA:GetChecked() and ButtonB:GetChecked() then
        ButtonC:Show()
        end
  end);

local button = CreateFrame("CheckButton", "ButtonC", TestFrame, "UIPanelButtonTemplate")
button:SetText("ButtonC")
button:SetPoint("RIGHT",0,0)
button:SetWidth(120)
button:SetHeight(50)
button:Hide()
button:SetScript("OnClick", function()
                                ButtonC:Hide()
                                ButtonA:SetChecked(false)
                                ButtonB:SetChecked(false)
                                end)



All times are GMT -6. The time now is 11:37 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI