Exemplo n.º 1
0
        public virtual void FollowPath(SimSet path, int node)
        {
            stopThread(0);

            if (!path.isObject() || !isObject())
            {
                this["path"] = "";
                return;
            }

            if (node > path.getCount() - 1)
            {
                this["targetNode"] = (path.getCount() - 1).AsString();
            }
            else
            {
                this["targetNode"] = node.AsString();
            }

            if ((this["path"]) == path)
            {
                MoveToNode(this["currentNode"].AsUint());
            }

            else
            {
                this["path"] = path;
                MoveToNode(0);
            }
        }
Exemplo n.º 2
0
        /// Pauses the playback of active sound sources.
        ///
        /// @param %channels    An optional word list of channel indices or an empty
        /// string to pause sources on all channels.
        /// @param %pauseSet    An optional SimSet which is filled with the paused
        /// sources.  If not specified the global SFXPausedSet
        /// is used.
        ///
        /// @deprecated
        public static void sfxPause(List <int> channels = null, SimSet pauseSet = null)
        {
            // Did we get a set to populate?
            if (pauseSet == null)
            {
                pauseSet = SFXPausedSet;
            }

            SimSet SFXSourceSet = Sim.FindObjectByName <SimSet>("SFXSourceSet");

            int count = SFXSourceSet.getCount();

            for (uint i = 0; i < count; i++)
            {
                SFXSource source = SFXSourceSet.getObject(i).As <SFXSource>();

                int channel = sfxGroupToOldChannel(source.getGroup());
                if (channels != null && !channels.Contains(channel))
                {
                    continue;
                }

                source.pause();
                pauseSet.add(source);
            }
        }
Exemplo n.º 3
0
        public override void onAction()
        {
            // NOTE: Though this is a GuiControl which exists on the client-side
            // we access and modify the server-side TimeOfDay object. This is acceptible
            // because this is a "tools" gui which is not intended for a real-game
            // or multiplayer situation.

            if (!this["tod"].isObject())
            {
                if ("MissionGroup".isObject())
                {
                    SimSet MissionGroup = "MissionGroup";
                    for (uint i = 0; i < MissionGroup.getCount(); i++)
                    {
                        SimObject obj = MissionGroup.getObject(i);
                        if (obj.getClassName() == "TimeOfDay")
                        {
                            this["tod"] = obj;
                            break;
                        }
                    }
                }
            }
            if (!this["tod"].isObject())
            {
                return;
            }

            TimeOfDay tod = this["tod"];

            tod.time = this.getValue();
        }
        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);
                }
            }
        }
Exemplo n.º 5
0
        public void initFilterList(string selectFilter)
        {
            GuiPopUpMenuCtrl SFXParameterFilter = this.FOT("SFXParameterFilter");
            SimSet           SFXParameterGroup  = "SFXParameterGroup";

            GuiPopUpMenuCtrl filterList = SFXParameterFilter;

            filterList.clear();
            filterList.add("", 0);

            for (uint i = 0; i < SFXParameterGroup.getCount(); i++)
            {
                SimObject obj = SFXParameterGroup.getObject(i);
                if (!Util.isMemberOfClass(obj.getClassName(), "SFXParameter"))
                {
                    continue;
                }

                for (int idx = 0; obj["categories[" + idx + "]"] != ""; idx++)
                {
                    string category = obj["categories[" + idx + "]"];
                    if (filterList.findText(category) == -1)
                    {
                        filterList.add(category, filterList.size());
                    }
                }
            }

            // Sort the filters.

            filterList.sort();
            filterList.setSelected(filterList.findText(selectFilter), false);
        }
Exemplo n.º 6
0
        public static void messageAll(string msgType, string msgString, params string[] args)
        {
            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            for (uint i = 0; i < ClientGroup.getCount(); i++)
            {
                GameConnectionToClient client = ClientGroup.getObject(i).As <GameConnectionToClient>();
                messageClient(client, msgType, msgString, args);
            }
        }
Exemplo n.º 7
0
        public static void ServerPlay3D(SFXProfile profile, TransformF transform)
        {
            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            // Play the given sound profile at the given position on every client
            // The sound will be transmitted as an event, not attached to any object.
            for (uint i = 0; i < ClientGroup.getCount(); i++)
            {
                ClientGroup.getObject(i).As <GameConnectionToClient>().play3D(profile, transform);
            }
        }
Exemplo n.º 8
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);
                }
            }
        }
        public static string MissionBoundsExtents(SimSet group)
        {
            string box   = "0 0 0 0 0 0";
            int    count = group.getCount();

            for (uint i = 0; i < count; i++)
            {
                // Skip LevelInfos. Need a way to detect other non-SceneObjects.
                // Also skip GroundPlanes. They're too big.
                SimObject obj = group.getObject(i);
                //var cls = obj.getClassName();
                var cls = obj.GetType().Name;
                if (cls == "LevelInfo" || cls == "GroundPlane" || cls == "GroundCover")
                {
                    continue;
                }

                // Get world box - might have to recurse into nested SimGroups.
                string wbox = "0 0 0 0 0 0";
                if (cls == "SimGroup" || cls == "SimSet" || cls == "Path")
                {
                    wbox = MissionBoundsExtents((SimSet)obj);
                }
                else if (obj.GetType() == typeof(SceneObject) && ((SceneObject)obj).getType() == omni.iGlobal["$TypeMasks::StaticObjectType"] &&
                         !(((SceneObject)obj).getType() == omni.iGlobal["$TypeMasks::EnvironmentObjectType"]))
                {
                    wbox = ((SceneObject)obj).getWorldBox().AsString();
                }
                else
                {
                    continue;
                }

                // Update min point.
                for (int j = 0; j < 3; j++)
                {
                    if (omni.Util.getWord(box, j).AsInt() > omni.Util.getWord(wbox, j).AsInt())
                    {
                        box = omni.Util.setWord(box, j, omni.Util.getWord(wbox, j));
                    }
                }
                // Update max point.
                for (int j = 3; j < 6; j++)
                {
                    if (omni.Util.getWord(box, j).AsInt() < omni.Util.getWord(wbox, j).AsInt())
                    {
                        box = omni.Util.setWord(box, j, omni.Util.getWord(wbox, j));
                    }
                }
            }
            return(box);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Spawns a AI on a passed path.
        /// </summary>
        /// <param name="ainame"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static DemoPlayer SpawnOnPath(string ainame, SimSet path)
        {
            if (!omni.console.isObject(path))
            {
                return(null);
            }

            Marker node = path.getObject((uint)r.Next(0, path.getCount() - 1));

            TransformF transform = node.getTransform();

            return(Spawn(ainame, transform));
        }
Exemplo n.º 11
0
        public void createDatablock()
        {
            GuiTreeViewCtrl DatablockEditorTypeTree     = "DatablockEditorTypeTree";
            GuiControl      DatablockEditorCreatePrompt = "DatablockEditorCreatePrompt";

            string className = DatablockEditorTypeTree.getItemText(DatablockEditorTypeTree.getSelectedItem());

            if (className != "")
            {
                // Need to prompt for a name.

                ((GuiTextEditCtrl)DatablockEditorCreatePrompt.findObjectByInternalName("CreateDatablockName", true))
                .setText("Name");
                ((GuiTextEditCtrl)DatablockEditorCreatePrompt.findObjectByInternalName("CreateDatablockName", true))
                .selectAllText();

                // Populate the copy source dropdown.

                GuiPopUpMenuCtrl list = DatablockEditorCreatePrompt.findObjectByInternalName("CopySourceDropdown",
                                                                                             true);
                list.clear();
                list.add("", 0);

                SimSet set   = "DataBlockSet";
                int    count = set.getCount();
                for (uint i = 0; i < count; i++)
                {
                    SimObject datablock      = set.getObject(i);
                    string    datablockClass = datablock.getClassName();

                    if (!Util.isMemberOfClass(datablockClass, className))
                    {
                        continue;
                    }

                    list.add(datablock.getName(), ((int)i + 1));
                }

                // Set up state of client-side checkbox.

                GuiCheckBoxCtrl clientSideCheckBox =
                    DatablockEditorCreatePrompt.findObjectByInternalName("ClientSideCheckBox", true);
                bool canBeClientSide = this.canBeClientSideDatablock(className);
                clientSideCheckBox.setStateOn(canBeClientSide);
                clientSideCheckBox.setActive(canBeClientSide);

                // Show the dialog.

                ((GuiCanvas)"canvas").pushDialog(DatablockEditorCreatePrompt, 0, true);
            }
        }
Exemplo n.º 12
0
        public override void onWake()
        {
            /*
             * %this-->theName.setText( "" );
             *
             * %matList = %this-->theMaterialList;
             * %matList.clear();
             * %count = TerrainMaterialSet.getCount();
             * for ( %i=0; %i < %count; %i++ )
             * %matList.add( TerrainMaterialSet.getObject( %i ).internalName, %i );
             * %matList.setSelected( 0 );
             *
             * %rezList = %this-->theRezList;
             * %rezList.clear();
             * %rezList.add( "256", 256 );
             * %rezList.add( "512", 512 );
             * %rezList.add( "1024", 1024 );
             * %rezList.add( "2048", 2048 );
             * //%rezList.add( "4096", 4096 );
             * %rezList.setSelected( 256 );
             *
             * %this-->flatRadio.setStateOn( true );
             */
            ((GuiTextEditCtrl)this.findObjectByInternalName("theName", true)).setText("");
            GuiPopUpMenuCtrl matList = this.findObjectByInternalName("theMaterialList", true);

            matList.clear();
            SimSet TerrainMaterialSet = "TerrainMaterialSet";
            int    count = TerrainMaterialSet.getCount();

            for (uint i = 0; i < count; i++)
            {
                matList.add(
                    ((SimObject)TerrainMaterialSet.getObject(i)).internalName,
                    (int)i);
            }
            matList.setSelected(0);

            GuiPopUpMenuCtrl rezList = this.findObjectByInternalName("theRezList", true);

            rezList.clear();
            rezList.add("256", 256);
            rezList.add("512", 512);
            rezList.add("1024", 1024);
            rezList.add("2048", 2048);

            rezList.setSelected(256);

            ((GuiRadioCtrl)this.findObjectByInternalName("flatRadio", true)).setStateOn(true);
        }
Exemplo n.º 13
0
        public static void sfxStopAll(SimSet channel)
        {
            channel = sfxOldChannelToGroup(channel);

            if (!channel.isObject())
            {
                return;
            }

            for (uint i = 0; i < channel.getCount(); i++)
            {
                ((SFXSource)channel.getObject(i)).stop(-1);
            }
            //SFXSource.stop(channel.getObject(i), -1);
        }
Exemplo n.º 14
0
        public static void messageAllExcept(GameConnectionToClient client, string msgType, string msgString, params string[] args)
        {
            //can exclude a client, a team or both. A -1 value in either field will ignore that exclusion, so
            //messageAllExcept(-1, -1, $Mesblah, 'Blah!'); will message everyone (since there shouldn't be a client -1 or client on team -1).
            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            for (uint i = 0; i < ClientGroup.getCount(); i++)
            {
                GameConnectionToClient recipient = ClientGroup.getObject(i).As <GameConnectionToClient>();
                if (recipient.getId() != client.getId())
                {
                    messageClient(recipient, msgType, msgString, args);
                }
            }
        }
Exemplo n.º 15
0
        public static void ClearCenterPrintAll()
        {
            SimSet ClientGroup = "ClientGroup";
            int    count       = ClientGroup.getCount();

            for (uint i = 0; i < count; i++)
            {
                GameConnection cl = ClientGroup.getObject(i);
                if (!cl.isAIControlled())
                {
                    t3d.console.commandToClient(cl, "ClearCenterPrint");
                }
            }
            //foreach (uint client in t3d.ClientGroup.Cast<GameConnection>().Where(client => !client.isAIControlled()))
            //   t3d.console.commandToClient(client.AsString(), "ClearCenterPrint");
        }
Exemplo n.º 16
0
        public void initList(string filter)
        {
            GuiStackControl SFXParametersStack = this.FOT("SFXParametersStack");
            SimSet          SFXParameterGroup  = "SFXParameterGroup";

            // Clear the current lists.

            SFXParametersStack.clear();

            // Add each SFXParameter in SFXParameterGroup.

            for (uint i = 0; i < SFXParameterGroup.getCount(); i++)
            {
                SimObject obj = SFXParameterGroup.getObject(i);
                if (!Util.isMemberOfClass(obj.getClassName(), "SFXParameter"))
                {
                    continue;
                }

                // If we have a filter, search for it in the parameter's
                // categories.

                bool matchesFilter = true;
                if (filter != "")
                {
                    matchesFilter = false;

                    for (int idx = 0; obj["categories[" + idx + "]"] != ""; idx++)
                    {
                        if (obj["categories[" + idx + "]"] == filter)
                        {
                            matchesFilter = true;
                            break;
                        }
                    }
                }

                if (matchesFilter)
                {
                    this.addParameter((SFXParameter)obj);
                }
            }

            // Init the filters.

            this.initFilterList(filter);
        }
Exemplo n.º 17
0
        /// Resumes the playback of paused sound sources.
        ///
        /// @param %pauseSet    An optional SimSet which contains the paused sound
        /// sources to be resumed.  If not specified the global
        /// SFXPausedSet is used.
        /// @deprecated
        public static void sfxResume(SimSet pauseSet = null)
        {
            if (pauseSet == null)
            {
                pauseSet = SFXPausedSet;
            }

            int count = pauseSet.getCount();

            for (uint i = 0; i < count; i++)
            {
                SFXSource source = pauseSet.getObject(i).As <SFXSource>();
                source.play();
            }

            // Clear our pause set... the caller is left
            // to clear his own if he passed one.
            pauseSet.clear();
        }
Exemplo n.º 18
0
        public void snapshotMaterials()
        {
            if (!"TerrainMaterialDlgSnapshot".isObject())
            {
                new ObjectCreator("SimGroup", "TerrainMaterialDlgSnapshot").Create();
            }

            SimGroup group = "TerrainMaterialDlgSnapshot";
            SimSet   TerrainMaterialSet = "TerrainMaterialSet";

            group.clear();

            int matCount = TerrainMaterialSet.getCount();

            for (uint i = 0; i < matCount; i++)
            {
                TerrainMaterial mat = TerrainMaterialSet.getObject(i);
                if (!mat.isMemberOfClass("TerrainMaterial"))
                {
                    continue;
                }

                ObjectCreator oc = new ObjectCreator("ScriptObject");
                oc["parentGroup"]       = group.ID;
                oc["material"]          = mat;
                oc["internalName"]      = mat["internalName"];
                oc["diffuseMap"]        = mat["diffuseMap"];
                oc["normalMap"]         = mat["normalMap"];
                oc["detailMap"]         = mat["detailMap"];
                oc["macroMap"]          = mat["macroMap"];
                oc["detailSize"]        = mat["detailSize"];
                oc["diffuseSize"]       = mat["diffuseSize"];
                oc["detailStrength"]    = mat["detailStrength"];
                oc["detailDistance"]    = mat["detailDistance"];
                oc["macroSize"]         = mat["macroSize"];
                oc["macroStrength"]     = mat["macroStrength"];
                oc["macroDistance"]     = mat["macroDistance"];
                oc["useSideProjection"] = mat["useSideProjection"];
                oc["parallaxScale"]     = mat["parallaxScale"];
                oc.Create();
            }
        }
Exemplo n.º 19
0
        public void buildTree()
        {
            // Refresh the material list.
            GuiTreeViewCtrl matLibTree = FOT("matLibTree");

            matLibTree.clear();

            int root = matLibTree.insertItem(0, "RootMaterial", "RootMaterial", "");

            //TerrainPainterAddition
            SimSet TerrainMaterialSet = "TerrainMaterialSet";

            for (uint i = 0; i < TerrainMaterialSet.getCount(); i++)
            {
                TerrainMaterial mat = TerrainMaterialSet.getObject(i);
                if (!mat.isObject())
                {
                    continue;
                }

                string terrainFolderName = mat["terrainFolder"];
                if (terrainFolderName == "")
                {
                    terrainFolderName = "Unused";
                }

                int folder = matLibTree.findItemByName(terrainFolderName);
                if (folder == 0)
                {
                    folder = matLibTree.insertItem(root, terrainFolderName, terrainFolderName, "");
                }

                if (matLibTree.getParentItem(folder) == root)
                {
                    matLibTree.insertObject(folder, mat, true);
                }
            }
        }
Exemplo n.º 20
0
        public static void endMission()
        {
            if (!Global.isObject("MissionGroup"))
            {
                return;
            }

            Global.echo("*** ENDING MISSION");

            Torque3D.LevelInfo TheLevelInfo = Sim.FindObject <Torque3D.LevelInfo>("TheLevelInfo");

            // Inform the game code we're done.
            //todo onMissionEnded
            TheLevelInfo.call("onMissionEnded");

            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            // Inform the clients
            for (uint clientIndex = 0; clientIndex < ClientGroup.getCount(); clientIndex++)
            {
                // clear ghosts and paths from all clients
                GameConnectionToClient cl = ClientGroup.getObject(clientIndex).As <GameConnectionToClient>();
                cl.endMission();
                cl.resetGhosting();
                cl.clearPaths();
            }

            SimGroup MissionGroup   = Sim.FindObject <SimGroup>("MissionGroup");
            SimGroup MissionCleanup = Sim.FindObject <SimGroup>("MissionCleanup");

            // Delete everything
            MissionGroup.delete();
            MissionCleanup.delete();

            Global.clearServerPaths();
        }
            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);
            }
Exemplo n.º 22
0
        public static void loadMissionStage2()
        {
            Global.echo("*** Stage 2 load");

            // Create the mission group off the ServerGroup
            Globals.SetString("instantGroup", "ServerGroup");

            // Make sure the mission exists
            string file = Globals.GetString("Server::MissionFile");

            if (!Global.isFile(file))
            {
                Globals.SetString("Server::LoadFailMsg", "Could not find mission \"" + file + "\"");
            }
            else
            {
                // Calculate the mission CRC.  The CRC is used by the clients
                // to caching mission lighting.
                Globals.SetInt("missionCRC", Global.getFileCRC(file));

                // Exec the mission.  The MissionGroup (loaded components) is added to the ServerGroup
                Global.exec(file);

                if (!Global.isObject("MissionGroup"))
                {
                    Globals.SetString("Server::LoadFailMsg", "No 'MissionGroup' found in mission \"" + file + "\".");
                }
            }

            SimSet ClientGroup = Sim.FindObject <SimSet>("ClientGroup");

            if (Globals.GetString("Server::LoadFailMsg") != "")
            {
                // Inform clients that are already connected
                for (uint clientIndex = 0; clientIndex < ClientGroup.getCount(); clientIndex++)
                {
                    Message.messageClient(ClientGroup.getObject(clientIndex).As <GameConnectionToClient>(), "MsgLoadFailed".Tag(), Globals.GetString("Server::LoadFailMsg"));
                }
                return;
            }

            Torque3D.LevelInfo TheLevelInfo = Sim.FindObject <Torque3D.LevelInfo>("TheLevelInfo");

            // Set mission name.
            if (Global.isObject("TheLevelInfo"))
            {
                Globals.SetString("Server::MissionName", TheLevelInfo.getFieldValue("levelName"));
            }

            // Mission cleanup group.  This is where run time components will reside.  The MissionCleanup
            // group will be added to the ServerGroup.
            SimGroup MissionCleanup = new SimGroup("MissionCleanup", true);

            // Make the MissionCleanup group the place where all new objects will automatically be added.
            Globals.SetInt("instantGroup", MissionCleanup.getId());

            // Construct MOD paths
            Global.pathOnMissionLoadDone();

            // Mission loading done...
            Global.echo("*** Mission loaded");

            // Start all the clients in the mission
            Globals.SetBool("missionRunning", true);
            for (uint clientIndex = 0; clientIndex < ClientGroup.getCount(); clientIndex++)
            {
                ClientGroup.getObject(clientIndex).As <GameConnectionToClient>().loadMission();
            }

            // Go ahead and launch the game
            //todo onMissionStart
            TheLevelInfo.call("onMissionStart");
        }
Exemplo n.º 23
0
            public void navigate(string address)
            {
                GuiDynamicCtrlArrayControl CreatorIconArray = "CreatorIconArray";
                CreatorPopupMenu           CreatorPopupMenu = "CreatorPopupMenu";

                CreatorIconArray.frozen = true;
                CreatorIconArray.clear();
                CreatorPopupMenu.clear();

                if (this.tab.ToLower() == "Scripted".ToLower())
                {
                    string category  = Util.getWord(address, 1);
                    SimSet dataGroup = "DataBlockGroup";

                    for (uint i = 0; i < dataGroup.getCount(); i++)
                    {
                        SimObject obj = dataGroup.getObject(i);
                        // echo ("Obj: " + obj.getName() + " - " + obj.category );

                        if (obj["category"] == "" && obj["category"].AsInt() == 0)
                        {
                            continue;
                        }

                        // Add category to popup menu if not there already
                        if (CreatorPopupMenu.findText(obj["category"]) == -1)
                        {
                            CreatorPopupMenu.add(obj["category"]);
                        }

                        if (address == "")
                        {
                            string ctrl = this.findIconCtrl(obj["category"]);
                            if (ctrl == "-1")
                            {
                                this.addFolderIcon(obj["category"]);
                            }
                        }
                        else if (address.ToLower() == obj["category"].ToLower())
                        {
                            string ctrl = this.findIconCtrl(obj.getName());
                            if (ctrl == "-1")
                            {
                                this.addShapeIcon(obj);
                            }
                        }
                    }
                }

                if (this.tab.ToLower() == "Meshes".ToLower())
                {
                    string fullPath =
                        Util.findFirstFileMultiExpr("*.dts" + '\t' + "*.dae" + '\t' + "*.kmz" + '\t' + "*.dif", true);

                    while (fullPath != "")
                    {
                        if (Util.strstr(fullPath, "cached.dts") != -1)
                        {
                            fullPath =
                                Util.findNextFileMultiExpr("*.dts" + '\t' + "*.dae" + '\t' + "*.kmz" + '\t' + "*.dif");
                            continue;
                        }

                        fullPath = Util.makeRelativePath(fullPath, Util.getMainDotCsDir());
                        string splitPath = Util.strreplace(fullPath, "/", " ");
                        if (Util.getWord(splitPath, 0) == "tools")
                        {
                            fullPath =
                                Util.findNextFileMultiExpr("*.dts" + '\t' + "*.dae" + '\t' + "*.kmz" + '\t' + "*.dif");
                            continue;
                        }

                        int dirCount = Util.getWordCount(splitPath) - 1;

                        string pathFolders = Util.getWords(splitPath, 0, dirCount - 1);

                        // Add this file's path (parent folders) to the
                        // popup menu if it isn't there yet.
                        string temp = Util.strreplace(pathFolders, " ", "/");
                        int    re   = CreatorPopupMenu.findText(temp);
                        if (re == -1)
                        {
                            CreatorPopupMenu.add(temp);
                        }

                        // Is this file in the current folder?
                        if (Util.stricmp(pathFolders, address) == 0)
                        {
                            this.addStaticIcon(fullPath);
                        }
                        // Then is this file in a subfolder we need to add
                        // a folder icon for?
                        else
                        {
                            int  wordIdx = 0;
                            bool add     = false;

                            if (address == "")
                            {
                                add     = true;
                                wordIdx = 0;
                            }
                            else
                            {
                                for (; wordIdx < dirCount; wordIdx++)
                                {
                                    temp = Util.getWords(splitPath, 0, wordIdx);
                                    if (Util.stricmp(temp, address) == 0)
                                    {
                                        add = true;
                                        wordIdx++;
                                        break;
                                    }
                                }
                            }

                            if (add == true)
                            {
                                string folder = Util.getWord(splitPath, wordIdx);

                                SimObject ctrl = this.findIconCtrl(folder);
                                if (ctrl == 0)
                                {
                                    this.addFolderIcon(folder);
                                }
                            }
                        }

                        fullPath = Util.findNextFileMultiExpr("*.dts" + '\t' + "*.dae" + '\t' + "*.kmz" + '\t' + "*.dif");
                    }
                }

                if (this.tab.ToLower() == "Level".ToLower())
                {
                    // Add groups to popup menu
                    array = this.array;
                    array.sortk(false);

                    int count = array.count();

                    if (count > 0)
                    {
                        string lastGroup = "";

                        for (int i = 0; i < count; i++)
                        {
                            string group = array.getKey(i);

                            if (group != lastGroup)
                            {
                                CreatorPopupMenu.add(group);

                                if (address == "")
                                {
                                    this.addFolderIcon(group);
                                }
                            }

                            if (address.ToLower() == group.ToLower())
                            {
                                ScriptObject args      = array.getValue(i);
                                string       className = args["val[0]"];
                                string       name      = args["val[1]"];
                                string       func      = args["val[2]"];

                                this.addMissionObjectIcon(className, name, func);
                            }

                            lastGroup = group;
                        }
                    }
                }

                if (this.tab.ToLower() == "Prefabs".ToLower())
                {
                    string expr     = "*.prefab";
                    string fullPath = Util.findFirstFile(expr);

                    while (fullPath != "")
                    {
                        fullPath = Util.makeRelativePath(fullPath, Util.getMainDotCsDir());
                        string splitPath = Util.strreplace(fullPath, "/", " ");
                        if (Util.getWord(splitPath, 0) == "tools")
                        {
                            fullPath = Util.findNextFile(expr);
                            continue;
                        }

                        int dirCount = Util.getWordCount(splitPath) - 1;

                        string pathFolders = Util.getWords(splitPath, 0, dirCount - 1);

                        // Add this file's path (parent folders) to the
                        // popup menu if it isn't there yet.
                        string temp = Util.strreplace(pathFolders, " ", "/");
                        int    re   = CreatorPopupMenu.findText(temp);
                        if (re == -1)
                        {
                            CreatorPopupMenu.add(temp);
                        }

                        // Is this file in the current folder?
                        if (Util.stricmp(pathFolders, address) == 0)
                        {
                            this.addPrefabIcon(fullPath);
                        }
                        // Then is this file in a subfolder we need to add
                        // a folder icon for?
                        else
                        {
                            int  wordIdx = 0;
                            bool add     = false;

                            if (address == "")
                            {
                                add     = true;
                                wordIdx = 0;
                            }
                            else
                            {
                                for (; wordIdx < dirCount; wordIdx++)
                                {
                                    temp = Util.getWords(splitPath, 0, wordIdx);
                                    if (Util.stricmp(temp, address) == 0)
                                    {
                                        add = true;
                                        wordIdx++;
                                        break;
                                    }
                                }
                            }

                            if (add == true)
                            {
                                string folder = Util.getWord(splitPath, wordIdx);

                                SimObject ctrl = this.findIconCtrl(folder);
                                if (ctrl == 0)
                                {
                                    this.addFolderIcon(folder);
                                }
                            }
                        }

                        fullPath = Util.findNextFile(expr);
                    }
                }

                CreatorIconArray.sort("alphaIconCompare");

                for (uint i = 0; i < CreatorIconArray.getCount(); i++)
                {
                    ((SimObject)CreatorIconArray.getObject(i))["autoSize"] = false.AsString();
                }

                CreatorIconArray.frozen = false;
                CreatorIconArray.refresh();

                // Recalculate the array for the parent guiScrollCtrl
                CreatorIconArray.getParent().call("computeSizes");

                this.address = address;

                CreatorPopupMenu.sort();

                string str = Util.strreplace(address, " ", "/");

                if (str != "")
                {
                    int r = CreatorPopupMenu.findText(str);
                    if (r != -1)
                    {
                        CreatorPopupMenu.setSelected(r, false);
                    }
                    else
                    {
                        CreatorPopupMenu.setText(str);
                    }
                }
                else
                {
                    CreatorPopupMenu.setText("");
                }
                CreatorPopupMenu.tooltip = str;
            }
Exemplo n.º 24
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");
            }
        }