diff --git a/.gitignore b/.gitignore index f01a16d..611168e 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/IRSequencer/IRSequencer/Gui/Sequencer.cs b/IRSequencer/IRSequencer/Gui/Sequencer.cs index 21bd125..72aca6e 100644 --- a/IRSequencer/IRSequencer/Gui/Sequencer.cs +++ b/IRSequencer/IRSequencer/Gui/Sequencer.cs @@ -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; @@ -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, @@ -146,7 +183,7 @@ private static void InitGUI() } } - private void OnAppReady() + private void AddAppLauncherButton() { if (appLauncherButton == null) { @@ -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); } } } @@ -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 @@ -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); @@ -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 @@ -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)); @@ -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; @@ -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)); @@ -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(); @@ -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(); @@ -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++ ) { @@ -897,7 +999,16 @@ private void SequencerEditorWindow(int windowID) commandStatus = "■"; 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) @@ -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(); @@ -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(); if (GUIEnabled && (storage == null || storage.Count == 0) ) { diff --git a/IRSequencer/IRSequencer/Properties/AssemblyInfo.cs b/IRSequencer/IRSequencer/Properties/AssemblyInfo.cs index 37e4004..3fce19f 100644 --- a/IRSequencer/IRSequencer/Properties/AssemblyInfo.cs +++ b/IRSequencer/IRSequencer/Properties/AssemblyInfo.cs @@ -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("")] @@ -35,5 +35,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1")] -[assembly: AssemblyFileVersion("0.1")] \ No newline at end of file +[assembly: AssemblyVersion("0.3.0")] +[assembly: AssemblyFileVersion("0.3.0")] \ No newline at end of file diff --git a/IRSequencer/IRSequencer/Utility/TextureLoader.cs b/IRSequencer/IRSequencer/Utility/TextureLoader.cs index 715dc05..02b84b9 100644 --- a/IRSequencer/IRSequencer/Utility/TextureLoader.cs +++ b/IRSequencer/IRSequencer/Utility/TextureLoader.cs @@ -13,6 +13,9 @@ public class TextureLoader internal static Texture2D PlayheadBG { get; private set; } internal static Texture2D PlayheadBGPaused { get; private set; } + internal static Texture2D ToggleBG { get; private set; } + internal static Texture2D ToggleBGHover { get; private set; } + internal static Texture2D ExpandIcon { get; private set; } internal static Texture2D CollapseIcon { get; private set; } internal static Texture2D DownIcon { get; private set; } @@ -48,8 +51,14 @@ public static void InitTextures() EditorBackgroundText = CreateTextureFromColor(1, 1, new Color32(81, 86, 94, 255)); PlayheadBG = CreateTextureFromColor(1, 1, new Color32(85, 170, 0, 64)); PlayheadBGPaused = CreateTextureFromColor(1, 1, new Color32(255, 170, 0, 64)); + + ToggleBG = CreateBorderTextureFromColor(25, 25, new Color32(128, 128, 128, 64), new Color32(155, 155, 155, 255)); + ToggleBGHover = CreateBorderTextureFromColor(25, 25, new Color32(200, 200, 200, 64), Color.white); //Transparent = CreateTextureFromColor(1, 1, new Color32(255, 255, 255, 0)); - + + //ExpandIcon = ToggleBG; + //CollapseIcon = ToggleBGHover; + //ExpandIcon = GameDatabase.Instance.GetTexture(texPath + "expand.png", false); ExpandIcon = new Texture2D(32, 32, TextureFormat.ARGB32, false); LoadImageFromFile(ExpandIcon, "expand.png"); @@ -158,5 +167,26 @@ private static Texture2D CreateTextureFromColor(int width, int height, Color col return result; } + private static Texture2D CreateBorderTextureFromColor(int width, int height, Color col, Color borderCol) + { + + var result = CreateTextureFromColor (width, height, col); + + for (int x = 0; x < result.width; x++) + { + for (int y = 0; y < result.height; y++) + { + if (x < 1 || x>result.width-2) + result.SetPixel(x, y, borderCol); + else if (y < 1 || y>result.height-2) + result.SetPixel(x, y, borderCol); + } + } + + result.Apply(); + + return result; + } + } }