Skip to content

Commit

Permalink
progess made on load screen
Browse files Browse the repository at this point in the history
well it's been a while since I commited lol

I got a basic layout of the select slot screen drawing. I had muliple bugs with entrygroup drawing that I didn't see till I did this. they are now fixed.

the background of windows now only stretches if it's smaller then the desired draw location. in order for all the windows to look the same i had to also set scale instead of auto detecting it.

I added a new value to entry for enabling fill on a texture.

moved more menu files into the menu folder.

I switched over to the newer hires fonts in the menus the low res font doesn't scale well.  I also added a small drop shadow. maybe we can make it optional in the future for people to just swap which font they want on the fly.

added a modded bool to texturehandler so we can detect if modded textures are being used. so i could skip the drawshadow if there is a mod.
  • Loading branch information
Sebanisu committed Apr 24, 2019
1 parent ca4bb26 commit d48d023
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 89 deletions.
1 change: 1 addition & 0 deletions FF8/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public Entry()
public float Width { get=>Size.X; internal set=> Size.X=value; }
public float Y { get => Location.Y; internal set => Location.Y = value; }
public float X { get => Location.X; internal set => Location.X = value; }
public Vector2 Fill { get; internal set; }

#endregion Properties

Expand Down
61 changes: 50 additions & 11 deletions FF8/EntryGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,36 +90,70 @@ public void Add(params Entry[] entries)
internal Vector2 Abs(Vector2 v2 ) {
return new Vector2(Math.Abs(v2.X), Math.Abs(v2.Y));
}

internal void Draw(List<TextureHandler> textures, int pallet, Rectangle inputdst, float scale = 1f, float fade = 1f)
internal Point RoundedPoint(Vector2 v) => new Point((int)Math.Round(v.X),(int)Math.Round(v.Y));
internal void Draw(List<TextureHandler> textures, int pallet, Rectangle inputdst, float inscale = 1f, float fade = 1f)
{
Rectangle dst;
scale = Math.Abs(scale);
inscale = Math.Abs(inscale);
inputdst.Width = Math.Abs(inputdst.Width);
inputdst.Height = Math.Abs(inputdst.Height);
if (inputdst.X + inputdst.Width < 0 || inputdst.Y + inputdst.Height < 0) return;
if ((int)(8 * scale) <= float.Epsilon)
if ((int)(8 * inscale) <= float.Epsilon)
{
//vscale = (float)dst.Height / Height;
scale = (float)inputdst.Width /Width;
inscale = (float)inputdst.Width /Width;
}

Vector2 scale = new Vector2(inscale);
foreach (Entry e in list)
{
int cpallet = e.CustomPallet < 0 || e.CustomPallet >= textures.Count ? pallet : e.CustomPallet;
dst = inputdst;


Vector2 Offset = e.Offset * scale;
Point offset2 = (e.End * scale).ToPoint();
Point offset2 = RoundedPoint(e.End * scale);
dst.Offset(e.Snap_Right ? inputdst.Width : 0, e.Snap_Bottom ? inputdst.Height : 0);
dst.Offset(Offset);
dst.Size = (e.Size * scale).ToPoint();

dst.Size = RoundedPoint(e.Size * scale);
Rectangle src = e.GetRectangle;
bool testY = false;
bool testX = false;

if (dst.Width > inputdst.Width)
{
int change = (dst.Width - inputdst.Width);
src.Width -= (int)(change / scale.X);
dst.Width -= change;
}
else if (e.Fill.X > 0)
{
//int change = Math.Abs(dst.Width - inputdst.Width);
float hscale = (float)inputdst.Width / Width;
if (hscale > scale.X)
{
scale.X = hscale;
dst.Width = (int)Math.Round((src.Width * hscale));
}
}
if (dst.Height > inputdst.Height)
{
int change = (dst.Height - inputdst.Height);
src.Height -= (int)(change / scale.Y);
dst.Height -= change;
}
else if (e.Fill.Y > 0)
{
//int change = Math.Abs(dst.Width - inputdst.Width);
float vscale = (float)inputdst.Height / Height;
if (vscale > scale.Y)
{
scale.Y = vscale;
dst.Height = (int)Math.Round((src.Height * vscale));
}
}

if (dst.Height<=0 || dst.Height <= 0) continue; //infinate loop prevention

do
{
do
Expand All @@ -131,7 +165,7 @@ internal void Draw(List<TextureHandler> textures, int pallet, Rectangle inputdst
{
int correction = (inputdst.Y + inputdst.Height + offset2.Y) - (dst.Y + dst.Height);
dst.Height += correction;
src.Height += (int)Math.Floor(correction / scale);
src.Height += (int)Math.Floor(correction / scale.Y);
}
}
if(e.Tile.X > 0)
Expand All @@ -141,9 +175,14 @@ internal void Draw(List<TextureHandler> textures, int pallet, Rectangle inputdst
{
int correction = (inputdst.X + inputdst.Width + offset2.X) - (dst.X + dst.Width);
dst.Width += correction;
src.Width += (int)Math.Floor(correction / scale);
src.Width += (int)Math.Floor(correction / scale.X);
}
}
//else if( dst.Width< inputdst.Width)
//{
// float hscale = (float)inputdst.Width / Width;
// dst.Width = (int)(src.Width * hscale);
//}
textures[cpallet].Draw(dst, src, Color.White * fade);
if (e.Tile.Y > 0)
{
Expand Down
16 changes: 8 additions & 8 deletions FF8/FF8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@
<Compile Include="Menu\Magazine.InsertCustomEntries.cs" />
<Compile Include="Menu\Magazine.ID.cs" />
<Compile Include="Menu\Strings.cs" />
<Compile Include="Module_card_test.cs" />
<Compile Include="Module_main_menu_debug.Item.cs" />
<Compile Include="Module_main_menu_Loading.cs" />
<Compile Include="Module_main_menu_MainLobby.cs" />
<Compile Include="Module_main_menu_DebugLobby.cs" />
<Compile Include="Menu\Module_card_test.cs" />
<Compile Include="Menu\Module_main_menu_debug.Item.cs" />
<Compile Include="Menu\Module_main_menu_Loading.cs" />
<Compile Include="Menu\Module_main_menu_MainLobby.cs" />
<Compile Include="Menu\Module_main_menu_DebugLobby.cs" />
<Compile Include="Sources\Environment\Game\Location\GameLocation.cs" />
<Compile Include="Sources\Environment\Game\Location\IGameLocationProvider.cs" />
<Compile Include="Sources\Environment\Game\Location\LinuxGameLocationProvider.cs" />
Expand Down Expand Up @@ -182,10 +182,10 @@
<Compile Include="ModuleHandler.cs" />
<Compile Include="Battle\module_battle.cs" />
<Compile Include="Battle\module_battle_Debug.cs" />
<Compile Include="Module_face_test.cs" />
<Compile Include="Menu\Module_face_test.cs" />
<Compile Include="module_field_debug.cs" />
<Compile Include="Module_icon_test.cs" />
<Compile Include="module_main_menu_debug.cs" />
<Compile Include="Menu\Module_icon_test.cs" />
<Compile Include="Menu\module_main_menu_debug.cs" />
<Compile Include="module_movie_test.cs" />
<Compile Include="module_overture_debug.cs" />
<Compile Include="World\module_world_debug.cs" />
Expand Down
112 changes: 67 additions & 45 deletions FF8/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,59 +619,71 @@ internal void LoadFonts()

internal void ReadTdw(byte[] Tdw)
{
int widthPointer = BitConverter.ToInt32(Tdw, 0);
int dataPointer = BitConverter.ToInt32(Tdw, 4);
TIM2 tim = new TIM2(Tdw, (uint)dataPointer);
uint widthPointer = BitConverter.ToUInt32(Tdw, 0);
uint dataPointer = BitConverter.ToUInt32(Tdw, 4);

getWidths(Tdw, widthPointer, dataPointer - widthPointer);
TIM2 tim = new TIM2(Tdw, dataPointer);
menuFont = new Texture2D(Memory.graphics.GraphicsDevice, tim.GetWidth, tim.GetHeight);
menuFont.SetData(tim.CreateImageBuffer(tim.GetClutColors(ColorID.White)));
}

public Rectangle CalcBasicTextArea(byte[] buffer, Vector2 pos, Vector2 zoom, int whichFont = 0, int isMenu = 0, float Fade = 1.0f) => CalcBasicTextArea(buffer, (int)pos.X, (int)pos.Y, zoom.X, zoom.Y);

public Rectangle CalcBasicTextArea(byte[] buffer, Point pos, Vector2 zoom, int whichFont = 0, int isMenu = 0, float Fade = 1.0f) => CalcBasicTextArea(buffer, pos.X, pos.Y, zoom.X, zoom.Y);

public Rectangle CalcBasicTextArea(byte[] buffer, int x, int y, float zoomWidth = 1f, float zoomHeight = 1f, int whichFont = 0)
internal void getWidths(byte[] Tdw,uint offset, uint length)
{
Rectangle ret = new Rectangle(x, y, 0, 0);
Point real = new Point(x, y);
int charCountWidth = whichFont == 0 ? 21 : 10;
int charSize = whichFont == 0 ? 12 : 24;
Vector2 zoom = new Vector2(zoomWidth, zoomHeight);
Point size = (new Vector2(charSize, charSize) * zoom * Memory.Scale()).ToPoint();
foreach (byte c in buffer)
using (MemoryStream os = new MemoryStream((int)length * 2))
using (BinaryWriter bw = new BinaryWriter(os))
using (MemoryStream ms = new MemoryStream(Tdw))
using (BinaryReader br = new BinaryReader(ms))
{
if (c == 0x02) //02 is encoded \n
//bw.Write((byte)10);//width of space
ms.Seek(offset, SeekOrigin.Begin);
while (ms.Position < offset + length)
{
real.X = x;
real.Y += size.Y;
continue;
byte b = br.ReadByte();
byte low = (byte)(b & 0x0F);
byte high = (byte)(b >> 4);
bw.Write(low);
bw.Write(high);
}
int verticalPosition = (byte)(c - 32) / charCountWidth;
//i.e. 1280 is 100%, 640 is 50% and therefore 2560 is 200% which means multiply by 0.5f or 2.0f
real.X += size.X;
int curWidth = real.X - x;
if (curWidth > ret.Width)
ret.Width = curWidth;
charWidths = os.ToArray();
}
ret.Height = size.Y + (real.Y - y);
return ret;

}
private byte[] charWidths;
public Rectangle CalcBasicTextArea(byte[] buffer, Vector2 pos, Vector2 zoom, int whichFont = 0, int isMenu = 0) => CalcBasicTextArea(buffer, (int)pos.X, (int)pos.Y, zoom.X, zoom.Y);

public Rectangle CalcBasicTextArea(byte[] buffer, Point pos, Vector2 zoom, int whichFont = 0, int isMenu = 0) => CalcBasicTextArea(buffer, pos.X, pos.Y, zoom.X, zoom.Y);

public Rectangle CalcBasicTextArea(byte[] buffer, int x, int y, float zoomWidth = 1f, float zoomHeight = 1f, int whichFont = 0, int isMenu = 0) => RenderBasicText(buffer, x, y, zoomWidth, zoomHeight, whichFont, isMenu, 1, true);

public Rectangle RenderBasicText(byte[] buffer, Vector2 pos, Vector2 zoom, int whichFont = 0, int isMenu = 0, float Fade = 1.0f) => RenderBasicText(buffer, (int)pos.X, (int)pos.Y, zoom.X, zoom.Y, whichFont, isMenu, Fade);

public Rectangle RenderBasicText(byte[] buffer, Point pos, Vector2 zoom, int whichFont = 0, int isMenu = 0, float Fade = 1.0f) => RenderBasicText(buffer, pos.X, pos.Y, zoom.X, zoom.Y, whichFont, isMenu, Fade);

public Rectangle RenderBasicText(byte[] buffer, int x, int y, float zoomWidth = 1f, float zoomHeight = 1f, int whichFont = 0, int isMenu = 0, float Fade = 1.0f)
public Rectangle RenderBasicText(byte[] buffer, int x, int y, float zoomWidth = 2.0f, float zoomHeight = 2.7f, int whichFont = 0, int isMenu = 0, float Fade = 1.0f, bool skipdraw =false)
{
Rectangle ret = new Rectangle(x, y, 0, 0);
Point real = new Point(x, y);
int charCountWidth = 21;
int charSize = 12; //pixelhandler does the 2x scaling on the fly.
Vector2 zoom = new Vector2(zoomWidth, zoomHeight);
Point size = (new Vector2(charSize, charSize) * zoom * Memory.Scale()).ToPoint();
Vector2 scale = Memory.Scale();
Point size = (new Vector2(0, charSize) * zoom * scale).ToPoint();
int width;
foreach (byte c in buffer)
{
byte deltaChar = (byte)(c - 32);
if (deltaChar < charWidths.Length)
{
width = charWidths[deltaChar];
size.X = (int)(charWidths[deltaChar] * zoom.X * scale.X);
}
else
{
width = charSize;
size.X = (int)(charSize * zoom.X * scale.X);
}
Point curSize = size;
int verticalPosition = deltaChar / charCountWidth;
//i.e. 1280 is 100%, 640 is 50% and therefore 2560 is 200% which means multiply by 0.5f or 2.0f
if (c == 0x02)// \n
Expand All @@ -683,24 +695,34 @@ public Rectangle RenderBasicText(byte[] buffer, int x, int y, float zoomWidth =
Rectangle destRect = new Rectangle(real, size);
// if you use Memory.SpriteBatchStartAlpha(SamplerState.PointClamp); you won't need
// to trim last pixel. but it doesn't look good on low res fonts.
Rectangle sourceRect = new Rectangle((deltaChar - (verticalPosition * charCountWidth)) * charSize,
verticalPosition * charSize,
charSize,
charSize);

if (whichFont == 0 || isMenu == 1)
if (!skipdraw)
{
//trim pixels to remove texture filtering artifacts.
sourceRect.Width -= 1;
sourceRect.Height -= 1;
Memory.spriteBatch.Draw(isMenu == 1 ? menuFont : sysfnt,
destRect,
sourceRect,
Color.White * Fade);
}
else
sysfntbig.Draw(destRect, sourceRect, Color.White * Fade);
Rectangle sourceRect = new Rectangle((deltaChar - (verticalPosition * charCountWidth)) * charSize,
verticalPosition * charSize,
width,
charSize);

if (whichFont == 0 || isMenu == 1)
{
//trim pixels to remove texture filtering artifacts.
sourceRect.Width -= 1;
sourceRect.Height -= 1;
Memory.spriteBatch.Draw(isMenu == 1 ? menuFont : sysfnt,
destRect,
sourceRect,
Color.White * Fade);
}
else
{
if (!sysfntbig.Modded)
{
Rectangle ShadowdestRect = new Rectangle(destRect.Location, destRect.Size);
ShadowdestRect.Offset(1 * zoomWidth, 1 * zoomHeight);
sysfntbig.Draw(ShadowdestRect, sourceRect, Color.Black * Fade * .5f);
}
sysfntbig.Draw(destRect, sourceRect, Color.White * Fade);
}
}
real.X += size.X;
int curWidth = real.X - x;
if (curWidth > ret.Width)
Expand Down
2 changes: 2 additions & 0 deletions FF8/Menu/Icons.InsertCustomEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected override void InsertCustomEntries()
Width = 256,
Height = 16,
CustomPallet = 1,
Fill = Vector2.UnitX,
Tile = Vector2.UnitY,
};
Entry Border_TopLeft = new Entry
Expand Down Expand Up @@ -129,6 +130,7 @@ protected override void InsertCustomEntries()
Width = 112,
Height = 16,
CustomPallet = 1,
Fill = Vector2.UnitX,
Tile = Vector2.UnitY
}, Border_Top, Border_Left, Border_Right, Border_Bottom, Border_TopLeft, Border_TopRight, Border_BottomLeft, Border_BottomRight);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static void DrawDebugLobby()
float item = 0;
Rectangle dst = FontBoxCalc<Ditems>(strDebugLobby);
Memory.SpriteBatchStartAlpha(SamplerState.PointClamp);
Memory.Icons.Draw(Icons.ID.Menu_BG_256, 0, dst, 0, Fade);
Memory.Icons.Draw(Icons.ID.Menu_BG_256, 0, dst, 2, Fade);
item = 0;
dst.Offset(4 * 3.5f, 0);
dst.Size = (Memory.Icons[Icons.ID.DEBUG].GetRectangle.Size.ToVector2() * scale * 3.5f).ToPoint();
Expand All @@ -149,17 +149,17 @@ private static void DrawDebugLobby()
dst.Offset(-(dst.Width + 10 * scale.X), 6 * scale.Y + vpSpace * ((float)Dchoose));

Memory.Icons.Draw(Icons.ID.Finger_Right, 2, dst, 0, fade);
Memory.SpriteBatchEnd();
//Memory.SpriteBatchEnd();
//pointclamp looks bad on default fonts.
Memory.SpriteBatchStartAlpha();
//Memory.SpriteBatchStartAlpha();
foreach (Ditems i in (Ditems[])Enum.GetValues(typeof(Ditems)))
{
byte[] end = Font.CipherDirty(InfoForLobby<Ditems>(i));
byte[] combine = new byte[strDebugLobby[i].Text.Length + end.Length];
Array.Copy(strDebugLobby[i].Text, combine, strDebugLobby[i].Text.Length);
Array.Copy(end, 0, combine, strDebugLobby[i].Text.Length, end.Length);
Memory.font.RenderBasicText(combine,
(int)(DFontPos.X), (int)(DFontPos.Y + vpSpace * item++), 1f, 2f, 0, 1, Fade);
(int)(DFontPos.X), (int)(DFontPos.Y + vpSpace * item++), 2.545454545f, 3.0375f, 1, 0, Fade);
}
//Memory.spriteBatch.Draw(Memory.iconsTex[2], dst,
// new Rectangle(232, 0, 23, 15), Color.White * Fade);
Expand Down

0 comments on commit d48d023

Please sign in to comment.