WoW - Adding event handler for modifier key - kgPanels - lua

I'm working with kgPanels to create a raid marker utility. I have two panels. One panel functions as a button - we'll call it rmButton. When rmButton is pressed it opens up the raid marker utility - rmUtility.
In kgPanels you create a panel on which you can add scripts that go in a number of different handlers. For rmUtility I am using OnLoad and OnEvent.
Right now everything is working as far as placing markers on targets. I would like to add further functionality that would allow placing world markers when either shift button is held. I'm having trouble getting that integrated.
In my OnLoad script:
local btnWidth = 30 -- the width of each button
local btnHeight = 30 -- the height of each button
local leftBorderOffset = 7 -- from the left border of the kgPanel to the first button
local btnOffset = 7 -- pixels between the buttons
local topBorderOffset = -7
self:RegisterEvent ("PLAYER_REGEN_DISABLED")
self:RegisterEvent ("PLAYER_REGEN_ENABLED")
self:Show()
self.buttons = {}
local hideFunc = function(s) s.parent:Hide() end
for n=1,6 do
local btn = CreateFrame("Button",nil,self,"SecureActionButtonTemplate")
btn:SetSize(btnWidth, btnHeight) -- replace this
btn:SetPoint("TOP",0,topBorderOffset - ((n-1) * (btnHeight + btnOffset)))
btn:SetAttribute("type","macro")
btn:RegisterForClicks("AnyUp")
btn.parent = self
btn:SetScript("PostClick",hideFunc)
btn:RegisterEvent ("MODIFIER_STATE_CHANGED")
if (event == "MODIFIER_STATE_CHANGED") then
if n == 6 then
btn:SetAttribute("macrotext","/cwm all")
else
btn:SetAttribute("macrotext",("/wm %d"):format(n))
end
else
if n == 6 then
btn:SetAttribute("macrotext","/tm 0")
else
btn:SetAttribute("macrotext",("/tm %d"):format(n))
end
end
self.buttons[n] = btn
end
self.buttons[1]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Square.tga")
self.buttons[2]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Triangle.tga")
self.buttons[3]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Diamond.tga")
self.buttons[4]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Cross.tga")
self.buttons[5]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Star.tga")
self.buttons[6]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Clear.tga")
In my OnEvent script:
if event == "PLAYER_REGEN_DISABLED" then
self:Hide()
elseif event == "PLAYER_REGEN_ENABLED" then
self:Hide()
end
When this panel loads it makes six buttons - five with raid markers, and one that clears the markers. When a button is pressed the panel will hide, and the panel will automatically hide when I enter combat.
As mentioned, I need the panel to accept a 'shift' modifier key to place the world marker.
Thanks.

Did you try something like
btn:SetAttribute("shift-macrotext1",("/wm %d"):format(n))
https://wow.gamepedia.com/SecureActionButtonTemplate#Modified_attributes
Unless you mean you want to use Shift to place a world marker? Instead of using it as a modifier for your secure action button? I'm not aware of any modifier keys like shift, ctrl, alt being able to activate an action button.

Related

Jetpack Compose: Firing onClick events using a remote control in Android TV

I'm building my Android TV app using Jetpack Compose, and I'm trying to fire some onClick events on some Text components.
I've implemented the Modifier.focusable, so it can be focused using the remote control, and I've implemented Modifier.clickable to be launched when, well, the component is clicked.
However, when I launch the app on an emulator, I can focus and select the component properly, as I can see the change on the background color, but I can't fire the event inside Modifier.clickable when pressing on the OK button on my remote control (in my case it's KEYCODE_DPAD_CENTER). The event is fired if I click with the mouse inside the emulator, however.
Here is my code
#Composable
fun FocusablePill(text: String, focusRequester: FocusRequester = FocusRequester()) {
val interactionSource = remember { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState()
val isPressed by interactionSource.collectIsPressedAsState()
val color = if (isFocused || isPressed) action else lightTranslucent_10
val shape = RoundedCornerShape(CornerSize(24.dp))
Text(
text = text,
color = MaterialTheme.colors.onPrimary,
style = MaterialTheme.typography.button,
modifier = Modifier
.focusRequester(focusRequester)
.focusable(
interactionSource = interactionSource
)
.clickable(
interactionSource = interactionSource,
indication = null //this is just cosmetic, setting LocalIndication.current still doesn't work
) {
onCommandEntered(text)
}
.background(color, shape)
.padding(16.dp, 8.dp)
)
}
I've also tried with Modifier.selectable, but the result is the same. Event is only fired on mouse click. Also, using Button components doesn't work either.
For future reference, this was fixed and should be working as of 1.1.0-beta01. Both the Dpad center and the enter key will trigger a click on the focused view now. If you want to handle other keys (e.g., a game controller), you can use Modifier.onKeyEvent.

Corona SDK - TextField Gets Left On Screen

I have a working textfield in corona...I instantiated it using:
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
nameTextField:addEventListener( "userInput", textListener )
I then made sure to add this to the scene's self.view in the create method:
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
The whole scene is shown using a showoverlay method.
composer.showOverlay( "renameoverlay", options )
When I hide the scene using hide overlay:
composer.hideOverlay( "fade", 400 )
Even after hiding the whole scene using the above code, the nameTextField still gets left on the screen.
This doesn't happen inside my other scenes.
What could be causing this????
How do I solve this???
First, native.newTextField()'s can be added to display.newGroup()'s. The will move with groups, but they still sit on top of the display hierarchy. Scene's that use fade or crossFade can't hide the text fields because they are not being moved.
Since it looks like your overlay is using "fade", you will need to hide the text fields when you call showOverlay and show them when you're done with the overlay.
Scope matters too. I can't tell what part of your code you're creating the new text field, but it has to be visible to any place you are referencing it.
It seems that native objects can't be added to dispaly groups , you need to remove the native object when you hide the scene, try this:
add scene:hide(event)
function scene:hide(event)
if nameTextField then
nameTextField :removeSelf()
nameTextField = nil
end
end
scene:addEventListener("hide", scene)
Hope this helps you!
I am fairly sure it is because of access issue for the local variable.
Change this
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
to this
nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
or this
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
to this
function scene:create( event )
sceneGroup = self.view
sceneGroup:insert(nameTextField)
end

addEventListener on youtube API with greasemonkey

I would like to use Greasemonkey to access some API objects of youtube videos while I'm in fullscreen mode.
It could be useful to have mouse clicks and position relative to screen.
This, to detect fullscreen mode, doesn't work:
window.fullScreen
I tried also to add mouse event detection to yt player, with this:
var player = document.getElementById('movie_player');
player.addEventListener("click", interceptClicks,true);
but it doesn't fire that func.
I tried also to inject some code like this:
function GM_main () {
var playerNode = document.getElementById ("movie_player");
playerNode.addEventListener ('click', interceptClicks ,false);
}
addJS_Node (null, null, GM_main);
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
var D = document;
var scriptNode = D.createElement ('script');
if (runOnLoad) {
scriptNode.addEventListener ("load", runOnLoad, false);
}
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}
I tried also to make a:
window.addEventListener('click', interceptClicks, false);
This works, BUT only in all areas different from the youtube flash player in non-fullscreen mode and in fullscreen mode, obviously none area, as there is only the player visible...
EDIT:
I made a partial progress indeed.
I created a button element with
btn.addEventListener("click", function () { player.mozRequestFullScreen();}, false)
This way flash video enters in Firefox fullscreen mode and so it receives the wheel events fired by the
window.addEventlistener('DOMMouseScroll', .....etc)
Besides, the fullscreen mode is detected by
window.fullScreen
Also, all keys (event) are detectable, but ESC; not again the mouse clicks..
There is a drawback:
Once in fullscreen, SOMETIMES if you click the left mouse button it suddenly exits fullscreen mode... SOMETIMES instead it stays normally full...
To exit it's not sufficient to press ESC, you need to press the normal flash fullscreen button on the lower right + ESC.
Some rare times it blocks itself in Fullscreen mode and you can't exit. You should press ctrl+alt+canc and then it appears firefox "block script" dialog box.
Why that odd behaviour and how to prevent it?
Ideally the best should be: intercept mouse click on the lower right flash fullscreen button, block it, redirect the call to mozFullscreen and block the fullscreen mode until you press ESC.
But I dont' think it's possible, is it?

how to go to back to a scene in corona sdk after moving to the next scene?

i need some help,
im making an app in corona sdk which contains 4 scenes, main, list, tab1, tab2, the main scene takes you to the list scene by a button and the List takes you to tab1 and tab1 takes you to tab2, what im trying to do is make tab2 go back to the scene List by pressing a button, and when i press on the button nothing happens!!
local button1 = widget.newButton
{
left= 250,
top= 650,
defaultFile = "red1.png",
label = "select chapter",
font = "Arial",
fontSize = 34,
onEvent = handleButtonEvent,
onPress = function() storyboard.gotoScene( "list" ); end,
selected = true
}
You appear to be using a function to handle the event of the botton with "onEvent = handleButtonEvent"
You should instead use that function to do the transition:
-- Function to handle the press of the button
local function handleButtonEvent(event)
if ( "ended" == event.phase) then
storyboard.gotoScene("list")
end
end
and
-- Creation of the button
local button1 = widget.newButton
{
-- All your variables here
onEvent = handleButtonEvent,
}
and you might even be looking for something like this; this function will instead take the user back to the previous scene.
-- Function to handle the press of the button
local function handleButtonEvent(event)
if ( "ended" == event.phase) then
storyboard.gotoScene(storyboard.getPrevious())
end
end

Dojo dialog, the iPad and the virtual keyboard issue

Recently, I have been working on a project where the interface should work for desktop and tablets (in particular the iPad).
One issue I am coming across is with a Dojo dialog on the iPad when text entry is taking place.
Basically here is what happens:
Load Dojo interface with buttons on iPad - OK
Press button (touch) to show dialog (90% height and width) - OK
Click on text box (touch) like DateTextBox or TimeTextBox - OK, the virtual keyboard is opened
Click the date or time I want in the UI (touch) - OK, but I can't see all of the options since it is longer than the screen size...
Try to scroll down (swipe up with two fingers or click 'next' in the keyboard) - not OK and the dialog repositions itself to have it's top at the top of the viewport area.
Basically, the issue is that the dialog keeps trying to reposition itself.
Am I able to stop dialog resizing and positioning if I catch the window onResize events?
Does anyone else have this issue with the iPad and Dojo dialogs?
Also, I found this StackOverflow topic on detecting the virtual keyboard, but it wasn't much help in this case...
iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari?
Thanks!
I just came across the same issue yesterday and found a hack,
which is not an elegant solution.
If you want to stop the dijit.Dialog from repositioning you can:
1) Set the property ._relativePosition of a dijit.Dialog object
(in this case it's "pop") after calling the method pop.show():
pop.show();
pop._relativePosition = new Object(); //create empty object
Next steps would probably be:
Check browser type&OS: dojo or even better BrowserDetect
Check when the virtual keyboard is activated and disable repositioning
Extend dijit.Dialog with custom class (handle all of the exceptions)
As suggested another way to do this is to override the _position function by extending the object (or maybe relative position, or other method). Here is my solution which only allows the dialog to be positioned in the middle of the screen once. There are probably better ways to change this by playing with the hide and show events but this suits my needs.
dojo.provide("inno.BigDialog");
dojo.require("dijit.Dialog");
dojo.declare("inno.BigDialog",dijit.Dialog,{
draggable:false,
firstPositioned : false,
_position : function() {
if (!dojo.hasClass(dojo.body(), "dojoMove") && !this.firstPositioned) {
this.firstPositioned = true;
var _8 = this.domNode, _9 = dijit.getViewport(), p = this._relativePosition, bb = p ? null
: dojo._getBorderBox(_8), l = Math
.floor(_9.l
+ (p ? p.x : (_9.w - bb.w) / 2)), t = Math
.floor(_9.t
+ (p ? p.y : (_9.h - bb.h) / 2));
if (t < 0) // Fix going off screen
t = 0;
dojo.style(_8, {
left : l + "px",
top : t + "px"
});
}
}
});
You can override the _position function and call the _position function of the superclass only once. (See http://dojotoolkit.org/reference-guide/dojo/declare.html#calling-superclass-methods)
if (!dojo._hasResource["scorll.asset.Dialog"]) {
dojo._hasResource["scorll.asset.Dialog"] = true;
dojo.provide("scorll.asset.Dialog");
dojo.require("dijit.Dialog");
dojo.declare("scorll.asset.Dialog", [dijit.Dialog], {
_isPositioned: false,
_position: function () {
if(this._isPositioned == false) {
// Calls the superclass method
this.inherited(arguments);
this._isPositioned = true;
}
}
})
}

Resources