コード例 #1
0
 public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
 {
     Ultima.FileIndex mFileIndex2;
     int num;
     int num1;
     int num2;
     bool flag;
     if (!preserveHue)
     {
         Animations.Translate(ref body, ref hue);
     }
     else
     {
         Animations.Translate(ref body);
     }
     switch (BodyConverter.Convert(ref body))
     {
         case 2:
         {
             mFileIndex2 = Animations.m_FileIndex2;
             if (body >= 200)
             {
                 num = 22000 + (body - 200) * 65;
                 break;
             }
             else
             {
                 num = body * 110;
                 break;
             }
         }
         case 3:
         {
             mFileIndex2 = Animations.m_FileIndex3;
             if (body < 300)
             {
                 num = body * 65;
                 break;
             }
             else if (body >= 400)
             {
                 num = 35000 + (body - 400) * 175;
                 break;
             }
             else
             {
                 num = 33000 + (body - 300) * 110;
                 break;
             }
         }
         default:
         {
             mFileIndex2 = Animations.m_FileIndex;
             if (body < 200)
             {
                 num = body * 110;
                 break;
             }
             else if (body >= 400)
             {
                 num = 35000 + (body - 400) * 175;
                 break;
             }
             else
             {
                 num = 22000 + (body - 200) * 65;
                 break;
             }
         }
     }
     num = num + action * 5;
     num = (direction > 4 ? num + (direction - (direction - 4) * 2) : num + direction);
     Stream stream = mFileIndex2.Seek(num, out num1, out num2, out flag);
     if (stream == null)
     {
         return null;
     }
     bool flag1 = direction > 4;
     BinaryReader binaryReader = new BinaryReader(stream);
     ushort[] numArray = new ushort[256];
     for (int i = 0; i < 256; i++)
     {
         numArray[i] = (ushort)(binaryReader.ReadUInt16() ^ 32768);
     }
     int position = (int)binaryReader.BaseStream.Position;
     int num3 = binaryReader.ReadInt32();
     int[] numArray1 = new int[num3];
     for (int j = 0; j < num3; j++)
     {
         numArray1[j] = position + binaryReader.ReadInt32();
     }
     bool flag2 = (hue & 32768) == 0;
     hue = (hue & 16383) - 1;
     Hue list = null;
     if (hue >= 0 && hue < (int)Hues.List.Length)
     {
         list = Hues.List[hue];
     }
     Frame[] frame = new Frame[num3];
     for (int k = 0; k < num3; k++)
     {
         binaryReader.BaseStream.Seek((long)numArray1[k], SeekOrigin.Begin);
         frame[k] = new Frame(numArray, binaryReader, flag1);
         if (list != null)
         {
             list.ApplyTo(frame[k].Bitmap, flag2);
         }
     }
     return frame;
 }
コード例 #2
0
		public static Frame[] GetAnimation(int body, int action, int direction, int fileType)
		{
			FileIndex fileIndex;
			int index;
			GetFileIndex(body, action, direction, fileType, out fileIndex, out index);

			int length, extra;
			bool patched;

			Stream stream = fileIndex.Seek(index, out length, out extra, out patched);

			if (stream == null)
			{
				return null;
			}

			bool flip = direction > 4;

			using (var bin = new BinaryReader(stream))
			{
				var palette = new ushort[0x100];

				for (int i = 0; i < 0x100; ++i)
				{
					palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);
				}

				var start = (int)bin.BaseStream.Position;
				int frameCount = bin.ReadInt32();

				var lookups = new int[frameCount];

				for (int i = 0; i < frameCount; ++i)
				{
					lookups[i] = start + bin.ReadInt32();
				}

				var frames = new Frame[frameCount];

				for (int i = 0; i < frameCount; ++i)
				{
					bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin);
					frames[i] = new Frame(palette, bin, flip);
				}

				return frames;
			}
		}
コード例 #3
0
		/// <summary>
		///     Returns Framelist
		/// </summary>
		/// <param name="body"></param>
		/// <param name="action"></param>
		/// <param name="direction"></param>
		/// <param name="hue"></param>
		/// <param name="preserveHue">
		///     No Hue override <see cref="bodydev" />
		/// </param>
		/// <param name="FirstFrame"></param>
		/// <returns></returns>
		public static Frame[] GetAnimation(
			int body, int action, int direction, ref int hue, bool preserveHue, bool FirstFrame)
		{
			if (preserveHue)
			{
				Translate(ref body);
			}
			else
			{
				Translate(ref body, ref hue);
			}

			int fileType = BodyConverter.Convert(ref body);

			FileIndex fileIndex;
			int index;
			GetFileIndex(body, action, direction, fileType, out fileIndex, out index);

			int length, extra;
			bool patched;
			Stream stream = fileIndex.Seek(index, out length, out extra, out patched);

			if (stream == null)
			{
				return null;
			}
			if (m_StreamBuffer == null || m_StreamBuffer.Length < length)
			{
				m_StreamBuffer = new byte[length];
			}
			stream.Read(m_StreamBuffer, 0, length);
			m_MemoryStream = new MemoryStream(m_StreamBuffer, false);

			bool flip = direction > 4;
			Frame[] frames;
			using (var bin = new BinaryReader(m_MemoryStream))
			{
				var palette = new ushort[0x100];

				for (int i = 0; i < 0x100; ++i)
				{
					palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);
				}

				var start = (int)bin.BaseStream.Position;
				int frameCount = bin.ReadInt32();

				var lookups = new int[frameCount];

				for (int i = 0; i < frameCount; ++i)
				{
					lookups[i] = start + bin.ReadInt32();
				}

				bool onlyHueGrayPixels = (hue & 0x8000) != 0;

				hue = (hue & 0x3FFF) - 1;

				Hue hueObject;

				if (hue >= 0 && hue < Hues.List.Length)
				{
					hueObject = Hues.List[hue];
				}
				else
				{
					hueObject = null;
				}

				if (FirstFrame)
				{
					frameCount = 1;
				}
				frames = new Frame[frameCount];

				for (int i = 0; i < frameCount; ++i)
				{
					bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin);
					frames[i] = new Frame(palette, bin, flip);

					if (hueObject != null)
					{
						if (frames[i] != null)
						{
							if (frames[i].Bitmap != null)
							{
								hueObject.ApplyTo(frames[i].Bitmap, onlyHueGrayPixels);
							}
						}
					}
				}
				bin.Close();
			}
			m_MemoryStream.Close();
			return frames;
		}
コード例 #4
0
 static Frame()
 {
     Frame.Empty = new Frame();
     Frame.EmptyFrames = new Frame[] { Frame.Empty };
 }
コード例 #5
0
ファイル: Animations.cs プロジェクト: greeduomacro/divinity
        public static Frame[] GetAnimation( int body, int action, int direction, int hue, bool preserveHue )
        {
            if ( preserveHue )
                Translate( ref body );
            else
                Translate( ref body, ref hue );

            int fileType = BodyConverter.Convert( ref body );
            FileIndex fileIndex;

            int index;

            switch ( fileType )
            {
                default:
                case 1:
                {
                    fileIndex = m_FileIndex;

                    if ( body < 200 )
                        index = body * 110;
                    else if ( body < 400 )
                        index = 22000 + ((body - 200) * 65);
                    else
                        index = 35000 + ((body - 400) * 175);

                    break;
                }
                case 2:
                {
                    fileIndex = m_FileIndex2;

                    if ( body < 200 )
                        index = body * 110;
                    else
                        index = 22000 + ((body - 200) * 65);

                    break;
                }
                case 3:
                {
                    fileIndex = m_FileIndex3;

                    if ( body < 300 )
                        index = body * 65;
                    else if ( body < 400 )
                        index = 33000 + ((body - 300) * 110);
                    else
                        index = 35000 + ((body - 400) * 175);

                    break;
                }
            }

            index += action * 5;

            if ( direction <= 4 )
                index += direction;
            else
                index += direction - (direction - 4) * 2;

            int length, extra;
            bool patched;
            Stream stream = fileIndex.Seek( index, out length, out extra, out patched );

            if ( stream == null )
                return null;

            bool flip = ( direction > 4 );

            BinaryReader bin = new BinaryReader( stream );

            ushort[] palette = new ushort[0x100];

            for ( int i = 0; i < 0x100; ++i )
                palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);

            int start = (int)bin.BaseStream.Position;
            int frameCount = bin.ReadInt32();

            int[] lookups = new int[frameCount];

            for ( int i = 0; i < frameCount; ++i )
                lookups[i] = start + bin.ReadInt32();

            bool onlyHueGrayPixels = ( (hue & 0x8000) == 0 );

            hue = (hue & 0x3FFF) - 1;

            Hue hueObject = null;

            if ( hue >= 0 && hue < Hues.List.Length )
                hueObject = Hues.List[hue];

            Frame[] frames = new Frame[frameCount];

            for ( int i = 0; i < frameCount; ++i )
            {
                bin.BaseStream.Seek( lookups[i], SeekOrigin.Begin );
                frames[i] = new Frame( palette, bin, flip );

                if ( hueObject != null )
                    hueObject.ApplyTo( frames[i].Bitmap, onlyHueGrayPixels );
            }

            return frames;
        }
コード例 #6
0
        private void DrawAnim(object sender, DrawListViewItemEventArgs e)
        {
            var race = Race.GetInstance(cbBody.SelectedIndex);
            var body = new int[3];
            var bhue = new int[body.Length];
            var bact = (e.Item.Tag as int[])[0];
            var bdir = (e.Item.Tag as int[])[1];
            var bfrm = (e.Item.Tag as int[])[2];

            if (sender == listViewBody) {
                body[1] = (e.Item.Tag as int[])[3];
                e.Graphics.DrawRectangle(e.Item.Selected ? PenAnimBorder : PenAnimBack, e.Bounds.X-0, e.Bounds.Y-0, e.Bounds.Width+0, e.Bounds.Height+0);
                e.Graphics.DrawRectangle(e.Item.Selected ? PenAnimBorder : PenAnimBack, e.Bounds.X-1, e.Bounds.Y-1, e.Bounds.Width+2, e.Bounds.Height+2);
                e.Graphics.DrawRectangle(e.Item.Selected ? PenAnimBorder : PenAnimBack, e.Bounds.X-2, e.Bounds.Y-2, e.Bounds.Width+4, e.Bounds.Height+4);
            } else if (sender == listViewBodyHue) {
                body[2] = SelectedEntry.Animation;
                bhue[2] = (e.Item.Tag as int[])[3];
                if (SelectedEntry.ItemPartialHue == CheckState.Checked)
                    bhue[2] |= 0x8000;
                e.Graphics.DrawRectangle(e.Item.Selected ? PenAnimBorder : PenAnimBack, e.Bounds.X-0, e.Bounds.Y-0, e.Bounds.Width+0, e.Bounds.Height+0);
                e.Graphics.DrawRectangle(e.Item.Selected ? PenAnimBorder : PenAnimBack, e.Bounds.X-1, e.Bounds.Y-1, e.Bounds.Width+2, e.Bounds.Height+2);
                e.Graphics.DrawRectangle(e.Item.Selected ? PenAnimBorder : PenAnimBack, e.Bounds.X-2, e.Bounds.Y-2, e.Bounds.Width+4, e.Bounds.Height+4);
            } else {
                body[1] = menuUseFemaleBody.Checked ? race.F_Body : race.M_Body;
                bhue[1] = race.ColHue;
                if (body[1] > 0 && bact >= 23 && bact <= 29) {
                    body[0] = 1052;
                    bhue[0] = 0;
                }
                if (SelectedEntry != null && SelectedEntry.Number > 0) {
                    body[2] = SelectedEntry.Animation;
                    bhue[2] = SelectedEntry.HueColor;
                    if (SelectedEntry.ItemPartialHue == CheckState.Checked)
                        bhue[2] |= 0x8000;
                }
            }

            var fram = new Frame[body.Length];
            var posx = new int[body.Length];
            var posy = new int[body.Length];
            int minx = int.MaxValue, miny = int.MaxValue, maxx = 0, maxy = 0;

            for (int i = 0; i < body.Length; ++i) {
                if (body[i] <= 0) continue;
                var anim = Animations.GetAnimation(body[i], bact, bdir, ref bhue[i], true, false);
                if (anim == null || anim.Length <= bfrm) continue;
                var prev = anim[bfrm-1 >= 0 ? bfrm-1 : anim.Length-1];
                fram[i] = anim[bfrm];
                if (prev == null || fram[i] == null || prev.Bitmap == null || fram[i].Bitmap == null) continue;

                posx[i] = e.Bounds.X-2 + (e.Bounds.Width+4)/2    - fram[i].Center.X;
                posy[i] = e.Bounds.Y-2 + (e.Bounds.Height+4)*4/5 - fram[i].Center.Y - fram[i].Bitmap.Height;
                var prx = e.Bounds.X-2 + (e.Bounds.Width+4)/2    - prev.Center.X;
                var pry = e.Bounds.Y-2 + (e.Bounds.Height+4)*4/5 - prev.Center.Y - prev.Bitmap.Height;
                minx = Math.Min(minx, Math.Min(posx[i], prx));
                miny = Math.Min(miny, Math.Min(posy[i], pry));
                maxx = Math.Max(maxx, Math.Max(posx[i]+fram[i].Bitmap.Width,  prx+prev.Bitmap.Width));
                maxy = Math.Max(maxy, Math.Max(posy[i]+fram[i].Bitmap.Height, pry+prev.Bitmap.Height));
            }

            e.Graphics.FillRectangle(BrushItemBack, minx, miny, maxx-minx, maxy-miny);
            for (int i = 0; i < fram.Length; ++i) {
                if (fram[i] == null || fram[i].Bitmap == null) continue;
                e.Graphics.DrawImage(fram[i].Bitmap, posx[i], posy[i], new Rectangle(0, 0, fram[i].Bitmap.Width, fram[i].Bitmap.Height), GraphicsUnit.Pixel);
            }
            if (!String.IsNullOrEmpty(e.Item.Name)) {
                var trect = new Rectangle(e.Bounds.X, e.Bounds.Y + e.Bounds.Height - FontItemName.Height, e.Bounds.Width, FontItemName.Height);
                var flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak;
                TextRenderer.DrawText(e.Graphics, e.Item.Name, FontItemName, trect, Color.LightSlateGray, flags);
            }
        }