public void DoBridgeList(Listing_Standard options) { options.GapLine(); Text.Font = GameFont.Medium; options.Label("TD.SettingsPreferredBridge".Translate()); Text.Font = GameFont.Small; float itemHeight = Text.LineHeight; Rect reorderRect = options.GetRect(BridgelikeTerrain.allBridgeTerrains.Count * itemHeight + 2); Widgets.DrawBox(reorderRect); Rect labelRect = reorderRect.ContractedBy(1).TopPartPixels(itemHeight); Rect globalDragRect = labelRect; globalDragRect.position = GUIUtility.GUIToScreenPoint(globalDragRect.position); int reorderID = ReorderableWidget.NewGroup_NewTemp( BridgelikeTerrain.Reorder, ReorderableDirection.Vertical, extraDraggedItemOnGUI : delegate(int index, Vector2 dragStartPos) { Rect dragRect = globalDragRect; //copy it in so multiple frames don't edit the same thing dragRect.y += index * itemHeight; //i-th item dragRect.position += Event.current.mousePosition - dragStartPos; //adjust for mouse vs starting point //Same id 34003428 as GenUI.DrawMouseAttachment Find.WindowStack.ImmediateWindow(34003428, dragRect, WindowLayer.Super, () => DefLabelWithIconButNoTooltipCmonReally(dragRect.AtZero(), BridgelikeTerrain.allBridgeTerrains[index], 0) ); }); foreach (TerrainDef terDef in BridgelikeTerrain.allBridgeTerrains) { Widgets.DefLabelWithIcon(labelRect, terDef, 0); ReorderableWidget.Reorderable(reorderID, labelRect); labelRect.y += itemHeight; } options.Label("TD.SettingsBridgeResources".Translate()); }
public override void FillContents(Listing_Standard standard, Rect inRect) { if (Find.Selector.selected.Count == 0) { Close(); return; } { var rect = standard.GetRect(30); Text.Font = GameFont.Tiny; var searchRect = new Rect(0, 0, rect.width, 20); if (Widgets.ButtonImage(searchRect.LeftPartPixels(20), TexButton.CloseXSmall)) { Close(); } searchString = Widgets.TextField(new Rect(searchRect.position + new Vector2(25, 0), searchRect.size - new Vector2(55, 0)), searchString).ToLower(); } { standard.Gap(5); var scrollRect = new Rect(inRect.position + new Vector2(0, 50), inRect.size - new Vector2(0, 50)); var section = standard.BeginSection_NewTemp(scrollRect.height); standard.EndSection(section); standard.BeginScrollView(new Rect(scrollRect.position + new Vector2(5, 0), scrollRect.size - new Vector2(10, 10)), ref scrollPosition, ref viewRect); Text.Font = GameFont.Tiny; foreach (Def def in defs) { if (def.label.ToLower().Contains(searchString)) { var rect = standard.GetRect(50); Widgets.DefLabelWithIcon(rect, def); if (Widgets.ButtonInvisible(rect)) { onSelect(def); Close(); } } } standard.EndScrollView(ref viewRect); } }
public override void DoWindowContents(Rect inRect) { float num = 40f; Rect rect = new Rect(0f, 0f, inRect.width, 40f); Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(rect, "SellableItemsTitle".Translate().CapitalizeFirst()); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleCenter; ITraderRestockingInfoProvider traderRestockingInfoProvider = trader as ITraderRestockingInfoProvider; if (traderRestockingInfoProvider != null) { int nextRestockTick = traderRestockingInfoProvider.NextRestockTick; if (nextRestockTick != -1) { Widgets.Label(label: "NextTraderRestock".Translate((nextRestockTick - Find.TickManager.TicksGame).TicksToDays().ToString("0.0")), rect: new Rect(0f, num, inRect.width, 20f)); num += 20f; } else if (!traderRestockingInfoProvider.EverVisited) { Widgets.Label(new Rect(0f, num, inRect.width, 20f), "TraderNotVisitedYet".Translate()); num += 20f; } else if (traderRestockingInfoProvider.RestockedSinceLastVisit) { Widgets.Label(new Rect(0f, num, inRect.width, 20f), "TraderRestockedSinceLastVisit".Translate()); num += 20f; } } Text.Anchor = TextAnchor.UpperLeft; inRect.yMin += 64f + num; Widgets.DrawMenuSection(inRect); TabDrawer.DrawTabs(inRect, tabs, 2); inRect = inRect.ContractedBy(17f); GUI.BeginGroup(inRect); Rect rect2 = inRect.AtZero(); DoBottomButtons(rect2); Rect outRect = rect2; outRect.yMax -= 65f; List <ThingDef> sellableItemsInCategory = GetSellableItemsInCategory(currentCategory, pawnsTabOpen); if (sellableItemsInCategory.Any()) { float height = (float)sellableItemsInCategory.Count * 24f; num = 0f; Rect viewRect = new Rect(0f, 0f, outRect.width - 16f, height); Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect); float num2 = scrollPosition.y - 24f; float num3 = scrollPosition.y + outRect.height; for (int i = 0; i < sellableItemsInCategory.Count; i++) { if (num > num2 && num < num3) { Widgets.DefLabelWithIcon(new Rect(0f, num, viewRect.width, 24f), sellableItemsInCategory[i]); } num += 24f; } Widgets.EndScrollView(); } else { Widgets.NoneLabel(0f, outRect.width); } GUI.EndGroup(); }
public void DrawFireSupportBox(float x, float y, float rowHeight) { //Set Text anchor and font GameFont fontBefore = Text.Font; TextAnchor anchorBefore = Text.Anchor; Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Small; for (int i = 0; i <= selectedSupport.projectiles.Count; i++) { //Declare Rects Rect text = new Rect(x + 2, y + 2 + i * rowHeight + scroll, rowHeight - 4, rowHeight - 4); Rect cost = deriveRectRow(text, 2, 0, 150); Rect icon = deriveRectRow(cost, 2, 0, 250); //Rect name = deriveRectRow(icon, 2, 0, 150); Rect options = deriveRectRow(icon, 2, 0, 74); Rect upArrow = deriveRectRow(options, 12, 0, rowHeight - 4, rowHeight - 4); Rect downArrow = deriveRectRow(upArrow, 4); Rect delete = deriveRectRow(downArrow, 12); //Create outside box last to encapsulate entirety Rect box = new Rect(x, y + i * rowHeight + scroll, delete.x + delete.width + 4 - x, rowHeight); Widgets.DrawHighlight(box); Widgets.DrawMenuSection(box); if (i == selectedSupport.projectiles.Count) { //If on last row Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(text, i.ToString()); if (Widgets.ButtonTextSubtle(icon, "Add new projectile")) { //if creating new projectile List <FloatMenuOption> thingOptions = new List <FloatMenuOption>(); foreach (ThingDef def in selectedSupport.returnFireSupportOptions()) { thingOptions.Add(new FloatMenuOption( def.LabelCap + " - " + Math.Round(def.BaseMarketValue * 1.5, 2).ToString(), delegate { selectedSupport.projectiles.Add(def); }, def)); } if (!thingOptions.Any()) { thingOptions.Add( new FloatMenuOption("No available projectiles found", delegate { })); } Find.WindowStack.Add(new FloatMenu(thingOptions)); } } else { //if on row with projectile Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(text, i.ToString()); if (Widgets.ButtonTextSubtle(icon, "")) { List <FloatMenuOption> thingOptions = new List <FloatMenuOption>(); foreach (ThingDef def in selectedSupport.returnFireSupportOptions()) { int k = i; thingOptions.Add(new FloatMenuOption( def.LabelCap + " - " + Math.Round(def.BaseMarketValue * 1.5, 2).ToString(), delegate { selectedSupport.projectiles[k] = def; }, def)); } if (!thingOptions.Any()) { thingOptions.Add( new FloatMenuOption("No available projectiles found", delegate { })); } Find.WindowStack.Add(new FloatMenu(thingOptions)); } Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(cost, "$ " + (Math.Round(selectedSupport.projectiles[i].BaseMarketValue * 1.5, 2))); //ADD in future mod setting for firesupport cost Widgets.DefLabelWithIcon(icon, selectedSupport.projectiles[i]); if (Widgets.ButtonTextSubtle(options, "Options")) { //If clicked options button int k = i; List <FloatMenuOption> listOptions = new List <FloatMenuOption> { new FloatMenuOption("Insert Projectile Above Slot", delegate { List <FloatMenuOption> thingOptions = new List <FloatMenuOption>(); foreach (ThingDef def in selectedSupport.returnFireSupportOptions()) { thingOptions.Add(new FloatMenuOption( def.LabelCap + " - " + Math.Round(def.BaseMarketValue * 1.5, 2).ToString(), delegate { Log.Message("insert at " + k); selectedSupport.projectiles.Insert(k, def); }, def)); } if (!thingOptions.Any()) { thingOptions.Add(new FloatMenuOption("No available projectiles found", delegate { })); } Find.WindowStack.Add(new FloatMenu(thingOptions)); }), new FloatMenuOption("Duplicate", delegate { ThingDef tempDef = selectedSupport.projectiles[k]; List <FloatMenuOption> thingOptions = new List <FloatMenuOption>(); thingOptions.Add(new FloatMenuOption("1x", delegate { for (int l = 0; l < 1; l++) { if (k == selectedSupport.projectiles.Count - 1) { selectedSupport.projectiles.Add(tempDef); } else { selectedSupport.projectiles.Insert(k + 1, tempDef); } } })); thingOptions.Add(new FloatMenuOption("5x", delegate { for (int l = 0; l < 5; l++) { if (k == selectedSupport.projectiles.Count - 1) { selectedSupport.projectiles.Add(tempDef); } else { selectedSupport.projectiles.Insert(k + 1, tempDef); } } })); thingOptions.Add(new FloatMenuOption("10x", delegate { for (int l = 0; l < 10; l++) { if (k == selectedSupport.projectiles.Count - 1) { selectedSupport.projectiles.Add(tempDef); } else { selectedSupport.projectiles.Insert(k + 1, tempDef); } } })); thingOptions.Add(new FloatMenuOption("20x", delegate { for (int l = 0; l < 20; l++) { if (k == selectedSupport.projectiles.Count - 1) { selectedSupport.projectiles.Add(tempDef); } else { selectedSupport.projectiles.Insert(k + 1, tempDef); } } })); thingOptions.Add(new FloatMenuOption("50x", delegate { for (int l = 0; l < 50; l++) { if (k == selectedSupport.projectiles.Count - 1) { selectedSupport.projectiles.Add(tempDef); } else { selectedSupport.projectiles.Insert(k + 1, tempDef); } } })); Find.WindowStack.Add(new FloatMenu(thingOptions)); }) }; Find.WindowStack.Add(new FloatMenu(listOptions)); } if (Widgets.ButtonTextSubtle(upArrow, "")) { //if click up arrow button if (i != 0) { ThingDef temp = selectedSupport.projectiles[i]; selectedSupport.projectiles[i] = selectedSupport.projectiles[i - 1]; selectedSupport.projectiles[i - 1] = temp; } } Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(upArrow, "^"); if (Widgets.ButtonTextSubtle(downArrow, "")) { //if click down arrow button if (i != selectedSupport.projectiles.Count - 1) { ThingDef temp = selectedSupport.projectiles[i]; selectedSupport.projectiles[i] = selectedSupport.projectiles[i + 1]; selectedSupport.projectiles[i + 1] = temp; } } Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(downArrow, "v"); if (Widgets.ButtonTextSubtle(delete, "")) { //if click delete button selectedSupport.projectiles.RemoveAt(i); } Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(delete, "X"); } } //Reset Text anchor and font Text.Font = fontBefore; Text.Anchor = anchorBefore; }
public static void DrawCard(Vector2 size, CompToggleDef compToggleDef) { var selectedThing = compToggleDef.parent; var toggleDefs = compToggleDef.Props.toggleDefs; var rect = new Rect(0f, ExtraTopPadding, size.x, size.y - ExtraTopPadding).ContractedBy(CardPadding); var rowCount = toggleDefs.Count; var yMin = -RowHeight; var yMax = rect.height; if (rowCount > MaxRows) { if (lastSelectedThing != selectedThing) { lastSelectedThing = selectedThing; scrollPosition.y = toggleDefs.IndexOf(selectedThing.def) * (RowHeight + RowGap); } var viewRect = new Rect(0f, 0f, rect.width - GenUI.ScrollBarWidth - CardPadding, TotalRowHeight(rowCount)); Widgets.BeginScrollView(rect, ref scrollPosition, viewRect); rect.width = viewRect.width; yMin += scrollPosition.y; yMax += scrollPosition.y; } else { GUI.BeginGroup(rect); } // Add the rows for each toggle def. var y = 0f; foreach (var toggleDef in toggleDefs) { if (y > yMax) { break; } if (y >= yMin) { var rowRect = new Rect(0f, y, rect.width, RowHeight); var iconAndLabelRect = rowRect.LeftPartPixels(rowRect.width - (Widgets.RadioButtonSize + DefLabelOffsetX)); Widgets.DefLabelWithIcon(iconAndLabelRect, toggleDef, DefIconMargin, DefLabelOffsetX); var iconRect = new Rect(DefIconMargin, y + DefIconMargin, DefIconSize, DefIconSize); if (Widgets.ButtonInvisible(iconRect)) { Find.WindowStack.Add(new Dialog_InfoCard(toggleDef)); } var isSelected = selectedThing.def == toggleDef; RadioButtonDraw(rowRect.width - Widgets.RadioButtonSize, y, isSelected); if (!isSelected && Widgets.ButtonInvisible(rowRect.RightPartPixels(rowRect.width - iconRect.xMax - DefLabelOffsetX))) { SwapThing(selectedThing, toggleDef); break; } } y += RowHeight + RowGap; } if (rowCount > MaxRows) { Widgets.EndScrollView(); } else { GUI.EndGroup(); } }
public static void Postfix(Rect rect) { Text.CurFontStyle.fontStyle = FontStyle.Bold; Widgets.Label(rect.TopPartPixels(25), "Dilated races"); Text.CurFontStyle.fontStyle = FontStyle.Normal; var font = Text.Font; var anchor = Text.Anchor; Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.MiddleLeft; rect.yMin += 25; var searchRect = rect.TopPartPixels(25); searchString = Widgets.TextField(searchRect, searchString).ToLower().Trim(); rect.yMin += 30; if (curSelection != null) { var height = 128; var selectionRect = rect.TopPartPixels(height); Widgets.DrawMenuSection(selectionRect); Text.Font = GameFont.Tiny; Widgets.DefLabelWithIcon(selectionRect.TopPartPixels(54), curSelection.pawnDef); if (Widgets.ButtonImage(selectionRect.RightPartPixels(30).TopPartPixels(30).ContractedBy(5), TexButton.CloseXSmall)) { curSelection = null; return; } selectionRect.yMin += 54; standard.Begin(selectionRect.ContractedBy(3)); Text.Font = GameFont.Tiny; standard.CheckboxLabeled($"Enable dilation for {curSelection.pawnDef.label}", ref curSelection.dilated); standard.CheckboxLabeled($"Enable dilation for all factions except Player", ref curSelection.ignoreFactions); standard.CheckboxLabeled($"Enable dilation for Player faction", ref curSelection.ignorePlayerFaction); standard.End(); rect.yMin += height + 8; } else if (Find.Selector.selected.Count == 1 && Find.Selector.selected.First() is Pawn pawn) { var height = 128; var selectionRect = rect.TopPartPixels(height); var model = pawn.GetPerformanceModel(); if (model != null) { model.DrawGraph(selectionRect, 2000); rect.yMin += height + 8; } } Widgets.DrawMenuSection(rect); rect = rect.ContractedBy(2); viewRect.size = rect.size; viewRect.height = 60 * Context.settings.raceSettings.Count; viewRect.width -= 15; Widgets.BeginScrollView(rect, ref scrollPosition, viewRect.AtZero()); Rect curRect = viewRect.TopPartPixels(54); curRect.width -= 15; var counter = 0; foreach (var element in Context.settings.raceSettings) { if (!element.pawnDef.label.ToLower().Contains(searchString)) { continue; } counter++; if (counter % 2 == 0) { Widgets.DrawBoxSolid(curRect, new Color(0.1f, 0.1f, 0.1f, 0.2f)); } Widgets.DrawHighlightIfMouseover(curRect); Widgets.DefLabelWithIcon(curRect.ContractedBy(3), element.pawnDef); if (Widgets.ButtonInvisible(curRect)) { curSelection = element; break; } curRect.y += 58; } Text.Font = font; Text.Anchor = anchor; Widgets.EndScrollView(); SoyuzSettingsUtility.CacheSettings(); }