Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: malfacine on November 30, 2015, 04:11:22 PM

Title: Need Help...display an image when you press a button
Post by: malfacine on November 30, 2015, 04:11:22 PM
Make a show image press a key
example press "H" show a image with instructions

Somebody helppp....
Title: Re: Need Help...display an image when you press a button
Post by: raygun on December 03, 2015, 11:17:01 PM
Here you go:

- Save the code set out below as the file "PopUp.nut" in your attract mode /plugins directory.  Change "image.png" to whatever the filename of your image is.
- In Attract-Mode's plugin configuration enable the PopUp plugin.  In the controls configuration, map the "custom1" control to whatever you want to trigger the image.

Pushing the key should now flip the selected image on and off...

Code: [Select]
class PopUpImage
{
        _my_image=null;

        constructor()
        {
                _my_image = fe.add_image( "image.png", 0, 0 );
                _my_image.visible=false;
                fe.add_signal_handler( this, "on_signal" )
        }

        function on_signal( signal )
        {
                if ( signal == "custom1" )
                {
                        _my_image.visible=!_my_image.visible;
                        return true;
                }
                return false;
        }
}

local blah = PopUpImage();
Title: Re: Need Help...display an image when you press a button
Post by: malfacine on December 10, 2015, 07:48:35 PM
Oh man thanks....  ;D
Title: Re: Need Help...display an image when you press a button
Post by: xbs on December 15, 2015, 01:09:37 PM
Very useful, maybe someone could make a script with options for image path and button.
I tried but couldn't make it work.
Title: Re: Need Help...display an image when you press a button
Post by: liquid8d on December 15, 2015, 08:54:46 PM
Here's a plugin version with a few changes... copy the code into plugins/PopupImage.nut

* I changed it to use get_input_state so you can use more than just a specific signal
* Added option to Hold key (default is toggle)
* Make sure to specify the full path to the image, otherwise it will look in the plugins folder

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified key is pressed." /> {
</ label="Image", help="The full path to the image that will be displayed", order=1 />
image="";
</ label="Key", help="The key that will display the image", is_input="yes", order=2 />
key="";
</ label="Hold Key", help="If enabled, you must hold the key down", options="Yes,No", order=3 />
hold="No";
};

class PopUpImage
{
        _image = null;
_key = null;
_hold = false;
_showing = false;
_key_delay = 250;
_last_check = 0;

        constructor()
        {
local config = fe.get_config();
_image = fe.add_image( config["image"], 0, 0, fe.layout.width, fe.layout.height );
_image.visible=false;
_image.preserve_aspect_ratio = true;
_key = config["key"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

function on_tick( ttime )
{
local is_down = fe.get_input_state( _key );
if ( _hold == "Yes" )
{
_image.visible = is_down;
_showing = is_down;
} else
{
if ( is_down )
{
if ( ttime - _last_check > _key_delay )
{
_last_check = ttime;
_image.visible = !_showing;
_showing = !_showing;
}
}
}
}
}

fe.plugin[ "PopUpImage" ] <- PopUpImage();

Let me know if you find any issues, then I will add this to my github... :)
Title: Re: Need Help...display an image when you press a button
Post by: verion on December 16, 2015, 12:48:09 AM
This is great!

And that addition with "hold-key-to-display" is very user friendly, especially for real cabinet use - this way people not familiar with cabinet won't "lock" themselves in help screen.

Can I display another artwork or text - or it is limited to one image?

Title: Re: Need Help...display an image when you press a button
Post by: xbs on December 16, 2015, 01:20:47 AM
Here's a plugin version with a few changes... copy the code into plugins/PopupImage.nut

* I changed it to use get_input_state so you can use more than just a specific signal
* Added option to Hold key (default is toggle)
* Make sure to specify the full path to the image, otherwise it will look in the plugins folder

Let me know if you find any issues, then I will add this to my github... :)

Thank you so much!  :D
Title: Re: Need Help...display an image when you press a button
Post by: raygun on December 16, 2015, 11:14:00 PM
This is great!

And that addition with "hold-key-to-display" is very user friendly, especially for real cabinet use - this way people not familiar with cabinet won't "lock" themselves in help screen.

Can I display another artwork or text - or it is limited to one image?

if you hack the "fe.add_image()" to "fe.add_artwork()" in the constructor  then I would think this will work for artworks instead of images... you would just have to specify the artwork label you want ("snap", "cpanel"...) in the configuration instead of the "Image"...
Title: Re: Need Help...display an image when you press a button
Post by: liquid8d on December 18, 2015, 01:33:42 PM
Here's an updated version.. now just set Is Artwork to Yes and you can use snap, marquee, wheel, etc as the image:

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified button is pressed." /> {
</ label="Image", help="The full path to the image that will be displayed", order=1 />
image="";
</ label="Is Artwork" help="If enabled, the image is the selected artwork type", options="Yes,No" order=2 />
is_art=false;
</ label="Key", help="The key that will display the image", is_input="yes", order=3 />
key="";
</ label="Hold Key", help="If enabled, you must hold the key down", options="Yes,No", order=4 />
hold="No";
};

class PopUpImage
{
        _image = null;
_key = null;
_hold = false;
_showing = false;
_key_delay = 250;
_last_check = 0;
_is_art = false;

        constructor()
        {
local config = fe.get_config();
_is_art = config["is_art"];
_image = ( _is_art ) ? fe.add_artwork( config["image"], 0, 0, fe.layout.width, fe.layout.height ) : fe.add_image( config["image"], 0, 0, fe.layout.width, fe.layout.height );
_image.visible=false;
_image.preserve_aspect_ratio = true;
_key = config["key"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

function on_tick( ttime )
{
if ( !fe.overlay.is_up )
{
local is_down = fe.get_input_state( _key );
if ( _hold == "Yes" )
{
_image.visible = is_down;
_showing = is_down;
} else
{
if ( is_down )
{
if ( ttime - _last_check > _key_delay )
{
_last_check = ttime;
_image.visible = !_showing;
_showing = !_showing;
}
}
}
}
}
}

fe.plugin[ "PopUpImage" ] <- PopUpImage();

Also fixed so the key has no effect when the fe.overlay is up (i.e. in config)
Title: Re: Need Help...display an image when you press a button
Post by: bobby_magee on February 20, 2017, 11:53:22 AM
This is a great script, I was wondering if you could offer some help in getting user specific sizes for the image to be used.

If I add say:

   </ label="Image Height", help="Choose the image height", order=5 />
   hsize="";
   </ label="Image Width", help="Choose the image width", order=6 />
   wsize="";

I doesn't work if I try to then get the config information under the constructor using:

         _image = fe.add_image( config["image"], 0, 0, config["hsize], config["wsize"]);

   //      _image = fe.add_image( config["image"], 0, 0, 100, 100);  This does work of course!

I'm not great with programming so any help would be appreciated!

thanks
Title: Re: Need Help...display an image when you press a button
Post by: keilmillerjr on February 20, 2017, 01:19:47 PM
This is a great script, I was wondering if you could offer some help in getting user specific sizes for the image to be used.

If I add say:

   </ label="Image Height", help="Choose the image height", order=5 />
   hsize="";
   </ label="Image Width", help="Choose the image width", order=6 />
   wsize="";

I doesn't work if I try to then get the config information under the constructor using:

         _image = fe.add_image( config["image"], 0, 0, config["hsize], config["wsize"]);

   //      _image = fe.add_image( config["image"], 0, 0, 100, 100);  This does work of course!

I'm not great with programming so any help would be appreciated!

thanks

You need to convert the string to an integer using the built in function tointeger()
Title: Re: Need Help...display an image when you press a button
Post by: bobby_magee on February 20, 2017, 02:03:21 PM
That's great, thank you. All working :)
Title: Re: Need Help...display an image when you press a button
Post by: Bbuschke on March 01, 2017, 01:20:25 PM
instead of a stored image I have a url to my surveillance camera feed. Could that be used in place of an image somehow? the url is just my ip address and port
Title: Re: Need Help...display an image when you press a button
Post by: keilmillerjr on March 01, 2017, 02:26:51 PM
instead of a stored image I have a url to my surveillance camera feed. Could that be used in place of an image somehow? the url is just my ip address and port

No. If you have something as important as a surveillance, my suggestion for the time being is to buy a dedicated rpi and have it output to a dedicated monitor. Perhaps you could use a smart strip and have it turn on a monitor when it senses motion? If you find an 8 inch cut, the rip could probably fit inside and make a cool project. Unless your a pro at coding and want to add http functionality to attract mode, or create a borderless webkit app and pin it to the corner of the monitor when monition is detected.
Title: Re: Need Help...display an image when you press a button
Post by: Bbuschke on March 01, 2017, 04:47:53 PM
Here's a plugin version with a few changes... copy the code into plugins/PopupImage.nut

* I changed it to use get_input_state so you can use more than just a specific signal
* Added option to Hold key (default is toggle)
* Make sure to specify the full path to the image, otherwise it will look in the plugins folder

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified key is pressed." /> {
</ label="Image", help="The full path to the image that will be displayed", order=1 />
image="";
</ label="Key", help="The key that will display the image", is_input="yes", order=2 />
key="";
</ label="Hold Key", help="If enabled, you must hold the key down", options="Yes,No", order=3 />
hold="No";
};

class PopUpImage
{
        _image = null;
_key = null;
_hold = false;
_showing = false;
_key_delay = 250;
_last_check = 0;

        constructor()
        {
local config = fe.get_config();
_image = fe.add_image( config["image"], 0, 0, fe.layout.width, fe.layout.height );
_image.visible=false;
_image.preserve_aspect_ratio = true;
_key = config["key"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

function on_tick( ttime )
{
local is_down = fe.get_input_state( _key );
if ( _hold == "Yes" )
{
_image.visible = is_down;
_showing = is_down;
} else
{
if ( is_down )
{
if ( ttime - _last_check > _key_delay )
{
_last_check = ttime;
_image.visible = !_showing;
_showing = !_showing;
}
}
}
}
}

fe.plugin[ "PopUpImage" ] <- PopUpImage();

Let me know if you find any issues, then I will add this to my github... :)
right now its displaying snaps. how can i get it to display the boxart. im not seeing what i would change
Title: Re: Need Help...display an image when you press a button
Post by: Thorvald on March 04, 2017, 11:44:28 AM
Thanks for this guys!   

I used CPWizard to export all my control panel layouts (because loading CPWizard dynamically was WAAAYYY too slow and glitchy).

Then moved all those exported images to a cpanelwiz directory.

Added a new artwork for cpanel to link to that directory.

Configured your plugin to do artwork and cpanel and voila!   Hit a button with game select and get instant display of controls.

---

Now I just need to add a little more such as turning the pop-up off if the user changes game (moves up and down).

Cheers
   Tim

EDIT: And of course there is an issue with CPWizards export function... only a bunch of the batch exports worked, the rest are defaulted.  Back to trying to get showcp plugin to work.
Title: Re: Need Help...display an image when you press a button
Post by: MisterNewbie on May 01, 2017, 05:56:43 PM
This is a neat plugin.

Question / Idea:

Modify the plugin to load folder's worth of images (or, better yet, a zip/cbz of images) that are named/ordered numerically (01.jpg - 09.jpg for instance) into an array or whatever and then display them / navigate through them with left/right.

You'd essentially have a game instruction booklet popup plugin that way.

My idea of workflow:
-Set custom key for plugin to "M" (non-hold)
-Load contents of folder/zip into memory, path based on current rom name (much like snap/wheel artwork)
-Display image 1 (or a default 'no content' image if folder/zip empty/nonexistent)
-Left / Right scrolls through images sequentially
-"M" again closes.
Title: Re: Need Help...display an image when you press a button
Post by: kent79 on May 01, 2017, 07:30:57 PM
This is a neat plugin.

Question / Idea:

Modify the plugin to load folder's worth of images (or, better yet, a zip/cbz of images) that are named/ordered numerically (01.jpg - 09.jpg for instance) into an array or whatever and then display them / navigate through them with left/right.

You'd essentially have a game instruction booklet popup plugin that way.

My idea of workflow:
-Set custom key for plugin to "M" (non-hold)
-Load contents of folder/zip into memory, path based on current rom name (much like snap/wheel artwork)
-Display image 1 (or a default 'no content' image if folder/zip empty/nonexistent)
-Left / Right scrolls through images sequentially
-"M" again closes.

Check it.  :)
http://forum.attractmode.org/index.php?topic=939.msg7057#msg7057
Title: Re: Need Help...display an image when you press a button
Post by: damelioj on March 01, 2018, 09:42:26 AM
Is there a way to have the screen automatically display when a game is selected? Or have the popup button automatically “pressed” on game selection?

It would be great for the user to be able to see a “How to Play” screen upon selecting a game. That screen could have an instruction the user to press the button defined in the pop up plugin to switch to the game selected.
Title: Re: Need Help...display an image when you press a button
Post by: qqplayer on March 07, 2018, 12:07:15 PM
Is there a way to have the screen automatically display when a game is selected? Or have the popup button automatically “pressed” on game selection?

It would be great for the user to be able to see a “How to Play” screen upon selecting a game. That screen could have an instruction the user to press the button defined in the pop up plugin to switch to the game selected.

Yes sure , just need to create a new "artwork" on your layout , for example:

Code: [Select]
local controlpanel = fe.add_artwork("controlpanel", 0, 10 100, 100);

And then add the path into your emulator.cfg

Code: [Select]
artwork    controlpanel                 C:\media\cpanel