[FIX] made mainwindow MVVM
This commit is contained in:
@@ -7,6 +7,8 @@ using System.Windows.Input;
|
|||||||
using SharedClientServer;
|
using SharedClientServer;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using Client.Views;
|
||||||
|
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
@@ -17,16 +19,12 @@ namespace Client
|
|||||||
public ICommand OnHostButtonClick { get; set; }
|
public ICommand OnHostButtonClick { get; set; }
|
||||||
public ICommand JoinSelectedLobby { get; set; }
|
public ICommand JoinSelectedLobby { get; set; }
|
||||||
|
|
||||||
|
public Lobby SelectedLobby { get; set; }
|
||||||
|
|
||||||
public ViewModel()
|
public ViewModel()
|
||||||
{
|
{
|
||||||
_model = new Model();
|
_model = new Model();
|
||||||
|
_lobbies = new ObservableCollection<Lobby>();
|
||||||
ButtonCommand = new RelayCommand(() =>
|
|
||||||
{
|
|
||||||
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
_lobbies = new List<Lobby>();
|
|
||||||
|
|
||||||
_lobbies.Add(new Lobby(50, 3, 8));
|
_lobbies.Add(new Lobby(50, 3, 8));
|
||||||
_lobbies.Add(new Lobby(69, 1, 9));
|
_lobbies.Add(new Lobby(69, 1, 9));
|
||||||
@@ -39,9 +37,13 @@ namespace Client
|
|||||||
|
|
||||||
JoinSelectedLobby = new RelayCommand(() =>
|
JoinSelectedLobby = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
|
if (SelectedLobby != null)
|
||||||
|
{
|
||||||
|
GameWindow window = new GameWindow();
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
|
||||||
Debug.WriteLine("Joining selected lobby");
|
}, true);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClickCheck()
|
private void ClickCheck()
|
||||||
@@ -52,7 +54,6 @@ namespace Client
|
|||||||
_model.Numbers = _model.Numbers + 5;
|
_model.Numbers = _model.Numbers + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommand ButtonCommand { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
private Model _model;
|
private Model _model;
|
||||||
@@ -69,8 +70,8 @@ namespace Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Lobby> _lobbies;
|
private ObservableCollection<Lobby> _lobbies;
|
||||||
public List<Lobby> Lobbies
|
public ObservableCollection<Lobby> Lobbies
|
||||||
{
|
{
|
||||||
get { return _lobbies; }
|
get { return _lobbies; }
|
||||||
set { _lobbies = value; }
|
set { _lobbies = value; }
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
<Label Grid.Row="1" Grid.Column="0" Content="Your username:" FontSize="15" VerticalAlignment="Center"/>
|
<Label Grid.Row="1" Grid.Column="0" Content="Your username:" FontSize="15" VerticalAlignment="Center"/>
|
||||||
|
|
||||||
<Label Grid.Row="2" Grid.Column="0" Content="Which color you want to be:" FontSize="15" VerticalAlignment="Center"/>
|
<Label Grid.Row="2" Grid.Column="0" Content="Select your color:" FontSize="15" VerticalAlignment="Center"/>
|
||||||
<ComboBox Name="colorSelection" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" FontSize="15">
|
<ComboBox Name="colorSelection" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" FontSize="15">
|
||||||
<ComboBoxItem Content="BLUE"/>
|
<ComboBoxItem Content="BLUE"/>
|
||||||
<ComboBoxItem Content="RED"/>
|
<ComboBoxItem Content="RED"/>
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
<ListView Name="LobbyList" Grid.Row="1" Grid.Column="0" Margin="10, 10, 10, 10" ItemsSource="{Binding Path=Lobbies}">
|
<ListView Name="LobbyList" Grid.Row="1" Grid.Column="0" SelectedItem="{Binding SelectedLobby}" Margin="10, 10, 10, 10" ItemsSource="{Binding Path=Lobbies}">
|
||||||
<ListView.View>
|
<ListView.View>
|
||||||
<GridView x:Name="grdList">
|
<GridView x:Name="grdList">
|
||||||
<GridViewColumn Header="Lobby ID" DisplayMemberBinding="{Binding ID}" Width="70"/>
|
<GridViewColumn Header="Lobby ID" DisplayMemberBinding="{Binding ID}" Width="70"/>
|
||||||
@@ -67,8 +67,8 @@
|
|||||||
<RowDefinition Height="50"/>
|
<RowDefinition Height="50"/>
|
||||||
<RowDefinition Height="50"/>
|
<RowDefinition Height="50"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Button Name="joinButton" Grid.Row="0" Content="join a selected lobby" Command="{Binding JoinSelectedLobby}" Width="200" Height="40" HorizontalAlignment="Left" Margin="10, 0, 0, 0"/>
|
<Button Name="joinButton" Grid.Row="0" Content="join a selected lobby" Command="{Binding JoinSelectedLobby}" IsEnabled="{Binding Model.CanStartGame}" Width="200" Height="40" HorizontalAlignment="Left" Margin="10, 0, 0, 0"/>
|
||||||
<Button Name="hostButton" Grid.Row="1" Content="host a new lobby" Command="{Binding OnHostButtonClick}" Width="200" Height="40" HorizontalAlignment="left" Margin="10, 0, 0, 0"/>
|
<Button Name="hostButton" Grid.Row="1" Content="host a new lobby" Command="{Binding OnHostButtonClick}" IsEnabled="{Binding Model.CanStartGame}" Width="200" Height="40" HorizontalAlignment="left" Margin="10, 0, 0, 0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user