CANVAS WORKS

This commit is contained in:
lars
2020-10-13 14:49:43 +02:00
parent 245130a648
commit e792d28746
7 changed files with 171 additions and 6 deletions

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Client.ViewModels
{
class ViewModelGame : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -0,0 +1,51 @@
<Window x:Class="Client.Views.GameWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Client.Views"
mc:Ignorable="d"
Title="GameWindow" Height="600" Width="1200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Path=...}" FontSize="15"/>
<Label Grid.Row="1" Content="{Binding Path=...}" FontSize="15"/>
<Label Grid.Row="2" Content="{Binding Path=...}" FontSize="15"/>
<Label Grid.Row="3" Content="{Binding Path=...}" FontSize="15"/>
<Label Grid.Row="4" Content="{Binding Path=...}" FontSize="15"/>
<Label Grid.Row="5" Content="{Binding Path=...}" FontSize="15"/>
<Label Grid.Row="6" Content="{Binding Path=...}" FontSize="15"/>
<Label Grid.Row="7" Content="{Binding Path=...}" FontSize="15"/>
</Grid>
<Button Name="CanvasReset" Click="CanvasReset_Click" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Width="100" Margin="10, 10, 10, 10" Content="RESET" />
<Canvas Name="CanvasForPaint" Grid.Row="1" Grid.Column="1" MouseDown="CanvasForPaint_MouseDown" MouseMove="CanvasForPaint_MouseMove" Margin="10, 10, 10, 10">
<Canvas.Background>
<SolidColorBrush Color="White" Opacity="0"/>
</Canvas.Background>
</Canvas>
</Grid>
</Window>

View File

@@ -0,0 +1,73 @@
using Client.ViewModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Client.Views
{
/// <summary>
/// Interaction logic for GameWindow.xaml
/// </summary>
public partial class GameWindow : Window
{
public GameWindow()
{
DataContext = new ViewModelGame();
InitializeComponent();
}
Point currentPoint = new Point();
private void CanvasForPaint_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
currentPoint = e.GetPosition(CanvasForPaint);
}
}
private void CanvasForPaint_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Line line = new Line();
line.Stroke = SystemColors.WindowFrameBrush;
line.X1 = currentPoint.X;
line.Y1 = currentPoint.Y;
line.X2 = e.GetPosition(CanvasForPaint).X;
line.Y2 = e.GetPosition(CanvasForPaint).Y;
currentPoint = e.GetPosition(CanvasForPaint);
CanvasForPaint.Children.Add(line);
}
}
private void CanvasReset_Click(object sender, RoutedEventArgs e)
{
CanvasForPaint.Children.Clear();
//FOR FUTURE USE, IF NECCESSARY
//TEST.Children.Clear();
//foreach (UIElement child in CanvasForPaint.Children)
//{
// var xaml = System.Windows.Markup.XamlWriter.Save(child);
// var deepCopy = System.Windows.Markup.XamlReader.Parse(xaml) as UIElement;
// TEST.Children.Add(deepCopy);
//}
}
}
}

View File

@@ -34,10 +34,10 @@
<Label Grid.Row="0" Content="This client information:" FontSize="17"/>
<Label Grid.Row="1" Grid.Column="0" Content="Your username:" FontSize="15" VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Grid.Column="1" MaxLength="10" FontSize="15" VerticalAlignment="Center"/>
<TextBox Name="usernameTextbox" Grid.Row="1" Grid.Column="1" MaxLength="10" FontSize="15" VerticalAlignment="Center"/>
<Label Grid.Row="2" Grid.Column="0" Content="Which color you want to be:" FontSize="15" VerticalAlignment="Center"/>
<ComboBox 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="RED"/>
<ComboBoxItem Content="YELLOW"/>
@@ -47,6 +47,8 @@
<ComboBoxItem Content="PURPLE"/>
</ComboBox>
<Label Grid.Row="3" Name="testLabel" FontSize="15" VerticalAlignment="Center"/>
</Grid>
@@ -60,7 +62,14 @@
</ListView.View>
</ListView>
<Button Grid.Column="1" Grid.Row="0" Content="CHECK" Command="{Binding ButtonCommand}"/>
<Grid Grid.Row="1" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Content="join a selected lobby" Click="Button_Click" Width="200" Height="40" HorizontalAlignment="Left" Margin="10, 0, 0, 0"/>
<Button Grid.Row="1" Content="host a new lobby" Command="{Binding ...}" Width="200" Height="40" HorizontalAlignment="left" Margin="10, 0, 0, 0"/>
</Grid>
</Grid>
</Window>

View File

@@ -1,4 +1,5 @@
using System;
using Client.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -24,5 +25,20 @@ namespace Client
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Lobby lobbySelected = LobbyList.SelectedItem as Lobby;
if(lobbySelected != null)
{
testLabel.Content = lobbySelected.ID;
usernameTextbox.IsEnabled = false;
colorSelection.IsEnabled = false;
GameWindow window = new GameWindow();
window.Show();
}
}
}
}