private void Awake() { //Debug.Log("FillItUp Awake"); smartTankPresent = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "SmartTank"); allShipResources = null; allPartsResourcesByStage = null; allPartsResourcesShip = null; _config = FillItUpConfigNode.LoadOrCreate(); _windowId = WindowHelper.NextWindowId("FillItUp"); _windowPosition = new Rect(_config.WindowX, _config.WindowY, 0, 0); _resourcesByStage = new FuelModel(); _resourcesShip = new FuelModel(); Instance = this; //GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady); OnGUIAppLauncherReady(); //GameEvents.onEditorPartEvent.Add(OnEditorPartEvent); GameEvents.onEditorLoad.Add(OnEditorLoad); GameEvents.onEditorUndo.Add(OnEditorUndo); GameEvents.onEditorShipModified.Add(OnEditorShipModified); GameEvents.onEditorLoad.Add(this.OnShipLoad); GameEvents.onPartPriorityChanged.Add(this.OnPartPriorityChanged); GameEvents.onPartRemove.Add(this.onPartAttachRemove); GameEvents.onPartAttach.Add(this.onPartAttachRemove); GameEvents.onEditorPartPlaced.Add(this.OnPartPriorityChanged); GameEvents.StageManager.OnGUIStageSequenceModified.Add(OnGUIStageSequenceModified); _windowStyle = new GUIStyle(HighLogic.Skin.window); }
public static void Discover(ShipConstruct ship, ref StageResDef allResources, ref SortedDictionary <int, StageResDef> allPartsResourcesByStage, out SortedDictionary <int, StageResDef> allPartsResourcesShip) { if (FillItUp.Instance._config == null) { FillItUp.Instance._config = FillItUpConfigNode.LoadOrCreate(); } if (resources == null) { resources = IgnoredResourcesConfigNode.LoadOrCreate(); } int maxStage = -1; SortedDictionary <int, StageResDef> oldPartResByStage = allPartsResourcesByStage; allPartsResourcesByStage = new SortedDictionary <int, StageResDef>(); allPartsResourcesShip = new SortedDictionary <int, StageResDef>(); StageResDef srd; // Get all parts in ship into individual lists // Also get max stages for (int i = ship.Parts.Count - 1; i >= 0; i--) { var partValidResources = ship.Parts[i].Resources.Distinct().Where(r => !resources.IgnoredResources.Contains(r.resourceName)).ToList(); if (partValidResources.Count > 0) { if (!allPartsResourcesByStage.ContainsKey(ship.Parts[i].inverseStage)) { srd = new StageResDef(); if (oldPartResByStage != null & oldPartResByStage.ContainsKey(ship.Parts[i].inverseStage)) { srd.stageExpanded = oldPartResByStage[ship.Parts[i].inverseStage].stageExpanded; } allPartsResourcesByStage.Add(ship.Parts[i].inverseStage, srd); } if (!allPartsResourcesShip.ContainsKey(StageRes.ALLSTAGES)) { srd = new StageResDef(); allPartsResourcesShip.Add(StageRes.ALLSTAGES, srd); } srd = allPartsResourcesByStage[ship.Parts[i].inverseStage]; srd.parts.Add(ship.Parts[i]); foreach (var r in partValidResources) { Tuple <string, string> key = new Tuple <string, string>(r.info.displayName, r.resourceName); if (!srd.resources.Contains(key)) { srd.resources.Add(key); } } maxStage = Math.Max(maxStage, ship.Parts[i].inverseStage); } } allResources = new StageResDef(); var r1 = ship.Parts.SelectMany(p => p.Resources.Select(r => r)).ToList(); foreach (var r2 in r1) { var key = new Tuple <string, string>(r2.info.displayName, r2.resourceName); if (!resources.IgnoredResources.Contains(r2.resourceName) && !allResources.resources.Contains(key)) { allResources.resources.Add(key); } } allResources.parts = ship.Parts; //allPartsResourcesByStage = stages; }