Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from HappyFaceIndustries/development
Merge development for 1.2.0.0 release
- Loading branch information
Showing
17 changed files
with
1,042 additions
and
376 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace KerbalAnimation | ||
{ | ||
[KSPAddon(KSPAddon.Startup.MainMenu, true)] | ||
public class EVAModuleAdder : MonoBehaviour | ||
{ | ||
void Start() | ||
{ | ||
KerbalEVAUtility.AddPartModule ("AnimationPlayerModule"); | ||
} | ||
} | ||
|
||
[KSPAddon(KSPAddon.Startup.Flight, false)] | ||
public class AnimationPlayerWindowHost : MonoBehaviour | ||
{ | ||
public static AnimationPlayerWindowHost Instance | ||
{get; private set;} | ||
|
||
public AnimationPlayerWindow Player; | ||
public static bool GUIOpen = false; | ||
|
||
//events | ||
public EventData<List<KerbalAnimationClip>> OnReloadAnimationClips = new EventData<List<KerbalAnimationClip>>("OnReloadAnimationClips"); | ||
|
||
private void Awake() | ||
{ | ||
Instance = this; | ||
} | ||
private void Start() | ||
{ | ||
Player = new AnimationPlayerWindow (); | ||
} | ||
private void OnGUI() | ||
{ | ||
//return if we are not in a valid state to draw | ||
if (!GUIHider.ShowUI) | ||
return; | ||
if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ActiveVessel.isEVA) | ||
return; | ||
if (KerbalAnimationSuite.Instance.IsAnimating) | ||
return; | ||
|
||
if (GUIOpen) | ||
{ | ||
Player.Draw (); | ||
} | ||
} | ||
private void Update() | ||
{ | ||
//return if we are not in a valid state to update | ||
if (!HighLogic.LoadedSceneIsFlight || !FlightGlobals.ActiveVessel.isEVA) | ||
return; | ||
if (KerbalAnimationSuite.Instance.IsAnimating) | ||
return; | ||
|
||
Player.Update (); | ||
} | ||
} | ||
|
||
public class AnimationPlayerModule : PartModule | ||
{ | ||
public string OpenGUIName = "Open Animation Player"; | ||
public string CloseGUIName = "Close Animation Player"; | ||
|
||
private Animation _animation; | ||
public Animation animation | ||
{ | ||
get | ||
{ | ||
if (_animation == null) | ||
{ | ||
_animation = GetComponent<Animation> (); | ||
} | ||
return _animation; | ||
} | ||
} | ||
|
||
//lifetime | ||
public override void OnStart (StartState state) | ||
{ | ||
AnimationPlayerWindowHost.Instance.OnReloadAnimationClips.Add (OnReloadAnimationClips); | ||
} | ||
public override void OnUpdate () | ||
{ | ||
Events ["ToggleGUI"].guiName = AnimationPlayerWindowHost.GUIOpen ? CloseGUIName : OpenGUIName; | ||
|
||
for(int i = 0; i < 10; i++) | ||
{ | ||
string buttonName = (i + 1).ToString (); | ||
if (i >= 9) | ||
buttonName = "0"; | ||
if (Input.GetKey (buttonName)) | ||
{ | ||
bool shift = Input.GetKey (KeyCode.LeftShift); | ||
|
||
if(!shift && FlightGlobals.ActiveVessel != vessel) | ||
{ | ||
continue; | ||
} | ||
var clip = AnimationPlayerWindowHost.Instance.Player.GetNumberKeyClip (i); | ||
if(clip != null && !animation.IsPlaying(clip.Name)) | ||
{ | ||
if (AnimationPlayerWindow.Loop) | ||
PlayAnimation (clip.Name, WrapMode.Loop); | ||
else | ||
PlayAnimation (clip.Name, WrapMode.Once); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void PlayAnimation(string name, WrapMode wrapMode) | ||
{ | ||
var state = animation [name]; | ||
if (state == null || animation.GetClip(name) == null) | ||
return; | ||
state.wrapMode = wrapMode; | ||
animation.CrossFade (name, 0.2f * state.length, PlayMode.StopSameLayer); | ||
} | ||
|
||
//events | ||
private void OnReloadAnimationClips (List<KerbalAnimationClip> clips) | ||
{ | ||
//initialize all of the clips with this kerbal | ||
foreach (var clip in clips) | ||
{ | ||
clip.Initialize (animation, transform); | ||
} | ||
} | ||
|
||
//KSPEvents | ||
[KSPEvent(guiName = "Open GUI", guiActiveUnfocused = false, guiActive = true)] | ||
public void ToggleGUI() | ||
{ | ||
AnimationPlayerWindowHost.GUIOpen = !AnimationPlayerWindowHost.GUIOpen; | ||
} | ||
} | ||
} | ||
|
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,141 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
|
||
using UnityEngine; | ||
|
||
namespace KerbalAnimation | ||
{ | ||
public class AnimationPlayerWindow : Window | ||
{ | ||
//constructor | ||
public AnimationPlayerWindow () | ||
{ | ||
WindowTitle = "Animation Player"; | ||
WindowRect = new Rect (Screen.width - 325f, 25f, 280f, 0f); | ||
ExpandHeight = true; | ||
Loop = false; | ||
} | ||
|
||
//animations | ||
private List<KerbalAnimationClip> Clips = null; | ||
public KerbalAnimationClip GetNumberKeyClip(int index) | ||
{ | ||
if (index >= Clips.Count) | ||
return null; | ||
else | ||
return Clips [NumberKeyClips [index]]; | ||
} | ||
|
||
//gui values | ||
private Dictionary<string, string> textBoxValues = new Dictionary<string, string>(); | ||
private Vector2 scroll; | ||
public static bool Loop | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public int[] NumberKeyClips = new int[10]; | ||
|
||
protected override void DrawWindow () | ||
{ | ||
if (Clips.Count > 0) | ||
{ | ||
scroll = GUILayout.BeginScrollView (scroll, GUILayout.Height (320f), GUILayout.ExpandWidth(true)); | ||
for (int i = 0; i < Clips.Count; i++) | ||
{ | ||
int nameValue = i + 1; | ||
if (nameValue > 9) | ||
nameValue = 0; | ||
NumberKeyClips [i] = DrawClipSelector ("NumberKey" + nameValue.ToString(), nameValue.ToString(), NumberKeyClips [i]); | ||
} | ||
|
||
GUILayout.Label ("<color=" + Colors.Information + ">Press the numbers 0-9 (not on the numpad) to play the selected animations. Hold left shift to play the animation on all kerbals instead of just the active one</color>"); | ||
|
||
GUILayout.EndScrollView (); | ||
} | ||
Loop = GUILayout.Toggle (Loop, "Loop?"); | ||
if (GUILayout.Button ("Reload Animations")) | ||
{ | ||
ReloadAnimations (); | ||
} | ||
} | ||
public override void Update () | ||
{ | ||
if(Clips == null) | ||
ReloadAnimations (); | ||
} | ||
|
||
//gui methods | ||
private int DrawClipSelector(string uniqueName, string name, int index) | ||
{ | ||
if (!textBoxValues.ContainsKey (uniqueName)) | ||
textBoxValues.Add (uniqueName, Clips[index].Name); | ||
|
||
string textBoxControlName = "ClipSelector_" + uniqueName; | ||
|
||
GUILayout.BeginHorizontal (); | ||
|
||
GUILayout.Label ("<color=" + Colors.Information + ">" + name + ":</color>", GUILayout.Width (30f)); | ||
|
||
bool buttonPressed = false; | ||
int buttonValue = index; | ||
int buttonIncrement = 1; | ||
if (GUILayout.Button ("<<", GUILayout.MaxWidth(40f), GUILayout.Height(24f))) | ||
{ | ||
buttonValue -= buttonIncrement; | ||
buttonPressed = true; | ||
} | ||
|
||
//text field | ||
GUI.SetNextControlName (textBoxControlName); | ||
GUILayout.TextField (textBoxValues [uniqueName], GUILayout.Width(160f)); | ||
|
||
if (GUILayout.Button (">>", GUILayout.MaxWidth(40f), GUILayout.Height(24f))) | ||
{ | ||
buttonValue += buttonIncrement; | ||
buttonPressed = true; | ||
} | ||
if (buttonPressed) | ||
{ | ||
if (buttonValue < 0) | ||
buttonValue = Clips.Count - 1; | ||
else if (buttonValue >= Clips.Count) | ||
buttonValue = 0; | ||
|
||
textBoxValues [uniqueName] = Clips[buttonValue].Name; | ||
GUI.FocusControl (""); | ||
} | ||
|
||
GUILayout.EndHorizontal (); | ||
|
||
return buttonValue; | ||
} | ||
|
||
//utility methods | ||
public void ReloadAnimations() | ||
{ | ||
Clips = new List<KerbalAnimationClip> (); | ||
foreach (var path in Directory.GetFiles(KSPUtil.ApplicationRootPath + "GameData/", "*.anim", SearchOption.AllDirectories)) | ||
{ | ||
KerbalAnimationClip clip = new KerbalAnimationClip (); | ||
clip.LoadFromPath (path); | ||
Clips.Add (clip); | ||
Debug.Log ("KerbalAnimationClip " + clip.Name + " loaded from " + path); | ||
} | ||
|
||
int length = 10; | ||
if (Clips.Count < 10) | ||
length = Clips.Count; | ||
for (int i = 0; i < length; i++) | ||
{ | ||
NumberKeyClips [i] = i; | ||
} | ||
|
||
AnimationPlayerWindowHost.Instance.OnReloadAnimationClips.Fire (Clips); | ||
} | ||
} | ||
} | ||
|
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.