public void Save() { CompLua luaComp = SelThing.TryGetComp <CompLua>(); luaComp.code = textInTerminal; luaComp.UpdateCode(); Messages.Message("LuaSaveSuccessful".Translate(), new MessageTypeDef()); }
protected override void FillTab() { var rect = new Rect(0f, 0f, 300f, 400f).ContractedBy(20f); if (SelThing.GetUniqueLoadID() != selThingId) { scrollbarPosition = Vector2.zero; selThingId = SelThing.GetUniqueLoadID(); } Widgets.TextAreaScrollable(rect, SelThing.TryGetComp <CompLua>().Stdout, ref scrollbarPosition, true); }
protected override void FillTab() { var selectedCompInfusion = SelThing.TryGetComp <CompInfused>(); Text.Font = GameFont.Medium; GUI.color = selectedCompInfusion.InfusedLabelColor; //Label var rectBase = new Rect(0f, 0f, WinSize.x, WinSize.y).ContractedBy(10f); var rectLabel = rectBase; var label = selectedCompInfusion.GetInfusionLabel(false).CapitalizeFirst(); Widgets.Label(rectLabel, label); //Quality var rectQuality = rectBase; rectQuality.yMin += Text.CalcHeight(label, rectBase.width); Text.Font = GameFont.Small; QualityCategory qc; selectedCompInfusion.parent.TryGetQuality(out qc); var subLabelBuilder = new StringBuilder(); subLabelBuilder.Append(qc.GetLabel().CapitalizeFirst()) .Append(" ") .Append(ResourceBank.Strings.Quality) .Append(" "); if (selectedCompInfusion.parent.Stuff != null) { subLabelBuilder.Append(selectedCompInfusion.parent.Stuff.LabelAsStuff).Append(" "); } subLabelBuilder.Append(selectedCompInfusion.parent.def.label); var subLabel = subLabelBuilder.ToString(); Widgets.Label(rectQuality, subLabel); GUI.color = Color.white; //Infusion descriptions Text.Anchor = TextAnchor.UpperLeft; var rectDesc = rectBase; rectDesc.yMin += rectQuality.yMin + Text.CalcHeight(subLabel, rectBase.width); Text.Font = GameFont.Small; Widgets.Label(rectDesc, selectedCompInfusion.GetDescriptionInfused()); }
protected override void FillTab() { var selected = SelThing.TryGetComp <CompInfused>(); var container = new Rect(0f, 0f, size.x, size.y).ContractedBy(16f); // Label var labelView = new Rect(container.xMin, container.yMin, container.xMax * 0.85f, container.yMax); float labelHeight = DrawLabel(selected, labelView) + 4f; // Quality var qualityView = new Rect(container.xMin, labelView.yMin + labelHeight, container.width, container.yMax - labelHeight); float qualityHeight = DrawQuality(selected, qualityView); // Infusion descriptions var descView = new Rect(container.xMin, qualityView.yMin + qualityHeight, container.xMax - 6.0f, container.yMax - qualityView.yMin - qualityHeight); DrawInfusions(selected, descView); }
protected override void FillTab() { if (SelThing.GetUniqueLoadID() != selThingReference) { RefreshTextInTerminal(); selThingReference = SelThing.GetUniqueLoadID(); } var inRect = new Rect(0f, 0f, WinSize.x, WinSize.y).ContractedBy(20f);//inner rectangle var contentRect = new Rect(inRect); contentRect.yMax -= 20f; var style = new GUIStyle(Text.CurTextFieldStyle) //Construct our GUIStyle { wordWrap = true }; if (Resources.CourierNew != null) //Implicit conversion to bool { style.font = Resources.CourierNew; } textInTerminal = GUI.TextArea(contentRect, textInTerminal, style); var buttonsRect = inRect.BottomPartPixels(18f); var margin = 5f; var width = (inRect.width - margin) / 2f; var leftRect = buttonsRect.LeftPartPixels(width); var rightRect = buttonsRect.RightPartPixels(width); var save = Widgets.ButtonText(leftRect, "LuaSave".Translate()); var help = Widgets.ButtonText(rightRect, "LuaHelp".Translate());//TODO: Implement help if (save) { Save(); } if (help) { Find.WindowStack.Add(new Dialog_LuaHelp()); } }
public void RefreshTextInTerminal() { textInTerminal = SelThing.TryGetComp <CompLua>().code; }
protected override void FillTab() { CompPowerTracker compPower = SelThing.TryGetComp <CompPowerTracker>(); if (compPower == null) { return; } PowerNet powerNet = compPower.powerNet; if (powerNet == null) { return; } Widgets.BeginScrollView( new Rect(default(Vector2), size).ContractedBy(GenUI.GapTiny), ref scrollPos, new Rect(default(Vector2), new Vector2(size.x - GenUI.GapTiny * 2 - GenUI.ScrollBarWidth, lastY)) ); float yref = 10; IEnumerable <IGrouping <CompPowerTracker.PowerType, IGrouping <ThingDef, CompPowerTracker> > > categories = powerNet.batteryComps.ConvertAll((c) => c.parent.GetComp <CompPowerTracker>()) .Concat(powerNet.powerComps.ConvertAll((c) => c.parent.GetComp <CompPowerTracker>())) .GroupBy((c) => c.parent.def) .GroupBy((d) => CompPowerTracker.powerTypeFor(d.Key)); foreach (IGrouping <CompPowerTracker.PowerType, IGrouping <ThingDef, CompPowerTracker> > type in categories) { float p = type.Sum((g) => g.Sum((t) => t.PowerUsage)); float m = type.Sum((g) => g.Sum((t) => t.maxPowerUsage)); Rect rect = new Rect(150, yref, size.x - 172, Text.SmallFontHeight); Widgets.FillableBarLabeled(rect, Math.Abs(p / m), 0, ""); string Label = "{0}W".Formatted(p.ToString("0")); float Width = GenUI.GetWidthCached(Label); Widgets.DrawRectFast(new RectOffset(-4, -4, -4, -4).Add(rect).LeftPartPixels(Width + 4), Color.black); Widgets.Label(new RectOffset(-4, 0, 0, 0).Add(rect), Label); Widgets.ListSeparator(ref yref, rect.width, "{0}".Formatted(CompPowerTracker.powerTypeString[(int)type.Key])); float maxPowerUsage = type.Max((g) => g.Sum((c) => Math.Abs(c.maxPowerUsage))); yref += GenUI.GapTiny; foreach (IGrouping <ThingDef, CompPowerTracker> defs in type) { // Begin group; All future GUI elements are relative to this group GUI.BeginGroup(new Rect(0, yref, size.x, Text.SmallFontHeight + GenUI.GapTiny * 2)); // Make a rect that is the size of our group rect = new Rect(0, 0, size.x - GenUI.GapTiny * 2 - GenUI.ScrollBarWidth, Text.SmallFontHeight + GenUI.GapTiny * 2); // Draw a background behind our group Widgets.DrawOptionSelected(rect); if (!collapseTab.ContainsKey(defs.Key)) { collapseTab.Add(defs.Key, false); } if (Widgets.ButtonText(rect.LeftPartPixels(rect.height).ContractedBy(GenUI.GapTiny), collapseTab[defs.Key] ? "-" : "+")) { collapseTab[defs.Key] = !collapseTab[defs.Key]; } rect.xMin += rect.height; Widgets.Label(rect.LeftPartPixels(150).ContractedBy(GenUI.GapTiny), "{0} {1}".Formatted(defs.Count(), defs.Key.LabelCap)); rect.xMin += 150; Widgets.FillableBarLabeled(rect.ContractedBy(GenUI.GapTiny), defs.Sum((c) => Math.Abs(c.PowerUsage)) / maxPowerUsage, 50, "Power"); Label = "{0}W".Formatted(defs.Sum((c) => c.PowerUsage).ToString("0")); Width = GenUI.GetWidthCached(Label); rect = new RectOffset(-58, 0, -4, -4).Add(rect).LeftPartPixels(Width + 4); Widgets.DrawRectFast(new RectOffset(0, 0, -4, -4).Add(rect), Color.black); Widgets.Label(rect, Label); yref += GenUI.ListSpacing + GenUI.GapTiny; GUI.EndGroup(); if (collapseTab[defs.Key]) { foreach (CompPowerTracker comp in defs) { comp.DrawGUI(ref yref, size.x, defs.Max((c) => c.maxPowerUsage)); } } } } Widgets.EndScrollView(); lastY = yref; }
protected override void FillTab() { float fieldHeight = 30.0f; PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.PrisonerTab, KnowledgeAmount.FrameDisplayed); Text.Font = GameFont.Small; Rect innerRect1 = new Rect(0.0f, 0.0f, size.x, size.y).ContractedBy(10f); GUI.BeginGroup(innerRect1); Rect mountedRect = new Rect(0.0f, 30.0f, innerRect1.width, fieldHeight); float mountedRectY = mountedRect.y; Widgets.ListSeparator(ref mountedRectY, innerRect1.width, txtDriver.Translate()); mountedRect.y += fieldHeight; Rect thingIconRect = new Rect(mountedRect.x, mountedRect.y, 30f, fieldHeight); Rect thingLabelRect = new Rect(mountedRect.x + 35f, mountedRect.y + 5.0f, innerRect1.width - 35f, fieldHeight); Rect thingButtonRect = new Rect(mountedRect.x, mountedRect.y, innerRect1.width, fieldHeight); CompMountable compMountable = SelThing.TryGetComp <CompMountable>(); if (compMountable.IsMounted) { Pawn driver = compMountable.Driver; Widgets.ThingIcon(thingIconRect, driver); Widgets.Label(thingLabelRect, driver.Label); if (Mouse.IsOver(thingLabelRect)) { GUI.DrawTexture(thingLabelRect, TexUI.HighlightTex); } if (Event.current.button == 1 && Widgets.ButtonInvisible(thingButtonRect)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); FloatMenuOption dismount = new FloatMenuOption("Dismount".Translate(driver.LabelShort), () => { compMountable.Dismount(); }); options.Add(dismount); Find.WindowStack.Add(new FloatMenu(options)); } thingIconRect.y += fieldHeight; thingLabelRect.y += fieldHeight; } Rect storageRect = new Rect(0.0f, thingIconRect.y, innerRect1.width, fieldHeight); float storageRectY = storageRect.y; Widgets.ListSeparator(ref storageRectY, innerRect1.width, txtStorage.Translate()); storageRect.y += fieldHeight; thingIconRect.y = storageRect.y; thingLabelRect.y = storageRect.y; thingButtonRect.y = storageRect.y; #region Cart Vehicle_Cart cart = SelThing as Vehicle_Cart; if (cart != null) { foreach (Thing thing in cart.storage) { if (thing.ThingID.IndexOf("Human_Corpse") > -1) { Widgets.DrawTextureFitted(thingIconRect, ContentFinder <Texture2D> .Get("Things/Pawn/IconHuman_Corpse"), 1.0f); } else if (thing.ThingID.IndexOf("Corpse") > -1) { Widgets.DrawTextureFitted(thingIconRect, ContentFinder <Texture2D> .Get("Things/Pawn/IconAnimal_Corpse"), 1.0f); } else { Widgets.ThingIcon(thingIconRect, thing); } Widgets.Label(thingLabelRect, thing.LabelCap); if (Event.current.button == 1 && Widgets.ButtonInvisible(thingButtonRect)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); options.Add(new FloatMenuOption("ThingInfo".Translate(), () => { Find.WindowStack.Add(new Dialog_InfoCard(thing)); })); options.Add(new FloatMenuOption("DropThing".Translate(), () => { Thing dummy; cart.storage.TryDrop(thing, SelThing.Position, ThingPlaceMode.Near, out dummy); })); Find.WindowStack.Add(new FloatMenu(options, thing.LabelCap)); } if (Mouse.IsOver(thingLabelRect)) { GUI.DrawTexture(thingLabelRect, TexUI.HighlightTex); } TooltipHandler.TipRegion(thingLabelRect, thing.def.LabelStyled()); thingIconRect.y += fieldHeight; thingLabelRect.y += fieldHeight; } if (Widgets.ButtonText(new Rect(180f, 400f, 100f, 30f), "Drop All")) { cart.storage.TryDropAll(SelThing.Position, ThingPlaceMode.Near); } } #endregion GUI.EndGroup(); }