164 lines
5.8 KiB
C#
164 lines
5.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media.Imaging;
|
|
using JD.Shotgun.Service;
|
|
using JD.Shotgun.Service.ShotgunEntities;
|
|
using JD.Shotgun.WPF.Settings;
|
|
using Plume.Interfaces.Settings;
|
|
|
|
namespace JD.Shotgun.WPF.Views
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ExplorerView.xaml
|
|
/// </summary>
|
|
public partial class ShotgunAssetExplorerView : UserControl, IShotgunExplorer
|
|
{
|
|
private readonly ShotgunSettings _settings;
|
|
private readonly IShotgunService _shotgunService;
|
|
|
|
public ShotgunObject FocusedItem { get; private set; }
|
|
public event Action<ShotgunObject> OnItemFocused;
|
|
public event Action<ShotgunObject> OnItemActivated;
|
|
|
|
public ShotgunAssetExplorerView(IShotgunService shotgunService, ISettingsManager settingsManager)
|
|
{
|
|
InitializeComponent();
|
|
_shotgunService = shotgunService;
|
|
_settings = settingsManager.Get<ShotgunSettings>();
|
|
}
|
|
|
|
public ICollection<ShotgunObject> Search(string userInput)
|
|
{
|
|
return new List<ShotgunObject>();
|
|
}
|
|
|
|
public void Focus(ShotgunObject item)
|
|
{
|
|
ShotgunMapAsset asset = item as ShotgunMapAsset;
|
|
if (asset == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ComboBoxOpus.SelectedIndex = ComboBoxOpus.Items.Cast<ShotgunOpus>().ToList().FindIndex(shotgunOpus => shotgunOpus.Name == asset.MapOpusName);
|
|
ComboBoxMaps.SelectedIndex = ComboBoxMaps.Items.Cast<ShotgunMap>().ToList().FindIndex(shotgunMap => shotgunMap.Name == asset.MapName);
|
|
ComboBoxAssets.SelectedIndex = ComboBoxAssets.Items.Cast<ShotgunMapAsset>().ToList().FindIndex(shotgunMapAsset => shotgunMapAsset.Name == asset.Name);
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
ComboBoxOpus.Items.Clear();
|
|
var opuses = _shotgunService.GetAllOpuses().OrderByDescending(o => o.Name, new OpusNameComparer()).ToList();
|
|
foreach (var shotgunJdOpus in opuses)
|
|
{
|
|
ComboBoxOpus.Items.Add(shotgunJdOpus);
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(_settings.CurrentOpus))
|
|
{
|
|
ComboBoxOpus.SelectedIndex = 0;
|
|
return;
|
|
}
|
|
|
|
int currentOpusIndex = opuses.FindIndex(opus => opus.Name == _settings.CurrentOpus);
|
|
ComboBoxOpus.SelectedIndex = Math.Max(0, currentOpusIndex);
|
|
}
|
|
|
|
private void ComboBoxOpus_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
ComboBoxMaps.Items.Clear();
|
|
|
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] is ShotgunOpus opus)
|
|
{
|
|
_settings.CurrentOpus = opus.Name;
|
|
|
|
var maps = _shotgunService.GetOpusMaps(opus).OrderBy(shotgunMap => shotgunMap.Name).ToList();
|
|
foreach (var shotgunJdMap in maps)
|
|
{
|
|
ComboBoxMaps.Items.Add(shotgunJdMap);
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(_settings.CurrentMap))
|
|
{
|
|
ComboBoxMaps.SelectedIndex = 0;
|
|
return;
|
|
}
|
|
|
|
int mapIndex = maps.FindIndex(shotgunMap => shotgunMap.Name == _settings.CurrentMap);
|
|
ComboBoxMaps.SelectedIndex = Math.Max(0, mapIndex);
|
|
}
|
|
else
|
|
{
|
|
ComboBoxMaps.SelectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
private void ComboBoxMaps_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
ComboBoxAssets.Items.Clear();
|
|
|
|
if (e.AddedItems.Count > 0 && e.AddedItems[0] is ShotgunMap map)
|
|
{
|
|
_settings.CurrentMap = map.Name;
|
|
|
|
Thumbnail.Source = string.IsNullOrEmpty(map.ThumbnailUrl) ?
|
|
new BitmapImage(new Uri("/JD.Shotgun.WPF;component/Resources/thumbnail-default.png", UriKind.Relative)) :
|
|
new BitmapImage(new Uri(map.ThumbnailUrl));
|
|
|
|
List<ShotgunMapAsset> assets = _shotgunService.GetMapAssets(map).ToList();
|
|
assets = assets.Where(asset => asset.AssetType == ShotgunAssetType.Fx || asset.AssetType == ShotgunAssetType.Coach).ToList();
|
|
|
|
foreach (var asset in assets)
|
|
{
|
|
ComboBoxAssets.Items.Add(asset);
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(_settings.CurrentAsset))
|
|
{
|
|
ComboBoxAssets.SelectedIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
int assetIndex = assets.FindIndex(shotgunMapAsset => shotgunMapAsset.Name == _settings.CurrentAsset);
|
|
ComboBoxAssets.SelectedIndex = Math.Max(0, assetIndex);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ComboBoxAssets.SelectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
private void ComboBoxAssets_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
ShotgunMapAsset focusedAsset;
|
|
if (e.AddedItems.Count < 1)
|
|
{
|
|
focusedAsset = null;
|
|
}
|
|
else
|
|
{
|
|
focusedAsset = e.AddedItems[0] as ShotgunMapAsset;
|
|
|
|
if (focusedAsset != null)
|
|
{
|
|
_settings.CurrentAsset = focusedAsset.Name;
|
|
}
|
|
}
|
|
|
|
OnItemFocused?.Invoke(focusedAsset);
|
|
FocusedItem = focusedAsset;
|
|
}
|
|
|
|
private void OkButton_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ComboBoxAssets.SelectedItem is ShotgunObject activatedAsset)
|
|
{
|
|
OnItemActivated?.Invoke(activatedAsset);
|
|
}
|
|
}
|
|
}
|
|
}
|