Skip to content

Commit

Permalink
更新黑暗模式,动画重写
Browse files Browse the repository at this point in the history
  • Loading branch information
mehaifeng committed Apr 12, 2023
1 parent 3c41632 commit dd2da5c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 63 deletions.
4 changes: 2 additions & 2 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<SolidColorBrush x:Key="LabelForegroundColor" Color="LightGray"/>
<SolidColorBrush x:Key="ButtonBackgroundColor" Color="LightGray"/>
<!--黑暗模式颜色-->
<SolidColorBrush x:Key="DarkBackgroundColor" Color="Black"/>
<SolidColorBrush x:Key="DarkBackgroundColor" Color="#1F1F1F"/>
<SolidColorBrush x:Key="DarkForegroundColor" Color="White"/>
<SolidColorBrush x:Key="DarkTextBoxBackgroundColor" Color="#696969"/>
<SolidColorBrush x:Key="DarkTextBoxBackgroundColor" Color="#454545"/>
<SolidColorBrush x:Key="DarkTextBoxForegroundColor" Color="White"/>
<SolidColorBrush x:Key="DarkLabelForegroundColor" Color="#483d8b"/>
<SolidColorBrush x:Key="DarkButtonBackgroundColor" Color="LightGray"/>
Expand Down
5 changes: 2 additions & 3 deletions Assets/Styles/DefaultStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!--Toggle样式-->
<ControlTemplate TargetType="ToggleButton" x:Key="ToggleButtonTemplate">
<Border>
<TextBlock
Expand All @@ -54,14 +55,12 @@
<Border
x:Name="borderBack"
Cursor="Hand"
BorderBrush="LightGray"
BorderThickness="0,0,0,1">
<TextBlock
x:Name="ButtonName"
Text="{Binding Content, RelativeSource={RelativeSource AncestorType=Button,Mode=FindAncestor}}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="Black"/>
VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
Expand Down
93 changes: 47 additions & 46 deletions ViewModels/VisualChatViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,57 +227,58 @@ void InitialOpreate()
[RelayCommand]
private void ClickAbout()
{
ShowOutput += $"\n ———————————————————————\n";
showOutput += $" || ||\n";
showOutput += $" || ||\n";
showOutput += $" || RK800_V0.1 ||\n";
showOutput += $" || ||\n";
showOutput += $" || 通用API: OpenAI.com ||\n";
showOutput += $" || ||\n";
showOutput += $" || ||\n";
showOutput += $" || ||\n";
showOutput += $" || ||\n";
showOutput += $" || ||\n";
ShowOutput += $" ———————————————————————\n";
ShowOutput += "\n";
ShowOutput += $" ———————————————————————\n";
ShowOutput += $" || ||\n";
ShowOutput += $" || ||\n";
ShowOutput += $" || RK800_V0.1 ||\n";
ShowOutput += $" || ||\n";
ShowOutput += $" || 通用API: OpenAI.com ||\n";
ShowOutput += $" || ||\n";
ShowOutput += $" || ||\n";
ShowOutput += $" || ||\n";
ShowOutput += $" || ||\n";
ShowOutput += $" || ||\n";
ShowOutput += $" ———————————————————————\n";
}

/// <summary>
/// 开启Or关闭配置栏
/// </summary>
/// <param name="o"></param>
[RelayCommand]
private void OpenOrCloseConfig(Grid o)
{
//如果是关闭的
if ( ConfigGridHeight < 60)
{
SettingBtnContent = "\xe797";
Timer timer = new(0.5);
timer.Elapsed += (sender,e) =>
{
ConfigGridHeight++;
if(ConfigGridHeight >= 60)
{
timer.Stop();
}
};
timer.Start();
}
//如果是打开的
if ( ConfigGridHeight >= 60)
{
SettingBtnContent = "\xe799";
Timer timer = new Timer(0.5);
timer.Elapsed += (sender, e) =>
{
ConfigGridHeight--;
if (ConfigGridHeight == 0)
{
timer.Stop();
}
};
timer.Start();
}
}
//[RelayCommand]
//private void OpenOrCloseConfig(Grid o)
//{
// //如果是关闭的
// if ( ConfigGridHeight < 60)
// {
// SettingBtnContent = "\xe797";
// Timer timer = new(0.5);
// timer.Elapsed += (sender,e) =>
// {
// ConfigGridHeight++;
// if(ConfigGridHeight >= 60)
// {
// timer.Stop();
// }
// };
// timer.Start();
// }
// //如果是打开的
// if ( ConfigGridHeight >= 60)
// {
// SettingBtnContent = "\xe799";
// Timer timer = new Timer(0.5);
// timer.Elapsed += (sender, e) =>
// {
// ConfigGridHeight--;
// if (ConfigGridHeight == 0)
// {
// timer.Stop();
// }
// };
// timer.Start();
// }
//}
}
}
43 changes: 32 additions & 11 deletions Views/VisualChat.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<Border Margin="7">
<Border.Effect>
<DropShadowEffect Color="Gray" BlurRadius="10" Opacity="0.7" Direction="320" ShadowDepth="5"/>
<DropShadowEffect Color="Black" BlurRadius="10" Opacity="0.7" Direction="320" ShadowDepth="5"/>
</Border.Effect>
<Grid
Grid.Row="3">
Expand Down Expand Up @@ -95,30 +95,34 @@
PlacementTarget="{Binding ElementName=MenuToggleBtn}"
Placement="Bottom">
<Border
Margin="10"
Name="sideMenu"
Background="White"
Margin="10"
Width="80"
Height="80"
CornerRadius="7">
<Border.Effect>
<DropShadowEffect Color="Gray" Direction="0" BlurRadius="10" Opacity="0.7" ShadowDepth="1"/>
<DropShadowEffect Color="Black" Direction="0" BlurRadius="10" Opacity="0.7" ShadowDepth="1"/>
</Border.Effect>
<StackPanel
Margin="5"
Orientation="Vertical">
<Button
Content="历史记录"
<Button
Name="MenuHistory"
Content="历史记录"
Template="{StaticResource MenuBtnTemplate}"
FontSize="12"
Margin="0,0,0,8"
/>
<Button
Name="MenuOpenAI"
Content="OpenAI"
FontSize="12"
Template="{StaticResource MenuBtnTemplate}"
Margin="0,0,0,8"
/>
<Button
Name="MenuAbout"
Content="关于"
FontSize="12"
Command="{Binding ClickAboutCommand}"
Expand All @@ -127,22 +131,39 @@
</StackPanel>
</Border>
</Popup>
<Button
<ToggleButton
IsThreeState="False"
Cursor="Hand"
Name="OpenSettingBtn"
Content="{Binding SettingBtnContent}"
Checked="OpenSettingBtn_Checked"
Unchecked="OpenSettingBtn_Checked"
HorizontalAlignment="Center"
FontSize="28"
Template="{StaticResource WindowControlButtomTemplate}"
Command="{Binding OpenOrCloseConfigCommand}"
CommandParameter="{Binding ElementName=ConfigGrid}"/>
Template="{StaticResource ToggleButtonTemplate}">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Content" Value="&#xe797;"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Content" Value="&#xe799;"/>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
<ToggleButton.Triggers>


</ToggleButton.Triggers>
</ToggleButton>
</Grid>
<Border
x:Name="ConfigBorder"
BorderBrush="LightGray"
BorderThickness="1"
Margin="5,0,5,5"
Height="{Binding ConfigGridHeight}"
Height="0"
Width="620">
<Grid
x:Name="ConfigGrid">
Expand Down
30 changes: 29 additions & 1 deletion Views/VisualChat.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.IO;
using VisualChatBot.Tools;
using Newtonsoft.Json;
using System.Windows.Media.Animation;

namespace VisualChatBot
{
Expand Down Expand Up @@ -183,7 +184,11 @@ private void MaxTokensTextbox_TextChanged(object sender, TextChangedEventArgs e)
File.WriteAllText(userConfigPath, jsonStr);
}
}

/// <summary>
/// 黑暗模式切换
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ModeSwitch_Click(object sender, RoutedEventArgs e)
{

Expand All @@ -197,6 +202,10 @@ private void ModeSwitch_Click(object sender, RoutedEventArgs e)
closeBtn.Foreground = Application.Current.Resources["ForegroundColor"] as SolidColorBrush;
MenuToggleBtn.Foreground = Application.Current.Resources["ForegroundColor"] as SolidColorBrush;
OpenSettingBtn.Foreground = Application.Current.Resources["ForegroundColor"] as SolidColorBrush;
sideMenu.Background = Application.Current.Resources["BackgroundColor"] as SolidColorBrush;
MenuHistory.Foreground = Application.Current.Resources["ForegroundColor"] as SolidColorBrush;
MenuOpenAI.Foreground = Application.Current.Resources["ForegroundColor"] as SolidColorBrush;
MenuAbout.Foreground = Application.Current.Resources["ForegroundColor"] as SolidColorBrush;
//AppBody
AppBody.Background = Application.Current.Resources["BackgroundColor"] as SolidColorBrush;
OutputBox.Background = Application.Current.Resources["TextBoxBackgroundColor"] as SolidColorBrush;
Expand All @@ -219,6 +228,10 @@ private void ModeSwitch_Click(object sender, RoutedEventArgs e)
closeBtn.Foreground = Application.Current.Resources["DarkForegroundColor"] as SolidColorBrush;
MenuToggleBtn.Foreground = Application.Current.Resources["DarkForegroundColor"] as SolidColorBrush;
OpenSettingBtn.Foreground = Application.Current.Resources["DarkForegroundColor"] as SolidColorBrush;
sideMenu.Background = Application.Current.Resources["DarkBackgroundColor"] as SolidColorBrush;
MenuHistory.Foreground = Application.Current.Resources["DarkForegroundColor"] as SolidColorBrush;
MenuOpenAI.Foreground = Application.Current.Resources["DarkForegroundColor"] as SolidColorBrush;
MenuAbout.Foreground = Application.Current.Resources["DarkForegroundColor"] as SolidColorBrush;
//AppBody
AppBody.Background = Application.Current.Resources["DarkBackgroundColor"] as SolidColorBrush;
OutputBox.Background = Application.Current.Resources["DarkTextBoxBackgroundColor"] as SolidColorBrush;
Expand All @@ -231,5 +244,20 @@ private void ModeSwitch_Click(object sender, RoutedEventArgs e)
SendBtn.Background = Application.Current.Resources["DarkButtonBackgroundColor"] as SolidColorBrush;
}
}

private void OpenSettingBtn_Checked(object sender, RoutedEventArgs e)
{
DoubleAnimation animation = new DoubleAnimation(0,60,TimeSpan.FromSeconds(0.2));
DoubleAnimation animation2 = new DoubleAnimation(60, 0, TimeSpan.FromSeconds(0.2));
if (OpenSettingBtn.IsChecked == true)
{
ConfigBorder.BeginAnimation(HeightProperty, animation);
}
else if(OpenSettingBtn.IsChecked == false)
{
ConfigBorder.BeginAnimation(HeightProperty, animation2);
}

}
}
}

0 comments on commit dd2da5c

Please sign in to comment.