Informacje o pozycji śmieciarki wyświetlane w oknie

This commit is contained in:
Michał Dulski 2019-04-02 23:09:32 +02:00
parent 3613cad37f
commit 9f8d9fb785
6 changed files with 1092 additions and 19 deletions

View File

@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Czoko_015Amieciarka_002EWPFv2_002EAnnotations/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Czoko_015Amieciarka_002EWPF_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Czoko_015Amieciarka_002EWPF_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -74,6 +74,7 @@
<Compile Include="Models\GarbageCollector.cs" /> <Compile Include="Models\GarbageCollector.cs" />
<Compile Include="Models\House.cs" /> <Compile Include="Models\House.cs" />
<Compile Include="Models\Road.cs" /> <Compile Include="Models\Road.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

View File

@ -5,10 +5,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CzokoŚmieciarka.WPFv2" xmlns:local="clr-namespace:CzokoŚmieciarka.WPFv2"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="800" Width="1000"> Title="MainWindow" Height="800" Width="1000"
KeyDown="MainWindow_OnKeyDown">
<Grid> <Grid>
<Grid Name="Board" Margin="0,0,200,0"/> <Grid Name="Board" Margin="0,0,200,0"/>
<Grid Name="CollectorInfo" Margin="800,0,0,0"/> <DataGrid Name="CollectorInfo" Margin="800,0,0,0"/>
<Grid Name="CollectorBoard" Margin="0,0,200,0"/> <Grid Name="CollectorBoard" Margin="0,0,200,0"/>
</Grid> </Grid>

View File

@ -65,25 +65,15 @@ namespace CzokoŚmieciarka.WPFv2
} }
for(int rows = 0; rows < 3; rows++)
{
row = new RowDefinition();
CollectorInfo.RowDefinitions.Add(row);
}
for (int columns = 0; columns < 2; columns++)
{
column = new ColumnDefinition();
CollectorInfo.ColumnDefinitions.Add(column);
}
CollectorInfo.ShowGridLines = true;
GarbageCollectorContainers = new List<AGarbageCollectorContainer>(); GarbageCollectorContainers = new List<AGarbageCollectorContainer>();
garbageCollector = new WPFGarbageCollector(new Coords(2, 1), GarbageCollectorContainers); garbageCollector = new WPFGarbageCollector(new Coords(2, 1), GarbageCollectorContainers);
Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y); Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y);
Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.X); Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.X);
CollectorBoard.Children.Add(garbageCollector.Image); CollectorBoard.Children.Add(garbageCollector.Image);
CollectorBoard.ShowGridLines = true; CollectorBoard.ShowGridLines = true;
CollectorInfo.Items.Add(garbageCollector);
CollectorInfo.Columns.Add(new DataGridTextColumn {Header="X", Binding = new Binding("Position.X")});
CollectorInfo.Columns.Add(new DataGridTextColumn { Header = "Y", Binding = new Binding("Position.Y") });
} }
private void MainWindow_OnKeyDown(object sender, KeyEventArgs e) private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
@ -91,9 +81,13 @@ namespace CzokoŚmieciarka.WPFv2
if (e.Key == Key.Space) if (e.Key == Key.Space)
{ {
garbageCollector.Position = garbageCollector.MoveRight();
} }
CollectorBoard.Children.Clear();
Grid.SetRow(garbageCollector.Image, garbageCollector.Position.Y);
Grid.SetColumn(garbageCollector.Image, garbageCollector.Position.X);
CollectorBoard.Children.Add(garbageCollector.Image);
} }
} }
} }

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls; using System.Windows.Controls;
@ -9,11 +11,12 @@ using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector; using CzokoŚmieciarka.DataModels.Interfaces.GarbageCollector;
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans; using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
using CzokoŚmieciarka.DataModels.Models; using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.WPFv2.Annotations;
using CzokoŚmieciarka.WPFv2.Interfaces; using CzokoŚmieciarka.WPFv2.Interfaces;
namespace CzokoŚmieciarka.WPFv2.Models namespace CzokoŚmieciarka.WPFv2.Models
{ {
class WPFGarbageCollector : AGarbageCollector, IWPFObject class WPFGarbageCollector : AGarbageCollector, IWPFObject, INotifyPropertyChanged
{ {
public string ImagePath { get; set; } public string ImagePath { get; set; }
public Image Image { get; set; } public Image Image { get; set; }
@ -27,5 +30,13 @@ namespace CzokoŚmieciarka.WPFv2.Models
@"..\..\Images\garbageCollector.png")) @"..\..\Images\garbageCollector.png"))
}; };
} }
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} }
} }

File diff suppressed because it is too large Load Diff