Author Topic: Customised Listbox  (Read 2712 times)

theamity9

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Customised Listbox
« on: May 06, 2018, 01:42:50 AM »
I tried implementing this:
https://github.com/mickelson/attract/wiki/Layouts---advanced-lists

Code: [Select]
function trimmed_name( index_offset ) {
    local s = split( fe.game_info( Info.Title, index_offset ), "(" );
    if ( s.len() > 0 )
        return s[0];

    return "";
}

local slot_a = fe.add_text( trimmed_name( -2 ), 100, 100, 900, 50 );
local slot_b = fe.add_text( trimmed_name( -1 ), 100, 150, 900, 50 );
local slot_c = fe.add_text( trimmed_name( 0 ), 100, 200, 900, 50 );
local slot_d = fe.add_text( trimmed_name( 1 ), 100, 250, 900, 50 );
local slot_e = fe.add_text( trimmed_name( 2 ), 100, 300, 900, 50 );

fe.add_transition_callback( "update_my_list" )
function update_my_list( ttype, var, ttime )
{
    if ( ttype == Transition.ToNewSelection )
    {
        slot_a.msg = trimmed_name( var - 2 );
        slot_b.msg = trimmed_name( var - 1 );
        slot_c.msg = trimmed_name( var );
        slot_d.msg = trimmed_name( var + 1 );
        slot_e.msg = trimmed_name( var + 2 );
    }
    return false;
}

However as much as I try I can't get it to respond correctly when transitioning to a new list.

Does anybody have a fully functioning one of this script with changing filters working correctly?

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: Customised Listbox
« Reply #1 on: May 06, 2018, 04:31:34 AM »
I tried implementing this:
https://github.com/mickelson/attract/wiki/Layouts---advanced-lists

Code: [Select]
function trimmed_name( index_offset ) {
    local s = split( fe.game_info( Info.Title, index_offset ), "(" );
    if ( s.len() > 0 )
        return s[0];

    return "";
}

local slot_a = fe.add_text( trimmed_name( -2 ), 100, 100, 900, 50 );
local slot_b = fe.add_text( trimmed_name( -1 ), 100, 150, 900, 50 );
local slot_c = fe.add_text( trimmed_name( 0 ), 100, 200, 900, 50 );
local slot_d = fe.add_text( trimmed_name( 1 ), 100, 250, 900, 50 );
local slot_e = fe.add_text( trimmed_name( 2 ), 100, 300, 900, 50 );

fe.add_transition_callback( "update_my_list" )
function update_my_list( ttype, var, ttime )
{
    if ( ttype == Transition.ToNewSelection )
    {
        slot_a.msg = trimmed_name( var - 2 );
        slot_b.msg = trimmed_name( var - 1 );
        slot_c.msg = trimmed_name( var );
        slot_d.msg = trimmed_name( var + 1 );
        slot_e.msg = trimmed_name( var + 2 );
    }
    return false;
}

However as much as I try I can't get it to respond correctly when transitioning to a new list.

Does anybody have a fully functioning one of this script with changing filters working correctly?

Code: [Select]
if ( ttype == Transition.StartLayout || ttype == Transition.ToNewList || ttype == Transition.ToNewSelection )
???

theamity9

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: Customised Listbox
« Reply #2 on: May 06, 2018, 05:04:43 PM »
If that's all it is I'm gonna be annoyed with myself. I'll give it a shot after work.

Thanks heaps mate. :)

theamity9

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: Customised Listbox
« Reply #3 on: May 07, 2018, 12:56:34 AM »
EDIT:
I fixed it. Your change made it so it loaded fine but when changing filter it was off. When going to a previous filter it showed slot_a as what would go before if there was a variable. slot_b showed slot_a, slot_c showed slot_b etc. When going forward a filter slot_a showed slot_b and so on.

The solution for anyone else looking at this. Change the update_my_list function to:
Code: [Select]
function update_my_list( ttype, var, ttime )
{
    if ( ttype == Transition.StartLayout || ttype == Transition.ToNewSelection )
    {
        slot_a.msg = trimmed_name( var - 2 );
        slot_b.msg = trimmed_name( var - 1 );
        slot_c.msg = trimmed_name( var );
        slot_d.msg = trimmed_name( var + 1 );
        slot_e.msg = trimmed_name( var + 2 );
    }

if ( ttype == Transition.ToNewList )
    {
        slot_a.msg = trimmed_name( -2 );
        slot_b.msg = trimmed_name( -1 );
        slot_c.msg = trimmed_name( 0 );
        slot_d.msg = trimmed_name( 1 );
        slot_e.msg = trimmed_name( 2 );
    }
    return false;
}
« Last Edit: May 07, 2018, 02:41:53 AM by theamity9 »