feat: add highlighting for target in creature list

This commit is contained in:
k0t9i
2023-02-09 23:07:57 +04:00
parent ad5d7a5159
commit 123d039263
2 changed files with 37 additions and 19 deletions

View File

@@ -24,6 +24,8 @@ namespace Client.Application.ViewModels
public float DeltaZ => creature.DeltaZ(hero); public float DeltaZ => creature.DeltaZ(hero);
public bool IsTarget => Id == hero.TargetId;
public ICommand MouseLeftClickCommand { get; } public ICommand MouseLeftClickCommand { get; }
public ICommand MouseLeftDoubleClickCommand { get; } public ICommand MouseLeftDoubleClickCommand { get; }
public ICommand MouseRightClickCommand { get; } public ICommand MouseRightClickCommand { get; }
@@ -47,6 +49,7 @@ namespace Client.Application.ViewModels
creature.PropertyChanged += Creature_PropertyChanged; creature.PropertyChanged += Creature_PropertyChanged;
creature.Transform.Position.PropertyChanged += Position_PropertyChanged; creature.Transform.Position.PropertyChanged += Position_PropertyChanged;
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged; hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
hero.PropertyChanged += Hero_PropertyChanged;
MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick); MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick);
MouseLeftDoubleClickCommand = new RelayCommand(OnMouseLeftDoubleClick); MouseLeftDoubleClickCommand = new RelayCommand(OnMouseLeftDoubleClick);
MouseRightClickCommand = new RelayCommand(OnMouseRightClick); MouseRightClickCommand = new RelayCommand(OnMouseRightClick);
@@ -80,6 +83,14 @@ namespace Client.Application.ViewModels
} }
} }
private void Hero_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "TargetId")
{
OnPropertyChanged("IsTarget");
}
}
private readonly CreatureInterface creature; private readonly CreatureInterface creature;
private readonly Hero hero; private readonly Hero hero;
private readonly WorldHandler worldHandler; private readonly WorldHandler worldHandler;

View File

@@ -49,30 +49,37 @@
<RowDefinition Height="2*"></RowDefinition> <RowDefinition Height="2*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition> <RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ListBox ItemsSource="{Binding Source={StaticResource SortedCreatures}, Mode=OneWay}" Grid.Row="0"> <ListBox ItemsSource="{Binding Source={StaticResource SortedCreatures}, Mode=OneWay}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Margin="5"> <Grid x:Name="Item">
<StackPanel.InputBindings> <StackPanel Margin="5">
<MouseBinding Gesture="LeftClick" Command="{Binding MouseLeftClickCommand}" /> <StackPanel.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding MouseLeftDoubleClickCommand}" /> <MouseBinding Gesture="LeftClick" Command="{Binding MouseLeftClickCommand}" />
<MouseBinding Gesture="RightClick" Command="{Binding MouseRightClickCommand}" /> <MouseBinding Gesture="LeftDoubleClick" Command="{Binding MouseLeftDoubleClickCommand}" />
</StackPanel.InputBindings> <MouseBinding Gesture="RightClick" Command="{Binding MouseRightClickCommand}" />
<TextBlock FontSize="16" Text="{Binding Path=Name,Mode=OneWay}" /> </StackPanel.InputBindings>
<TextBlock FontSize="11"> <TextBlock FontSize="16" Text="{Binding Path=Name,Mode=OneWay}" />
<TextBlock.Text> <TextBlock FontSize="11">
<MultiBinding StringFormat="{}{0}; distance: {1:F0}; delta z: {2:F0}"> <TextBlock.Text>
<Binding Path="BriefInfo" Mode="OneWay"/> <MultiBinding StringFormat="{}{0}; distance: {1:F0}; delta z: {2:F0}">
<Binding Path="Distance" Mode="OneWay"/> <Binding Path="BriefInfo" Mode="OneWay"/>
<Binding Path="DeltaZ" Mode="OneWay"/> <Binding Path="Distance" Mode="OneWay"/>
</MultiBinding> <Binding Path="DeltaZ" Mode="OneWay"/>
</TextBlock.Text> </MultiBinding>
</TextBlock> </TextBlock.Text>
</StackPanel> </TextBlock>
</StackPanel>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsTarget,Mode=OneWay}" Value="True">
<Setter TargetName="Item" Property="Background" Value="#110000ff" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<ListBox ItemsSource="{Binding Source={StaticResource SortedDrops}, Mode=OneWay}" Grid.Row="1"> <ListBox ItemsSource="{Binding Source={StaticResource SortedDrops}, Mode=OneWay}" Grid.Row="1" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<DockPanel> <DockPanel>