chore: 猫猫改为全局

This commit is contained in:
uye
2025-02-26 14:35:47 +08:00
parent 96941913ff
commit 3f26ed79d2
4 changed files with 128 additions and 107 deletions

View File

@@ -899,8 +899,11 @@ namespace MaaWpfGui.Main
if (DateTime.UtcNow.ToYjDate().IsAprilFoolsDay())
{
Instances.TaskQueueViewModel.GifVisibility = true;
Instances.TaskQueueViewModel.ChangeGif();
if (Application.Current.MainWindow?.DataContext is RootViewModel rvm)
{
rvm.GifVisibility = true;
rvm.ChangeGif();
}
}
// Instances.TaskQueueViewModel.CheckAndShutdown();

View File

@@ -11,9 +11,13 @@
// but WITHOUT ANY WARRANTY
// </copyright>
#nullable enable
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using HandyControl.Tools;
using MaaWpfGui.Constants;
@@ -175,9 +179,9 @@ namespace MaaWpfGui.ViewModels.UI
}
}
private Brush _windowTopMostButtonForeground = (SolidColorBrush)Application.Current.FindResource("PrimaryTextBrush");
private Brush? _windowTopMostButtonForeground = (SolidColorBrush?)Application.Current.FindResource("PrimaryTextBrush");
public Brush WindowTopMostButtonForeground
public Brush? WindowTopMostButtonForeground
{
get => _windowTopMostButtonForeground;
set => SetAndNotify(ref _windowTopMostButtonForeground, value);
@@ -189,8 +193,8 @@ namespace MaaWpfGui.ViewModels.UI
{
IsWindowTopMost = !IsWindowTopMost;
WindowTopMostButtonForeground = IsWindowTopMost
? (Brush)Application.Current.FindResource("TitleBrush")
: (Brush)Application.Current.FindResource("PrimaryTextBrush");
? (Brush?)Application.Current.FindResource("TitleBrush")
: (Brush?)Application.Current.FindResource("PrimaryTextBrush");
}
/// <inheritdoc/>
@@ -198,5 +202,91 @@ namespace MaaWpfGui.ViewModels.UI
{
Bootstrapper.Shutdown();
}
private static readonly string[] _gitList =
[
"/Res/Img/EasterEgg/1.gif",
"/Res/Img/EasterEgg/2.gif",
];
private static int _gifIndex = -1;
private static string? _gifPath = null;
public string? GifPath
{
get => _gifPath;
set => SetAndNotify(ref _gifPath, value);
}
private bool _gifVisibility = true;
public bool GifVisibility
{
get => _gifVisibility;
set => SetAndNotify(ref _gifVisibility, value);
}
// ReSharper disable once UnusedMember.Global
public void ChangeGif()
{
if (++_gifIndex >= _gitList.Length)
{
_gifIndex = 0;
}
GifPath = _gitList[_gifIndex];
}
private static bool _isDragging = false;
private static Point _offset;
// ReSharper disable once UnusedMember.Global
public void DraggableElementMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender is not HandyControl.Controls.GifImage childElement)
{
return;
}
_isDragging = true;
_offset = e.GetPosition(childElement);
childElement.CaptureMouse();
}
// ReSharper disable once UnusedMember.Global
public void DraggableElementMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (sender is not HandyControl.Controls.GifImage childElement)
{
return;
}
_isDragging = false;
childElement.ReleaseMouseCapture();
}
// ReSharper disable once UnusedMember.Global
public void DraggableElementMouseMove(object sender, MouseEventArgs e)
{
if (!_isDragging || sender is not HandyControl.Controls.GifImage { Parent: Grid parentElement } childElement)
{
return;
}
Point currentPosition = e.GetPosition(parentElement);
// 计算偏移量
double newX = currentPosition.X - _offset.X;
double newY = currentPosition.Y - _offset.Y;
// 确保元素在父元素范围内
newX = Math.Max(10, Math.Min(newX, parentElement.ActualWidth - childElement.ActualWidth - 10));
newY = Math.Max(10, Math.Min(newY, parentElement.ActualHeight - childElement.ActualHeight - 10));
childElement.HorizontalAlignment = HorizontalAlignment.Left;
childElement.VerticalAlignment = VerticalAlignment.Top;
childElement.Margin = new(newX, newY, 10, 10);
}
}
}

View File

@@ -2247,90 +2247,5 @@ namespace MaaWpfGui.ViewModels.UI
instance.ProcSubTaskMsg(msg, details);
}
}
private static readonly string[] _gitList =
[
"/Res/Img/EasterEgg/1.gif",
"/Res/Img/EasterEgg/2.gif",
];
private static int _gifIndex = -1;
private static string _gifPath = null;
public string GifPath
{
get => _gifPath;
set => SetAndNotify(ref _gifPath, value);
}
private bool _gifVisibility = false;
public bool GifVisibility
{
get => _gifVisibility;
set => SetAndNotify(ref _gifVisibility, value);
}
// ReSharper disable once UnusedMember.Global
public void ChangeGif()
{
if (++_gifIndex >= _gitList.Length)
{
_gifIndex = 0;
}
GifPath = _gitList[_gifIndex];
}
private static bool _isDragging = false;
private static Point _offset;
// ReSharper disable once UnusedMember.Global
public void DraggableElementMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender is not HandyControl.Controls.GifImage childElement)
{
return;
}
_isDragging = true;
_offset = e.GetPosition(childElement);
childElement.CaptureMouse();
}
public void DraggableElementMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (sender is not HandyControl.Controls.GifImage childElement)
{
return;
}
_isDragging = false;
childElement.ReleaseMouseCapture();
}
// ReSharper disable once UnusedMember.Global
public void DraggableElementMouseMove(object sender, MouseEventArgs e)
{
if (!_isDragging || sender is not HandyControl.Controls.GifImage { Parent: Grid parentElement } childElement)
{
return;
}
Point currentPosition = e.GetPosition(parentElement);
// 计算偏移量
double newX = currentPosition.X - _offset.X;
double newY = currentPosition.Y - _offset.Y;
// 确保元素在父元素范围内
newX = Math.Max(0, Math.Min(newX, parentElement.ActualWidth - childElement.ActualWidth - 10));
newY = Math.Max(0, Math.Min(newY, parentElement.ActualHeight - childElement.ActualHeight - 10));
childElement.HorizontalAlignment = HorizontalAlignment.Left;
childElement.VerticalAlignment = VerticalAlignment.Top;
childElement.Margin = new(newX, newY, 0, 0);
}
}
}

View File

@@ -53,22 +53,35 @@
</hc:Window.NonClientAreaContent>
<DockPanel>
<local:NotifyIcon x:Name="NotifyIcon" Visibility="Hidden" />
<TabControl
BorderThickness="0,1,0,0"
DisplayMemberPath="DisplayName"
ItemsSource="{Binding Items}"
SelectedItem="{s:RethrowingBinding ActiveItem}"
Style="{StaticResource TabControlInLine}">
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
s:View.Model="{Binding}"
IsTabStop="False" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
<Grid>
<TabControl
BorderThickness="0,1,0,0"
DisplayMemberPath="DisplayName"
ItemsSource="{Binding Items}"
SelectedItem="{s:RethrowingBinding ActiveItem}"
Style="{StaticResource TabControlInLine}">
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
s:View.Model="{Binding}"
IsTabStop="False" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
<hc:GifImage
Width="100"
Margin="10"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
MouseLeftButtonDown="{s:Action DraggableElementMouseLeftButtonDown}"
MouseLeftButtonUp="{s:Action DraggableElementMouseLeftButtonUp}"
MouseMove="{s:Action DraggableElementMouseMove}"
MouseRightButtonDown="{s:Action ChangeGif}"
Uri="{Binding GifPath}"
Visibility="{c:Binding GifVisibility}" />
</Grid>
</DockPanel>
<hc:Interaction.Behaviors>
<hc:TaskbarRebuildBehavior Element="{Binding ElementName=NotifyIcon}" />