Skip to content

Commit

Permalink
Merge pull request #27 from MagicSmokeIndustries/develop
Browse files Browse the repository at this point in the history
Sequencer v0.3
  • Loading branch information
ZiwKerman committed May 7, 2015
2 parents ebe31e3 + 2d13ab9 commit 57e4a9a
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ IRSequencer/IRSequencer.v12.suo
IRSequencer/IRSequencer.v12.suo
*.suo
IRSequencer/IRSequencer.v12.suo
*.cache
IRSequencer/IRSequencer/obj/Release/IRSequencer.csproj.FileListAbsolute.txt
193 changes: 161 additions & 32 deletions IRSequencer/IRSequencer/Gui/Sequencer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ public class Sequencer : MonoBehaviour
private static GUIStyle dotStyle;
private static GUIStyle playheadStyle;
private static GUIStyle textFieldStyle;
private static GUIStyle insertToggleStyle;

private static Color solidColor;
private static Color opaqueColor;

//Sequence Editor UI related
private float currentDelay = 1.0f;
private int currentMode = 0;
private string currentGotoIndexString = "1";
private int currentGotoIndex = 0;
private int currentGotoCounter = -1;
//index wher to insert new commands
private int insertCommandIndex = -1;


protected static Rect SequencerWindowPos;
protected static Rect SequencerEditorWindowPos;
Expand Down Expand Up @@ -131,6 +136,38 @@ private static void InitGUI()
},
};

insertToggleStyle = new GUIStyle (GUI.skin.label)
{
onNormal =
{
textColor = Color.white,
background = TextureLoader.ToggleBG
},
onActive =
{
textColor = Color.white,
background = TextureLoader.ToggleBG
},
onHover =
{
textColor = Color.white,
background = TextureLoader.ToggleBGHover
},
hover =
{
textColor = Color.white,
background = TextureLoader.ToggleBGHover
},
active =
{
textColor = Color.white,
background = TextureLoader.ToggleBG
},
alignment = TextAnchor.MiddleCenter,
padding = new RectOffset(1, 1, 1, 1),
border = new RectOffset (1, 1, 1, 1)
};

dotStyle = new GUIStyle(GUI.skin.label)
{
richText = true,
Expand All @@ -146,7 +183,7 @@ private static void InitGUI()
}
}

private void OnAppReady()
private void AddAppLauncherButton()
{
if (appLauncherButton == null)
{
Expand All @@ -157,13 +194,12 @@ private void OnAppReady()

appLauncherButton = ApplicationLauncher.Instance.AddModApplication(delegate { GUIEnabled = true; },
delegate { GUIEnabled = false; }, null, null, null, null,
ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.VAB |
ApplicationLauncher.AppScenes.SPH, texture);
ApplicationLauncher.AppScenes.FLIGHT, texture);

}
catch (Exception ex)
{
Logger.Log(string.Format("[GUI OnnAppReady Exception, {0}", ex.Message), Logger.Level.Fatal);
Logger.Log(string.Format("[GUI AddAppLauncherButton Exception, {0}", ex.Message), Logger.Level.Fatal);
}
}
}
Expand Down Expand Up @@ -386,16 +422,22 @@ private void Awake()

GameEvents.onVesselChange.Add(OnVesselChange);
GameEvents.onVesselWasModified.Add(OnVesselWasModified);
GameEvents.onGUIApplicationLauncherReady.Add(OnAppReady);

GameEvents.onGameSceneLoadRequested.Remove(OnGameSceneLoadRequestedForAppLauncher);

if (ApplicationLauncher.Ready && appLauncherButton == null)
{
OnAppReady();
AddAppLauncherButton();
}

Logger.Log("[Sequencer] Awake successful", Logger.Level.Debug);
}


void OnGameSceneLoadRequestedForAppLauncher(GameScenes SceneToLoad)
{
DestroyAppLauncherButton();
}

public void Start()
{
try
Expand All @@ -420,21 +462,10 @@ private void OnHideUI()
guiHidden = true;
}

private void OnDestroy()
private void DestroyAppLauncherButton()
{
GameEvents.onShowUI.Remove(OnShowUI);
GameEvents.onHideUI.Remove(OnHideUI);

GameEvents.onVesselChange.Remove(OnVesselChange);
GameEvents.onVesselWasModified.Remove(OnVesselWasModified);

Sequencer.Instance.isReady = false;
SaveConfigXml();

try
{
GameEvents.onGUIApplicationLauncherReady.Remove(OnAppReady);

if (appLauncherButton != null && ApplicationLauncher.Instance != null)
{
ApplicationLauncher.Instance.RemoveModApplication(appLauncherButton);
Expand All @@ -445,6 +476,21 @@ private void OnDestroy()
{
Logger.Log("[Sequencer] Failed unregistering AppLauncher handlers," + e.Message);
}
}

private void OnDestroy()
{
GameEvents.onShowUI.Remove(OnShowUI);
GameEvents.onHideUI.Remove(OnHideUI);

GameEvents.onVesselChange.Remove(OnVesselChange);
GameEvents.onVesselWasModified.Remove(OnVesselWasModified);

Sequencer.Instance.isReady = false;
SaveConfigXml();

GameEvents.onGameSceneLoadRequested.Remove(OnGameSceneLoadRequestedForAppLauncher);
DestroyAppLauncherButton();

//consider unloading textures too in TextureLoader

Expand Down Expand Up @@ -711,8 +757,15 @@ private void SequencerEditorWindow(int windowID)
{
openSequence.Pause ();
openSequence.Reset ();

openSequence.commands.Add (new BasicCommand (avCommand));
if (insertCommandIndex + 1 == openSequence.commands.Count)
{
openSequence.commands.Add (new BasicCommand (avCommand));
insertCommandIndex++;
}
else
{
openSequence.commands.Insert (insertCommandIndex + 1, new BasicCommand (avCommand));
}
}

GUILayout.Label (servo.Name, nameStyle, GUILayout.ExpandWidth (true), GUILayout.Height (22));
Expand Down Expand Up @@ -762,7 +815,16 @@ private void SequencerEditorWindow(int windowID)
openSequence.Reset ();

var newCommand = new BasicCommand (a);
openSequence.commands.Add (newCommand);

if (insertCommandIndex + 1 == openSequence.commands.Count)
{
openSequence.commands.Add (newCommand);
insertCommandIndex++;
}
else
{
openSequence.commands.Insert (insertCommandIndex + 1, newCommand);
}
}
GUILayout.Label ("Toggle AG: " + a.ToString(), GUILayout.ExpandWidth (true), GUILayout.Height (22));
GUI.color = opaqueColor;
Expand All @@ -784,7 +846,15 @@ private void SequencerEditorWindow(int windowID)
openSequence.Reset ();

var newCommand = new BasicCommand(true, currentDelay);
openSequence.commands.Add(newCommand);
if (insertCommandIndex + 1 == openSequence.commands.Count)
{
openSequence.commands.Add (newCommand);
insertCommandIndex++;
}
else
{
openSequence.commands.Insert (insertCommandIndex + 1, newCommand);
}
}

GUILayout.Label("Delay for ", nameStyle, GUILayout.ExpandWidth(true), GUILayout.Height(22));
Expand All @@ -804,7 +874,15 @@ private void SequencerEditorWindow(int windowID)
openSequence.Reset ();

var newCommand = new BasicCommand(true);
openSequence.commands.Add(newCommand);
if (insertCommandIndex + 1 == openSequence.commands.Count)
{
openSequence.commands.Add (newCommand);
insertCommandIndex++;
}
else
{
openSequence.commands.Insert (insertCommandIndex + 1, newCommand);
}
}
GUILayout.Label("Wait for Moves", nameStyle, GUILayout.ExpandWidth(true), GUILayout.Height(22));
GUILayout.EndHorizontal();
Expand All @@ -817,7 +895,15 @@ private void SequencerEditorWindow(int windowID)
openSequence.Reset ();

var newCommand = new BasicCommand(currentGotoIndex, currentGotoCounter);
openSequence.commands.Add(newCommand);
if (insertCommandIndex + 1 == openSequence.commands.Count)
{
openSequence.commands.Add (newCommand);
insertCommandIndex++;
}
else
{
openSequence.commands.Insert (insertCommandIndex + 1, newCommand);
}
}

GUILayout.BeginVertical();
Expand Down Expand Up @@ -875,6 +961,22 @@ private void SequencerEditorWindow(int windowID)
GUI.color = opaqueColor;
GUILayout.EndHorizontal();

//set pointer to last command
if (insertCommandIndex < -1 || insertCommandIndex >= openSequence.commands.Count)
insertCommandIndex = openSequence.commands.Count-1;

if (insertCommandIndex == -1)
{
playheadStyle.normal.background = TextureLoader.ToggleBGHover;
GUILayout.BeginHorizontal (GUILayout.Height(1));
GUILayout.Label ("", playheadStyle, GUILayout.Height(1));
GUILayout.EndHorizontal ();
}
else
{
playheadStyle.normal.background = null;
}

//now begin listing commands in sequence
for (int i = 0; i < openSequence.commands.Count; i++ )
{
Expand All @@ -897,7 +999,16 @@ private void SequencerEditorWindow(int windowID)
commandStatus = "<color=yellow>■</color>";
GUILayout.Label(commandStatus, dotStyle, GUILayout.Width(20), GUILayout.Height(22));

GUILayout.Label((i+1).ToString() + ":", dotStyle, GUILayout.Width(25), GUILayout.Height(22));
//GUILayout.Label((i+1).ToString() + ":", dotStyle, GUILayout.Width(25), GUILayout.Height(22));

if(GUILayout.Toggle((i == insertCommandIndex), new GUIContent((i+1).ToString() + ":", "Insert After"), insertToggleStyle, GUILayout.Width(25), GUILayout.Height(22)))
{
insertCommandIndex = i;
}
else if (insertCommandIndex==i)
{
insertCommandIndex = -1;
}

var labelText = "";
if (bc.wait)
Expand Down Expand Up @@ -964,6 +1075,19 @@ private void SequencerEditorWindow(int windowID)
}
GUI.color = opaqueColor;
GUILayout.EndHorizontal();

if (i == insertCommandIndex)
{
playheadStyle.normal.background = TextureLoader.ToggleBGHover;
GUILayout.BeginHorizontal (GUILayout.Height(1));
GUILayout.Label ("", playheadStyle, GUILayout.Height(1));
GUILayout.EndHorizontal ();
}
else
{
playheadStyle.normal.background = null;
}

}

GUILayout.EndVertical();
Expand Down Expand Up @@ -1035,14 +1159,19 @@ private void OnGUI()
{
//requires ServoGroups to be parsed
if (!IRWrapper.APIReady)
{
if (appLauncherButton != null)
{
appLauncherButton.VisibleInScenes = ApplicationLauncher.AppScenes.NEVER;
}
return;
}

/*if (IRWrapper.IRController.ServoGroups == null)
return;
if (IRWrapper.IRController.ServoGroups.Count == 0)
return;
*/
if (appLauncherButton != null)
{
appLauncherButton.VisibleInScenes = ApplicationLauncher.AppScenes.FLIGHT;
}

var storage = FlightGlobals.ActiveVessel.FindPartModulesImplementing<SequencerStorage>();
if (GUIEnabled && (storage == null || storage.Count == 0) )
{
Expand Down
8 changes: 4 additions & 4 deletions IRSequencer/IRSequencer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// associated with an assembly.

[assembly: AssemblyTitle("IRSequencer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Sequencer Add-on to Infernal Robotics")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("MagicSmokeIndustries")]
[assembly: AssemblyProduct("IRSequencer")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
Expand All @@ -35,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("0.1")]
[assembly: AssemblyFileVersion("0.1")]
[assembly: AssemblyVersion("0.3.0")]
[assembly: AssemblyFileVersion("0.3.0")]
Loading

0 comments on commit 57e4a9a

Please sign in to comment.