first commit

This commit is contained in:
Digi
2025-02-23 20:09:12 +01:00
commit f3da4b9c3e
175 changed files with 2729 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace YapperClient.MVVM.Core
{
class RelayCommand : ICommand
{
private Action<object> execute;
private Func<object, bool> canExecute;
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value;}
}
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return this.canExecute == null || this.canExecute(parameter);
}
public void Execute(object parameter)
{
this.execute(parameter);
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YapperClient.MVVM.Model
{
class UserModel
{
public string UserName { get; set; }
public string UID { get; set; }
}
}

View File

@@ -0,0 +1,53 @@
<Window x:Class="Yapper.MainWindow"
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:Yapper"
xmlns:viewmodel="clr-namespace:YapperClient.MVVM.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<viewmodel:MainViewModel/>
</Window.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<DockPanel>
<TextBox Height="25"
DockPanel.Dock="Top"
Text="{Binding UserName, UpdateSourceTrigger=PropertyChanged}"
/>
<Button Height="25"
DockPanel.Dock="Top"
Content="connect"
Command="{Binding ConnectToServerCommand}"
/>
<ListView
ItemsSource="{Binding Users}"
>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding UserName}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
<StackPanel Grid.Column="1">
<ListView Height="380"></ListView>
<StackPanel Orientation="Horizontal">
<TextBox Height="55" Width="545" VerticalContentAlignment="Center"></TextBox>
<Button Width="55" Content="send"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,24 @@
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.Navigation;
using System.Windows.Shapes;
namespace Yapper
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using YapperClient.MVVM.Core;
using YapperClient.MVVM.Model;
using YapperClient.Net;
namespace YapperClient.MVVM.ViewModel
{
class MainViewModel
{
public ObservableCollection<UserModel> Users { get; set; }
public RelayCommand ConnectToServerCommand { get; set; }
public string UserName { get; set; }
private Server _server;
public MainViewModel() {
Users = new ObservableCollection<UserModel>();
_server = new Server();
_server.connectedEvent += UserConnected;
ConnectToServerCommand = new RelayCommand(o => _server.ConnectToServer(UserName), o => !string.IsNullOrEmpty(UserName));
}
private void UserConnected()
{
var user = new UserModel
{
UserName = _server.PacketReader.ReadMessage(),
UID = _server.PacketReader.ReadMessage(),
};
if (!Users.Any(x => x.UID == user.UID))
{
Application.Current.Dispatcher.Invoke(() => Users.Add(user));
}
}
}
}