User avatar
rmcq
Topic Author
Posts: 16
Joined: 18 Feb 2020, 23:31

Multiplayer Input - Selecting Items in a Listbox - Best Practices

21 Apr 2020, 06:29

Hi team,


Another best practice question. I need to extend a Listbox to handle multiplayer input. It's a character select screen. Each user can move through the list but they can't highlight/select the same item. If they try to move onto a selected item, it jumps to the next one. Is there an easy way to do this without having to add lots of custom code to the Listbox? What would be the best approach?


Right now my Listbox supports one player. It looks like:
<ListBox x:Name="theListBox" 
	ItemsSource="{Binding Players}" 
	SelectedItem="{Binding SelectedItem}"
	SelectedIndex="{Binding SelectedIndex}"
....other stuff....
>

I'm aware there's a SelectionMode="Multiple" property on Listbox. I figure I'll need to use that. I see there is a SelectedItemsCollection but I don't know how I'm supposed to bind to it so I can use it in my ViewModel. And there doesn't seem to be a SelectedIndexes/Indices either.

While testing I removed SelectedItem and SelectedIndex. Then I added SelectionMode. When I ran the game, I could no longer move through the Listbox with my gamepad. How do I get it to move through it again?


My next question is about multiplayer. It seems Noesis doesn't distinguish between which gamepad the input comes from. Is this correct? If so, we have some code in our engine that we can use to do that. But what's the best way to hook them up with the Listbox events and be MVVM friendly? Would it be a good approach for my ViewModel to know about the game engine inputs? Then on Listbox SelectionChanged, do a check to see which gamepad did the selection? We also thought about having individual Views for each gamepad. Would this be a good approach?


Thank you for your help,
R
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Multiplayer Input - Selecting Items in a Listbox - Best Practices

22 Apr 2020, 12:00

If I understood correctly you are talking about two players selecting different options for the same ListBox in the same screen (no split screen), right?

In Noesis only one control can have focus per View, so handling multiple selection in a ListBox with different gamepads will require directing input directly to the application viewmodel to move selection accordingly. In your scenario I don't think it would be possible to use 2 views to associate with each gamepad because you are sharing the same UI.

For managing multiple selection in MVVM you just need to bind the IsSelected property of the ListBoxItem via a stlye to a property of the items in your ItemsSource bound collection, look at this answer: https://stackoverflow.com/questions/346 ... vm-listbox#

Who is online

Users browsing this forum: No registered users and 16 guests