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 bool IsTarget => Id == hero.TargetId;
public ICommand MouseLeftClickCommand { get; }
public ICommand MouseLeftDoubleClickCommand { get; }
public ICommand MouseRightClickCommand { get; }
@ -47,6 +49,7 @@ namespace Client.Application.ViewModels
creature.PropertyChanged += Creature_PropertyChanged;
creature.Transform.Position.PropertyChanged += Position_PropertyChanged;
hero.Transform.Position.PropertyChanged += HeroPosition_PropertyChanged;
hero.PropertyChanged += Hero_PropertyChanged;
MouseLeftClickCommand = new RelayCommand(OnMouseLeftClick);
MouseLeftDoubleClickCommand = new RelayCommand(OnMouseLeftDoubleClick);
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 Hero hero;
private readonly WorldHandler worldHandler;

View File

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