Skip to content

Commit

Permalink
Initial Working Project
Browse files Browse the repository at this point in the history
The component is able to detect the current level being played, and show
the level name and rainbow medal time for that level.

For challenges, it shows the time to beat your opponent.
For bonuses, it shows the time needed to beat the bonus.
For the credits, it shows the time you get when you just hold right
(1:01.00).
  • Loading branch information
faultyserver committed Jul 11, 2016
1 parent b8a49bb commit 745e713
Show file tree
Hide file tree
Showing 12 changed files with 1,297 additions and 0 deletions.
76 changes: 76 additions & 0 deletions LiveSplit.HenkMedals.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{44CE67E8-D96C-4786-AE74-95ABC12D9C12}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LiveSplit.HenkMedals</RootNamespace>
<AssemblyName>LiveSplit.HenkMedals</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="LiveSplit.Core">
<HintPath>..\..\..\..\GitHub\LiveSplit\LiveSplit\bin\Debug\LiveSplit.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UpdateManager">
<HintPath>..\..\..\..\GitHub\LiveSplit\LiveSplit\bin\Debug\UpdateManager.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="TimeFormatters\RegularHenkMedalsTimeFormatter.cs" />
<Compile Include="UI\Components\CurrentLevelComponent.cs" />
<Compile Include="UI\Components\HenkMedalsComponent.cs" />
<Compile Include="UI\Components\HenkMedalsComponentFactory.cs" />
<Compile Include="UI\Components\HenkMedalsComponentSettings.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UI\Components\HenkMedalsComponentSettings.Designer.cs">
<DependentUpon>HenkMedalsComponentSettings.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\Components\RainbowMedalComponent.cs" />
<Compile Include="Util\HenkMemoryReader.cs" />
<Compile Include="Util\BonusLevel.cs" />
<Compile Include="Util\RegularLevel.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LiveSplit.HenkMedals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LiveSplit.HenkMedals")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("44ce67e8-d96c-4786-ae74-95abc12d9c12")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
16 changes: 16 additions & 0 deletions TimeFormatters/RegularHenkMedalsTimeFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace LiveSplit.TimeFormatters
{
class RegularHenkMedalsTimeFormatter : ITimeFormatter
{
public string Format(TimeSpan? time)
{
var formatter = new RegularTimeFormatter(TimeAccuracy.Hundredths);
if (time == null)
return "-";
else
return formatter.Format(time);
}
}
}
129 changes: 129 additions & 0 deletions UI/Components/CurrentLevelComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using LiveSplit.HenkMedals.Util;
using LiveSplit.Model;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LiveSplit.UI.Components
{
class CurrentLevelComponent : IComponent
{
protected InfoTextComponent InternalComponent { get; set; }
public HenkMedalsComponentSettings Settings { get; set; }
protected LiveSplitState CurrentState { get; set; }
public IDictionary<string, Action> ContextMenuControls => null;

public float PaddingTop => InternalComponent.PaddingTop;
public float PaddingLeft => InternalComponent.PaddingLeft;
public float PaddingBottom => InternalComponent.PaddingBottom;
public float PaddingRight => InternalComponent.PaddingRight;

public String LevelNameValue { get; set; }

public CurrentLevelComponent(LiveSplitState state)
{
InternalComponent = new InfoTextComponent("Current Level", null)
{
AlternateNameText = new string[]
{
"Level Name",
"Lvl"
}
};

Settings = new HenkMedalsComponentSettings();
}

private void DrawBackground(Graphics g, LiveSplitState state, float width, float height)
{
if (Settings.BackgroundColor.ToArgb() != Color.Transparent.ToArgb()
|| Settings.BackgroundGradient != GradientType.Plain
&& Settings.BackgroundColor2.ToArgb() != Color.Transparent.ToArgb())
{
var gradientBrush = new LinearGradientBrush(
new PointF(0, 0),
Settings.BackgroundGradient == GradientType.Horizontal
? new PointF(width, 0)
: new PointF(0, height),
Settings.BackgroundColor,
Settings.BackgroundGradient == GradientType.Plain
? Settings.BackgroundColor
: Settings.BackgroundColor2);
g.FillRectangle(gradientBrush, 0, 0, width, height);
}
}

public void DrawVertical(Graphics g, LiveSplitState state, float width, Region clipRegion)
{
DrawBackground(g, state, width, VerticalHeight);

InternalComponent.DisplayTwoRows = Settings.Display2Rows;
InternalComponent.NameLabel.HasShadow
= InternalComponent.ValueLabel.HasShadow
= state.LayoutSettings.DropShadows;
InternalComponent.NameLabel.ForeColor = Settings.OverrideTextColor ? Settings.TextColor : state.LayoutSettings.TextColor;
InternalComponent.ValueLabel.ForeColor = Settings.OverrideTimeColor ? Settings.TimeColor : state.LayoutSettings.TextColor;

InternalComponent.DrawVertical(g, state, width, clipRegion);
}

public void DrawHorizontal(Graphics g, LiveSplitState state, float height, Region clipRegion)
{
DrawBackground(g, state, HorizontalWidth, height);

InternalComponent.NameLabel.HasShadow
= InternalComponent.ValueLabel.HasShadow
= state.LayoutSettings.DropShadows;
InternalComponent.NameLabel.ForeColor = Settings.OverrideTextColor ? Settings.TextColor : state.LayoutSettings.TextColor;
InternalComponent.ValueLabel.ForeColor = Settings.OverrideTimeColor ? Settings.TimeColor : state.LayoutSettings.TextColor;

InternalComponent.DrawHorizontal(g, state, height, clipRegion);
}

public float VerticalHeight => InternalComponent.VerticalHeight;

public float MinimumWidth => InternalComponent.MinimumWidth;

public float HorizontalWidth => InternalComponent.HorizontalWidth;

public float MinimumHeight => InternalComponent.MinimumHeight;

public string ComponentName => "Current Henk Level";

public Control GetSettingsControl(LayoutMode mode)
{
Settings.Mode = mode;
return Settings;
}

public void SetSettings(System.Xml.XmlNode settings)
{
Settings.SetSettings(settings);
}


public System.Xml.XmlNode GetSettings(System.Xml.XmlDocument document)
{
return Settings.GetSettings(document);
}

public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{
LevelNameValue = HenkMemoryReader.CurrentLevelName();

InternalComponent.InformationValue = LevelNameValue;
InternalComponent.Update(invalidator, state, width, height, mode);
}

public void Dispose()
{
}

public int GetSettingsHashCode() => Settings.GetSettingsHashCode();
}
}
103 changes: 103 additions & 0 deletions UI/Components/HenkMedalsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using LiveSplit.Model;
using LiveSplit.TimeFormatters;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace LiveSplit.UI.Components
{
public class HenkMedalsComponent : IComponent
{
protected ComponentRendererComponent InternalComponent { get; set; }
public HenkMedalsComponentSettings Settings { get; set; }

public float PaddingTop => InternalComponent.PaddingTop;
public float PaddingLeft => InternalComponent.PaddingLeft;
public float PaddingBottom => InternalComponent.PaddingBottom;
public float PaddingRight => InternalComponent.PaddingRight;

protected IList<IComponent> Components { get; set; }

public string ComponentName => "Henk Medals";

public IDictionary<string, Action> ContextMenuControls => null;

public float VerticalHeight => InternalComponent.VerticalHeight;
public float HorizontalWidth => InternalComponent.HorizontalWidth;
public float MinimumHeight => InternalComponent.MinimumHeight;
public float MinimumWidth => InternalComponent.MinimumWidth;


public HenkMedalsComponent(LiveSplitState state)
{
Settings = new HenkMedalsComponentSettings();
Components = new List<IComponent>();
Components.Add(new CurrentLevelComponent(state));
Components.Add(new ThinSeparatorComponent());
Components.Add(new RainbowMedalComponent(state));
InternalComponent = new ComponentRendererComponent();
InternalComponent.VisibleComponents = Components;
}

private void DrawBackground(Graphics g, float width, float height)
{
if (Settings.BackgroundColor.ToArgb() != Color.Transparent.ToArgb()
|| Settings.BackgroundGradient != GradientType.Plain
&& Settings.BackgroundColor2.ToArgb() != Color.Transparent.ToArgb())
{
var gradientBrush = new LinearGradientBrush(
new PointF(0, 0),
Settings.BackgroundGradient == GradientType.Horizontal
? new PointF(width, 0)
: new PointF(0, height),
Settings.BackgroundColor,
Settings.BackgroundGradient == GradientType.Plain
? Settings.BackgroundColor
: Settings.BackgroundColor2);
g.FillRectangle(gradientBrush, 0, 0, width, height);
}
}

public void DrawVertical(Graphics g, LiveSplitState state, float width, Region clipRegion)
{
DrawBackground(g, width, VerticalHeight);
InternalComponent.DrawVertical(g, state, width, clipRegion);
}

public void DrawHorizontal(Graphics g, LiveSplitState state, float height, Region clipRegion)
{
DrawBackground(g, HorizontalWidth, height);
InternalComponent.DrawHorizontal(g, state, height, clipRegion);
}

public Control GetSettingsControl(LayoutMode mode)
{
Settings.Mode = mode;
return Settings;
}

public void SetSettings(System.Xml.XmlNode settings)
{
Settings.SetSettings(settings);
}


public System.Xml.XmlNode GetSettings(System.Xml.XmlDocument document)
{
return Settings.GetSettings(document);
}

public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{
InternalComponent.Update(invalidator, state, width, height, mode);
}

public void Dispose()
{
}

public int GetSettingsHashCode() => Settings.GetSettingsHashCode();
}
}
27 changes: 27 additions & 0 deletions UI/Components/HenkMedalsComponentFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using LiveSplit.Model;
using LiveSplit.UI.Components;
using System;

[assembly: ComponentFactory(typeof(HenkMedalsComponentFactory))]

namespace LiveSplit.UI.Components
{
public class HenkMedalsComponentFactory : IComponentFactory
{
public string ComponentName => "Action Henk Medals";

public string Description => "Displays the current level's name and rainbow medal time";

public ComponentCategory Category => ComponentCategory.Information;

public IComponent Create(LiveSplitState state) => new HenkMedalsComponent(state);

public string UpdateName => ComponentName;

public string XMLURL => "";

public string UpdateURL => "";

public Version Version => Version.Parse("0.1.0");
}
}
Loading

0 comments on commit 745e713

Please sign in to comment.