Exemplo n.º 1
0
            public void DoUI(IObjectUIControl control)
            {
                lightID   = Convert.ToInt32(control.NumberInput(obj.mEntry.Get <int>("LightID"), "LightID"));
                lightName = control.FullWidthTextInput(obj.mEntry.Get <string>("AreaLightName"), "AreaLightName");

                if (control.Button("View Light Attributes"))
                {
                    LightAttribEditor l = new LightAttribEditor(lightName);
                    l.Show();
                }
            }
Exemplo n.º 2
0
            public void DoUI(IObjectUIControl control)
            {
                control.PlainText(scene.SelectedConnection.Source + " to " + scene.SelectedConnection.Dest);

                connectionName = control.DropDownTextInput("Connection Name", connectionName, scene.SelectedConnection.PossibleNames);
                if (control.Button("Reverse Connection"))
                {
                    scene.ChangeSelectedConnection(
                        scene.SelectedConnection.Dest,
                        scene.SelectedConnection.Source,
                        scene.SelectedConnection.Name);

                    scene.GL_Control.Refresh();
                }
            }
Exemplo n.º 3
0
            public void DoUI(IObjectUIControl control)
            {
                rail.ObjType = (RailObjType)control.ChoicePicker("Rail Type", rail.ObjType, Enum.GetValues(typeof(RailObjType)));

                rail.IsLadder = control.CheckBox("Is Ladder", rail.IsLadder);

                rail.Closed = control.CheckBox("Closed", rail.Closed);

                if (rail.ObjType == RailObjType.RailWithMoveParameter)
                {
                    rail.IsReverseCoord = control.CheckBox("Reverse Coord", rail.IsReverseCoord);
                }

                if (scene.CurrentList != rail.pathPoints && control.Button("Edit Pathpoints"))
                {
                    scene.EnterList(rail.pathPoints);
                }
            }
            public void DoUI(IObjectUIControl control)
            {
                for (int i = 0; i < propertyDictKeys.Length; i++)
                {
                    string key = propertyDictKeys[i];

                    if (propertyInfos != null && propertyInfos.TryGetValue(key, out string desc))
                    {
                        control.SetTooltip(desc);
                    }
                    else
                    {
                        control.SetTooltip("No info for " + key);
                    }


                    if (propertyDict[key] is int)
                    {
                        propertyDict[key] = (int)control.NumberInput(propertyDict[key], key);
                    }
                    else if (propertyDict[key] is float)
                    {
                        propertyDict[key] = control.NumberInput(propertyDict[key], key);
                    }
                    else if (propertyDict[key] is string)
                    {
                        propertyDict[key] = control.TextInput(propertyDict[key], key);
                    }
                    else if (propertyDict[key] is bool)
                    {
                        propertyDict[key] = control.CheckBox(key, propertyDict[key]);
                    }
                }

                control.SetTooltip(null);


                if (control.Button("Edit"))
                {
                    ObjectParameterForm.TypeDef.Localize();
                    List <(ObjectParameterForm.TypeDef typeDef, string name)> parameterInfos = new List <(ObjectParameterForm.TypeDef typeDef, string name)>();

                    List <KeyValuePair <string, dynamic> > otherParameters = new List <KeyValuePair <string, dynamic> >();

                    //get parameterInfos from propertyDict
                    foreach (var item in propertyDict)
                    {
                        if (item.Value is int)
                        {
                            parameterInfos.Add((ObjectParameterForm.TypeDef.IntDef, item.Key));
                        }
                        else if (item.Value is float)
                        {
                            parameterInfos.Add((ObjectParameterForm.TypeDef.FloatDef, item.Key));
                        }
                        else if (item.Value is string)
                        {
                            parameterInfos.Add((ObjectParameterForm.TypeDef.StringDef, item.Key));
                        }
                        else if (item.Value is bool)
                        {
                            parameterInfos.Add((ObjectParameterForm.TypeDef.BoolDef, item.Key));
                        }
                        else
                        {
                            otherParameters.Add(item); //arrays and dictionaries are not supported
                        }
                    }

                    var parameterForm = new ObjectParameterForm(parameterInfos);

                    if (parameterForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        List <RevertableDictAddition.AddInfo>    addInfos    = new List <RevertableDictAddition.AddInfo>();
                        List <RevertableDictDeletion.DeleteInfo> deleteInfos = new List <RevertableDictDeletion.DeleteInfo>();
                        List <RevertableDictEntryChange>         changeInfos = new List <RevertableDictEntryChange>();

                        HashSet <string> newParamNames = new HashSet <string>();

                        List <KeyValuePair <string, dynamic> > newParameters = new List <KeyValuePair <string, dynamic> >();
                        foreach ((ObjectParameterForm.TypeDef typeDef, string parameterName) in parameterForm.EditedParameterInfos)
                        {
                            //check if name stayed the same
                            if (propertyDict.ContainsKey(parameterName))
                            {
                                if (propertyDict[parameterName].GetType() == typeDef.Type)
                                {
                                    //keep value if name and type stayed the same
                                    newParameters.Add(new KeyValuePair <string, dynamic>(parameterName, propertyDict[parameterName]));
                                }
                                else
                                {
                                    //set value to the default value of the new type
                                    newParameters.Add(new KeyValuePair <string, dynamic>(parameterName, typeDef.DefaultValue));
                                    //and add the value change to changeInfos
                                    changeInfos.Add(new RevertableDictEntryChange(parameterName, propertyDict, propertyDict[parameterName]));
                                }
                            }
                            else
                            {
                                //add added paramter to addInfos
                                newParameters.Add(new KeyValuePair <string, dynamic>(parameterName, typeDef.DefaultValue));
                                addInfos.Add(new RevertableDictAddition.AddInfo(typeDef.DefaultValue, parameterName));
                            }
                            newParamNames.Add(parameterName);
                        }

                        //add removed parameters to deleteInfos
                        foreach (var property in propertyDict)
                        {
                            if (!newParamNames.Contains(property.Key))
                            {
                                deleteInfos.Add(new RevertableDictDeletion.DeleteInfo(property.Value, property.Key));
                            }
                        }

                        //add everything to undo
                        scene.BeginUndoCollection();
                        scene.AddToUndo(new RevertableDictAddition(new RevertableDictAddition.AddInDictInfo[]
                        {
                            new RevertableDictAddition.AddInDictInfo(addInfos.ToArray(), propertyDict)
                        },
                                                                   Array.Empty <RevertableDictAddition.SingleAddInDictInfo>()));

                        scene.AddToUndo(new RevertableDictDeletion(new RevertableDictDeletion.DeleteInDictInfo[]
                        {
                            new RevertableDictDeletion.DeleteInDictInfo(deleteInfos.ToArray(), propertyDict)
                        },
                                                                   Array.Empty <RevertableDictDeletion.SingleDeleteInDictInfo>()));


                        foreach (var changeInfo in changeInfos)
                        {
                            scene.AddToUndo(changeInfo);
                        }
                        scene.EndUndoCollection();

                        //regenerate propertyDict by merging the newParameters and the oterParameters
                        propertyDict.Clear();

                        foreach (var parameter in newParameters)
                        {
                            propertyDict.Add(parameter.Key, parameter.Value);
                        }

                        foreach (var parameter in otherParameters)
                        {
                            propertyDict.Add(parameter.Key, parameter.Value);
                        }

                        //update keys
                        propertyDictKeys = propertyDict.Keys.ToArray();
                    }
                }
            }
Exemplo n.º 5
0
            public void DoUI(IObjectUIControl control)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    string key = keys[i];
                    if (dict[key] is int)
                    {
                        dict[key] = (int)control.NumberInput(dict[key], key);
                    }
                    else if (dict[key] is float)
                    {
                        dict[key] = control.NumberInput(dict[key], key);
                    }
                    else if (dict[key] is string)
                    {
                        dict[key] = control.TextInput(dict[key], key);
                    }
                    else if (dict[key] is bool)
                    {
                        dict[key] = control.CheckBox(key, dict[key]);
                    }
                }

                if (control.Button("Edit"))
                {
                    List <(ObjectParameterForm.TypeDef typeDef, string name)> parameters = new List <(ObjectParameterForm.TypeDef typeDef, string name)>();

                    List <KeyValuePair <string, dynamic> > otherParameters = new List <KeyValuePair <string, dynamic> >();

                    foreach (var item in dict)
                    {
                        if (item.Value is int)
                        {
                            parameters.Add((ObjectParameterForm.typeDefs[0], item.Key));
                        }
                        else if (item.Value is float)
                        {
                            parameters.Add((ObjectParameterForm.typeDefs[1], item.Key));
                        }
                        else if (item.Value is string)
                        {
                            parameters.Add((ObjectParameterForm.typeDefs[2], item.Key));
                        }
                        else if (item.Value is bool)
                        {
                            parameters.Add((ObjectParameterForm.typeDefs[3], item.Key));
                        }
                        else
                        {
                            otherParameters.Add(item);
                        }
                    }

                    var parameterForm = new ObjectParameterForm(parameters);

                    if (parameterForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        List <RevertableDictAddition.AddInfo>    addInfos    = new List <RevertableDictAddition.AddInfo>();
                        List <RevertableDictDeletion.DeleteInfo> deleteInfos = new List <RevertableDictDeletion.DeleteInfo>();

                        HashSet <string> newParamNames = new HashSet <string>();

                        List <KeyValuePair <string, dynamic> > newEntries = new List <KeyValuePair <string, dynamic> >();
                        foreach ((ObjectParameterForm.TypeDef def, string name) in parameterForm.Parameters)
                        {
                            if (dict.ContainsKey(name))
                            {
                                newEntries.Add(new KeyValuePair <string, dynamic>(name, dict[name]));
                            }
                            else
                            {
                                newEntries.Add(new KeyValuePair <string, dynamic>(name, def.DefaultValue));
                                addInfos.Add(new RevertableDictAddition.AddInfo(def.DefaultValue, name));
                            }
                            newParamNames.Add(name);
                        }

                        foreach (var keyValuePair in dict)
                        {
                            if (!newParamNames.Contains(keyValuePair.Key))
                            {
                                deleteInfos.Add(new RevertableDictDeletion.DeleteInfo(keyValuePair.Value, keyValuePair.Key));
                            }
                        }

                        scene.BeginUndoCollection();
                        scene.AddToUndo(new RevertableDictAddition(new RevertableDictAddition.AddInDictInfo[]
                        {
                            new RevertableDictAddition.AddInDictInfo(addInfos.ToArray(), dict)
                        },
                                                                   new RevertableDictAddition.SingleAddInDictInfo[0]));

                        scene.AddToUndo(new RevertableDictDeletion(new RevertableDictDeletion.DeleteInDictInfo[]
                        {
                            new RevertableDictDeletion.DeleteInDictInfo(deleteInfos.ToArray(), dict)
                        },
                                                                   new RevertableDictDeletion.SingleDeleteInDictInfo[0]));
                        scene.EndUndoCollection();

                        dict.Clear();

                        foreach (var keyValuePair in newEntries)
                        {
                            dict.Add(keyValuePair.Key, keyValuePair.Value);
                        }

                        foreach (var keyValuePair in otherParameters)
                        {
                            dict.Add(keyValuePair.Key, keyValuePair.Value);
                        }


                        keys = dict.Keys.ToArray();
                    }
                }
            }