Skip to content

Commit

Permalink
수동 장문 미리 입력 #86
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheric0210 committed Dec 14, 2023
1 parent 4a7af20 commit 344fe89
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
24 changes: 14 additions & 10 deletions AutoKkutuGui/Main.GameProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void OnPathUpdated(object? sender, PathUpdateEventArgs args)
}
}

private void TryAutoEnter(PathList list, bool usedPresearchResult = false)
private void TryAutoEnter(PathList list, bool flushPreinputPath = false)
{
if (!EntererManager.TryGetEnterer(AutoKkutu.Game, Preference.AutoEnterMode, out var enterer))
{
Expand All @@ -112,7 +112,7 @@ private void TryAutoEnter(PathList list, bool usedPresearchResult = false)
else
{
var param = list.Details;
if (usedPresearchResult)
if (flushPreinputPath)
param = param.WithoutFlags(PathFlags.PreSearch); // Fixme: 이런 번거로운 방법 대신 더 나은 방법 생각해보기

enterer.RequestSend(new EnterInfo(opt, param, bestPath.Object.Content));
Expand Down Expand Up @@ -194,10 +194,10 @@ private void OnTurnStarted(object? sender, TurnStartEventArgs args)
{
if (preSearch is PathList list)
{
if (list.Details.Condition.IsSimilar(args.Condition))
if (list.Details.Condition.IsSimilar(args.Condition)) // pre-search 해 놓은 검색 결과가 여전히 유효함! 미리 입력해 놓은 단어 그대로 써 먹을 수 있음.
{
Log.Debug("Using the pre-search result for: {condition}", list.Details.Condition);
TryAutoEnter(list, usedPresearchResult: true);
TryAutoEnter(list, flushPreinputPath: true);
return;
}

Expand Down Expand Up @@ -248,19 +248,23 @@ private void OnTurnEnded(object? sender, TurnEndEventArgs args)
goto presearchFail;
}

Log.Verbose("Performing pre-search on: {condition}", condition);
AutoKkutu.PathFinder.FindPath(
args.Session.GameMode,
new PathDetails((WordCondition)condition, SetupPathFinderFlags() | PathFlags.PreSearch, Preference.ReturnModeEnabled, Preference.MaxDisplayedWordCount),
Preference.ActiveWordPreference);

PerformPreSearchAndPreInput(args.Session.GameMode, (WordCondition)condition);
return;

presearchFail:
Log.Verbose("Pre-search result flushed.");
preSearch = null;
}

public void PerformPreSearchAndPreInput(GameMode gameMode, WordCondition condition)
{
Log.Verbose("Performing pre-search (+ pre-input) on: {condition}", condition);
AutoKkutu.PathFinder.FindPath(
gameMode,
new PathDetails(condition, SetupPathFinderFlags() | PathFlags.PreSearch, Preference.ReturnModeEnabled, Preference.MaxDisplayedWordCount),
Preference.ActiveWordPreference);
}

private void OnTypingWordPresented(object? sender, WordPresentEventArgs args)
{
var word = args.Word;
Expand Down
4 changes: 2 additions & 2 deletions AutoKkutuGui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Margin="10,10,0,0" VerticalAlignment="Bottom" Content="장문 미리 입력" FontFamily="/AutoKkutu;component/Resources/Font/#NanumBarunGothic" FontSize="20" Foreground="#FFFFFFFF" />
<Button Name="PreEnterButton" Grid.Row="1" Grid.Column="1" MinHeight="25" Margin="0,5,15,5" Click="SubmitSearch_Click" Content="검색" FontSize="14" Style="{StaticResource BaseButtonStyle}" />
<TextBox x:Name="PreEnterNodeField" Grid.Row="1" Grid.Column="0" Margin="15,5,0,5" KeyDown="SearchField_KeyDown" Style="{StaticResource BaseSearchBox}" />
<Button Name="PreEnterButton" Grid.Row="1" Grid.Column="1" MinHeight="25" Margin="0,5,15,5" Click="PreEnterButton_Click" Content="검색" FontSize="14" Style="{StaticResource BaseButtonStyle}" />
<TextBox x:Name="PreEnterNodeField" Grid.Row="1" Grid.Column="0" Margin="15,5,0,5" KeyDown="PreEnterNodeField_KeyDown" Style="{StaticResource BaseSearchBox}" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="15,0,0,0" Text="미리 입력할 장문 키워드">
<TextBlock.Style>
<Style BasedOn="{StaticResource BaseSearchBoxPlaceholder}" TargetType="TextBlock">
Expand Down
23 changes: 22 additions & 1 deletion AutoKkutuGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ private void SubmitSearch_Click(object? sender, RoutedEventArgs e)
default:
gameMode = mainInstance.AutoKkutu.Game.Session.GameMode;
break;

}

var missionChar = SearchMissionChar.Text;
Expand All @@ -464,4 +463,26 @@ private void SubmitSearch_Click(object? sender, RoutedEventArgs e)
SearchField.Text = "";
}
}

private void PreEnterNodeField_KeyDown(object? sender, KeyEventArgs e)
{
if (e.Key is Key.Enter or Key.Return)
PreEnterButton_Click(sender, e);
}

private void PreEnterButton_Click(object? sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(PreEnterNodeField.Text))
{
// TODO: 페이지가 아직 로드되지 않은 등, 입력할 수 없는 상황에서는 입력 필드 자체를 비활성화하던지 아니면 입력 시 오류를 띄우던지
mainInstance.PerformPreSearchAndPreInput(
mainInstance.AutoKkutu.Game.Session.GameMode,
new WordCondition(
PreEnterNodeField.Text,
missionChar: mainInstance.AutoKkutu.Game.Session.WordCondition.MissionChar
));

PreEnterNodeField.Text = "";
}
}
}

0 comments on commit 344fe89

Please sign in to comment.