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

@ -1,40 +0,0 @@
<StackPanel x:Class="Client.Application.Components.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"
mc:Ignorable="d">
<local:StatsBar
BackgroundSource="/Assets/icons/ps_cpbar_back.png"
ForegroundSource="/Assets/icons/ps_cpbar.png"
Current="{Binding VitalStats.Cp}"
Total="{Binding VitalStats.MaxCp}"
Height="15"
Margin="0 0 0 2"
/>
<local:StatsBar
BackgroundSource="/Assets/icons/ps_hpbar_back.png"
ForegroundSource="/Assets/icons/ps_hpbar.png"
Current="{Binding VitalStats.Hp}"
Total="{Binding VitalStats.MaxHp}"
Height="15"
Margin="0 0 0 2"
/>
<local:StatsBar
BackgroundSource="/Assets/icons/ps_mpbar_back.png"
ForegroundSource="/Assets/icons/ps_mpbar.png"
Current="{Binding VitalStats.Mp}"
Total="{Binding VitalStats.MaxMp}"
Height="15"
Margin="0 0 0 2"
/>
<local:StatsBar
BackgroundSource="/Assets/icons/ps_expbar_back.png"
ForegroundSource="/Assets/icons/ps_expbar.png"
Current="{Binding Experience.ExpPercent}"
Format="{}{0:F2}%"
Height="15"
Margin="0 0 0 2"
/>
</StackPanel>

View File

@ -1,27 +0,0 @@
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 StatsPanel.xaml
/// </summary>
public partial class StatsPanel : StackPanel
{
public StatsPanel()
{
InitializeComponent();
}
}
}