Ejemplo n.º 1
0
        private void UpdateInstance(IValueEditor editor, object valueOverride, bool committedChange)
        {
            if (lstProperties.SelectedItem is EffectProperty effectProperty)
            {
                // Store this change in the Mini.
                if (frmPersistentEffectPropertyEditor != null)
                {
                    Control childAtPoint = frmPersistentEffectPropertyEditor.GetChildAtPoint(new Point(4, 4));
                    if (childAtPoint is IValueEditor valueEditor)
                    {
                        BasePropertyChanger propertyChanger = valueEditor.GetPropertyChanger();
                        string saveValue = propertyChanger.Value;
                        if (propertyChanger != null)
                        {
                            string[] paths      = effectProperty.Paths.Split(';');
                            bool     needToSave = true;
                            foreach (string path in paths)
                            {
                                propertyChanger.FullPropertyPath = path;
                                propertyChanger.ValueOverride    = valueOverride;
                                propertyChanger.ModifyProperty(Instance);

                                if (needToSave)
                                {
                                    if (committedChange)
                                    {
                                        needToSave = false;
                                        IOldPersistentEffect persistentEffect = Mini.GetPersistentEffect();
                                        if (editor is IScriptEditor scriptEditor)
                                        {
                                            //Talespire.Log.Debug($"");
                                            //Talespire.Log.Warning($"editor is IScriptEditor scriptEditor!!!");
                                            //Talespire.Log.Warning($"effectProperty.Type = {effectProperty.Type?.FullName}");
                                            //Talespire.Log.Warning($"scriptEditor.LastSerializedData = \"{scriptEditor.LastSerializedData}\"");
                                            //Talespire.Log.Debug($"");
                                            if (persistentEffect is SuperPersistentEffect superPersistentEffect)
                                            {
                                                if (effectProperty.Type != null)
                                                {
                                                    superPersistentEffect.ScriptData[effectProperty.Type.FullName] = scriptEditor.LastSerializedData;
                                                    Mini.SavePersistentEffect(persistentEffect);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            string propertyKey;

                                            if (effectProperty.Name.StartsWith("$"))
                                            {
                                                propertyKey = effectProperty.Name;
                                            }
                                            else
                                            {
                                                propertyKey = effectProperty.Paths;
                                            }

                                            if (persistentEffect != null)
                                            {
                                                Talespire.Log.Warning($"Properties[{propertyKey}] = \"{saveValue}\"!!!");

                                                // TODO: Use the correct EffectProperties instead of Properties (based on the prefix of the selected control).
                                                // TODO: Change this to be indexed by the property NAME, not the path (to support multiple linked properties (to a single SmartProperty).
                                                persistentEffect.Properties[propertyKey] = saveValue;                                                 // valueOverride.ToString();
                                                Talespire.Log.Debug($"Mini.SavePersistentEffect();");
                                                Mini.SavePersistentEffect(persistentEffect);
                                            }
                                            else
                                            {
                                                Talespire.Log.Error($"persistentEffect is not found!!");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //Talespire.Log.Warning($"Not a committed change! Not saving my friend!");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Talespire.Log.Error($"propertyChanger not found!!!");
                        }
                    }
                    else
                    {
                        Talespire.Log.Error($"childAtPoint is not a value editor!");
                    }
                }
                else
                {
                    Talespire.Log.Error($"frmPersistentEffectPropertyEditor is null!");
                }
            }
            else
            {
                Talespire.Log.Error($"effectProperty is NULL!!!");
            }
        }
Ejemplo n.º 2
0
        private void lstProperties_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                EffectProperty effectProperty = lstProperties.SelectedItem as EffectProperty;
                if (effectProperty != null)
                {
                    Talespire.Log.Warning($"{effectProperty.Name} selected!");
                    WindowHelper.FocusTaleSpire();
                }

                frmPersistentEffectPropertyEditor.Controls.Clear();

                UserControl valueEditor = ValueEditors.Get(STR_PersistentEffectsEditorKey, effectProperty.Type) as UserControl;
                if (valueEditor != null)
                {
                    // TODO: Set the control's state based on the actual value.
                    frmPersistentEffectPropertyEditor.Controls.Add(valueEditor);
                    frmPersistentEffectPropertyEditor.Height = valueEditor.Height + 8;

                    if (valueEditor is IScriptEditor scriptEditor)
                    {
                        //Talespire.Log.Warning($"Instance = \"{Instance}\"");
                        if (effectProperty.Paths.StartsWith("<") && effectProperty.Paths.EndsWith(">"))
                        {
                            // Could be a script!
                            //Talespire.Log.Debug($"Could be a script!");
                            Type scriptType = KnownScripts.GetType(effectProperty.Paths.Substring(1, effectProperty.Paths.Length - 2));
                            if (scriptType != null)
                            {
                                //Talespire.Log.Debug($"scriptType found {scriptType.FullName}");
                                UnityEngine.Component script = Instance.GetComponent(scriptType.FullName);
                                scriptEditor.InitializeInstance(script as MonoBehaviour);
                            }
                            else
                            {
                                //Talespire.Log.Debug($"{effectProperty.Paths} is not a Script!");
                            }
                        }
                    }

                    if (valueEditor is IValueEditor iValueEditor)
                    {
                        iValueEditor.EditingProperty(effectProperty.Name, effectProperty.Paths);
                        //Talespire.Log.Warning($"effectProperty.Paths = \"{effectProperty.Paths}\"");

                        PropertyModDetails propertyModDetails = BasePropertyChanger.GetPropertyModDetails(Instance, effectProperty.Paths);

                        //Talespire.Log.Warning($"iValueEditor.SetValue(\"{propertyModDetails.GetValue()}\");");
                        object newValue = propertyModDetails.GetValue();
                        if (newValue == null)
                        {
                            BasePropertyChanger propertyChanger = iValueEditor.GetPropertyChanger();
                            newValue = propertyChanger.TryGetValue(Instance, effectProperty.Paths);
                        }
                        iValueEditor.SetValue(newValue);
                    }
                    else
                    {
                        Talespire.Log.Error($"valueEditor is NOT an IValueEditor!!!");
                    }
                }
                else
                {
                    Talespire.Log.Error($"value editor NOT found!!!");
                }

                frmPersistentEffectPropertyEditor.Show();
            }
            catch (Exception ex)
            {
                Talespire.Log.Exception(ex, nameof(lstProperties_SelectedIndexChanged));
            }
        }