Пример #1
0
 public void PrepForClose()
 {
     windowDragTimer.Stop();
     windowDragTimer.Elapsed   -= WindowDragTimer_Elapsed;
     windowDragTimer            = null;
     ValueEditors.ValueChanged -= ValueEditors_ValueChanged;
     ValueEditors.Clean(STR_PersistentEffectsEditorKey);
     frmPersistentEffectPropertyEditor?.Close();
     frmPersistentEffectPropertyEditor = null;
 }
Пример #2
0
        public FrmPropertyList()
        {
            InitializeComponent();
            windowDragTimer          = new System.Timers.Timer();
            windowDragTimer.Interval = 20;
            windowDragTimer.Elapsed += WindowDragTimer_Elapsed;

            ValueEditors.Register(STR_PersistentEffectsEditorKey);
            foreach (IValueEditor valueEditor in ValueEditors.GetAll(STR_PersistentEffectsEditorKey))
            {
                //Talespire.Log.Debug($"valueEditor ({valueEditor.GetType().Name}).Initialize(this);");
                valueEditor.Initialize(this);
            }

            if (frmPersistentEffectPropertyEditor == null)
            {
                //Talespire.Log.Debug($"frmPersistentEffectPropertyEditor = new FrmPersistentEffectPropertyEditor();");
                frmPersistentEffectPropertyEditor = new FrmPersistentEffectPropertyEditor();
            }

            //Talespire.Log.Debug($"ValueEditors.ValueChanged += ValueEditors_ValueChanged;");
            ValueEditors.ValueChanged += ValueEditors_ValueChanged;
        }
Пример #3
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));
            }
        }