protected override void FillTab() { Text.Font = GameFont.Small; Rect rect = new Rect(0f, 20f, this.size.x, this.size.y - 20f); Rect rect2 = rect.ContractedBy(10f); Rect position = new Rect(rect2.x, rect2.y, rect2.width, rect2.height); GUI.BeginGroup(position); Text.Font = GameFont.Small; GUI.color = Color.white; //TODO: handle each cell separately? cabinetInvList.Clear(); Building_Storage cabinetBuilding = SelThing as Building_Storage; List <IntVec3> cabinetStorageCells = cabinetBuilding.AllSlotCellsList(); foreach (IntVec3 storageCell in cabinetStorageCells) { foreach (Thing t in cabinetBuilding.Map.thingGrid.ThingsListAt(storageCell)) { if (t.Spawned && t.def.EverStorable(false)) { cabinetInvList.Add(t); } } } cabinetInvList = cabinetInvList.OrderBy((Thing x) => x.def.defName). ThenByDescending((Thing x) => { QualityCategory c; x.TryGetQuality(out c); return((int)c); }). ThenByDescending((Thing x) => (x.HitPoints / x.MaxHitPoints)).ToList(); float curY = 0f; Widgets.ListSeparator(ref curY, position.width, labelKey.Translate() #if DEBUG + " (" + cabinetBuilding.ToString() + ")" // extra info for debugging #endif ); curY += 5f; // Show count of contents, mass, etc: DisplayHeaderInfo(ref curY, position.width - 16f, cabinetBuilding, cabinetStorageCells.Count, cabinetInvList); Rect outRect = new Rect(0f, 10f + curY, position.width, position.height - curY); // viewRect is inside the ScrollView, so it starts at y=0f Rect viewRect = new Rect(0f, 0f, position.width - 16f, this.scrollViewHeight); Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect, true); curY = 0f; // now inside ScrollView for (int i = 0; i < cabinetInvList.Count; i++) { this.DrawThingRow(ref curY, viewRect.width, cabinetInvList[i]); } cabinetInvList.Clear(); if (Event.current.type == EventType.Layout) { this.scrollViewHeight = curY + 25f; //25f buffer } Widgets.EndScrollView(); GUI.EndGroup(); GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; }
protected override void FillTab() { buildingStorage = this.SelThing as Building_Storage; // don't attach this to other things, 'k? List <Thing> storedItems; //TODO: set fonts ize, etc. Text.Font = GameFont.Small; // 10f border: Rect frame = new Rect(10f, 10f, this.size.x - 10, this.size.y - 10); GUI.BeginGroup(frame); Text.Font = GameFont.Small; GUI.color = Color.white; /******* Title *******/ float curY = 0f; Widgets.ListSeparator(ref curY, frame.width, labelKey.Translate() #if DEBUG + " (" + buildingStorage.ToString() + ")" // extra info for debugging #endif ); curY += 5f; /****************** Header: Show count of contents, mass, etc: ****************/ //TODO: handle each cell separately? string header, headerTooltip; CompDeepStorage cds = buildingStorage.GetComp <CompDeepStorage>(); if (cds != null) { storedItems = cds.getContentsHeader(out header, out headerTooltip); } else { storedItems = CompDeepStorage.genericContentsHeader(buildingStorage, out header, out headerTooltip); } Rect tmpRect = new Rect(8f, curY, frame.width - 16, Text.CalcHeight(header, frame.width - 16)); Widgets.Label(tmpRect, header); // TODO: tooltip. Not that it's anything but null now curY += (tmpRect.height); //todo? /************* ScrollView ************/ /************* (contents) ************/ storedItems = storedItems.OrderBy((Thing x) => x.def.defName). ThenByDescending((Thing x) => { QualityCategory c; x.TryGetQuality(out c); return((int)c); }). ThenByDescending((Thing x) => (x.HitPoints / x.MaxHitPoints)).ToList(); // outRect is the is the rectangle that is visible on the screen: Rect outRect = new Rect(0f, 10f + curY, frame.width, frame.height - curY - GenUI.ListSpacing - TopPadding); // viewRect is inside the ScrollView, so it starts at y=0f Rect viewRect = new Rect(0f, 0f, frame.width - 16f, this.scrollViewHeight);//TODO: scrollbars are slightly too far to the right // 16f ensures plenty of room for scrollbars. // scrollViewHeight is set at the end of this call (via layout?); it is the proper // size the next time through, so it all works out. Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect, true); curY = 0f; // now inside ScrollView if (storedItems.Count < 1) { Widgets.Label(viewRect, "NoItemsAreStoredHere".Translate()); curY += 22; } string stringUpper = searchString.ToUpperInvariant(); List <Thing> itemToDraw = storedItems .Where(t => t.LabelNoCount .ToUpperInvariant() .Contains(stringUpper)).ToList(); GetIndexRangeFromScrollPosition(outRect.height, this.scrollPosition.y, out int from, out int to, GenUI.ListSpacing); to = to > itemToDraw.Count ? itemToDraw.Count : to; curY = from * GenUI.ListSpacing; for (int i = from; i < to; i++) { this.DrawThingRow(ref curY, viewRect.width, itemToDraw[i]); } if (Event.current.type == EventType.Layout) { this.scrollViewHeight = storedItems.Count * GenUI.ListSpacing + 25f; //25f buffer -- ?? } Widgets.EndScrollView(); searchString = Widgets.TextField( new Rect(0, outRect.yMax, outRect.width - GenUI.ScrollBarWidth, GenUI.ListSpacing) , searchString); GUI.EndGroup(); //TODO: this should get stored at top and set here. GUI.color = Color.white; //TODO: this should get stored at top and set here. // it should get set to whatever draw-row uses at top Text.Anchor = TextAnchor.UpperLeft; }