Пример #1
0
        public override void SaveClassControls(ISpawnRangeList obj, TableLayoutPanel control)
        {
            SpawnRangeListBox lbxValue = (SpawnRangeListBox)control.Controls[0];

            for (int ii = 0; ii < lbxValue.Collection.Count; ii++)
            {
                obj.Add(lbxValue.Collection.GetSpawn(ii), lbxValue.Collection.GetSpawnRange(ii), lbxValue.Collection.GetSpawnRate(ii));
            }
        }
Пример #2
0
        public override ISpawnRangeList SaveWindowControls(StackPanel control, string name, Type type, object[] attributes)
        {
            int controlIndex = 0;

            controlIndex++;
            SpawnRangeListBox          lbxValue = (SpawnRangeListBox)control.Children[controlIndex];
            SpawnRangeListBoxViewModel mv       = (SpawnRangeListBoxViewModel)lbxValue.DataContext;

            return(mv.GetList(type));
        }
Пример #3
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);
        }
Пример #4
0
        public override void LoadClassControls(ISpawnRangeList obj, TableLayoutPanel control)
        {
            SpawnRangeListBox lbxValue = new SpawnRangeListBox();

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

            Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ISpawnRangeList <>), 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, SpawnRangeListBox.EditElementOp op) =>
            {
                ElementForm frmData = new ElementForm();
                if (element == null)
                {
                    frmData.Text = "New " + elementType.Name;
                }
                else
                {
                    frmData.Text = element.ToString();
                }

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

                frmData.OnOK += (object okSender, EventArgs okE) =>
                {
                    DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "SpawnRangeList", 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);
        }