Author Topic: What's the right way to access the entries in a list?  (Read 5878 times)

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
What's the right way to access the entries in a list?
« on: August 20, 2015, 02:28:07 PM »
Hi all,

I'm trying to create a kind of "flip card" layout, but in order to do it, I need to know the right way to access all (or at least a specified subset) of the entries in the current filter, and I'm not sure how to go about determining that. Specifically, when I'm creating an array of "cards," each card has that game's snap on it, etc. I guess what I'm really asking is how do I get the next/previous, etc. snaps of the currently selected game? I've tried studying the SimpleArtStrip example, but I'm obviously missing something. I'll keep at it, but in case anyone had any other ideas... Thanks!

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: What's the right way to access the entries in a list?
« Reply #1 on: August 21, 2015, 09:18:56 AM »
If you added 3 art objects, and set the index_offsets manually:
Code: [Select]
local slot1 = fe.add_artwork("snap", 0, 0, 100, 100);
local slot2 = fe.add_artwork("snap", 0, 100, 100, 100);
local slot3 = fe.add_artwork("snap", 0, 200, 100, 100);
slot1.index_offset = -1;
slot2.index_offset = 0;
slot3.index_offset = 1;
You'll notice that the fe automatically updates the artwork based on the offset when you move "up/down" the list. 0 - the middle artwork will always be the selected one.

However, if you are moving objects ( animating ) - something like slot2 going to slot1, you'll need to be a little more tricky and use a transition callback. When Transition.ToNewSelection occurs you are provided with var which is the index_offset you are moving to. Based on that, you'd need to update each objects x/y/w/h to move to the new location, update the .index_offset accordingly and/or use .swap() since your slots "moved".

That can get a little complicated which is why conveyor is there to help out. SimpleArtStrip extends conveyor. Rather than "flip cards" though - it just animates movement of the artwork objects, swaps textures and updates index_offsets where appropriate.

Depending on how complicated your flip cards might be, I'd play around with Conveyor/SimpleArtStrip and take a good look at what it's doing behind the scenes. If you are just using single artwork objects for your cards, you might be able to use those directly but ideally you can extend Conveyor/ConveyorSlot as a custom FlipCard/FlipCardSlot classes that would handle updating positions, sizes, textures and index offsets of each of your objects when appropriate when ToNewSelection occurs.

Hope that helps.

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: What's the right way to access the entries in a list?
« Reply #2 on: August 21, 2015, 05:52:56 PM »
Ah! That does help a lot! I wasn't getting it into my head that snaps added via add_artwork weren't "static," per se, but rather could be adjusted by tweaking index_offset. That was a lightbulb for me, so thanks very much!

I think I'll start by just getting the "cards" to display the way I want and worry about animation later (if ever), but this definitely gets me one (or more!) steps closer, so again, thanks!