47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Controls;
|
|
using JD.Asset.Types.Map;
|
|
using Plume.Interfaces.WPF.Documents;
|
|
|
|
namespace SongEditor.View
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MapToolWindow.xaml
|
|
/// </summary>
|
|
public partial class MapToolWindow : UserControl
|
|
{
|
|
private readonly IDocumentManager _documentManager;
|
|
public MapToolWindow(IDocumentManager documentManager)
|
|
{
|
|
InitializeComponent();
|
|
_documentManager = documentManager;
|
|
DataContext = ViewModel;
|
|
documentManager.PrimaryDocumentChanged += DocumentManagerOnPrimaryDocumentChanged;
|
|
}
|
|
|
|
private void DocumentManagerOnPrimaryDocumentChanged(object sender, EventArgs e)
|
|
{
|
|
var map = Map.FromPath(_documentManager.ActiveDocument.Uri.OriginalString);
|
|
ViewModel.MapName = map.Name;
|
|
ViewModel.ArtistAndTitle = $"{map.SongDesc.Artist} - {map.SongDesc.Title}";
|
|
if (Directory.Exists(map.MenuArtTexturesFolder))
|
|
{
|
|
var images = Directory.EnumerateFiles(map.MenuArtTexturesFolder, "*.jpg").ToArray();
|
|
var image = images.FirstOrDefault(x => x.Contains("_Cover.jpg")) ?? images.FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(image))
|
|
{
|
|
ViewModel.ImageUri = new Uri(image);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ViewModel.ImageUri = new Uri("/JD.Shotgun.WPF;component/Resources/thumbnail-default.png", UriKind.Relative);
|
|
}
|
|
|
|
}
|
|
|
|
public MapToolWindowViewModel ViewModel { get; } = new MapToolWindowViewModel();
|
|
}
|
|
}
|