-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Fruh
committed
Apr 22, 2016
1 parent
e1e64c6
commit c4252f8
Showing
12 changed files
with
329 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using KSP_LogiRGB.ColorSchemes; | ||
|
||
namespace KSP_LogiRGB | ||
{ | ||
/// <summary> | ||
/// Handles all animations to avoid confusion and multiple animations running at the same time. | ||
/// </summary> | ||
internal class AnimationManager | ||
{ | ||
/// <summary> | ||
/// Singleton instance | ||
/// </summary> | ||
private static AnimationManager instance; | ||
|
||
/// <summary> | ||
/// The currently running animation or null | ||
/// </summary> | ||
private KeyboardAnimation activeAnimation; | ||
|
||
/// <summary> | ||
/// Private constructor to avoid out of singleton instantiation | ||
/// </summary> | ||
private AnimationManager() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Instance getter | ||
/// </summary> | ||
public static AnimationManager Instance | ||
{ | ||
get | ||
{ | ||
if (instance == null) | ||
{ | ||
instance = new AnimationManager(); | ||
} | ||
return instance; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Set the current animation | ||
/// </summary> | ||
/// <param name="animation">the animation to display</param> | ||
public void setAnimation(KeyboardAnimation animation) | ||
{ | ||
activeAnimation = animation; | ||
} | ||
|
||
/// <summary> | ||
/// Fetches one frame from the animation | ||
/// </summary> | ||
/// <returns>the current animation frame</returns> | ||
public ColorScheme getFrame() | ||
{ | ||
return animationRunning() ? activeAnimation.getFrame() : new ColorScheme(); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if there is still an animation running. | ||
/// </summary> | ||
/// <returns></returns> | ||
public bool animationRunning() | ||
{ | ||
return activeAnimation != null && !activeAnimation.isFinished(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using KSP_LogiRGB.ColorSchemes; | ||
|
||
namespace KSP_LogiRGB | ||
{ | ||
/// <summary> | ||
/// Implement this to create an animation on your keyboard. | ||
/// </summary> | ||
public interface KeyboardAnimation | ||
{ | ||
/// <summary> | ||
/// Returns the current animation frame. | ||
/// </summary> | ||
/// <returns>the current animation frame.</returns> | ||
ColorScheme getFrame(); | ||
|
||
/// <summary> | ||
/// Checks if the animation is complete. | ||
/// </summary> | ||
/// <returns>true, if the animation is finished.</returns> | ||
bool isFinished(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Linq; | ||
using KSP_LogiRGB.ColorSchemes; | ||
using UnityEngine; | ||
|
||
namespace KSP_LogiRGB | ||
{ | ||
/// <summary> | ||
/// Displays a warning on the keyboard, indicating that the vessel is currently out of power and cannot | ||
/// be controlled. Consists of two frames alternating at 1fps. | ||
/// </summary> | ||
internal class PowerLostAnimation : KeyboardAnimation | ||
{ | ||
/// <summary> | ||
/// The red frame | ||
/// </summary> | ||
private static readonly ColorScheme red = new ColorScheme(Color.red); | ||
|
||
/// <summary> | ||
/// The blue frame | ||
/// </summary> | ||
private static readonly ColorScheme blue = new ColorScheme(Color.blue); | ||
|
||
/// <summary> | ||
/// Static constructor adds lightning bolts in different colors to both frames | ||
/// </summary> | ||
static PowerLostAnimation() | ||
{ | ||
KeyCode[] lightningKeys = | ||
{ | ||
/// Left lightning | ||
KeyCode.F2, KeyCode.Alpha3, KeyCode.W, KeyCode.E, KeyCode.R, KeyCode.D, KeyCode.X, KeyCode.LeftAlt, | ||
|
||
/// Right lightning | ||
KeyCode.F9, KeyCode.Alpha0, KeyCode.O, KeyCode.P, KeyCode.LeftBracket, KeyCode.Semicolon, KeyCode.Period, | ||
KeyCode.RightAlt | ||
}; | ||
|
||
blue.SetKeysToColor(lightningKeys, Color.white); | ||
red.SetKeysToColor(lightningKeys, Color.blue); | ||
} | ||
|
||
/// <summary> | ||
/// <see cref="KeyboardAnimation.getFrame" /> | ||
/// </summary> | ||
/// <returns>the current animation frame.</returns> | ||
public ColorScheme getFrame() | ||
{ | ||
return (int) Time.realtimeSinceStartup%2 == 0 ? red : blue; | ||
} | ||
|
||
/// <summary> | ||
/// <see cref="KeyboardAnimation.isFinished" /> | ||
/// </summary> | ||
/// <returns>true, if the animation is finished, false if not.</returns> | ||
public bool isFinished() | ||
{ | ||
/// Exit if the scene changes. | ||
if (HighLogic.LoadedScene != GameScenes.FLIGHT) | ||
return true; | ||
|
||
/// Check if the vessel needs power, and if empty, continue blinking | ||
var resource = FlightGlobals.ActiveVessel.GetActiveResources() | ||
.Where(res => res.info.name.Equals("ElectricCharge")); | ||
if (resource.Count() > 0) | ||
return resource.First().amount > 0.0001; | ||
|
||
/// No energy stored on the ship, end the animation. | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.