Skip to content

Commit

Permalink
Added icons for "Random" and "Last played"
Browse files Browse the repository at this point in the history
  • Loading branch information
netquick committed Aug 11, 2024
1 parent b440ac5 commit e10d1b5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 25 deletions.
8 changes: 8 additions & 0 deletions DeFRaG_Helper/DeFRaG_Helper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<None Remove="Icons\config.svg" />
<None Remove="Icons\dice.svg" />
<None Remove="Icons\download.svg" />
<None Remove="Icons\edit.svg" />
<None Remove="Icons\esports.svg" />
Expand Down Expand Up @@ -59,6 +60,7 @@
<None Remove="Icons\Items\scout.svg" />
<None Remove="Icons\Items\teleporter.svg" />
<None Remove="Icons\map.svg" />
<None Remove="Icons\replay.svg" />
<None Remove="Icons\settings.svg" />
<None Remove="Icons\slideshow.svg" />
<None Remove="Icons\Weapons\chaingun.svg" />
Expand All @@ -85,6 +87,9 @@
<Resource Include="Icons\config.svg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
<Resource Include="Icons\dice.svg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
<Resource Include="Icons\download.svg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
Expand Down Expand Up @@ -223,6 +228,9 @@
<Resource Include="Icons\map.svg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
<Resource Include="Icons\replay.svg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
<Resource Include="Icons\settings.svg">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
Expand Down
1 change: 1 addition & 0 deletions DeFRaG_Helper/Icons/dice.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions DeFRaG_Helper/Icons/replay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions DeFRaG_Helper/UserControls/DropDownButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
xmlns:converters="clr-namespace:DeFRaG_Helper.Converters"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="200"
SizeChanged="UserControl_SizeChanged">
SizeChanged="UserControl_SizeChanged"
Loaded="UserControl_Loaded">
<UserControl.Resources>
<!-- Existing resources -->
<converters:DynamicSvgConverter x:Key="DynamicSvgConverter"/>
<!-- Define the icon source as a resource -->
<sys:String x:Key="IconSource">Icons/esports.svg</sys:String>
<!-- Define the icon sources as resources -->
<sys:String x:Key="PlayGameIconSource">Icons/esports.svg</sys:String>
<sys:String x:Key="RandomMapIconSource">Icons/dice.svg</sys:String>
<sys:String x:Key="LastPlayedIconSource">Icons/replay.svg</sys:String>
</UserControl.Resources>
<Border CornerRadius="10" Background="#2D2D2D">
<Grid>
<Button x:Name="ActionButton" Content="" Click="ActionButton_Click"/>
<Button x:Name="DropdownButton" Content="" HorizontalAlignment="Right" Width="30" Click="DropdownButton_Click"/>
<Image Source="{Binding Source={StaticResource IconSource}, Converter={StaticResource DynamicSvgConverter}}" Height="30" Width="30" Margin="10,30,0,30" HorizontalAlignment="Left" IsHitTestVisible="False"/>
<Image x:Name="ActionButtonIcon" Source="{Binding Source={StaticResource PlayGameIconSource}, Converter={StaticResource DynamicSvgConverter}}" Height="30" Width="30" Margin="10,30,0,30" HorizontalAlignment="Left" IsHitTestVisible="False"/>
<Label Name="lblAction" Content="Play Game" FontFamily="Segoe UI" FontSize="20" Foreground="White" VerticalAlignment="Center" Margin="45,0,0,0" HorizontalAlignment="Left" Width="155" IsHitTestVisible="False"/>
</Grid>
</Border>
Expand Down
79 changes: 58 additions & 21 deletions DeFRaG_Helper/UserControls/DropDownButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,45 @@ protected virtual void OnMapPlayed()
{
MapPlayed?.Invoke(this, EventArgs.Empty);
}

public DropDownButton()
{
InitializeComponent();
lblAction.Content = AppConfig.ButtonState;
mapHistoryManager = MapHistoryManager.Instance; // Correctly initialize the class-level field
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
UpdateActionButtonIcon();
}

private void UpdateActionButtonIcon()
{
var iconConverter = (DynamicSvgConverter)FindResource("DynamicSvgConverter");
string iconSourceKey = string.Empty;

switch (lblAction.Content.ToString())
{
case "Play Game":
iconSourceKey = "PlayGameIconSource";
break;
case "Random Map":
iconSourceKey = "RandomMapIconSource";
break;
case "Last Played":
iconSourceKey = "LastPlayedIconSource";
break;
default:
break;
}

if (!string.IsNullOrEmpty(iconSourceKey))
{
ActionButtonIcon.Source = iconConverter.Convert((string)FindResource(iconSourceKey), typeof(ImageSource), null, null) as ImageSource;
}
}

private async void ActionButton_Click(object sender, RoutedEventArgs e)
{
var mainWindow = Application.Current.MainWindow as MainWindow;
Expand Down Expand Up @@ -64,6 +96,28 @@ private async void ActionButton_Click(object sender, RoutedEventArgs e)
default:
break;
}

// Update the icon after the action
UpdateActionButtonIcon();
}

private async void MenuItem_Click(object sender, RoutedEventArgs e)
{
// Cast the sender back to a MenuItem
MenuItem clickedItem = sender as MenuItem;

if (clickedItem != null)
{
lblAction.Content = clickedItem.Header.ToString();
AppConfig.ButtonState = clickedItem.Header.ToString(); // Update AppConfig with the new state
await AppConfig.SaveConfigurationAsync(); // Save the updated configuration

// Trigger the action associated with the new state
ActionButton_Click(this, new RoutedEventArgs());

// Update the icon after the action
UpdateActionButtonIcon();
}
}

private void DropdownButton_Click(object sender, RoutedEventArgs e)
Expand All @@ -75,25 +129,24 @@ private void DropdownButton_Click(object sender, RoutedEventArgs e)
MenuItem option2 = new MenuItem() { Header = "Random Map" };
MenuItem option3 = new MenuItem() { Header = "Last Played" };

// Set icons for the menu items using the same source
string iconSource = (string)FindResource("IconSource");
// Set icons for the menu items using different sources
var iconConverter = (DynamicSvgConverter)FindResource("DynamicSvgConverter");

option1.Icon = new Image
{
Source = iconConverter.Convert(iconSource, typeof(ImageSource), null, null) as ImageSource,
Source = iconConverter.Convert((string)FindResource("PlayGameIconSource"), typeof(ImageSource), null, null) as ImageSource,
Width = 18, // Adjusted icon size
Height = 18 // Adjusted icon size
};
option2.Icon = new Image
{
Source = iconConverter.Convert(iconSource, typeof(ImageSource), null, null) as ImageSource,
Source = iconConverter.Convert((string)FindResource("RandomMapIconSource"), typeof(ImageSource), null, null) as ImageSource,
Width = 18, // Adjusted icon size
Height = 18 // Adjusted icon size
};
option3.Icon = new Image
{
Source = iconConverter.Convert(iconSource, typeof(ImageSource), null, null) as ImageSource,
Source = iconConverter.Convert((string)FindResource("LastPlayedIconSource"), typeof(ImageSource), null, null) as ImageSource,
Width = 18, // Adjusted icon size
Height = 18 // Adjusted icon size
};
Expand All @@ -118,22 +171,6 @@ private void DropdownButton_Click(object sender, RoutedEventArgs e)
menu.IsOpen = true;
}

private async void MenuItem_Click(object sender, RoutedEventArgs e)
{
// Cast the sender back to a MenuItem
MenuItem clickedItem = sender as MenuItem;

if (clickedItem != null)
{
lblAction.Content = clickedItem.Header.ToString();
AppConfig.ButtonState = clickedItem.Header.ToString(); // Update AppConfig with the new state
await AppConfig.SaveConfigurationAsync(); // Save the updated configuration

// Trigger the action associated with the new state
ActionButton_Click(this, new RoutedEventArgs());
}
}

private async void PlayRandomMap()
{
// Ensure this method is called from an event that can handle async operations
Expand Down

0 comments on commit e10d1b5

Please sign in to comment.