114 lines
4.4 KiB
C#
114 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media.Imaging;
|
|
using ActiproSoftware.Windows.Extensions;
|
|
using JD.Shotgun.Service;
|
|
using JD.Shotgun.Service.ShotgunEntities;
|
|
using JD.Shotgun.WPF.Settings;
|
|
using Plume.Interfaces.Settings;
|
|
using Action = Plume.Interfaces.WPF.Actions.Action;
|
|
|
|
namespace JD.Shotgun.WPF.Views
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MapExplorerView.xaml
|
|
/// </summary>
|
|
public partial class ShotgunMapExplorerView : UserControl
|
|
{
|
|
private readonly ShotgunSettings _settings;
|
|
private readonly IShotgunService _shotgunService;
|
|
private readonly Func<ShotgunMap, IEnumerable<Action>> _getActionsFunc;
|
|
|
|
public event EventHandler<ShotgunMap> MapSelected;
|
|
|
|
public event EventHandler<ShotgunOpus> OpusSelected;
|
|
|
|
public ShotgunMapExplorerView(IShotgunService shotgunService, ISettingsManager settingsManager, Func<ShotgunMap, IEnumerable<Action>> getActionsFunc)
|
|
{
|
|
InitializeComponent();
|
|
Actions = new ObservableCollection<Action>();
|
|
_shotgunService = shotgunService;
|
|
_settings = settingsManager.Get<ShotgunSettings>();
|
|
_getActionsFunc = getActionsFunc;
|
|
UpdateOpuses();
|
|
}
|
|
|
|
private void UpdateOpuses()
|
|
{
|
|
ComboBoxOpus.Items.Clear();
|
|
var opuses = _shotgunService.GetAllOpuses().Reverse().ToList();
|
|
foreach (var shotgunJdOpus in opuses)
|
|
{
|
|
ComboBoxOpus.Items.Add(shotgunJdOpus);
|
|
}
|
|
|
|
ComboBoxOpus.SelectedIndex = !string.IsNullOrEmpty(_settings.CurrentOpus) ? Math.Max(0, opuses.FindIndex(opus => opus.Name == _settings.CurrentOpus)) : 0;
|
|
}
|
|
|
|
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(x => x.Name).ToList();
|
|
foreach (var shotgunJdMap in maps)
|
|
{
|
|
ComboBoxMaps.Items.Add(shotgunJdMap);
|
|
}
|
|
ComboBoxMaps.SelectedIndex = !string.IsNullOrEmpty(_settings.CurrentMap) ? Math.Max(0, maps.FindIndex(x => x.Name == _settings.CurrentMap)) : 0;
|
|
OpusSelected?.Invoke(this, opus);
|
|
}
|
|
else
|
|
{
|
|
ComboBoxMaps.SelectedIndex = 0;
|
|
OpusSelected?.Invoke(this, null);
|
|
}
|
|
}
|
|
|
|
private void ComboBoxMaps_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
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));
|
|
MapSelected?.Invoke(this, map);
|
|
}
|
|
else
|
|
{
|
|
MapSelected?.Invoke(this, null);
|
|
}
|
|
RefreshActions();
|
|
}
|
|
|
|
private void RefreshActions()
|
|
{
|
|
Actions.Clear();
|
|
if (ComboBoxMaps.SelectedValue is ShotgunMap map)
|
|
{
|
|
Actions.AddRange(_getActionsFunc(map));
|
|
}
|
|
}
|
|
|
|
public void Select(ShotgunMapAsset asset)
|
|
{
|
|
ComboBoxOpus.SelectedIndex = ComboBoxOpus.Items.Cast<ShotgunOpus>().ToList().FindIndex(opus => opus.Name == asset.MapOpusName);
|
|
ComboBoxMaps.SelectedIndex = ComboBoxMaps.Items.Cast<ShotgunMap>().ToList().FindIndex(map => map.Name == asset.MapName);
|
|
}
|
|
|
|
public static readonly DependencyProperty ActionsProperty = DependencyProperty.Register("Actions", typeof(ObservableCollection<Action>), typeof(ShotgunMapExplorerView), new PropertyMetadata(default(ObservableCollection<Action>)));
|
|
|
|
public ObservableCollection<Action> Actions
|
|
{
|
|
get { return (ObservableCollection<Action>)GetValue(ActionsProperty); }
|
|
set { SetValue(ActionsProperty, value); }
|
|
}
|
|
|
|
}
|
|
}
|