Skip to content

Commit

Permalink
Radar now gives focus back to the game window ASAP
Browse files Browse the repository at this point in the history
  • Loading branch information
tapahob committed Jul 20, 2022
1 parent 9639b1c commit 34f8662
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class Configuration
public static string FontSize3Small { get; set; }

private static Dictionary<String, String> storedConfig = new Dictionary<string, string>();
public const string Version = "2.0.4.5";
public const string Version = "2.0.4.7";

public static void Init()
{
Expand Down
2 changes: 1 addition & 1 deletion WPFFrontend/EnemyControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
x:Class="WPFFrontend.EnemyControl"
mc:Ignorable="d"
Height="Auto" Width="450"
Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="3" VerticalAlignment="Center">
Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="3" VerticalAlignment="Center" MouseUp="UserControl_MouseUp" MouseLeave="UserControl_MouseLeave">
<UserControl.BorderBrush>
<ImageBrush/>
</UserControl.BorderBrush>
Expand Down
20 changes: 19 additions & 1 deletion WPFFrontend/EnemyControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ private void init(BGEntity bgEntity, MainWindow mainWindow)
//Canvas.SetTop(this, y / 2);
Canvas.SetLeft(this, left);
this.MouseRightButtonUp += EnemyControl_MouseRightButtonDown;
WinApiBindings.WinAPIBindings.SetForegroundWindow(Configuration.HWndPtr);
WinApiBindings.WinAPIBindings.SetFocus(Configuration.HWndPtr);
Logger.Debug($"Create Enemy Control for {bgEntity?.Name1}: Done");
} catch (Exception ex)
{
Expand Down Expand Up @@ -114,7 +116,9 @@ public void Label_MouseDown(object sender, MouseButtonEventArgs e)
(this.Parent as Canvas)?.Children.Remove(this);
};
anim.FillBehavior = FillBehavior.HoldEnd;
this.BeginAnimation(System.Windows.Controls.UserControl.MarginProperty, anim, HandoffBehavior.SnapshotAndReplace);
this.BeginAnimation(System.Windows.Controls.UserControl.MarginProperty, anim, HandoffBehavior.SnapshotAndReplace);
WinApiBindings.WinAPIBindings.SetForegroundWindow(Configuration.HWndPtr);
WinApiBindings.WinAPIBindings.SetFocus(Configuration.HWndPtr);
}

internal void updateView(BGEntity item)
Expand Down Expand Up @@ -210,5 +214,19 @@ internal void updateView(BGEntity item)
}

}

private void UserControl_MouseLeave(object sender, MouseEventArgs e)
{
if (WinApiBindings.WinAPIBindings.GetForegroundWindow() != Configuration.HWndPtr)
{
WinApiBindings.WinAPIBindings.SetForegroundWindow(Configuration.HWndPtr);
WinApiBindings.WinAPIBindings.SetFocus(Configuration.HWndPtr);
}
}

private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
{
UserControl_MouseLeave(null, null);
}
}
}
2 changes: 2 additions & 0 deletions WPFFrontend/OptionsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ private void OptionsControl_MouseUp(object sender, MouseButtonEventArgs e)
};
anim.FillBehavior = FillBehavior.HoldEnd;
this.BeginAnimation(UserControl.MarginProperty, anim, HandoffBehavior.SnapshotAndReplace);
WinApiBindings.WinAPIBindings.SetForegroundWindow(Configuration.HWndPtr);
WinApiBindings.WinAPIBindings.SetFocus(Configuration.HWndPtr);
}

private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
Expand Down
9 changes: 8 additions & 1 deletion WinAPIBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,14 @@ public enum ShowWindowCommands : uint

[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);


[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[Flags]
public enum WindowStyles : uint
{
Expand Down

0 comments on commit 34f8662

Please sign in to comment.