Page 1 of 2

Opening the menu on Android/Apple Devices Via Touch Input

Posted: Mon Jan 22, 2018 8:11 am
by crimsonnight
Hey guys, as you know, screen-space on mobile devices is precious, especially when trying to provide a cinematic experience. As such, instead of using the quick menu or an on-screen button, I'd like the menu to be shown (ie the default right-click function) if the player taps and holds anywhere on the screen for 2 seconds; is this possible?

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Mon Jan 22, 2018 8:37 am
by Remix
Long press (you can set duration and wobble amount (to separate from drag/swipe touches) in config) is governed by the "alternate" button action for Android, so pseudo-code example:

Code: Select all

screen android_overlay():
    # variant "android" # probably better to use renpy.variant test as below
    button:
        alternate ShowMenu( 'main' )

init python:
    if renpy.variant( [ "touch", "android" ] ): config.overlay_screens.append( "android_overlay" )
The configs...

define config.longpress_duration = 0.5
# The amount of time the player must press the screen for for a longpress to be recognized on a touch device.

define config.longpress_radius = 15
# The number of pixels the touch must remain within for a press to be recognized as a longpress.

define config.longpress_vibrate = .1
# The amount of time the device will vibrate for after a longpress.

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Mon Jan 22, 2018 1:39 pm
by crimsonnight
Thanks very much for this @Remix :)

I'd like to get it working before playing around with it but am having an issue doing so.

I guess I add this:

Code: Select all

screen android_overlay():
    # variant "android" # probably better to use renpy.variant test as below
    button:
        alternate ShowMenu( 'main' )
along with the configs to screens.rpy?

And this part:

Code: Select all

init python:
    if renpy.variant( [ "touch", "android" ] ): config.overlay_screens.append( "android_overlay" )
just under the 'start' label (in script.rpy)?

Also, I've tested the code on an actual device, but would it be sufficient just to test it on renpy's android emulator in the future?

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Mon Jan 22, 2018 4:13 pm
by Imperf3kt
The android emulator will not emulate alternate clicks if you use renpy.variant in that manner.
You'll have to continue testing on an actual android device or test without the variant check.
These are only set when running on the actual devices, not when running on in the emulators. These are more intended for use in platform-specific Python. For display layout, use screen variants.
https://www.renpy.org/doc/html/other.ht ... py-version

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Mon Jan 22, 2018 5:53 pm
by Remix
For the time being (while testing) just throw it all in script.rpy outside of any label block... Once you get it working as wanted, maybe separate the parts and put in other files (personally I'd put both the screen and python: config.overlay bits in screens and the config in options)

Note: You might need to change the ShowMenu call... cannot offhand remember the label name myself, it maybe "_game_menu" or somesuch

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Tue Jan 23, 2018 9:13 pm
by crimsonnight
Ah, that could be the issue! Well according to this page here: https://www.renpy.org/doc/html/keymap.html, the command should be 'game_menu', but when I change the code to:

Code: Select all

button:
        alternate game_menu( 'main' )
I'm getting the following crash when running it on my phone:
https://puu.sh/z8gPf/c3e85628e0.png
https://puu.sh/z8gOk/245016191c.png

Do you have any idea why? :?

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Tue Jan 23, 2018 9:42 pm
by DragoonHP
You want ShowMenu("save")[\b] instead of game_menu

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Wed Jan 24, 2018 7:09 am
by crimsonnight
Thanks - I'm no longer getting an error, but the code still doesn't seem to be working :?

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Wed Jan 24, 2018 11:09 am
by DragoonHP
What are you testing on? Emulator or an actual device?

If you are using the emulator, alternate is triggered by right click on the button

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Wed Jan 24, 2018 11:16 am
by crimsonnight
Actual device - although trying to trigger it by right-clicking in the emulator also isn't working :(

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Wed Jan 24, 2018 11:27 am
by DragoonHP
Can you give it a normal action too and see if that is triggering?

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Wed Jan 24, 2018 6:59 pm
by crimsonnight
Sorry, I'm a bit of a n00b with this stuff, by normal action, do you mean something like the 'show' command? If so should I remove the 'button:' line too?

Looking over the code again, where is the check for the 'longpress'? What's triggering the button's action at the moment? Do we not need some sort of conditional statement?

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Thu Jan 25, 2018 7:39 am
by DragoonHP
This:

Code: Select all

screen android_overlay():
    # variant "android" # probably better to use renpy.variant test as below
    button:
        alternate ShowMenu( 'main' )
        action ShowMenu("load")

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Thu Jan 25, 2018 9:45 am
by crimsonnight
Still no joy :(

Re: Opening the menu on Android/Apple Devices Via Touch Input

Posted: Thu Jan 25, 2018 11:31 am
by DragoonHP
No. Try with a simple left click/tap to see if anyything loads.

If nothing loads, that means the screen isn't showing up.