Ejemplo n.º 1
0
 private void Start()
 {
     weatherCtrl    = GameObject.Find("WeatherCtrl").GetComponent <WeatherCtrl>();
     country_Effect = GetComponent <Country_Effect>();
     tr_Pos         = this.transform;
     ChangeState(eState.Clear);
 }
Ejemplo n.º 2
0
        public WeatherViewModel(WeatherFile weatherFile, Window parentWindow)
            : base(weatherFile, parentWindow)
        {
            _weatherFile = weatherFile;

            NewTimeRangeCmd = new RelayCommand(arg =>
            {
                _weatherFile.WeatherSet.Add(new WeatherTimeRange(WeatherFile));
                SelectedTimeRange = _weatherFile.WeatherSet.Last();
            }
                                               );

            DelTimeRangeCmd = new RelayCommand(arg =>
            {
                _weatherFile.WeatherSet.Remove(SelectedTimeRange);
            },
                                               arg =>
            {
                return(SelectedTimeRange != null);
            }
                                               );

            AddVariableCmd = new RelayCommand(arg =>
            {
                if (SelectedTimeRange != null)
                {
                    SelectedTimeRange.Variables.Add(new L3dVariable(WeatherFile, "Variable", string.Empty));
                    SelectedVariable = SelectedTimeRange.Variables.Last();
                }
            },
                                              arg =>
            {
                return(SelectedTimeRange != null);
            }
                                              );

            RemoveVariableCmd = new RelayCommand(arg =>
            {
                if (SelectedTimeRange != null && SelectedVariable != null)
                {
                    SelectedTimeRange.Variables.Remove(SelectedVariable);
                    SelectedVariable = null;
                }
            },
                                                 arg =>
            {
                return(SelectedTimeRange != null && SelectedVariable != null);
            }
                                                 );

            CopyTimeRange = new RelayCommand(arg =>
            {
                try
                {
                    if (SelectedTimeRange != null)
                    {
                        Clipboard.SetText(SelectedTimeRange.ConvertToXml().ToString(), TextDataFormat.UnicodeText);
                    }
                }
                catch (Exception)
                {
                    SystemSounds.Exclamation.Play();
                }
            },
                                             arg =>
            {
                return(SelectedTimeRange != null);
            }
                                             );

            CutTimeRange = new RelayCommand(arg =>
            {
                try
                {
                    if (SelectedTimeRange != null)
                    {
                        Clipboard.SetText(SelectedTimeRange.ConvertToXml().ToString(), TextDataFormat.UnicodeText);
                        _weatherFile.WeatherSet.Remove(SelectedTimeRange);
                    }
                }
                catch (Exception)
                {
                    SystemSounds.Exclamation.Play();
                }
            },
                                            arg =>
            {
                return(SelectedTimeRange != null);
            }
                                            );

            PasteTimeRange = new RelayCommand(arg =>
            {
                var w = WeatherTimeRange.ReadFromXml(Clipboard.GetText(), WeatherFile);
                if (w != null)
                {
                    _weatherFile.WeatherSet.Add(w);
                    SelectedTimeRange = w;
                }
            },
                                              arg =>
            {
                try
                {
                    return(Clipboard.ContainsText() && WeatherTimeRange.ReadFromXml(Clipboard.GetText(), WeatherFile) != null);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
                                              );

            SortTimeRangesCmd = new RelayCommand(arg =>
            {
                string sortCol = (string)arg;
                _timerangesView.SortDescriptions.Clear();

                if (_timerangesSortAsc)
                {
                    _timerangesView.SortDescriptions.Add(new SortDescription(sortCol, ListSortDirection.Ascending));
                }
                else
                {
                    _timerangesView.SortDescriptions.Add(new SortDescription(sortCol, ListSortDirection.Descending));
                }
                _timerangesSortAsc = !_timerangesSortAsc;
            }
                                                 );

            _weatherCtrl             = new WeatherCtrl();
            _weatherCtrl.WeatherFile = _weatherFile;

            _timerangesView        = new CollectionViewSource();
            _timerangesView.Source = _weatherFile.WeatherSet;

            SelectedTimeRange = _weatherFile.WeatherSet.FirstOrDefault();
        }