Skip to content
Snippets Groups Projects
Commit 0c1a84e6 authored by Dorian Selimovic's avatar Dorian Selimovic
Browse files

Merge branch 'editor'

parents af3f4d45 87d432ce
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="CharacterEditor.xaml.cs">
<DependentUpon>CharacterEditor.xaml</DependentUpon>
</Compile>
<Compile Include="Characters.xaml.cs">
<DependentUpon>Characters.xaml</DependentUpon>
</Compile>
......@@ -77,6 +80,13 @@
<Compile Include="Houses.xaml.cs">
<DependentUpon>Houses.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\CharacterEditorVM.cs" />
<Compile Include="ViewModels\RelayCommand.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
<Page Include="CharacterEditor.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Characters.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......
<UserControl x:Class="ApplicationWPF.CharacterEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ApplicationWPF"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="6" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button Grid.Row="0" Grid.Column="0" Content="Retour" Click="OnReturnClick" Margin="0, 0 ,0, 15" />
<Label Grid.Row="1" Grid.Column="0" Content="First Name : " HorizontalAlignment="Right" />
<TextBox x:Name="FirstNameBox" Grid.Row="1" Grid.Column="1" Text="{Binding Path=FirstName, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,-160,0" />
<Label Grid.Row="2" Grid.Column="0" Content="Last Name : " HorizontalAlignment="Right" />
<TextBox x:Name="LastNameBox" Grid.Row="2" Grid.Column="1" Text="{Binding Path=LastName, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,-160,0" />
<Label Grid.Row="3" Grid.Column="0" Content="Bravoury : " HorizontalAlignment="Right" />
<TextBox x:Name="BravouryBox" Grid.Row="3" Grid.Column="1" Text="{Binding Path=Bravoury, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,-160,0" />
<Label Grid.Row="4" Grid.Column="0" Content="Crazyness : " HorizontalAlignment="Right" />
<TextBox x:Name="CrazynessBox" Grid.Row="4" Grid.Column="1" Text="{Binding Path=Crazyness, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,-160,0" />
<Label Grid.Row="5" Grid.Column="0" Content="Strength : " HorizontalAlignment="Right" />
<TextBox x:Name="StrengthBox" Grid.Row="5" Grid.Column="1" Text="{Binding Path=Strength, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,-160,0" />
<Label Grid.Row="6" Grid.Column="0" Content="Health : " HorizontalAlignment="Right" />
<TextBox x:Name="HealthBox" Grid.Row="6" Grid.Column="1" Text="{Binding Path=Health, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,-160,15" />
<Button Grid.Row="7" Grid.Column="0" Content="Valider" Click="OnSave"/>
</Grid>
</UserControl>
using ApplicationWPF.ViewModels;
using EntityLayer;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
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 ApplicationWPF
{
/// <summary>
/// Logique d'interaction pour CharacterEditor.xaml
/// </summary>
public partial class CharacterEditor : UserControl
{
public CharacterEditor()
{
InitializeComponent();
getCharacter(ViewModel.Instance.Param);
}
private void OnReturnClick(object sender, RoutedEventArgs e)
{
ViewModel.Instance.SwitchView = 2;
}
private async void OnSave(object sender, RoutedEventArgs e)
{
Console.WriteLine("Baudhuit");
using (var client = new HttpClient())
{
var values = new Dictionary<string, string>
{
{ "firstname", FirstNameBox.Text },
{ "lastname", LastNameBox.Text },
{ "bravoury", BravouryBox.Text },
{ "strength", StrengthBox.Text },
{ "health", HealthBox.Text },
{ "crazyness", CrazynessBox.Text }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://localhost:4205/Character/Edit/" + ViewModel.Instance.Param, content);
if (response.IsSuccessStatusCode)
{
ViewModel.Instance.SwitchView = 2;
}
else
{
// TODO afficher erreur
}
}
}
public async void getCharacter(int id)
{
Character c = null;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:4205/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync($"Character/Details/{id}");
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
var item = (JObject) JsonConvert.DeserializeObject(temp);
System.Diagnostics.Debug.WriteLine(temp);
c = new Character() { ID = item.Value<int>("id"), FirstName = item.Value<String>("firstName"), LastName = item.Value<String>("lastName"), Bravoury = item.Value<int>("bravoury"), Crazyness = item.Value<int>("crazyness"), Strength = item.Value<int>("strength"), Health = item.Value<int>("health") };
}
}
FirstNameBox.Text = c.FirstName;
LastNameBox.Text = c.LastName;
BravouryBox.Text = c.Bravoury.ToString();
StrengthBox.Text = c.Strength.ToString();
HealthBox.Text = c.Health.ToString();
CrazynessBox.Text = c.Crazyness.ToString();
}
}
}
......@@ -15,9 +15,10 @@
<Button Content="Retour" Click="OnReturnClick"/>
</Grid>
</Grid>
<ListView Margin="10, 25, 10, 10" Name="cList">
<ListView Margin="10, 25, 10, 10" Name="cList" SelectionChanged="OnClickItem">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="0" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="First name" Width="120" DisplayMemberBinding="{Binding FirstName}" />
<GridViewColumn Header="Last name" Width="120" DisplayMemberBinding="{Binding LastName}" />
<GridViewColumn Header="Bravoury" Width="120" DisplayMemberBinding="{Binding Bravoury}" />
......
......@@ -36,6 +36,19 @@ namespace ApplicationWPF
ViewModel.Instance.SwitchView = 0;
}
private void OnClickItem(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (cList.SelectedIndex != -1)
{
Character c = (Character)cList.SelectedItem;
Console.WriteLine(c.FirstName + " " + c.ID);
ViewModel.Instance.Param = c.ID;
ViewModel.Instance.SwitchView = 4;
}
}
public async void getCharacters()
{
......@@ -57,7 +70,7 @@ namespace ApplicationWPF
int i = 0;
foreach (var item in ((JArray)obj))
{
items.Add(new Character() { FirstName = item.Value<String>("FirstName"), LastName = item.Value<String>("LastName"), Bravoury = item.Value<int>("Bravoury"), Crazyness = item.Value<int>("Crazyness"), Strength = item.Value<int>("Strength"), Health = item.Value<int>("Health") });
items.Add(new Character() { ID=item.Value<int>("ID"), FirstName = item.Value<String>("FirstName"), LastName = item.Value<String>("LastName"), Bravoury = item.Value<int>("Bravoury"), Crazyness = item.Value<int>("Crazyness"), Strength = item.Value<int>("Strength"), Health = item.Value<int>("Health") });
i++;
}
}
......
......@@ -27,6 +27,10 @@
<DataTemplate x:Key="duelTemplate" DataType="{x:Type local:ViewModel}">
<local:Duels />
</DataTemplate>
<DataTemplate x:Key="CharacterEditorTemplate" DataType="{x:Type local:ViewModel}">
<local:CharacterEditor />
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl Content="{Binding }">
......@@ -43,6 +47,9 @@
<DataTrigger Binding="{Binding SwitchView}" Value="3">
<Setter Property="ContentTemplate" Value="{StaticResource duelTemplate}" />
</DataTrigger>
<DataTrigger Binding="{Binding SwitchView}" Value="4">
<Setter Property="ContentTemplate" Value="{StaticResource CharacterEditorTemplate}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
......
......@@ -9,6 +9,7 @@ namespace EntityLayer
public class Character
{
//Attributes
public int ID { get; set; }
public int Bravoury { get; set; } //Over 100
public int Crazyness { get; set; } //Over 100
public int Strength { get; set; } //Over 100
......@@ -17,9 +18,7 @@ namespace EntityLayer
public int Health { get; set; } //Over 100
public Dictionary<int, RelationshipEnum> Relationships { get; set; }
//Methods
public void addRelation(int ID, RelationshipEnum type)
{
Relationships.Add(ID, type);
......
......@@ -5,6 +5,13 @@ using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
/* SwitchView :
* 0 : Accueil
* 1 : Houses
* 2 : Characters
* 3 : Duels
* 4 : CharacterEditor */
namespace ApplicationWPF
{
class ViewModel : INotifyPropertyChanged
......@@ -12,6 +19,7 @@ namespace ApplicationWPF
public static ViewModel instance = null;
public int switchView;
public int Param { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
......
using EntityLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationWPF.ViewModels
{
class CharacterEditorVM : ViewModelBase
{
private Character _character;
public Character Character
{
get { return _character; }
private set { _character = value; }
}
public CharacterEditorVM(Character c)
{
_character = c;
}
public string FirstName
{
get { return _character.FirstName; }
set
{
if (value == _character.FirstName) return;
_character.FirstName = value;
base.OnPropertyChanged("FirstName");
}
}
public string LastName
{
get { return _character.LastName; }
set
{
if (value == _character.LastName) return;
_character.LastName = value;
base.OnPropertyChanged("LastName");
}
}
public int Health
{
get { return _character.Health; }
set
{
if (value == _character.Health) return;
_character.Health = value;
base.OnPropertyChanged("Health");
}
}
public int Bravoury
{
get { return _character.Bravoury; }
set
{
if (value == _character.Bravoury) return;
_character.Bravoury = value;
base.OnPropertyChanged("Bravoury");
}
}
public int Crazyness
{
get { return _character.Crazyness; }
set
{
if (value == _character.Crazyness) return;
_character.Crazyness = value;
base.OnPropertyChanged("Crazyness");
}
}
public int Strength
{
get { return _character.Strength; }
set
{
if (value == _character.Strength) return;
_character.Strength = value;
base.OnPropertyChanged("Strength");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
namespace ApplicationWPF.ViewModels
{
/// <summary>
/// A command whose sole purpose is to relay its functionality to other
/// objects by invoking delegates. The default return value for the CanExecute
/// method is 'true'.
/// </summary>
public class RelayCommand : ICommand
{
#region private fields
private readonly Action execute;
private readonly Func<bool> canExecute;
#endregion
public event EventHandler CanExecuteChanged
{
add
{
if (this.canExecute != null)
CommandManager.RequerySuggested += value;
}
remove
{
if (this.canExecute != null)
CommandManager.RequerySuggested -= value;
}
}
/// <summary>
/// Initializes a new instance of the RelayCommand class
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand(Action execute)
: this(execute, null)
{
}
/// <summary>
/// Initializes a new instance of the RelayCommand class
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action execute, Func<bool> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
this.execute = execute;
this.canExecute = canExecute;
}
public void Execute(object parameter)
{
this.execute();
}
public bool CanExecute(object parameter)
{
return this.canExecute == null ? true : this.canExecute();
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Diagnostics;
namespace ApplicationWPF.ViewModels
{
/// <summary>
/// Base class for all ViewModel classes in the application. Provides support for
/// property changes notification.
/// </summary>
public abstract class ViewModelBase : INotifyPropertyChanged
{
/// <summary>
/// Raised when a property on this object has a new value.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Warns the developer if this object does not have a public property with
/// the specified name. This method does not exist in a Release build.
/// </summary>
[Conditional("DEBUG")]
[DebuggerStepThrough]
public void VerifyPropertyName(string propertyName)
{
// verify that the property name matches a real,
// public, instance property on this object.
if (TypeDescriptor.GetProperties(this)[propertyName] == null)
{
Debug.Fail("Invalid property name: " + propertyName);
}
}
/// <summary>
/// Raises this object's PropertyChanged event.
/// </summary>
/// <param name="propertyName">The name of the property that has a new value.</param>
protected virtual void OnPropertyChanged(string propertyName)
{
this.VerifyPropertyName(propertyName);
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment