Multiple Inputs (Splitscreen)
Posted: 10 Sep 2019, 16:23
Hi!
We are looking to allow multiple users to interact with a subsection of the screen in our Windows app. I.e. a splitscreen pause menu, where 2 or more players can interact with their own menu independently and simultaneously. We have one xaml and multiple viewmodels:
This produces a window with two stack panels. I want to forward inputs from one gamepad to one window, and the other to the other.
Here is how I am attempting to do this. I parse the xaml, create one view for the whole screen using Noesis::GUI::CreateView(), then create 2 more views, passing in StackPanelContainer1 and StackPanelContainer2 as root.
We can isolate inputs from the gamepads and push them to the appropriate IView. The Focus on the last line appears to succeed, but interaction doesn't work, and causes an assert during GetNextDirection, at element->TransformToAncestor(root). root is the Noesis::View::RootVisual, but doesn't appear to be the one in the main scene. Calling GetView() on the appropriate elements seems to return what I would expect (the set View appears to propagate properly), but I feel I must be missing something.
Any advice greatly appreciated!
Cheers,
Scott
Edit: Clarification
We are looking to allow multiple users to interact with a subsection of the screen in our Windows app. I.e. a splitscreen pause menu, where 2 or more players can interact with their own menu independently and simultaneously. We have one xaml and multiple viewmodels:
Code: Select all
<Window
x:Class="OurProject.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:OurProject"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:noesis="clr-namespace:NoesisGUIExtensions"
mc:Ignorable="d"
Title="TestWindow"
Background="{x:Null}">
<Viewbox
Margin="0">
<Grid x:Name="mainCanvas" Width="1920">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Viewbox Name="StackPanelContainer1" HorizontalAlignment="Left" Grid.Column="0">
<StackPanel Name="StackPanel1" Margin="10" Width="80">
<ToggleButton Name="Btn11" Content="Left 1"/>
<ToggleButton Name="Btn12" Content="Left 2"/>
<ToggleButton Name="Btn13" Content="Left 3"/>
<ToggleButton Name="Btn14" Content="Left 4"/>
<ToggleButton Name="Btn15" Content="Left 5"/>
</StackPanel>
</Viewbox>
<Viewbox Name="StackPanelContainer2" HorizontalAlignment="Right" Grid.Column="1">
<StackPanel Name="StackPanel2" Margin="10" Width="50">
<ToggleButton Name="Btn21" Content="Right 1"/>
<ToggleButton Name="Btn22" Content="Right 2"/>
<ToggleButton Name="Btn23" Content="Right 3"/>
</StackPanel>
</Viewbox>
</Grid>
</Viewbox>
</Window>
Here is how I am attempting to do this. I parse the xaml, create one view for the whole screen using Noesis::GUI::CreateView(), then create 2 more views, passing in StackPanelContainer1 and StackPanelContainer2 as root.
Code: Select all
OurProject* pTheMainWindow = [...]; // : public Noesis::ContentControl
Noesis::StackPanel* pPanel1 = pTheMainWindow->FindName<Noesis::StackPanel>("StackPanel1");
Noesis::StackPanel* pPanel2 = pTheMainWindow->FindName<Noesis::StackPanel>("StackPanel2");
Noesis::Ptr<Noesis::IView> pNewView1 = Noesis::GUI::CreateView(pPanel1);
Noesis::Ptr<Noesis::IView> pNewView2 = Noesis::GUI::CreateView(pPanel2);
// All Noesis::Ptrs stored off, etc
pPanel1->DisconnectFromView();
pPanel1->ConnectToView(pNewView1);
pPanel2->DisconnectFromView();
pPanel2->ConnectToView(pNewView2);
pPanel1->GetChildren()->Get(0)->Focus();
Any advice greatly appreciated!
Cheers,
Scott
Edit: Clarification