Skip to content

Commit

Permalink
Feature - Improved Context Menus! V. 5.2.0.2 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
tsgsOFFICIAL committed Nov 15, 2024
1 parent 20de39e commit c4eac90
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 244 deletions.
8 changes: 7 additions & 1 deletion CS2-AutoAccept/CS2-AutoAccept.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Description>A program to automatically find and press "ACCEPT" for you, when entering a competitive match in CS2.</Description>
<Copyright>©️ tsgsOFFICIAL - 2024</Copyright>
<FileVersion>5.2.0.1</FileVersion>
<FileVersion>5.2.0.2</FileVersion>
<AssemblyName>CS2-AutoAccept</AssemblyName>
</PropertyGroup>

Expand All @@ -26,7 +26,10 @@
<ItemGroup>
<None Remove="background.png" />
<None Remove="Discord white.png" />
<None Remove="discord.png" />
<None Remove="github.png" />
<None Remove="logo.png" />
<None Remove="tsgs.png" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -569,7 +572,10 @@
<ItemGroup>
<Resource Include="background.png" />
<Resource Include="Discord white.png" />
<Resource Include="discord.png" />
<Resource Include="github.png" />
<Resource Include="logo.png" />
<Resource Include="tsgs.png" />
</ItemGroup>

<ItemGroup>
Expand Down
119 changes: 117 additions & 2 deletions CS2-AutoAccept/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@

<StackPanel Orientation="Horizontal">
<CheckBox x:Name="Program_state" Content="AutoAccept (OFF)" ToolTip="Will find the ACCEPT button, only for the current match" IsChecked="False" Foreground="Red" FontWeight="Bold" Checked="Program_state_Checked" Unchecked="Program_state_Unchecked"/>

<!-- TextBlock to show current hotkey -->
<TextBlock x:Name="CurrentHotkeyText" Text="Hotkey: None" VerticalAlignment="Bottom" Margin="10, 0, 0, 0" Foreground="GhostWhite"/>

Expand Down Expand Up @@ -219,8 +219,123 @@
<tb:TaskbarIcon x:Name="MyNotifyIcon" IconSource="/logo.png" ToolTipText="CS2 AutoAccept by tsgsOFFICIAL" DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}}" Visibility="Collapsed">
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Minimize" Command="{Binding ToggleWindowCommand }" />
<!--MenuItem with centered icon and text-->
<MenuItem Header="CS2 AutoAccept" IsEnabled="False" Foreground="LightGray">
<MenuItem.Icon>
<Canvas Width="24" Height="24" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="/tsgs.png" Width="24" Height="24" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="6, 0"/>
</Canvas>
</MenuItem.Icon>
</MenuItem>

<Separator Margin="0"/>

<MenuItem x:Name="StartCS2" Header="Start CS2" Command="{Binding StartCS2Command}">
<MenuItem.Icon>
<Canvas Width="24" Height="24" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="/logo.png" Width="24" Height="24" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="6, 0"/>
</Canvas>
</MenuItem.Icon>
</MenuItem>

<MenuItem x:Name="JoinDiscord" Header="Join Discord" Command="{Binding JoinDiscordCommand}">
<MenuItem.Icon>
<Canvas Width="24" Height="24" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="/discord.png" Width="24" Height="24" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="6, 0"/>
</Canvas>
</MenuItem.Icon>
</MenuItem>

<MenuItem x:Name="OpenGithub" Header="Open Github" Command="{Binding OpenGithubCommand}">
<MenuItem.Icon>
<Canvas Width="24" Height="24" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="/github.png" Width="24" Height="24" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="6, 0"/>
</Canvas>
</MenuItem.Icon>
</MenuItem>

<MenuItem x:Name="MinimizeAndRestore" Header="Minimize" Command="{Binding ToggleWindowCommand}" />
<MenuItem Header="Exit" Command="{Binding CloseCommand}" />

<!--Define a style for the ContextMenu-->
<ContextMenu.Resources>
<!--Set background and foreground colors for MenuItems-->
<Style TargetType="MenuItem">
<Setter Property="Background" Value="#353535"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontFamily" Value="Roboto"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Padding" Value="10, 6"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Margin" Value="0,1,0,1"/>

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Border x:Name="templateRoot" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true">
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ContentPresenter x:Name="Icon" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Width="16" Margin="2,5,5,5" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
<ContentPresenter ContentSource="Header" Grid.Column="1" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Icon" Value="{x:Null}">
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter Property="Background" TargetName="templateRoot" Value="#999999"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="LightGray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!--Style for the ContextMenu itself-->
<Style TargetType="ContextMenu">
<Setter Property="Background" Value="#353535"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContextMenu">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="6"
SnapsToDevicePixels="True"
Padding="10">

<Grid>
<ItemsPresenter/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!--Style for separators-->
<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="Separator">
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Separator}">
<Border Height="1" Margin="4,4,4,0" Background="LightGray" HorizontalAlignment="Stretch"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ContextMenu.Resources>
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>
Expand Down
13 changes: 11 additions & 2 deletions CS2-AutoAccept/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public partial class MainWindow : Window
private readonly bool debugMode = false;
public ICommand ToggleWindowCommand { get; }
public ICommand CloseCommand { get; }
public ICommand OpenGithubCommand { get; }
public ICommand JoinDiscordCommand { get; }
public ICommand StartCS2Command { get; }
private bool _isTrayIconVisible;
public bool IsTrayIconVisible
{
Expand All @@ -89,6 +92,9 @@ public MainWindow()

ToggleWindowCommand = new RelayCommand(o => ToggleWindowState());
CloseCommand = new RelayCommand(o => CloseApplication());
OpenGithubCommand = new RelayCommand(o => LaunchWeb("https://github.com/tsgsOFFICIAL/CS2-AutoAccept"));
JoinDiscordCommand = new RelayCommand(o => LaunchWeb("https://discord.gg/Cddu5aJ"));
StartCS2Command = new RelayCommand(o => LaunchWeb("steam://rungameid/730"));

// Event handler for double-click on TaskbarIcon
MyNotifyIcon.TrayMouseDoubleClick += OnTrayIconDoubleClick;
Expand Down Expand Up @@ -215,6 +221,7 @@ public MainWindow()
}
#endregion
}

private void ToggleWindowState()
{
if (WindowState == WindowState.Minimized)
Expand Down Expand Up @@ -449,7 +456,7 @@ protected override void OnStateChanged(EventArgs e)

// Find context menu items and update texts based on WindowState
var menu = (System.Windows.Controls.ContextMenu)MyNotifyIcon.ContextMenu;
var toggleMenuItem = (System.Windows.Controls.MenuItem)menu.Items[0];
var toggleMenuItem = (System.Windows.Controls.MenuItem)MinimizeAndRestore;

if (WindowState == WindowState.Minimized)
{
Expand Down Expand Up @@ -981,6 +988,7 @@ private void IsGameRunning()
TextBlock_MonitorSize.Text = $"Display Size: {_activeScreen.Bounds.Width}x{_activeScreen.Bounds.Height} ({AspectRatio()})";
Button_LaunchCS.Visibility = Visibility.Collapsed;
Button_LaunchCS.Content = "Launch CS2";
StartCS2.Visibility = Visibility.Collapsed;
}));

CalculateSizes(AspectRatio());
Expand All @@ -999,6 +1007,7 @@ private void IsGameRunning()
Program_state_continuously.IsEnabled = false;
Button_LaunchCS.Content = "Launch CS2";
Button_LaunchCS.Visibility = Visibility.Visible;
StartCS2.Visibility = Visibility.Visible;
}));
}
}
Expand Down Expand Up @@ -1523,7 +1532,7 @@ private void ShowGameOverlay(string message)
int overlayWidth = 600;
int overlayHeight = 250;
int overlayleft = _activeScreen.Bounds.Left + (_activeScreen.Bounds.Width / 2) - (overlayWidth / 2);
int overlayTop = _activeScreen.Bounds.Top + (_activeScreen.Bounds.Height / 2) - (overlayHeight / 2);
int overlayTop = _acceptPosY + overlayHeight;

Window overlay = new Window
{
Expand Down
Loading

0 comments on commit c4eac90

Please sign in to comment.