Author Topic: Image w/switch  (Read 8967 times)

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Image w/switch
« on: April 27, 2018, 07:26:53 AM »
OK... here is my goal:

Currently I have a vertical layout that includes two arrows (left/right).  They are,  of course,  static.   I would like to create a 2nd set of arrows that looks like the first set but "depressed"... and then when someone selects the direction of the arrow,  the "depressed" image pop up "over" the standard one giving the impression the arrow is being pushed when the direction is being selected.  Also,  the image has to remain on screen the entire time the "switch" is activated... so if they hold the stick to the left to scroll through the games,  the button remains "activated" the entire time.

SO... I'm trying to come up with code that will make an image appear on screen in a specific location but ONLY while the switch is activated... when deactivated the image is to disappear.

Any suggestions?   

Thanks!

I've uploaded an image of the current layout so you can get an idea for the arrows...


« Last Edit: April 27, 2018, 07:54:12 AM by FrizzleFried »
Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Image w/switch
« Reply #1 on: April 27, 2018, 01:34:49 PM »
Not perfect but...

Code: [Select]
class PopUpImage
{
        _my_imageleft=null;
        _my_imageright=null;

        constructor()
        {
                _my_imageleft = fe.add_image ("left.png",50,100,200, 200);
                _my_imageleft.visible=false;
                _my_imageright = fe.add_image ("right.png",450,100,200, 200);
                _my_imageright.visible=false;
                fe.add_signal_handler( this, "on_signal" )
        }

        function on_signal( signal )
        {
                if ( signal == "left" )
                {
                        _my_imageleft.visible=!_my_imageleft.visible;
                        _my_imageright.visible=false;
                        return true;
                }
                else if ( signal == "right" )
                {
                        _my_imageright.visible=!_my_imageright.visible;
                        _my_imageleft.visible=false;
                        return true;
                }
                return false;
        }
}

local blah = PopUpImage();

http://forum.attractmode.org/index.php?topic=456.0

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Image w/switch
« Reply #2 on: April 27, 2018, 02:12:40 PM »
Updated liquid8 plugin for "two pngs"

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified key is pressed." /> {
</ label="Key", help="The key that will display the image", is_input="yes", order=2 />
key="";
</ label="Key2", help="The key that will display the image", is_input="yes", order=3 />
key2="";
</ 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;

        constructor()
        {
local config = fe.get_config();
_image = fe.add_image("Arrow/left.png",50,100,200, 200);
_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();

class PopUpImage2
{
        _image2 = null;
_key2 = null;
_hold = false;
_showing = false;
_key2_delay = 250;
_last_check = 0;

        constructor()
        {
local config = fe.get_config();
_image2 = fe.add_image("Arrow/right.png",450,100,200, 200);
_image2.visible=false;
_image2.preserve_aspect_ratio = true;
_key2 = config["key2"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

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

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


Change this for what you need:

Code: [Select]
fe.add_image("Arrow/left.png",50,100,200, 200);
fe.add_image("Arrow/right.png",450,100,200, 200);

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #3 on: April 28, 2018, 12:02:12 AM »
Updated liquid8 plugin for "two pngs"

Code: [Select]
class UserConfig </ help="This plugin will show a popup image when the specified key is pressed." /> {
</ label="Key", help="The key that will display the image", is_input="yes", order=2 />
key="";
</ label="Key2", help="The key that will display the image", is_input="yes", order=3 />
key2="";
</ 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;

        constructor()
        {
local config = fe.get_config();
_image = fe.add_image("Arrow/left.png",50,100,200, 200);
_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();

class PopUpImage2
{
        _image2 = null;
_key2 = null;
_hold = false;
_showing = false;
_key2_delay = 250;
_last_check = 0;

        constructor()
        {
local config = fe.get_config();
_image2 = fe.add_image("Arrow/right.png",450,100,200, 200);
_image2.visible=false;
_image2.preserve_aspect_ratio = true;
_key2 = config["key2"];
_hold = config["hold"];
fe.add_ticks_callback( this, "on_tick" );
        }

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

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


Change this for what you need:

Code: [Select]
fe.add_image("Arrow/left.png",50,100,200, 200);
fe.add_image("Arrow/right.png",450,100,200, 200);

Got it working... thank you!
« Last Edit: April 28, 2018, 12:18:11 AM by FrizzleFried »
Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #4 on: April 28, 2018, 10:04:30 AM »
Welp, I do have a small issue.  I am using the conveyor_helper mod to scroll through marquees.... I have an option for "FASTEST, FAST, MEDIUM, SLOW, and SLOWEST" as far as the scroll speed.  Unfortunately,  that scroll speed also affects how long it takes for the image to pop up using this code.  It's fine for the FAST and FASTEST setting... the image almost immediately pops up because fastest is set for only 50 ms and FAST I believe is at 125... but when you get to MEDIUM there is a noticeable delay... by the time you get to SLOW or SLOWEST,  well,  the slowest setting is set for 450ms... so nearly a half second delay. 

It doesn't sound like much,  but when you are selecting a game,  it's only taking 100ms-200ms to select "one game at a time"...

Is there any way to make this code ignore the conveyor_helper's scroll speed settings?

EDIT: Also,  the code you posted prior works SOMEWHAT as well... it will turn on the image with left/right button presses,  but then it requires a 2nd button press to turn it off... it doesn't automatically turn off the button when the button press ends.
« Last Edit: April 28, 2018, 10:50:41 AM by FrizzleFried »
Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Image w/switch
« Reply #5 on: April 28, 2018, 03:22:58 PM »
Welp, I do have a small issue.  I am using the conveyor_helper mod to scroll through marquees.... I have an option for "FASTEST, FAST, MEDIUM, SLOW, and SLOWEST" as far as the scroll speed.  Unfortunately,  that scroll speed also affects how long it takes for the image to pop up using this code.  It's fine for the FAST and FASTEST setting... the image almost immediately pops up because fastest is set for only 50 ms and FAST I believe is at 125... but when you get to MEDIUM there is a noticeable delay... by the time you get to SLOW or SLOWEST,  well,  the slowest setting is set for 450ms... so nearly a half second delay. 

It doesn't sound like much,  but when you are selecting a game,  it's only taking 100ms-200ms to select "one game at a time"...

Is there any way to make this code ignore the conveyor_helper's scroll speed settings?

EDIT: Also,  the code you posted prior works SOMEWHAT as well... it will turn on the image with left/right button presses,  but then it requires a 2nd button press to turn it off... it doesn't automatically turn off the button when the button press ends.

Post the complete code and some pics , I´m lost :)

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #6 on: April 28, 2018, 03:34:49 PM »
Welp, I do have a small issue.  I am using the conveyor_helper mod to scroll through marquees.... I have an option for "FASTEST, FAST, MEDIUM, SLOW, and SLOWEST" as far as the scroll speed.  Unfortunately,  that scroll speed also affects how long it takes for the image to pop up using this code.  It's fine for the FAST and FASTEST setting... the image almost immediately pops up because fastest is set for only 50 ms and FAST I believe is at 125... but when you get to MEDIUM there is a noticeable delay... by the time you get to SLOW or SLOWEST,  well,  the slowest setting is set for 450ms... so nearly a half second delay. 

It doesn't sound like much,  but when you are selecting a game,  it's only taking 100ms-200ms to select "one game at a time"...

Is there any way to make this code ignore the conveyor_helper's scroll speed settings?

EDIT: Also,  the code you posted prior works SOMEWHAT as well... it will turn on the image with left/right button presses,  but then it requires a 2nd button press to turn it off... it doesn't automatically turn off the button when the button press ends.

Post the complete code and some pics , I´m lost :)

Here's the layout.nut.

Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Image w/switch
« Reply #7 on: April 29, 2018, 07:24:14 AM »
Welp, I do have a small issue.  I am using the conveyor_helper mod to scroll through marquees.... I have an option for "FASTEST, FAST, MEDIUM, SLOW, and SLOWEST" as far as the scroll speed.  Unfortunately,  that scroll speed also affects how long it takes for the image to pop up using this code.  It's fine for the FAST and FASTEST setting... the image almost immediately pops up because fastest is set for only 50 ms and FAST I believe is at 125... but when you get to MEDIUM there is a noticeable delay... by the time you get to SLOW or SLOWEST,  well,  the slowest setting is set for 450ms... so nearly a half second delay. 

It doesn't sound like much,  but when you are selecting a game,  it's only taking 100ms-200ms to select "one game at a time"...

Is there any way to make this code ignore the conveyor_helper's scroll speed settings?

EDIT: Also,  the code you posted prior works SOMEWHAT as well... it will turn on the image with left/right button presses,  but then it requires a 2nd button press to turn it off... it doesn't automatically turn off the button when the button press ends.

Post the complete code and some pics , I´m lost :)

Here's the layout.nut.

But you also mod the conveyour_helper so wil be esier if you upload a beta version of your theme and the module too.

Code: [Select]
local glist = MyGameList();
Maybe you need to synchronize fade_speed with ms_speed
« Last Edit: April 29, 2018, 07:32:14 AM by qqplayer »

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #8 on: April 29, 2018, 08:04:37 AM »
Welp, I do have a small issue.  I am using the conveyor_helper mod to scroll through marquees.... I have an option for "FASTEST, FAST, MEDIUM, SLOW, and SLOWEST" as far as the scroll speed.  Unfortunately,  that scroll speed also affects how long it takes for the image to pop up using this code.  It's fine for the FAST and FASTEST setting... the image almost immediately pops up because fastest is set for only 50 ms and FAST I believe is at 125... but when you get to MEDIUM there is a noticeable delay... by the time you get to SLOW or SLOWEST,  well,  the slowest setting is set for 450ms... so nearly a half second delay. 

It doesn't sound like much,  but when you are selecting a game,  it's only taking 100ms-200ms to select "one game at a time"...

Is there any way to make this code ignore the conveyor_helper's scroll speed settings?

EDIT: Also,  the code you posted prior works SOMEWHAT as well... it will turn on the image with left/right button presses,  but then it requires a 2nd button press to turn it off... it doesn't automatically turn off the button when the button press ends.

Post the complete code and some pics , I´m lost :)

Here's the layout.nut.

But you also mod the conveyour_helper so wil be esier if you upload a beta version of your theme and the module too.

Code: [Select]
local glist = MyGameList();
Maybe you need to synchronize fade_speed with ms_speed

I'll package it up and send you a link via PM.  Thanks

What APPEARS to already be affecting the delay for the image to appear is the delay associated with the "speed" setting of the conveyor_helper...  the slower you set the conveyor,  the long it takes for the image to appear on screen. 

Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #9 on: April 30, 2018, 11:50:37 AM »
I am not sure if anything can be done about this...

It appears that the CONVEYOR_HELPER module takes over and STOPS all other scripts from running until it's completed it's task.  So if you add a delay to it's task,  then that delay will be added to the beginning of anything waiting for the conveyor_helper module to complete.

In another mod I use a starfield... when I move from one game to the other it pauses even the star field.  I also have an animated marquee that doesn't even begin it's animation until after the conveyor_helper module completes it's task.
Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Image w/switch
« Reply #10 on: April 30, 2018, 12:15:19 PM »
I am not sure if anything can be done about this...

It appears that the CONVEYOR_HELPER module takes over and STOPS all other scripts from running until it's completed it's task.  So if you add a delay to it's task,  then that delay will be added to the beginning of anything waiting for the conveyor_helper module to complete.

In another mod I use a starfield... when I move from one game to the other it pauses even the star field.  I also have an animated marquee that doesn't even begin it's animation until after the conveyor_helper module completes it's task.

Testing the theme but still dont understand exactly whats the issue  ;D

Your are talking about the time to "fade in" the snap?

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #11 on: April 30, 2018, 01:42:12 PM »
when you press left and right,  the arrows change colors.  They are supposed to do so IMMEDIATELY.  If you adjust the scroll speed it affects when those arrows change color... basically adding a delay before they change colors ... so with slower scroll speeds the delay is such that they never change colors unless you HOLD DOWN the left/right button.

One thing I forgot to mention... you need to go in to the DISPLAY settings and configure LEFT/RIGHT for it to start functioning...

Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #12 on: April 30, 2018, 01:43:37 PM »
I guess I'm at the point where I can simply ask...

Is there a way to prevent the conveyor_helper module from FREEZING everything else while it does it's task?

If I can figure out how to do that,  I do believe it fixes more than one issue I am having.

:)
Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Image w/switch
« Reply #13 on: April 30, 2018, 02:55:53 PM »
when you press left and right,  the arrows change colors.  They are supposed to do so IMMEDIATELY.  If you adjust the scroll speed it affects when those arrows change color... basically adding a delay before they change colors ... so with slower scroll speeds the delay is such that they never change colors unless you HOLD DOWN the left/right button.

One thing I forgot to mention... you need to go in to the DISPLAY settings and configure LEFT/RIGHT for it to start functioning...

Are you testing this on a "powerfull" computer and with a keyboard?
I´ve set this:

Code: [Select]
layout_config Vertical Sphere_BETA
param                glsel Dark
param                glspeed Fastest
param                hold Yes
param                key left
param                key2 right

But seems to work perfectly.

FrizzleFried

  • Sr. Member
  • ****
  • Posts: 243
    • View Profile
    • Idaho Garagecade
Re: Image w/switch
« Reply #14 on: April 30, 2018, 05:05:01 PM »
when you press left and right,  the arrows change colors.  They are supposed to do so IMMEDIATELY.  If you adjust the scroll speed it affects when those arrows change color... basically adding a delay before they change colors ... so with slower scroll speeds the delay is such that they never change colors unless you HOLD DOWN the left/right button.

One thing I forgot to mention... you need to go in to the DISPLAY settings and configure LEFT/RIGHT for it to start functioning...

Are you testing this on a "powerfull" computer and with a keyboard?
I´ve set this:

Code: [Select]
layout_config Vertical Sphere_BETA
param                glsel Dark
param                glspeed Fastest
param                hold Yes
param                key left
param                key2 right

But seems to work perfectly.

OK...set glspeed to SLOWEST... now note how long it takes for the yellow arrows to turn red when you move left and right.

THAT's the delay I'm referring to.  No problem at FASTEST... the delay comes the SLOWER you set the scroll...
Visit my arcade blog ... www.idahogaragecade.com (updated 06-27-19)