コード例 #1
0
        public override void LoadMemberControl(AutoTileBase obj, TableLayoutPanel control, string name, Type type, object[] attributes, object member, bool isWindow)
        {
            if (type == typeof(List <TileLayer>))
            {
                List <TileLayer> anims = (List <TileLayer>)member;
                DataEditor.LoadLabelControl(control, name);

                Dev.TilePreview preview = new Dev.TilePreview();
                preview.Size = new Size(GraphicsManager.TileSize, GraphicsManager.TileSize);
                preview.SetChosenAnim(anims.Count > 0 ? anims[0] : new TileLayer());
                preview.Tag = member;
                control.Controls.Add(preview);
                preview.TileClick += (object sender, EventArgs e) =>
                {
                    Dev.ElementForm frmData = new Dev.ElementForm();
                    frmData.Text = "Edit Tile";
                    Rectangle boxRect = new Rectangle(new Point(), frmData.Size);
                    DataEditor.StaticLoadMemberControl(frmData.ControlPanel, name, type, attributes, preview.Tag, true);

                    if (frmData.ShowDialog() == DialogResult.OK)
                    {
                        object element = preview.Tag;
                        DataEditor.StaticSaveMemberControl(frmData.ControlPanel, name, type, attributes, ref element, true);
                        List <TileLayer> new_anims = (List <TileLayer>)element;
                        preview.SetChosenAnim(new_anims.Count > 0 ? new_anims[0] : new TileLayer());
                        preview.Tag = element;
                    }
                };
            }
            else
            {
                base.LoadMemberControl(obj, control, name, type, attributes, member, isWindow);
            }
        }
コード例 #2
0
        private CollectionBoxViewModel createViewModel(StackPanel control, string parent, string name, Type type, object[] attributes, IList member, bool index1)
        {
            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IList <>), type, 0);

            CollectionBoxViewModel mv = new CollectionBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes)));

            mv.Index1 = index1;
            //add lambda expression for editing a single element
            mv.OnEditItem += (int index, object element, CollectionBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + index + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(1, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), element, true);

                frmData.SelectedOKEvent += () =>
                {
                    element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), true);
                    op(index, element);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            mv.LoadFromList(member);
            return(mv);
        }
コード例 #3
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IPriorityList member)
        {
            LoadLabelControl(control, name);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IPriorityList <>), type, 0);

            PriorityListBox          lbxValue = new PriorityListBox();
            PriorityListBoxViewModel mv       = new PriorityListBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(2, attributes)));

            lbxValue.DataContext = mv;

            //add lambda expression for editing a single element
            mv.OnEditItem = (Priority priority, int index, object element, PriorityListBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + priority.ToString() + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(2, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), element, true);

                frmData.SelectedOKEvent += () =>
                {
                    element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), true);
                    op(priority, index, element);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };
            mv.OnEditPriority = (Priority priority, int index, PriorityListBoxViewModel.EditPriorityOp op) =>
            {
                string       elementName = name + "<Priority>";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, priority, typeof(Priority), ReflectionExt.GetPassableAttributes(1, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, typeof(Priority), ReflectionExt.GetPassableAttributes(1, attributes), priority, true);

                frmData.SelectedOKEvent += () =>
                {
                    object priorityObj = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, typeof(Priority), ReflectionExt.GetPassableAttributes(1, attributes), true);
                    op(priority, index, (Priority)priorityObj);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            mv.LoadFromList(member);
            control.Children.Add(lbxValue);
        }
コード例 #4
0
ファイル: Editor.cs プロジェクト: RogueCollab/RogueEssence
        public static void LoadLabelControl(StackPanel control, string name)
        {
            TextBlock lblName = new TextBlock();

            lblName.Margin = new Thickness(0, 4, 0, 0);
            lblName.Text   = DataEditor.GetMemberTitle(name) + ":";
            control.Children.Add(lblName);
        }
コード例 #5
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, Boolean member)
        {
            CheckBox chkValue = new CheckBox();

            chkValue.Margin    = new Thickness(0, 4, 0, 0);
            chkValue.Content   = DataEditor.GetMemberTitle(name);
            chkValue.IsChecked = member;
            control.Children.Add(chkValue);
        }
コード例 #6
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, ISpawnRangeList member)
        {
            LoadLabelControl(control, name);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ISpawnRangeList <>), type, 0);

            RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes);

            SpawnRangeListBox lbxValue = new SpawnRangeListBox();

            lbxValue.MaxHeight = 260;
            SpawnRangeListBoxViewModel mv = new SpawnRangeListBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes)));

            if (rangeAtt != null)
            {
                mv.Index1    = rangeAtt.Index1;
                mv.Inclusive = rangeAtt.Inclusive;
            }
            lbxValue.DataContext = mv;


            //add lambda expression for editing a single element
            mv.OnEditItem += (int index, object element, SpawnRangeListBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + index + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(2, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), element, true);

                frmData.SelectedOKEvent += () =>
                {
                    element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), true);
                    op(index, element);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            mv.LoadFromList(member);
            control.Children.Add(lbxValue);
        }
コード例 #7
0
 public override void LoadMemberControl(ItemData obj, TableLayoutPanel control, string name, Type type, object[] attributes, object member, bool isWindow)
 {
     if (name == "Sprite")
     {
         DataEditor.LoadLabelControl(control, name);
         //for strings, use an edit textbox
         Dev.SpriteBrowser browser = new Dev.SpriteBrowser();
         browser.Size      = new Size(210, 256);
         browser.ChosenPic = (int)member;
         control.Controls.Add(browser);
     }
     else
     {
         base.LoadMemberControl(obj, control, name, type, attributes, member, isWindow);
     }
 }
コード例 #8
0
        public override void LoadClassControls(ISpawnList obj, TableLayoutPanel control)
        {
            SpawnListBox lbxValue = new SpawnListBox();

            lbxValue.Dock = DockStyle.Fill;
            lbxValue.Size = new Size(0, 200);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ISpawnList <>), obj.GetType(), 0);

            lbxValue.StringConv = DataEditor.GetStringRep(elementType, new object[0] {
            });
            //add lambda expression for editing a single element
            lbxValue.OnEditItem = (int index, object element, SpawnListBox.EditElementOp op) =>
            {
                ElementForm frmData = new ElementForm();
                if (element == null)
                {
                    frmData.Text = "New " + elementType.Name;
                }
                else
                {
                    frmData.Text = element.ToString();
                }

                DataEditor.StaticLoadMemberControl(frmData.ControlPanel, "(SpawnList) [" + index + "]", elementType, new object[0] {
                }, element, true);

                frmData.OnOK += (object okSender, EventArgs okE) =>
                {
                    DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "SpawnList", elementType, new object[0] {
                    }, ref element, true);

                    op(index, element);
                    frmData.Close();
                };
                frmData.OnCancel += (object okSender, EventArgs okE) =>
                {
                    frmData.Close();
                };

                frmData.Show();
            };

            lbxValue.LoadFromList(obj.GetType(), obj);
            control.Controls.Add(lbxValue);
        }
コード例 #9
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, T obj)
        {
            base.LoadWindowControls(control, parent, name, type, attributes, obj);

            Button btnTest = new Button();

            btnTest.Margin  = new Avalonia.Thickness(0, 4, 0, 0);
            btnTest.Content = "Test";
            btnTest.Click  += (object sender, RoutedEventArgs e) =>
            {
                lock (GameBase.lockObj)
                {
                    if (CheckTest())
                    {
                        T testObj = (T)DataEditor.SaveWindowControls(control, "", type, attributes);
                        RunTest(testObj);
                    }
                }
            };
            control.Children.Add(btnTest);
        }
コード例 #10
0
ファイル: Editor.cs プロジェクト: RogueCollab/RogueEssence
 public virtual object SaveMemberControl(T obj, StackPanel control, string name, Type type, object[] attributes, bool isWindow)
 {
     return(DataEditor.SaveClassControls(control, name, type, attributes, isWindow));
 }
コード例 #11
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IList member)
        {
            LoadLabelControl(control, name);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IList <>), member.GetType(), 0);

            CollectionBox lbxValue = new CollectionBox();

            lbxValue.MaxHeight = 180;
            CollectionBoxViewModel mv = new CollectionBoxViewModel(new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes)));

            lbxValue.DataContext = mv;

            //add lambda expression for editing a single element
            mv.OnEditItem += (int index, object element, CollectionBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + index + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(1, attributes));

                //TODO: make this a member and reference it that way
                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), element, true);

                frmData.SelectedOKEvent += async() =>
                {
                    object newElement = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), true);

                    bool itemExists = false;

                    List <object> states = (List <object>)mv.GetList(typeof(List <object>));
                    for (int ii = 0; ii < states.Count; ii++)
                    {
                        //ignore the current index being edited
                        //if the element is null, then we are editing a new object, so skip
                        if (ii != index || element == null)
                        {
                            if (states[ii].Equals(newElement))
                            {
                                itemExists = true;
                            }
                        }
                    }

                    if (itemExists)
                    {
                        await MessageBox.Show(control.GetOwningForm(), "Cannot add duplicate states.", "Entry already exists.", MessageBox.MessageBoxButtons.Ok);
                    }
                    else
                    {
                        op(index, newElement);
                        frmData.Close();
                    }
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            List <object> states = new List <object>();

            foreach (object state in member)
            {
                states.Add(state);
            }
            mv.LoadFromList(states);
            control.Children.Add(lbxValue);
        }
コード例 #12
0
        private void OpenList(DataManager.DataType dataType, GetEntry entryOp, CreateEntry createOp)
        {
            DataList choices = new DataList();

            choices.Text = dataType.ToString();
            string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true);
            choices.AddEntries(entries);
            choices.SelectedOKEvent = () => {
                if (choices.ChosenEntry > -1)
                {
                    ElementForm editor   = new ElementForm();
                    int         entryNum = choices.ChosenEntry;
                    editor.Text = entries[entryNum];
                    IEntryData data = entryOp(entryNum);
                    editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum;
                    DataEditor.LoadDataControls(data, editor.ControlPanel);

                    editor.OnOK += (object okSender, EventArgs okE) => {
                        object obj = data;
                        DataEditor.SaveDataControls(ref obj, editor.ControlPanel);
                        data = (IEntryData)obj;
                        DataManager.SaveData(entryNum, dataType.ToString(), data);
                        DataManager.Instance.ClearCache(dataType);
                        IEntryData   entryData    = ((IEntryData)data);
                        EntrySummary entrySummary = entryData.GenerateEntrySummary();
                        DataManager.Instance.DataIndices[dataType].Entries[entryNum] = entrySummary;
                        DataManager.Instance.SaveIndex(dataType);
                        choices.ModifyEntry(entryNum, entrySummary.GetLocalString(true));
                        editor.Close();
                    };
                    editor.OnCancel += (object okSender, EventArgs okE) => {
                        editor.Close();
                    };

                    editor.Show();
                }
            };
            choices.SelectedAddEvent = () => {
                ElementForm editor   = new ElementForm();
                int         entryNum = DataManager.Instance.DataIndices[dataType].Entries.Count;
                editor.Text = "New " + dataType.ToString();
                IEntryData data = createOp();
                editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum;
                DataEditor.LoadDataControls(data, editor.ControlPanel);

                editor.OnOK += (object okSender, EventArgs okE) => {
                    object obj = data;
                    DataEditor.SaveDataControls(ref obj, editor.ControlPanel);
                    data = (IEntryData)obj;
                    DataManager.SaveData(entryNum, dataType.ToString(), data);
                    DataManager.Instance.ClearCache(dataType);
                    IEntryData   entryData    = ((IEntryData)data);
                    EntrySummary entrySummary = entryData.GenerateEntrySummary();
                    DataManager.Instance.DataIndices[dataType].Entries.Add(entrySummary);
                    DataManager.Instance.SaveIndex(dataType);
                    entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true);
                    choices.AddEntry(entrySummary.GetLocalString(true));
                    editor.Close();
                };
                editor.OnCancel += (object okSender, EventArgs okE) => {
                    editor.Close();
                };

                editor.Show();
            };
            choices.Show();
        }
コード例 #13
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IDictionary member)
        {
            LoadLabelControl(control, name);

            Type keyType     = ReflectionExt.GetBaseTypeArg(typeof(IDictionary <,>), type, 0);
            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IDictionary <,>), type, 1);

            DictionaryBox lbxValue = new DictionaryBox();

            lbxValue.MaxHeight = 180;
            DictionaryBoxViewModel mv = new DictionaryBoxViewModel(control.GetOwningForm(), new StringConv(elementType, ReflectionExt.GetPassableAttributes(2, attributes)));

            lbxValue.DataContext = mv;

            //add lambda expression for editing a single element
            mv.OnEditItem += (object key, object element, DictionaryBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + key.ToString() + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(2, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), element, true);

                frmData.SelectedOKEvent += () =>
                {
                    element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(2, attributes), true);
                    op(key, element);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            mv.OnEditKey += (object key, object element, DictionaryBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "<Key>";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, key, keyType, ReflectionExt.GetPassableAttributes(1, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, keyType, ReflectionExt.GetPassableAttributes(1, attributes), key, true);

                frmData.SelectedOKEvent += () =>
                {
                    key = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, keyType, ReflectionExt.GetPassableAttributes(1, attributes), true);
                    op(key, element);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            mv.LoadFromDict(member);
            control.Children.Add(lbxValue);
        }
コード例 #14
0
ファイル: Editor.cs プロジェクト: RogueCollab/RogueEssence
        void IEditor.LoadClassControls(StackPanel control, string parent, string name, Type type, object[] attributes, object member, bool isWindow)
        {
            //if you want a class that is by default isolated to a classbox but has a custom UI when opened on its own/overridden to render,
            //override LoadWindowControls, which is called by those methods.

            //in all cases where the class itself isn't being rendered to the window, simply represent as an editable object

            //isWindow will force subgroup automatically
            //otherwise, the presence of a Subgroup attribute will force it (or the presence of a Separation attribute will force it into its own classbox)
            //then defaultSubgroup will force it.

            bool subGroup = DefaultSubgroup;

            if (ReflectionExt.FindAttribute <SepGroupAttribute>(attributes) != null)
            {
                subGroup = false;
            }
            if (ReflectionExt.FindAttribute <SubGroupAttribute>(attributes) != null)
            {
                subGroup = true;
            }
            if (isWindow)
            {
                subGroup = true;
            }

            if (!subGroup)
            {
                LoadLabelControl(control, name);
                if (member == null)
                {
                    Type[] children;
                    if (DefaultType)
                    {
                        children = new Type[1] {
                            type
                        }
                    }
                    ;
                    else
                    {
                        children = type.GetAssignableTypes();
                    }
                    //create an empty instance
                    member = ReflectionExt.CreateMinimalInstance(children[0]);
                }

                ClassBox           cbxValue  = new ClassBox();
                MultilineAttribute attribute = ReflectionExt.FindAttribute <MultilineAttribute>(attributes);
                if (attribute != null)
                {
                    //txtValue.Multiline = true;
                    cbxValue.Height = 80;
                    //txtValue.Size = new Size(0, 80);
                }
                //else
                //    txtValue.Size = new Size(0, 20);
                ClassBoxViewModel mv = new ClassBoxViewModel(new StringConv(type, ReflectionExt.GetPassableAttributes(0, attributes)));
                mv.LoadFromSource(member);
                cbxValue.DataContext = mv;
                control.Children.Add(cbxValue);

                //add lambda expression for editing a single element
                mv.OnEditItem += (object element, ClassBoxViewModel.EditElementOp op) =>
                {
                    DataEditForm frmData = new DataEditForm();
                    frmData.Title = DataEditor.GetWindowTitle(parent, name, element, type, ReflectionExt.GetPassableAttributes(0, attributes));

                    DataEditor.LoadClassControls(frmData.ControlPanel, parent, name, type, ReflectionExt.GetPassableAttributes(0, attributes), element, true);

                    frmData.SelectedOKEvent += () =>
                    {
                        element = DataEditor.SaveClassControls(frmData.ControlPanel, name, type, ReflectionExt.GetPassableAttributes(0, attributes), true);
                        op(element);
                        frmData.Close();
                    };
                    frmData.SelectedCancelEvent += () =>
                    {
                        frmData.Close();
                    };

                    control.GetOwningForm().RegisterChild(frmData);
                    frmData.Show();
                };

                {
                    ContextMenu copyPasteStrip = new ContextMenu();

                    MenuItem copyToolStripMenuItem  = new MenuItem();
                    MenuItem pasteToolStripMenuItem = new MenuItem();

                    Avalonia.Collections.AvaloniaList <object> list = (Avalonia.Collections.AvaloniaList <object>)copyPasteStrip.Items;
                    list.AddRange(new MenuItem[] {
                        copyToolStripMenuItem,
                        pasteToolStripMenuItem
                    });

                    copyToolStripMenuItem.Header  = "Copy " + type.Name;
                    pasteToolStripMenuItem.Header = "Paste " + type.Name;

                    copyToolStripMenuItem.Click += (object copySender, RoutedEventArgs copyE) =>
                    {
                        DataEditor.SetClipboardObj(mv.Object);
                    };
                    pasteToolStripMenuItem.Click += async(object copySender, RoutedEventArgs copyE) =>
                    {
                        Type type1 = DataEditor.clipboardObj.GetType();
                        Type type2 = type;
                        if (type2.IsAssignableFrom(type1))
                        {
                            mv.LoadFromSource(DataEditor.clipboardObj);
                        }
                        else
                        {
                            await MessageBox.Show(control.GetOwningForm(), String.Format("Incompatible types:\n{0}\n{1}", type1.AssemblyQualifiedName, type2.AssemblyQualifiedName), "Invalid Operation", MessageBox.MessageBoxButtons.Ok);
                        }
                    };

                    control.ContextMenu = copyPasteStrip;
                }
            }
            else
            {
                //when being drawn as a subgroup, we have 2 options:
                //(A) include a label and border, OR
                //(B) add controls directly to the current stackpanel?

                //additionally, there will be complications when the Type for a member has child classes
                //in this case, (A) choosing to have a label and border will result in label over the type dropdown, and border in the chosen class
                //(B) choosing not to have a label and border will remove the label, but still have a dropdown and contain it a child stackpanel, without border or margin

                //when isWindow is true, we never want option A. No label, no border, no margin
                //when isWindow is false, (which means either subgroup or defaultsubgroup is active) it's up to the editor itself to decide

                bool includeDecoration = DefaultDecoration;
                if (isWindow)
                {
                    includeDecoration = false;
                }


                //if it's a class of its own, create a new panel
                //then pass it into the call
                //use the returned "ref" int to determine how big the panel should be
                //continue from there
                Type[] children;
                if (DefaultType)
                {
                    children = new Type[1] {
                        type
                    }
                }
                ;
                else
                {
                    children = type.GetAssignableTypes();
                }

                //handle null members by getting an instance of the FIRST instantiatable subclass (including itself) it can find
                if (member == null)
                {
                    member = ReflectionExt.CreateMinimalInstance(children[0]);
                }

                if (children.Length < 1)
                {
                    throw new Exception("Completely abstract field found for: " + name);
                }
                else if (children.Length == 1)
                {
                    Type memberType = member.GetType();
                    if (children[0] != memberType)
                    {
                        throw new TargetException("Types do not match.");
                    }

                    StackPanel controlParent = control;
                    if (includeDecoration)
                    {
                        LoadLabelControl(control, name);

                        Border border = new Border();
                        border.BorderThickness = new Thickness(1);
                        border.BorderBrush     = Avalonia.Media.Brushes.LightGray;
                        border.Margin          = new Thickness(2);
                        control.Children.Add(border);

                        StackPanel groupBoxPanel = new StackPanel();
                        groupBoxPanel.Margin = new Thickness(2);
                        border.Child         = groupBoxPanel;

                        controlParent = groupBoxPanel;
                    }

                    {
                        ContextMenu copyPasteStrip = new ContextMenu();

                        MenuItem copyToolStripMenuItem  = new MenuItem();
                        MenuItem pasteToolStripMenuItem = new MenuItem();

                        Avalonia.Collections.AvaloniaList <object> list = (Avalonia.Collections.AvaloniaList <object>)copyPasteStrip.Items;
                        list.AddRange(new MenuItem[] {
                            copyToolStripMenuItem,
                            pasteToolStripMenuItem
                        });

                        copyToolStripMenuItem.Header  = "Copy " + type.Name;
                        pasteToolStripMenuItem.Header = "Paste " + type.Name;

                        copyToolStripMenuItem.Click += (object copySender, RoutedEventArgs copyE) =>
                        {
                            object obj = DataEditor.SaveWindowControls(controlParent, name, children[0], attributes);
                            DataEditor.SetClipboardObj(obj);
                        };
                        pasteToolStripMenuItem.Click += async(object copySender, RoutedEventArgs copyE) =>
                        {
                            Type type1 = DataEditor.clipboardObj.GetType();
                            Type type2 = type;
                            if (type2.IsAssignableFrom(type1))
                            {
                                controlParent.Children.Clear();
                                DataEditor.LoadWindowControls(controlParent, parent, name, type1, attributes, DataEditor.clipboardObj);
                            }
                            else
                            {
                                await MessageBox.Show(control.GetOwningForm(), String.Format("Incompatible types:\n{0}\n{1}", type1.AssemblyQualifiedName, type2.AssemblyQualifiedName), "Invalid Operation", MessageBox.MessageBoxButtons.Ok);
                            }
                        };

                        control.ContextMenu = copyPasteStrip;
                    }
                    controlParent.Background = Avalonia.Media.Brushes.Transparent;
                    DataEditor.LoadWindowControls(controlParent, parent, name, children[0], attributes, member);
                }
                else
                {
                    //note: considerations must be made when dealing with inheritance/polymorphism
                    //eg: find all children in this assembly that can be instantiated,
                    //add them to different panels
                    //show the one that is active right now
                    //include a combobox for switching children

                    StackPanel controlParent = null;
                    if (includeDecoration)
                    {
                        LoadLabelControl(control, name);
                    }

                    Grid sharedRowPanel = getSharedRowPanel(2);

                    TextBlock lblType = new TextBlock();
                    lblType.Text = "Type:";
                    lblType.VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center;
                    sharedRowPanel.Children.Add(lblType);
                    sharedRowPanel.ColumnDefinitions[0].Width = new GridLength(30);
                    lblType.SetValue(Grid.ColumnProperty, 0);

                    ComboBox cbValue = new ComboBox();
                    cbValue.Margin             = new Thickness(4, 0, 0, 0);
                    cbValue.VirtualizationMode = ItemVirtualizationMode.Simple;
                    sharedRowPanel.Children.Add(cbValue);
                    cbValue.SetValue(Grid.ColumnProperty, 1);

                    control.Children.Add(sharedRowPanel);


                    if (includeDecoration)
                    {
                        Border border = new Border();
                        border.BorderThickness = new Thickness(1);
                        border.BorderBrush     = Avalonia.Media.Brushes.LightGray;
                        border.Margin          = new Thickness(2);
                        control.Children.Add(border);

                        StackPanel groupBoxPanel = new StackPanel();
                        groupBoxPanel.Margin = new Thickness(2);
                        border.Child         = groupBoxPanel;

                        controlParent = groupBoxPanel;
                    }
                    else
                    {
                        StackPanel groupBoxPanel = new StackPanel();
                        control.Children.Add(groupBoxPanel);
                        controlParent = groupBoxPanel;
                    }



                    List <CreateMethod> createMethods = new List <CreateMethod>();

                    bool          refreshPanel = true;
                    List <string> items        = new List <string>();
                    int           selection    = -1;
                    for (int ii = 0; ii < children.Length; ii++)
                    {
                        Type childType = children[ii];
                        items.Add(childType.GetDisplayName());

                        createMethods.Add(() =>
                        {
                            if (refreshPanel)
                            {
                                controlParent.Children.Clear();
                                object emptyMember = ReflectionExt.CreateMinimalInstance(childType);
                                DataEditor.LoadWindowControls(controlParent, parent, name, childType, attributes, emptyMember);//TODO: POTENTIAL INFINITE RECURSION?
                            }
                        });
                        if (childType == member.GetType())
                        {
                            selection = ii;
                        }
                    }
                    if (selection == -1)
                    {
                        throw new TargetException("Types do not match.");
                    }

                    var subject = new Subject <List <string> >();
                    cbValue.Bind(ComboBox.ItemsProperty, subject);
                    subject.OnNext(items);
                    cbValue.SelectedIndex = selection;

                    cbValue.SelectionChanged += (object sender, SelectionChangedEventArgs e) =>
                    {
                        createMethods[cbValue.SelectedIndex]();
                    };

                    {
                        ContextMenu copyPasteStrip = new ContextMenu();

                        MenuItem copyToolStripMenuItem  = new MenuItem();
                        MenuItem pasteToolStripMenuItem = new MenuItem();

                        Avalonia.Collections.AvaloniaList <object> list = (Avalonia.Collections.AvaloniaList <object>)copyPasteStrip.Items;
                        list.AddRange(new MenuItem[] {
                            copyToolStripMenuItem,
                            pasteToolStripMenuItem
                        });

                        copyToolStripMenuItem.Header  = "Copy " + type.Name;
                        pasteToolStripMenuItem.Header = "Paste " + type.Name;

                        copyToolStripMenuItem.Click += (object copySender, RoutedEventArgs copyE) =>
                        {
                            object obj = DataEditor.SaveWindowControls(controlParent, name, children[cbValue.SelectedIndex], attributes);
                            DataEditor.SetClipboardObj(obj);
                        };
                        pasteToolStripMenuItem.Click += async(object copySender, RoutedEventArgs copyE) =>
                        {
                            Type type1    = DataEditor.clipboardObj.GetType();
                            Type type2    = type;
                            int  type_idx = -1;
                            for (int ii = 0; ii < children.Length; ii++)
                            {
                                if (children[ii] == type1)
                                {
                                    type_idx = ii;
                                    break;
                                }
                            }
                            if (type_idx > -1)
                            {
                                refreshPanel          = false;
                                cbValue.SelectedIndex = type_idx;
                                refreshPanel          = true;

                                controlParent.Children.Clear();
                                DataEditor.LoadWindowControls(controlParent, parent, name, type1, attributes, DataEditor.clipboardObj);
                            }
                            else
                            {
                                await MessageBox.Show(control.GetOwningForm(), String.Format("Incompatible types:\n{0}\n{1}", type1.AssemblyQualifiedName, type2.AssemblyQualifiedName), "Invalid Operation", MessageBox.MessageBoxButtons.Ok);
                            }
                        };

                        control.ContextMenu = copyPasteStrip;
                    }
                    controlParent.Background = Avalonia.Media.Brushes.Transparent;
                    DataEditor.LoadWindowControls(controlParent, parent, name, children[selection], attributes, member);
                }
            }
        }
コード例 #15
0
 public virtual void SaveClassControls(T obj, TableLayoutPanel control)
 {
     DataEditor.StaticSaveClassControls(obj, control);
 }
コード例 #16
0
 public virtual void SaveMemberControl(T obj, TableLayoutPanel control, string name, Type type, object[] attributes, ref object member, bool isWindow)
 {
     DataEditor.StaticSaveMemberControl(control, name, type, attributes, ref member, isWindow);
 }
コード例 #17
0
ファイル: Editor.cs プロジェクト: RogueCollab/RogueEssence
        public virtual T SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            try
            {
                //create instance of type here; object always starts null?
                T obj = (T)ReflectionExt.CreateMinimalInstance(type);

                List <MemberInfo> myFields = type.GetEditableMembers();

                List <List <MemberInfo> > tieredFields = new List <List <MemberInfo> >();
                for (int ii = 0; ii < myFields.Count; ii++)
                {
                    if (myFields[ii].GetCustomAttributes(typeof(NonEditedAttribute), false).Length > 0)
                    {
                        continue;
                    }
                    if (myFields[ii].GetCustomAttributes(typeof(NonSerializedAttribute), false).Length > 0)
                    {
                        continue;
                    }

                    object member = myFields[ii].GetValue(obj);
                    if (member == null && myFields[ii].GetCustomAttributes(typeof(NonNullAttribute), false).Length > 0)
                    {
                        throw new Exception("Null class member found in " + type.ToString() + ": " + myFields[ii].Name);
                    }

                    if (myFields[ii].GetCustomAttributes(typeof(SharedRowAttribute), false).Length == 0)
                    {
                        tieredFields.Add(new List <MemberInfo>());
                    }

                    tieredFields[tieredFields.Count - 1].Add(myFields[ii]);
                }

                int controlIndex = 0;
                for (int ii = 0; ii < tieredFields.Count; ii++)
                {
                    if (tieredFields[ii].Count == 1)
                    {
                        MemberInfo myInfo = tieredFields[ii][0];
                        object     member = DataEditor.SaveMemberControl(obj, (StackPanel)control.Children[controlIndex], myInfo.Name, myInfo.GetMemberInfoType(), myInfo.GetCustomAttributes(false), false);
                        myInfo.SetValue(obj, member);
                        controlIndex++;
                    }
                    else
                    {
                        Grid sharedRowControl      = (Grid)control.Children[controlIndex];
                        int  sharedRowControlIndex = 0;
                        for (int jj = 0; jj < tieredFields[ii].Count; jj++)
                        {
                            MemberInfo myInfo = tieredFields[ii][jj];
                            object     member = DataEditor.SaveMemberControl(obj, (StackPanel)sharedRowControl.Children[jj], myInfo.Name, myInfo.GetMemberInfoType(), myInfo.GetCustomAttributes(false), false);
                            myInfo.SetValue(obj, member);
                            sharedRowControlIndex++;
                        }
                        controlIndex++;
                    }
                }
                return(obj);
            }
            catch (Exception e)
            {
                DiagManager.Instance.LogError(e);
                return(default(T));
            }
        }
コード例 #18
0
 public string GetString(object obj)
 {
     return(DataEditor.GetString(obj, ObjectType, Attributes));
 }
コード例 #19
0
        public override void LoadClassControls(ITypeDict obj, TableLayoutPanel control)
        {
            CollectionBox lbxValue = new CollectionBox();

            lbxValue.Dock = DockStyle.Fill;
            lbxValue.Size = new Size(0, 150);

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ITypeDict <>), obj.GetType(), 0);

            lbxValue.StringConv = DataEditor.GetStringRep(elementType, new object[0] {
            });
            //add lambda expression for editing a single element
            lbxValue.OnEditItem = (int index, object element, CollectionBox.EditElementOp op) =>
            {
                ElementForm frmData = new ElementForm();
                if (element == null)
                {
                    frmData.Text = "New " + elementType.Name;
                }
                else
                {
                    frmData.Text = element.ToString();
                }

                DataEditor.StaticLoadMemberControl(frmData.ControlPanel, "(StateCollection) [" + index + "]", elementType, new object[0] {
                }, element, true);

                frmData.OnOK += (object okSender, EventArgs okE) =>
                {
                    DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "StateCollection", elementType, new object[0] {
                    }, ref element, true);

                    bool itemExists = false;
                    for (int ii = 0; ii < lbxValue.Collection.Count; ii++)
                    {
                        if (ii != index)
                        {
                            if (lbxValue.Collection[ii].GetType() == element.GetType())
                            {
                                itemExists = true;
                            }
                        }
                    }

                    if (itemExists)
                    {
                        MessageBox.Show("Cannot add duplicate states.", "Entry already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        op(index, element);
                        frmData.Close();
                    }
                };
                frmData.OnCancel += (object okSender, EventArgs okE) =>
                {
                    frmData.Close();
                };

                frmData.Show();
            };

            List <object> states = new List <object>();

            foreach (object state in obj)
            {
                states.Add(state);
            }
            lbxValue.LoadFromList(typeof(List <object>), states);
            control.Controls.Add(lbxValue);
        }
コード例 #20
0
ファイル: Editor.cs プロジェクト: RogueCollab/RogueEssence
        public virtual void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, T obj)
        {
            //go through all members and add for them
            //control starts off clean; this is the control that will have all member controls on it
            try
            {
                List <MemberInfo> myFields = type.GetEditableMembers();

                List <List <MemberInfo> > tieredFields = new List <List <MemberInfo> >();
                for (int ii = 0; ii < myFields.Count; ii++)
                {
                    if (myFields[ii].GetCustomAttributes(typeof(NonEditedAttribute), false).Length > 0)
                    {
                        continue;
                    }
                    if (myFields[ii].GetCustomAttributes(typeof(NonSerializedAttribute), false).Length > 0)
                    {
                        continue;
                    }

                    object member = myFields[ii].GetValue(obj);
                    if (member == null && myFields[ii].GetCustomAttributes(typeof(NonNullAttribute), false).Length > 0)
                    {
                        throw new Exception("Null class member found in " + type.ToString() + ": " + myFields[ii].Name);
                    }

                    if (myFields[ii].GetCustomAttributes(typeof(SharedRowAttribute), false).Length == 0)
                    {
                        tieredFields.Add(new List <MemberInfo>());
                    }
                    tieredFields[tieredFields.Count - 1].Add(myFields[ii]);
                }

                for (int ii = 0; ii < tieredFields.Count; ii++)
                {
                    if (tieredFields[ii].Count == 1)
                    {
                        MemberInfo myInfo = tieredFields[ii][0];
                        StackPanel stack  = new StackPanel();
                        control.Children.Add(stack);
                        DataEditor.LoadMemberControl(name, obj, stack, myInfo.Name, myInfo.GetMemberInfoType(), myInfo.GetCustomAttributes(false), myInfo.GetValue(obj), false);
                    }
                    else
                    {
                        Grid sharedRowPanel = getSharedRowPanel(tieredFields[ii].Count);
                        control.Children.Add(sharedRowPanel);
                        for (int jj = 0; jj < tieredFields[ii].Count; jj++)
                        {
                            MemberInfo myInfo = tieredFields[ii][jj];
                            StackPanel stack  = new StackPanel();
                            sharedRowPanel.Children.Add(stack);
                            stack.SetValue(Grid.ColumnProperty, jj);
                            DataEditor.LoadMemberControl(name, obj, stack, myInfo.Name, myInfo.GetMemberInfoType(), myInfo.GetCustomAttributes(false), myInfo.GetValue(obj), false);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DiagManager.Instance.LogError(e);
            }
        }
コード例 #21
0
ファイル: Editor.cs プロジェクト: RogueCollab/RogueEssence
        object IEditor.SaveClassControls(StackPanel control, string name, Type type, object[] attributes, bool isWindow)
        {
            int controlIndex = 0;

            bool subGroup = DefaultSubgroup;

            if (ReflectionExt.FindAttribute <SepGroupAttribute>(attributes) != null)
            {
                subGroup = false;
            }
            if (ReflectionExt.FindAttribute <SubGroupAttribute>(attributes) != null)
            {
                subGroup = true;
            }
            if (isWindow)
            {
                subGroup = true;
            }

            if (!subGroup)
            {
                controlIndex++;
                ClassBox          cbxValue = (ClassBox)control.Children[controlIndex];
                ClassBoxViewModel mv       = (ClassBoxViewModel)cbxValue.DataContext;
                return(mv.Object);
            }
            else
            {
                Type[] children;
                if (DefaultType)
                {
                    children = new Type[1] {
                        type
                    }
                }
                ;
                else
                {
                    children = type.GetAssignableTypes();
                }

                //need to create a new instance
                //note: considerations must be made when dealing with inheritance/polymorphism
                //eg: check to see if there are children of the type,
                //and if so, do this instead:
                //get the combobox index determining the type
                //instantiate the type
                //get the panel for the index
                //save using THAT panel

                bool includeDecoration = DefaultDecoration;
                if (isWindow)
                {
                    includeDecoration = false;
                }


                if (children.Length == 1)
                {
                    StackPanel chosenParent = control;
                    if (includeDecoration)
                    {
                        controlIndex++;

                        Border border = (Border)control.Children[controlIndex];
                        chosenParent = (StackPanel)border.Child;
                    }
                    return(DataEditor.SaveWindowControls(chosenParent, name, children[0], attributes));
                }
                else
                {
                    StackPanel chosenParent = null;
                    if (includeDecoration)
                    {
                        controlIndex++;
                    }

                    Grid     subGrid = (Grid)control.Children[controlIndex];
                    ComboBox cbValue = (ComboBox)subGrid.Children[1];

                    controlIndex++;

                    if (includeDecoration)
                    {
                        Border border = (Border)control.Children[controlIndex];
                        chosenParent = (StackPanel)border.Child;
                    }
                    else
                    {
                        chosenParent = (StackPanel)control.Children[controlIndex];
                    }

                    return(DataEditor.SaveWindowControls(chosenParent, name, children[cbValue.SelectedIndex], attributes));
                }
            }
        }
コード例 #22
0
        public override void LoadWindowControls(StackPanel control, string parent, string name, Type type, object[] attributes, IRangeDict member)
        {
            LoadLabelControl(control, name);

            Type keyType     = typeof(IntRange);
            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(IRangeDict <>), type, 0);

            RangeBorderAttribute rangeAtt = ReflectionExt.FindAttribute <RangeBorderAttribute>(attributes);

            RangeDictBox lbxValue = new RangeDictBox();

            lbxValue.MaxHeight = 180;
            RangeDictBoxViewModel mv = new RangeDictBoxViewModel(control.GetOwningForm(), new StringConv(elementType, ReflectionExt.GetPassableAttributes(1, attributes)));

            if (rangeAtt != null)
            {
                mv.Index1    = rangeAtt.Index1;
                mv.Inclusive = rangeAtt.Inclusive;
            }
            lbxValue.DataContext = mv;

            //add lambda expression for editing a single element
            mv.OnEditItem += (IntRange key, object element, RangeDictBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "[" + key.ToString() + "]";
                DataEditForm frmData     = new DataEditForm();
                frmData.Title = DataEditor.GetWindowTitle(parent, elementName, element, elementType, ReflectionExt.GetPassableAttributes(1, attributes));

                DataEditor.LoadClassControls(frmData.ControlPanel, parent, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), element, true);

                frmData.SelectedOKEvent += () =>
                {
                    element = DataEditor.SaveClassControls(frmData.ControlPanel, elementName, elementType, ReflectionExt.GetPassableAttributes(1, attributes), true);
                    op(key, element);
                    frmData.Close();
                };
                frmData.SelectedCancelEvent += () =>
                {
                    frmData.Close();
                };

                control.GetOwningForm().RegisterChild(frmData);
                frmData.Show();
            };

            mv.OnEditKey += (IntRange key, object element, RangeDictBoxViewModel.EditElementOp op) =>
            {
                string       elementName = name + "<Range>";
                DataEditForm frmKey      = new DataEditForm();

                List <object> attrList = new List <object>();
                if (rangeAtt != null)
                {
                    attrList.Add(rangeAtt);
                }
                frmKey.Title = DataEditor.GetWindowTitle(parent, elementName, key, keyType, attrList.ToArray());

                DataEditor.LoadClassControls(frmKey.ControlPanel, parent, elementName, keyType, attrList.ToArray(), key, true);

                frmKey.SelectedOKEvent += () =>
                {
                    key = (IntRange)DataEditor.SaveClassControls(frmKey.ControlPanel, elementName, keyType, attrList.ToArray(), true);
                    op(key, element);
                    frmKey.Close();
                };
                frmKey.SelectedCancelEvent += () =>
                {
                    frmKey.Close();
                };

                control.GetOwningForm().RegisterChild(frmKey);
                frmKey.Show();
            };

            mv.LoadFromDict(member);
            control.Children.Add(lbxValue);
        }
コード例 #23
0
ファイル: Editor.cs プロジェクト: RogueCollab/RogueEssence
 //TODO: add the ability to tag- using attributes- a specific member with a specific editor
 public virtual void LoadMemberControl(string parent, T obj, StackPanel control, string name, Type type, object[] attributes, object member, bool isWindow)
 {
     DataEditor.LoadClassControls(control, parent, name, type, attributes, member, isWindow);
 }