Skip to content

Commit

Permalink
juno building preview
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed May 24, 2024
1 parent eb49b3c commit 9781446
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 54 deletions.
1 change: 1 addition & 0 deletions FModel/Creator/CreatorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public bool TryConstructCreator(out UCreator creator)
case "FortConversionControlItemDefinition":
case "FortAccountBuffCreditItemDefinition":
case "JunoBuildInstructionsItemDefinition":
case "JunoBuildingSetAccountItemDefinition":
case "FortEventCurrencyItemDefinitionRedir":
case "FortPersistentResourceItemDefinition":
case "FortWeaponMeleeOffhandItemDefinition":
Expand Down
21 changes: 20 additions & 1 deletion FModel/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using ICSharpCode.AvalonEdit.Document;

namespace FModel.Extensions;

Expand Down Expand Up @@ -94,7 +95,7 @@ public static string SubstringAfterLast(this string s, string delimiter, StringC
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetLineNumber(this string s, string lineToFind)
public static int GetNameLineNumber(this string s, string lineToFind)
{
if (int.TryParse(lineToFind, out var index))
return s.GetLineNumber(index);
Expand All @@ -113,6 +114,24 @@ public static int GetLineNumber(this string s, string lineToFind)
return 1;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetParentExportType(this TextDocument doc, int startOffset)
{
var line = doc.GetLineByOffset(startOffset);
var lineNumber = line.LineNumber - 1;

while (doc.GetText(line.Offset, line.Length) is { } content)
{
if (content.StartsWith(" \"Type\": \"", StringComparison.OrdinalIgnoreCase))
return content.Split("\"")[3];

lineNumber--;
line = doc.GetLineByNumber(lineNumber);
}

return string.Empty;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetKismetLineNumber(this string s, string input)
{
Expand Down
2 changes: 1 addition & 1 deletion FModel/Resources/default.vert
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ void main()
fTangent = vec3(transpose(inverse(vInstanceMatrix)) * finalTangent);
fTexCoords = vTexCoords;
fTexLayer = vTexLayer;
fColor = unpackARGB(int(vColor));
fColor = unpackARGB(int(vColor)) / 255.0;
}
26 changes: 11 additions & 15 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,13 @@ public void Extract(CancellationToken cancellationToken, string fullPath, bool a
var fileName = fullPath.SubstringAfterLast('/');
var ext = fullPath.SubstringAfterLast('.').ToLower();

if (addNewTab && TabControl.CanAddTabs)
{
TabControl.AddTab(fileName, directory);
}
else
{
TabControl.SelectedTab.Header = fileName;
TabControl.SelectedTab.Directory = directory;
}
if (addNewTab && TabControl.CanAddTabs) TabControl.AddTab(fileName, directory);
else TabControl.SelectedTab.SoftReset(fileName, directory);
TabControl.SelectedTab.Highlighter = AvalonExtensions.HighlighterSelector(ext);

var updateUi = !HasFlag(bulk, EBulkType.Auto);
var saveProperties = HasFlag(bulk, EBulkType.Properties);
var saveTextures = HasFlag(bulk, EBulkType.Textures);
TabControl.SelectedTab.ClearImages();
TabControl.SelectedTab.ResetDocumentText();
TabControl.SelectedTab.ScrollTrigger = null;
TabControl.SelectedTab.Highlighter = AvalonExtensions.HighlighterSelector(ext);
switch (ext)
{
case "uasset":
Expand Down Expand Up @@ -801,10 +791,10 @@ public void Extract(CancellationToken cancellationToken, string fullPath, bool a
}
}

public void ExtractAndScroll(CancellationToken cancellationToken, string fullPath, string objectName)
public void ExtractAndScroll(CancellationToken cancellationToken, string fullPath, string objectName, string parentExportType)
{
Log.Information("User CTRL-CLICKED to extract '{FullPath}'", fullPath);
TabControl.AddTab(fullPath.SubstringAfterLast('/'), fullPath.SubstringBeforeLast('/'));
TabControl.AddTab(fullPath.SubstringAfterLast('/'), fullPath.SubstringBeforeLast('/'), parentExportType);
TabControl.SelectedTab.ScrollTrigger = objectName;

var exports = Provider.LoadAllObjects(fullPath);
Expand Down Expand Up @@ -855,6 +845,12 @@ public void ExtractAndScroll(CancellationToken cancellationToken, string fullPat
return false;
}
case UWorld when isNone && UserSettings.Default.PreviewWorlds:
case UBlueprintGeneratedClass when isNone && UserSettings.Default.PreviewWorlds && TabControl.SelectedTab.ParentExportType switch
{
"JunoBuildInstructionsItemDefinition" => true,
"JunoBuildingSetAccountItemDefinition" => true,
_ => false
}:
case UAtomModel when isNone && UserSettings.Default.PreviewStaticMeshes:
case UStaticMesh when isNone && UserSettings.Default.PreviewStaticMeshes:
case USkeletalMesh when isNone && UserSettings.Default.PreviewSkeletalMeshes:
Expand Down
30 changes: 16 additions & 14 deletions FModel/ViewModels/TabControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ private void SetImage(SKBitmap bitmap)

public class TabItem : ViewModel
{
public string ParentExportType { get; private set; }

private string _header;
public string Header
{
Expand Down Expand Up @@ -211,20 +213,28 @@ public TabImage SelectedImage
private GoToCommand _goToCommand;
public GoToCommand GoToCommand => _goToCommand ??= new GoToCommand(null);

public TabItem(string header, string directory)
public TabItem(string header, string directory, string parentExportType)
{
Header = header;
Directory = directory;
ParentExportType = parentExportType;
_images = new ObservableCollection<TabImage>();
}

public void ClearImages()
public void SoftReset(string header, string directory)
{
Header = header;
Directory = directory;
ParentExportType = string.Empty;
ScrollTrigger = null;
Application.Current.Dispatcher.Invoke(() =>
{
_images.Clear();
SelectedImage = null;
RaisePropertyChanged("HasMultipleImages");
Document ??= new TextDocument();
Document.Text = string.Empty;
});
}

Expand Down Expand Up @@ -274,15 +284,6 @@ public void SetDocumentText(string text, bool save, bool updateUi)
});
}

public void ResetDocumentText()
{
Application.Current.Dispatcher.Invoke(() =>
{
Document ??= new TextDocument();
Document.Text = string.Empty;
});
}

public void SaveImage() => SaveImage(SelectedImage, true);
private void SaveImage(TabImage image, bool updateUi)
{
Expand Down Expand Up @@ -368,12 +369,13 @@ public TabControlViewModel()
SelectedTab = TabsItems.FirstOrDefault();
}

public void AddTab(string header = null, string directory = null)
public void AddTab(string header = null, string directory = null, string parentExportType = null)
{
if (!CanAddTabs) return;

var h = header ?? "New Tab";
var d = directory ?? string.Empty;
var p = parentExportType ?? string.Empty;
if (SelectedTab is { Header : "New Tab" })
{
SelectedTab.Header = h;
Expand All @@ -383,7 +385,7 @@ public void AddTab(string header = null, string directory = null)

Application.Current.Dispatcher.Invoke(() =>
{
_tabItems.Add(new TabItem(h, d));
_tabItems.Add(new TabItem(h, d, p));
SelectedTab = _tabItems.Last();
});
}
Expand Down Expand Up @@ -445,6 +447,6 @@ public void RemoveAllTabs()

private static IEnumerable<TabItem> EnumerateTabs()
{
yield return new TabItem("New Tab", string.Empty);
yield return new TabItem("New Tab", string.Empty, string.Empty);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using FModel.Extensions;
using ICSharpCode.AvalonEdit.Rendering;

namespace FModel.Views.Resources.Controls;
Expand Down Expand Up @@ -29,8 +30,10 @@ public override int GetFirstInterestedOffset(int startOffset)
public override VisualLineElement ConstructElement(int offset)
{
var m = FindMatch(offset);
if (!m.Success || m.Index != 0) return null;
if (!m.Success || m.Index != 0 ||
!m.Groups.TryGetValue("target", out var g)) return null;

return m.Groups.TryGetValue("target", out var g) ? new GamePathVisualLineText(g.Value, CurrentContext.VisualLine, g.Length + g.Index + 1) : null;
var parentExportType = CurrentContext.Document.GetParentExportType(offset);
return new GamePathVisualLineText(g.Value, parentExportType, CurrentContext.VisualLine, g.Length + g.Index + 1);
}
}
}
18 changes: 10 additions & 8 deletions FModel/Views/Resources/Controls/Aed/GamePathVisualLineText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ public class GamePathVisualLineText : VisualLineText
private ThreadWorkerViewModel _threadWorkerView => ApplicationService.ThreadWorkerView;
private ApplicationViewModel _applicationView => ApplicationService.ApplicationView;

public delegate void GamePathOnClick(string gamePath);
public delegate void GamePathOnClick(string gamePath, string parentExportType);

public event GamePathOnClick OnGamePathClicked;
private readonly string _gamePath;
private readonly string _parentExportType;

public GamePathVisualLineText(string gamePath, VisualLine parentVisualLine, int length) : base(parentVisualLine, length)
public GamePathVisualLineText(string gamePath, string parentExportType, VisualLine parentVisualLine, int length) : base(parentVisualLine, length)
{
_gamePath = gamePath;
_parentExportType = parentExportType;
}

public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
Expand Down Expand Up @@ -56,14 +58,14 @@ protected override void OnMouseDown(MouseButtonEventArgs e)
if (e.Handled || OnGamePathClicked == null)
return;

OnGamePathClicked(_gamePath);
OnGamePathClicked(_gamePath, _parentExportType);
e.Handled = true;
}

protected override VisualLineText CreateInstance(int length)
{
var a = new GamePathVisualLineText(_gamePath, ParentVisualLine, length);
a.OnGamePathClicked += async gamePath =>
var a = new GamePathVisualLineText(_gamePath, _parentExportType, ParentVisualLine, length);
a.OnGamePathClicked += async (gamePath, parentExportType) =>
{
var obj = gamePath.SubstringAfterLast('.');
var package = gamePath.SubstringBeforeLast('.');
Expand All @@ -80,17 +82,17 @@ protected override VisualLineText CreateInstance(int length)
}
else
{
lineNumber = a.ParentVisualLine.Document.Text.GetLineNumber(obj);
lineNumber = a.ParentVisualLine.Document.Text.GetNameLineNumber(obj);
line = a.ParentVisualLine.Document.GetLineByNumber(lineNumber);
}
AvalonEditor.YesWeEditor.Select(line.Offset, line.Length);
AvalonEditor.YesWeEditor.ScrollToLine(lineNumber);
}
else
{
await _threadWorkerView.Begin(cancellationToken =>
_applicationView.CUE4Parse.ExtractAndScroll(cancellationToken, fullPath, obj));
_applicationView.CUE4Parse.ExtractAndScroll(cancellationToken, fullPath, obj, parentExportType));
}
};
return a;
Expand Down
2 changes: 1 addition & 1 deletion FModel/Views/Resources/Controls/AvalonEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void OnTextChanged(object sender, EventArgs e)

if (!tabItem.ShouldScroll) return;

var lineNumber = avalonEditor.Document.Text.GetLineNumber(tabItem.ScrollTrigger);
var lineNumber = avalonEditor.Document.Text.GetNameLineNumber(tabItem.ScrollTrigger);
var line = avalonEditor.Document.GetLineByNumber(lineNumber);
avalonEditor.Select(line.Offset, line.Length);
avalonEditor.ScrollToLine(lineNumber);
Expand Down
Loading

0 comments on commit 9781446

Please sign in to comment.