public void onInspectorPostFieldModification()
            {
                GuiEditorProfilesTree         GuiEditorProfilesTree         = "GuiEditorProfilesTree";
                GuiEditorProfileChangeManager GuiEditorProfileChangeManager = "GuiEditorProfileChangeManager";

                GuiEditorGui.GuiEditor GuiEditor   = "GuiEditor";
                ProfilePane            ProfilePane = "ProfilePane";

                UndoAction action     = this.currentFieldEditAction;
                SimObject  objectx    = action["objectId"];
                string     fieldName  = action["fieldName"];
                string     arrayIndex = action["arrayIndex"];
                string     oldValue   = action["fieldValue"];
                string     newValue   = objectx.getFieldValue(fieldName, arrayIndex == "(null)" ? -1 : arrayIndex.AsInt());

                // If it's the name field, make sure to sync up the treeview.

                if (action["fieldName"] == "name")
                {
                    GuiEditorProfilesTree.onProfileRenamed(objectx, newValue);
                }

                ProfilePane.onProfileSelected();

                // Add change record.

                GuiEditorProfileChangeManager.registerEdit(objectx, fieldName, arrayIndex, oldValue);

                this.currentFieldEditAction.addToManager(ProfilePane.getUndoManager());
                this.currentFieldEditAction = "";

                //GuiEditor.updateUndoMenu();
                GuiEditor.setProfileDirty(objectx, true, false);
            }
            public void onInspectorPreFieldModification(string fieldName, string arrayIndex)
            {
                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

                Util.pushInstantGroup();
                //UndoManager undoManager = GuiEditor.getUndoManager();

                SimObject objectx = this.getInspectObject();

                string nameOrClass = objectx.getName();

                if (nameOrClass == "")
                {
                    nameOrClass = objectx.getClassName();
                }

                ObjectCreator oc = new ObjectCreator("InspectorFieldUndoAction");

                oc["actionName"] = nameOrClass + "." + fieldName + " Change";

                oc["objectId"]   = objectx.getId();
                oc["fieldName"]  = fieldName;
                oc["fieldValue"] = objectx.getFieldValue(fieldName, arrayIndex == "(null)" ? -1 : arrayIndex.AsInt());
                oc["arrayIndex"] = arrayIndex;

                oc["inspectorGui"] = this;

                InspectorFieldUndoAction action = oc.Create();

                this.currentFieldEditAction = action;
                Util.popInstantGroup();
            }
Exemple #3
0
            public string getOpenName(string defaultFileName)
            {
                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

                if (defaultFileName == "")
                {
                    defaultFileName = omni.Util._expandFilename("^game/gui/untitled.gui");
                }

                var ofd = new System.Windows.Forms.OpenFileDialog
                {
                    FileName         = defaultFileName,
                    InitialDirectory = GuiEditor["LastPath"],
                    Filter           = omni.sGlobal["$GUI::FileSpec"],
                    CheckFileExists  = true,
                    Multiselect      = false
                };

                DialogResult dr = Dialogs.OpenFileDialog(ref ofd);

                if (dr == DialogResult.OK)
                {
                    var fileName = Dialogs.GetForwardSlashFile(ofd.FileName);
                    GuiEditor["LastPath"] = omni.Util.filePath(fileName);
                    return(fileName);
                }
                return("");
            }
        public void update()
        {
            GuiControl GuiEditorContent = "GuiEditorContent";

            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            SimObject obj = GuiEditorContent.getObject(0);

            if (!obj.isObject())
            {
                this.clear();
            }
            else
            {
                // Open inspector tree.

                this.open(obj);

                // Sync selection with GuiEditor.

                this.clearSelection();

                SimSet selection = GuiEditor.getSelection();
                int    count     = selection.getCount();

                for (uint i = 0; i < count; i++)
                {
                    this.addSelection(selection.getObject(i).AsInt(), false);
                }
            }
        }
        public override void onEndReparenting()
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            UndoActionReparentObjects action = this.reparentUndoAction;

            this.reparentUndoAction = "";

            if (action.numObjects > 0)
            {
                if (action.numObjects == 1)
                {
                    action.actionName = "Reparent Control";
                }
                else
                {
                    action.actionName = "Reparent Controls";
                }

                action.addToManager(GuiEditor.getUndoManager());

                GuiEditor.updateUndoMenu();
            }
            else
            {
                action.delete();
            }
        }
        public bool includeClass(string className)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            return(Util.isMemberOfClass(className, "GuiControl") &&
                   !GuiEditor.isFilteredClass(className));
        }
        public void setViewTypeAlphabetical()
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
            string      controls             = Util.enumerateConsoleClassesByCategory("Gui");
            ArrayObject classes = new ObjectCreator("ArrayObject").Create();

            // Collect relevant classes.

            foreach (string className in controls.Split('\t'))
            {
                if (GuiEditor.isFilteredClass(className) ||
                    !(Util.isMemberOfClass(className, "GuiControl")))
                {
                    continue;
                }

                classes.push_back(className, "");
            }

            // Sort classes alphabetically.

            classes.sortk(true);

            // Add toolbox buttons.

            int numClasses = classes.count();

            for (int i = 0; i < numClasses; i++)
            {
                string className = classes.getKey(i);

                #region GuiIconButtonCtrl ()        oc_Newobject2

                ObjectCreator oc_Newobject2 = new ObjectCreator("GuiIconButtonCtrl", "", typeof(GuiEditorToolboxButton));
                oc_Newobject2["profile"]    = "ToolsGuiIconButtonSmallProfile";
                oc_Newobject2["extent"]     = "128 18";
                oc_Newobject2["text"]       = className;
                oc_Newobject2["iconBitmap"] = console.Call_Classname("EditorIconRegistry", "findIconByClassName",
                                                                     new string[] { className });
                oc_Newobject2["buttonMargin"]   = "2 2";
                oc_Newobject2["iconLocation"]   = "left";
                oc_Newobject2["textLocation"]   = "left";
                oc_Newobject2["textMargin"]     = "24";
                oc_Newobject2["AutoSize"]       = new ObjectCreator.StringNoQuote("true");
                oc_Newobject2["command"]        = "GuiEditor.createControl( " + className + " );";
                oc_Newobject2["useMouseEvents"] = new ObjectCreator.StringNoQuote("true");
                oc_Newobject2["tooltip"]        = className + '\n' + "\n" + Util.getDescriptionOfClass(className);
                oc_Newobject2["tooltipProfile"] = "ToolsGuiToolTipProfile";

                #endregion

                GuiIconButtonCtrl ctrl = oc_Newobject2.Create();


                this.add(ctrl);
            }

            classes.delete();
            this.currentViewType = "Alphabetical";
        }
Exemple #8
0
        public void init(string guiName, string guiClass)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
            GuiTextEditCtrl        nameField = this.FOT("nameField");

            nameField.setValue(guiName);

            // Initialize the class dropdown if we haven't already.

            GuiPopUpMenuCtrl classDropdown = this.FOT("classDropdown");

            if (classDropdown.size() == 0)
            {
                string classes = Util.enumerateConsoleClassesByCategory("Gui");
                int    count   = Util.getFieldCount(classes);

                for (int i = 0; i < count; i++)
                {
                    string className = Util.getField(classes, i);
                    if (GuiEditor.isFilteredClass(className) ||
                        !Util.isMemberOfClass(className, "GuiControl"))
                    {
                        continue;
                    }

                    classDropdown.add(className, 0);
                }

                classDropdown.sort();
            }

            classDropdown.setText("GuiControl");
        }
        public override void onRemoveSelection(int ctrl)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            GuiEditor.dontSyncTreeViewSelection = true;
            GuiEditor.removeSelection(ctrl);
            GuiEditor.dontSyncTreeViewSelection = false;
        }
Exemple #10
0
            /// GuiBuilder::getSaveName - Open a Native File dialog and retrieve the
            ///  location to save the current document.
            /// @arg defaultFileName   The FileName to default in the field and to be selected when a path is opened
            public static string GetSaveName(string defaultFileName)
            {
                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

                string defaultPath = GuiEditor["LastPath"];

                if (defaultFileName == "")
                {
                    string prefix = "";
                    if (omni.Util.isFunction("isScriptPathExpando"))
                    {
                        // if we're editing a game, we want to default to the games dir.
                        // if we're not, then we default to the tools directory or the base.
                        if (omni.console.Call("isScriptPathExpando", new string[] { "^game" }).AsBool())
                        {
                            prefix = "^game/";
                        }
                        else if (omni.console.Call("isScriptPathExpando", new string[] { "^tools" }).AsBool())
                        {
                            prefix = "^tools/";
                        }
                    }

                    defaultFileName = omni.Util._expandFilename(prefix + "gui/untitled.gui");
                }
                else
                {
                    defaultPath = omni.Util.filePath(defaultFileName);
                }

                var sfd = new System.Windows.Forms.SaveFileDialog
                {
                    Filter           = omni.sGlobal["$GUI::FileSpec"],
                    InitialDirectory = omni.Util.makeFullPath(defaultPath, ""),
                    FileName         = defaultFileName,
                    OverwritePrompt  = true,
                };

                string filename = "";

                DialogResult dr = Dialogs.SaveFileDialog(ref sfd);

                if (dr == DialogResult.OK)
                {
                    filename = Dialogs.GetForwardSlashFile(sfd.FileName);
                    GuiEditor["LastPath"] = omni.Util.filePath(filename);
                    //filename = dlg["FileName"];
                    if (omni.Util.fileExt(filename) != ".gui")
                    {
                        filename = filename + ".gui";
                    }
                }

                //dlg.delete();

                return(filename);
            }
        public override void onAddSelection(int ctrl, bool isLastSelection)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            GuiEditor.dontSyncTreeViewSelection = true;
            GuiEditor.addSelection(ctrl);
            GuiEditor.dontSyncTreeViewSelection = false;
            GuiEditor.setFirstResponderX();
        }
Exemple #12
0
        public void scanGroup(SimSet group)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
            for (uint i = 0; i < group.getCount(); i++)
            {
                SimObject obj = group.getObject(i);
                if (obj.isMemberOfClass("GuiControl"))
                {
                    if (obj.getClassName() == "GuiCanvas")
                    {
                        this.scanGroup((GuiCanvas)obj);
                    }
                    else
                    {
                        string name;
                        if (obj.getName() == "")
                        {
                            name = "(unnamed) - " + obj;
                        }
                        else
                        {
                            name = obj.getName() + " - " + obj;
                        }

                        bool skip = false;

                        foreach (string guiEntry in sGlobal["$GuiEditor::GuiFilterList"].Split('\t'))
                        {
                            if (obj.getName() == guiEntry)
                            {
                                skip = true;
                                break;
                            }
                        }

                        if (!skip)
                        {
                            this.add(name, obj);
                        }
                    }
                }
                else if (obj.isMemberOfClass("SimGroup")
                         &&
                         (                                               //(%obj.internalName !$= "EditorGuiGroup" /* Copyright (C) 2013 WinterLeaf Entertainment LLC. */&& %obj.internalName !$= "IngameGuiGroup" )   // Don't put our editor's GUIs in the list
                           /*||*/ GuiEditor["showEditorGuis"].AsBool())) // except if explicitly requested.
                {
                    // Scan nested SimGroups for GuiControls.

                    this.scanGroup((SimGroup)obj);
                }
            }
        }
Exemple #13
0
        public void append()
        {
            GuiEditorGui.GuiEditor GuiEditor          = "GuiEditor";
            GuiControl             GuiEditorContent   = "GuiEditorContent";
            GuiEditorStatusBar     GuiEditorStatusBar = "GuiEditorStatusBar";

            // Get filename.

            string openFileName = console.Call_Classname("GuiBuilder", "getOpenName");

            if (openFileName == "" ||
                (!Util.isFile(openFileName) &&
                 !Util.isFile(openFileName + ".dso")))
            {
                return;
            }

            // Exec file.

            string oldRedefineBehavior = sGlobal["$Con::redefineBehavior"];

            sGlobal["$Con::redefineBehavior"] = "renameNew";

            //TODO
            GuiControl guiContent = Util.eval(openFileName);

            sGlobal["$Con::redefineBehavior"] = oldRedefineBehavior;

            // Find guiContent.

            if (!guiContent.isObject())
            {
                Util.messageBox("Error loading GUI file",
                                "The GUI content controls could not be found.  This function can only be used with files saved by the GUI editor.",
                                "Ok", "Error");
                return;
            }

            if (GuiEditorContent.getCount() == 0)
            {
                GuiEditor.openForEditing(guiContent);
            }
            else
            {
                ((SimSet)GuiEditor.getCurrentAddSet()).add(guiContent);
                GuiEditor.readGuides(guiContent);
                GuiEditor.onAddNewCtrl(guiContent);
                GuiEditor.onHierarchyChanged();
            }

            GuiEditorStatusBar.print("Appended controls from '" + openFileName + "'");
        }
        public override void onSelect(string obj, string y)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
            GuiEditorInspectFields GuiEditorInspectFields = "GuiEditorInspectFields";

            if (obj.isObject())
            {
                GuiEditor.dontSyncTreeViewSelection = true;
                GuiEditor.select(obj);
                GuiEditor.dontSyncTreeViewSelection = false;
                GuiEditorInspectFields.update(obj);
            }
        }
        public void selectObject(SimObject obj, bool val)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            if (val)
            {
                GuiEditor.addSelection(obj);
            }
            else
            {
                GuiEditor.removeSelection(obj);
            }
        }
Exemple #16
0
        public void onInspectorPreFieldModification(string fieldName, string arrayIndex)
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            Util.pushInstantGroup();
            UndoManager undoManager = GuiEditor.getUndoManager();

            string action     = "";
            int    numObjects = this.getNumInspectObjects();

            if (numObjects > 1)
            {
                action = undoManager.pushCompound("Multiple Field Edit");
            }

            for (uint i = 0; i < numObjects; i++)
            {
                SimObject obj = this.getInspectObject(i);

                string nameOrClass = obj.getName();
                if (nameOrClass == "")
                {
                    nameOrClass = obj.getClassName();
                }

                ObjectCreator oc = new ObjectCreator("InspectorFieldUndoAction");
                oc["actionName"] = nameOrClass + "." + fieldName + " Change";

                oc["objectId"]   = obj.getId();
                oc["fieldName"]  = fieldName;
                oc["fieldValue"] = obj.getFieldValue(fieldName, arrayIndex == "(null)" ? -1 : arrayIndex.AsInt());
                oc["arrayIndex"] = arrayIndex;

                oc["inspectorGui"] = this;

                InspectorFieldUndoAction undo = oc.Create();

                if (numObjects > 1)
                {
                    undo.addToManager(undoManager);
                }
                else
                {
                    action = undo;
                    break;
                }
            }

            this.currentFieldEditAction = action;
            Util.popInstantGroup();
        }
Exemple #17
0
        public void load(string filename)
        {
            GuiEditorStatusBar GuiEditorStatusBar = "GuiEditorStatusBar";

            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            string newRedefineBehavior = "replaceExisting";

            if (Util.isDefined("$GuiEditor::loadRedefineBehavior"))
            {
                // This trick allows to choose different redefineBehaviors when loading
                // GUIs.  This is useful, for example, when loading GUIs that would lead to
                // problems when loading with their correct names because script behavior
                // would immediately attach.
                //
                // This allows to also edit the GUI editor's own GUI inside itself.

                newRedefineBehavior = sGlobal["$GuiEditor::loadRedefineBehavior"];
            }

            // Allow stomping objects while exec'ing the GUI file as we want to
            // pull the file's objects even if we have another version of the GUI
            // already loaded.

            string oldRedefineBehavior = sGlobal["$Con::redefineBehavior"];

            sGlobal["$Con::redefineBehavior"] = newRedefineBehavior;

            // Load up the gui.
            Util.exec(filename);
            GuiControl guiContent = Util.eval("return %guiContent;");

            //GuiControl guiContent = Util.eval(filename);

            sGlobal["$Con::redefineBehavior"] = oldRedefineBehavior;

            // The GUI file should have contained a GUIControl which should now be in the instant
            // group. And, it should be the only thing in the group.
            //TODO
            if (!guiContent.isObject())
            {
                Util.messageBox(Util.getEngineName(),
                                "You have loaded a Gui file that was created before this version.  It has been loaded but you must open it manually from the content list dropdown",
                                "Ok", "Information");
                return;
            }

            GuiEditor.openForEditing(guiContent);

            GuiEditorStatusBar.print("Loaded '" + filename + "'");
        }
            public override void onInspectorFieldModified(string objectx, string fieldName, string arrayIndex, string oldValue, string newValue)
            {
                SimObject obj = objectx;

                GuiEditorGui.GuiEditor        GuiEditor                     = "GuiEditor";
                GuiEditorProfilesTree         GuiEditorProfilesTree         = "GuiEditorProfilesTree";
                GuiEditorProfileChangeManager GuiEditorProfileChangeManager = "GuiEditorProfileChangeManager";
                ProfilePane ProfilePane = "ProfilePane";

                GuiEditor.setProfileDirty(obj, true, false);

                // If it's the name field, make sure to sync up the treeview.

                if (fieldName == "name")
                {
                    GuiEditorProfilesTree.onProfileRenamed(obj, newValue);
                }

                // Add change record.

                //GuiEditorProfileChangeManager.registerEdit(obj, fieldName, oldValue);
                GuiEditorProfileChangeManager.registerEdit(obj, fieldName, arrayIndex, oldValue);

                // Add undo.

                Util.pushInstantGroup();

                string nameOrClass = obj.getName();

                if (nameOrClass == "")
                {
                    nameOrClass = obj.getClassName();
                }

                ObjectCreator oc = new ObjectCreator("InspectorFieldUndoAction");

                oc["actionName"] = nameOrClass + "." + fieldName + " Change";

                oc["objectId"]   = obj.getId();
                oc["fieldName"]  = fieldName;
                oc["fieldValue"] = oldValue;
                oc["arrayIndex"] = arrayIndex;

                oc["inspectorGui"] = this;

                InspectorFieldUndoAction action = oc.Create();

                Util.popInstantGroup();
                action.addToManager(ProfilePane.getUndoManager());
                //GuiEditor.updateUndoMenu();
            }
            public override void onAction()
            {
                GuiEditorPrefsDlg         GuiEditorPrefsDlg         = "GuiEditorPrefsDlg";
                GuiEditorPrefsDlgGridEdit GuiEditorPrefsDlgGridEdit = "GuiEditorPrefsDlgGridEdit";
                GuiCanvas Canvas = "Canvas";

                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
                GuiEditor["snap2gridsize"] = GuiEditorPrefsDlgGridEdit.getValue();
                if (GuiEditor["snap2grid"].AsBool())
                {
                    GuiEditor.setSnapToGrid(GuiEditor["snap2gridsize"].AsUint());
                }

                Canvas.popDialog(GuiEditorPrefsDlg);
            }
Exemple #20
0
        public void onInspectorPostFieldModification()
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            if (this.currentFieldEditAction.isMemberOfClass("CompoundUndoAction"))
            {
                // Finish multiple field edit.
                GuiEditor.getUndoManager().popCompound();
            }
            else
            {
                // Queue single field undo.
                this.currentFieldEditAction.addToManager(GuiEditor.getUndoManager());
            }

            this.currentFieldEditAction = "";
            GuiEditor.updateUndoMenu();
        }
Exemple #21
0
        public void onInspectorDiscardFieldModification()
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            this.currentFieldEditAction.undo();

            if (this.currentFieldEditAction.isMemberOfClass("CompoundUndoAction"))
            {
                // Multiple field editor.  Pop and discard.
                GuiEditor.getUndoManager().popCompound(true);
            }
            else
            {
                // Single field edit.  Just kill undo action.
                this.currentFieldEditAction.delete();
            }

            this.currentFieldEditAction = "";
        }
            public void onProfileRenamed(string profile, string newName)
            {
                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

                int item = this.findItemByValue(profile.getID().AsString());

                if (item == -1)
                {
                    return;
                }

                string newText = newName + " (" + profile.getID() + ")";

                if (GuiEditor.isProfileDirty(profile))
                {
                    newText = newText + " *";
                }

                this.editItem(item, newText, profile.getID().AsString());
            }
Exemple #23
0
        public string getMouseModeHelp()
        {
            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
            bool isMac = (sGlobal["$platform"] == "macos");

            string cmdCtrl;

            if (isMac)
            {
                cmdCtrl = "CMD";
            }
            else
            {
                cmdCtrl = "CTRL";
            }

            string mouseMode = GuiEditor.getMouseMode();

            switch (mouseMode)
            {
            case "Selecting":
                return("");

            case "DragSelecting":
                return(cmdCtrl + " to add to selection; ALT to exclude parents; CTRL+ALT to exclude children");

            case "MovingSelection":
                return("");

            case "SizingSelection":
                return("CTRL to activate snapping; ALT to move instead of resize");

            case "DragGuide":
                return("Drag into ruler to delete; drop to place");
            }

            return("");
        }
Exemple #24
0
        public override void onInspectorFieldModified(string objectx, string fieldName, string arrayIndex, string oldValue, string newValue)
        {
            SimObject obj = objectx;

            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

            // The instant group will try to add our
            // UndoAction if we don't disable it.
            Util.pushInstantGroup();

            string nameOrClass = obj.getName();

            if (nameOrClass == "")
            {
                nameOrClass = obj.getClassName();
            }

            ObjectCreator oc = new ObjectCreator("InspectorFieldUndoAction");

            oc["actionName"] = nameOrClass + "." + fieldName + " Change";

            oc["objectId"]   = obj.getId();
            oc["fieldName"]  = fieldName;
            oc["fieldValue"] = oldValue;
            oc["arrayIndex"] = arrayIndex;

            oc["inspectorGui"] = this;

            InspectorFieldUndoAction action = oc.Create();

            // Restore the instant group.
            Util.popInstantGroup();

            action.addToManager(GuiEditor.getUndoManager());

            GuiEditor.updateUndoMenu();
        }
Exemple #25
0
        public void quit()
        {
            GuiEditorGui GuiEditorGui = "GuiEditorGui";

            GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
            SimSet     GuiGroup = "GuiGroup";
            GuiCanvas  Canvas   = "Canvas";
            PostEffect MLAAFx   = "MLAAFx";

            this.close();
            GuiGroup.add(GuiEditorGui);
            // we must not delete a window while in its event handler, or we foul the event dispatch mechanism
            this.schedule("10", "delete");

            Canvas.setContent(GuiEditor["lastContent"]);
            bGlobal["$InGuiEditor"] = false;

            //Temp fix to disable MLAA when in GUI editor
            if (MLAAFx.isObject() && bGlobal["$MLAAFxGuiEditorTemp"])
            {
                MLAAFx.isEnabled = true;
                bGlobal["$MLAAFxGuiEditorTemp"] = false;
            }
        }
            public override void onWake()
            {
                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

                this.setValue(GuiEditor["snap2gridsize"]);
            }
            public void init()
            {
                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
                SimSet GuiDataGroup = "GuiDataGroup";

                this.clear();

                int defaultGroup = this.insertItem(0, "Default", "-1", "", 1, 1);
                int otherGroup   = this.insertItem(0, sGlobal["$GUI_EDITOR_DEFAULT_PROFILE_CATEGORY"], "-1", "", 1, 1);

                for (uint i = 0; i < GuiDataGroup.getCount(); i++)
                {
                    SimObject obj = GuiDataGroup.getObject(i);
                    if (!obj.isMemberOfClass("GuiControlProfile"))
                    {
                        continue;
                    }

                    // If it's an Editor profile, skip if showing them is not enabled.

                    if (obj["category"] == "Editor" && !GuiEditor["showEditorProfiles"].AsBool())
                    {
                        continue;
                    }

                    // Create a visible name.

                    string name = obj.getName();
                    if (name == "")
                    {
                        name = "<Unnamed>";
                    }
                    string text = name + " (" + obj.getId() + ")";

                    // Find which group to put the control in.

                    bool isDefaultProfile = GuiEditor.isDefaultProfile(name);

                    int group;
                    if (isDefaultProfile)
                    {
                        group = defaultGroup;
                    }
                    else if (obj["category"] != "")
                    {
                        group = this.findChildItemByName(0, obj["category"]);
                        if (group == 0)
                        {
                            group = this.insertItem(0, obj["category"], "", "", 1, 1);
                        }
                    }
                    else
                    {
                        group = otherGroup;
                    }

                    // Insert the item.

                    this.insertItem(group, text, obj.getId().AsString(), "", 1, 1);
                }

                this.sort(0, true, true, false);
            }
Exemple #28
0
        public void save(bool selectedOnly, bool noPrompt)
        {
            GuiEditorGui.GuiEditor GuiEditor          = "GuiEditor";
            GuiControl             GuiEditorContent   = "GuiEditorContent";
            GuiEditorStatusBar     GuiEditorStatusBar = "GuiEditorStatusBar";

            SimObject currentObject;

            // Get the control we should save.

            if (selectedOnly)
            {
                SimSet selected = GuiEditor.getSelection();
                if (selected.getCount() == 0)
                {
                    return;
                }
                else if (selected.getCount() > 1)
                {
                    Util.messageBox("Invalid selection", "Only a single control hierarchy can be saved to a file.  Make sure you have selected only one control in the tree view.", "", "");
                    return;
                }

                currentObject = selected.getObject(0);
            }
            else if (GuiEditorContent.getCount() > 0)
            {
                currentObject = GuiEditorContent.getObject(0);
            }
            else
            {
                return;
            }

            // Store the current guide set on the control.

            GuiEditor.writeGuides(currentObject);
            currentObject.canSaveDynamicFields = true; // Make sure the guides get saved out.

            // Construct a base filename.

            string name;

            if (currentObject.getName() != "")
            {
                name = currentObject.getName() + ".gui";
            }
            else
            {
                name = "Untitled.gui";
            }

            // Construct a path.

            string currentFile;

            if (selectedOnly && currentObject != GuiEditorContent.getObject(0) && currentObject.getFilename() == ((SimObject)GuiEditorContent.getObject(0)).getFilename())
            {
                // Selected child control that hasn't been yet saved to its own file.

                currentFile = GuiEditor["LastPath"] + "/" + name;
                currentFile = Util.makeRelativePath(currentFile, Util.getMainDotCsDir());
            }
            else
            {
                currentFile = currentObject.getFilename();
                if (currentFile == "")
                {
                    // No file name set on control.  Force a prompt.
                    noPrompt = false;

                    if (GuiEditor["LastPath"] != "")
                    {
                        currentFile = GuiEditor["LastPath"] + "/" + name;
                        currentFile = Util.makeRelativePath(currentFile, Util.getMainDotCsDir());
                    }
                    else
                    {
                        currentFile = Util._expandFilename(name);
                    }
                }
                else
                {
                    currentFile = Util._expandFilename(currentFile);
                }
            }

            // Get the filename.

            string filename;

            if (!noPrompt)
            {
                filename = GuiEditorFileDialog.GuiBuilder.GetSaveName(currentFile);
                // console.Call_Classname("GuiBuilder", "getSaveName", new string[] {currentFile} );
                if (filename == "")
                {
                    return;
                }
            }
            else
            {
                filename = currentFile;
            }

            // Save the Gui.

            if (Util.isWriteableFileName(filename))
            {
                //
                // Extract any existent TorqueScript before writing out to disk
                //
                FileObject fileObject = new ObjectCreator("FileObject").Create();
                fileObject.openForRead(filename);
                bool skipLines    = true;
                bool beforeObject = true;
                // var++ does not post-increment var, in torquescript, it pre-increments it,
                // because ++var is illegal.
                //int lines = -1;
                //int beforeLines = -1;
                skipLines = false;

                //string[] beforeNewFileLines = new string[]{};
                //string[] newFileLines = new string[]{};

                List <string> beforeNewFileLines = new List <string>();
                List <string> newFileLines       = new List <string>();

                while (!fileObject.isEOF())
                {
                    string line = fileObject.readLine();
                    if (line == "//--- OBJECT WRITE BEGIN ---")
                    {
                        skipLines = true;
                    }
                    else if (line == "//--- OBJECT WRITE END ---")
                    {
                        skipLines    = false;
                        beforeObject = false;
                    }
                    else if (skipLines == false)
                    {
                        if (beforeObject)
                        {
                            beforeNewFileLines.Add(line);
                        }
                        //beforeNewFileLines[ beforeLines++ ] = line;
                        else
                        {
                            //newFileLines[ lines++ ] = line;
                            newFileLines.Add(line);
                        }
                    }
                }
                fileObject.close();
                fileObject.delete();

                FileObject fo = new ObjectCreator("FileObject").Create();
                fo.openForWrite(filename);

                // Write out the captured TorqueScript that was before the object before the object
                foreach (string line in beforeNewFileLines)
                {
                    fo.writeLine(line);
                }

                //for(int i = 0; i <= beforeLines; i++)
                //    fo.writeLine( beforeNewFileLines[ i ] );

                fo.writeLine("//--- OBJECT WRITE BEGIN ---");
                fo.writeObject(currentObject, "%guiContent = ");
                fo.writeLine("//--- OBJECT WRITE END ---");

                // Write out captured TorqueScript below Gui object
                //for( int i = 0; i <= lines; i++ )
                //    fo.writeLine( newFileLines[ i ] );
                foreach (string line in newFileLines)
                {
                    fo.writeLine(line);
                }

                fo.close();
                fo.delete();

                currentObject.setFilename(Util.makeRelativePath(filename, Util.getMainDotCsDir()));

                GuiEditorStatusBar.print("Saved file '" + currentObject.getFilename() + "'");
            }
            else
            {
                Util.messageBox("Error writing to file", "There was an error writing to file '" + currentFile + "'. The file may be read-only.", "Ok", "Error");
            }
        }
            public override void onFieldRenamed(string objectx, string oldFieldName, string newFieldName)
            {
                GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";

                GuiEditor.setProfileDirty(objectx, true, false);
            }
Exemple #30
0
 public override void onSelect(string ctrl, string text)
 {
     GuiEditorGui.GuiEditor GuiEditor = "GuiEditor";
     GuiEditor.openForEditing(ctrl);
 }