Пример #1
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            EngineGroupIdStr = string.IsNullOrEmpty(EngineGroupId) ? "not set" : EngineGroupId;
            if (part == null || part.Modules == null)
            {
                DebugHelper.Debug("part == null || part.Modules == null");
                return;
            }
            var modEnginesFx = part.FindModulesImplementing <ModuleEnginesFX>();
            var modEngines   = part.FindModulesImplementing <ModuleEngines>();

            if (modEnginesFx.Any())
            {
                Wrappers = modEnginesFx.Select(x => new EngineWrapper(x)).ToList();
            }
            else if (modEngines.Any())
            {
                Wrappers = modEngines.Select(x => new EngineWrapper(x)).ToList();
            }
            else
            {
                DebugHelper.Warning("No engine module was found!");
            }
        }
Пример #2
0
 public void OnDestroy()
 {
     DebugHelper.Debug("EngineFlightControl:OnDestroy");
     GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
     ApplicationLauncher.Instance.RemoveModApplication(_appLauncherButton);
     //GameEvents.onVesselChange.Remove(OnVesselWasModified);
     GameEvents.onVesselWasModified.Remove(OnVesselWasModified);
     _gui.RenderEnabled = false;
     Instance           = null;
     _gui       = null;
     _framework = null;
 }
 public void Start()
 {
     DebugHelper.Debug("EngineFlightControl:Start");
     _framework              = new GUIFramework();
     _gui                    = new EngineFlightUI("Engine Groups Controller", _framework);
     _gui.IsDisplayDelegate += () => _displayGUI;
     Instance                = this;
     OnVesselWasModified(FlightGlobals.ActiveVessel);
     //GameEvents.onVesselChange.Add(OnVesselWasModified);
     GameEvents.onVesselWasModified.Add(OnVesselWasModified);
     _gui.StartPostDisplay(1);
     GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
 }
Пример #4
0
        private void OnVesselWasModified(Vessel data)
        {
            if (!ReferenceEquals(data, FlightGlobals.ActiveVessel))
            {
                DebugHelper.Debug("OnVesselWasModified called on non-active vessel, skipping");
                return;
            }
            DebugHelper.Debug("OnVesselWasModified, groups count {0}", Groups.Count);
            //_gui.ClearGroups();
            foreach (var engineGroup in Groups.Values)
            {
                DebugHelper.Debug("Cleaning group {0}: {1} engine(s)", engineGroup.GroupId, engineGroup.EngineRefList.Count);
                engineGroup.EngineRefList.Clear();
            }
            //Groups.Clear();
            RecurseParts(data.rootPart,
                         x =>
            {
                //DebugHelper.Debug("Part {0}", x.name);
                //x.FindModuleImplementing<>()
                if (!x.Modules.Contains("EngineGroupModule"))
                {
                    //DebugHelper.Debug("!x.Modules.Contains('EngineGroupModule')");
                    return;
                }
                var moduleRef = x.Modules["EngineGroupModule"] as EngineGroupModule;
                if (moduleRef == null)
                {
                    //DebugHelper.Debug("moduleRef == null");
                    return;
                }
                var groupId = moduleRef.EngineGroupId;
                if (string.IsNullOrEmpty(groupId))
                {
                    return;
                }
                if (!Groups.ContainsKey(groupId))
                {
                    DebugHelper.Debug("Creating a group {0}", groupId);
                    Groups.Add(groupId, new EngineGroup(groupId));
                    _gui.AddGroup(Groups[groupId]);
                }
                foreach (var wrapper in moduleRef.Wrappers)
                {
                    Groups[groupId].EngineRefList.Add(wrapper);
                }
            });

            foreach (var groupId in Groups.Keys.ToList())
            {
                if (Groups[groupId].EngineRefList.Count == 0)
                {
                    DebugHelper.Debug("Removing group {0} (no engines)", groupId);
                    _gui.RemoveGroup(Groups[groupId]);
                    Groups.Remove(groupId);
                }
            }
            if (Groups.Count == 0)
            {
                _gui.DisplayNoGroupsMessage();
            }
        }