diff --git a/FModel/Creator/Bases/BaseOfferMaterial.cs b/FModel/Creator/Bases/BaseOfferMaterial.cs new file mode 100644 index 00000000..4fc29567 --- /dev/null +++ b/FModel/Creator/Bases/BaseOfferMaterial.cs @@ -0,0 +1,116 @@ +using PakReader.Parsers.Class; +using PakReader.Parsers.Objects; +using PakReader.Parsers.PropertyTagData; +using SkiaSharp; +using System; +using System.Windows; + +namespace FModel.Creator.Bases +{ + public class BaseOfferMaterial + { + public SKBitmap FallbackImage; + public SKBitmap IconImage; + public SKBitmap RarityBackgroundImage; + public SKColor[] RarityBackgroundColors; + public SKColor RarityBorderColor; + public int Size = 512; + public int Margin = 2; + + public BaseOfferMaterial() + { + FallbackImage = SKBitmap.Decode(Application.GetResourceStream(new Uri("pack://application:,,,/Resources/T_Placeholder_Item_Image.png")).Stream); + IconImage = FallbackImage; + RarityBackgroundImage = null; + RarityBackgroundColors = new SKColor[2] { SKColor.Parse("4F4F69"), SKColor.Parse("4F4F69") }; + RarityBorderColor = SKColor.Parse("9092AB"); + } + + public BaseOfferMaterial(IUExport export) : this() + { + if (export.GetExport("VectorParameterValues") is ArrayProperty vectorParameterValues) + { + foreach (StructProperty vectorParameter in vectorParameterValues.Value) + { + if (vectorParameter.Value is UObject parameter && + parameter.TryGetValue("ParameterValue", out var i) && i is StructProperty v && v.Value is FLinearColor value && + parameter.TryGetValue("ParameterInfo", out var i1) && i1 is StructProperty i2 && i2.Value is UObject info && + info.TryGetValue("Name", out var j1) && j1 is NameProperty name) + { + if (name.Value.String.Equals("Background_Color_A")) + { + RarityBackgroundColors[0] = SKColor.Parse(value.Hex); + RarityBorderColor = RarityBackgroundColors[0]; + } + else if (name.Value.String.Equals("Background_Color_B")) + { + RarityBackgroundColors[1] = SKColor.Parse(value.Hex); + } + } + } + } + + if (export.GetExport("TextureParameterValues") is ArrayProperty textureParameterValues) + { + foreach (StructProperty textureParameter in textureParameterValues.Value) + { + if (textureParameter.Value is UObject parameter && + parameter.TryGetValue("ParameterValue", out var i) && i is ObjectProperty value && + parameter.TryGetValue("ParameterInfo", out var i1) && i1 is StructProperty i2 && i2.Value is UObject info && + info.TryGetValue("Name", out var j1) && j1 is NameProperty name) + { + if (name.Value.String.Equals("OfferImage") || name.Value.String.Equals("Texture")) + { + IconImage = Utils.GetObjectTexture(value); + } + else if (name.Value.String.Equals("SeriesTexture")) + { + RarityBackgroundImage = Utils.GetObjectTexture(value); + } + } + } + } + } + + public void DrawBackground(SKCanvas c) + { + if (RarityBackgroundColors[0] == RarityBackgroundColors[1]) + RarityBackgroundColors[0] = RarityBorderColor; + + RarityBackgroundColors[0].ToHsl(out var _, out var _, out var l1); + RarityBackgroundColors[1].ToHsl(out var _, out var _, out var l2); + bool reverse = l1 > l2; + + // border + c.DrawRect(new SKRect(0, 0, Size, Size), + new SKPaint + { + IsAntialias = true, + FilterQuality = SKFilterQuality.High, + Color = RarityBorderColor + }); + + c.DrawRect(new SKRect(Margin, Margin, Size - Margin, Size - Margin), + new SKPaint + { + IsAntialias = true, + FilterQuality = SKFilterQuality.High, + Shader = SKShader.CreateRadialGradient( + new SKPoint(Size / 2, Size / 2), + Size / 5 * 4, + new SKColor[2] { reverse ? RarityBackgroundColors[0] : RarityBackgroundColors[1], reverse ? RarityBackgroundColors[1] : RarityBackgroundColors[0] }, + SKShaderTileMode.Clamp) + }); + } + + public void DrawImage(SKCanvas c) + { + if (RarityBackgroundImage != null) + c.DrawBitmap(RarityBackgroundImage, new SKRect(Margin, Margin, Size - Margin, Size - Margin), + new SKPaint { FilterQuality = SKFilterQuality.High, IsAntialias = true }); + + c.DrawBitmap(IconImage ?? FallbackImage, new SKRect(Margin, Margin, Size - Margin, Size - Margin), + new SKPaint { FilterQuality = SKFilterQuality.High, IsAntialias = true }); + } + } +} diff --git a/FModel/Creator/Creator.cs b/FModel/Creator/Creator.cs index 06ae330f..8a3c7e97 100644 --- a/FModel/Creator/Creator.cs +++ b/FModel/Creator/Creator.cs @@ -151,6 +151,27 @@ namespace FModel.Creator } return true; } + case "MaterialInstanceConstant": + { + if (assetFolder.Equals("MI_OfferImages")) + { + BaseOfferMaterial icon = new BaseOfferMaterial(exports[index]); + using (var ret = new SKBitmap(icon.Size, icon.Size, SKColorType.Rgba8888, SKAlphaType.Premul)) + using (var c = new SKCanvas(ret)) + { + if ((EIconDesign)Properties.Settings.Default.AssetsIconDesign != EIconDesign.NoBackground) + { + icon.DrawBackground(c); + } + icon.DrawImage(c); + + Watermark.DrawWatermark(c); // watermark should only be applied on icons with width = 512 + ImageBoxVm.imageBoxViewModel.Set(ret, assetName); + } + return true; + } + return false; + } case "FortItemSeriesDefinition": { BaseIcon icon = new BaseIcon(); diff --git a/FModel/Creator/Utils.cs b/FModel/Creator/Utils.cs index 73704a8c..c38e2cd6 100644 --- a/FModel/Creator/Utils.cs +++ b/FModel/Creator/Utils.cs @@ -58,9 +58,13 @@ namespace FModel.Creator public static SKBitmap GetSoftObjectTexture(SoftObjectProperty s) => GetTexture(s.Value.AssetPathName.String); public static SKBitmap GetTexture(string s) { - // FortniteGame/Content/Catalog/DisplayAssets/DA_BattlePassBundle_2020.uasset - if (s != null && s.Equals("/Game/UI/Foundation/Textures/BattleRoyale/FeaturedItems/Outfit/T_UI_InspectScreen_annualPass")) - s += "_1024"; + if (s != null) + { + if (s.Equals("/Game/UI/Foundation/Textures/BattleRoyale/FeaturedItems/Outfit/T_UI_InspectScreen_annualPass")) + s += "_1024"; + else if (s.Equals("/Game/UI/Foundation/Textures/BattleRoyale/BattlePass/T-BattlePass-Season14-Tile") || s.Equals("/Game/UI/Foundation/Textures/BattleRoyale/BattlePass/T-BattlePassWithLevels-Season14-Tile")) + s += "_1"; + } PakPackage p = GetPropertyPakPackage(s); if (p.HasExport() && !p.Equals(default))