wyświetlanie ilości śmieci

This commit is contained in:
Michał Dulski 2019-03-27 01:11:14 +01:00
parent 9ff635db9f
commit 56d2a4ff75
4 changed files with 35 additions and 24 deletions

View File

@ -12,7 +12,7 @@
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type models:Tile}">
<Grid Background="{Binding Object.Image}">
<TextBlock Text="{Binding Object.Data}"></TextBlock>
<TextBlock Text="{Binding Object.Data}" Foreground="White"></TextBlock>
</Grid>
</DataTemplate>
</ItemsControl.Resources>

View File

@ -48,19 +48,29 @@ namespace CzokoŚmieciarka.WPF
}
}
House house = new House(columns, new Coords(0, 0));
List<Trash> trashes = new List<Trash>();
Trash glass = new Trash(GarbageType.Glass, 100);
Trash plasticMetal = new Trash(GarbageType.PlasticMetal, 100);
Trash organic = new Trash(GarbageType.Organic, 100);
Trash paper = new Trash(GarbageType.Paper, 100);
trashes.Add(glass);
trashes.Add(plasticMetal);
trashes.Add(organic);
trashes.Add(paper);
House house = new House(columns, new Coords(0, 0),trashes);
Objects[house.Location.X + house.Location.Y] = house;
house = new House(columns, new Coords(1, 0));
house = new House(columns, new Coords(1, 0),trashes);
Objects[house.Location.X + house.Location.Y] = house;
house = new House(columns, new Coords(2, 0));
house = new House(columns, new Coords(2, 0),trashes);
Objects[house.Location.X + house.Location.Y] = house;
DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), new TypeOfGarbage("glass", 0, 0));
DumpWPF dump = new DumpWPF(columns, new Coords(2, 4), glass);
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(2, 5), new TypeOfGarbage("plasticmetal", 0, 0));
dump = new DumpWPF(columns, new Coords(2, 5), paper);
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(3, 4), new TypeOfGarbage("organic", 0, 0));
dump = new DumpWPF(columns, new Coords(3, 4), organic);
Objects[dump.Location.X + dump.Location.Y] = dump;
dump = new DumpWPF(columns, new Coords(3, 5), new TypeOfGarbage("paper", 0, 0));
dump = new DumpWPF(columns, new Coords(3, 5), plasticMetal);
Objects[dump.Location.X + dump.Location.Y] = dump;

View File

@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using CzokoŚmieciarka.DataModels.Enums;
using CzokoŚmieciarka.DataModels.Interfaces;
using CzokoŚmieciarka.DataModels.Models;
using CzokoŚmieciarka.WPF.Interfaces;
@ -14,34 +15,33 @@ namespace CzokoŚmieciarka.WPF.Models
{
class DumpWPF : AObject, INotifyPropertyChanged
{
public ITypeOfGarbage TypeOfGarbage { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public DumpWPF(int columns, Coords location, ITypeOfGarbage typeOfGarbage)
public Trash Trash;
public DumpWPF(int columns, Coords location, Trash trash)
{
Location = new Coords(location.X, location.Y * columns);
TypeOfGarbage = typeOfGarbage;
switch (TypeOfGarbage.GarbageType)
Trash = trash;
switch (Trash.Type)
{
case "glass":
case GarbageType.Glass:
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\glass.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Szkło";
Data = String.Format("House\n{0}: {1}", Trash.Type.ToString(), Trash.Weight);
break;
case "plasticmetal":
case GarbageType.PlasticMetal:
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\plasticmetal.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Plastiki i metale";
Data = String.Format("House\n{0}: {1}", Trash.Type.ToString(), Trash.Weight);
break;
case "organic":
case GarbageType.Organic:
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\organic.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Organiczne";
Data = String.Format("House\n{0}: {1}", Trash.Type.ToString(), Trash.Weight);
break;
case "paper":
case GarbageType.Paper:
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\Dumps\paper.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Data = "Papier";
Data = String.Format("House\n{0}: {1}", Trash.Type.ToString(), Trash.Weight);
break;
}
}

View File

@ -12,13 +12,14 @@ namespace CzokoŚmieciarka.WPF.Models
{
public class House : AObject
{
public List<Trash> Trashes = new List<Trash>(4);
public House(int columns, Coords location)
public List<Trash> Trashes = new List<Trash>();
public House(int columns, Coords location, List<Trash> trashes)
{
Trashes = trashes;
ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\Images\house.png";
Image = new ImageBrush(new BitmapImage(new Uri(ImagePath)));
Location = new Coords(location.X, location.Y*columns);
Data = "";
Data = String.Format("House\n{0}: {1}\n{2}: {3}\n{4}: {5}\n{6}: {7}", Trashes[0].Type.ToString(), Trashes[0].Weight, Trashes[1].Type.ToString(), Trashes[1].Weight, Trashes[2].Type.ToString(), Trashes[2].Weight, Trashes[3].Type.ToString(), Trashes[3].Weight);
}
}
}