Skip to content

Commit

Permalink
2.0.0 : Added skins.
Browse files Browse the repository at this point in the history
  • Loading branch information
DynamicField committed Dec 31, 2017
1 parent a527fde commit b9f671d
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 26 deletions.
12 changes: 12 additions & 0 deletions HeimerFlyingOnYourScreen/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="HeimerFlyingOnYourScreen.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<userSettings>
<HeimerFlyingOnYourScreen.Properties.Settings>
<setting name="Skin" serializeAs="String">
<value>Classic</value>
</setting>
</HeimerFlyingOnYourScreen.Properties.Settings>
</userSettings>
</configuration>
7 changes: 7 additions & 0 deletions HeimerFlyingOnYourScreen/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using HeimerFlyingOnYourScreen.Properties;

namespace HeimerFlyingOnYourScreen
{
Expand All @@ -16,6 +17,12 @@ public partial class App : Application
public App()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Settings.Default.Upgrade();
if (!ResourceData.ImplementedSkins.Contains(Settings.Default.Skin))
{
Settings.Default.Skin = "Classic";
Settings.Default.Save();
}
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand Down
84 changes: 84 additions & 0 deletions HeimerFlyingOnYourScreen/ExclusiveMenuItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace HeimerFlyingOnYourScreen
{
/// <summary>
/// STACKOVERFLOW FTW
/// </summary>
public class ExclusiveMenuItem : DependencyObject
{
public static Dictionary<MenuItem, String> ElementToGroupNames = new Dictionary<MenuItem, String>();

public static readonly DependencyProperty GroupNameProperty =
DependencyProperty.RegisterAttached("GroupName",
typeof(String),
typeof(ExclusiveMenuItem),
new PropertyMetadata(String.Empty, OnGroupNameChanged));

public static void SetGroupName(MenuItem element, String value)
{
element.SetValue(GroupNameProperty, value);
}

public static String GetGroupName(MenuItem element)
{
return element.GetValue(GroupNameProperty).ToString();
}

private static void OnGroupNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//Add an entry to the group name collection
var menuItem = d as MenuItem;

if (menuItem != null)
{
String newGroupName = e.NewValue.ToString();
String oldGroupName = e.OldValue.ToString();
if (String.IsNullOrEmpty(newGroupName))
{
//Removing the toggle button from grouping
RemoveCheckboxFromGrouping(menuItem);
}
else
{
//Switching to a new group
if (newGroupName != oldGroupName)
{
if (!String.IsNullOrEmpty(oldGroupName))
{
//Remove the old group mapping
RemoveCheckboxFromGrouping(menuItem);
}
ElementToGroupNames.Add(menuItem, e.NewValue.ToString());
menuItem.Checked += MenuItemChecked;
}
}
}
}

private static void RemoveCheckboxFromGrouping(MenuItem checkBox)
{
ElementToGroupNames.Remove(checkBox);
checkBox.Checked -= MenuItemChecked;
}


static void MenuItemChecked(object sender, RoutedEventArgs e)
{
var menuItem = e.OriginalSource as MenuItem;
foreach (var item in ElementToGroupNames)
{
if (item.Key != menuItem && item.Value == GetGroupName(menuItem))
{
item.Key.IsChecked = false;
}
}
}
}
}
6 changes: 6 additions & 0 deletions HeimerFlyingOnYourScreen/HeimerFlyingOnYourScreen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ExclusiveMenuItem.cs" />
<Compile Include="ResourceData.cs" />
<Compile Include="TurretWindow.xaml.cs">
<DependentUpon>TurretWindow.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -120,6 +122,10 @@
<ItemGroup>
<Resource Include="294873165371408385.ico" />
<Resource Include="MiscImages\Error.png" />
<Resource Include="HeimerImages\PiltoverHeim\PiltoverHeimTurret.png" />
<Resource Include="HeimerImages\ExplodingHeim\ExplodingHeimTurret.png" />
<Resource Include="HeimerImages\Snowmerdinger\SnowmerdingerTurret.png" />
<Resource Include="HeimerImages\AlienInvader\AlienInvaderTurret.png" />
<Content Include="Sounds\Turret\TurretPlaced1.wav">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion HeimerFlyingOnYourScreen/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
d:DataContext="{d:DesignInstance local:MainWindow}">
<Grid>
<Image Source="HeimerImages/Classic/Classic.png" Stretch="Uniform" StretchDirection="DownOnly"
MaxWidth="256" MaxHeight="256" MouseDown="Image_MouseDown">
MaxWidth="256" MaxHeight="256" MouseDown="Image_MouseDown" x:Name="mainImage">
<Image.ContextMenu>
<ContextMenu Opened="ContextMenu_Opened" Closed="ContextMenu_Closed">
<MenuItem Header="Close" Click="CloseMenuItem_Click"/>
Expand Down Expand Up @@ -57,6 +57,18 @@
</MenuItem.Header>
</MenuItem>
<Separator/>
<MenuItem Header="Skin" ItemsSource="{x:Static local:ResourceData.ImplementedSkins}" x:Name="skins">
<MenuItem.ItemContainerStyle>
<Style>
<Setter Property="MenuItem.Header" Value="{Binding}"/>
<Setter Property="local:ExclusiveMenuItem.GroupName" Value="Skin"/>
<Setter Property="MenuItem.IsCheckable" Value="True"/>
<EventSetter Event="MenuItem.Loaded" Handler="SkinMenuItem_Loaded"/>
<EventSetter Event="MenuItem.Checked" Handler="SkinMenuItem_Checked"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<Separator/>
<MenuItem Header="Close all turrets" Click="CloseAllTurretsMenuItem_Click" />
</ContextMenu>
</Image.ContextMenu>
Expand Down
27 changes: 27 additions & 0 deletions HeimerFlyingOnYourScreen/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public MainWindow()
Opacity = 0;
DataContext = this;
InitializeComponent();
ResourceData.UpdateImageSource(mainImage);
TurretTimer.Elapsed += TurretTimer_Elapsed;
TurretTimer.Start();
Closed += MainWindow_Closed;

}

private void MainWindow_Closed(object sender, EventArgs e)
Expand Down Expand Up @@ -79,6 +81,8 @@ public decimal Interval
set { interval = value * 1000; TurretTimer.Interval = (double)interval; }
}

private bool IsLoadedEvent { get; set; }

public double Volume
{
get
Expand All @@ -103,6 +107,8 @@ public double Volume
private MediaPlayer Player { get; set; } = new MediaPlayer();
#endregion
#region Functions and Events


private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
Expand Down Expand Up @@ -213,6 +219,27 @@ private void ContextMenu_Closed(object sender, RoutedEventArgs e)
if (TurretSpawnState)
TurretTimer.Start();
}

private void SkinMenuItem_Loaded(object sender, RoutedEventArgs e)
{
IsLoadedEvent = true;
var casted = (MenuItem)sender;
if (casted.Header.ToString() == Properties.Settings.Default.Skin)
{
casted.IsChecked = true;
}
IsLoadedEvent = false;
}
private void SkinMenuItem_Checked(object sender, RoutedEventArgs e)
{
if (IsLoadedEvent) return;
var casted = (MenuItem)sender;
ResourceData.UpdateImageSource(mainImage,casted.Header.ToString());
foreach (var item in Turrets)
{
ResourceData.UpdateImageSource(item.MainImage,true);
}
}
#endregion
}
}
4 changes: 2 additions & 2 deletions HeimerFlyingOnYourScreen/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
42 changes: 25 additions & 17 deletions HeimerFlyingOnYourScreen/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions HeimerFlyingOnYourScreen/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="HeimerFlyingOnYourScreen.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="Skin" Type="System.String" Scope="User">
<Value Profile="(Default)">Classic</Value>
</Setting>
</Settings>
</SettingsFile>
38 changes: 38 additions & 0 deletions HeimerFlyingOnYourScreen/ResourceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace HeimerFlyingOnYourScreen
{
public static class ResourceData
{
public static string[] ImplementedSkins { get; } = new string[]
{
"Classic",
"AlienInvader",
"ExplodingHeim",
"PiltoverHeim",
"Snowmerdinger"
};
public static void UpdateImageSource(Image img, bool isTurret = false)
{
var skin = Properties.Settings.Default.Skin;
img.Source = new BitmapImage(new Uri($"pack://application:,,,/HeimerFlyingOnYourScreen;component/HeimerImages/{skin}/{skin}{(isTurret ? "Turret" : "")}.png"));
}

public static void UpdateImageSource(Image img, string skinName, bool replaceSettings = true)
{
if (!ImplementedSkins.Contains(skinName)) throw new InvalidOperationException("Skin name isn't right :/");
if (replaceSettings)
{
Properties.Settings.Default.Skin = skinName;
Properties.Settings.Default.Save();
}
img.Source = new BitmapImage(new Uri($"pack://application:,,,/HeimerFlyingOnYourScreen;component/HeimerImages/{skinName}/{skinName}.png"));
}
}
}
2 changes: 1 addition & 1 deletion HeimerFlyingOnYourScreen/TurretWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Title="Turret" Style="{StaticResource EntityWindow}" ShowInTaskbar="False">
<Grid>
<Image Source="HeimerImages/Classic/ClassicTurret.png" Stretch="Uniform" StretchDirection="DownOnly" MaxHeight="64" MaxWidth="64"
MouseDown="Image_MouseDown">
MouseDown="Image_MouseDown" x:Name="mainImage">
<Image.ContextMenu>
<ContextMenu>
<MenuItem Header="Close" Click="MenuItem_Click"/>
Expand Down
3 changes: 3 additions & 0 deletions HeimerFlyingOnYourScreen/TurretWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public TurretWindow(double volume = 0.5)
Player.Play();
Opacity = 0;
InitializeComponent();
ResourceData.UpdateImageSource(mainImage, true);
Top = Randomiser.Next(100, (int)SystemParameters.PrimaryScreenHeight - 100);
Left = Randomiser.Next(100, (int)SystemParameters.PrimaryScreenWidth - 100);
}
private MediaPlayer Player = new MediaPlayer();
private Random Randomiser = new Random(DateTime.Now.Millisecond);

public Image MainImage => mainImage;

private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
Expand Down

0 comments on commit b9f671d

Please sign in to comment.