Ejemplo n.º 1
0
        public override LayerPropertiesModel GetAppliedProperties()
        {
            var properties = GeneralHelpers.Clone(ProposedProperties);

            properties.Brush = Brush;
            return(properties);
        }
Ejemplo n.º 2
0
        public override async void CanClose(Action <bool> callback)
        {
            // Create a fake layer and apply the properties to it
            var fakeLayer = GeneralHelpers.Clone(ProposedLayer);

            if (LayerPropertiesViewModel != null)
            {
                fakeLayer.Properties = LayerPropertiesViewModel.GetAppliedProperties();
            }
            fakeLayer.Properties.Conditions.Clear();
            foreach (var conditionViewModel in LayerConditionVms)
            {
                fakeLayer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);
            }


            var fake = GeneralHelpers.Serialize(fakeLayer);
            var real = GeneralHelpers.Serialize(Layer);

            if (fake.Equals(real))
            {
                callback(true);
                return;
            }

            var close =
                await DialogService.ShowQuestionMessageBox("Unsaved changes", "Do you want to discard your changes?");

            callback(close.Value);
        }
Ejemplo n.º 3
0
        public async void DuplicateProfile()
        {
            if (SelectedProfile == null)
            {
                return;
            }

            var newProfile = GeneralHelpers.Clone(SelectedProfile);

            newProfile.Name =
                await DialogService.ShowInputDialog("Duplicate profile", "Please enter a unique profile name");

            // Verify the name
            while (ProfileProvider.GetAll().Contains(newProfile))
            {
                newProfile.Name =
                    await DialogService.ShowInputDialog("Name already in use", "Please enter a unique profile name");

                // Null when the user cancelled
                if (string.IsNullOrEmpty(SelectedProfile.Name))
                {
                    return;
                }
            }

            newProfile.IsDefault = false;
            ProfileProvider.AddOrUpdate(newProfile);
            LoadProfiles();
            SelectedProfile = Profiles.FirstOrDefault(p => p.Name == newProfile.Name);
        }
Ejemplo n.º 4
0
        public LayerEditorViewModel(LayerModel layer, ModuleDataModel dataModel, IEnumerable <ILayerType> types,
                                    IEnumerable <ILayerAnimation> layerAnimations)
        {
            Layer         = layer;
            ProposedLayer = GeneralHelpers.Clone(layer);
            ProposedLayer.Children.Clear();
            DataModel       = DataModel;
            LayerTypes      = new BindableCollection <ILayerType>(types.OrderBy(t => t.Name));
            LayerAnimations = layerAnimations.OrderBy(l => l.Name).ToList();

            DataModelProps = new BindableCollection <GeneralHelpers.PropertyCollection>(GeneralHelpers.GenerateTypeMap(dataModel));

            if (Layer.Properties == null)
            {
                Layer.SetupProperties();
            }

            // Setup existing conditions
            var conditions = ProposedLayer.Properties.Conditions.Select(c => new LayerConditionViewModel(this, c));
            var keyBinds   = ProposedLayer.Properties.LayerKeybindModels.Select(c => new LayerKeybindViewModel(this, c));

            LayerConditionVms = new BindableCollection <LayerConditionViewModel>(conditions);
            LayerKeybindVms   = new BindableCollection <LayerKeybindViewModel>(keyBinds);

            PropertyChanged += PropertiesViewModelHandler;

            // Setup existiing properties
            PreSelect();
        }
Ejemplo n.º 5
0
        public LayerDynamicPropertiesViewModel(string property, LayerEditorViewModel layerEditorViewModel)
        {
            _property             = property;
            _layerEditorViewModel = layerEditorViewModel;

            // Look for the existing property model
            Proposed = new DynamicPropertiesModel();
            var original = layerEditorViewModel
                           .ProposedLayer
                           .Properties
                           .DynamicProperties
                           .FirstOrDefault(lp => lp.LayerProperty == _property);

            if (original == null)
            {
                Proposed.LayerProperty     = property;
                Proposed.LayerPropertyType = LayerPropertyType.PercentageOf;
            }
            else
            {
                Proposed = GeneralHelpers.Clone(original);
            }

            PropertyChanged += OnPropertyChanged;
            SetupControls();
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Clones the given layer and adds it to the profile, after the original
        /// </summary>
        /// <param name="layer"></param>
        public void CloneLayer(LayerModel layer)
        {
            var clone = GeneralHelpers.Clone(layer);

            layer.InsertAfter(clone);

            UpdateLayerList(clone);
        }
Ejemplo n.º 7
0
        public override async void CanClose(Action <bool> callback)
        {
            // Create a fake layer and apply the properties to it
            LayerPropertiesViewModel?.ApplyProperties();
            // TODO: EventPropVM must have layer too
            if (EventPropertiesViewModel != null)
            {
                ProposedLayer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
            }

            ProposedLayer.Properties.Conditions.Clear();
            foreach (var conditionViewModel in LayerConditionVms)
            {
                ProposedLayer.Properties.Conditions.Add(conditionViewModel.ConditionModel);
            }

            ProposedLayer.Properties.LayerKeybindModels.Clear();
            foreach (var layerKeybindViewModel in LayerKeybindVms)
            {
                ProposedLayer.Properties.LayerKeybindModels.Add(layerKeybindViewModel.LayerKeybindModel);
            }

            // Ignore this property as it isn't user input
            ProposedLayer.RenderAllowed = Layer.RenderAllowed;

            // If not a keyboard, ignore size and position
            if ((ProposedLayer.LayerType.DrawType != DrawType.Keyboard) || !ProposedLayer.LayerType.ShowInEdtor)
            {
                ProposedLayer.Properties.Width   = Layer.Properties.Width;
                ProposedLayer.Properties.Height  = Layer.Properties.Height;
                ProposedLayer.Properties.X       = Layer.Properties.X;
                ProposedLayer.Properties.Y       = Layer.Properties.Y;
                ProposedLayer.Properties.Contain = Layer.Properties.Contain;
            }

            // Ignore the children, can't just temporarily add them to the proposed layer because
            // that would upset the child layers' relations (sounds like Dr. Phil amirite?)
            var currentObj = GeneralHelpers.Clone(Layer);

            currentObj.Children.Clear();

            // Apply the IsEvent boolean
            currentObj.SetupCondition();
            ProposedLayer.SetupCondition();

            var current  = JsonConvert.SerializeObject(currentObj, Formatting.Indented);
            var proposed = JsonConvert.SerializeObject(ProposedLayer, Formatting.Indented);

            if (current.Equals(proposed))
            {
                callback(true);
                return;
            }

            var close = await DialogService.ShowQuestionMessageBox("Unsaved changes", "Do you want to discard your changes?");

            callback(close.Value);
        }
Ejemplo n.º 8
0
        public override LayerPropertiesModel GetAppliedProperties()
        {
            HeightProperties.Apply(ProposedProperties);
            WidthProperties.Apply(ProposedProperties);
            OpacityProperties.Apply(ProposedProperties);

            var properties = GeneralHelpers.Clone(ProposedProperties);

            properties.Brush = Brush;
            return(properties);
        }
Ejemplo n.º 9
0
        public KeyboardPropertiesViewModel(IDataModel dataModel, LayerPropertiesModel properties)
            : base(dataModel)
        {
            var keyboardProperties = (KeyboardPropertiesModel)properties;

            ProposedProperties = GeneralHelpers.Clone(keyboardProperties);
            Brush = ProposedProperties.Brush.CloneCurrentValue();

            DataModelProps = new BindableCollection <GeneralHelpers.PropertyCollection>();
            DataModelProps.AddRange(GeneralHelpers.GenerateTypeMap(dataModel));

            HeightProperties  = new LayerDynamicPropertiesViewModel("Height", DataModelProps, keyboardProperties);
            WidthProperties   = new LayerDynamicPropertiesViewModel("Width", DataModelProps, keyboardProperties);
            OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", DataModelProps, keyboardProperties);
        }
Ejemplo n.º 10
0
 public EventPropertiesViewModel(EventPropertiesModel eventPropertiesModel)
 {
     if (eventPropertiesModel == null)
     {
         ProposedProperties = new KeyboardEventPropertiesModel
         {
             ExpirationType = ExpirationType.Time,
             Length         = new TimeSpan(0, 0, 1),
             TriggerDelay   = new TimeSpan(0)
         }
     }
     ;
     else
     {
         ProposedProperties = GeneralHelpers.Clone(eventPropertiesModel);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        ///     Updates the inner layers when the settings have changed
        /// </summary>
        /// <param name="layerModel"></param>
        private void UpdateLayers(LayerModel layerModel)
        {
            var settings = (AudioPropertiesModel)layerModel.Properties;

            if (JsonConvert.SerializeObject(settings).Equals(JsonConvert.SerializeObject(_previousSettings)))
            {
                return;
            }

            _previousSettings = GeneralHelpers.Clone((AudioPropertiesModel)layerModel.Properties);

            _audioLayers.Clear();
            if (settings.Direction == Direction.TopToBottom || settings.Direction == Direction.BottomToTop)
            {
                SetupVertical(settings);
            }
            else if (settings.Direction == Direction.LeftToRight || settings.Direction == Direction.RightToLeft)
            {
                SetupHorizontal(settings);
            }
        }
Ejemplo n.º 12
0
        public LayerEditorViewModel(IDataModel dataModel, LayerModel layer)
        {
            _dataModel = dataModel;

            Layer         = layer;
            ProposedLayer = GeneralHelpers.Clone(layer);

            if (Layer.Properties == null)
            {
                Layer.SetupProperties();
            }

            DataModelProps = new BindableCollection <GeneralHelpers.PropertyCollection>();
            DataModelProps.AddRange(GeneralHelpers.GenerateTypeMap(dataModel));
            LayerConditionVms = new BindableCollection <LayerConditionViewModel>(layer.Properties.Conditions
                                                                                 .Select(c => new LayerConditionViewModel(this, c, DataModelProps)));

            PropertyChanged += PropertiesViewModelHandler;

            PreSelect();
        }
Ejemplo n.º 13
0
        public async Task <ProfileModel> DuplicateProfile(ProfileModel selectedProfile)
        {
            var newProfile = GeneralHelpers.Clone(selectedProfile);
            var name       = await GetValidProfileName("Duplicate profile", "Please enter a unique new profile name");

            // User cancelled
            if (name == null)
            {
                return(null);
            }
            var doRename = await MakeProfileUnique(newProfile, name, newProfile.Name);

            if (!doRename)
            {
                return(null);
            }

            // Make sure it's not default, in case of copying a default profile
            newProfile.IsDefault = false;
            ProfileProvider.AddOrUpdate(newProfile);

            return(newProfile);
        }
Ejemplo n.º 14
0
        public LayerDynamicPropertiesViewModel(string property,
                                               BindableCollection <GeneralHelpers.PropertyCollection> dataModelProps,
                                               KeyboardPropertiesModel keyboardProperties)
        {
            _property = property;

            // Look for the existing property model
            Proposed = new DynamicPropertiesModel();
            var original = keyboardProperties.DynamicProperties.FirstOrDefault(lp => lp.LayerProperty == _property);

            if (original == null)
            {
                Proposed.LayerProperty     = property;
                Proposed.LayerPropertyType = LayerPropertyType.PercentageOf;
            }
            else
            {
                Proposed = GeneralHelpers.Clone(original);
            }

            PropertyChanged += OnPropertyChanged;
            SetupControls(dataModelProps);
        }
Ejemplo n.º 15
0
 public MousePropertiesViewModel(IDataModel dataModel, LayerPropertiesModel properties)
     : base(dataModel)
 {
     ProposedProperties = GeneralHelpers.Clone(properties);
     Brush = ProposedProperties.Brush.CloneCurrentValue();
 }
Ejemplo n.º 16
0
 public FolderPropertiesViewModel(IDataModel dataModel, LayerPropertiesModel properties)
     : base(dataModel)
 {
     ProposedProperties = GeneralHelpers.Clone(properties);
 }
Ejemplo n.º 17
0
 public EventPropertiesModel GetAppliedProperties()
 {
     return(GeneralHelpers.Clone(ProposedProperties));
 }
Ejemplo n.º 18
0
 public override LayerPropertiesModel GetAppliedProperties()
 {
     return(GeneralHelpers.Clone(ProposedProperties));
 }