コード例 #1
0
        public SettingsViewModel(IEnumerable <MapLayout> mapLayouts, IEnumerable <Scenery> textureSets, PreviewViewModel preview)
        {
            this.preview = preview;
            MapLayouts   = new ObservableCollection <MapLayout>(mapLayouts);
            MapLayout    = MapLayouts.FirstOrDefault();

            Sceneries = new ObservableCollection <Scenery>(textureSets);
            Scenery   = Sceneries.FirstOrDefault();

            Frequencies    = new ObservableCollection <Frequency>((Frequency[])Enum.GetValues(typeof(Frequency)));
            TreeFrequency  = Frequency.Medium;
            CliffFrequency = Frequency.Medium;

            TimesOfDay = new ObservableCollection <TimeOfDay>((TimeOfDay[])Enum.GetValues(typeof(TimeOfDay)));
            TimeOfDay  = TimeOfDay.Afternoon;

            Players = new ObservableCollection <int>()
            {
                2, 4
            };
            NumberOfPlayers = 2;

            Width  = 250;
            Height = 250;
            Border = 30;

            IsModified = false;
        }
コード例 #2
0
ファイル: GeneratorViewModel.cs プロジェクト: leex279/genesis
        public GeneratorViewModel(MapGenerator generator, MapLayout[] layouts, Scenery[] sceneries, string logPath = null)
        {
            dispatcher = Dispatcher.CurrentDispatcher;

            LogPath = logPath;

            messages = new StringBuilder();

            Generator      = generator;
            Generator.Log += (s, e) =>
            {
                messages.Append(e.Message);
                messages.Append("...");

                if (e.Message == "Generating rocks")
                {
                    messages.Append(" (it does indeed ;)");
                }

                messages.AppendLine();

                OnPropertyChanged("Messages");
            };

            Generator.PreviewUpdated += (s, e) =>
            {
                dispatcher.Invoke(new Action(() => Preview.UpdatePreview(Generator.Map, Generator.PreviewGenerator.BmpPreview)));
            };

            Preview  = new PreviewViewModel();
            Settings = new SettingsViewModel(layouts, sceneries, Preview);

            if (File.Exists(LogPath))
            {
                log = XDocument.Load(LogPath);
                try
                {
                    var lastMap = log.Root.Descendants("Map").Last();
                    if (lastMap != null)
                    {
                        Generator.MapId         = int.Parse(lastMap.Attribute("Id").Value);
                        Settings.Width          = int.Parse(lastMap.Attribute("Width").Value);
                        Settings.Height         = int.Parse(lastMap.Attribute("Height").Value);
                        Settings.MapLayout      = Settings.MapLayouts.First(l => l.Name == lastMap.Attribute("Layout").Value);
                        Settings.Scenery        = Settings.Sceneries.First(t => t.Name == lastMap.Attribute("Scenery").Value);
                        Settings.CliffFrequency = Settings.Frequencies.First(f => f.ToString() == lastMap.Attribute("Mountains").Value);
                        Settings.TreeFrequency  = Settings.Frequencies.First(f => f.ToString() == lastMap.Attribute("Trees").Value);
                        Settings.TimeOfDay      = Settings.TimesOfDay.First(t => t.ToString() == lastMap.Attribute("TimeOfDay").Value);
                        Settings.IsModified     = false;
                    }
                }
                catch (Exception)
                {
                }
            }
            else
            {
                log = new XDocument(new XElement("Log"));
            }

            Settings.MapId = Generator.MapId;

            NewMapCommand   = new Command(NewMap, CanGenerateNew);
            GenerateCommand = new Command(Generate, CanGenerate);
            SaveCommand     = new Command(Save, CanSave);
            CancelCommand   = new Command(Cancel, CanCancel);
        }