Esempio n. 1
0
 protected override void OnInit(EventArgs e)
 {
     mContainer = new TitleContainer(string.Empty);
     Template.InstantiateIn(mContainer);
     divHelp.Controls.Add(mContainer);
     base.OnInit(e);
 }
        public void Initialize(TitleContainer control)
        {
            control.Width = 300;

            child = new Placeholder{Text = "My Child", Height = 250};

            control.Title = "My Title";
            control.Child = child;
        }
Esempio n. 3
0
        protected override void LoadContent()
        {
            /// <summary>method <c>LoadContent</c> load the game content.</summary>

            _spriteBatch = new SpriteBatch(GraphicsDevice);
            using (var stream = TitleContainer.OpenStream("Content/charactersheet.png"))
            {
                characterSheetTexture = Texture2D.FromStream(this.GraphicsDevice, stream);
            }

            // (With this.Content) Load your game content here
            title     = Content.Load <SpriteFont>("Title");
            paragraph = Content.Load <SpriteFont>("Paragraph");
        }
        public Stream Open(string assetName)
        {
            if (AssetManager.SeparatorSymbol != Path.DirectorySeparatorChar)
            {
                assetName = assetName.Replace(AssetManager.SeparatorSymbol, Path.DirectorySeparatorChar);
            }

            if (!string.IsNullOrEmpty(BaseFolder))
            {
                assetName = Path.Combine(BaseFolder, assetName);
            }

            return(TitleContainer.OpenStream(assetName));
        }
Esempio n. 5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            testTexture = null;
            if (!Program.loadTexture)
            {
                return;
            }
            //decrypt tpf file;
            string tpfFile = Program.orgFileName.Substring(0, Program.orgFileName.Length - 5) + "tpf";

            try {
                if (Program.targetTPF != null)
                {
                    foreach (var t in Program.targetTPF.Textures)
                    {
                        textureMap.Add(t.Name, getTextureFromBitmap(readDdsStreamToBitmap(new MemoryStream(t.Bytes)), this.GraphicsDevice));
                        //   System.Windows.MessageBox.Show("Added:" + t.Name);
                    }
                }
                else
                if (File.Exists(tpfFile))
                {
                    var tpf = SoulsFormats.TPF.Read(tpfFile);
                    foreach (var t in tpf.Textures)
                    {
                        textureMap.Add(t.Name, getTextureFromBitmap(readDdsStreamToBitmap(new MemoryStream(t.Bytes)), this.GraphicsDevice));
                        //   System.Windows.MessageBox.Show("Added:" + t.Name);
                    }
                }
            } catch (Exception e)
            {
            }


            using (var stream = TitleContainer.OpenStream("singleColor.png"))
            {
                testTexture = Texture2D.FromStream(this.GraphicsDevice, stream);
            }
            //  testTexture = getTextureFromBitmap(readDdsFileToBitmap("EliteKnight.dds"),this.GraphicsDevice);


            /*  string path = @"data\img\27.png";
             *
             * System.Drawing.Bitmap btt = new System.Drawing.Bitmap(path);
             * test = Texture2D.FromStream(this.GraphicsDevice, File.OpenRead(path));
             * test = getTextureFromBitmap(btt, this.GraphicsDevice);*/
            // TODO: use this.Content to load your game content here
        }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="containerName"></param>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public Boolean FileExists(String containerName, String fileName)
 {
     try
     {
         using (Stream stream = TitleContainer.OpenStream(String.Join(@"\", containerName, fileName)))
         {
             return(true);
         }
     }
     catch (FileNotFoundException)
     {
         return(false);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Plays a sound file from the application assets.
        /// </summary>
        /// <param name="soundName"></param>
        private static void PlaySound(string soundName)
        {
            using (var stream = TitleContainer.OpenStream(soundName))
            {
                if (stream == null)
                {
                    return;
                }

                var effect = SoundEffect.FromStream(stream);
                FrameworkDispatcher.Update();
                effect.Play();
            }
        }
Esempio n. 8
0
        protected internal override Video Read(ContentReader input, Video existingInstance)
        {
            string path = input.ReadObject <string>();

            path = Path.Combine(input.ContentManager.RootDirectory, path);
            path = TitleContainer.GetFilename(path);

            /*int durationMS =*/ input.ReadObject <int>();
            /*int width =*/ input.ReadObject <int>();
            /*int height =*/ input.ReadObject <int>();
            /*float framesPerSecond =*/ input.ReadObject <Single>();
            /*int soundTrackType =*/ input.ReadObject <int>();   // 0 = Music, 1 = Dialog, 2 = Music and dialog
            return(new Video(path));
        }
Esempio n. 9
0
        protected override void LoadContent()
        {
            // Notice that loading a model is very similar
            // to loading any other XNB (like a Texture2D).
            // The only difference is the generic type.
            model = Content.Load <Model> ("robot");

            // We aren't using the content pipeline, so we need
            // to access the stream directly:
            using (var stream = TitleContainer.OpenStream("Content/checkerboard.png"))
            {
                checkerboardTexture = Texture2D.FromStream(this.GraphicsDevice, stream);
            }
        }
Esempio n. 10
0
 public static Texture2D LoadTextureFromFile(string filePath, GraphicsDevice graphicsDevice)
 {
     try
     {
         using (System.IO.Stream stream = TitleContainer.OpenStream(filePath)) //TODO what is TitleContainer?
         {
             return(LoadTextureFromStream(stream, graphicsDevice));
         }
     }
     catch
     {
         throw new System.IO.FileLoadException("Cannot load '" + filePath + "' file!");
     }
 }
Esempio n. 11
0
        public CharacterEntity(GraphicsDevice graphicsDevice)
        {
            if (characterSheetTexture == null)
            {
                using var stream      = TitleContainer.OpenStream("Content/charactersheet.png");
                characterSheetTexture = Texture2D.FromStream(graphicsDevice, stream);
            }

            walkDown = new Animation()
                       .AddFrame(new Rectangle(0, 0, 32, 32), TimeSpan.FromSeconds(.25))
                       .AddFrame(new Rectangle(32, 0, 32, 32), TimeSpan.FromSeconds(.25))
                       .AddFrame(new Rectangle(0, 0, 32, 32), TimeSpan.FromSeconds(.25))
                       .AddFrame(new Rectangle(64, 0, 32, 32), TimeSpan.FromSeconds(.25));
        }
        private BmFont loadFont(string path)
        {
            var fontFilePath = findFile(path);

            using (var stream = TitleContainer.OpenStream(fontFilePath))
            {
                var fontFile = FontLoader.Load(stream);
                var fontPng  = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), fontFile.Pages[0].File);

                // textRenderer initialization will go here
                stream.Close();
                return(new BmFont(fontFile, fontPng));
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Load track data
 /// </summary>
 /// <param name="setFilename">Set filename</param>
 public static TrackData Load(string setFilename)
 {
     // Load track data
     using (StreamReader file = new StreamReader(TitleContainer.OpenStream(
                                                     Directory + "\\" + setFilename + "." + Extension)))
     {
         // Load everything into this class with help of the XmlSerializer.
         TrackData loadedTrack = (TrackData)
                                 new XmlSerializer(typeof(TrackData)).
                                 Deserialize(file.BaseStream);
         // Return loaded file
         return(loadedTrack);
     }
 }
Esempio n. 14
0
        /// <summary>
        ///     Given the path to a file relative to the game's content directory,
        ///     reads the file as text and returns the content as a string.
        /// </summary>
        /// <param name="contentPath">
        ///     The path ot hte file to read relative to the content directory.
        /// </param>
        /// <returns>
        ///     The content of the file as a string.
        /// </returns>
        public static async Task <string> ReadFileAsync(string contentPath)
        {
            string fileContent = string.Empty;

            using (var stream = TitleContainer.OpenStream(Path.Combine(Engine.Instance.Content.RootDirectory, contentPath)))
            {
                using (var reader = new StreamReader(stream))
                {
                    fileContent = await reader.ReadToEndAsync();
                }
            }

            return(fileContent);
        }
Esempio n. 15
0
    private static LevelData[] LoadXmlDoc()
    {
        string data = null;

        using (var fs = TitleContainer.OpenStream("levels.xml")) {
            using (var sr = new StreamReader(fs))
                data = sr.ReadToEnd();
        }


        var lvls = new List <LevelData>();
        var doc  = XDocument.Parse(data);

        foreach (var ld in  doc.Root.Elements("LevelData"))
        {
            if (ld.IsEmpty)
            {
                break;
            }

            var levelData = new LevelData();

            levelData.map = new Array <Array <int> >();

            var map = ld.Element("map");

            foreach (var aoi in map.Elements("ArrayOfInt"))
            {
                var a = new Array <int>();
                foreach (var i in aoi.Elements("int"))
                {
                    a.push(Convert.ToInt32(i.Value));
                }
                levelData.map.push(a);
            }

            levelData.playerDir = Convert.ToInt32(ld.Element("playerDir").Value);
            int x = Convert.ToInt32(ld.Element("player").Element("x").Value);
            int y = Convert.ToInt32(ld.Element("player").Element("y").Value);
            levelData.player     = new Point(x, y);
            levelData.food       = Convert.ToInt32(ld.Element("food").Value);
            levelData.endingDist = Convert.ToInt32(ld.Element("endingDist").Value);
            levelData.turns      = Convert.ToInt32(ld.Element("turns").Value);

            lvls.Add(levelData);
        }

        return(lvls.ToArray());
    }
Esempio n. 16
0
        protected virtual void ReloadAsset <T>(string originalAssetName, T currentAsset)
        {
            string str = originalAssetName;

            if (string.IsNullOrEmpty(str))
            {
                throw new ArgumentNullException("assetName");
            }
            if (this.disposed)
            {
                throw new ObjectDisposedException("ContentManager");
            }
            if (this.graphicsDeviceService == null)
            {
                this.graphicsDeviceService = this.serviceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
                if (this.graphicsDeviceService == null)
                {
                    throw new InvalidOperationException("No Graphics Device Service");
                }
            }
            try
            {
                Stream stream = this.OpenStream(str);
                try
                {
                    using (BinaryReader xnbReader = new BinaryReader(stream))
                    {
                        using (ContentReader contentReaderFromXnb = this.GetContentReaderFromXnb(str, ref stream, xnbReader, (Action <IDisposable>)null))
                        {
                            contentReaderFromXnb.InitializeTypeReaders();
                            contentReaderFromXnb.ReadObject <T>(currentAsset);
                            contentReaderFromXnb.ReadSharedResources();
                        }
                    }
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                }
            }
            catch (ContentLoadException ex)
            {
                string assetName = this.Normalize <T>(TitleContainer.GetFilename(Path.Combine(this.RootDirectory, str)));
                this.ReloadRawAsset <T>(currentAsset, assetName, originalAssetName);
            }
        }
Esempio n. 17
0
        public void Play(int id)
        {
            if (effectInstance != null && effectInstance.State == SoundState.Playing)
            {
                effectInstance.Stop();
            }
            SoundModel selectedSound = Sounds.First(s => s.ID == id);

            var stream = TitleContainer.OpenStream(selectedSound.Uri);

            effectInstance = SoundEffect.FromStream(stream).CreateInstance();
            FrameworkDispatcher.Update();

            effectInstance.Play();
        }
Esempio n. 18
0
        public void LoadContent()
        {
            System.IO.Stream       imgStream = TitleContainer.OpenStream(GameManager.Instance.Content.RootDirectory + "/images.txt");
            System.IO.StreamReader reader    = new System.IO.StreamReader(imgStream);
            string line = reader.ReadLine();

            while (line != null)
            {
                string[] data    = line.Split(new char[] { ' ' });
                int      lastPos = data[0].LastIndexOf('.');
                string   name    = data[0].Substring(0, lastPos);
                LoadImage(name, data[1]);
                line = reader.ReadLine();
            }
        }
        public static bool LoadTitleLevel(string Path)
        {
            Stream s = TitleContainer.OpenStream("Content/Levels/" + Path + ".lvl");

            if (s != null)
            {
                GameManager.SetLevel(new Level(false));
                GameManager.GetLevel().Read(new BinaryReader(s));
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Method to load each level
        /// </summary>
        private void LoadLevel()
        {
            levelIndex = (levelIndex + 1) % numberOfLevels;
            if (level != null)
            {
                level.Dispose();
            }

            string path = string.Format("Content/Levels/{0}.txt", levelIndex);

            using (Stream fileStream = TitleContainer.OpenStream(path))
            {
                level = new LevelHandler(Services, fileStream, levelIndex);
            }
        }
 public Animation(GraphicsDevice graphicsDevice, String dir)
 {
     string[] files = System.IO.Directory.GetFiles(dir);
     frameCount      = files.Count();
     AnimationFrames = new List <Texture2D>();
     for (int i = 0; i < frameCount; i++)
     {
         System.Diagnostics.Debug.WriteLine(files[i]);
         System.Diagnostics.Debug.WriteLine(files[i].Remove(0, "Content/".Length));
         var stream = TitleContainer.OpenStream(files[i].Remove(0, "Content/".Length));
         AnimationFrames.Add(Texture2D.FromStream(graphicsDevice, stream));
     }
     frameHeight = AnimationFrames[0].Height;
     frameWidth  = AnimationFrames[0].Width;
 }
Esempio n. 22
0
 public override Stream OpenInputStream(String path)
 {
     if (path.StartsWith("monkey://data/"))
     {
         try{
             return(TitleContainer.OpenStream(PathToContentPath(path)));
         }catch (Exception) {
         }
     }
     else
     {
         return(base.OpenInputStream(path));
     }
     return(null);
 }
Esempio n. 23
0
        public override void Init(GraphicsDeviceManager _graphics, ContentManager Content, GraphicsDevice GraphicsDevice, ScreenManager screenManager, Game game)
        {
            this.game = game;
            FPS       = new Vector2(10, 10);
            font      = Content.Load <SpriteFont>("File");
            FontSystem fontSystem = FontSystemFactory.Create(GraphicsDevice, 2048, 2048);

            fontSystem.AddFont(TitleContainer.OpenStream($"{Content.RootDirectory}/Monaco-1.ttf"));

            GuiHelper.Setup(game, fontSystem);

            _ui  = new IMGUI();
            Text = new Vector2(30, 30);
            base.Init(_graphics, Content, GraphicsDevice, screenManager, game);
        }
Esempio n. 24
0
 protected void Page_Init()
 {
     if (_content != null)
       {
     BoxContainer c = new BoxContainer();
     Content.InstantiateIn(c);
     phContent.Controls.Add(c);
       }
       if (_title != null)
       {
     TitleContainer t = new TitleContainer();
     Title.InstantiateIn(t);
     phTitle.Controls.Add(t);
       }
 }
Esempio n. 25
0
        public FlxTilemap loadMapFile(String CSVdataFile, String Graphic, int TileWidth, int TileHeight, uint DrawIndex = 0, int CollideIndex = 1)
        {
            string CsvData = "";

            using (var stream = TitleContainer.OpenStream("Content/" + CSVdataFile))
                using (var reader = new StreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        CsvData += reader.ReadLine() + "\n";
                    }
                    stream.Dispose();
                }
            return(loadMap(CsvData, Graphic, TileWidth, TileHeight, DrawIndex, CollideIndex));
        }
Esempio n. 26
0
        public TileBase Initialise(int x, int y, string image)
        {
            X = x;
            Y = y;

            var yFromTop = Screen.Height - 1 - y;
            var rawY     = yFromTop * TileDimension;
            var rawX     = x * TileDimension;

            Position = new Rectangle(rawX, rawY, TileDimension, TileDimension);
            using (var stream = TitleContainer.OpenStream($"Content/img/{image}")) // ToDo: this should be done using a `Content.mgcb` file, but I couldn't get it to work
                _texture = Texture2D.FromStream(GameLoopBase.GraphicsDevice, stream);

            return(this);
        }
Esempio n. 27
0
        public void readLevels()
        {
            Stream       stream = TitleContainer.OpenStream("Content/levels/levels.txt");
            StreamReader sr     = new StreamReader(stream);

            String temp = "";

            while (!sr.EndOfStream)
            {
                temp = "corrupted load";//will be replaced if loaded properly
                temp = sr.ReadLine();
                level_names.Add(temp);
            }
            sr.Close();
        }
Esempio n. 28
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //whiteRectangle = Content.Load<Texture2D>("60789_01");
            whiteRectangle = new Texture2D(GraphicsDevice, 1, 1);
            whiteRectangle.SetData(new[] { Color.White });

            // We aren't using the content pipeline, so we need
            // to access the stream directly:
            using (var stream = TitleContainer.OpenStream("Content/checkerboard.png"))
            {
                checkerboardTexture = Texture2D.FromStream(this.GraphicsDevice, stream);
            }
        }
Esempio n. 29
0
        /// <summary>
        /// After the font has been loaded, (with the <see cref="FilePath"/>, <see cref="GlyphHeight"/>, and <see cref="GlyphWidth"/> fields filled out) this method will create the actual texture.
        /// </summary>
        public void Generate()
        {
            cachedFonts = new Dictionary <Font.FontSizes, Font>();

            LoadedFilePath = System.IO.Path.Combine(Global.SerializerPathHint, FilePath);

            // I know.. bad way to do this.. yuck
            if (!Settings.LoadingEmbeddedFont)
            {
                using (System.IO.Stream fontStream = TitleContainer.OpenStream(LoadedFilePath))
                    Image = Texture2D.FromStream(Global.GraphicsDevice, fontStream);

                ConfigureRects();
            }
        }
Esempio n. 30
0
        private void LoadMap(string mapName)
        {
            // Unloads the content for the current level before loading the next one.
            if (map != null)
            {
                map.Dispose();
            }

            // Load the level.

            string levelPath = string.Format("Content/Maps/{0}.txt", mapName);

            using (Stream fileStream = TitleContainer.OpenStream(levelPath))
                map = new Map(Services, fileStream);
        }
Esempio n. 31
0
 private void PlaySound(string path)
 {
     if (!string.IsNullOrEmpty(path))
     {
         using (var stream = TitleContainer.OpenStream(path))
         {
             if (stream != null)
             {
                 var effect = SoundEffect.FromStream(stream);
                 FrameworkDispatcher.Update();
                 effect.Play();
             }
         }
     }
 }
Esempio n. 32
0
        private void LoadLevel(int levelnr)
        {
            if (map != null)
            {
                map.Dispose();
            }

            string path = $"Content/MapContent/{levelnr}.txt";

            using (Stream stream = TitleContainer.OpenStream(path))
            {
                map = new Map(mapContent, stream);
                Console.WriteLine(path);
            }
        }
Esempio n. 33
0
        protected virtual async Task <Stream> OpenStreamAsync(string assetName)
        {
            Stream stream;

            try
            {
                var assetPath = Path.Combine(RootDirectory, assetName) + ".xnb";

                // This is primarily for editor support.
                // Setting the RootDirectory to an absolute path is useful in editor
                // situations, but TitleContainer can ONLY be passed relative paths.
#if DESKTOPGL || WINDOWS
                if (Path.IsPathRooted(assetPath))
                {
                    stream = File.OpenRead(assetPath);
                }
                else
#endif
                stream = await TitleContainer.OpenStreamAsync(assetPath);

#if ANDROID
                // Read the asset into memory in one go. This results in a ~50% reduction
                // in load times on Android due to slow Android asset streams.
                MemoryStream memStream = new MemoryStream();
                stream.CopyTo(memStream);
                memStream.Seek(0, SeekOrigin.Begin);
                stream.Close();
                stream = memStream;
#endif
            }
#if !WEB
            catch (FileNotFoundException fileNotFound)
            {
                throw new ContentLoadException("The content file was not found.", fileNotFound);
            }
#if !WINDOWS_UAP
            catch (DirectoryNotFoundException directoryNotFound)
            {
                throw new ContentLoadException("The directory was not found.", directoryNotFound);
            }
#endif
#endif
            catch (Exception exception)
            {
                throw new ContentLoadException("Opening stream error.", exception);
            }
            return(stream);
        }
 public void ToggleIsOpenOn(TitleContainer control)
 {
     control.ToggleIsOpenOn = control.ToggleIsOpenOn == ClickGesture.SingleClick
                                                 ? ClickGesture.DoubleClick 
                                                 : ClickGesture.SingleClick;
     Debug.WriteLine("ToggleIsOpenOn: " + control.ToggleIsOpenOn);
 }
 public void Toggle_IsOpen(TitleContainer control)
 {
     control.IsOpen = !control.IsOpen;
     Debug.WriteLine("IsOpen" + control.IsOpen);
 }
 public void Animate_Default_Speed(TitleContainer control)
 {
     control.AnimationDuration = 0.15;
 }
 public void Child_Height_250(TitleContainer control)
 {
     child.Height = 250;
 }
 public void Toggle_AnimateIcon(TitleContainer control)
 {
     control.AnimateIcon = !control.AnimateIcon;
     Debug.WriteLine("AnimateIcon: " + control.AnimateIcon);
 }
 public void Child_Height_10(TitleContainer control)
 {
     child.Height = 10;
 }
 public void Animate_Slow(TitleContainer control)
 {
     control.AnimationDuration = 1;
 }
 public void ShouldThrowExceptionWhenTemplateNotFound()
 {
     var control = new TitleContainer();
     Templates.Instance.ApplyTemplate(control);
 }
 public void Child_Height_Random(TitleContainer control)
 {
     child.Height = RandomData.Random.Next(10, 300);
 }