Ejemplo n.º 1
0
		public async Task<IAnimation> LoadAnimationFromSpriteSheetAsync(ISpriteSheet spriteSheet,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			animationConfig = animationConfig ?? new AGSAnimationConfiguration ();
			string filePath = spriteSheet.Path;
			IResource resource = await Task.Run(() =>_resources.LoadResource (filePath));
			if (resource == null) {
				throw new InvalidOperationException ("Failed to load sprite sheet from " + filePath);
			}
			IBitmap bitmap = await Task.Run(() => _bitmapLoader.Load (resource.Stream));
			int cellsInRow, cellsInCol, cellsTotal, cellX, cellY, cellsToGrab, cellsGrabbed = 0;
			Point mainStep, secondStep;
			AGSAnimation animation;
			getSpriteSheetData (bitmap, spriteSheet, animationConfig, out cellsInRow, out cellsInCol,
								out cellsTotal, out cellX, out cellY, out cellsToGrab, out mainStep, out secondStep,
								out animation);
			for (int currentCell = 0; cellsGrabbed < cellsToGrab; currentCell++) 
			{
				if (currentCell >= spriteSheet.StartFromCell) 
				{
                    Rectangle rect; IBitmap clone; string path; ITexture tex;
                    getImageInfo (bitmap, cellX, cellY, spriteSheet, loadConfig, filePath, out rect, out clone, out path, out tex);
                    IImage image = _loadImage (tex, clone, path, loadConfig, spriteSheet);
					_addAnimationFrame (image, animation);
					cellsGrabbed++;
				}

				nextCell (mainStep, secondStep, cellsInRow, cellsInCol, ref cellX, ref cellY);
			}
			animation.Setup ();
			return animation;
		}
Ejemplo n.º 2
0
		public async Task<IInventoryItem> GetInventoryItemAsync(string hotspot, string graphicsFile, string cursorFile = null,
			ILoadImageConfig loadConfig = null, bool playerStartsWithItem = false)
		{
			var graphicsImage = await _graphics.LoadImageAsync (graphicsFile, loadConfig);
			var cursorImage = cursorFile == null ? graphicsImage : await _graphics.LoadImageAsync(cursorFile, loadConfig);
			return getInventoryItem(hotspot, graphicsImage, cursorImage, playerStartsWithItem);
		}
Ejemplo n.º 3
0
		public IInventoryItem GetInventoryItem(string hotspot, string graphicsFile, string cursorFile = null, 
			ILoadImageConfig loadConfig = null, bool playerStartsWithItem = false)
		{
			var graphicsImage = _graphics.LoadImage(graphicsFile, loadConfig);
			var cursorImage = cursorFile == null ? graphicsImage : _graphics.LoadImage(cursorFile, loadConfig);
			return getInventoryItem (hotspot, graphicsImage, cursorImage, playerStartsWithItem);
		}
Ejemplo n.º 4
0
        public GLImage(IBitmap bitmap, string id, ITexture texture, ISpriteSheet spriteSheet, ILoadImageConfig loadConfig)
		{
			OriginalBitmap = bitmap;
			Width = bitmap.Width;
			Height = bitmap.Height;
			ID = id;
			Texture = texture;
			SpriteSheet = spriteSheet;
			LoadConfig = loadConfig;
		}
Ejemplo n.º 5
0
		public async Task<IOutfit> LoadOutfitFromFoldersAsync(string baseFolder, string walkLeftFolder = null, string walkRightFolder = null,
			string walkDownFolder = null, string walkUpFolder = null, string idleLeftFolder = null, string idleRightFolder = null,
			string idleDownFolder = null, string idleUpFolder = null, string speakLeftFolder = null, string speakRightFolder = null,
			string speakDownFolder = null, string speakUpFolder = null,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			IOutfit outfit = _resolver.Resolve<IOutfit> ();

            outfit[AGSOutfit.Idle] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, idleLeftFolder, idleRightFolder,
				idleDownFolder, idleUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Walk] = await _graphics.LoadDirectionalAnimationFromFoldersAsync (baseFolder, walkLeftFolder, walkRightFolder,
				walkDownFolder, walkUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Speak] = await _graphics.LoadDirectionalAnimationFromFoldersAsync (baseFolder, speakLeftFolder, speakRightFolder,
				speakDownFolder, speakUpFolder, animationConfig, loadConfig);

			return outfit;
		}
Ejemplo n.º 6
0
		public async Task<IDirectionalAnimation> LoadDirectionalAnimationFromFoldersAsync(string baseFolder, string leftFolder = null,
			string rightFolder = null, string downFolder = null, string upFolder = null,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			if (leftFolder == null && rightFolder == null && downFolder == null && upFolder == null) return null;

			AGSDirectionalAnimation dirAnimation = new AGSDirectionalAnimation ();
			if (leftFolder != null) dirAnimation.Left = await LoadAnimationFromFolderAsync(baseFolder + leftFolder, animationConfig, loadConfig);
			if (rightFolder != null) dirAnimation.Right = await LoadAnimationFromFolderAsync(baseFolder + rightFolder, animationConfig, loadConfig);
			if (downFolder != null) dirAnimation.Down = await LoadAnimationFromFolderAsync(baseFolder + downFolder, animationConfig, loadConfig);
			if (upFolder != null) dirAnimation.Up = await LoadAnimationFromFolderAsync(baseFolder + upFolder, animationConfig, loadConfig);

			if (dirAnimation.Left != null && dirAnimation.Right == null) {
				dirAnimation.Right = createLeftRightAnimation (dirAnimation.Left);
			}

			if (dirAnimation.Right != null && dirAnimation.Left == null) {
				dirAnimation.Left = createLeftRightAnimation (dirAnimation.Right);
			}

			return dirAnimation;
		}
Ejemplo n.º 7
0
        public async Task <IPanel> GetPanelAsync(string id, string imagePath, float x, float y, IObject parent = null, ILoadImageConfig loadConfig = null, bool addToUi = true)
        {
            IImage image = await _graphics.LoadImageAsync(imagePath, loadConfig);

            return(GetPanel(id, image, x, y, parent, addToUi));
        }
Ejemplo n.º 8
0
        private IImage loadImage(ITexture texture, IBitmap bitmap, string id, ILoadImageConfig config, ISpriteSheet spriteSheet)
		{
			manipulateImage(bitmap, config);
			bitmap.LoadTexture(null);
			GLImage image = new GLImage (bitmap, id, texture, spriteSheet, config);

			if (_textures != null)
                _textures.GetOrAdd (image.ID, () => image.Texture);
			return image;
		}
Ejemplo n.º 9
0
 private ITexture createTexture(ILoadImageConfig config)
 {
     ITextureConfig textureConfig = config == null ? null : config.TextureConfig;
     TypedParameter textureConfigParam = new TypedParameter(typeof(ITextureConfig), textureConfig);
     return _resolver.Resolve<ITexture>(textureConfigParam);
 }
Ejemplo n.º 10
0
		private async Task<IAnimation> loadAnimationFromResourcesAsync (List<IResource> resources,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			AGSAnimation animation = getAnimation (animationConfig, resources.Count);

			foreach (IResource resource in resources) 
			{
				var image = await loadImageAsync (resource, loadConfig);
				addAnimationFrame (image, animation);
			}
			animation.Setup ();
			return animation;
		}
Ejemplo n.º 11
0
        private IImage loadImage(IResource resource, ILoadImageConfig config = null)
		{
			ITexture tex = createTexture(config);
			try
			{
				IBitmap bitmap = _bitmapLoader.Load(resource.Stream);
				return loadImage (tex, bitmap, resource.ID, config, null);
			}
			catch (ArgumentException e)
			{
				Debug.WriteLine("Failed to load image from {0}, is it really an image?\r\n{1}", resource.ID, e.ToString());
				return null;
			}
		}
Ejemplo n.º 12
0
		public async Task<IAnimation> LoadAnimationFromSpriteSheetAsync (ISpriteSheet spriteSheet, 
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return await _spriteSheetLoader.LoadAnimationFromSpriteSheetAsync (spriteSheet, animationConfig, loadConfig);
		}
Ejemplo n.º 13
0
        public IImage LoadImage(string path, ILoadImageConfig config = null)
		{
			IResource resource = _resources.LoadResource(path);
            return loadImage(resource, config);
		}
Ejemplo n.º 14
0
 public IImage LoadImage(IBitmap bitmap, ILoadImageConfig config = null, string id = null)
 {
     return(loadImage(bitmap, config, id));
 }
Ejemplo n.º 15
0
        public IImage LoadImage(string path, ILoadImageConfig config = null)
        {
            IResource resource = _resources.LoadResource(path);

            return(loadImage(resource, config));
        }
Ejemplo n.º 16
0
 public IAnimation LoadAnimationFromSpriteSheet(ISpriteSheet spriteSheet,
                                                IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(_spriteSheetLoader.LoadAnimationFromSpriteSheet(spriteSheet, animationConfig, loadConfig));
 }
Ejemplo n.º 17
0
 public async Task <IAnimation> LoadAnimationFromSpriteSheetAsync(ISpriteSheet spriteSheet,
                                                                  IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(await _spriteSheetLoader.LoadAnimationFromSpriteSheetAsync(spriteSheet, animationConfig, loadConfig));
 }
Ejemplo n.º 18
0
 public async Task <IAnimation> LoadAnimationFromFolderAsync(string folderPath,
                                                             IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(await loadAnimationFromResourcesAsync(folderPath, await Task.Run(() => _resources.LoadResources(folderPath)),
                                                  animationConfig, loadConfig));
 }
Ejemplo n.º 19
0
 public IAnimation LoadAnimationFromFolder(string folderPath,
                                           IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
 {
     return(loadAnimationFromResources(folderPath, _resources.LoadResources(folderPath), animationConfig, loadConfig));
 }
Ejemplo n.º 20
0
        public IPanel GetPanel(string id, string imagePath, float x, float y, IObject parent = null, ILoadImageConfig loadConfig = null, bool addToUi = true)
        {
            IImage image = _graphics.LoadImage(imagePath, loadConfig);

            return(GetPanel(id, image, x, y, parent, addToUi));
        }
Ejemplo n.º 21
0
 public GLImage(IBitmap bitmap, string id, ITexture texture, ISpriteSheet spriteSheet, ILoadImageConfig loadConfig)
 {
     OnImageDisposed = new AGSEvent();
     OriginalBitmap  = bitmap;
     Width           = bitmap.Width;
     Height          = bitmap.Height;
     ID          = id;
     Texture     = texture;
     SpriteSheet = spriteSheet;
     LoadConfig  = loadConfig;
 }
Ejemplo n.º 22
0
        public async Task <IImage> LoadImageAsync(string filePath, ILoadImageConfig config = null)
        {
            IResource resource = await Task.Run(() => _resources.LoadResource(filePath));

            return(await loadImageAsync(resource, config));
        }
Ejemplo n.º 23
0
		public IAnimation LoadAnimationFromSpriteSheet (ISpriteSheet spriteSheet, 
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return _spriteSheetLoader.LoadAnimationFromSpriteSheet (spriteSheet, animationConfig, loadConfig);
		}
Ejemplo n.º 24
0
        private async Task <IAnimation> loadAnimationFromResourcesAsync(string samplePath, List <IResource> resources,
                                                                        IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            AGSAnimation animation = getAnimation(samplePath, animationConfig, resources.Count);

            foreach (IResource resource in resources)
            {
                var image = await loadImageAsync(resource, loadConfig);

                addAnimationFrame(image, animation);
            }
            animation.Setup();
            return(animation);
        }
Ejemplo n.º 25
0
		public IImage LoadImage(IBitmap bitmap, ILoadImageConfig config = null, string id = null)
		{
            return loadImage(bitmap, config, id);
		}
Ejemplo n.º 26
0
        public async Task <IDirectionalAnimation> LoadDirectionalAnimationFromFoldersAsync(string baseFolder, string leftFolder = null,
                                                                                           string rightFolder = null, string downFolder = null, string upFolder = null,
                                                                                           IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            if (leftFolder == null && rightFolder == null && downFolder == null && upFolder == null)
            {
                return(null);
            }

            AGSDirectionalAnimation dirAnimation = new AGSDirectionalAnimation();

            if (leftFolder != null)
            {
                dirAnimation.Left = await LoadAnimationFromFolderAsync(baseFolder + leftFolder, animationConfig, loadConfig);
            }
            if (rightFolder != null)
            {
                dirAnimation.Right = await LoadAnimationFromFolderAsync(baseFolder + rightFolder, animationConfig, loadConfig);
            }
            if (downFolder != null)
            {
                dirAnimation.Down = await LoadAnimationFromFolderAsync(baseFolder + downFolder, animationConfig, loadConfig);
            }
            if (upFolder != null)
            {
                dirAnimation.Up = await LoadAnimationFromFolderAsync(baseFolder + upFolder, animationConfig, loadConfig);
            }

            if (dirAnimation.Left != null && dirAnimation.Right == null)
            {
                dirAnimation.Right = createLeftRightAnimation(dirAnimation.Left);
            }

            if (dirAnimation.Right != null && dirAnimation.Left == null)
            {
                dirAnimation.Left = createLeftRightAnimation(dirAnimation.Right);
            }

            return(dirAnimation);
        }
Ejemplo n.º 27
0
		public async Task<IImage> LoadImageAsync (string filePath, ILoadImageConfig config = null)
		{
			IResource resource = await Task.Run(() => _resources.LoadResource(filePath));
            return await loadImageAsync(resource, config);
		}
Ejemplo n.º 28
0
		public IAnimation LoadAnimationFromFiles(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string[] files)
		{
			return loadAnimationFromResources(_resources.LoadResources(files), animationConfig, loadConfig);
		}
Ejemplo n.º 29
0
 private IImage loadImage(IBitmap bitmap, ILoadImageConfig config = null, string id = null)
 {
     id = id ?? Guid.NewGuid().ToString();
     ITexture tex = createTexture(config);
     return loadImage(tex, bitmap, id, config, null);
 }
Ejemplo n.º 30
0
		public IAnimation LoadAnimationFromFolder (string folderPath, 
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return loadAnimationFromResources(_resources.LoadResources(folderPath), animationConfig, loadConfig);
		}
Ejemplo n.º 31
0
        private async Task<IImage> loadImageAsync (IResource resource, ILoadImageConfig config = null)
		{
			try 
			{
                if (resource == null) return new EmptyImage(1f, 1f);
				IBitmap bitmap = await Task.Run(() => _bitmapLoader.Load (resource.Stream));
				ITexture tex = createTexture(config);
				return loadImage(tex, bitmap, resource.ID, config, null);
			} 
			catch (ArgumentException e) 
			{
				Debug.WriteLine ("Failed to load image from {0}, is it really an image?\r\n{1}", resource.ID, e.ToString ());
				return null;
			}
		}
Ejemplo n.º 32
0
		private void getImageInfo(IBitmap bitmap, int cellX, int cellY, ISpriteSheet spriteSheet, 
                                  ILoadImageConfig loadConfig, string filePath, 
                                  out Rectangle rect, out IBitmap clone, out string path, out ITexture texture)
		{
            texture = new GLTexture(loadConfig.TextureConfig, _graphics);
			rect = new Rectangle (cellX * spriteSheet.CellWidth,
										cellY * spriteSheet.CellHeight, spriteSheet.CellWidth, spriteSheet.CellHeight);
			clone = bitmap.Crop (rect);
			path = string.Format ("{0}_{1}_{2}", rect.X, rect.Y, filePath);
		}
Ejemplo n.º 33
0
		private void manipulateImage(IBitmap bitmap, ILoadImageConfig config)
		{
			if (config == null) return;
			if (config.TransparentColorSamplePoint != null)
			{
				Color transparentColor = bitmap.GetPixel((int)config.TransparentColorSamplePoint.Value.X,
					(int)config.TransparentColorSamplePoint.Value.Y);
				bitmap.MakeTransparent(transparentColor);
			}
		}
Ejemplo n.º 34
0
		public IPanel GetPanel(string id, string imagePath, float x, float y, ILoadImageConfig loadConfig = null, bool addToUi = true)
		{
			IImage image = _graphics.LoadImage(imagePath, loadConfig);
			return GetPanel(id, image, x, y, addToUi);
		}
Ejemplo n.º 35
0
 private IImage getImage(ITexture texture, ISpriteSheet spriteSheet, ILoadImageConfig loadConfig)
 {
     return(new GLImage(AGSGame.Device.BitmapLoader.Load((int)Width, (int)Height), ID, texture, spriteSheet, loadConfig));
 }
Ejemplo n.º 36
0
        public async Task <ISlider> GetSliderAsync(string id, string imagePath, string handleImagePath, float value, float min, float max,
                                                   IObject parent = null, ITextConfig config = null, ILoadImageConfig loadConfig = null, bool addToUi = true)
        {
            var image = imagePath == null ? null : await _graphics.LoadImageAsync(imagePath, loadConfig);

            var handleImage = handleImagePath == null ? null : await _graphics.LoadImageAsync(handleImagePath, loadConfig);

            return(getSlider(id, image, handleImage, value, min, max, parent, config, addToUi));
        }
Ejemplo n.º 37
0
		public async Task<IAnimation> LoadAnimationFromFilesAsync(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string [] files)
		{
			return await loadAnimationFromResourcesAsync(await Task.Run(() => _resources.LoadResources (files)), 
			                                             animationConfig, loadConfig);
		}
Ejemplo n.º 38
0
        public async Task <IOutfit> LoadOutfitFromFoldersAsync(string baseFolder, string walkLeftFolder = null, string walkRightFolder = null,
                                                               string walkDownFolder  = null, string walkUpFolder  = null, string idleLeftFolder  = null, string idleRightFolder  = null,
                                                               string idleDownFolder  = null, string idleUpFolder  = null, string speakLeftFolder = null, string speakRightFolder = null,
                                                               string speakDownFolder = null, string speakUpFolder = null,
                                                               IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            IOutfit outfit = _resolver.Container.Resolve <IOutfit> ();

            outfit[AGSOutfit.Idle] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, idleLeftFolder, idleRightFolder,
                                                                                              idleDownFolder, idleUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Walk] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, walkLeftFolder, walkRightFolder,
                                                                                              walkDownFolder, walkUpFolder, animationConfig, loadConfig);

            outfit[AGSOutfit.Speak] = await _graphics.LoadDirectionalAnimationFromFoldersAsync(baseFolder, speakLeftFolder, speakRightFolder,
                                                                                               speakDownFolder, speakUpFolder, animationConfig, loadConfig);

            return(outfit);
        }
Ejemplo n.º 39
0
		public async Task<IAnimation> LoadAnimationFromFolderAsync (string folderPath,
			IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
		{
			return await loadAnimationFromResourcesAsync (await Task.Run(() => _resources.LoadResources (folderPath)), 
			                                   animationConfig, loadConfig);
		}
Ejemplo n.º 40
0
        public async Task <IAnimation> LoadAnimationFromSpriteSheetAsync(ISpriteSheet spriteSheet,
                                                                         IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null)
        {
            animationConfig = animationConfig ?? new AGSAnimationConfiguration();
            string    filePath = spriteSheet.Path;
            IResource resource = await Task.Run(() => _resources.LoadResource(filePath));

            if (resource == null)
            {
                throw new InvalidOperationException("Failed to load sprite sheet from " + filePath);
            }
            IBitmap bitmap = await Task.Run(() => _bitmapLoader.Load(resource.Stream));

            int          cellsInRow, cellsInCol, cellsTotal, cellX, cellY, cellsToGrab, cellsGrabbed = 0;
            Point        mainStep, secondStep;
            AGSAnimation animation;

            getSpriteSheetData(bitmap, spriteSheet, animationConfig, out cellsInRow, out cellsInCol,
                               out cellsTotal, out cellX, out cellY, out cellsToGrab, out mainStep, out secondStep,
                               out animation);
            for (int currentCell = 0; cellsGrabbed < cellsToGrab; currentCell++)
            {
                if (currentCell >= spriteSheet.StartFromCell)
                {
                    Rectangle rect; IBitmap clone; string path; ITexture tex;
                    getImageInfo(bitmap, cellX, cellY, spriteSheet, loadConfig, filePath, out rect, out clone, out path, out tex);
                    IImage image = _loadImage(tex, clone, path, loadConfig, spriteSheet);
                    _addAnimationFrame(image, animation);
                    cellsGrabbed++;
                }

                nextCell(mainStep, secondStep, cellsInRow, cellsInCol, ref cellX, ref cellY);
            }
            animation.Setup();
            return(animation);
        }
Ejemplo n.º 41
0
		public async Task<ISlider> GetSliderAsync(string id, string imagePath, string handleImagePath, float value, float min, float max,
			ITextConfig config = null, ILoadImageConfig loadConfig = null, bool addToUi = true)
		{
			var image = await _graphics.LoadImageAsync(imagePath, loadConfig);
			var handleImage = await _graphics.LoadImageAsync(handleImagePath, loadConfig);
			return getSlider(id, image, handleImage, value, min, max, config, addToUi);
		}
Ejemplo n.º 42
0
 public IAnimation LoadAnimationFromFiles(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string[] files)
 {
     if (files.Length == 0)
     {
         throw new InvalidOperationException("No files given to LoadAnimationFromFiles");
     }
     return(loadAnimationFromResources(files[0], _resources.LoadResourcesFromPaths(files), animationConfig, loadConfig));
 }
Ejemplo n.º 43
0
		public async Task<IPanel> GetPanelAsync(string id, string imagePath, float x, float y, ILoadImageConfig loadConfig = null, bool addToUi = true)
		{
			IImage image = await _graphics.LoadImageAsync(imagePath, loadConfig);
			return GetPanel (id, image, x, y, addToUi);
		}
Ejemplo n.º 44
0
 public async Task <IAnimation> LoadAnimationFromFilesAsync(IAnimationConfiguration animationConfig = null, ILoadImageConfig loadConfig = null, params string [] files)
 {
     if (files.Length == 0)
     {
         throw new InvalidOperationException("No files given to LoadAnimationFromFilesAsync");
     }
     return(await loadAnimationFromResourcesAsync(files[0], await Task.Run(() => _resources.LoadResourcesFromPaths(files)),
                                                  animationConfig, loadConfig));
 }