protected void DoSubRow(Rect rect, string key, HybridExtensionExposable extension, List <string> removeelements) { bool isPawnKind = false; int value = (int)extension.hybridInfo.TryGetValue(key); string valuestr = value.ToString(); string label = null; label = DefDatabase <ThingDef> .GetNamedSilentFail(key)?.label; if (label == null) { label = DefDatabase <PawnKindDef> .GetNamedSilentFail(key)?.label ?? "Undefined"; isPawnKind = true; } Rect buttonRect = new Rect(rect.xMax - 90f, rect.y, 80f, rect.height); if (Widgets.ButtonText(buttonRect, "Delete")) { removeelements.Add(key); } buttonRect.x -= 80f; if (!isPawnKind) { if (Widgets.ButtonText(buttonRect, "PawnKind")) { List <FloatMenuOption> list = new List <FloatMenuOption>(); if (!VariousDefOf.AllKinds.NullOrEmpty()) { foreach (PawnKindDef def in VariousDefOf.AllKinds) { if (def.race.defName == key) { if (extension.hybridInfo.ContainsKey(def.defName)) { continue; } else { list.Add(new FloatMenuOption(def.label, delegate { extension.hybridInfo.Add(def.defName, 1.0f); }, Widgets.GetIconFor(def.race), Color.white)); } } } } if (!list.NullOrEmpty()) { Find.WindowStack.Add(new FloatMenu(list)); } else { SoundDefOf.ClickReject.PlayOneShotOnCamera(); } } buttonRect.x -= 80f; } else { Widgets.Label(buttonRect, " PawnKind"); buttonRect.x -= 80f; } label += ": " + key; Widgets.Label(rect, " - " + label); Widgets.TextFieldNumeric(buttonRect, ref value, ref valuestr, 0, 9999999); extension.hybridInfo.SetOrAdd(key, value); buttonRect.x -= 80f; Widgets.Label(buttonRect, String.Format("{0,0:P2}", value / totalWeight)); Widgets.DrawHighlightIfMouseover(rect); TooltipHandler.TipRegion(rect, Translations.CustomHybrid_Tooltip(info.GetDef?.label ?? "Undefined", extension.GetDef?.label ?? "Undefined", label, String.Format("{0,0:0.########%}", value / totalWeight))); }
protected void DoRow(Rect rect, HybridExtensionExposable extension) { Rect mainRect = new Rect(rect.x, rect.y, rect.width, rowH); Rect subRect = new Rect(rect.x, rect.y + rowH, rect.width, rect.height - rowH); Rect buttonRect = new Rect(rect.xMax - 90f, rect.y, 80f, rowH); Widgets.Label(mainRect, extension.GetDef?.label ?? "Undefined"); if (Widgets.ButtonText(buttonRect, "Delete")) { removeList.Add(extension); } buttonRect.x -= 80f; if (Widgets.ButtonText(buttonRect, "Add")) { List <FloatMenuOption> list = new List <FloatMenuOption>(); if (!VariousDefOf.AllRaces.NullOrEmpty()) { foreach (ThingDef def in VariousDefOf.AllRaces) { if (def.race != null) { if (extension.hybridInfo.ContainsKey(def.defName)) { continue; } else { list.Add(new FloatMenuOption(def.label, delegate { extension.hybridInfo.Add(def.defName, 1.0f); }, Widgets.GetIconFor(def), Color.white)); } } } } if (!list.NullOrEmpty()) { list.SortBy(x => x.Label); Find.WindowStack.Add(new FloatMenu(list)); } } buttonRect.x -= 80f; Listing_Standard sublist = new Listing_Standard(); sublist.Begin(subRect); List <string> removeelements = new List <string>(); if (!extension.hybridInfo.EnumerableNullOrEmpty()) { totalWeight = 0; foreach (KeyValuePair <string, float> element in extension.hybridInfo) { totalWeight += element.Value; } List <string> keys = new List <string>(extension.hybridInfo.Keys); foreach (string key in keys) { DoSubRow(sublist.GetRect(rowH), key, extension, removeelements); } } if (!removeelements.NullOrEmpty()) { foreach (string key in removeelements) { extension.hybridInfo.Remove(key); } } sublist.End(); Widgets.DrawHighlightIfMouseover(rect); }