Skip to content

Commit

Permalink
Merge pull request #48 from ZiwKerman/V1.0-overhaul
Browse files Browse the repository at this point in the history
V1 0 overhaul - beta 3
  • Loading branch information
ZiwKerman committed Apr 24, 2016
2 parents a7d45a3 + 4d62f84 commit afc328a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ IRSequencer/IRSequencer/obj/Release/IRSequencer.csproj.FileListAbsolute.txt

IRSequencer/IRSequencer/obj/Release/IRSequencer.csproj.FilesWrittenAbsolute.txt
*.cache
IRSequencer/.vs/IRSequencer/IRSequencer.scgdat
Binary file modified IRSequencer/.vs/IRSequencer/IRSequencer.scgdat
Binary file not shown.
46 changes: 36 additions & 10 deletions IRSequencer/IRSequencer/Gui/SequencerGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public class SequencerGUI : MonoBehaviour

public bool GUIEnabled = false;
public bool guiControlWindowEditMode = false;


public bool alwaysStartInEditMode = false;

private bool isReady = false;
private bool firstUpdate = true;

Expand Down Expand Up @@ -537,6 +539,8 @@ private void Awake()
{
LoadConfigXml();

guiControlWindowEditMode = alwaysStartInEditMode;

GameEvents.onShowUI.Add(OnShowUI);
GameEvents.onHideUI.Add(OnHideUI);

Expand Down Expand Up @@ -665,6 +669,16 @@ private void InitSettingsWindow()

_settingsWindow.GetComponent<CanvasGroup>().alpha = 0f;

if (SequencerSettingsWindowPosition == Vector3.zero)
{
//get the default position from the prefab
SequencerSettingsWindowPosition = _settingsWindow.transform.position;
}
else
{
_settingsWindow.transform.position = SequencerSettingsWindowPosition;
}

var closeButton = _settingsWindow.GetChild("WindowTitle").GetChild("RightWindowButton");
if (closeButton != null)
{
Expand Down Expand Up @@ -704,7 +718,12 @@ private void InitSettingsWindow()
scaleText.text = string.Format("{0:#0.00}", v);
});
}


var startEditModeToggle = _settingsWindow.GetChild ("WindowContent").GetChild ("StartEditModeHLG").GetChild ("StartEditModeToggle").GetComponent<Toggle> ();
startEditModeToggle.isOn = alwaysStartInEditMode;
startEditModeToggle.onValueChanged.AddListener (v => alwaysStartInEditMode = v);


var footerButtons = _settingsWindow.GetChild("WindowFooter").GetChild("WindowFooterButtonsHLG");

var cancelButton = footerButtons.GetChild("CancelButton").GetComponent<Button>();
Expand Down Expand Up @@ -1191,7 +1210,7 @@ private void InitEditorWindow(bool startSolid = true)

var resizeHandler = editorFooterButtons.GetChild("ResizeHandle").AddComponent<PanelResizer>();
resizeHandler.rectTransform = _editorWindow.transform as RectTransform;
resizeHandler.minSize = new Vector2(450, 365);
resizeHandler.minSize = new Vector2(470, 365);
resizeHandler.maxSize = new Vector2(2000, 1600);

var leftPane = _editorWindow.GetChild("WindowContent").GetChild("Panes").GetChild("LeftPane").GetChild("CommandZone");
Expand Down Expand Up @@ -1759,13 +1778,19 @@ public void RebuildUI()
else
_sequenceUIControls.Clear();

if (UIAssetsLoader.allPrefabsReady && _settingsWindow == null)
if (!UIAssetsLoader.allPrefabsReady)
{
GUIEnabled = false;
return;
}

if (_settingsWindow == null)
{
InitSettingsWindow();
}

//here we need to wait until prefabs become available and then Instatiate the window
if (UIAssetsLoader.allPrefabsReady && _controlWindow == null)
if (_controlWindow == null)
{
InitControlWindow(GUIEnabled);
}
Expand Down Expand Up @@ -1884,6 +1909,7 @@ public void LoadConfigXml()
SequencerEditorWindowPosition = config.GetValue<Vector3>("SequencerEditorWindowPosition");
SequencerEditorWindowSize = config.GetValue<Vector2>("SequencerEditorWindowSize");
SequencerSettingsWindowPosition = config.GetValue<Vector3>("SequencerSettingsWindowPosition");
alwaysStartInEditMode = config.GetValue<bool>("alwaysStartInEditMode");

_UIAlphaValue = (float)config.GetValue<double>("UIAlphaValue", 0.8);
_UIScaleValue = (float)config.GetValue<double>("UIScaleValue", 1.0);
Expand All @@ -1906,13 +1932,13 @@ public void SaveConfigXml()
}

PluginConfiguration config = PluginConfiguration.CreateForType<SequencerGUI>();
config.SetValue("controlWindowPosition", SequencerWindowPosition);
config.SetValue("editorWindowPosition", SequencerEditorWindowPosition);
config.SetValue("editorWindowSize", SequencerEditorWindowSize);
config.SetValue("uiSettingsWindowPosition", SequencerSettingsWindowPosition);
config.SetValue("SequencerWindowPosition", SequencerWindowPosition);
config.SetValue("SequencerEditorWindowPosition", SequencerEditorWindowPosition);
config.SetValue("SequencerEditorWindowSize", SequencerEditorWindowSize);
config.SetValue("SequencerSettingsWindowPosition", SequencerSettingsWindowPosition);
config.SetValue("UIAlphaValue", (double)_UIAlphaValue);
config.SetValue("UIScaleValue", (double)_UIScaleValue);

config.SetValue("alwaysStartInEditMode", (bool)alwaysStartInEditMode);
config.save();
}

Expand Down
55 changes: 30 additions & 25 deletions IRSequencer/IRSequencer/Gui/UIAssetsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace IRSequencer.Gui
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
public class UIAssetsLoader : MonoBehaviour
{
private AssetBundle IRAssetBundle;
Expand All @@ -29,7 +29,7 @@ public class UIAssetsLoader : MonoBehaviour
internal static List<UnityEngine.Sprite> spriteAssets;

public static bool allPrefabsReady = false;

public IEnumerator LoadBundle(string location)
{
while (!Caching.ready)
Expand All @@ -41,7 +41,7 @@ public IEnumerator LoadBundle(string location)

LoadBundleAssets();

IRAssetBundle.Unload(false);
//IRAssetBundle.Unload(false);
}
}

Expand Down Expand Up @@ -74,7 +74,7 @@ private void LoadBundleAssets()
prefabsLoadedCount++;
}

if (prefabs[i].name == "UISettingsWindowPrefab")
if (prefabs[i].name == "SequencerUISettingsWindowPrefab")
{
uiSettingsWindowPrefab = prefabs[i] as GameObject;
prefabsLoadedCount++;
Expand All @@ -100,7 +100,7 @@ private void LoadBundleAssets()
}

allPrefabsReady = (prefabsLoadedCount > 7);

/*
spriteAssets = new List<UnityEngine.Sprite>();
var sprites = IRAssetBundle.LoadAllAssets<UnityEngine.Sprite>();
Expand All @@ -122,44 +122,49 @@ private void LoadBundleAssets()
iconAssets.Add(icons[i]);
}
}

*/
if(allPrefabsReady)
Logger.Log("Successfully loaded all prefabs from AssetBundle");
else
Logger.Log("Some prefabs failed to load, bundle = " + IRAssetBundle.name);
}

public void LoadBundleFromDisk(string path)
{
IRAssetBundle = AssetBundle.CreateFromFile(path);

LoadBundleAssets();

//had to move bundle unloading further down in time due to unexplained and unreproducable on my PC issues for some users
}

public void Start()
{
var assemblyFile = Assembly.GetExecutingAssembly().Location;
//we will use same path for AssetBundles as IR and share some assets
//var bundlePath = "file://" + assemblyFile.Replace(new FileInfo(assemblyFile).Name, "").Replace("\\","/") + "../../AssetBundles/";
var filePath = assemblyFile.Replace(new FileInfo(assemblyFile).Name, "") + "../../AssetBundles/";

//Logger.Log("Loading bundles from BundlePath: " + bundlePath, Logger.Level.Debug);
var bundlePath = "file://" + assemblyFile.Replace(new FileInfo(assemblyFile).Name, "").Replace("\\","/") + "../../AssetBundles/";

Logger.Log("Loading bundles from BundlePath: " + bundlePath, Logger.Level.Debug);

//need to clean cache
//Caching.CleanCache();
Caching.CleanCache();

if(!allPrefabsReady)
StartCoroutine(LoadBundle(bundlePath + "ir_ui_objects.ksp"));

var IRAssetsLoaderType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "InfernalRobotics.Gui.UIAssetsLoader");

var fieldInfo = IRAssetsLoaderType.GetField("iconAssets", BindingFlags.NonPublic | BindingFlags.Static);

iconAssets = (List<Texture2D>)fieldInfo.GetValue(null);

//StartCoroutine(LoadBundle(bundlePath + "ir_ui_objects.ksp"));
fieldInfo = IRAssetsLoaderType.GetField("spriteAssets", BindingFlags.NonPublic | BindingFlags.Static);

spriteAssets = (List<Sprite>)fieldInfo.GetValue(null);

Logger.Log("Loading bundles from filePath: " + filePath, Logger.Level.Debug);
LoadBundleFromDisk(filePath + "ir_ui_objects.ksp");
}

public void OnDestroy()
{
Logger.Log("Unloading bundle", Logger.Level.Debug);
IRAssetBundle.Unload(false);
if(IRAssetBundle)
{
Logger.Log("Unloading bundle", Logger.Level.Debug);
IRAssetBundle.Unload(false);
}
}
}
}
Expand Down

0 comments on commit afc328a

Please sign in to comment.