Exemplo n.º 1
0
        } // LoadAllSong

        /// <summary>
        /// Load song in a temporal content manager.
        /// </summary>
        private static Song LoadSongInTemporalContentManager(string _currentSongFilename)
        {
            try
            {
                // Save the current content manager.
                AssetContentManager userContentManager = AssetContentManager.CurrentContentManager;

                if (musicContentManager != null)
                {
                    musicContentManager.Unload();
                }
                else
                {
                    // Creates a new content manager and load the new song.
                    musicContentManager = new AssetContentManager {
                        Name = "Temporal Content Manager", Hidden = true
                    }
                };

                AssetContentManager.CurrentContentManager = musicContentManager;
                Song song = new Song(_currentSongFilename);

                // Restore the user content manager.
                AssetContentManager.CurrentContentManager = userContentManager;

                return(song);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Music Manager: Failed to load song: " + _currentSongFilename, e);
            }
        } // LoadSongInTemporalContentManager
Exemplo n.º 2
0
        /// <summary>
        /// Manage the skin content (mouse cursors, elements' images, fonts, and skin's parameters)
        /// </summary>
        public static void LoadSkin(string skinName)
        {
            CurrentSkinName = skinName;

            AssetContentManager userContentManager = AssetContentManager.CurrentContentManager;

            #region Unload previous skin

            Controls = new SkinList <SkinControlInformation>();
            Fonts    = new SkinList <SkinFont>();
            Images   = new SkinList <SkinImage>();
            #if (WINDOWS)
            Cursors = new SkinList <SkinCursor>();
            #endif

            if (skinContentManager == null)
            {
                skinContentManager = new AssetContentManager {
                    Name = "Skin Content Manager", Hidden = true
                }
            }
            ;
            else
            {
                skinContentManager.Unload();
            }
            AssetContentManager.CurrentContentManager = skinContentManager;

            #endregion

            #region Load Description File

            string fullPath = "Skin" + "\\" + skinName + "\\Description";
            skinDescription = new Document(fullPath);

            // Read XML data.
            if (skinDescription.Resource.Element("Skin") != null)
            {
                try
                {
                    LoadImagesDescription();
                    LoadFontsDescription();
                    #if (WINDOWS)
                    LoadCursorsDescription();
                    #endif
                    LoadControlsDescription();
                }
                catch (Exception e)
                {
                    throw new Exception("Failed to load skin: " + skinName + ".\n\n" + e.Message);
                }
            }
            else
            {
                throw new Exception("Failed to load skin: " + skinName + ". Skin tag doesn't exist.");
            }

            #endregion

            #region Load Resources

            try
            {
                foreach (SkinFont skinFont in Fonts)
                {
                    skinFont.Font = new Font(skinFont.Filename);
                }
                #if (WINDOWS)
                foreach (SkinCursor skinCursor in Cursors)
                {
                    skinCursor.Cursor = new Cursor(skinName + "\\" + skinCursor.Filename);
                }
                #endif
                foreach (SkinImage skinImage in Images)
                {
                    skinImage.Texture = new Texture("Skin\\" + skinName + "\\" + skinImage.Filename);
                }
                foreach (SkinControlInformation skinControl in Controls)
                {
                    foreach (SkinLayer skinLayer in skinControl.Layers)
                    {
                        if (skinLayer.Image.Name != null)
                        {
                            skinLayer.Image = Images[skinLayer.Image.Name];
                        }
                        else
                        {
                            skinLayer.Image = Images[0];
                        }
                        skinLayer.Text.Font = skinLayer.Text.Name != null ? Fonts[skinLayer.Text.Name] : Fonts[0];
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Failed to load skin: " + skinName + ".\n\n" + e.Message);
            }

            #endregion

            // Restore user content manager.
            AssetContentManager.CurrentContentManager = userContentManager;
        } // LoadSkin