Skip to content

Commit

Permalink
Always use a dropdown for new weapon/item in backpack and bank tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbed committed Jun 14, 2019
1 parent 2593f0c commit a8beae0
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,18 @@ internal DownloadablePackageDefinition()
public int Id { get; internal set; }
public string DLCName { get; internal set; }
public string DisplayName { get; internal set; }

public static readonly DownloadablePackageDefinition Default;

static DownloadablePackageDefinition()
{
Default = new DownloadablePackageDefinition()
{
ResourcePath = null,
Id = 0,
DLCName = null,
DisplayName = "Base Game",
};
}
}
}
28 changes: 12 additions & 16 deletions projects/Gibbed.BorderlandsOz.SaveEdit/Tabs/BackpackView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,55 @@
<CollectionViewSource x:Key="SlotCollectionViewSource"
Source="{Binding Path=Slots}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="DisplayGroup"></PropertyGroupDescription>
<PropertyGroupDescription PropertyName="DisplayGroup" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<system:Int32 x:Key="DefaultWeaponSetId">0</system:Int32>
<system:Int32 x:Key="DefaultItemSetId">0</system:Int32>
</UserControl.Resources>
<DockPanel>
<cal:Message.Attach>
[Shortcut Control+V] = [Action PasteCode]
</cal:Message.Attach>
<ToolBar Name="ButtonBar"
DockPanel.Dock="Top">
<Button Command="{Binding Path=NewWeapon}"
CommandParameter="{StaticResource DefaultWeaponSetId}">
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}"
IsOpen="{Binding Path=NewWeaponDropDownIsOpen, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<Image Height="24"
Source="..\Resources\assaultrifle.png" />
<Label Content="New Weapon" />
</StackPanel>
</Button>
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}">
<xctk:DropDownButton.DropDownContent>
<ItemsControl ItemsSource="{Binding Path=DownloadablePackages}"
Width="Auto"
Height="Auto">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="gameInfo:DownloadablePackageDefinition">
<Button Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewWeapon}"
CommandParameter="{Binding Path=Id}">
<Button
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewWeapon}"
CommandParameter="{Binding Path=Id}">
<Label Content="{Binding Path=DisplayName}" />
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</xctk:DropDownButton.DropDownContent>
</xctk:DropDownButton>
<Button Command="{Binding Path=NewItem}"
CommandParameter="{StaticResource DefaultItemSetId}">
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}"
IsOpen="{Binding Path=NewItemDropDownIsOpen, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<Image Height="24"
Source="..\Resources\shield.png" />
<Label Content="New Item" />
</StackPanel>
</Button>
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}">
<xctk:DropDownButton.DropDownContent>
<ItemsControl ItemsSource="{Binding Path=DownloadablePackages}"
Width="Auto"
Height="Auto">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="gameInfo:DownloadablePackageDefinition">
<Button Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewItem}"
CommandParameter="{Binding Path=Id}">
<Button
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewItem}"
CommandParameter="{Binding Path=Id}">
<Label Content="{Binding Path=DisplayName}" />
</Button>
</DataTemplate>
Expand Down Expand Up @@ -211,7 +207,7 @@
<ScrollViewer Grid.Column="2"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<ContentControl x:Name="SelectedSlot"></ContentControl>
<ContentControl x:Name="SelectedSlot" />
</ScrollViewer>
</Grid>
</DockPanel>
Expand Down
35 changes: 33 additions & 2 deletions projects/Gibbed.BorderlandsOz.SaveEdit/Tabs/BackpackViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ namespace Gibbed.BorderlandsOz.SaveEdit
[Export(typeof(BackpackViewModel))]
internal class BackpackViewModel : PropertyChangedBase
{
private static readonly DownloadablePackageDefinition[] _DefaultDownloadablePackages;

static BackpackViewModel()
{
_DefaultDownloadablePackages = new[] { DownloadablePackageDefinition.Default };
}

#region Imports
private CharacterViewModel _Character;
private BankViewModel _Bank;
Expand Down Expand Up @@ -80,22 +87,24 @@ public BankViewModel Bank
private IBackpackSlotViewModel _SelectedSlot;

private ICommand _NewWeapon;
private bool _NewWeaponDropDownIsOpen;
private ICommand _NewItem;
private bool _NewItemDropDownIsOpen;
#endregion

#region Properties
public IEnumerable<DownloadablePackageDefinition> DownloadablePackages
{
get
{
return
return _DefaultDownloadablePackages.Concat(
InfoManager.DownloadableContents.Items
.Where(dc => dc.Value.Type == DownloadableContentType.ItemSet &&
dc.Value.Package != null)
.Select(dc => dc.Value.Package)
.Where(dp => InfoManager.AssetLibraryManager.Sets.Any(s => s.Id == dp.Id) == true)
.Distinct()
.OrderBy(dp => dp.Id);
.OrderBy(dp => dp.Id));
}
}

Expand Down Expand Up @@ -134,10 +143,30 @@ public ICommand NewWeapon
get { return this._NewWeapon; }
}

public bool NewWeaponDropDownIsOpen
{
get { return this._NewWeaponDropDownIsOpen; }
set
{
this._NewWeaponDropDownIsOpen = value;
this.NotifyOfPropertyChange(() => this.NewWeaponDropDownIsOpen);
}
}

public ICommand NewItem
{
get { return this._NewItem; }
}

public bool NewItemDropDownIsOpen
{
get { return this._NewItemDropDownIsOpen; }
set
{
this._NewItemDropDownIsOpen = value;
this.NotifyOfPropertyChange(() => this.NewItemDropDownIsOpen);
}
}
#endregion

[ImportingConstructor]
Expand All @@ -162,6 +191,7 @@ public void DoNewWeapon(int assetLibrarySetId)
var viewModel = new BackpackWeaponViewModel(weapon);
this.Slots.Add(viewModel);
this.SelectedSlot = viewModel;
this.NewWeaponDropDownIsOpen = false;
}

public void DoNewItem(int assetLibrarySetId)
Expand All @@ -175,6 +205,7 @@ public void DoNewItem(int assetLibrarySetId)
var viewModel = new BackpackItemViewModel(item);
this.Slots.Add(viewModel);
this.SelectedSlot = viewModel;
this.NewItemDropDownIsOpen = false;
}

private static readonly Regex _CodeSignature =
Expand Down
26 changes: 12 additions & 14 deletions projects/Gibbed.BorderlandsOz.SaveEdit/Tabs/BankView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<CollectionViewSource x:Key="SlotCollectionViewSource"
Source="{Binding Path=Slots}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="DisplayGroup"></PropertyGroupDescription>
<PropertyGroupDescription PropertyName="DisplayGroup" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<system:Int32 x:Key="DefaultWeaponSetId">0</system:Int32>
Expand All @@ -50,47 +50,45 @@
</cal:Message.Attach>
<ToolBar Name="ButtonBar"
DockPanel.Dock="Top">
<Button Command="{Binding Path=NewWeapon}"
CommandParameter="{StaticResource DefaultWeaponSetId}">
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}"
IsOpen="{Binding Path=NewWeaponDropDownIsOpen, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<Image Height="24"
Source="..\Resources\assaultrifle.png" />
<Label Content="New Weapon" />
</StackPanel>
</Button>
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}">
<xctk:DropDownButton.DropDownContent>
<ItemsControl ItemsSource="{Binding Path=DownloadablePackages}"
Width="Auto"
Height="Auto">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="gameInfo:DownloadablePackageDefinition">
<Button Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewWeapon}"
CommandParameter="{Binding Path=Id}">
<Button
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewWeapon}"
CommandParameter="{Binding Path=Id}">
<Label Content="{Binding Path=DisplayName}" />
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</xctk:DropDownButton.DropDownContent>
</xctk:DropDownButton>
<Button Command="{Binding Path=NewItem}"
CommandParameter="{StaticResource DefaultItemSetId}">
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}"
IsOpen="{Binding Path=NewItemDropDownIsOpen, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<Image Height="24"
Source="..\Resources\shield.png" />
<Label Content="New Item" />
</StackPanel>
</Button>
<xctk:DropDownButton IsEnabled="{Binding Path=HasDownloadablePackages}">
<xctk:DropDownButton.DropDownContent>
<ItemsControl ItemsSource="{Binding Path=DownloadablePackages}"
Width="Auto"
Height="Auto">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="gameInfo:DownloadablePackageDefinition">
<Button Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewItem}"
CommandParameter="{Binding Path=Id}">
<Button
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NewItem}"
CommandParameter="{Binding Path=Id}">
<Label Content="{Binding Path=DisplayName}" />
</Button>
</DataTemplate>
Expand Down Expand Up @@ -203,7 +201,7 @@
<ScrollViewer Grid.Column="2"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<ContentControl x:Name="SelectedSlot"></ContentControl>
<ContentControl x:Name="SelectedSlot" />
</ScrollViewer>
</Grid>
</DockPanel>
Expand Down
35 changes: 33 additions & 2 deletions projects/Gibbed.BorderlandsOz.SaveEdit/Tabs/BankViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ namespace Gibbed.BorderlandsOz.SaveEdit
[Export(typeof(BankViewModel))]
internal class BankViewModel : PropertyChangedBase
{
private static readonly DownloadablePackageDefinition[] _DefaultDownloadablePackages;

static BankViewModel()
{
_DefaultDownloadablePackages = new[] { DownloadablePackageDefinition.Default };
}

#region Imports
private CharacterViewModel _Character;
private BackpackViewModel _Backpack;
Expand Down Expand Up @@ -76,22 +83,24 @@ public BackpackViewModel Backpack
private IBaseSlotViewModel _SelectedSlot;

private readonly ICommand _NewWeapon;
private bool _NewWeaponDropDownIsOpen;
private readonly ICommand _NewItem;
private bool _NewItemDropDownIsOpen;
#endregion

#region Properties
public IEnumerable<DownloadablePackageDefinition> DownloadablePackages
{
get
{
return
return _DefaultDownloadablePackages.Concat(
InfoManager.DownloadableContents.Items
.Where(dc => dc.Value.Type == DownloadableContentType.ItemSet &&
dc.Value.Package != null)
.Select(dc => dc.Value.Package)
.Where(dp => InfoManager.AssetLibraryManager.Sets.Any(s => s.Id == dp.Id) == true)
.Distinct()
.OrderBy(dp => dp.Id);
.OrderBy(dp => dp.Id));
}
}

Expand Down Expand Up @@ -125,10 +134,30 @@ public ICommand NewWeapon
get { return this._NewWeapon; }
}

public bool NewWeaponDropDownIsOpen
{
get { return this._NewWeaponDropDownIsOpen; }
set
{
this._NewWeaponDropDownIsOpen = value;
this.NotifyOfPropertyChange(() => this.NewWeaponDropDownIsOpen);
}
}

public ICommand NewItem
{
get { return this._NewItem; }
}

public bool NewItemDropDownIsOpen
{
get { return this._NewItemDropDownIsOpen; }
set
{
this._NewItemDropDownIsOpen = value;
this.NotifyOfPropertyChange(() => this.NewItemDropDownIsOpen);
}
}
#endregion

[ImportingConstructor]
Expand All @@ -151,6 +180,7 @@ public void DoNewWeapon(int assetLibrarySetId)
var viewModel = new BaseWeaponViewModel(weapon);
this.Slots.Add(viewModel);
this.SelectedSlot = viewModel;
this.NewWeaponDropDownIsOpen = false;
}

public void DoNewItem(int assetLibrarySetId)
Expand All @@ -164,6 +194,7 @@ public void DoNewItem(int assetLibrarySetId)
var viewModel = new BaseItemViewModel(item);
this.Slots.Add(viewModel);
this.SelectedSlot = viewModel;
this.NewItemDropDownIsOpen = false;
}

private static readonly Regex _CodeSignature =
Expand Down

0 comments on commit a8beae0

Please sign in to comment.