Inheritance: ISpriteFolder
Exemple #1
0
        public SpriteManager()
        {
            _spriteUpdateHandler = new SpriteFolder.SpritesUpdatedHandler(RootSpriteFolder_SpritesUpdated);
            InitializeComponent();
            spriteSelector.OnSelectionChanged += new SpriteSelector.SelectionChangedHandler(spriteSelector_OnSelectionChanged);

            _attachedToFolder = Factory.AGSEditor.CurrentGame.RootSpriteFolder;
            _attachedToFolder.SpritesUpdated += _spriteUpdateHandler;
        }
Exemple #2
0
        public void GameChanged()
        {
            if (_attachedToFolder != null)
            {
                _attachedToFolder.SpritesUpdated -= _spriteUpdateHandler;
            }
            _attachedToFolder = Factory.AGSEditor.CurrentGame.RootSpriteFolder;
            _attachedToFolder.SpritesUpdated += _spriteUpdateHandler;

            spriteSelector.SetDataSource(_attachedToFolder);
        }
Exemple #3
0
        public Game()
        {
            _guis                    = new GUIFolders(GUIFolder.MAIN_GUI_FOLDER_NAME);
            _inventoryItems          = new InventoryItemFolders(InventoryItemFolder.MAIN_INVENTORY_ITEM_FOLDER_NAME);
            _cursors                 = new List <MouseCursor>();
            _dialogs                 = new DialogFolders(DialogFolder.MAIN_DIALOG_FOLDER_NAME);
            _fonts                   = new List <Font>();
            _characters              = new CharacterFolders(CharacterFolder.MAIN_CHARACTER_FOLDER_NAME);
            _plugins                 = new List <Plugin>();
            _translations            = new List <Translation>();
            _rooms                   = new UnloadedRoomFolders(UnloadedRoomFolder.MAIN_UNLOADED_ROOM_FOLDER_NAME);
            _oldInteractionVariables = new List <OldInteractionVariable>();
            _settings                = new Settings();
            _defaultSetup            = new RuntimeSetup(_settings);
            _workspaceState          = new WorkspaceState();
            _palette                 = new PaletteEntry[PALETTE_SIZE];
            _sprites                 = new SpriteFolder("Main");
            _views                   = new ViewFolders("Main");
            _audioClips              = new AudioClipFolders("Main");
            _audioClipTypes          = new List <AudioClipType>();
            _textParser              = new TextParser();
            _lipSync                 = new LipSync();
            _propertySchema          = new CustomPropertySchema();
            _globalVariables         = new GlobalVariables();
            _globalMessages          = new string[NUMBER_OF_GLOBAL_MESSAGES];
            _deletedViewIDs          = new Dictionary <int, object>();
            _scripts                 = new ScriptFolders(ScriptFolder.MAIN_SCRIPT_FOLDER_NAME);
            _scriptsToCompile        = new ScriptsAndHeaders();
            ScriptAndHeader globalScript = new ScriptAndHeader(
                new Script(Script.GLOBAL_HEADER_FILE_NAME, "// script header\r\n", true),
                new Script(Script.GLOBAL_SCRIPT_FILE_NAME, "// global script\r\n", false));

            ((IList <ScriptAndHeader>)_scripts).Add(globalScript);
            _playerCharacter = null;

            for (int i = 0; i < _globalMessages.Length; i++)
            {
                _globalMessages[i] = string.Empty;
            }

            InitializeDefaultPalette();
        }
Exemple #4
0
        /// <summary>
        /// Finds the SpriteFolder object for the folder that contains the sprite.
        /// Returns null if the sprite is not found.
        /// </summary>
        /// <param name="spriteNumber">Sprite number to look for</param>
        public SpriteFolder FindFolderThatContainsSprite(int spriteNumber)
        {
            foreach (Sprite sprite in _sprites)
            {
                if (sprite.Number == spriteNumber)
                {
                    return(this);
                }
            }

            foreach (SpriteFolder subFolder in this.SubFolders)
            {
                SpriteFolder found = subFolder.FindFolderThatContainsSprite(spriteNumber);
                if (found != null)
                {
                    return(found);
                }
            }
            return(null);
        }
Exemple #5
0
        public Game()
        {
            _guis = new GUIFolders(GUIFolder.MAIN_GUI_FOLDER_NAME);
            _inventoryItems = new InventoryItemFolders(InventoryItemFolder.MAIN_INVENTORY_ITEM_FOLDER_NAME);
            _cursors = new List<MouseCursor>();
            _dialogs = new DialogFolders(DialogFolder.MAIN_DIALOG_FOLDER_NAME);
            _fonts = new List<Font>();
            _characters = new CharacterFolders(CharacterFolder.MAIN_CHARACTER_FOLDER_NAME);
            _plugins = new List<Plugin>();
            _translations = new List<Translation>();
            _rooms = new UnloadedRoomFolders(UnloadedRoomFolder.MAIN_UNLOADED_ROOM_FOLDER_NAME);
            _oldInteractionVariables = new List<OldInteractionVariable>();
            _settings = new Settings();
            _workspaceState = new WorkspaceState();
            _palette = new PaletteEntry[PALETTE_SIZE];
            _sprites = new SpriteFolder("Main");
            _views = new ViewFolders("Main");
            _audioClips = new AudioClipFolders("Main");
            _audioClipTypes = new List<AudioClipType>();
            _textParser = new TextParser();
            _lipSync = new LipSync();
            _propertySchema = new CustomPropertySchema();
            _globalVariables = new GlobalVariables();
            _globalMessages = new string[NUMBER_OF_GLOBAL_MESSAGES];
            _deletedViewIDs = new Dictionary<int, object>();
            _scripts = new ScriptFolders(ScriptFolder.MAIN_SCRIPT_FOLDER_NAME);
            _scriptsToCompile = new ScriptsAndHeaders();
            ScriptAndHeader globalScript = new ScriptAndHeader(
                new Script(Script.GLOBAL_HEADER_FILE_NAME, "// script header\r\n", true),
                new Script(Script.GLOBAL_SCRIPT_FILE_NAME, "// global script\r\n", false));
            ((IList<ScriptAndHeader>)_scripts).Add(globalScript);
            _playerCharacter = null;

            for (int i = 0; i < _globalMessages.Length; i++)
            {
                _globalMessages[i] = string.Empty;
            }

            InitializeDefaultPalette();
        }
Exemple #6
0
        public Game()
        {
            _guis                    = new List <GUI>();
            _inventoryItems          = new List <InventoryItem>();
            _cursors                 = new List <MouseCursor>();
            _dialogs                 = new List <Dialog>();
            _fonts                   = new List <Font>();
            _characters              = new List <Character>();
            _plugins                 = new List <Plugin>();
            _translations            = new List <Translation>();
            _rooms                   = new RoomList();
            _oldInteractionVariables = new List <OldInteractionVariable>();
            _settings                = new Settings();
            _palette                 = new PaletteEntry[PALETTE_SIZE];
            _sprites                 = new SpriteFolder("Main");
            _views                   = new ViewFolder("Main");
            _audioClips              = new AudioClipFolder("Main");
            _audioClipTypes          = new List <AudioClipType>();
            _textParser              = new TextParser();
            _lipSync                 = new LipSync();
            _propertySchema          = new CustomPropertySchema();
            _globalVariables         = new GlobalVariables();
            _globalMessages          = new string[NUMBER_OF_GLOBAL_MESSAGES];
            _deletedViewIDs          = new Dictionary <int, object>();
            _scripts                 = new Scripts();
            _scriptsToCompile        = new Scripts();
            _scripts.Add(new Script(Script.GLOBAL_HEADER_FILE_NAME, "// script header\r\n", true));
            _scripts.Add(new Script(Script.GLOBAL_SCRIPT_FILE_NAME, "// global script\r\n", false));
            _playerCharacter = null;

            for (int i = 0; i < _globalMessages.Length; i++)
            {
                _globalMessages[i] = string.Empty;
            }

            InitializeDefaultPalette();
        }
Exemple #7
0
        public Game()
        {
            _guis = new List<GUI>();
            _inventoryItems = new List<InventoryItem>();
            _cursors = new List<MouseCursor>();
            _dialogs = new List<Dialog>();
            _fonts = new List<Font>();
            _characters = new List<Character>();
            _plugins = new List<Plugin>();
            _translations = new List<Translation>();
            _rooms = new RoomList();
            _oldInteractionVariables = new List<OldInteractionVariable>();
            _settings = new Settings();
            _palette = new PaletteEntry[PALETTE_SIZE];
            _sprites = new SpriteFolder("Main");
            _views = new ViewFolder("Main");
            _audioClips = new AudioClipFolder("Main");
            _audioClipTypes = new List<AudioClipType>();
            _textParser = new TextParser();
            _lipSync = new LipSync();
            _propertySchema = new CustomPropertySchema();
            _globalVariables = new GlobalVariables();
            _globalMessages = new string[NUMBER_OF_GLOBAL_MESSAGES];
            _deletedViewIDs = new Dictionary<int, object>();
            _scripts = new Scripts();
            _scriptsToCompile = new Scripts();
            _scripts.Add(new Script(Script.GLOBAL_HEADER_FILE_NAME, "// script header\r\n", true));
            _scripts.Add(new Script(Script.GLOBAL_SCRIPT_FILE_NAME, "// global script\r\n", false));
            _playerCharacter = null;

            for (int i = 0; i < _globalMessages.Length; i++)
            {
                _globalMessages[i] = string.Empty;
            }

            InitializeDefaultPalette();
        }
Exemple #8
0
        /// <summary>
        /// Import a 2.72-compatible CHA file. This code is horrid, but it's
        /// backwards compatible!!
        /// </summary>
        public static Character ImportCharacter272(string fileName, Game game)
        {
            BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));
            string fileSig = Encoding.ASCII.GetString(reader.ReadBytes(12));
            if (fileSig != CHARACTER_FILE_SIGNATURE)
            {
                reader.Close();
                throw new AGS.Types.InvalidDataException("This is not a valid AGS character file.");
            }
            int fileVersion = reader.ReadInt32();
            if ((fileVersion < 5) || (fileVersion > 6))
            {
                reader.Close();
                throw new AGS.Types.InvalidDataException("This character file is not supported by this version of AGS.");
            }

            Color []palette = new Color[256];
            for (int i = 0; i < 256; i++)
            {
                int r = reader.ReadByte();
                int g = reader.ReadByte();
                int b = reader.ReadByte();
                reader.ReadByte();
                palette[i] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            Character character = new Character();
            reader.ReadInt32();
            character.SpeechView = reader.ReadInt32();
            reader.ReadInt32();
            character.StartingRoom = reader.ReadInt32();
            reader.ReadInt32();
            character.StartX = reader.ReadInt32();
            character.StartY = reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            character.IdleView = reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            character.SpeechColor = reader.ReadInt32();
            character.ThinkingView = reader.ReadInt32();
            character.BlinkingView = reader.ReadInt16();
            reader.ReadInt16();
            reader.ReadBytes(40);
            character.MovementSpeed = reader.ReadInt16();
            character.AnimationDelay = reader.ReadInt16();
            reader.ReadBytes(606);
            character.RealName = ReadNullTerminatedString(reader, 40);
            character.ScriptName = ReadNullTerminatedString(reader, 20);
            if (character.ScriptName.Length > 0)
            {
                character.ScriptName = "c" + Char.ToUpper(character.ScriptName[0]) + character.ScriptName.Substring(1).ToLower();

                EnsureCharacterScriptNameIsUnique(character, game);
            }
            reader.ReadInt16();

            string viewNamePrefix = character.ScriptName;
            if (viewNamePrefix.StartsWith("c")) viewNamePrefix = viewNamePrefix.Substring(1);

            SpriteFolder folder = new SpriteFolder(character.ScriptName + "Sprites");
            character.NormalView = ReadAndAddView(viewNamePrefix + "Walk", reader, game, folder, palette);
            if (character.SpeechView > 0)
            {
                character.SpeechView = ReadAndAddView(viewNamePrefix + "Talk", reader, game, folder, palette);
            }
            else
            {
                character.SpeechView = 0;
            }

            if (character.IdleView > 0)
            {
                character.IdleView = ReadAndAddView(viewNamePrefix + "Idle", reader, game, folder, palette);
            }
            else
            {
                character.IdleView = 0;
            }

            if ((character.ThinkingView > 0) && (fileVersion >= 6))
            {
                character.ThinkingView = ReadAndAddView(viewNamePrefix + "Think", reader, game, folder, palette);
            }
            else
            {
                character.ThinkingView = 0;
            }

            if ((character.BlinkingView > 0) && (fileVersion >= 6))
            {
                character.BlinkingView = ReadAndAddView(viewNamePrefix + "Blink", reader, game, folder, palette);
            }
            else
            {
                character.BlinkingView = 0;
            }

            reader.Close();

            game.RootSpriteFolder.SubFolders.Add(folder);
            game.RootSpriteFolder.NotifyClientsOfUpdate();
            game.NotifyClientsViewsUpdated();

            return character;
        }
Exemple #9
0
        private static View ReadOldStyleView(BinaryReader reader, Game game, SpriteFolder folder, Color[] palette)
        {
            View view = new View();
            int i;
            int numLoops = reader.ReadInt16();
            int[] numFrames = new int[numLoops];
            for (i = 0; i < numLoops; i++)
            {
                view.AddNewLoop();
                numFrames[i] = reader.ReadInt16();
            }
            if (numLoops < 16)
            {
                reader.ReadBytes((16 - numLoops) * 2);
            }
            reader.ReadBytes(16 * 4 + 2);
            for (i = 0; i < 16; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    ViewFrame frame = new ViewFrame();
                    frame.ID = j;
                    frame.Image = reader.ReadInt32();
                    reader.ReadInt32();
                    frame.Delay = reader.ReadInt16();
                    reader.ReadBytes(2);
                    frame.Flipped = (reader.ReadInt32() == 1);
                    frame.Sound = reader.ReadInt32();
                    reader.ReadBytes(8);
                    if ((i < numLoops) && (j < numFrames[i]))
                    {
                        view.Loops[i].Frames.Add(frame);
                    }
                }
            }

            foreach (ViewLoop loop in view.Loops)
            {
                foreach (ViewFrame frame in loop.Frames)
                {
                    Sprite newSprite = ReadOldStyleViewFrame(reader, loop, frame, palette);
                    if (newSprite == null)
                    {
                        break;
                    }
                    folder.Sprites.Add(newSprite);
                    frame.Image = newSprite.Number;
                }
            }
            return view;
        }
Exemple #10
0
 private static int ReadAndAddView(string viewName, BinaryReader reader, Game game, SpriteFolder folder, Color[] palette)
 {
     View newView = ReadOldStyleView(reader, game, folder, palette);
     newView.ID = game.FindAndAllocateAvailableViewID();
     newView.Name = viewName;
     game.RootViewFolder.Views.Add(newView);
     return newView.ID;
 }
Exemple #11
0
 private static int ReadAndAddNewStyleView(XmlNode parentOfViewNode, Game game, Dictionary<int, int> spriteMapping, PaletteEntry[] palette, SpriteFolder newFolder)
 {
     View newView = new View(parentOfViewNode.SelectSingleNode("View"));
     newView.ID = game.FindAndAllocateAvailableViewID();
     ImportSpritesFromXML(parentOfViewNode, palette, newFolder, spriteMapping);
     UpdateViewWithSpriteMapping(newView, spriteMapping);
     EnsureViewNameIsUnique(newView, game);
     game.RootViewFolder.Views.Add(newView);
     return newView.ID;
 }
Exemple #12
0
 private static Dictionary<int, int> ImportSpritesFromXML(XmlNode spritesNode, PaletteEntry[] paletteEntries, SpriteFolder folderToAddTo)
 {
     Dictionary<int, int> spriteNumberMapping = new Dictionary<int, int>();
     ImportSpritesFromXML(spritesNode, paletteEntries, folderToAddTo, spriteNumberMapping);
     return spriteNumberMapping;
 }
Exemple #13
0
        public void FromXml(XmlNode node)
        {
            node = node.SelectSingleNode("Game");

            _settings.FromXml(node);

            if (node.SelectSingleNode(_defaultSetup.GetType().Name) != null)
            {
                // Only for >= 3.4.1
                _defaultSetup.FromXml(node);
            }

            _lipSync.FromXml(node);
            _propertySchema.FromXml(node);

            if (node.SelectSingleNode("InventoryHotspotMarker") != null)
            {
                // Pre-3.0.3
                InventoryHotspotMarker marker = new InventoryHotspotMarker();
                marker.FromXml(node);
                _settings.InventoryHotspotMarker = marker;
            }

            foreach (XmlNode msgNode in SerializeUtils.GetChildNodes(node, "GlobalMessages"))
            {
                _globalMessages[Convert.ToInt32(msgNode.Attributes["ID"].InnerText) - GLOBAL_MESSAGE_ID_START] = msgNode.InnerText;
            }

            _plugins.Clear();
            foreach (XmlNode pluginNode in SerializeUtils.GetChildNodes(node, "Plugins"))
            {
                _plugins.Add(new Plugin(pluginNode));
            }

            _rooms = new UnloadedRoomFolders(node.SelectSingleNode("Rooms").FirstChild, node);

            _guis = new GUIFolders(node.SelectSingleNode("GUIs").FirstChild, node);

            _inventoryItems = new InventoryItemFolders(node.SelectSingleNode("InventoryItems").FirstChild, node);

            _textParser = new TextParser(node.SelectSingleNode("TextParser"));

            _characters = new CharacterFolders(node.SelectSingleNode("Characters").FirstChild, node);

            _playerCharacter = null;
            string playerCharText = SerializeUtils.GetElementString(node, "PlayerCharacter");

            if (playerCharText.Length > 0)
            {
                int playerCharID = Convert.ToInt32(playerCharText);
                foreach (Character character in RootCharacterFolder.AllItemsFlat)
                {
                    if (character.ID == playerCharID)
                    {
                        _playerCharacter = character;
                        break;
                    }
                }
            }

            _dialogs = new DialogFolders(node.SelectSingleNode("Dialogs").FirstChild, node);

            _cursors.Clear();
            foreach (XmlNode cursNode in SerializeUtils.GetChildNodes(node, "Cursors"))
            {
                _cursors.Add(new MouseCursor(cursNode));
            }

            _fonts.Clear();
            foreach (XmlNode fontNode in SerializeUtils.GetChildNodes(node, "Fonts"))
            {
                _fonts.Add(new Font(fontNode));
            }

            _palette = ReadPaletteFromXML(node);

            _sprites = new SpriteFolder(node.SelectSingleNode("Sprites").FirstChild);

            _views = new ViewFolders(node.SelectSingleNode("Views").FirstChild);

            _deletedViewIDs.Clear();
            if (node.SelectSingleNode("DeletedViews") != null)
            {
                foreach (XmlNode transNode in SerializeUtils.GetChildNodes(node, "DeletedViews"))
                {
                    _deletedViewIDs.Add(Convert.ToInt32(transNode.InnerText), null);
                }
            }

            _scripts = new ScriptFolders(node.SelectSingleNode("Scripts").FirstChild, node);

            if (node.SelectSingleNode("AudioClips") != null)
            {
                _audioClips = new AudioClipFolders(node.SelectSingleNode("AudioClips").FirstChild);
            }
            else
            {
                _audioClips = new AudioClipFolders("Main");
                _audioClips.RootFolder.DefaultPriority = AudioClipPriority.Normal;
                _audioClips.RootFolder.DefaultRepeat   = InheritableBool.False;
                _audioClips.RootFolder.DefaultVolume   = 100;
            }

            _audioClipTypes.Clear();
            if (node.SelectSingleNode("AudioClipTypes") != null)
            {
                foreach (XmlNode clipTypeNode in SerializeUtils.GetChildNodes(node, "AudioClipTypes"))
                {
                    _audioClipTypes.Add(new AudioClipType(clipTypeNode));
                }
            }

            _translations.Clear();
            if (node.SelectSingleNode("Translations") != null)
            {
                foreach (XmlNode transNode in SerializeUtils.GetChildNodes(node, "Translations"))
                {
                    _translations.Add(new Translation(transNode));
                }
            }

            if (node.SelectSingleNode("GlobalVariables") != null)
            {
                _globalVariables = new GlobalVariables(node.SelectSingleNode("GlobalVariables"));
            }
            else
            {
                _globalVariables = new GlobalVariables();
            }

            _oldInteractionVariables.Clear();
            if (node.SelectSingleNode("OldInteractionVariables") != null)
            {
                foreach (XmlNode varNode in SerializeUtils.GetChildNodes(node, "OldInteractionVariables"))
                {
                    _oldInteractionVariables.Add(new OldInteractionVariable(SerializeUtils.GetAttributeString(varNode, "Name"), SerializeUtils.GetAttributeInt(varNode, "Value")));
                }
            }

            if (_savedXmlVersionIndex == null)
            {
                // Pre-3.0.3, upgrade co-ordinates
                ConvertCoordinatesToNativeResolution();
            }
        }
Exemple #14
0
        private void BuildNodeTree(SpriteFolder folder, TreeNodeCollection parent)
        {
            TreeNode newNode = AddTreeNode(folder, parent);

            foreach (SpriteFolder subFolder in folder.SubFolders)
            {
                BuildNodeTree(subFolder, newNode.Nodes);
            }
        }
        private int CountSprites(SpriteFolder folder)
        {
            int total = folder.Sprites.Count;

            foreach (SpriteFolder subFolder in folder.SubFolders)
            {
                total += CountSprites(subFolder);
            }

            return total;
        }
Exemple #16
0
 public void SetDataSource(SpriteFolder rootFolder)
 {
     _rootFolder = rootFolder;
     folderList.Nodes.Clear();
     _folders.Clear();
     _folderNodeMapping.Clear();
     _nodeFolderMapping.Clear();
     BuildNodeTree(rootFolder, folderList.Nodes);
     folderList.SelectedNode = folderList.Nodes[0];
     folderList.Nodes[0].Expand();
     /* This doens't work, not sure why
     if ((_currentFolder != null) &&
         (_folderNodeMapping.ContainsKey(_currentFolder)))
     {
         folderList.SelectedNode = _folderNodeMapping[_currentFolder];
         DisplaySpritesForFolder(_currentFolder);
     }
     else*/
     {
         DisplaySpritesForFolder(rootFolder);
     }
 }
Exemple #17
0
 private TreeNode AddTreeNode(SpriteFolder folder, TreeNodeCollection parent)
 {
     string nodeID = folder.Name;
     while (_folders.ContainsKey(nodeID))
     {
         nodeID = nodeID + "A";
     }
     TreeNode addedNode = parent.Add(nodeID, folder.Name, "Folder", "OpenFolder");
     _folders.Add(nodeID, folder);
     _folderNodeMapping.Add(folder, addedNode);
     _nodeFolderMapping.Add(addedNode, folder);
     return addedNode;
 }
Exemple #18
0
        private void VerifySpriteFolderTreeCanBeDeleted(SpriteFolder folderToDelete)
        {
            foreach (Sprite sprite in folderToDelete.Sprites)
            {
                string usageReport = _spriteUsageChecker.GetSpriteUsageReport(sprite.Number, Factory.AGSEditor.CurrentGame);
                if (usageReport != null)
                {
                    throw new AGSEditorException("Folder cannot be deleted because sprite " + sprite.Number + " is in use:" + Environment.NewLine + usageReport);
                }

                if (!Factory.AGSEditor.AboutToDeleteSprite(sprite.Number))
                {
                    throw new AGSEditorException("Folder cannot be deleted because sprite " + sprite.Number + " could not be marked for deletion");
                }
            }
        }
Exemple #19
0
 private void TreeContextMenuEventHandler(object sender, EventArgs e)
 {
     ToolStripMenuItem item = (ToolStripMenuItem)sender;
     TreeNode node = (TreeNode)item.Owner.Tag;
     if (item.Name == MENU_ITEM_CREATE_SUB_FOLDER)
     {
         SpriteFolder newFolder = new SpriteFolder("New folder");
         _folders[node.Name].SubFolders.Add(newFolder);
         TreeNode newNode = AddTreeNode(newFolder, node.Nodes);
         node.Expand();
         folderList.SelectedNode = newNode;
         newNode.BeginEdit();
     }
     else if (item.Name == MENU_ITEM_RENAME)
     {
         node.BeginEdit();
     }
     else if (item.Name == MENU_ITEM_DELETE_FOLDER)
     {
         DeleteFolder(node);
     }
 }
Exemple #20
0
        public void FromXml(XmlNode node)
        {
            node = node.SelectSingleNode("Game");

            _settings.FromXml(node);
            _lipSync.FromXml(node);
            _propertySchema.FromXml(node);

            if (node.SelectSingleNode("InventoryHotspotMarker") != null)
            {
                // Pre-3.0.3
                InventoryHotspotMarker marker = new InventoryHotspotMarker();
                marker.FromXml(node);
                _settings.InventoryHotspotMarker = marker;
            }

            foreach (XmlNode msgNode in SerializeUtils.GetChildNodes(node, "GlobalMessages"))
            {
                _globalMessages[Convert.ToInt32(msgNode.Attributes["ID"].InnerText) - GLOBAL_MESSAGE_ID_START] = msgNode.InnerText;
            }

            _plugins.Clear();
            foreach (XmlNode pluginNode in SerializeUtils.GetChildNodes(node, "Plugins"))
            {
                _plugins.Add(new Plugin(pluginNode));
            }

            _rooms = new UnloadedRoomFolder(node.SelectSingleNode("Rooms").FirstChild, node);

            _guis = new GUIFolder(node.SelectSingleNode("GUIs").FirstChild, node);

            _inventoryItems = new InventoryItemFolder(node.SelectSingleNode("InventoryItems").FirstChild, node);

            _textParser = new TextParser(node.SelectSingleNode("TextParser"));

            _characters = new CharacterFolder(node.SelectSingleNode("Characters").FirstChild, node);

            _playerCharacter = null;
            string playerCharText = SerializeUtils.GetElementString(node, "PlayerCharacter");
            if (playerCharText.Length > 0)
            {
                int playerCharID = Convert.ToInt32(playerCharText);
                foreach (Character character in RootCharacterFolder.AllItemsFlat)
                {
                    if (character.ID == playerCharID)
                    {
                        _playerCharacter = character;
                        break;
                    }
                }
            }

            _dialogs = new DialogFolder(node.SelectSingleNode("Dialogs").FirstChild, node);

            _cursors.Clear();
            foreach (XmlNode cursNode in SerializeUtils.GetChildNodes(node, "Cursors"))
            {
                _cursors.Add(new MouseCursor(cursNode));
            }

            _fonts.Clear();
            foreach (XmlNode fontNode in SerializeUtils.GetChildNodes(node, "Fonts"))
            {
                _fonts.Add(new Font(fontNode));
            }

            _palette = ReadPaletteFromXML(node);

            _sprites = new SpriteFolder(node.SelectSingleNode("Sprites").FirstChild);

            _views = new ViewFolder(node.SelectSingleNode("Views").FirstChild);

            _deletedViewIDs.Clear();
            if (node.SelectSingleNode("DeletedViews") != null)
            {
                foreach (XmlNode transNode in SerializeUtils.GetChildNodes(node, "DeletedViews"))
                {
                    _deletedViewIDs.Add(Convert.ToInt32(transNode.InnerText), null);
                }
            }

            _scripts = new ScriptFolder(node.SelectSingleNode("Scripts").FirstChild, node);

            if (node.SelectSingleNode("AudioClips") != null)
            {
                _audioClips = new AudioClipFolder(node.SelectSingleNode("AudioClips").FirstChild);
            }
            else
            {
                _audioClips = new AudioClipFolder("Main");
                _audioClips.DefaultPriority = AudioClipPriority.Normal;
                _audioClips.DefaultRepeat = InheritableBool.False;
                _audioClips.DefaultVolume = 100;
            }

            _audioClipTypes.Clear();
            if (node.SelectSingleNode("AudioClipTypes") != null)
            {
                foreach (XmlNode clipTypeNode in SerializeUtils.GetChildNodes(node, "AudioClipTypes"))
                {
                    _audioClipTypes.Add(new AudioClipType(clipTypeNode));
                }
            }

            _translations.Clear();
            if (node.SelectSingleNode("Translations") != null)
            {
                foreach (XmlNode transNode in SerializeUtils.GetChildNodes(node, "Translations"))
                {
                    _translations.Add(new Translation(transNode));
                }
            }

            if (node.SelectSingleNode("GlobalVariables") != null)
            {
                _globalVariables = new GlobalVariables(node.SelectSingleNode("GlobalVariables"));
            }
            else
            {
                _globalVariables = new GlobalVariables();
            }

            _oldInteractionVariables.Clear();
            if (node.SelectSingleNode("OldInteractionVariables") != null)
            {
                foreach (XmlNode varNode in SerializeUtils.GetChildNodes(node, "OldInteractionVariables"))
                {
                    _oldInteractionVariables.Add(new OldInteractionVariable(SerializeUtils.GetAttributeString(varNode, "Name"), SerializeUtils.GetAttributeInt(varNode, "Value")));
                }
            }

            if (_savedXmlVersionIndex == null)
            {
                // Pre-3.0.3, upgrade co-ordinates
                ConvertCoordinatesToNativeResolution();
            }
        }
Exemple #21
0
        public static Character ImportCharacterNew(string fileName, Game game)
        {
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(fileName);
            }
            catch (XmlException ex)
            {
                throw new AGS.Types.InvalidDataException("This does not appear to be a valid AGS Character file." + Environment.NewLine + Environment.NewLine + ex.Message, ex);
            }

            if (doc.DocumentElement.Name != CHARACTER_XML_ROOT_NODE)
            {
                throw new AGS.Types.InvalidDataException("Not a valid AGS Character file.");
            }
            if (SerializeUtils.GetAttributeString(doc.DocumentElement, CHARACTER_XML_VERSION_ATTRIBUTE) != CHARACTER_XML_CURRENT_VERSION)
            {
                throw new AGS.Types.InvalidDataException("This file requires a newer version of AGS to import it.");
            }

            Character newChar = new Character(doc.DocumentElement.FirstChild);
            PaletteEntry[] palette = game.ReadPaletteFromXML(doc.DocumentElement);

            // Clear any existing event handler function names
            for (int i = 0; i < newChar.Interactions.ScriptFunctionNames.Length; i++)
            {
                newChar.Interactions.ScriptFunctionNames[i] = string.Empty;
            }

            SpriteFolder newFolder = new SpriteFolder(newChar.ScriptName + "Import");
            game.RootSpriteFolder.SubFolders.Add(newFolder);

            Dictionary<int, int> spriteMapping = new Dictionary<int, int>();
            XmlNode viewsNode = doc.DocumentElement.SelectSingleNode("Views");

            newChar.NormalView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("NormalView"), game, spriteMapping, palette, newFolder);

            if (newChar.SpeechView > 0)
            {
                newChar.SpeechView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("SpeechView"), game, spriteMapping, palette, newFolder);
            }
            if (newChar.IdleView > 0)
            {
                newChar.IdleView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("IdleView"), game, spriteMapping, palette, newFolder);
            }
            if (newChar.ThinkingView > 0)
            {
                newChar.ThinkingView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("ThinkingView"), game, spriteMapping, palette, newFolder);
            }
            if (newChar.BlinkingView > 0)
            {
                newChar.BlinkingView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("BlinkingView"), game, spriteMapping, palette, newFolder);
            }

            EnsureCharacterScriptNameIsUnique(newChar, game);

            game.RootSpriteFolder.NotifyClientsOfUpdate();
            game.NotifyClientsViewsUpdated();
            return newChar;
        }
Exemple #22
0
 private void DeleteSpriteFolder(SpriteFolder folderToDelete, SpriteFolder folderToCheck)
 {
     foreach (SpriteFolder folder in folderToCheck.SubFolders)
     {
         if (folder == folderToDelete)
         {
             folderToCheck.SubFolders.Remove(folderToDelete);
             DeleteAllSpritesInTree(folderToDelete);
             break;
         }
         DeleteSpriteFolder(folderToDelete, folder);
     }
 }
Exemple #23
0
        public static GUI ImportGUIFromFile(string fileName, Game game)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);

            if (doc.DocumentElement.Name != GUI_XML_ROOT_NODE)
            {
                throw new AGS.Types.InvalidDataException("Not a valid AGS GUI file.");
            }
            if (SerializeUtils.GetAttributeString(doc.DocumentElement, GUI_XML_VERSION_ATTRIBUTE) != GUI_XML_CURRENT_VERSION)
            {
                throw new AGS.Types.InvalidDataException("This file requires a newer version of AGS to import it.");
            }

            GUI newGui;
            if (doc.DocumentElement.FirstChild.FirstChild.Name == NormalGUI.XML_ELEMENT_NAME)
            {
                newGui = new NormalGUI(doc.DocumentElement.FirstChild);
            }
            else
            {
                newGui = new TextWindowGUI(doc.DocumentElement.FirstChild);
            }

            PaletteEntry[] palette = game.ReadPaletteFromXML(doc.DocumentElement);

            SpriteFolder newFolder = new SpriteFolder(newGui.Name + "Import");
            game.RootSpriteFolder.SubFolders.Add(newFolder);

            Dictionary<int, int> spriteMapping = ImportSpritesFromXML(doc.DocumentElement.SelectSingleNode(GUI_XML_SPRITES_NODE), palette, newFolder);
            if (newGui.BackgroundImage > 0)
            {
                newGui.BackgroundImage = spriteMapping[newGui.BackgroundImage];
            }

            if (newGui.BackgroundImage < 0)
                newGui.BackgroundImage = 0;

            foreach (GUIControl control in newGui.Controls)
            {
                control.UpdateSpritesWithMapping(spriteMapping);
            }
            AdjustScriptNamesToEnsureEverythingIsUnique(newGui, game);

            game.RootSpriteFolder.NotifyClientsOfUpdate();
            return newGui;
        }
Exemple #24
0
        private void DisplaySpritesForFolder(SpriteFolder folder)
        {
            if (OnSelectionChanged != null)
            {
                // this means the previously selected sprite is un-selected
                // from the property grid
                OnSelectionChanged(new Sprite[0]);
            }

            if (this.ParentForm != null)
            {
                this.ParentForm.Cursor = Cursors.WaitCursor;
                this.Cursor = Cursors.WaitCursor;
            }

            _currentFolder = folder;
            spriteList.BeginUpdate();
            spriteList.Clear();
            _spriteImages.Images.Clear();
            _spriteImages.ColorDepth = ColorDepth.Depth16Bit;
            _spriteImages.ImageSize = new Size(64, 64);
            _spriteImages.TransparentColor = Color.Pink;
            foreach (Sprite sprite in folder.Sprites)
            {
                Bitmap bmp = Utilities.GetBitmapForSpriteResizedKeepingAspectRatio(sprite, 64, 64, false, true, Color.Pink);
                _spriteImages.Images.Add(sprite.Number.ToString(), bmp);
                spriteList.Items.Add(sprite.Number.ToString(), sprite.Number.ToString(), sprite.Number.ToString());
            }
            spriteList.LargeImageList = _spriteImages;
            spriteList.EndUpdate();

            if (this.ParentForm != null)
            {
                this.ParentForm.Cursor = Cursors.Default;
                this.Cursor = Cursors.Default;
            }
        }
Exemple #25
0
        private static void ImportSpritesFromXML(XmlNode spritesNode, PaletteEntry[] paletteEntries, SpriteFolder folderToAddTo, Dictionary<int, int> spriteNumberMapping)
        {
            Color[] palette = new Color[paletteEntries.Length];
            for (int i = 0; i < paletteEntries.Length; i++)
            {
                palette[i] = paletteEntries[i].Colour;
            }

            List<Sprite> newSprites = new List<Sprite>();

            foreach (XmlNode childNode in spritesNode.ChildNodes)
            {
                if (childNode.Name == GUI_XML_SPRITE_NODE)
                {
                    int spriteNumber = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_NUMBER);
                    int colDepth = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_COLOR_DEPTH);
                    bool hasAlphaChannel = bool.Parse(SerializeUtils.GetAttributeString(childNode, GUI_XML_SPRITE_ALPHA_CHANNEL));
                    int width = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_WIDTH);
                    int height = SerializeUtils.GetAttributeInt(childNode, GUI_XML_SPRITE_HEIGHT);
                    SpriteImportResolution resolution = (SpriteImportResolution)Enum.Parse(typeof(SpriteImportResolution), SerializeUtils.GetAttributeString(childNode, GUI_XML_SPRITE_RESOLUTION));
                    byte[]spriteData = Convert.FromBase64String(childNode.InnerText);

                    Sprite newSprite = ImportSpriteFromRawData(colDepth, width, height, hasAlphaChannel, spriteData, palette);
                    newSprite.Resolution = resolution;

                    newSprites.Add(newSprite);
                    spriteNumberMapping.Add(spriteNumber, newSprite.Number);
                    folderToAddTo.Sprites.Add(newSprite);
                }
            }

            Factory.NativeProxy.SpriteResolutionsChanged(newSprites.ToArray());
        }
Exemple #26
0
 private void RemoveSpritesFromFolder(SpriteFolder folder, List<Sprite> spritesToRemove)
 {
     foreach (Sprite draggedSprite in spritesToRemove)
     {
         folder.Sprites.Remove(draggedSprite);
     }
 }
Exemple #27
0
        private void DeleteAllSpritesInTree(SpriteFolder topFolder)
        {
            if (_folderNodeMapping.ContainsKey(topFolder))
            {
                _folderNodeMapping.Remove(topFolder);
            }

            foreach (Sprite sprite in topFolder.Sprites)
            {
                Factory.NativeProxy.DeleteSprite(sprite);
            }

            foreach (SpriteFolder subFolder in topFolder.SubFolders)
            {
                DeleteAllSpritesInTree(subFolder);
            }
        }
Exemple #28
0
 private static void UpdateSpriteFlags(SpriteFolder folder, byte[] flags)
 {
     foreach (Sprite sprite in folder.Sprites)
     {
         flags[sprite.Number] = 0;
         if (sprite.Resolution == SpriteImportResolution.HighRes) flags[sprite.Number] |= NativeConstants.SPF_640x400;
         if (sprite.AlphaChannel) flags[sprite.Number] |= NativeConstants.SPF_ALPHACHANNEL;
     }
     foreach (SpriteFolder subfolder in folder.SubFolders)
     {
         UpdateSpriteFlags(subfolder, flags);
     }
 }