Skip to content

Commit

Permalink
support material all check/uncheck
Browse files Browse the repository at this point in the history
  • Loading branch information
turtle-insect committed Dec 8, 2024
1 parent e985ff2 commit aaccb9d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 32 deletions.
14 changes: 11 additions & 3 deletions CMNDAT/BitItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace CMNDAT
using System.ComponentModel;

namespace CMNDAT
{
internal class BitItem
internal class BitItem : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;

private readonly uint mAddress;
private readonly uint mBit;

Expand All @@ -14,7 +18,11 @@ public BitItem(uint address, uint bit)
public bool Value
{
get { return SaveData.Instance().ReadBit(mAddress, mBit); }
set { SaveData.Instance().WriteBit(mAddress, mBit, value); }
set
{
SaveData.Instance().WriteBit(mAddress, mBit, value);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));
}
}
}
}
62 changes: 36 additions & 26 deletions CMNDAT/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -322,33 +322,43 @@
</ListBox>
</TabItem>
<TabItem Header="Material Island">
<ListBox ItemsSource="{Binding MaterialIslands}">
<ListBox.Resources>
<local:MaterialIslandStateConverter x:Key="MaterialIslandStateConverter"/>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Name}"/>
<StackPanel Orientation="Horizontal">
<Label Content="State"/>
<ComboBox SelectedIndex="{Binding State, Converter={StaticResource MaterialIslandStateConverter}}">
<ComboBoxItem Content="None"/>
<ComboBoxItem Content="View"/>
<ComboBoxItem Content="Open"/>
</ComboBox>
<DockPanel>
<Grid DockPanel.Dock="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Content="All Check" Command="{Binding CommandAllCheckMaterials}"/>
<Button Grid.Column="1" Content="All UnCheck" Command="{Binding CommandAllUnCheckMaterials}"/>
</Grid>
<ListBox ItemsSource="{Binding MaterialIslands}">
<ListBox.Resources>
<local:MaterialIslandStateConverter x:Key="MaterialIslandStateConverter"/>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Name}"/>
<StackPanel Orientation="Horizontal">
<Label Content="State"/>
<ComboBox SelectedIndex="{Binding State, Converter={StaticResource MaterialIslandStateConverter}}">
<ComboBoxItem Content="None"/>
<ComboBoxItem Content="View"/>
<ComboBoxItem Content="Open"/>
</ComboBox>
</StackPanel>
<ListBox Height="100" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Value}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<ListBox Height="100" ItemsSource="{Binding Info}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Value}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</TabItem>
<TabItem Header="Crafts">
<DockPanel>
Expand Down
4 changes: 2 additions & 2 deletions CMNDAT/MaterialIsland.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CMNDAT
internal class MaterialIsland
{
private readonly uint mAddress;
public ObservableCollection<BitItem> Info { get; set; } = new ObservableCollection<BitItem>();
public ObservableCollection<BitItem> Items { get; set; } = new ObservableCollection<BitItem>();

public MaterialIsland(uint address, String name)
{
Expand All @@ -15,7 +15,7 @@ public MaterialIsland(uint address, String name)

for (uint i = 0; i < 48; i++)
{
Info.Add(new BitItem(address + i / 8, i % 8));
Items.Add(new BitItem(address + i / 8, i % 8));
}
}

Expand Down
26 changes: 25 additions & 1 deletion CMNDAT/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal class ViewModel
public ICommand CommandCraftAllInfinite { get; init; }
public ICommand CommandAllCheckSceneries { get; init; }
public ICommand CommandAllUnCheckSceneries { get; init; }
public ICommand CommandAllCheckMaterials { get; init; }
public ICommand CommandAllUnCheckMaterials { get; init; }

public Appearance Appearance { get; private set; } = new Appearance();
public ObservableCollection<Item> Inventory { get; private set; } = new ObservableCollection<Item>();
Expand Down Expand Up @@ -124,7 +126,8 @@ public ViewModel()
CommandCraftAllInfinite = new CommandAction(CraftAllInfinite);
CommandAllCheckSceneries = new CommandAction(AllCheckSceneries);
CommandAllUnCheckSceneries = new CommandAction(AllUnCheckSceneries);

CommandAllCheckMaterials = new CommandAction(AllCheckMaterials);
CommandAllUnCheckMaterials = new CommandAction(AllUnCheckMaterials);

for (uint i = 0; i < 15; i++)
{
Expand Down Expand Up @@ -507,5 +510,26 @@ private void UpdateSceneries(bool flag)
scene.Visit = flag;
}
}

private void AllCheckMaterials(Object? obj)
{
UpdateMaterials(true);
}

private void AllUnCheckMaterials(Object? obj)
{
UpdateMaterials(false);
}

private void UpdateMaterials(bool flag)
{
foreach (var island in MaterialIslands)
{
foreach (var item in island.Items)
{
item.Value = flag;
}
}
}
}
}

0 comments on commit aaccb9d

Please sign in to comment.