Skip to content

Commit 46b37d3

Browse files
authored
Merge pull request WolvenKit#1868 from WolvenKit/feature/add-axl-files
feat: generate ArchiveXL files thanks to a wizard dialog
2 parents 793ba5f + d217341 commit 46b37d3

33 files changed

+3568
-215
lines changed

WolvenKit.App/Equipment_Enums.cs

Lines changed: 593 additions & 0 deletions
Large diffs are not rendered by default.

WolvenKit.App/Factories/DialogViewModelFactory.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ public class DialogViewModelFactory : IDialogViewModelFactory
1010
private readonly ILoggerService _loggerService;
1111
private readonly IProjectManager _projectManager;
1212
private readonly INotificationService _notificationService;
13+
private readonly ISettingsManager _settingsManager;
1314

1415
public DialogViewModelFactory(
1516
IProjectManager projectManager,
1617
ILoggerService loggerService,
17-
INotificationService notificationService
18+
INotificationService notificationService,
19+
ISettingsManager settingsManager
1820
)
1921
{
2022
_projectManager = projectManager;
2123
_loggerService = loggerService;
2224
_notificationService = notificationService;
23-
25+
_settingsManager = settingsManager;
2426
}
27+
2528
public SoundModdingViewModel SoundModdingViewModel() => new(_notificationService, _loggerService, _projectManager);
26-
public NewFileViewModel NewFileViewModel() => new(_projectManager, _loggerService);
29+
public NewFileViewModel NewFileViewModel() => new(_projectManager, _settingsManager, _loggerService);
2730
}

WolvenKit.App/Helpers/ArchiveXlHelper.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public static partial class ArchiveXlHelper
2525
private static ILoggerService? LoggerService => s_loggerService ??= Locator.Current.GetService<ILoggerService>();
2626

2727
private static IProjectManager? s_projectManager;
28-
29-
private static IProjectManager? ProjectManager =>
30-
s_projectManager ??= Locator.Current.GetService<IProjectManager>();
31-
28+
private static IProjectManager? ProjectManager => s_projectManager ??= Locator.Current.GetService<IProjectManager>();
3229

3330
private static readonly Dictionary<string, string[]> s_keysAndValues = new()
3431
{
@@ -90,7 +87,7 @@ private static IEnumerable<string> Substitute(string depotPath, Cp77Project? act
9087

9188
// For {body}: If we get meshes from active project, we'll use these instead of substituting.
9289
// The list will only hold "base_body" anyway.
93-
if (depotPath.Contains("{body}") && depotPath.Split("{body}") is string[] { Length: 2 } parts &&
90+
if (depotPath.Contains("{body}") && depotPath.Split("{body}") is { Length: 2 } parts &&
9491
activeProject is not null)
9592
{
9693
if (!s_keysAndValues.TryGetValue("{body}", out var bodyValues))
@@ -159,7 +156,7 @@ List<string> ExtractVariants()
159156
foreach (var path in activeProject.ModFiles)
160157
{
161158
if (!string.IsNullOrEmpty(pathStart) && path.StartsWith(pathStart) &&
162-
path.Replace(pathStart, "").Split(Path.DirectorySeparatorChar) is string[]
159+
path.Replace(pathStart, "").Split(Path.DirectorySeparatorChar) is
163160
{
164161
Length: > 1
165162
} variantParts)
@@ -181,7 +178,7 @@ List<string> ExtractVariants()
181178
public static string? GetFirstExistingPath(string? depotPath, Cp77Project? activeProject = null)
182179
{
183180
if (depotPath is null || ProjectManager?.ActiveProject?.ModDirectory is not string pathToArchiveFolder
184-
|| ProjectManager?.ActiveProject?.FileDirectory is not string pathToGameFiles)
181+
|| ProjectManager.ActiveProject?.FileDirectory is not string pathToGameFiles)
185182
{
186183
return null;
187184
}
@@ -414,4 +411,6 @@ public static string ReplaceInDynamicPath(string dynamicPathStr, string newPathS
414411

415412
[GeneratedRegex(@"(\{[^}]+\})")]
416413
private static partial Regex PlaceholderSplitPattern();
414+
415+
417416
}

WolvenKit.App/Helpers/Cr2WTools.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Red4ParserService parserService
3030
_parserService = parserService;
3131
}
3232

33-
3433
#region cr2w
3534

3635
public bool WriteCr2W(CR2WFile cr2WFile, string? absolutePath)
@@ -96,6 +95,20 @@ public CR2WFile ReadCr2W(string absolutePath)
9695
return cr2WFile;
9796
}
9897

98+
public CR2WFile? ReadCr2WNoException(string absolutePath)
99+
{
100+
try
101+
{
102+
return ReadCr2W(absolutePath);
103+
}
104+
catch
105+
{
106+
// do nothing
107+
}
108+
109+
return null;
110+
}
111+
99112
#endregion
100113

101114
private void SaveHashedValues(CR2WFile file)
@@ -122,4 +135,4 @@ private void SaveHashedValues(CR2WFile file)
122135
}
123136
}
124137
}
125-
}
138+
}

WolvenKit.App/Helpers/InkatlasImageGenerator.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Drawing;
4+
using System.Drawing.Imaging;
45
using System.IO;
56
using System.Linq;
67
using WolvenKit.App.Models.ProjectManagement.Project;
@@ -36,6 +37,53 @@ public static void GenerateAtlas(
3637
}
3738

3839

40+
public static void GenerateDummyIcons(string folderPath, string prefix, string[] variants)
41+
{
42+
Directory.CreateDirectory(folderPath);
43+
try
44+
{
45+
foreach (var file in Directory.GetFiles(folderPath))
46+
{
47+
File.Delete(file);
48+
}
49+
}
50+
catch
51+
{
52+
// don't delete, we'll have extra items
53+
}
54+
55+
foreach (var variant in variants)
56+
{
57+
var fileName = Path.Combine(folderPath, $"{prefix}{variant}.png");
58+
59+
60+
using var bmp = new Bitmap(160, 160);
61+
using var g = Graphics.FromImage(bmp);
62+
63+
// Use a simpler font constructor and ensure high quality rendering
64+
using var font = new Font("Arial", 14, FontStyle.Bold); // Simplified font creation
65+
using var brush = new SolidBrush(Color.Black); // Use SolidBrush instead of Brushes.Black
66+
using var stringFormat = new StringFormat()
67+
{
68+
Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
69+
};
70+
71+
// Clear background white
72+
g.Clear(Color.White);
73+
74+
75+
// Set high quality rendering
76+
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
77+
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
78+
79+
// Draw the text centered using StringFormat
80+
g.DrawString(variant, font, brush, new RectangleF(0, 0, bmp.Width, bmp.Height), stringFormat);
81+
82+
// Save as PNG
83+
bmp.Save(fileName, ImageFormat.Png);
84+
}
85+
}
86+
3987
private static List<AtlasPart> CreateAtlasImages(string pngFolder, string relativeSourcePath, string atlasFileName,
4088
Cp77Project activeProject, int tileWidth, int tileHeight)
4189
{
@@ -356,4 +404,4 @@ private class AtlasPart
356404
public Rectangle PixelRect { get; init; }
357405
public RectangleF UvRect { get; init; }
358406
}
359-
}
407+
}

0 commit comments

Comments
 (0)