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; }
protected override void FillTab() { var storageBuilding = 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: var frame = new Rect(10f, 10f, size.x - 10, size.y - 10); GUI.BeginGroup(frame); Text.Font = GameFont.Small; GUI.color = Color.white; /******* Title *******/ var curY = 0f; Widgets.ListSeparator(ref curY, frame.width, labelKey.Translate() #if DEBUG + " (" + storageBuilding.ToString() + ")" // extra info for debugging #endif ); curY += 5f; /****************** Header: Show count of contents, mass, etc: ****************/ //TODO: handle each cell separately? string header, headerTooltip; var cds = storageBuilding.GetComp <CompDeepStorage>(); if (cds != null) { storedItems = cds.getContentsHeader(out header, out headerTooltip); } else { storedItems = CompDeepStorage.genericContentsHeader(storageBuilding, out header, out headerTooltip); } var 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(x => x.def.defName).ThenByDescending(x => { QualityCategory c; x.TryGetQuality(out c); return((int)c); }).ThenByDescending(x => x.HitPoints / x.MaxHitPoints).ToList(); // outRect is the is the rectangle that is visible on the screen: var outRect = new Rect(0f, 10f + curY, frame.width, frame.height - curY); // viewRect is inside the ScrollView, so it starts at y=0f var viewRect = new Rect(0f, 0f, frame.width - 16f, 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 scrollPosition, viewRect); curY = 0f; // now inside ScrollView if (storedItems.Count < 1) { Widgets.Label(viewRect, "NoItemsAreStoredHere".Translate()); curY += 22; } for (var i = 0; i < storedItems.Count; i++) { DrawThingRow(ref curY, viewRect.width, storedItems[i]); } if (Event.current.type == EventType.Layout) { scrollViewHeight = curY + 25f; //25f buffer -- ?? } Widgets.EndScrollView(); 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; }