コード例 #1
0
        void IEditingOptionsModule.OptionsMenuOpening(ILevelObj clickedObj)
        {
            addMoveKeyMenu.Visible         = clickedObj != null && clickedObj.Prop[LevelObj.N_UnitConfig][LevelObj.N_UnitConfigBaseClass] == "KeyMoveMapParts" && !clickedObj.Prop[LevelObj.N_Links].ContainsKey("KeyMoveNext");
            removeMoveKeyMenu.Visible      = clickedObj != null && clickedObj.Prop[LevelObj.N_UnitConfig][LevelObj.N_UnitConfigBaseClass] == "KeyMoveMapParts" && clickedObj.Prop[LevelObj.N_Links].ContainsKey("KeyMoveNext");
            resetControlPointsMenu.Visible = clickedObj != null && clickedObj is RailPoint;
            if (clickedObj != null)
            {
                selectedLinksNode = clickedObj[LevelObj.N_Links] as LinksNode;
                if (selectedLinksNode.Count == 0)
                {
                    LinksMenu.Visible = false;
                    return;
                }
                LinksMenu.Visible = true;
                LinksMenu.DropDownItems.Clear();

                foreach (string k in selectedLinksNode.Keys)
                {
                    var item = LinksMenu.DropDownItems.Add(k);
                    item.Text   = k;
                    item.Click +=
                        delegate(object sender, EventArgs e) { ViewForm.EditList(selectedLinksNode[(sender as ToolStripItem).Text]); };
                }
            }
        }
コード例 #2
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            LinksNode node = value as LinksNode;

            /*context should be of type System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry
             * OwnerGrid is not a public property, we get it through reflection
             * A reference to the parent form is needed to add the ObjList to the ListEditingStack*/
            Type t = context.GetType();

            if (!(t.GetProperty("OwnerGrid").GetValue(context, null) is PropertyGrid targetGrid))
            {
                throw new Exception("context is not of the expected type");
            }
            if (!(targetGrid.ParentForm is IEditorFormContext TargetForm))
            {
                throw new Exception("context is not of the expected type");
            }
            if (node != null)
            {
                using (var form = new EditorFroms.LinksEditor(node, TargetForm))
                {
                    form.ShowDialog();
                }
            }
            return(node);
        }
コード例 #3
0
 public LevelObj(Dictionary <string, dynamic> bymlNode)
 {
     Prop = bymlNode;
     if (Prop.ContainsKey(N_Links) && !(Prop[N_Links] is LinksNode))
     {
         Prop[N_Links] = new LinksNode(Prop[N_Links]);
     }
 }
コード例 #4
0
        private void AddViewBtn_Click(object sender, EventArgs e)
        {
            if (ViewForm.SelectedObjs.Length == 0)
            {
                MessageBox.Show("Select at least an object to use this function");
                return;
            }
            var res = MessageBox.Show(
                "This will add a ViewGroup to all the selected objects. The children list will be LINKED among all the objects, this means that when editing the GroupView for one object it will automatically change for all the objects you selected when creating it.\r\n" +
                "This only works for the current session (aka if you save and then reload the level the linked editing will be lost).\r\n" +
                "This action cannot be undone, do you want to continue ?", "", MessageBoxButtons.YesNo);

            if (res != DialogResult.Yes)
            {
                return;
            }
            var list = new List <dynamic>();
            var obj  = OdysseyModule.ObjsDB.MakeObject("GroupView");

            obj[LevelObj.N_UnitConfig][LevelObj.N_UnitConfigBaseClass] = "GroupView";
            obj.ID_int = ++ViewForm.LoadedLevel.HighestID;
            list.Add(obj.Prop);
            bool?KeepCurrent = null;

            foreach (var o in ViewForm.SelectedObjs)
            {
                var linkNode = o[LevelObj.N_Links] as LinksNode;
                if (linkNode == null)
                {
                    linkNode            = new LinksNode();
                    o[LevelObj.N_Links] = linkNode;
                }
                if (linkNode.ContainsKey("ViewGroup"))
                {
                    if (KeepCurrent == null)
                    {
                        res = MessageBox.Show("One or more objects already have a ViewGroup list, do you want to replace it ?\r\n" +
                                              "Clicking No will add the GroupView object but will not link the list to keep the already existing GroupViews, the object will be linked anyway", "", MessageBoxButtons.YesNo);
                        KeepCurrent = res != DialogResult.Yes;
                    }
                    else if (KeepCurrent.Value)
                    {
                        ((List <dynamic>)linkNode["ViewGroup"]).Add(obj.Prop);
                    }
                    else
                    {
                        linkNode["ViewGroup"] = list;
                    }
                }
                else
                {
                    linkNode.Add("ViewGroup", list);
                }
            }
        }
コード例 #5
0
        void ParseObject(LevelObj o)
        {
            internalObjectDatabaseEntry data;

            if (Objs.ContainsKey(o.Name))
            {
                data = Objs[o.Name];
            }
            else
            {
                data = new internalObjectDatabaseEntry();
                Objs.Add(o.Name, data);
            }

            foreach (var prop in (Dictionary <string, dynamic>)o.Prop)
            {
                if (prop.Value == null || data.Properties.ContainsKey(prop.Key))
                {
                    continue;
                }

                if (prop.Key == LevelObj.N_Links ||
                    prop.Key == LevelObj.N_ModelName ||
                    prop.Key == LevelObj.N_Name ||
                    prop.Key == LevelObj.N_Rotate ||
                    prop.Key == LevelObj.N_Scale ||
                    prop.Key == LevelObj.N_Translate ||
                    prop.Key == LevelObj.N_Id ||
                    prop.Key == LevelObj.N_UnitConfig ||
                    prop.Key == LevelObj.N_LinkDest ||
                    prop.Key == LevelObj.N_LayerConfigName ||
                    prop.Key == LevelObj.N_PlacementFileName ||
                    prop.Key == LevelObj.N_Comment ||
                    prop.Key == LevelObj.N_LinkReferenceList ||
                    prop.Key == LevelObj.N_ResourceCategory)
                {
                    continue;
                }

                if (prop.Value is IList <dynamic> )
                {
                    if (data.ArrWarn == null)
                    {
                        data.ArrWarn = new List <string>();
                    }
                    if (!data.ArrWarn.Contains(prop.Key))
                    {
                        data.ArrWarn.Add(prop.Key);
                    }
                }
                else if (prop.Value is IDictionary <string, dynamic> )
                {
                    if (data.DictWarn == null)
                    {
                        data.DictWarn = new List <string>();
                    }
                    if (!data.DictWarn.Contains(prop.Key))
                    {
                        data.DictWarn.Add(prop.Key);
                    }
                }
                else
                {
                    data.Properties.Add(prop.Key, ((Type)prop.Value.GetType()).Name);
                }
            }

            if (o.ContainsKey(LevelObj.N_ModelName) && o[LevelObj.N_ModelName] != null && !data.ModelNames.Contains(o[LevelObj.N_ModelName]))
            {
                data.ModelNames.Add(o[LevelObj.N_ModelName]);
            }

            if (o.ContainsKey(LevelObj.N_UnitConfig) && o[LevelObj.N_UnitConfig].ContainsKey(LevelObj.N_UnitConfigBaseClass))
            {
                if (data.ParameterConfigName != null)
                {
                    Debug.Assert(data.ParameterConfigName == ((string)o[LevelObj.N_UnitConfig][LevelObj.N_UnitConfigBaseClass]));
                }
                data.ParameterConfigName = o[LevelObj.N_UnitConfig][LevelObj.N_UnitConfigBaseClass];

                if (data.ParameterConfigName == o.Name)
                {
                    data.ParameterConfigName = null;
                }
            }

            if (o.ContainsKey(LevelObj.N_Links))
            {
                LinksNode n = o[LevelObj.N_Links];
                foreach (var k in n.Keys)
                {
                    if (data.LinkedObjs == null)
                    {
                        data.LinkedObjs = new Dictionary <string, List <string> >();
                    }

                    List <string> objNames = null;
                    if (data.LinkedObjs.ContainsKey(k))
                    {
                        objNames = data.LinkedObjs[k];
                    }
                    else
                    {
                        objNames = new List <string>();
                        data.LinkedObjs.Add(k, objNames);
                    }

                    foreach (dynamic d in n[k])
                    {
                        var g = new LevelObj(d);
                        if (!objNames.Contains(g.Name))
                        {
                            objNames.Add(g.Name);
                        }
                        ParseObject(g);
                    }
                }
            }
        }