Beispiel #1
0
		public Video.DrawState SetupDrawing(SpriteId id, Vector2 location, Vector2 offset, Vector2 scale, SpriteEffects flip)
		{
			Sprite sprite = GetSprite(id);

			if ((flip & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally) offset.X = -offset.X;
			if ((flip & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically) offset.Y = -offset.Y;

			m_drawstate.Reset();
			m_drawstate.Set(sprite);
			m_drawstate.Offset = offset;
			m_drawstate.AddData(location, null);
			m_drawstate.Flip = flip;
			m_drawstate.Scale = scale;

			if (UseOverride == true && sprite != null && sprite.PaletteOverride == true)
			{
				if (OverridePalette != null)
				{
					m_drawstate.Palette = OverridePalette;
				}
				else
				{
					Texture2D newpalette = SpriteFile.GetFirstPalette();
					if (newpalette != null) m_drawstate.Palette = newpalette;
				}
			}

			return m_drawstate;
		}
		public Int32 GetIndex(SpriteId id)
		{
			Int32 index;
			if (m_indexcache.TryGetValue(id, out index) == false) return Int32.MinValue;

			return index;
		}
Beispiel #3
0
		public SpriteFileData(Int32 fileoffset, Int32 pcxsize, Point axis, SpriteId id, Int32 sharedindex, Boolean copylastpalette)
		{
			m_fileoffset = fileoffset;
			m_pcxsize = pcxsize;
			m_axis = axis;
			m_id = id;
			m_sharedindex = sharedindex;
			m_copylastpalette = copylastpalette;
			m_isvalid = null;
		}
		public SpriteFileSubHeader(File file)
		{
			if (file == null) throw new ArgumentNullException("file");

			Byte[] data = file.ReadBytes(19);
			if (data.Length != 19) throw new ArgumentException("File is not long enough", "file");

			m_nextoffset = BitConverter.ToInt32(data, 0);
			m_imagesize = BitConverter.ToInt32(data, 4);
			m_axis = new Point(BitConverter.ToInt16(data, 8), BitConverter.ToInt16(data, 10));
			m_id = new SpriteId(BitConverter.ToInt16(data, 12), BitConverter.ToInt16(data, 14));
			m_sharedindex = BitConverter.ToInt16(data, 16);
			m_copylastpalette = data[18] > 0;
		}
Beispiel #5
0
		/// <summary>
		/// Initializes a new instance of this class.
		/// </summary>
		/// <param name="id">The index of this element in the Animation.</param>
		/// <param name="clsns">The collection of collision boxes in this elements.</param>
		/// <param name="ticks">The time, in gameticks, that this element is drawn.</param>
		/// <param name="spriteid">The Sprite that is drawn for this element. SpriteId.Invalid for nothing to be drawn.</param>
		/// <param name="offset">The offset, in pixels, used to draw this element.</param>
		/// <param name="flip">The drawing orientation of this element.</param>
		/// <param name="blending">Alpha blending to be used while drawing this element.</param>
		public AnimationElement(Int32 id, List<Clsn> clsns, Int32 ticks, Int32 starttick, SpriteId spriteid, Point offset, SpriteEffects flip, Blending blending)
		{
			if (id < 0) throw new ArgumentOutOfRangeException("id");
			if (clsns == null) throw new ArgumentNullException("clsns");
			if (ticks < -1) throw new ArgumentOutOfRangeException("ticks");
			if (starttick < 0) throw new ArgumentOutOfRangeException("starttick");
			if (blending == null) throw new ArgumentNullException("blending");

			m_id = id;
			m_clsns = clsns;
			m_gameticks = ticks;
			m_spriteid = spriteid;
			m_offset = (Vector2)offset;
			m_flip = flip;
			m_blending = blending;
			m_starttick = starttick;
		}
Beispiel #6
0
		Boolean TryGetSpriteData(SpriteId id, out SpriteFileData data, out Int32 dataindex)
		{
			data = null;
			dataindex = Int32.MinValue;

			if (id == SpriteId.Invalid) return false;

			Int32 index = m_collection.GetIndex(id);
			if (index == Int32.MinValue) return false;

			SpriteFileData sfd = m_collection.GetData(index);
			if (sfd == null) return false;

			data = sfd;
			dataindex = index;
			return true;
		}
Beispiel #7
0
		public Sprite GetSprite(SpriteId id)
		{
			if (id == SpriteId.Invalid) return null;

			if (m_cachedsprites.ContainsKey(id) == true) return m_cachedsprites[id];

			SpriteFileData data;
			Int32 dataindex;
			if (TryGetSpriteData(id, out data, out dataindex) == false) return null;

			Point size;
			Texture2D pixels;
			Texture2D palette;
			Boolean paletteoverride = false;
			Boolean ownpixels = true;
			Boolean ownpalette = true;

			if (data.PcxSize > 0)
			{
				m_file.SeekFromBeginning(data.FileOffset);
				if (m_spritesystem.LoadImage(m_file, data.PcxSize, out size, out pixels, out palette) == false)
				{
					Log.Write(LogLevel.Warning, LogSystem.SpriteSystem, "Cannot load PCX image data from '{0}' for sprite #{1}", Filepath, id);

					data.IsValid = false;
					return null;
				}
			}
			else
			{
				SpriteFileData shareddata = m_collection.GetData(data.SharedIndex);
				if (shareddata == null || shareddata.Id == id) return null;

				Sprite shared_sprite = GetSprite(shareddata.Id);
				if (shared_sprite == null) return null;

				size = shared_sprite.Size;
				paletteoverride = shared_sprite.PaletteOverride;
				pixels = shared_sprite.Pixels;
				palette = shared_sprite.Palette;
				ownpixels = false;
				ownpalette = false;
			}

			if (data.CopyLastPalette == true && dataindex != 0)
			{
				SpriteFileData previousdata = m_collection.GetData(dataindex - 1);
				if (previousdata != null && previousdata.Id != id)
				{
					Sprite previoussprite = GetSprite(previousdata.Id);
					if (previoussprite != null)
					{
						paletteoverride = previoussprite.PaletteOverride;
						ownpalette = false;

						palette = previoussprite.Palette;
					}
				}
			}

			if (id == new SpriteId(0, 0) || id == SpriteId.SmallPortrait) paletteoverride = true;

			Sprite sprite = new Sprite(size, data.Axis, ownpixels, pixels, ownpalette, palette, paletteoverride);
			m_cachedsprites.Add(id, sprite);

			return sprite;
		}
Beispiel #8
0
 /// private メソッド
 ///---------------------------------------------------------------------------
 /// スプライトの登録
 public void SetSprite( SpriteId id )
 {
     spritList[(int)id].Visible = true;
 }
Beispiel #9
0
 /// スプライトのフォーカスを変更する
 public void SetFocus( SpriteId sprId, int idx )
 {
     int id = (int)sprId;
     spritList[id].SetDrawRect( lytRectData[id*4+0] + lytRectData[id*4+2] * idx,
                            lytRectData[id*4+1], lytRectData[id*4+2], lytRectData[id*4+3] );
 }
Beispiel #10
0
 /// スプライトのα値を変更する
 public void SetAlpha( SpriteId sprId, float alpha )
 {
     int id = (int)sprId;
     spritList[id].Alpha = alpha;
 }
Beispiel #11
0
 public int GetCenterY( SpriteId sprId )
 {
     int id = (int)sprId;
     int scrPosY = (int)spritList[id].PositionY;
     return( scrPosY+(int)(spritList[id].DrawRectHeight/2) );
 }
Beispiel #12
0
 /// 配置物の中心座標を返す
 public int GetCenterX( SpriteId sprId )
 {
     int id = (int)sprId;
     int scrPosX = (int)spritList[id].PositionX;
     return( scrPosX+(int)(spritList[id].DrawRectWidth/2) );
 }
Beispiel #13
0
 /// スプライトを削除
 public void ClearSprite( SpriteId id )
 {
     spritList[(int)id].Visible = false;
 }
Beispiel #14
0
        /// Rectの範囲に入っているかのチェック
        public bool CheckRect( SpriteId sprId, int pointX, int pointY )
        {
            if(spritList==null){
            return false;
            }

            int id = (int)sprId;
            int scrPosX = (int)spritList[id].PositionX;
            int scrPosY = (int)spritList[id].PositionY;

            if( ( scrPosX <= pointX && pointX <= (scrPosX + spritList[id].DrawRectWidth) ) &&
            ( scrPosY <= pointY && pointY <= (scrPosY + spritList[id].DrawRectHeight) ) ){
            return true;
            }
            return false;
        }
Beispiel #15
0
		public void Draw(SpriteId id, Vector2 location, Vector2 offset, Vector2 scale, SpriteEffects flip)
		{
			SetupDrawing(id, location, offset, scale, flip).Use();
		}
Beispiel #16
0
		public Sprite GetSprite(SpriteId spriteid)
		{
			return m_spritefile.GetSprite(spriteid);
		}