Author Topic: I'm doing something wrong - why doesn't my text change?  (Read 2896 times)

cools

  • Full Member
  • ***
  • Posts: 77
  • Arcade Otaku Sysadmin
    • View Profile
    • Arcade Otaku
I'm doing something wrong - why doesn't my text change?
« on: July 28, 2014, 12:54:07 PM »
Trying to build a simple list routine so I can alter the selected game height.

Only lists the first 9 games. Using up/down changes the preview image appropriately but the list doesn't change.

Code: [Select]
// Layout by cools / Arcade Otaku
// Layout User Options
class UserConfig {
 </ label="Preview Image", help="Choose snap/video snap, title, flyer or none.", options="snap,video,title,flyer,none" /> preview_image = "snap";
}
local my_config = fe.get_config();

// Layout Constants
// Font found on 9031.com
fe.layout.font="Arcade-Regular"
local rot=(fe.layout.base_rotation+fe.layout.toggle_rotation)%4;
local flw=fe.layout.width;
local flh=fe.layout.height;
switch (rot) {
 case RotateScreen.Right:
 case RotateScreen.Left:
  fe.layout.width=flh;
  fe.layout.height=flw;
  flw=fe.layout.width;
  flh=fe.layout.height;
  break;
}

// Preview image
local preview=fe.add_artwork (my_config["preview_image"],0,0,flw,flh/3);

// List
local lbx=0;
local lby=flh/3;
local lbw=flw;
local lbh=flh-lby;
local itn=9;
local ith=lbh/itn;
lby+=(ith*(itn/2));

for (local i=(itn/2)*-1;i<(itn/2);i+=1){
 if (i==0) {
  fe.add_text(fe.game_info (Info.Title),lbx,lby+(ith*i)-5,lbw,ith+10);
 }
 else {
  fe.add_text(fe.game_info (Info.Title,i),lbx,lby+(ith*i),lbw,ith);
 }
}

Actually, just doing this doesn't work as I'd expect:
Code: [Select]
fe.add_text(fe.game_info (Info.Title),0,0,fe.layout.width,fe.layout.height/25);
Even throwing the latter part alone into a "local game=" statement fails for it to update.

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 391
    • View Profile
Re: I'm doing something wrong - why doesn't my text change?
« Reply #1 on: July 29, 2014, 08:22:00 PM »
Trying to build a simple list routine so I can alter the selected game height.

Only lists the first 9 games. Using up/down changes the preview image appropriately but the list doesn't change.

Code: [Select]
// Layout by cools / Arcade Otaku
// Layout User Options
class UserConfig {
 </ label="Preview Image", help="Choose snap/video snap, title, flyer or none.", options="snap,video,title,flyer,none" /> preview_image = "snap";
}
local my_config = fe.get_config();

// Layout Constants
// Font found on 9031.com
fe.layout.font="Arcade-Regular"
local rot=(fe.layout.base_rotation+fe.layout.toggle_rotation)%4;
local flw=fe.layout.width;
local flh=fe.layout.height;
switch (rot) {
 case RotateScreen.Right:
 case RotateScreen.Left:
  fe.layout.width=flh;
  fe.layout.height=flw;
  flw=fe.layout.width;
  flh=fe.layout.height;
  break;
}

// Preview image
local preview=fe.add_artwork (my_config["preview_image"],0,0,flw,flh/3);

// List
local lbx=0;
local lby=flh/3;
local lbw=flw;
local lbh=flh-lby;
local itn=9;
local ith=lbh/itn;
lby+=(ith*(itn/2));

for (local i=(itn/2)*-1;i<(itn/2);i+=1){
 if (i==0) {
  fe.add_text(fe.game_info (Info.Title),lbx,lby+(ith*i)-5,lbw,ith+10);
 }
 else {
  fe.add_text(fe.game_info (Info.Title,i),lbx,lby+(ith*i),lbw,ith);
 }
}

Actually, just doing this doesn't work as I'd expect:
Code: [Select]
fe.add_text(fe.game_info (Info.Title),0,0,fe.layout.width,fe.layout.height/25);
Even throwing the latter part alone into a "local game=" statement fails for it to update.

Try replacing:

Code: [Select]
fe.add_text(fe.game_info (Info.Title),0,0,fe.layout.width,fe.layout.height/25);
with:

Code: [Select]
local temp = fe.add_text("[Title]",0,0,fe.layout.width,fe.layout.height/25);
temp.index_offset = i;

in both the places where you have it.  I think that should work.

The fe.game_info() command is only really useful when it is called from a tick or a transition function.  The frontend doesn't actually know what the current game is when the layout script itself is run (it only knows that later on when transitions and ticks occur)....


cools

  • Full Member
  • ***
  • Posts: 77
  • Arcade Otaku Sysadmin
    • View Profile
    • Arcade Otaku
Re: I'm doing something wrong - why doesn't my text change?
« Reply #2 on: July 30, 2014, 10:08:54 AM »
That works perfectly, thanks!

cools

  • Full Member
  • ***
  • Posts: 77
  • Arcade Otaku Sysadmin
    • View Profile
    • Arcade Otaku
Re: I'm doing something wrong - why doesn't my text change?
« Reply #3 on: July 30, 2014, 12:04:55 PM »
Result below. The list should be transplantable into any other layout ;)
Code: [Select]
// Layout by cools / Arcade Otaku
// Layout User Options
class UserConfig {
 </ label="Preview Image", help="Choose snap/video snap, title, flyer or none.", options="snap,video,title,flyer,none" /> preview_image = "snap";
}
local my_config = fe.get_config();

// Layout Constants
// Font found on 9031.com
fe.layout.font="Arcade-Regular"
local rot=(fe.layout.base_rotation+fe.layout.toggle_rotation)%4;
local flw=fe.layout.width;
local flh=fe.layout.height;
switch (rot) {
 case RotateScreen.Right:
 case RotateScreen.Left:
  fe.layout.width=flh;
  fe.layout.height=flw;
  flw=fe.layout.width;
  flh=fe.layout.height;
  break;
}

// Preview image
local preview=fe.add_artwork(my_config["preview_image"],(flw/2)-((flw/4)/2),flh*0.05,flw/4,flh/3);

// List
local lbx=flw*0.125;     // Listbox X position
local lby=(flh/3)*1.2;   // Listbox Y position
local lbw=flw*0.75;      // Listbox width
local lbh=(flh-lby)*0.9; // Listbox height
local itn=15;            // Listbox entries
local ith=lbh/itn;       // Listbox entry height
lby+=(ith*(itn/2));      // Listbox draw point - do not change
local lbr=255;           // Listbox red
local lbg=255;           // Listbox green
local lbb=128;           // Listbox blue
local lbf=0.8;           // Listbox colour fade. Lower values = less fade.

for (local i=(itn/2)*-1;i<=(itn/2);i+=1){
 if (i==0) {
     local selgame=fe.add_text("[Title]",lbx,lby-((ith*1.3)/4),lbw,ith*1.3);
     selgame.set_rgb(lbr,lbg,lbb);
     }
    else {
     local unselgame=fe.add_text("[Title]",lbx,lby+(ith*i),lbw,ith*0.7);
     unselgame.index_offset=i;
     unselgame.set_rgb(lbr,lbg,lbb);
     if (i<0) {unselgame.alpha=255-((i*(255/(itn/2))*-1)*lbf);}
     else {unselgame.alpha=255-(i*(255/(itn/2))*lbf);}
     // Fades colour rather than alpha     
     //if (i<0) {unselgame.set_rgb( lbr-((i*(lbr/(itn/2))*-1)*lbf) , lbg-((i*(lbg/(itn/2))*-1)*lbf) , lbb-((i*(lbb/(itn/2))*-1)*lbf) );}
     //else {unselgame.set_rgb( lbr-(i*(lbr/(itn/2))*lbf) , lbg-(i*(lbg/(itn/2))*lbf) , lbb-(i*(lbb/(itn/2))*lbf) );}
    }
}