Some more fixes

Only save bflan files if they have been edited
Start to merge some classes with brlyt so that can be properly supported soon
This commit is contained in:
KillzXGaming 2019-10-16 18:17:16 -04:00
parent ea29db89f5
commit 2478527a1c
5 changed files with 300 additions and 67 deletions

View file

@ -187,6 +187,10 @@ namespace LayoutBXLYT.Cafe
if (Utils.GetExtension(file.FileName) == ".bflan")
{
BFLAN bflan = (BFLAN)file.OpenFile();
//Disable saving unless the file gets edited
//Prevents broken files if version is unsupported
bflan.CanSave = false;
animations.Add(bflan);
}
}
@ -430,6 +434,14 @@ namespace LayoutBXLYT.Cafe
return panes;
}
public override BxlytMaterial GetMaterial(ushort index) {
return MaterialList.Materials[index];
}
public override BxlytMaterial CreateNewMaterial(string name) {
return new Material(name, this);
}
public override List<BxlytMaterial> GetMaterials()
{
List<BxlytMaterial> materials = new List<BxlytMaterial>();
@ -1165,41 +1177,41 @@ namespace LayoutBXLYT.Cafe
{
case 1:
if (WindowFrames.Count == 0)
WindowFrames.Add(new WindowFrame(header,$"{Name}_LT"));
WindowFrames.Add(new BxlytWindowFrame(header,$"{Name}_LT"));
break;
case 2:
if (WindowFrames.Count == 0)
WindowFrames.Add(new WindowFrame(header, $"{Name}_L"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_L"));
if (WindowFrames.Count == 1)
WindowFrames.Add(new WindowFrame(header, $"{Name}_R"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_R"));
break;
case 4:
if (WindowFrames.Count == 0)
WindowFrames.Add(new WindowFrame(header, $"{Name}_LT"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LT"));
if (WindowFrames.Count == 1)
WindowFrames.Add(new WindowFrame(header, $"{Name}_RT"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RT"));
if (WindowFrames.Count == 2)
WindowFrames.Add(new WindowFrame(header, $"{Name}_LB"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LB"));
if (WindowFrames.Count == 3)
WindowFrames.Add(new WindowFrame(header, $"{Name}_RB"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RB"));
break;
case 8:
if (WindowFrames.Count == 0)
WindowFrames.Add(new WindowFrame(header, $"{Name}_LT"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LT"));
if (WindowFrames.Count == 1)
WindowFrames.Add(new WindowFrame(header, $"{Name}_RT"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RT"));
if (WindowFrames.Count == 2)
WindowFrames.Add(new WindowFrame(header, $"{Name}_LB"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LB"));
if (WindowFrames.Count == 3)
WindowFrames.Add(new WindowFrame(header, $"{Name}_RB"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RB"));
if (WindowFrames.Count == 4)
WindowFrames.Add(new WindowFrame(header, $"{Name}_T"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_T"));
if (WindowFrames.Count == 5)
WindowFrames.Add(new WindowFrame(header, $"{Name}_B"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_B"));
if (WindowFrames.Count == 6)
WindowFrames.Add(new WindowFrame(header, $"{Name}_R"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_R"));
if (WindowFrames.Count == 7)
WindowFrames.Add(new WindowFrame(header, $"{Name}_L"));
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_L"));
break;
}
@ -1350,7 +1362,7 @@ namespace LayoutBXLYT.Cafe
foreach (int offset in offsets)
{
reader.SeekBegin(pos + offset);
WindowFrames.Add(new WindowFrame(reader, header));
WindowFrames.Add(new BxlytWindowFrame(reader, header));
}
}
@ -1387,7 +1399,7 @@ namespace LayoutBXLYT.Cafe
for (int i = 0; i < FrameCount; i++)
{
writer.WriteUint32Offset(_ofsFramePos + (i * 4), pos);
((WindowFrame)WindowFrames[i]).Write(writer);
WindowFrames[i].Write(writer);
}
}
}
@ -1452,34 +1464,6 @@ namespace LayoutBXLYT.Cafe
}
}
}
public class WindowFrame : BxlytWindowFrame
{
public WindowFrame(Header header, string materialName)
{
TextureFlip = WindowFrameTexFlip.None;
var mat = new Material(materialName, header);
MaterialIndex = (ushort)header.AddMaterial(mat);
Material = mat;
}
public WindowFrame(FileReader reader, Header header)
{
MaterialIndex = reader.ReadUInt16();
TextureFlip = (WindowFrameTexFlip)reader.ReadByte();
reader.ReadByte(); //padding
Material = header.MaterialList.Materials[MaterialIndex];
}
public void Write(FileWriter writer)
{
writer.Write(MaterialIndex);
writer.Write(TextureFlip, false);
writer.Write((byte)0);
}
}
}
public class ALI1 : PAN1
@ -2228,6 +2212,32 @@ namespace LayoutBXLYT.Cafe
Name = name;
}
public override BasePane Copy()
{
PAN1 pan1 = new PAN1();
pan1.Alpha = Alpha;
pan1.DisplayInEditor = DisplayInEditor;
pan1.Childern = Childern;
pan1.Parent = Parent;
pan1.Name = Name;
pan1.LayoutFile = LayoutFile;
pan1.NodeWrapper = NodeWrapper;
pan1.originX = originX;
pan1.originY = originY;
pan1.ParentOriginX = ParentOriginX;
pan1.ParentOriginY = ParentOriginY;
pan1.Rotate = Rotate;
pan1.Scale = Scale;
pan1.Translate = Translate;
pan1.Visible = Visible;
pan1.Height = Height;
pan1.Width = Width;
pan1.UserData = UserData;
pan1.UserDataInfo = UserDataInfo;
pan1._flags1 = _flags1;
return pan1;
}
public override UserData CreateUserData()
{
return new USD1();
@ -2402,9 +2412,6 @@ namespace LayoutBXLYT.Cafe
[DisplayName("Texture Coordinate Params"), CategoryAttribute("Texture")]
public TexCoordGen[] TexCoords { get; set; }
[DisplayName("Tev Stages"), CategoryAttribute("Tev")]
public TevStage[] TevStages { get; set; }
[DisplayName("Indirect Parameter"), CategoryAttribute("Texture")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public IndirectParameter IndParameter { get; set; }
@ -2560,7 +2567,7 @@ namespace LayoutBXLYT.Cafe
for (int i = 0; i < TevStages.Length; i++)
{
flags += Bit.BitInsert(1, 1, 2, 24);
TevStages[i].Write(writer);
((TevStage)TevStages[i]).Write(writer);
}
if (AlphaCompare != null && EnableAlphaCompare)

View file

@ -2,11 +2,8 @@
namespace LayoutBXLYT.Cafe
{
public class TevStage
public class TevStage : BxlytTevStage
{
public TevMode ColorMode { get; set; }
public TevMode AlphaMode { get; set; }
private byte colorFlags;
private byte alphaFlags;

View file

@ -139,6 +139,11 @@ namespace LayoutBXLYT
ParentOriginY = OriginY.Center;
}
public virtual BasePane Copy()
{
return new BasePane();
}
public virtual UserData CreateUserData()
{
return new UserData();
@ -956,6 +961,7 @@ namespace LayoutBXLYT
}
public enum TevScale
{
Scale1,
@ -1121,6 +1127,31 @@ namespace LayoutBXLYT
public ushort MaterialIndex;
public WindowFrameTexFlip TextureFlip { get; set; }
public BxlytWindowFrame(BxlytHeader header, string materialName)
{
TextureFlip = WindowFrameTexFlip.None;
var mat = header.CreateNewMaterial(materialName);
MaterialIndex = (ushort)header.AddMaterial(mat);
Material = mat;
}
public BxlytWindowFrame(FileReader reader, BxlytHeader header)
{
MaterialIndex = reader.ReadUInt16();
TextureFlip = (WindowFrameTexFlip)reader.ReadByte();
reader.ReadByte(); //padding
Material = header.GetMaterial(MaterialIndex);
}
public void Write(FileWriter writer)
{
writer.Write(MaterialIndex);
writer.Write(TextureFlip, false);
writer.Write((byte)0);
}
}
public class TexCoord
@ -1589,6 +1620,16 @@ namespace LayoutBXLYT
public virtual void TryRemoveMaterial(BxlytMaterial material) { }
public virtual void TryRemoveMaterial(List<BxlytMaterial> materials) { }
public virtual BxlytMaterial CreateNewMaterial(string name)
{
return new BxlytMaterial();
}
public virtual BxlytMaterial GetMaterial(ushort index)
{
return new BxlytMaterial();
}
public BxlytMaterial SearchMaterial(string name)
{
var materials = GetMaterials();
@ -1792,6 +1833,15 @@ namespace LayoutBXLYT
[DisplayName("Texture Maps"), CategoryAttribute("Texture")]
public BxlytTextureRef[] TextureMaps { get; set; }
[DisplayName("Tev Stages"), CategoryAttribute("Tev")]
public BxlytTevStage[] TevStages { get; set; }
}
public class BxlytTevStage
{
public TevMode ColorMode { get; set; }
public TevMode AlphaMode { get; set; }
}
public class MaterialAnimController

View file

@ -198,6 +198,11 @@ namespace LayoutBXLYT
return materials;
}
public override BxlytMaterial CreateNewMaterial(string name)
{
return new Material(name, this);
}
public List<GRP1> GetGroupPanes()
{
List<GRP1> panes = new List<GRP1>();
@ -475,18 +480,12 @@ namespace LayoutBXLYT
LineAlignment = (LineAlign)reader.ReadByte();
_flags = reader.ReadByte();
reader.Seek(1); //padding
ItalicTilt = reader.ReadSingle();
uint textOffset = reader.ReadUInt32();
FontForeColor = STColor8.FromBytes(reader.ReadBytes(4));
FontBackColor = STColor8.FromBytes(reader.ReadBytes(4));
FontSize = reader.ReadVec2SY();
CharacterSpace = reader.ReadSingle();
LineSpace = reader.ReadSingle();
ShadowXY = reader.ReadVec2SY();
ShadowXYSize = reader.ReadVec2SY();
ShadowForeColor = STColor8.FromBytes(reader.ReadBytes(4));
ShadowBackColor = STColor8.FromBytes(reader.ReadBytes(4));
ShadowItalic = reader.ReadSingle();
if (RestrictedTextLengthEnabled)
Text = reader.ReadString(MaxTextLength);
@ -507,7 +506,6 @@ namespace LayoutBXLYT
writer.Write(LineAlignment, false);
writer.Write(_flags);
writer.Seek(1);
writer.Write(ItalicTilt);
long _ofsTextPos = writer.Position;
writer.Write(0); //text offset
writer.Write(FontForeColor.ToBytes());
@ -515,11 +513,6 @@ namespace LayoutBXLYT
writer.Write(FontSize);
writer.Write(CharacterSpace);
writer.Write(LineSpace);
writer.Write(ShadowXY);
writer.Write(ShadowXYSize);
writer.Write(ShadowForeColor.ToBytes());
writer.Write(ShadowBackColor.ToBytes());
writer.Write(ShadowItalic);
writer.WriteUint32Offset(_ofsTextPos, pos);
if (RestrictedTextLengthEnabled)
@ -544,13 +537,164 @@ namespace LayoutBXLYT
};
}
public class WND1 : PAN1
public class WND1 : PAN1, IWindowPane
{
public Header layoutHeader;
public bool UseOneMaterialForAll
{
get { return Convert.ToBoolean(_flag & 1); }
set { }
}
public bool UseVertexColorForAll
{
get { return Convert.ToBoolean((_flag >> 1) & 1); }
set { }
}
public WindowKind WindowKind { get; set; }
public bool NotDrawnContent
{
get { return (_flag & 8) == 16; }
set { }
}
public ushort StretchLeft { get; set; }
public ushort StretchRight { get; set; }
public ushort StretchTop { get; set; }
public ushort StretchBottm { get; set; }
public ushort FrameElementLeft { get; set; }
public ushort FrameElementRight { get; set; }
public ushort FrameElementTop { get; set; }
public ushort FrameElementBottm { get; set; }
private byte _flag;
private byte frameCount;
public byte FrameCount
{
get { return frameCount; }
set
{
frameCount = value;
}
}
public System.Drawing.Color[] GetVertexColors()
{
return new System.Drawing.Color[4]
{
Content.ColorTopLeft.Color,
Content.ColorTopRight.Color,
Content.ColorBottomLeft.Color,
Content.ColorBottomRight.Color,
};
}
public void ReloadFrames()
{
SetFrames(layoutHeader);
}
public void SetFrames(Header header)
{
if (WindowFrames == null)
WindowFrames = new List<BxlytWindowFrame>();
switch (FrameCount)
{
case 1:
if (WindowFrames.Count == 0)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LT"));
break;
case 2:
if (WindowFrames.Count == 0)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_L"));
if (WindowFrames.Count == 1)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_R"));
break;
case 4:
if (WindowFrames.Count == 0)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LT"));
if (WindowFrames.Count == 1)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RT"));
if (WindowFrames.Count == 2)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LB"));
if (WindowFrames.Count == 3)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RB"));
break;
case 8:
if (WindowFrames.Count == 0)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LT"));
if (WindowFrames.Count == 1)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RT"));
if (WindowFrames.Count == 2)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_LB"));
if (WindowFrames.Count == 3)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_RB"));
if (WindowFrames.Count == 4)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_T"));
if (WindowFrames.Count == 5)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_B"));
if (WindowFrames.Count == 6)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_R"));
if (WindowFrames.Count == 7)
WindowFrames.Add(new BxlytWindowFrame(header, $"{Name}_L"));
break;
}
//Now search for invalid unused materials and remove them
for (int i = 0; i < WindowFrames.Count; i++)
{
if (i >= FrameCount)
header.TryRemoveMaterial(WindowFrames[i].Material);
else if (!header.MaterialList.Materials.Contains((Material)WindowFrames[i].Material))
header.AddMaterial(WindowFrames[i].Material);
}
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowContent Content { get; set; }
[Browsable(false)]
public List<BxlytWindowFrame> WindowFrames { get; set; }
public WND1() : base()
{
}
public WND1(Header header, string name)
{
layoutHeader = header;
LoadDefaults();
Name = name;
Content = new WindowContent(header, this.Name);
UseOneMaterialForAll = true;
UseVertexColorForAll = true;
WindowKind = WindowKind.Around;
NotDrawnContent = false;
StretchLeft = 0;
StretchRight = 0;
StretchTop = 0;
StretchBottm = 0;
Width = 70;
Height = 80;
FrameElementLeft = 16;
FrameElementRight = 16;
FrameElementTop = 16;
FrameElementBottm = 16;
FrameCount = 1;
WindowFrames = new List<BxlytWindowFrame>();
SetFrames(header);
}
public WND1(FileReader reader) : base(reader)
{
@ -562,6 +706,14 @@ namespace LayoutBXLYT
}
}
public class WindowContent : BxlytWindowContent
{
public WindowContent(Header header, string name)
{
}
}
public class BND1 : PAN1, IBoundryPane
{
public BND1() : base()
@ -758,6 +910,26 @@ namespace LayoutBXLYT
}
public void LoadDefaults()
{
Alpha = 255;
PaneMagFlags = 0;
Name = "";
Translate = new Vector3F(0, 0, 0);
Rotate = new Vector3F(0, 0, 0);
Scale = new Vector2F(1, 1);
Width = 30;
Height = 40;
UserDataInfo = "";
originX = OriginX.Center;
originY = OriginY.Center;
ParentOriginX = OriginX.Center;
ParentOriginY = OriginY.Center;
InfluenceAlpha = false;
Visible = true;
}
enum OriginType : byte
{
Left = 0,
@ -909,7 +1081,7 @@ namespace LayoutBXLYT
return "";
}
public Material()
public Material(string name, Header header)
{
TextureMaps = new TextureRef[0];
TextureTransforms = new List<TextureTransform>();

View file

@ -13,6 +13,7 @@ namespace LayoutBXLYT
{
public partial class LayoutAnimEditorBasic : LayoutDocked
{
private BxlanHeader ActiveAnim;
public EventHandler OnPropertyChanged;
public LayoutAnimEditorBasic()
@ -31,6 +32,8 @@ namespace LayoutBXLYT
public void LoadAnimations(BxlanHeader bxlan, TreeNode root, bool LoadRoot = true)
{
ActiveAnim = bxlan;
if (LoadRoot)
treeView1.Nodes.Add(root);
@ -84,6 +87,10 @@ namespace LayoutBXLYT
private void PropertyChanged()
{
OnPropertyChanged?.Invoke(null, new EventArgs());
//Enable saving if file is edited
if (ActiveAnim != null)
ActiveAnim.FileInfo.CanSave = true;
}
}
}