void BaseAction_Clicked(UIBaseActionManager obj) { if (IsFolderVisible) { //Folder already visible, so clean the folders, and redisplay all baseaction foreach (UIActionGroupManager item in actionGroupList) { item.Events[UIActionGroupManager.EVENTNAME].guiActive = false; item.Events[UIActionGroupManager.EVENTNAME].active = false; item.Current = null; } foreach (UIBaseActionManager item in baseActionList) { item.Events[UIBaseActionManager.EVENTNAME].guiActive = true; item.Events[UIBaseActionManager.EVENTNAME].active = true; } IsFolderVisible = false; } else { foreach (UIBaseActionManager item in baseActionList) { //There is a weird issue, if there is only one action on the part, and so we don't want to hide any other actions //the folder won't show. So a dirty solution is to hide this part when it's the only one. if (item == obj && baseActionList.Count > 1) { continue; } item.Events[UIBaseActionManager.EVENTNAME].guiActive = false; item.Events[UIBaseActionManager.EVENTNAME].active = false; } foreach (UIActionGroupManager item in actionGroupList) { item.Current = obj; if (!item.Isfolder) { continue; } item.Events[UIActionGroupManager.EVENTNAME].guiActive = true; item.Events[UIActionGroupManager.EVENTNAME].active = true; } IsFolderVisible = true; } }
public UIPartManager(Part p) { this.Part = p; IsActive = false; IsFolderVisible = false; IsActionGroupsVisible = false; IsSymmetryModeVisible = false; baseActionList = new List <UIBaseActionManager>(); actionGroupList = new List <UIActionGroupManager>(); if (Part.Modules.Contains("UIBaseActionManager") || Part.Modules.Contains("UIActionGroupManager")) { //if the part already contains actionManager class, we clean them. List <PartModule> toRemove = new List <PartModule>(); foreach (PartModule item in Part.Modules) { if (item is UIBaseActionManager || item is UIActionGroupManager) { toRemove.Add(item); } } foreach (PartModule mod in toRemove) { Part.Modules.Remove(mod); } } //We create our base action list foreach (BaseAction ba in BaseActionFilter.FromParts(p)) { //We create the module through AddModule to get the initialization done UIBaseActionManager man = Part.AddModule("UIBaseActionManager") as UIBaseActionManager; // and we remove it to avoid bloating an eventual save. Part.Modules.Remove(man); man.Action = ba; man.Origin = this; man.Clicked += BaseAction_Clicked; man.Initialize(); baseActionList.Add(man); } // and our action group list //First two specific uiactionmanager as folder. UIActionGroupManager agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager; Part.Modules.Remove(agm); agm.Events[UIActionGroupManager.EVENTNAME].guiName = " AGM : General"; agm.Origin = this; agm.Isfolder = true; agm.Type = UIActionGroupManager.FolderType.General; agm.Clicked += Folder_Clicked; actionGroupList.Add(agm); agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager; Part.Modules.Remove(agm); agm.Events[UIActionGroupManager.EVENTNAME].guiName = " AGM : Custom"; agm.Origin = this; agm.Isfolder = true; agm.Type = UIActionGroupManager.FolderType.Custom; agm.Clicked += Folder_Clicked; actionGroupList.Add(agm); //and the rest of action groups foreach (KSPActionGroup ag in Enum.GetValues(typeof(KSPActionGroup))) { if (ag == KSPActionGroup.None) { continue; } agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager; Part.Modules.Remove(agm); agm.Origin = this; agm.ActionGroup = ag; agm.Clicked += ActionGroup_Clicked; agm.Initialize(); actionGroupList.Add(agm); } agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager; Part.Modules.Remove(agm); agm.Events[UIActionGroupManager.EVENTNAME].guiName = " Only this part"; agm.Origin = this; agm.IsSymmetrySelector = true; agm.SymmetryMode = UIActionGroupManager.SymmetryType.One; agm.Clicked += SymmetryMode_Clicked; actionGroupList.Add(agm); agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager; Part.Modules.Remove(agm); agm.Events[UIActionGroupManager.EVENTNAME].guiName = " This part and all symmetry counterparts"; agm.Origin = this; agm.IsSymmetrySelector = true; agm.SymmetryMode = UIActionGroupManager.SymmetryType.All; agm.Clicked += SymmetryMode_Clicked; actionGroupList.Add(agm); }
void BaseAction_Clicked(UIBaseActionManager obj) { if (IsFolderVisible) { //Folder already visible, so clean the folders, and redisplay all baseaction foreach (UIActionGroupManager item in actionGroupList) { item.Events[UIActionGroupManager.EVENTNAME].guiActive = false; item.Events[UIActionGroupManager.EVENTNAME].active = false; item.Current = null; } foreach (UIBaseActionManager item in baseActionList) { item.Events[UIBaseActionManager.EVENTNAME].guiActive = true; item.Events[UIBaseActionManager.EVENTNAME].active = true; } IsFolderVisible = false; } else { foreach (UIBaseActionManager item in baseActionList) { //There is a weird issue, if there is only one action on the part, and so we don't want to hide any other actions //the folder won't show. So a dirty solution is to hide this part when it's the only one. if (item == obj && baseActionList.Count > 1) continue; item.Events[UIBaseActionManager.EVENTNAME].guiActive = false; item.Events[UIBaseActionManager.EVENTNAME].active = false; } foreach (UIActionGroupManager item in actionGroupList) { item.Current = obj; if (!item.Isfolder) continue; item.Events[UIActionGroupManager.EVENTNAME].guiActive = true; item.Events[UIActionGroupManager.EVENTNAME].active = true; } IsFolderVisible = true; } }