mickelson / attract

A graphical front-end for command line emulators that hides the underlying operating system and is intended to be controlled with a joystick or gamepad.
http://attractmode.org
GNU General Public License v3.0
397 stars 115 forks source link

fe.filters.len and filters data not updated after display change #566

Closed zpaolo11x closed 4 years ago

zpaolo11x commented 5 years ago

I have a very basic layout like this:

fe.add_text("[Title]",0,0,1000,100)
print (fe.filters.len()+"\n")

I have a setup with three Displays, all using this layout, and the Displays Menu uses the same layout. Now when you launch AM you see in the console the number of filters, for example 8 in my "Mame" Display. If I then open the Displays Menu via hotkey on the console I get "0" filters, which is ok since Displays don't have filters.

Now if I select another Display from the menu, like "Capcom" which has 4 filters, the layout is loaded but, probably since it's the same as the Displays Menu layout, filter data is not correctly updated and I don't get any output on the console. If I have code in a layout that depends or checks the filters, this is not going to work if the same layout is used as Displays Menu layout.

zpaolo11x commented 5 years ago

Basically here the main issue is that when you select a display from a display menu, and the display menu is using the same layout as the display, the layout is not reloaded correctly, I'd expect it to reload from scratch

qqplayer commented 5 years ago

I made this for other thing, can you test?

function filters_transition( ttype, var, ttime ) {
 switch ( ttype ) {
  case Transition.StartLayout:
  case Transition.ToNewSelection:
  case Transition.ToNewList:
  case Transition.EndNavigation:
       fe.add_text("[Title]",0,0,1000,100);
       print (fe.filters.len()+"\n");
       break;
  }
 return false;
}

fe.add_transition_callback( "filters_transition" );
zpaolo11x commented 5 years ago

I made this for other thing, can you test?

I really wanted it to work, sadly it doesn't work: when I launch AM and use this as both Displays Menu layout and display layout, I get lists of 0s on the console. I only get "2" as output at the very beginning because AM first loads a display layout (with 2 filters) briefly (you can't even see it) before the displays menu layout is launched. Once the displays menu layout is engaged no matter if you change display it will still output "0" as filter length :(

zpaolo11x commented 5 years ago

Found a couple of workaraound for this. First you need to detect if your layout is being used as Displays Menu layout, this can be done setting a variable like this:

local DISPLAYMENUON = (fe.list.display_index == -1)

Once this variable is set, you can add a line like this in your signal_callback function:


if (sig == "select"){
         if (DISPLAYMENUON){
            fe.set_display(fe.list.index)
            return true
         }

   }

this will force a display load (and layout reload) when someone hits "select" and the layout is used as Displays Menu. Another option would be to set a variable in the signal_callback function when "select" is used and displays menu is on, and then add a fe.reload call in the ticks_callback function.

mickelson commented 5 years ago

Should be fixed now, thanks!

oomek commented 4 years ago

This commit https://github.com/mickelson/attract/commit/7dc5c88ca15d756f53ff28e427f8b6be019a1db7 has caused a regression resulting in inability to get the filters list before Transition.ToNewList occurs.

print(fe.filters.len()+"\n") returns 0 when called inside the main layout body

mickelson commented 4 years ago

Thanks for reporting the regression, it should be fixed now

oomek commented 4 years ago

Works fine now, thanks.