public static void StartSelectedDemo()
        {
            // first unit is filename
            GuiTextListCtrl RecordingsDlgList = "RecordingsDlgList";
            int             sel     = RecordingsDlgList.getSelectedId();
            string          rowText = RecordingsDlgList.getRowTextById(sel);

            string file = omni.sGlobal["$currentMod"] + "/recordings/" + omni.Util.getField(rowText, 0) + ".rec";

            GameConnection ServerConnection = new ObjectCreator("GameConnection", "ServerConnection").Create();

            ((SimGroup)"RootGroup").add(ServerConnection);

            // Start up important client-side stuff, such as the group
            // for particle emitters.  This doesn't get launched during a demo
            // as we short circuit the whole mission loading sequence.
            mission.clientStartMission();

            if (ServerConnection.playDemo(file))
            {
                ((GuiCanvas)"canvas").setContent("PlayGui");
                ((GuiCanvas)"canvas").popDialog("RecordingsDlg");
                ServerConnection.call("prepDemoPlayback");
            }
            else
            {
                messageBox.MessageBoxOK("Playback Failed", "Demo playback failed for file '" + file + "'.", "");
                if ("ServerConnection".isObject())
                {
                    "ServerConnection".delete();
                }
            }
        }
        public static void TerrainImportGui_TerrainMaterialApplyCallback(string mat, string matIndex)
        {
            // Skip over a bad selection.
            if (!mat.isObject())
            {
                return;
            }
            GuiTextListCtrl opacityList =
                ((GuiControl)"TerrainImportGui").findObjectByInternalName("OpacityLayerTextList", true);
            string itemIdx = ((SimObject)"TerrainImportGui")["activeIdx"];

            if (itemIdx.AsInt() < 0 || itemIdx == "")
            {
                return;
            }

            string rowTxt = opacityList.getRowTextById(itemIdx.AsInt());

            int columTxtCount = omni.Util.getFieldCount(rowTxt);

            if (columTxtCount > 2)
            {
                rowTxt = omni.Util.getFields(rowTxt, 0, 1);
            }

            opacityList.setRowById(itemIdx.AsInt(), rowTxt + "\t" + ((SimObject)mat).internalName + "/t" + mat);
        }
        public virtual void update(GameConnection clientId, string name, bool isSuperAdmin, bool isAdmin, bool isAI,
                                   int score, int kills, int deaths)
        {
            // Build the row to display.  The name can have ML control tags, including
            // color and font.  Since we're not using an ML control here, we need to
            // strip them off.

            string tag = isSuperAdmin ? "[Super]" : (isAdmin ? "[Admin]" : (isAI ? "[Bot]" : ""));

            string text = string.Format("{0} {1}\t{2}\t{3}\t{4}", Util.StripMLControlChars(name), tag, score, kills,
                                        deaths);
            // Update or add the player to the control

            GuiTextListCtrl PlayerListGuiList = "PlayerListGuiList";

            if (clientId == -1)
            {
                PlayerListGuiList.addRow(clientId, text, -1);
            }
            else
            {
                PlayerListGuiList.setRowById(clientId, text);
            }

            // Sorts by score

            PlayerListGuiList.sortNumerical(1, false);
            PlayerListGuiList.clearSelection();
        }
Beispiel #4
0
        public static void DbgWatchDialogEdit()
        {
            GuiTextEditCtrl      EditWatchDialogValue = "EditWatchDialogValue";
            GuiTextListCtrl      DebuggerWatchView    = "DebuggerWatchView";
            DebuggerEditWatchDlg DebuggerEditWatchDlg = "DebuggerEditWatchDlg";
            TCPDebugger          TCPDebugger          = "TCPDebugger";
            GuiCanvas            Canvas = "Canvas";

            string newValue = EditWatchDialogValue.getValue();
            int    id       = DebuggerWatchView.getSelectedId();

            if (id >= 0)
            {
                string row  = DebuggerWatchView.getRowTextById(id);
                string expr = omni.Util.getField(row, 0);
                string assignment;
                if (newValue == "")
                {
                    assignment = expr + " = \"\"";
                }
                else
                {
                    assignment = expr + " = " + newValue;
                }
                TCPDebugger.send("EVAL " + id + " 0 " + assignment + "\r\n");
            }
            Canvas.popDialog(DebuggerEditWatchDlg);
        }
Beispiel #5
0
        public void addMissionFile(string file)
        {
            string levelName = Util.fileBase(file);
            string levelDesc = "A Torque Level";

            string _LevelInfoObject = getLevelInfo(file);

            if (_LevelInfoObject != "0")
            {
                ScriptObject LevelInfoObject = _LevelInfoObject;

                if (LevelInfoObject["levelName"] != "")
                {
                    levelName = LevelInfoObject["levelName"];
                }
                else if (LevelInfoObject["name"] != "")
                {
                    levelName = LevelInfoObject["name"];
                }

                if (LevelInfoObject["desc0"] != "")
                {
                    levelDesc = LevelInfoObject["desc0"];
                }

                LevelInfoObject.delete();
            }

            GuiTextListCtrl CL_levelList = "CL_levelList";

            CL_levelList.addRow(CL_levelList.rowCount(), levelName + "\t" + file + "\t" + levelDesc, -1);
        }
Beispiel #6
0
        public static void StartLevel(string mission, string hostingType)
        {
            GuiTextListCtrl CL_levelList = "CL_levelList";

            if (mission == "")
            {
                mission = omni.Util.getField(CL_levelList.getRowTextById(CL_levelList.getSelectedId()), 1);
            }

            string serverType = hostingType;

            if (serverType == "")
            {
                if (omni.bGlobal["$pref::HostMultiPlayer"])
                {
                    serverType = "MultiPlayer";
                }
                else
                {
                    serverType = "SinglePlayer";
                }
            }

            // Show the loading screen immediately.
            if ("LoadingGui".isObject())
            {
                ((GuiCanvas)"Canvas").setContent("LoadingGui");
                ((GuiProgressBitmapCtrl)"LoadingProgress").setValue("1");
                ((GuiTextCtrl)"LoadingProgressTxt").setValue("LOADING MISSION FILE");
                ((GuiCanvas)"Canvas").repaint(-1);
            }

            server.createAndConnectToLocalServer(serverType, mission);
        }
Beispiel #7
0
        public static void ClientCmdGameEnd(string endgamepause)
        {
            audio.sfxStopAll("");


            if (GuiCanvas.EditorIsActive() || GuiCanvas.GuiEditorIsActive())
            {
                return;
            }
            // Copy the current scores from the player list into the
            // end game gui (bit of a hack for now).
            GuiTextListCtrl EndGameGuiList = "EndGameGuiList";

            EndGameGuiList.clear();

            GuiTextListCtrl PlayerListGuiList = "PlayerListGuiList";

            for (int i = 0; i < PlayerListGuiList.rowCount(); i++)
            {
                string text = PlayerListGuiList.getRowText(i);
                string id   = PlayerListGuiList.getRowId(i).AsString();
                EndGameGuiList.addRow(id.AsInt(), text, -1);
            }
            EndGameGuiList.sortNumerical(1, false);
            ((GuiCanvas)"Canvas").setContent("EndGameGui");

            if (endgamepause.AsInt() > 0)
            {
                omni.Util._schedule((endgamepause.AsInt() * 1000).AsString(), "0", "ShowLoading");
            }
        }
        public static void TerrainImportGuiAddOpacityMap(string name)
        {
            // TODO: Need to actually look at
            // the file here and figure
            // out how many channels it has.
            string txt = omni.Util.makeRelativePath(name, omni.Util.getWorkingDirectory());
            // Will need to do this stuff
            // once per channel in the file
            // currently it works with just grayscale.

            string channelsTxt = "R\tG\tB\tA";
            string bitmapInfo  = omni.Util.getBitmapInfo(name);

            string channelCount = omni.Util.getWord(bitmapInfo, 2);

            GuiTextListCtrl opacityList =
                ((GuiControl)"TerrainImportGui").findObjectByInternalName("OpacityLayerTextList", true);

            guiTerrainImportGui TerrainImportGui = "TerrainImportGui";
            ArrayObject         namesArray       = TerrainImportGui["namesArray"];
            ArrayObject         channelsArray    = TerrainImportGui["channelsArray"];


            for (int i = 0; i < channelCount.AsInt(); i++)
            {
                namesArray.push_back(txt, name);
                channelsArray.push_back(txt, omni.Util.getWord(channelsTxt, i) + "/t" + channelCount);
                //TerrainImportGui.namesArray.echo();
                int count = opacityList.rowCount();
                opacityList.addRow(count, txt + "/t" + omni.Util.getWord(channelsTxt, i), -1);
            }
            //OpacityMapListBox.addItem( %name );
        }
Beispiel #9
0
        public static void redoMapping(string device, string action, string cmd, int oldIndex, int newIndex)
        {
            ((ActionMap)"moveMap").bind(device, action, cmd);

            GuiTextListCtrl remapList = ((OptRemapInputCtrl)"OptRemapInputCtrl").findObjectByInternalName("OptRemapList", true);

            remapList.setRowById(oldIndex, OptionsDlg.buildFullMapString(oldIndex));
            remapList.setRowById(newIndex, OptionsDlg.buildFullMapString(newIndex));
        }
Beispiel #10
0
        public static void DbgDeleteSelectedWatch()
        {
            GuiTextListCtrl DebuggerWatchView = "DebuggerWatchView";

            int selectedWatch = DebuggerWatchView.getSelectedId();
            int rowNum        = DebuggerWatchView.getRowNumById(selectedWatch);

            DebuggerWatchView.removeRow(rowNum);
        }
Beispiel #11
0
        public static void DbgRefreshWatches()
        {
            GuiTextListCtrl DebuggerWatchView = "DebuggerWatchView";
            TCPDebugger     TCPDebugger       = "TCPDebugger";

            for (int i = 0; i < DebuggerWatchView.rowCount(); i++)
            {
                int    id   = DebuggerWatchView.getRowId(i);
                string row  = DebuggerWatchView.getRowTextById(id);
                string expr = omni.Util.getField(row, 0);
                TCPDebugger.send("EVAL " + id + " 0 " + expr + "\r\n");
            }
        }
        public virtual void zeroScores()
        {
            GuiTextListCtrl PlayerListGuiList = "PlayerListGuiList";

            for (int i = 0; i < PlayerListGuiList.rowCount(); i++)
            {
                string text = PlayerListGuiList.getRowText(i);
                text = Util.setField(text, 1, "0");
                text = Util.setField(text, 2, "0");
                text = Util.setField(text, 3, "0");
                PlayerListGuiList.setRowById(PlayerListGuiList.getRowId(i), text);
            }
            PlayerListGuiList.clearSelection();
        }
Beispiel #13
0
        public void previewSelected(SimObject preview)
        {
            GuiTextListCtrl CL_levelList = "CL_levelList";

            if (preview.isObject() && preview["levelIndex"] != "")
            {
                CL_levelList.setSelectedRow(preview["levelIndex"].AsInt());
            }
            else
            {
                CL_levelList.setSelectedRow(-1);
            }

            // Set the large preview image
            if (preview.isObject() && preview["bitmap"] != "")
            {
                ((GuiBitmapCtrl)this.findObjectByInternalName("CurrentPreview", false)).setBitmapX(preview["bitmap"]);
            }
            else
            {
                ((GuiBitmapCtrl)this.findObjectByInternalName("CurrentPreview", false)).setBitmapX(
                    "art/gui/no-preview");
            }

            // Set the current level name
            if (preview.isObject() && preview["levelName"] != "")
            {
                ((GuiTextCtrl)this.findObjectByInternalName("LevelName", false)).setText(preview["levelName"]);
            }
            else
            {
                ((GuiTextCtrl)this.findObjectByInternalName("LevelName", false)).setText("Level");
            }

            // Set the current level description
            if (preview.isObject() && preview["levelDesc"] != "")
            {
                ((GuiMLTextCtrl)this.findObjectByInternalName("LevelDescription", false)).setText(
                    preview["levelDesc"]);
            }
            else
            {
                ((GuiMLTextCtrl)this.findObjectByInternalName("LevelDescription", false)).setText("A Torque Level");
            }
        }
Beispiel #14
0
        public static void DbgWatchDialogAdd()
        {
            GuiTextEditCtrl  WatchDialogExpression = "WatchDialogExpression";
            GuiTextListCtrl  DebuggerWatchView     = "DebuggerWatchView";
            TCPDebugger      TCPDebugger           = "TCPDebugger";
            DebuggerWatchDlg DebuggerWatchDlg      = "DebuggerWatchDlg";
            GuiCanvas        Canvas = "Canvas";

            string expr = WatchDialogExpression.getValue();

            if (expr != "")
            {
                DebuggerWatchView.setRowById(omni.iGlobal["$DbgWatchSeq"], expr + "\t(unknown)");
                TCPDebugger.send("EVAL " + omni.iGlobal["$DbgWatchSeq"] + " 0 " + expr + "\r\n");
                omni.iGlobal["$DbgWatchSeq"]++;
            }
            Canvas.popDialog(DebuggerWatchDlg);
        }
        public virtual void updateScore(GameConnection clientId, int score, int kills, int deaths)
        {
            GuiTextListCtrl PlayerListGuiList = "PlayerListGuiList";

            string text = PlayerListGuiList.getRowTextById(clientId);

            //Since I'm lazy and I don't feel like writing a csharp function...

            text = Util.setField(text, 1, score.AsString());
            text = Util.setField(text, 2, kills.AsString());
            text = Util.setField(text, 3, deaths.AsString());

            PlayerListGuiList.setRowById(clientId, text);

            // Sorts by score
            PlayerListGuiList.sortNumerical(1, false);
            PlayerListGuiList.clearSelection();
        }
Beispiel #16
0
            public void handleBreak(string line)
            {
                GuiTextCtrl       DebuggerStatus    = "DebuggerStatus";
                GuiTextListCtrl   DebuggerWatchView = "DebuggerWatchView";
                DebuggerCallStack DebuggerCallStack = "DebuggerCallStack";

                DebuggerStatus.setValue("BREAK");

                // Query all the watches.
                for (int i = 0; i < DebuggerWatchView.rowCount(); i++)
                {
                    int    id   = DebuggerWatchView.getRowId(i);
                    string row  = DebuggerWatchView.getRowTextById(id);
                    string expr = Util.getField(row, 0);
                    this.send("EVAL " + id + " 0 " + expr + "\r\n");
                }

                // Update the call stack window.
                DebuggerCallStack.clear();

                string file       = Util.getWord(line, 0);
                string lineNumber = Util.getWord(line, 1);
                string funcName   = Util.getWord(line, 2);

                DbgOpenFile(file, lineNumber.AsInt(), true);

                int nextWord = 3;
                //int rowId = 0;
                int iD = 0;

                while (true)
                {
                    DebuggerCallStack.setRowById(iD, file + "\t" + lineNumber + "\t" + funcName);
                    iD++;
                    file       = Util.getWord(line, nextWord);
                    lineNumber = Util.getWord(line, nextWord + 1);
                    funcName   = Util.getWord(line, nextWord + 2);
                    nextWord  += 3;
                    if (file == "")
                    {
                        break;
                    }
                }
            }
        public void removeOpacitymap()
        {
            GuiTextListCtrl opacityList =
                ((GuiControl)"TerrainImportGui").findObjectByInternalName("OpacityLayerTextList", true);
            int itemIdx = opacityList.getSelectedId();

            if (itemIdx < 0)
            {
                return;
            }

            ArrayObject namesArray    = this["namesArray"];
            ArrayObject channelsArray = this["channelsArray"];

            namesArray.erase(itemIdx);
            channelsArray.erase(itemIdx);

            opacityList.removeRowById(itemIdx);
        }
        public void onOpacityListDblClick()
        {
            GuiTextListCtrl opacityList =
                ((GuiControl)"TerrainImportGui").findObjectByInternalName("OpacityLayerTextList", true);

            int itemIdx = opacityList.getSelectedId();

            if (itemIdx < 0)
            {
                return;
            }

            this["activeIdx"] = itemIdx.AsString();
            string rowTxt = opacityList.getRowTextById(itemIdx);
            string matTxt = Util.getField(rowTxt, 2);
            string matID  = Util.getField(rowTxt, 3);

            "TerrainMaterialDlg".call("showByObjectId",
                                      new string[] { matID, "TerrainImportGui_TerrainMaterialApplyCallback" });
        }
Beispiel #19
0
        public void update()
        {
            // Copy the servers into the server list.
            ((GuiWindowCtrl)"JS_queryStatus").setVisible(false);

            GuiTextListCtrl JS_serverList = "JS_serverList";

            JS_serverList.clear();

            int sc = Util.getServerCount();

            for (int i = 0; i < sc; i++)
            {
                Util.setServerInfo((uint)i);
                JS_serverList.addRow(i, sGlobal["$ServerInfo::Name"] + '\t' + sGlobal["$ServerInfo::Ping"] + "\t" + sGlobal["$ServerInfo::PlayerCount"] + "/" + sGlobal["$ServerInfo::MaxPlayers"] + "/t" + sGlobal["$ServerInfo::Version"] + "\t" + sGlobal["$ServerInfo::MissionName"], -1);
            }
            JS_serverList.sort("0");
            JS_serverList.setSelectedRow(0);
            JS_serverList.scrollVisible(0);
            ((GuiButtonCtrl)"JS_joinServer").setActive(JS_serverList.rowCount() > 0);
        }
        public override void onExitMission()
        {
            ShapeEditor.ShapeEdShapeView ShapeEdShapeView = "ShapeEdShapeView";
            ShapeEditor ShapeEditor = "ShapeEditor";

            ShapeEditorActions.ShapeEdUndoManager ShapeEdUndoManager  = "ShapeEdUndoManager";
            ShapeEditor.ShapeEdSequenceList       ShapeEdSequenceList = "ShapeEdSequenceList";
            ShapeEditor.ShapeEdNodeTreeView       ShapeEdNodeTreeView = "ShapeEdNodeTreeView";
            ShapeEdPropWindow ShapeEdPropWindow = "ShapeEdPropWindow";

            ShapeEditor.ShapeEdDetailTree ShapeEdDetailTree = "ShapeEdDetailTree";
            GuiTextListCtrl ShapeEdMaterialList             = "ShapeEdMaterialList";

            ShapeEditor.ShapeEdMountWindow  ShapeEdMountWindow  = "ShapeEdMountWindow";
            ShapeEditor.ShapeEdThreadWindow ShapeEdThreadWindow = "ShapeEdThreadWindow";
            ShapeEditor.ShapeEdThreadList   ShapeEdThreadList   = "ShapeEdThreadList";

            GuiTextListCtrl mountList = ShapeEdMountWindow.FOT("mountList");
            GuiTextListCtrl seqList   = ShapeEdThreadWindow.FOT("seqList");

            // unselect the current shape
            ShapeEdShapeView.setModel("");
            if (ShapeEditor.shape != 0)
            {
                ShapeEditor.shape.delete();
            }
            ShapeEditor.shape = 0;
            ShapeEdUndoManager.clearAll();
            ShapeEditor.setDirty(false);

            ShapeEdSequenceList.clear();
            ShapeEdNodeTreeView.removeItem(0);
            ShapeEdPropWindow.update_onNodeSelectionChanged(-1);
            ShapeEdDetailTree.removeItem(0);
            ShapeEdMaterialList.clear();

            mountList.clear();
            seqList.clear();
            ShapeEdThreadList.clear();
        }
Beispiel #21
0
        public static void StartGame(string mission = null, string hostingType = null)
        {
            if (string.IsNullOrEmpty(mission))
            {
                GuiTextListCtrl CL_levelList = Sim.FindObject <GuiTextListCtrl>("CL_levelList");
                int             id           = CL_levelList.getSelectedId();
                mission = Global.getField(CL_levelList.getRowTextById(id), 1);
                // Alternatively:
                //error("Cannot start a level with no level selected!");
            }

            string serverType = hostingType;

            if (string.IsNullOrEmpty(hostingType))
            {
                if (Globals.GetBool("pref::HostMultiPlayer"))
                {
                    serverType = "MultiPlayer";
                }
                else
                {
                    serverType = "SinglePlayer";
                }
            }

            // Show the loading screen immediately.
            if (Global.isObject("LoadingGui"))
            {
                Core.Canvas.GameCanvas.setContent("LoadingGui");
                GuiProgressBitmapCtrl LoadingProgress    = Sim.FindObject <GuiProgressBitmapCtrl>("LoadingProgress");
                GuiTextCtrl           LoadingProgressTxt = Sim.FindObject <GuiTextCtrl>("LoadingProgressTxt");
                LoadingProgress.setValue("1");
                LoadingProgressTxt.setValue("LOADING MISSION FILE");
                Core.Canvas.GameCanvas.repaint();
            }

            Server.Server.createAndConnectToLocalServer(serverType, mission);
        }
Beispiel #22
0
            public void handleEvalOut(string line)
            {
                GuiTextCtrl     DebuggerCursorWatch = "DebuggerCursorWatch";
                GuiTextListCtrl DebuggerWatchView   = "DebuggerWatchView";

                int    id    = Util.firstWord(line).AsInt();
                string value = Util.restWords(line);

                // See if it's the cursor watch, or from the watch window.
                if (id < 0)
                {
                    DebuggerCursorWatch.setText(DebuggerCursorWatch["expr"] + ' ' + "=" + ' ' + value);
                }
                else
                {
                    string row = DebuggerWatchView.getRowTextById(id);
                    if (row == "")
                    {
                        return;
                    }
                    string expr = Util.getField(row, 0);
                    DebuggerWatchView.setRowById(id, expr + "\t" + value);
                }
            }
Beispiel #23
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));
            }
        }
        public void import()
        {
            // Gather all the import settings.
            GuiTextEditCtrl HeightfieldFilename = this.findObjectByInternalName("HeightfieldFilename", true);
            string          heightMapPng        = HeightfieldFilename.getText();
            GuiTextEditCtrl MetersPerPixel      = this.findObjectByInternalName("MetersPerPixel", true);
            string          metersPerPixel      = MetersPerPixel.getText();
            GuiTextEditCtrl HeightScale         = findObjectByInternalName("HeightScale", true);
            string          heightScale         = HeightScale.getText();
            GuiCheckBoxCtrl FlipYAxis           = findObjectByInternalName("FlipYAxis", true);
            bool            flipYAxis           = FlipYAxis.isStateOn();

            editor Editor = "Editor";
            // Grab and validate terrain object name.

            string terrainName = ((GuiTextEditCtrl)this.findObjectByInternalName("TerrainName", true)).getText();

            if (!terrainName.isObject() && ((SimObject)terrainName).isMemberOfClass("TerrainBlock") &&
                !Editor.validateObjectName(terrainName, false))
            {
                return;
            }

            string opacityNames  = "";
            string materialNames = "";

            GuiTextListCtrl opacityList = this.findObjectByInternalName("OpacityLayerTextList", true);


            ArrayObject namesArray    = this["namesArray"];
            ArrayObject channelsArray = this["channelsArray"];

            for (int i = 0; i < opacityList.rowCount(); i++)
            {
                string itemText    = opacityList.getRowTextById(i);
                string opacityName = namesArray.getValue(i);
                string channelInfo = channelsArray.getValue(i);
                string channel     = Util.getWord(channelInfo, 0);

                string materialName = Util.getField(itemText, 2);
                opacityNames  += opacityName + "\t" + channel + "\n";
                materialNames += materialName + "\n";
            }

            int updated = Util.nameToID(terrainName);
            // This will update an existing terrain with the name %terrainName,
            // or create a new one if %terrainName isn't a TerrainBlock

            String obj = console.Call_Classname("TerrainBlock", "import",
                                                new string[]
            {
                terrainName, heightMapPng, metersPerPixel, heightScale, opacityNames, materialNames,
                flipYAxis.AsString()
            });

            ((GuiCanvas)"Canvas").popDialog(this);

            if (obj.isObject())
            {
                if (obj != updated.AsString())
                {
                    // created a new TerrainBlock
                    // Submit an undo action.
                    Extendable.MECreateUndoAction.submit(obj);
                }

                EWorldEditor EWorldEditor = "EWorldEditor";

                if (!EWorldEditor.isObject())
                {
                    throw new Exception("ObjectBuilderGui::processNewObject - EWorldEditor is missing!");
                }

                // Select it in the editor.
                EWorldEditor.clearSelection();
                EWorldEditor.selectObject(obj);
                // When we drop the selection don't store undo
                // state for it... the creation deals with it.

                EWorldEditor.dropSelection(obj.AsBool());

                EWorldEditor.isDirty = true;
                //Copyright Winterleaf Entertainment L.L.C. 2013
                ((TerrainPainter)"TerrainPainter").updateLayers("");
                //Copyright Winterleaf Entertainment L.L.C. 2013
            }
            else
            {
                messageBox.MessageBoxOK("Import Terrain", "Terrain import failed! Check console for error messages.",
                                        "Ok");
            }
        }