featL add skill component

This commit is contained in:
k0t9i 2023-02-01 14:48:59 +04:00
parent 32fdef9b1c
commit 9a0204c6ed
10 changed files with 257 additions and 76 deletions

View File

@ -0,0 +1,52 @@
<Button x:Class="Client.Application.Components.Skill"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Client.Application.Components"
xmlns:converters="clr-namespace:Client.Application.Converters"
mc:Ignorable="d"
IsEnabled="{Binding Path=IsButtonActive,ElementName=root,Mode=OneWay}"
ToolTipService.ShowOnDisabled="True"
x:Name="root">
<Button.Resources>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
<DataTemplate x:Key="ToolTipContent">
<StackPanel MaxWidth="300">
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Lv {1}">
<Binding Path="SkillName" Mode="OneWay" Source="{x:Reference root}"/>
<Binding Path="Level" Mode="OneWay" Source="{x:Reference root}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock
TextWrapping="Wrap"
Text="{Binding Source={x:Reference root},Path=Cost,Mode=OneWay,StringFormat='MP Cost {0}'}"
Visibility="{Binding Source={x:Reference root},Path=Cost,Converter={StaticResource NullToVisibilityConverter},ConverterParameter=Hidden,Mode=OneWay}"
/>
<TextBlock
TextWrapping="Wrap"
Text="{Binding Source={x:Reference root},Path=Range,Mode=OneWay,StringFormat='Range {0}'}"
Visibility="{Binding Source={x:Reference root},Path=Range,Converter={StaticResource NullToVisibilityConverter},ConverterParameter=Hidden,Mode=OneWay}"
/>
<TextBlock
TextWrapping="Wrap"
Text="{Binding Source={x:Reference root},Path=Description,Mode=OneWay}"
Visibility="{Binding Source={x:Reference root},Path=Description,Converter={StaticResource NullToVisibilityConverter},ConverterParameter=Hidden,Mode=OneWay}"
/>
</StackPanel>
</DataTemplate>
</Button.Resources>
<Button.Content>
<Grid>
<Image Source="{Binding Path=ImageSource,ElementName=root}" Height="32" Width="32" />
<Rectangle Fill="Black" Opacity=".5" Visibility="{Binding Path=IsReadyToUse,ElementName=root,Converter={StaticResource BooleanToVisibilityConverter},ConverterParameter=Inverted,Mode=OneWay}"/>
</Grid>
</Button.Content>
<Button.ToolTip >
<ContentControl ContentTemplate="{StaticResource ToolTipContent}"/>
</Button.ToolTip>
</Button>

View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Client.Application.Components
{
/// <summary>
/// Interaction logic for Skill.xaml
/// </summary>
public partial class Skill : Button
{
public static readonly DependencyProperty IsButtonActiveProperty =
DependencyProperty.Register("IsButtonActive", typeof(bool), typeof(Skill), new PropertyMetadata(true, null, OnCoerceButtonActivity));
public static readonly DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(Skill), new PropertyMetadata(default(ImageSource)));
public static readonly DependencyProperty IsReadyToUseProperty =
DependencyProperty.Register("IsReadyToUse", typeof(bool), typeof(Skill), new PropertyMetadata(true, OnButtonActivityChanged));
public static readonly DependencyProperty SkillNameProperty =
DependencyProperty.Register("SkillName", typeof(string), typeof(Skill), new PropertyMetadata("Skill"));
public static readonly DependencyProperty LevelProperty =
DependencyProperty.Register("Level", typeof(uint), typeof(Skill), new PropertyMetadata((uint)1));
public static readonly DependencyProperty CostProperty =
DependencyProperty.Register("Cost", typeof(uint?), typeof(Skill), new PropertyMetadata(null));
public static readonly DependencyProperty RangeProperty =
DependencyProperty.Register("Range", typeof(int?), typeof(Skill), new PropertyMetadata(null));
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(Skill), new PropertyMetadata(null));
public static readonly DependencyProperty IsActiveProperty =
DependencyProperty.Register("IsActive", typeof(bool), typeof(Skill), new PropertyMetadata(true, OnButtonActivityChanged));
private static void OnButtonActivityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var model = (Skill)d;
model.CoerceValue(IsButtonActiveProperty);
}
private static object OnCoerceButtonActivity(DependencyObject d, object baseValue)
{
var model = (Skill)d;
return model.IsReadyToUse && model.IsActive;
}
public Skill()
{
InitializeComponent();
}
public bool IsButtonActive
{
get { return (bool)GetValue(IsButtonActiveProperty); }
set { SetValue(IsButtonActiveProperty, value); }
}
public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set { SetValue(ImageSourceProperty, value); }
}
public bool IsReadyToUse
{
get { return (bool)GetValue(IsReadyToUseProperty); }
set { SetValue(IsReadyToUseProperty, value); }
}
public string SkillName
{
get { return (string)GetValue(SkillNameProperty); }
set { SetValue(SkillNameProperty, value); }
}
public uint Level
{
get { return (uint)GetValue(LevelProperty); }
set { SetValue(LevelProperty, value); }
}
public uint? Cost
{
get { return (uint?)GetValue(CostProperty); }
set { SetValue(CostProperty, value); }
}
public int? Range
{
get { return (int?)GetValue(RangeProperty); }
set { SetValue(RangeProperty, value); }
}
public string? Description
{
get { return (string?)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public bool IsActive
{
get { return (bool)GetValue(IsActiveProperty); }
set { SetValue(IsActiveProperty, value); }
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace Client.Application.Converters
{
public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var isInverted = parameter == null ? false : true;
var preparedValue = value == null ? false : (bool)value;
preparedValue = isInverted ? !preparedValue : preparedValue;
return innerConverter.Convert(preparedValue, targetType, parameter, culture);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
System.Windows.Controls.BooleanToVisibilityConverter innerConverter = new System.Windows.Controls.BooleanToVisibilityConverter();
}
}

View File

@ -13,7 +13,9 @@ namespace Client.Application.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? Visibility.Hidden : Visibility.Visible;
var isCollapsedWhenNull = parameter == null ? false : true;
var nullVisibility = isCollapsedWhenNull ? Visibility.Collapsed : Visibility.Hidden;
return value == null ? nullVisibility : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

View File

@ -18,8 +18,8 @@ namespace Client.Application.ViewModels
public bool IsActive => skill.IsActive;
public bool IsReadyToUse => skill.IsReadyToUse;
public bool IsBusy => !skill.IsReadyToUse;
public uint Cost => skill.Cost;
public int Range => skill.Range;
public uint? Cost => skill.Cost == 0 ? null : skill.Cost;
public int? Range => skill.Range <= 0 ? null : skill.Range;
public SkillListViewModel(Skill skill)
{

View File

@ -5,9 +5,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Client"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:ctrls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
xmlns:converters="clr-namespace:Client.Application.Converters"
xmlns:components="clr-namespace:Client.Application.Components"
xmlns:views="clr-namespace:Client.Application.Views"
mc:Ignorable="d"
Title="L2Bot 2.0 Client" Height="600" Width="1024">
<Window.Resources>
@ -22,7 +22,6 @@
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
<ctrls:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
@ -105,74 +104,13 @@
<TabItem>
<TabItem.Header>Active</TabItem.Header>
<TabItem.Content>
<ItemsControl ItemsSource="{Binding ActiveSkills,Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button IsEnabled="{Binding Path=IsReadyToUse,Mode=OneWay}">
<Button.Content>
<Grid>
<Image Source="{Binding Path=IconName}" Height="32" Width="32" />
<Rectangle Fill="Black" Opacity=".5" Visibility="{Binding Path=IsBusy,Converter={StaticResource BooleanToVisibilityConverter},Mode=OneWay}"/>
</Grid>
</Button.Content>
<Button.ToolTip>
<StackPanel MaxWidth="300">
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Lv {1}">
<Binding Path="Name" Mode="OneWay"/>
<Binding Path="Level" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Cost,Mode=OneWay,StringFormat='MP Cost {0}'}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Range,Mode=OneWay,StringFormat='Range {0}'}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Description,Mode=OneWay}" />
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<views:SkillPanel ItemsSource="{Binding ActiveSkills,Mode=OneWay}" />
</TabItem.Content>
</TabItem>
<TabItem>
<TabItem.Header>Passive</TabItem.Header>
<TabItem.Content>
<ItemsControl ItemsSource="{Binding PassiveSkills,Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button IsEnabled="False" ToolTipService.ShowOnDisabled="True">
<Button.Content>
<Image Source="{Binding Path=IconName}" Height="32" Width="32" />
</Button.Content>
<Button.ToolTip>
<StackPanel MaxWidth="300">
<TextBlock TextWrapping="Wrap" FontWeight="Bold" FontSize="14" Margin="0,0,0,5">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Lv {1}">
<Binding Path="Name" Mode="OneWay"/>
<Binding Path="Level" Mode="OneWay"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Description,Mode=OneWay}" />
</StackPanel>
</Button.ToolTip>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<views:SkillPanel ItemsSource="{Binding PassiveSkills,Mode=OneWay}" />
</TabItem.Content>
</TabItem>
</TabControl>
@ -201,7 +139,7 @@
</TextBlock.Text>
</TextBlock>
</StackPanel>
<components:StatsPanel DataContext="{Binding ., Mode=OneWay}" Margin="4" Grid.Row="1" />
<views:StatsPanel DataContext="{Binding ., Mode=OneWay}" Margin="4" Grid.Row="1" />
<DockPanel Grid.Row="2" Margin="4">
<StackPanel DockPanel.Dock="Left" Margin="0 0 5 0">
<TextBlock Padding="0 0 0 3">Position:</TextBlock>

View File

@ -0,0 +1,28 @@
<ItemsControl x:Class="Client.Application.Views.SkillPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Client.Application.Views"
xmlns:components="clr-namespace:Client.Application.Components"
mc:Ignorable="d">
<ItemsControl.ItemTemplate>
<DataTemplate>
<components:Skill
ImageSource="{Binding Path=IconName,Mode=OneWay}"
IsReadyToUse="{Binding Path=IsReadyToUse,Mode=OneWay}"
IsActive="{Binding Path=IsActive,Mode=OneWay}"
SkillName="{Binding Path=Name,Mode=OneWay}"
Level="{Binding Path=Level,Mode=OneWay}"
Cost="{Binding Path=Cost,Mode=OneWay}"
Range="{Binding Path=Range,Mode=OneWay}"
Description="{Binding Path=Description,Mode=OneWay}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Client.Application.Views
{
/// <summary>
/// Interaction logic for SkillPanel.xaml
/// </summary>
public partial class SkillPanel : ItemsControl
{
public SkillPanel()
{
InitializeComponent();
}
}
}

View File

@ -1,11 +1,11 @@
<StackPanel x:Class="Client.Application.Components.StatsPanel"
<StackPanel x:Class="Client.Application.Views.StatsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Client.Application.Components"
xmlns:components="clr-namespace:Client.Application.Components"
mc:Ignorable="d">
<local:StatsBar
<components:StatsBar
BackgroundSource="/Assets/icons/ps_cpbar_back.png"
ForegroundSource="/Assets/icons/ps_cpbar.png"
Current="{Binding VitalStats.Cp}"
@ -13,7 +13,7 @@
Height="15"
Margin="0 0 0 2"
/>
<local:StatsBar
<components:StatsBar
BackgroundSource="/Assets/icons/ps_hpbar_back.png"
ForegroundSource="/Assets/icons/ps_hpbar.png"
Current="{Binding VitalStats.Hp}"
@ -21,7 +21,7 @@
Height="15"
Margin="0 0 0 2"
/>
<local:StatsBar
<components:StatsBar
BackgroundSource="/Assets/icons/ps_mpbar_back.png"
ForegroundSource="/Assets/icons/ps_mpbar.png"
Current="{Binding VitalStats.Mp}"
@ -29,7 +29,7 @@
Height="15"
Margin="0 0 0 2"
/>
<local:StatsBar
<components:StatsBar
BackgroundSource="/Assets/icons/ps_expbar_back.png"
ForegroundSource="/Assets/icons/ps_expbar.png"
Current="{Binding Experience.ExpPercent}"

View File

@ -12,7 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Client.Application.Components
namespace Client.Application.Views
{
/// <summary>
/// Interaction logic for StatsPanel.xaml