Skip to content

Commit

Permalink
增加一个全局配置的按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinyuell committed Oct 9, 2021
1 parent 3f4618a commit 43b40bb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion DspFindSeed/DspSearchSeed.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<TextBox x:Name="searchOnceCount" HorizontalAlignment="Left" Height="23" Margin="204,12,0,0" TextWrapping="Wrap" Text="1000" VerticalAlignment="Top" Width="51" AutomationProperties.Name="searchOnceCount"/>
<Label Content="总次数" HorizontalAlignment="Left" Margin="260,12,0,0" VerticalAlignment="Top" FontWeight="Bold" RenderTransformOrigin="-0.804,0.44" Height="25" Width="46"/>
<TextBox x:Name="searchTimes" HorizontalAlignment="Left" Height="23" Margin="306,12,0,0" TextWrapping="Wrap" Text="100" VerticalAlignment="Top" Width="52" RenderTransformOrigin="-0.26,0.678" AutomationProperties.Name="searchTimes"/>
<Label Content="从输入的种子ID搜索,单次搜索10000,代表一次自增搜一万个种子,然后会打印一次时间。" HorizontalAlignment="Left" Margin="10,44,0,0" VerticalAlignment="Top" Width="486" Height="25" FontSize="9" FontStyle="Italic"/>
<Label Content="从输入的种子ID搜索,单次搜索10000,代表一次自增搜一万个种子,然后会打印一次时间。" HorizontalAlignment="Left" Margin="10,44,0,0" VerticalAlignment="Top" Width="374" Height="25" FontSize="9" FontStyle="Italic"/>
<Label Content="筛选条件" HorizontalAlignment="Left" Margin="16,69,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.092,0.413" FontWeight="Bold" Height="25" Width="58"/>
<Label Content="必须条件都满足的种子才会记录&#xA;仅记录条件会将参数写入文件,但不满足不影响筛选&#xA;磁石总量、蓝巨星、0恒星数量是整个宇宙的条件,如果添值是独立的必须条件(始终会记录)" HorizontalAlignment="Left" Margin="87,69,0,0" VerticalAlignment="Top" Width="446" FontSize="10" FontStyle="Italic" Height="48"/>
<Label Content="卫星数" HorizontalAlignment="Left" Margin="16,151,0,0" VerticalAlignment="Top" Height="25" Width="46"/>
Expand Down Expand Up @@ -273,5 +273,6 @@
</ComboBox>
<ComboBox x:Name="SearchMaxStarCount" HorizontalAlignment="Left" Margin="493,12,0,0" VerticalAlignment="Top" Width="55" RenderTransformOrigin="0.503,0.556" Height="23"/>
<Label Content="" HorizontalAlignment="Left" Margin="475,12,0,0" VerticalAlignment="Top" Height="23" Width="18" FontSize="8"/>
<Button x:Name="ConfigSave" Content="保存默认配置" Click="Button_Click_ConfigSave" HorizontalAlignment="Left" Margin="370,413,0,0" VerticalAlignment="Top" Width="96" Height="19" ToolTip="全局数据:恒星数、磁石数量等,保存为默认配置,覆盖本地目的config.json文件"/>
</Grid>
</Window>
42 changes: 41 additions & 1 deletion DspFindSeed/DspSearchSeed.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using DysonSphereProgramSeed.Dyson;
using Newtonsoft.Json;


namespace DspFindSeed
Expand Down Expand Up @@ -101,6 +103,28 @@ public void Reset ()
}
}

public class SearchConfig
{
/// <summary>
/// 磁石数量要求
/// </summary>
public int magCount = 0;
/// <summary>
/// 蓝巨星数量要求
/// </summary>
public int bluePlanetCount = 0;
/// <summary>
/// O恒星数量
/// </summary>
public int oPlanetCount = 0;

public int curMinSearchStarSelectIndex = 32;
public int curMaxSearchSelectIndex = 32;

public int onceCount = 1000;
public int times = 100;
}

public class JsonCondition
{
public List<SearchCondition> searchNecessaryConditions = new List<SearchCondition>();
Expand All @@ -116,6 +140,7 @@ public partial class MainWindow
public List<SearchCondition> searchNecessaryConditions = new List<SearchCondition> ();
public List<SearchCondition> searchLogConditions = new List<SearchCondition> ();
public SearchCondition minConditions = new SearchCondition ();
public SearchConfig searchConfig = new SearchConfig();
/// <summary>
/// 自定义搜索ID
/// </summary>
Expand All @@ -141,7 +166,7 @@ public partial class MainWindow
private int curMaxSearchStarCount = 64;
private DateTime startTime;
int onceCount = 1000;
int times = 10;
int times = 100;
public int curSeeds;
public int lastSeedId;
public Thread curThread;
Expand All @@ -150,6 +175,7 @@ public partial class MainWindow
private string searchlogContent = "";
private float processValue = 0;


private Dictionary<string, int> AllPlanetNameDictionary = new Dictionary<string, int>()
{
{"无要求", 0},
Expand Down Expand Up @@ -205,6 +231,20 @@ public MainWindow ()
SearchMinStarCount.Items.Add(i);
SearchMaxStarCount.Items.Add(i);
}

if (!File.Exists(saveConditionPath + "\\config.json"))
return;
string text = File.ReadAllText(saveConditionPath + "\\config.json");
if (string.IsNullOrEmpty(text))
return;
searchConfig = JsonConvert.DeserializeObject<SearchConfig>(text);
searchTimes.Text = searchConfig.times.ToString();
searchOnceCount.Text = searchConfig.onceCount.ToString();
MagCount.Text = searchConfig.magCount.ToString();
BluePlanetCount.Text = searchConfig.bluePlanetCount.ToString();
OPlanetCount.Text = searchConfig.oPlanetCount.ToString();
SearchMinStarCount.SelectedIndex = searchConfig.curMinSearchStarSelectIndex;
SearchMaxStarCount.SelectedIndex = searchConfig.curMaxSearchSelectIndex;
}

void ResetMinCondition ()
Expand Down
14 changes: 14 additions & 0 deletions DspFindSeed/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ private void Button_Click_ImportSeedFile (object sender, System.Windows.RoutedEv
}
}

private void Button_Click_ConfigSave(object sender, System.Windows.RoutedEventArgs e)
{
searchConfig.times = int.Parse (searchTimes.Text);
searchConfig.onceCount = int.Parse (searchOnceCount.Text);
searchConfig.magCount = int.Parse(MagCount.Text);
searchConfig.bluePlanetCount = int.Parse (BluePlanetCount.Text);
searchConfig.oPlanetCount = int.Parse (OPlanetCount.Text);
searchConfig.curMinSearchStarSelectIndex = SearchMinStarCount.SelectedIndex;
searchConfig.curMaxSearchSelectIndex = SearchMaxStarCount.SelectedIndex;
string text = JsonConvert.SerializeObject(searchConfig);
System.IO.File.WriteAllText(saveConditionPath + "\\config.json", text, Encoding.UTF8);
MessageBox.Show("保存成功,下次打开会继承当前搜索的全局的配置,包括单次搜索数量、搜索次数、恒星数区间、磁石、蓝巨、0型数量", "成功", MessageBoxButtons.OKCancel);
}

private void Button_Click_Stop (object sender, System.Windows.RoutedEventArgs e)
{
if (curThread == null || curThread.ThreadState == ThreadState.Aborted || curThread.ThreadState == ThreadState.Stopped)
Expand Down

0 comments on commit 43b40bb

Please sign in to comment.