Skip to content

Commit

Permalink
Add "Add" and "Remove" buttons to Item
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeeynamo committed Nov 16, 2019
1 parent 3a451a3 commit 8d1fc32
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
18 changes: 17 additions & 1 deletion OpenKh.Tools.Kh2SystemEditor/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public ushort DescriptionId

private const string entryName = "item";
private string _searchTerm;
private IMessageProvider _messageProvider;
private List<Item.Stat> _item2;

public ItemViewModel(IMessageProvider messageProvider, IEnumerable<Bar.Entry> entries) :
Expand All @@ -90,6 +91,7 @@ public ItemViewModel(IMessageProvider messageProvider) :
private ItemViewModel(IMessageProvider messageProvider, Item item) :
this(messageProvider, item.Items1)
{
_messageProvider = messageProvider;
_item2 = item.Items2;
}

Expand Down Expand Up @@ -134,7 +136,6 @@ public void InvalidateItemName(int itemId)
OnPropertyChanged(nameof(ItemEntries));
}


protected override void OnSelectedItem(Entry item)
{
base.OnSelectedItem(item);
Expand All @@ -143,6 +144,21 @@ protected override void OnSelectedItem(Entry item)
OnPropertyChanged(nameof(IsItemEditMessageVisible));
}

protected override Entry OnNewItem()
{
ushort smallestUnusedId = 0;
foreach (var item in UnfilteredItems.OrderBy(x => x.Id))
{
if (smallestUnusedId++ + 1 != item.Id)
break;
}

return SelectedItem = new Entry(_messageProvider, new Item.Entry
{
Id = smallestUnusedId
});
}

private void PerformFiltering()
{
if (string.IsNullOrWhiteSpace(SearchTerm))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public SystemEditorViewModel()
{
SaveFile(FileName, fileName);
FileName = fileName;
}, SystemFilter, defaultFileName: FileName parent: Window));
}, SystemFilter, defaultFileName: FileName, parent: Window));

ExitCommand = new RelayCommand(x => Window.Close());

Expand Down
2 changes: 1 addition & 1 deletion OpenKh.Tools.Kh2SystemEditor/ViewModels/TrsrViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected override void OnSelectedItem(Entry item)
protected override Entry OnNewItem()
{
ushort smallestUnusedId = 0;
foreach (var item in this.OrderBy(x => x.Id))
foreach (var item in UnfilteredItems.OrderBy(x => x.Id))
{
if (smallestUnusedId++ + 1 != item.Id)
break;
Expand Down
16 changes: 14 additions & 2 deletions OpenKh.Tools.Kh2SystemEditor/Views/ItemView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<ListBox
Grid.Column="0"
ItemsSource="{Binding Items}"
SelectedItem="{Binding SelectedItem}"
DisplayMemberPath="Name">
DisplayMemberPath="Title">
</ListBox>

<Grid Grid.Row="1" Margin="0 5 0 5">
<Grid Grid.Row="1" Margin="0 3 0 3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="3"/>
Expand All @@ -40,6 +41,17 @@
<TextBox Grid.Column="2"
Text="{Binding SearchTerm, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>

<Grid Grid.Row="2" Margin="0 0 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="_Add" Command="{Binding AddCommand}"/>
<Button Grid.Column="2" Content="_Remove" Command="{Binding RemoveCommand}"/>
</Grid>

</Grid>

<StackPanel
Expand Down

0 comments on commit 8d1fc32

Please sign in to comment.