支持保存&写入区域设置

This commit is contained in:
YukkuriC 2023-09-05 23:33:08 +08:00 committed by ZouJin
parent e6051e04f5
commit 35aba15a5d
4 changed files with 87 additions and 20 deletions

View File

@ -430,5 +430,44 @@ namespace VPet_Simulator.Windows.Interface
this["gameconfig"].SetBool("autobuy", value);
}
}
public bool MoveAreaDefault
{
get
{
var line = FindLine("movearea");
if (line == null)
return true;
return line.GetBool("set");
}
set
{
var line = FindorAddLine("movearea");
line.SetBool("set", value);
}
}
public System.Drawing.Rectangle MoveArea
{
get
{
var line = FindLine("movearea");
if (line == null)
return default(System.Drawing.Rectangle);
return new System.Drawing.Rectangle(
line.GetInt("x", 0),
line.GetInt("y", 0),
line.GetInt("w", 114),
line.GetInt("h", 514)
);
}
set
{
var line = FindorAddLine("movearea");
line.SetInt("x", value.X);
line.SetInt("y", value.Y);
line.SetInt("w", value.Width);
line.SetInt("h", value.Height);
}
}
}
}

View File

@ -14,18 +14,25 @@ namespace VPet_Simulator.Windows
public MWController(MainWindow mw)
{
this.mw = mw;
_isPrimaryScreen = mw.Set.MoveAreaDefault;
_screenBorder = mw.Set.MoveArea;
}
private static Rectangle _screenBorder;
private static bool _isPrimaryScreen = true;
public static bool IsPrimaryScreen
private Rectangle _screenBorder;
private bool _isPrimaryScreen = true;
public bool IsPrimaryScreen
{
get
{
return _isPrimaryScreen;
}
private set
{
_isPrimaryScreen = value;
mw.Set.MoveAreaDefault = value;
}
}
public static Rectangle ScreenBorder
public Rectangle ScreenBorder
{
get
{
@ -34,12 +41,13 @@ namespace VPet_Simulator.Windows
set
{
_screenBorder = value;
_isPrimaryScreen = false;
mw.Set.MoveArea = value;
IsPrimaryScreen = false;
}
}
public static void ResetScreenBorder()
public void ResetScreenBorder()
{
_isPrimaryScreen = true;
IsPrimaryScreen = true;
}
public double GetWindowsDistanceLeft()

View File

@ -504,17 +504,17 @@
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{ll:Str '当前区域:'}"/>
<TextBlock Grid.Column="1" Grid.ColumnSpan="2" Text="{ll:Str '主屏幕'}"/>
<Button x:Name="BtnSetScreen_Default" Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" Padding="1"
<TextBlock x:Name="textMoveArea" Grid.Column="1" Grid.ColumnSpan="2" Text="{ll:Str '主屏幕'}"/>
<Button x:Name="BtnSetMoveArea_Default" Grid.Row="1" Grid.Column="0" Margin="5,5,5,5" Padding="1"
pu:ButtonHelper.CornerRadius="4" Background="{DynamicResource SecondaryLight}"
Click="BtnSetScreen_Default_Click" Content="{ll:Str 重置为主屏}"/>
<Button x:Name="BtnSetScreen_DetectScreen" Grid.Row="1" Grid.Column="1" Margin="5,5,5,5" Padding="1"
Click="BtnSetMoveArea_Default_Click" Content="{ll:Str 重置为主屏}"/>
<Button x:Name="BtnSetMoveArea_DetectScreen" Grid.Row="1" Grid.Column="1" Margin="5,5,5,5" Padding="1"
pu:ButtonHelper.CornerRadius="4" Background="{DynamicResource SecondaryLight}"
Click="BtnSetScreen_DetectScreen_Click" Content="{ll:Str 设为桌宠屏幕}"
Click="BtnSetMoveArea_DetectScreen_Click" Content="{ll:Str 设为桌宠屏幕}"
ToolTip="{ll:Str 当屏幕分辨率不为100%时可能识别有误}"/>
<Button x:Name="BtnSetScreen_Window" Grid.Row="1" Grid.Column="2" Margin="5,5,5,5" Padding="1"
<Button x:Name="BtnSetMoveArea_Window" Grid.Row="1" Grid.Column="2" Margin="5,5,5,5" Padding="1"
pu:ButtonHelper.CornerRadius="4" Background="{DynamicResource SecondaryLight}"
Click="BtnSetScreen_Window_Click" Content="{ll:Str 设为窗口范围}">
Click="BtnSetMoveArea_Window_Click" Content="{ll:Str 设为窗口范围}">
<Button.ToolTip>
<TextBlock>
<TextBlock Text="{ll:Str 使用设置窗口框选范围后点击}"/>

View File

@ -212,6 +212,8 @@ namespace VPet_Simulator.Windows
voicetimer.Tick += Voicetimer_Tick;
AllowChange = true;
UpdateMoveAreaText();
}
private void Voicetimer_Tick(object sender, EventArgs e)
@ -615,24 +617,42 @@ namespace VPet_Simulator.Windows
}
}
private void BtnSetScreen_Default_Click(object sender, RoutedEventArgs e)
private void UpdateMoveAreaText()
{
MWController.ResetScreenBorder();
var mwCtrl = mw.Core.Controller as MWController;
if (mwCtrl.IsPrimaryScreen)
{
textMoveArea.Text = "主屏幕".Translate();
return;
}
var rect = mwCtrl.ScreenBorder;
textMoveArea.Text = $"X:{rect.X};Y:{rect.Y};W:{rect.Width};H:{rect.Height}";
}
private void BtnSetScreen_DetectScreen_Click(object sender, RoutedEventArgs e)
private void BtnSetMoveArea_Default_Click(object sender, RoutedEventArgs e)
{
var mwCtrl = mw.Core.Controller as MWController;
mwCtrl.ResetScreenBorder();
UpdateMoveAreaText();
}
private void BtnSetMoveArea_DetectScreen_Click(object sender, RoutedEventArgs e)
{
var windowInteropHelper = new System.Windows.Interop.WindowInteropHelper(mw);
var currentScreen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
MWController.ScreenBorder = currentScreen.Bounds;
var mwCtrl = mw.Core.Controller as MWController;
mwCtrl.ScreenBorder = currentScreen.Bounds;
UpdateMoveAreaText();
}
private void BtnSetScreen_Window_Click(object sender, RoutedEventArgs e)
private void BtnSetMoveArea_Window_Click(object sender, RoutedEventArgs e)
{
MWController.ScreenBorder = new System.Drawing.Rectangle(
var mwCtrl = mw.Core.Controller as MWController;
mwCtrl.ScreenBorder = new System.Drawing.Rectangle(
(int)Left, (int)Top,
(int)Width, (int)Height
);
UpdateMoveAreaText();
}
private void hyper_moreInfo(object sender, RoutedEventArgs e)