forked from ZeroK-RTS/Zero-K-Infrastructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanetDialog.xaml.cs
65 lines (59 loc) · 2.18 KB
/
PlanetDialog.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
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;
using ZkData;
namespace GalaxyDesigner
{
/// <summary>
/// Interaction logic for PlanetDialog.xaml
/// </summary>
public partial class PlanetDialog : Window
{
PlanetDrawing pd;
public Planet planet { get; set; }
public PlanetDialog(PlanetDrawing pd, IEnumerable<Resource> maps, IEnumerable<StructureType> structureTypes)
{
this.pd = pd;
this.planet = pd.Planet;
InitializeComponent();
lbName.Text = planet.Name;
maps = maps.OrderBy(x => x.MetadataName);
foreach (var mn in maps) cbMaps.Items.Add(new ComboBoxItem() { Content = mn.InternalName, Tag = mn.ResourceID, IsSelected = mn.ResourceID == this.planet.MapResourceID });
if (this.planet.MapResourceID == null) cbMaps.SelectedIndex = new Random().Next(cbMaps.Items.Count);
foreach (var s in structureTypes)
{
lbStructures.Items.Add(new ListBoxItem() {Content = s.Name, Tag = s.StructureTypeID, IsSelected = planet.PlanetStructures.Any(y=>y.StructureTypeID==s.StructureTypeID) });
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
//planet.Detach();
planet.Name = lbName.Text;
//planet.MapResourceID = (int?)((ComboBoxItem)cbMaps.SelectedItem).Tag;
var mid = (int?)((ComboBoxItem)cbMaps.SelectedItem).Tag;
planet.Resource = new ZkDataContext().Resources.Single(x => x.ResourceID == mid);
planet.MapResourceID = planet.Resource.ResourceID;
planet.PlanetStructures.Clear();
foreach (ListBoxItem s in lbStructures.Items)
{
if (s.IsSelected) planet.PlanetStructures.Add(new PlanetStructure() { StructureTypeID = (int)s.Tag});
}
pd.UpdateData(lbStructures.Items.Cast<ListBoxItem>().Where(x => x.IsSelected).Select(x => x.Content.ToString()));
DialogResult = true;
Close();
}
void Cancel_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}