| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using OpenVIII.Encoding.Tags;
- using System;
- using System.IO;
- using System.Linq;
- namespace OpenVIII
- {
- public static class Module_icon_test
- {
- #region Fields
- private const int DefaultPalette = 2;
- private static Mode currentMode;
- private static Icons.ID icon = Icons.ID.Arrow_Down;
- private static int palette = DefaultPalette;
- private static float zoom = 40f;
- #endregion Fields
- #region Enums
- private enum Mode
- {
- Initialize,
- Draw,
- Wait
- }
- #endregion Enums
- #region Methods
- public static void Draw()
- {
- switch (currentMode)
- {
- case Mode.Initialize:
- break;
- case Mode.Wait:
- case Mode.Draw:
- DrawIcons();
- break;
- }
- }
- public static void SaveStringToFile()
- {
- FileStream fs = null;
- //fs is disposed by binary writer
- using (var bw =
- new BinaryWriter(fs = File.Open("D:\\iconsdatadump.csv",
- FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
- {
- bw.Write(System.Text.Encoding.UTF8.GetBytes(ToString()));
- fs = null;
- }
- }
- /// <summary>
- /// Make sure the next frame will draw.
- /// </summary>
- public static void Show()
- {
- if (currentMode == Mode.Wait)
- currentMode = Mode.Draw;
- Memory.SuppressDraw = false;
- }
- public static new string ToString()
- {
- var output = "{Enum Name},{Enum ID}," + Memory.Icons.GetEntry(Icons.ID.Finger_Right).ToStringHeader;
- for (uint i = 0; i < Memory.Icons.Count; i++)
- {
- var eg = Memory.Icons.GetEntryGroup((Icons.ID)i);
- foreach (Entry e in eg)
- {
- output += $"{((Icons.ID)i).ToString().Replace('_', ' ')},{i}," + e.ToString();
- }
- }
- return output;
- }
- public static void Update()
- {
- if (Input2.DelayedButton(new InputButton() { Key = Keys.OemMinus, Trigger = ButtonTrigger.Press }) || Input2.DelayedButton(new InputButton() { Key = Keys.Subtract, Trigger = ButtonTrigger.Press }))
- {
- if (zoom - 1 < 1f)
- zoom = 1f;
- else
- zoom--;
- Show();
- }
- if (Input2.DelayedButton(new InputButton() { Key = Keys.OemPlus, Trigger = ButtonTrigger.Press }) || Input2.DelayedButton(new InputButton() { Key = Keys.Add, Trigger = ButtonTrigger.Press }))
- {
- if (zoom + 1 > 100f)
- zoom = 100f;
- else
- zoom++;
- Show();
- }
- if (Input2.DelayedButton(FF8TextTagKey.Up))
- {
- if (palette <= 0)
- palette = (int)Memory.Icons.PaletteCount - 1;
- else
- palette--;
- Show();
- }
- if (Input2.DelayedButton(FF8TextTagKey.Down))
- {
- if (palette >= Memory.Icons.PaletteCount - 1)
- palette = 0;
- else
- palette++;
- Show();
- }
- if (Input2.DelayedButton(FF8TextTagKey.Right) || Input2.Button(Keys.PageDown))
- {
- do
- {
- if (icon >= Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max())
- icon = 0;
- else
- icon++;
- }
- while (Memory.Icons.GetEntry(icon) == null);
- Show();
- }
- if (Input2.DelayedButton(FF8TextTagKey.Left) || Input2.Button(Keys.PageUp))
- {
- do
- {
- if (icon <= 0)
- icon = Enum.GetValues(typeof(Icons.ID)).Cast<Icons.ID>().Max();
- //else if (Memory.Icons.GetEntry(icon) != null && Memory.Icons.GetEntry(icon).GetLoc.Count > 1)
- // icon -= Memory.Icons.GetEntry(icon).GetLoc.Count;
- else
- icon--;
- }
- while (Memory.Icons.GetEntry(icon) == null);
- Show();
- }
- switch (currentMode)
- {
- case Mode.Initialize:
- //SaveStringToFile();
- currentMode++;
- break;
- case Mode.Draw:
- currentMode++;
- break;
- case Mode.Wait:
- Memory.SuppressDraw = true;
- break;
- }
- }
- private static void DrawIcons()
- {
- Memory.SpriteBatchStartAlpha(ss: SamplerState.PointClamp);
- Memory.SpriteBatch.GraphicsDevice.Clear(Color.Gray);
- Memory.SpriteBatchEnd();
- var vp = Memory.Graphics.GraphicsDevice.Viewport;
- var scale = new Vector2(zoom);
- var dst = new Rectangle()
- {
- Width = (int)(Memory.Icons.GetEntryGroup(icon).Width * scale.X),
- Height = (int)(Memory.Icons.GetEntryGroup(icon).Height * scale.Y)
- };
- if (icon == Icons.ID.Menu_BG_368)
- {
- dst.Width = vp.Width;
- dst.Height = vp.Height - 50;
- scale = Vector2.Zero;
- }
- else
- {
- dst.X = vp.Width / 2 - dst.Width / 2;
- dst.Y = vp.Height / 2 - dst.Height / 2;
- }
- dst.Size = Point.Zero;
- Memory.SpriteBatchStartAlpha(ss: SamplerState.PointClamp);
- Memory.Icons.Draw(icon, palette, dst, scale);
- Memory.Font.RenderBasicText(
- $"{(icon).ToString().Replace('_', ' ')}\n" +
- $"ID: {(ushort)icon}\n\n" +
- $"palette: {palette}\n\n" +
- $"width: {Memory.Icons[icon].Width}\n" +
- $"height: {Memory.Icons[icon].Height}",
- (int)(vp.Width * 0.10f), (int)(vp.Height * 0.05f), lineSpacing: 0);
- Memory.SpriteBatchEnd();
- }
- #endregion Methods
- }
- }
|