Skip to content

Commit

Permalink
add new button
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceshi committed Oct 16, 2022
1 parent a012db4 commit c1dbbaf
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 17 deletions.
29 changes: 23 additions & 6 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,32 @@
</Grid>
</GroupBox>
</Grid>
<Button Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center"
Name="Start" Click="Start_Click">
开始游戏 (Start)
</Button>
<Grid Grid.Row="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Margin="16">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Registry_Click">
注册表 (Registry)
</Button>
<Button Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Click="Start_Click">
开始游戏 (Start)
</Button>
<Button Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"
Name="Start" Click="FAQ_Click">
常见问题 (FAQ)
</Button>
</Grid>
</Grid>
<TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="10">
<Hyperlink Cursor="Hand" NavigateUri="https://github.com/peaceshi/Wind3/"
<Hyperlink Name="CheckUpdateLink" Cursor="Hand"
NavigateUri="https://github.com/peaceshi/Wind3/"
RequestNavigate="Hyperlink_RequestNavigate">
<Run Text=" V2.1" />
<Run Text="更新 (Update)" />
</Hyperlink>
</TextBlock>
</Grid>
Expand Down
61 changes: 50 additions & 11 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows.Navigation;

using WindConfig.Model;
using WindConfig.View;

namespace WindConfig;

Expand All @@ -20,35 +21,44 @@ public MainWindow(string title, string processName)

private void Resolution_RadioButton1_Checked(object sender, RoutedEventArgs e)
{
WindRegistry.CreationWidth = 800;
WindRegistry.CreationHeight = 600;
if (ProcessName?.Length != 0)
{
WindRegistry.CreationWidth = 800;
WindRegistry.CreationHeight = 600;
}
}

private void Resolution_RadioButton2_Checked(object sender, RoutedEventArgs e)
{
WindRegistry.CreationWidth = 1024;
WindRegistry.CreationHeight = 768;
if (ProcessName?.Length != 0)
{
WindRegistry.CreationWidth = 1024;
WindRegistry.CreationHeight = 768;
}
}

private void Window_WindowMode_Checked(object sender, RoutedEventArgs e)
{
WindRegistry.IsFullscreen = 0;
if (ProcessName?.Length != 0)
{
WindRegistry.IsFullscreen = 0;
}
}

private void Window_FullScreenMode_Checked(object sender, RoutedEventArgs e)
{
WindRegistry.IsFullscreen = 1;
if (ProcessName?.Length != 0)
{
WindRegistry.IsFullscreen = 1;
}
}

private void Start_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult CustomResolutionResult = MessageBoxResult.Cancel;
if (CustomResolution.IsEnabled)
{
const string caption = "警告 (Warning)";
const string message = "自定义分辨率可能产生预期之外的错误. 甚至损坏你的硬件.\nCustom resolutions can produce unexpected errors. Even damage your hardware.";
const MessageBoxResult defaultResult = MessageBoxResult.Cancel;
CustomResolutionResult = MessageBox.Show(message, caption, MessageBoxButton.OKCancel, MessageBoxImage.Warning, defaultResult);
CustomResolutionResult = Wind.ShowCustomResolutionWarningMessage();
}
//1. File must exists.
//2. File exists with IsCustomResolution == true. CustomResolutionResult == MessageBoxResult.OK must be IsCustomResolution == true.
Expand All @@ -73,7 +83,7 @@ private void Start_Click(object sender, RoutedEventArgs e)
// if CustomResolutionResult is MessageBoxResult.Cancel, nothing needs to do.
else if (!File.Exists(ProcessName))
{
MessageBox.Show($"未找到 {ProcessName} \n Can not find {ProcessName}", "警告 (Warning)");
Wind.ShowProcessNotFoundWarningMessage(ProcessName);
}
}

Expand All @@ -82,4 +92,33 @@ private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}

private void Registry_Click(object sender, RoutedEventArgs e)
{
if (ProcessName?.Length == 0)
{
Wind.ShowProcessNotFoundWarningMessage(ProcessName);
}
else
{
WindRegistry.LastKey = WindRegistry.WindKey;
using Process Regedit = new();
{
Regedit.StartInfo.FileName = "regedit";
Regedit.StartInfo.UseShellExecute = true;
Regedit.StartInfo.Verb = "runas";
Regedit.Start();
}
}
}

private void FAQ_Click(object sender, RoutedEventArgs e)
{
Window FAQ = new FAQ()
{
Owner = this
};

FAQ.ShowDialog();
}
}
27 changes: 27 additions & 0 deletions Model/Wind.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;

using Windows.Win32;
using Windows.Win32.Foundation;

using static Windows.Win32.UI.WindowsAndMessaging.SET_WINDOW_POS_FLAGS;

using MessageBox = System.Windows.MessageBox;
using Point = System.Drawing.Point;

namespace WindConfig.Model;

public static class Wind
Expand All @@ -18,6 +22,9 @@ public static class Wind
public const string Wind4RegistryKeyName = "Wind4";
public const string Wind3ConfigTitleName = "风色幻想3 配置向导";
public const string Wind4ConfigTitleName = "风色幻想4 配置向导";
public const string DefaultConfigTitleName = "WindConfig";
public const int Wind3Version = 211;
public const int Wind4Version = 110;

public static void SetWindowPosToCenter(Process process)
{
Expand All @@ -33,4 +40,24 @@ public static void SetWindowPosToCenter(Process process)
Point point = new(screen.Left + (screen.Width / 2) - ((rect.right - rect.left) / 2), screen.Top + (screen.Height / 2) - ((rect.bottom - rect.top) / 2));
PInvoke.SetWindowPos(hWnd, (HWND)IntPtr.Zero, point.X, point.Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
}

public static MessageBoxResult ShowProcessNotFoundWarningMessage(string? ProcessName)
{
if (ProcessName?.Length == 0)
{
return MessageBox.Show("未找到游戏 \nCan not find game", "警告 (Warning)", MessageBoxButton.OK, MessageBoxImage.Warning);
}
else
{
return MessageBox.Show($"未找到 {ProcessName} \nCan not find {ProcessName}", "警告 (Warning)", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}

public static MessageBoxResult ShowCustomResolutionWarningMessage()
{
const string caption = "警告 (Warning)";
const string message = "自定义分辨率可能产生预期之外的错误. 甚至损坏你的硬件.\nCustom resolutions can produce unexpected errors. Even damage your hardware.";
const MessageBoxResult defaultResult = MessageBoxResult.Cancel;
return MessageBox.Show(message, caption, MessageBoxButton.OKCancel, MessageBoxImage.Warning, defaultResult);
}
}

0 comments on commit c1dbbaf

Please sign in to comment.