コード例 #1
0
        public void Apply()
        {
            LayerPropertiesViewModel?.ApplyProperties();

            Layer.Properties.DynamicProperties.Clear();
            JsonConvert.PopulateObject(JsonConvert.SerializeObject(ProposedLayer), Layer);
            Layer.Properties.Conditions.Clear();
            foreach (var conditionViewModel in LayerConditionVms)
            {
                Layer.Properties.Conditions.Add(conditionViewModel.LayerConditionModel);
            }

            // TODO: EventPropVM must have layer too
            if (EventPropertiesViewModel != null)
            {
                Layer.EventProperties = EventPropertiesViewModel.GetAppliedProperties();
            }

            Layer.SetupCondition();

            // Don't bother checking for a GIF path unless the type is GIF
            if (!(Layer.LayerType is KeyboardGifType))
            {
                return;
            }
            if (!File.Exists(((KeyboardPropertiesModel)Layer.Properties).GifFile))
            {
                DialogService.ShowErrorMessageBox("Couldn't find or access the provided GIF file.");
            }
        }
コード例 #2
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);
        }