Exemplo n.º 1
0
        private static void ImportRoomList(Game game, BinaryReader reader, string fullPathToGameFiles, CompileMessages importErrors)
        {
            Dictionary<int, UnloadedRoom> rooms = new Dictionary<int, UnloadedRoom>();
            foreach (string roomFileFullPath in Utilities.GetDirectoryFileList(Path.GetDirectoryName(fullPathToGameFiles), "room*.crm"))
            {
                int roomNumber = GetRoomNumberFromFileName(Path.GetFileName(roomFileFullPath));

                if (roomNumber >= 0)
                {
                    try
                    {
                        string roomScript = Factory.NativeProxy.LoadRoomScript(roomFileFullPath);
                        if (roomScript != null)
                        {
                            StreamWriter sw = new StreamWriter(roomFileFullPath.Substring(0, roomFileFullPath.Length - 4) + ".asc", false, Encoding.Default);
                            sw.Write(roomScript);
                            sw.Close();
                        }
                    }
                    catch (AGSEditorException ex)
                    {
                        importErrors.Add(new CompileError("There was an error saving the script for room " + roomNumber + ": " + ex.Message));
                    }

                    UnloadedRoom newUnloadedRoom = new UnloadedRoom(roomNumber);
                    rooms.Add(roomNumber, newUnloadedRoom);
                    game.Rooms.Add(newUnloadedRoom);
                }
                else
                {
                    importErrors.Add(new CompileWarning("The room file '" + roomFileFullPath + "' does not have a recognised name and will not be part of the game."));
                }
            }

            ((List<IRoom>)game.Rooms).Sort();

            int roomCount = reader.ReadInt32();
            for (int i = 0; i < roomCount; i++)
            {
                string roomDescription = ReadNullTerminatedString(reader);
                if (rooms.ContainsKey(i))
                {
                    rooms[i].Description = roomDescription;
                }
            }
        }
Exemplo n.º 2
0
        public void ShowCreateRoomTemplateWizard(UnloadedRoom room)
        {
            List<WizardPage> pages = new List<WizardPage>();
            MakeTemplateWizardPage templateCreationPage = new MakeTemplateWizardPage(_agsEditor.TemplatesDirectory, ".art");
            pages.Add(templateCreationPage);

            WizardDialog dialog = new WizardDialog("Room Template", "This wizard will guide you through the process of creating a room template. A room template allows you to easily create new rooms based off an existing one.", pages);
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string templateFileName = templateCreationPage.GetFullPath();
                try
                {
                    if (File.Exists(templateFileName))
                    {
                        File.Delete(templateFileName);
                    }
                    BinaryWriter writer = new BinaryWriter(new FileStream(ROOM_TEMPLATE_ID_FILE, FileMode.Create, FileAccess.Write));
                    writer.Write(ROOM_TEMPLATE_ID_FILE_SIGNATURE);
                    writer.Write(room.Number);
                    writer.Close();

                    Factory.NativeProxy.CreateTemplateFile(templateFileName, ConstructRoomTemplateFileList(room));

                    File.Delete(ROOM_TEMPLATE_ID_FILE);

                    Factory.GUIController.ShowMessage("Template created successfully. To try it out, create a new room.", MessageBoxIcon.Information);
                }
                catch (AGSEditorException ex)
                {
                    Factory.GUIController.ShowMessage("There was an error creating your template: " + ex.Message, MessageBoxIcon.Warning);
                }
                catch (Exception ex)
                {
                    Factory.GUIController.ShowMessage("There was an error creating your template. The error was: " + ex.Message + Environment.NewLine + Environment.NewLine + "Error details: " + ex.ToString(), MessageBoxIcon.Warning);
                }
            }

            dialog.Dispose();
        }
Exemplo n.º 3
0
 public Room LoadRoom(UnloadedRoom roomToLoad)
 {
     return _native.LoadRoomFile(roomToLoad);
 }
Exemplo n.º 4
0
        private void ImportExistingRoomFile(string fileName)
        {
            bool selectedFileInGameDirectory = false;
            if (Path.GetDirectoryName(fileName).ToLower() == _agsEditor.GameDirectory.ToLower())
            {
                selectedFileInGameDirectory = true;
            }

            int newRoomNumber, fileRoomNumber = -1;
            string fileNameWithoutPath = Path.GetFileName(fileName);
            Match match = Regex.Match(fileNameWithoutPath, @"room(\d+).crm", RegexOptions.IgnoreCase);
            if ((match.Success) && (match.Groups.Count == 2))
            {
                fileRoomNumber = Convert.ToInt32(match.Groups[1].Captures[0].Value);
                if (_agsEditor.CurrentGame.DoesRoomNumberAlreadyExist(fileRoomNumber))
                {
                    if (selectedFileInGameDirectory)
                    {
                        _guiController.ShowMessage("This file is already part of this game.", MessageBoxIcon.Information);
                        return;
                    }
                    _guiController.ShowMessage("This game already has a room " + fileRoomNumber + ". If you are sure that you want to import this file, rename it first.", MessageBoxIcon.Warning);
                    return;
                }
                newRoomNumber = fileRoomNumber;
            }
            else
            {
                newRoomNumber = _agsEditor.CurrentGame.FindFirstAvailableRoomNumber(0);
            }

            try
            {
                string newFileName = string.Format("room{0}.crm", newRoomNumber);
                string newScriptName = Path.ChangeExtension(newFileName, ".asc");

                if (selectedFileInGameDirectory)
                {
                    if (!File.Exists(newScriptName))
                    {
                        CopyScriptOutOfOldRoomFile(fileName, newScriptName);
                    }
                    if (newRoomNumber != fileRoomNumber)
                    {
                        File.Copy(fileName, newFileName, true);
                    }
                }
                else
                {
                    File.Copy(fileName, newFileName, true);

                    if (File.Exists(Path.ChangeExtension(fileName, ".asc")))
                    {
                        File.Copy(Path.ChangeExtension(fileName, ".asc"), newScriptName, true);
                    }
                    else
                    {
                        CopyScriptOutOfOldRoomFile(fileName, newScriptName);
                    }
                }

                UnloadedRoom newRoom = new UnloadedRoom(newRoomNumber);
                _agsEditor.CurrentGame.Rooms.Add(newRoom);
                _agsEditor.CurrentGame.FilesAddedOrRemoved = true;

                RePopulateTreeView();
                RoomListTypeConverter.SetRoomList(_agsEditor.CurrentGame.Rooms);
                _guiController.ShowMessage("Room file imported successfully as room " + newRoomNumber + ".", MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                _guiController.ShowMessage("There was a problem importing the room file: " + ex.Message, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 5
0
 private string[] ConstructRoomTemplateFileList(UnloadedRoom room)
 {
     List<string> files = new List<string>();
     Utilities.AddAllMatchingFiles(files, Path.ChangeExtension(room.FileName, ".ico"));
     Utilities.AddAllMatchingFiles(files, ROOM_TEMPLATE_ID_FILE);
     Utilities.AddAllMatchingFiles(files, room.FileName);
     Utilities.AddAllMatchingFiles(files, room.ScriptFileName);
     return files.ToArray();
 }
Exemplo n.º 6
0
 private ContentDocument CreateOrShowScript(UnloadedRoom selectedRoom)
 {
     ContentDocument scriptEditor = GetScriptEditor(selectedRoom);
     _guiController.AddOrShowPane(_roomScriptEditors[selectedRoom.Number]);
     return scriptEditor;
 }
Exemplo n.º 7
0
        private ContentDocument GetScriptEditor(UnloadedRoom selectedRoom)
        {
            if ((_roomScriptEditors.ContainsKey(selectedRoom.Number)) &&
                (!_roomScriptEditors[selectedRoom.Number].Visible))
            {
                DisposePane(_roomScriptEditors[selectedRoom.Number]);
                _roomScriptEditors.Remove(selectedRoom.Number);
            }

            if (!_roomScriptEditors.ContainsKey(selectedRoom.Number))
            {
                if (selectedRoom.Script == null)
                {
                    selectedRoom.LoadScript();
                }
                ScriptEditor scriptEditor = new ScriptEditor(selectedRoom.Script, _agsEditor);
                scriptEditor.RoomNumber = selectedRoom.Number;
                scriptEditor.IsModifiedChanged += new EventHandler(ScriptEditor_IsModifiedChanged);
                if ((_loadedRoom != null) && (_loadedRoom.Number == selectedRoom.Number))
                {
                    scriptEditor.Room = _loadedRoom;
                }
                _roomScriptEditors.Add(selectedRoom.Number, new ContentDocument(scriptEditor, selectedRoom.Script.FileName, this));
                _roomScriptEditors[selectedRoom.Number].ToolbarCommands = scriptEditor.ToolbarIcons;
                _roomScriptEditors[selectedRoom.Number].MainMenu = scriptEditor.ExtraMenu;
            }

            return _roomScriptEditors[selectedRoom.Number];
        }
Exemplo n.º 8
0
        private void AddTreeNodeForRoom(UnloadedRoom room)
        {
            string iconName = ROOM_ICON_UNLOADED;

            if ((_loadedRoom != null) && (room.Number == _loadedRoom.Number))
            {
                iconName = ROOM_ICON_LOADED;
            }

            ProjectTree treeController = _guiController.ProjectTree;
            treeController.AddTreeBranch(this, TREE_PREFIX_ROOM_NODE + room.Number, room.Number.ToString() + ": " + room.Description, iconName);
            treeController.AddTreeLeaf(this, TREE_PREFIX_ROOM_SETTINGS + room.Number, "Edit room", iconName);
            treeController.AddTreeLeaf(this, TREE_PREFIX_ROOM_SCRIPT + room.Number, "Room script", "ScriptIcon");
        }
Exemplo n.º 9
0
        private void CreateNewRoom(int roomNumber, RoomTemplate template)
        {
            UnloadedRoom newRoom = new UnloadedRoom(roomNumber);
            if (!PromptForAndDeleteAnyExistingRoomFile(newRoom.FileName))
            {
                return;
            }

            try
            {
                if (template.FileName == null)
                {
                    Resources.ResourceManager.CopyFileFromResourcesToDisk("blank.crm", newRoom.FileName);
                    StreamWriter sw = new StreamWriter(newRoom.ScriptFileName);
                    sw.WriteLine("// room script file");
                    sw.Close();
                }
                else
                {
                    _nativeProxy.ExtractRoomTemplateFiles(template.FileName, newRoom.Number);
                }

                _agsEditor.CurrentGame.Rooms.Add(newRoom);
                _guiController.ProjectTree.StartFromNode(this, TOP_LEVEL_COMMAND_ID);
                AddTreeNodeForRoom(newRoom);
                _agsEditor.CurrentGame.FilesAddedOrRemoved = true;
            //                _guiController.ProjectTree.AddTreeLeaf(this, TREE_PREFIX_ROOM_NODE + newRoom.Number, newRoom.Number.ToString() + ": ", ROOM_ICON_UNLOADED);
                _guiController.ProjectTree.SelectNode(this, TREE_PREFIX_ROOM_NODE + newRoom.Number);
                RoomListTypeConverter.SetRoomList(_agsEditor.CurrentGame.Rooms);
            }
            catch (Exception ex)
            {
                _guiController.ShowMessage("There was an error attempting to create the new room. The error was: " + ex.Message, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 10
0
        private void RenameRoom(int currentNumber, int numberRequested)
        {
            UnloadedRoom room = _agsEditor.CurrentGame.FindRoomByID(numberRequested);
            if (room != null)
            {
                _guiController.ShowMessage("There is already a room number " + numberRequested + ". Please choose another number.", MessageBoxIcon.Warning);
            }
            else if ((numberRequested < 0) || (numberRequested > UnloadedRoom.HIGHEST_ROOM_NUMBER_ALLOWED))
            {
                _guiController.ShowMessage("The new room number must be between 0 and " + UnloadedRoom.HIGHEST_ROOM_NUMBER_ALLOWED + ".", MessageBoxIcon.Warning);
            }
            else if (UnloadedRoom.DoRoomFilesExist(numberRequested))
            {
                _guiController.ShowMessage("Your game directory already has an existing file with the target room number.", MessageBoxIcon.Warning);
            }
            else if (SaveRoomAndShowAnyErrors(_loadedRoom))
            {
                UnloadedRoom oldRoom = FindRoomByID(currentNumber);
                UnloadedRoom tempNewRoom = new UnloadedRoom(numberRequested);
                CloseRoomScriptEditorIfOpen(currentNumber);
                UnloadCurrentRoom();

                _agsEditor.SourceControlProvider.RenameFileOnDiskAndInSourceControl(oldRoom.FileName, tempNewRoom.FileName);
                _agsEditor.SourceControlProvider.RenameFileOnDiskAndInSourceControl(oldRoom.ScriptFileName, tempNewRoom.ScriptFileName);

                oldRoom.Number = numberRequested;

                LoadDifferentRoom(oldRoom);
                _guiController.AddOrShowPane(_roomSettings);
                _agsEditor.CurrentGame.FilesAddedOrRemoved = true;
                RePopulateTreeView();
            }
        }
Exemplo n.º 11
0
 private Room LoadNewRoomIntoMemory(UnloadedRoom newRoom, CompileMessages errors)
 {
     if ((newRoom.Script == null) || (!newRoom.Script.Modified))
     {
         try
         {
             newRoom.LoadScript();
         }
         catch (FileNotFoundException)
         {
             _guiController.ShowMessage("The script file '" + newRoom.ScriptFileName + "' is missing. An empty script has been loaded instead.", MessageBoxIcon.Warning);
         }
     }
     else if (_roomScriptEditors.ContainsKey(newRoom.Number))
     {
         ((ScriptEditor)_roomScriptEditors[newRoom.Number].Control).UpdateScriptObjectWithLatestTextInWindow();
     }
     _loadedRoom = _nativeProxy.LoadRoom(newRoom);
     _loadedRoom.Modified = ImportExport.CreateInteractionScripts(_loadedRoom, errors);
     _loadedRoom.Modified |= HookUpInteractionVariables(_loadedRoom);
     _loadedRoom.Modified |= AddPlayMusicCommandToPlayerEntersRoomScript(_loadedRoom, errors);
     if (_loadedRoom.Script.Modified)
     {
         if (_roomScriptEditors.ContainsKey(_loadedRoom.Number))
         {
             ((ScriptEditor)_roomScriptEditors[_loadedRoom.Number].Control).ScriptModifiedExternally();
         }
     }
     return _loadedRoom;
 }
Exemplo n.º 12
0
        private bool LoadDifferentRoom(UnloadedRoom newRoom)
        {
            if ((_roomSettings != null) && (_roomSettings.Visible))
            {
                // give them a chance to save the current room first
                bool cancelLoad = false;
                ((RoomSettingsEditor)_roomSettings.Control).PanelClosing(true, ref cancelLoad);
                if (cancelLoad)
                {
                    return false;
                }
            }

            // lock to stop the load proceeding until a save has finished,
            // just to make sure we don't end up with a race condition if
            // the user is madly clicking around
            lock (_roomLoadingOrSavingLock)
            {
                UnloadCurrentRoomAndGreyOutTree();

                if (!File.Exists(newRoom.FileName))
                {
                    _guiController.ShowMessage("The file '" + newRoom.FileName + "' was not found. Unable to open this room.", MessageBoxIcon.Warning);
                }
                else
                {
                    CompileMessages errors = new CompileMessages();

                    LoadNewRoomIntoMemory(newRoom, errors);

                    _loadedRoom.RoomModifiedChanged += _modifiedChangedHandler;

                    string paneTitle = "Room " + _loadedRoom.Number + (_loadedRoom.Modified ? " *" : "");

                    _roomSettings = new ContentDocument(new RoomSettingsEditor(_loadedRoom), paneTitle, this, ConstructPropertyObjectList(_loadedRoom));
                    _roomSettings.SelectedPropertyGridObject = _loadedRoom;
                    ((RoomSettingsEditor)_roomSettings.Control).SaveRoom += new RoomSettingsEditor.SaveRoomHandler(RoomEditor_SaveRoom);
                    ((RoomSettingsEditor)_roomSettings.Control).AbandonChanges += new RoomSettingsEditor.AbandonChangesHandler(RoomsComponent_AbandonChanges);

                    if (_loadedRoom.Modified)
                    {
                        CreateOrShowScript(_loadedRoom);
                    }

                    if (_roomScriptEditors.ContainsKey(_loadedRoom.Number))
                    {
                        ((ScriptEditor)_roomScriptEditors[_loadedRoom.Number].Control).Room = _loadedRoom;
                        if (_loadedRoom.Modified)
                        {
                            ((ScriptEditor)_roomScriptEditors[_loadedRoom.Number].Control).ScriptModifiedExternally();
                        }
                    }

                    ProjectTree treeController = _guiController.ProjectTree;
                    treeController.ChangeNodeIcon(this, TREE_PREFIX_ROOM_NODE + _loadedRoom.Number, ROOM_ICON_LOADED);
                    treeController.ChangeNodeIcon(this, TREE_PREFIX_ROOM_SETTINGS + _loadedRoom.Number, ROOM_ICON_LOADED);

                    _guiController.ShowOutputPanel(errors);
                }

                return true;
            }
        }
Exemplo n.º 13
0
        private static void ImportRoomList(Game game, BinaryReader reader, string fullPathToGameFiles, CompileMessages importErrors)
        {
            Dictionary<int, UnloadedRoom> rooms = new Dictionary<int, UnloadedRoom>();
            foreach (string roomFileFullPath in Utilities.GetDirectoryFileList(Path.GetDirectoryName(fullPathToGameFiles), "room*.crm"))
            {
                int roomNumber = GetRoomNumberFromFileName(Path.GetFileName(roomFileFullPath));

                if (roomNumber >= 0)
                {
                    try
                    {
                        string roomScript = Factory.NativeProxy.LoadRoomScript(roomFileFullPath);
                        if (roomScript != null)
                        {
                            StreamWriter sw = new StreamWriter(roomFileFullPath.Substring(0, roomFileFullPath.Length - 4) + ".asc", false, Encoding.Default);
                            sw.Write(roomScript);
                            sw.Close();
                        }
                    }
                    catch (AGSEditorException ex)
                    {
                        importErrors.Add(new CompileError("Erreur lors de la sauvegarde du script de la pièce " + roomNumber + " : " + ex.Message));
                    }

                    UnloadedRoom newUnloadedRoom = new UnloadedRoom(roomNumber);
                    rooms.Add(roomNumber, newUnloadedRoom);
                    game.RootRoomFolder.Items.Add(newUnloadedRoom);
                }
                else
                {
                    importErrors.Add(new CompileWarning("Le fichier de pièce '" + roomFileFullPath + "' possède un nom non-reconnu et ne sera pas intégré au jeu."));
                }
            }

            game.RootRoomFolder.Sort(false);

            int roomCount = reader.ReadInt32();
            for (int i = 0; i < roomCount; i++)
            {
                string roomDescription = ReadNullTerminatedString(reader);
                if (rooms.ContainsKey(i))
                {
                    rooms[i].Description = roomDescription;
                }
            }
        }
Exemplo n.º 14
0
 public int CompareTo(UnloadedRoom other)
 {
     return(CompareTo(other));
 }