Exemple #1
0
        public override void onWake()
        {
            GuiTextListCtrl CL_levelList = "CL_levelList";

            CL_levelList.clear();
            ChooseLevelWindow          ChooseLevelWindow = "ChooseLevelWindow";
            GuiDynamicCtrlArrayControl SmallPreviews     = ((GuiDynamicCtrlArrayControl)((GuiWindowCtrl)"ChooseLevelWindow").findObjectByInternalName("SmallPreviews", false));

            ((GuiDynamicCtrlArrayControl)ChooseLevelWindow.findObjectByInternalName("SmallPreviews", false)).clear();
            string file = "";

            for (file = Util.findFirstFile(sGlobal["$Server::MissionFileSpec"], true); file != ""; file = Util.findNextFile(sGlobal["$Server::MissionFileSpec"]))
            {
                // Skip our new level/mission if we arent choosing a level
                // to launch in the editor.
                if (!this["launchInEditor"].AsBool())
                {
                    if (Util.strstr(file, "newMission.mis") > -1)
                    {
                        continue;
                    }
                    if (Util.strstr(file, "newLevel.mis") > -1)
                    {
                        continue;
                    }
                }
                addMissionFile(file);
            }
            // Also add the new level mission as defined in the world editor settings
            // if we are choosing a level to launch in the editor.
            if (this["launchInEditor"].AsBool())
            {
                file = ((Settings)"EditorSettings").value("WorldEditor/newLevelFile");
                if (file != "")
                {
                    addMissionFile(file);
                }
            }
            // Sort our list
            CL_levelList.sort("0");

            // Set the first row as the selected row
            CL_levelList.setSelectedRow(0);

            GuiBitmapButtonCtrl preview;

            for (int i = 0; i < CL_levelList.rowCount(); i++)
            {
                ObjectCreator oc = new ObjectCreator("GuiBitmapButtonCtrl");
                oc["internalName"] = "SmallPreview" + i;
                oc["Extent"]       = "108 81";
                oc["bitmap"]       = "art/gui/no-preview";
                oc["command"]      = "ChooseLevelWindow.previewSelected(ChooseLevelWindow->SmallPreviews->SmallPreview" + i + ");";
                preview            = oc.Create();
                SmallPreviews.add(preview);
                // Set this small preview visible
                if (i > 5)
                {
                    preview.setVisible(false);
                }
                // Set the level index
                preview["levelIndex"] = i.AsString();
                // Get the name
                string name = Util.getField(CL_levelList.getRowText(i), 0);
                preview["levelName"] = name;
                file = Util.getField(CL_levelList.getRowText(i), 1);
                // Find the preview image
                string levelPreview = Util.filePath(file) + "/" + Util.fileBase(file) + "_preview";
                // Test against all of the different image formats
                // This should probably be moved into an engine function
                if (Util.isFile(levelPreview + ".png") || Util.isFile(levelPreview + ".jpg") || Util.isFile(levelPreview + ".bmp") || Util.isFile(levelPreview + ".gif") || Util.isFile(levelPreview + ".jng") || Util.isFile(levelPreview + ".mng") || Util.isFile(levelPreview + ".tga"))
                {
                    preview.setBitmap(levelPreview);
                }
                // Get the description
                String desc = Util.getField(CL_levelList.getRowText(i), 2);
                preview["levelDesc"] = desc;
            }

            SmallPreviews["firstVisible"] = "-1";
            SmallPreviews["lastVisible"]  = "-1";

            if (SmallPreviews.getCount() > 0)
            {
                SmallPreviews["firstVisible"] = "0";
                if (SmallPreviews.getCount() < 6)
                {
                    SmallPreviews["lastVisible"] = (SmallPreviews.getCount() - 1).AsString();
                }
                else
                {
                    SmallPreviews["lastVisible"] = "4";
                }
            }

            if (SmallPreviews.getCount() > 0)
            {
                ChooseLevelWindow.previewSelected(SmallPreviews.getObject(0));
            }
            // If we have 5 or less previews then hide our next/previous buttons
            // and resize to fill their positions

            if (SmallPreviews.getCount() < 6)
            {
                ((GuiBitmapButtonCtrl)ChooseLevelWindow.findObjectByInternalName("PreviousSmallPreviews", false)).setVisible(false);
                ((GuiBitmapButtonCtrl)ChooseLevelWindow.findObjectByInternalName("NextSmallPreviews", false)).setVisible(false);

                Point2I previewPos  = SmallPreviews.getPosition();
                Point2I previousPos = ((GuiBitmapButtonCtrl)ChooseLevelWindow.findObjectByInternalName("PreviousSmallPreviews", false)).getPosition();

                SmallPreviews.setPosition(previousPos.x, previewPos.y);

                SmallPreviews.colSpacing = 10;
                SmallPreviews.refresh();
            }

            if (SmallPreviews.getCount() <= 1)
            {
                // Hide the small previews
                SmallPreviews.setVisible(false);
                // Shrink the ChooseLevelWindow so that we don't have a large blank space

                ChooseLevelWindow.setExtent(new Point2F(ChooseLevelWindow.getExtent().x + " " + SmallPreviews.getPosition().y));

                ChooseLevelWindow.setExtent(new Point2F(ChooseLevelWindow.getExtent().x, SmallPreviews.getPosition().y));
            }
            else
            {
                // Make sure the small previews are visible
                SmallPreviews.setVisible(true);

                int extentX = ChooseLevelWindow.getExtent().x;
                int extentY = SmallPreviews.getPosition().y;
                extentY  = extentY + SmallPreviews.getExtent().y;
                extentY += 9;
                ChooseLevelWindow.setExtent(new Point2F(extentX, extentY));
            }
        }
Exemple #2
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;
            }