private void ToggleTab(ITab tab) { Type openTabType = this.OpenTabType; if ((tab == null && openTabType == null) || tab.GetType() == openTabType) { this.OpenTabType = null; SoundDefOf.TabClose.PlayOneShotOnCamera(); } else { tab.OnOpen(); this.OpenTabType = tab.GetType(); SoundDefOf.TabOpen.PlayOneShotOnCamera(); } }
private static bool Prefix() { if (!DSGUIMod.Settings.DSGUI_Tab_EnableTab) { return(true); } if (selectInst.NumSelected != 1) { return(false); } var t = selectInst.SingleSelectedThing; if (t == null) { return(false); } if (!(t is ThingWithComps)) { return(false); } var cds = t.TryGetComp <CompDeepStorage>(); if (cds == null) { return(false); } var pane = (MainTabWindow_Inspect)MainButtonDefOf.Inspect.TabWindow; var alreadyOpenTabType = pane.OpenTabType; if (alreadyOpenTabType != null) { var listOfTabs = t.GetInspectTabs(); if (listOfTabs.Any(x => x.GetType() == alreadyOpenTabType)) { return(false); } } ITab tab = null; if (t.Spawned && t is IStoreSettingsParent && t is ISlotGroupParent parent) { foreach (var _ in from c in parent.GetSlotGroup().CellsList select t.Map.thingGrid.ThingsListAt(c) into l from tmp in l.Where(tmp => tmp.def.EverStorable(false)) select l) { goto EndLoop; } tab = t.GetInspectTabs().OfType <ITab_Storage>().First(); } EndLoop: if (tab == null && DSGUIMod.Settings.DSGUI_Tab_EnableTab) { try { tab = t.GetInspectTabs().OfType <DSGUI_TabModal>().First(); } catch (Exception e) { Log.Warning("[DSGUI] Could not get DSGUI_TabModel, trying default. (" + e + ")"); } } if (tab == null) { try { tab = t.GetInspectTabs().OfType <ITab_DeepStorage_Inventory>().First(); } catch (Exception e) { Log.Warning("[DSGUI] Could not get ITab_DeepStorage_Inventory, trying vanilla. (" + e + ")"); } } if (tab == null) { Log.Error("[DSGUI] Deep Storage object " + t + " does not have an inventory tab?"); return(false); } tab.OnOpen(); pane.OpenTabType = tab switch { ITab_DeepStorage_Inventory _ => typeof(ITab_DeepStorage_Inventory), DSGUI_TabModal _ => typeof(DSGUI_TabModal), _ => typeof(ITab_Storage) }; return(false); } }
public static void Postfix(Selector __instance) { if (__instance.NumSelected != 1) { return; } Thing t = __instance.SingleSelectedThing; if (t == null) { return; } if (!(t is ThingWithComps)) { return; } CompDeepStorage cds = t.TryGetComp <CompDeepStorage>(); if (cds == null) { return; } // Off to a good start; it's a DSU // Check to see if a tab is already open. var pane = (MainTabWindow_Inspect)MainButtonDefOf.Inspect.TabWindow; Type alreadyOpenTabType = pane.OpenTabType; if (alreadyOpenTabType != null) { var listOfTabs = t.GetInspectTabs(); foreach (var x in listOfTabs) { if (x.GetType() == alreadyOpenTabType) // Misses any subclassing? { return; // standard Selector behavior should kick in. } } } // If not, open ours! // TODO: ...make this happen for shelves, heck, any storage buildings? ITab tab = null; /* If there are no items stored, default intead to settings (preferably with note about being empty?) */ // If we find a stored item, open Contents tab: // TODO: Make storage settings tab show label if it's empty if (t.Spawned && t is IStoreSettingsParent && t is ISlotGroupParent) { foreach (IntVec3 c in ((ISlotGroupParent)t).GetSlotGroup().CellsList) { List <Thing> l = t.Map.thingGrid.ThingsListAt(c); foreach (Thing tmp in l) { if (tmp.def.EverStorable(false)) { goto EndLoop; // Seriously? C# doesn't have "break 2;"? } } } tab = t.GetInspectTabs().OfType <ITab_Storage>().First(); } EndLoop: if (tab == null) { tab = t.GetInspectTabs().OfType <ITab_DeepStorage_Inventory>().First(); } if (tab == null) { Log.Error("LWM Deep Storage object " + t + " does not have an inventory tab?"); return; } tab.OnOpen(); if (tab is ITab_DeepStorage_Inventory) { pane.OpenTabType = typeof(ITab_DeepStorage_Inventory); } else { pane.OpenTabType = typeof(ITab_Storage); } }