public static bool ButtonImageOn(Rect rect, Texture2D tex, bool doMouseoverSound = true) { var atlas = ButtonBgAtlas; if (Mouse.IsOver(rect)) { atlas = ButtonBgAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = ButtonBgAtlasClick; } } Widgets.DrawAtlas(rect, atlas); if (doMouseoverSound) { MouseoverSounds.DoRegion(rect); } GUI.DrawTexture(rect.ScaledBy(0.75f), (Texture)tex); return(Widgets.ButtonInvisible(rect, false)); }
public virtual void DoButton(Rect rect) { Text.Font = GameFont.Small; string labelCap = this.def.LabelCap; if ((!this.def.validWithoutMap || this.def == MainButtonDefOf.World) && Find.VisibleMap == null) { Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas); if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect)) { Event.current.Use(); } return; } string label = labelCap; float buttonBarPercent = this.ButtonBarPercent; SoundDef mouseoverCategory = SoundDefOf.MouseoverCategory; if (Widgets.ButtonTextSubtle(rect, label, buttonBarPercent, -1f, mouseoverCategory, default(Vector2))) { this.InterfaceTryActivate(); } if (Find.MainTabsRoot.OpenTab != this.def && !Find.WindowStack.NonImmediateDialogWindowOpen) { UIHighlighter.HighlightOpportunity(rect, this.def.cachedHighlightTagClosed); } if (!this.def.description.NullOrEmpty()) { TooltipHandler.TipRegion(rect, this.def.description); } }
public static void Draw() { Rect rect = new Rect(_x, _y, GenUI.ListSpacing, GenUI.ListSpacing * 2); Find.WindowStack.ImmediateWindow( typeof(StatPanelToggle).GetHashCode() , rect , WindowLayer.GameUI , () => { Texture2D atlas = TexResource.ButtonBGAtlas; if (Mouse.IsOver(rect)) { atlas = TexResource.ButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = TexResource.ButtonBGAtlasClick; } } Widgets.DrawAtlas(rect, atlas); Widgets.ButtonText(rect.AtZero(), string.Empty); GUI.DrawTexture(new Rect(0, 0, GenUI.SmallIconSize, GenUI.SmallIconSize), TexResource.TriangleRight); } , true , false); }
//button text subtle copied from Rimworld basecode but with minor changes to fit this UI public static bool ButtonTextSubtleCentered(Rect rect, string label, Vector2 functionalSizeOffset = default(Vector2)) { Rect rect2 = rect; rect2.width += functionalSizeOffset.x; rect2.height += functionalSizeOffset.y; bool flag = false; if (Mouse.IsOver(rect2)) { flag = true; GUI.color = GenUI.MouseoverColor; } Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas); GUI.color = Color.white; Rect rect3 = new Rect(rect); if (flag) { rect3.x += 2f; rect3.y -= 2f; } Text.Anchor = TextAnchor.MiddleCenter; Text.WordWrap = false; Text.Font = GameFont.Small; Widgets.Label(rect3, label); Text.Anchor = TextAnchor.MiddleLeft; Text.WordWrap = true; return(Widgets.ButtonInvisible(rect2, false)); }
private void DrawSlotInfo(Rect rect, ModuleSlot <MKArmorModule> slot, ArmorSlot armorSlot) { Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas); if (slot.Module != null) { GUI.DrawTexture(new Rect(rect.x + 5, rect.y + 5, 100, 100), slot.Module.def.IconImage); string fullDesc = $"{slot.Module.def.LabelCap}\n\n{slot.Module.def.description}\n{slot.Module.StatDescription()}"; TooltipHandler.TipRegion(rect, new TipSignal(fullDesc, 4321211)); if (Widgets.ButtonInvisible(rect)) { Find.WindowStack.Add(new FloatMenu(new List <FloatMenuOption>() { new FloatMenuOption("Station_UnloadModule".Translate(), delegate { if (CellFinder.TryFindRandomCellNear(mkStation.Position, mkStation.Map, 3, null, out IntVec3 result)) { GenSpawn.Spawn(slot.Item, result, mkStation.Map); slot.Item = null; slot.Module = null; mkStation.ContainedArmor.Notify_ModulesChanges(); } else { Messages.Message("NotEnoughSpace".Translate(), MessageTypeDefOf.NeutralEvent, false); } }) }));
private void DoRow(Listing listing, DefState <T> state, int reorderableGroup, bool isCheckbox) { var rect = listing.GetRect(26f); ReorderableWidget.Reorderable(reorderableGroup, rect); Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas); rect.xMin += 28f; if (isCheckbox) { var wasEnabled = state.Enabled; Widgets.CheckboxLabeled(rect, state.Def.LabelCap, ref state.Enabled); if (state.Enabled != wasEnabled) { _applyChanges(); } } else { Widgets.Label(rect, state.Def.LabelCap); } }
static bool KeyGroupButton(Rect rect, string keyGroup, List <FloatMenuOption> floatMenuList, Color textColor) { MouseoverSounds.DoRegion(rect); //Texture2D atlas = Widgets.ButtonSubtleAtlas; Texture2D atlas = TexUI.HighlightTex; Color color = GUI.color; GUI.color = textColor; if (Mouse.IsOver(rect)) { Widgets.DrawAtlas(rect, atlas); } TextAnchor anchor = Text.Anchor; Text.Anchor = TextAnchor.MiddleRight; Widgets.Label(rect, keyGroup); Text.Anchor = anchor; GUI.color = color; Widgets.DraggableResult result = (!Widgets.ButtonInvisible(rect, false)) ? Widgets.DraggableResult.Idle : Widgets.DraggableResult.Pressed; return(result == Widgets.DraggableResult.Pressed || result == Widgets.DraggableResult.DraggedThenPressed); }
internal void <> m__0() { Rect rect = this.bgRect.AtZero(); Widgets.DrawAtlas(rect, ActiveTip.TooltipBGAtlas); Text.Font = GameFont.Small; Widgets.Label(rect.ContractedBy(4f), this.finalText); }
private static void DrawBorders() { var allUi = new Rect(0, 0, UI.screenWidth, UI.screenHeight); GUI.BeginGroup(allUi); _borders.ForEach(pair => Widgets.DrawAtlas(pair.First, pair.Second)); GUI.EndGroup(); }
protected void DrawFieldSelector(Rect fieldRect, string label, Action previousAction, Action nextAction, Action clickAction, Color labelColor) { GUI.color = Color.white; Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); Text.Anchor = TextAnchor.MiddleCenter; fieldRect.y += 2; GUI.color = labelColor; if (clickAction != null && fieldRect.Contains(Event.current.mousePosition)) { GUI.color = Color.white; } Widgets.Label(fieldRect, label); GUI.color = Color.white; // Draw previous and next buttons. Disable the buttons if no action arguments were passed in. float buttonHalfHeight = Textures.TextureButtonPrevious.height * 0.5f; Rect prevButtonRect = new Rect(fieldRect.x - Textures.TextureButtonPrevious.width - 2, fieldRect.MiddleY() - buttonHalfHeight, Textures.TextureButtonPrevious.width, Textures.TextureButtonPrevious.height); Rect nextButtonRect = new Rect(fieldRect.x + fieldRect.width + 1, fieldRect.MiddleY() - buttonHalfHeight, Textures.TextureButtonPrevious.width, Textures.TextureButtonPrevious.height); if (previousAction != null) { Style.SetGUIColorForButton(prevButtonRect); GUI.DrawTexture(prevButtonRect, Textures.TextureButtonPrevious); if (previousAction != null && Widgets.ButtonInvisible(prevButtonRect, false)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); previousAction(); } } else { GUI.color = Style.ColorButtonDisabled; GUI.DrawTexture(prevButtonRect, Textures.TextureButtonPrevious); } if (nextAction != null) { Style.SetGUIColorForButton(nextButtonRect); GUI.DrawTexture(nextButtonRect, Textures.TextureButtonNext); if (nextAction != null && Widgets.ButtonInvisible(nextButtonRect, false)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); nextAction(); } } else { GUI.color = Style.ColorButtonDisabled; GUI.DrawTexture(nextButtonRect, Textures.TextureButtonNext); } if (clickAction != null && Widgets.ButtonInvisible(fieldRect, false)) { clickAction(); } Text.Anchor = TextAnchor.UpperLeft; }
// Draw a button with a graphic icon in the middle. Similar to Verse.Widgets.TextButton(), // but draws an image instead of text in the button. public static bool IconButton(Rect rect, Texture texture, Color baseColor, Color highlightColor, bool enabled) { if (texture == null) { return(false); } // Use the inactive color if the button is inactive. if (!enabled) { GUI.color = InactiveButtonColor; } else { GUI.color = Color.white; } // Draw the button background. Texture2D atlas = ButtonBGAtlas; if (rect.Contains(Event.current.mousePosition)) { atlas = ButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = ButtonBGAtlasClick; } } Widgets.DrawAtlas(rect, atlas); // Set up the icon image position. It's centered in the button rectangle. Rect iconRect = new Rect(rect.x + (rect.width / 2) - (texture.width / 2), rect.y + (rect.height / 2) - (texture.height / 2), texture.width, texture.height); // Draw the icon image. if (!enabled) { GUI.color = InactiveButtonColor; } else { GUI.color = baseColor; } if (enabled && rect.Contains(Event.current.mousePosition)) { GUI.color = highlightColor; } GUI.DrawTexture(iconRect, texture); GUI.color = Color.white; // If the button is inactive, always return false. Otherwise return true // if the user clicked on the button. if (!enabled) { return(false); } return(Widgets.InvisibleButton(rect)); }
public float DrawRelationship(float cursor, PawnRelationDef def, CustomPawn source, CustomPawn target, bool removeable) { cursor += ContentPadding.y; Vector2 relationshipBoxSize = SizeRelation; if (scrollView.ScrollbarsVisible) { relationshipBoxSize.x -= ScrollView.ScrollbarSize; } Rect relationshipBox = new Rect(ContentPadding.x, cursor, relationshipBoxSize.x, relationshipBoxSize.y); // Draw background box. GUI.color = BackgroundBoxColor; GUI.DrawTexture(relationshipBox, BaseContent.WhiteTex); GUI.BeginGroup(relationshipBox); // Draw pawn name. GUI.color = Page_ConfigureStartingPawnsCarefully.TextColor; Widgets.Label(new Rect(8, 6, relationshipBoxSize.x - 16, 24), target.Pawn.NameStringShort); // Draw relationship field. Rect fieldRect = new Rect(16, 30, relationshipBoxSize.x - 32, 28); GUI.color = Color.white; Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); // TODO: Move this color to another file like we did with the textures. GUI.color = Page_ConfigureStartingPawnsCarefully.TextColor; if (def != null) { Widgets.Label(new Rect(fieldRect.x, fieldRect.y + 1, fieldRect.width, fieldRect.height), def.GetGenderSpecificLabelCap(target.Pawn)); } // Delete relation Rect buttonRect = new Rect(relationshipBoxSize.x - 21, 3, 18, 18); GUI.color = buttonRect.Contains(Event.current.mousePosition) ? Page_ConfigureStartingPawnsCarefully.ButtonHighlightColor : Page_ConfigureStartingPawnsCarefully.ButtonColor; if (removeable) { GUI.DrawTexture(buttonRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); PrepareCarefully.Instance.RelationshipManager.DeleteRelationship(def, source, target); } } else { GUI.DrawTexture(buttonRect, Textures.TextureDerivedRelationship); TooltipHandler.TipRegion(buttonRect, "EdB.PrepareCarefully.CannotDeleteRelationship".Translate()); } GUI.color = Color.white; GUI.EndGroup(); return(cursor + relationshipBoxSize.y); }
public float DrawCustomBodyPart(float cursor, CustomBodyPart customPart) { cursor += ContentPadding.y; Vector2 boxSize = SizeElement; if (scrollView.ScrollbarsVisible) { boxSize.x -= ScrollView.ScrollbarSize; } Rect elementBox = new Rect(ContentPadding.x, cursor, boxSize.x, boxSize.y); // Draw background box. GUI.color = BackgroundBoxColor; GUI.DrawTexture(elementBox, BaseContent.WhiteTex); GUI.BeginGroup(elementBox); // Draw body part name. GUI.color = Page_ConfigureStartingPawnsCarefully.TextColor; Widgets.Label(new Rect(8, 6, boxSize.x - 16, 24), customPart.PartName); // Draw field. Rect fieldRect = new Rect(16, 30, boxSize.x - 32, 28); GUI.color = Color.white; Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); GUI.color = Page_ConfigureStartingPawnsCarefully.TextColor; // Draw the hediff label. GUI.color = customPart.LabelColor; Rect labelRect = new Rect(fieldRect.x, fieldRect.y + 1, fieldRect.width, fieldRect.height); Widgets.Label(labelRect, customPart.ChangeName); if (customPart.HasTooltip) { TooltipHandler.TipRegion(labelRect, customPart.Tooltip); } GUI.color = Page_ConfigureStartingPawnsCarefully.TextColor; // Delete the option. Rect buttonRect = new Rect(boxSize.x - 21, 3, 18, 18); GUI.color = buttonRect.Contains(Event.current.mousePosition) ? Page_ConfigureStartingPawnsCarefully.ButtonHighlightColor : Page_ConfigureStartingPawnsCarefully.ButtonColor; GUI.DrawTexture(buttonRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); partRemovalList.Add(customPart); } GUI.color = Color.white; GUI.EndGroup(); return(cursor + boxSize.y); }
public bool Draw(Vector2 pos, bool isSelected, float scale) { var direction = Settings.GetOffsetDirection(); var font = Settings.GetFont(scale); var paddingX = Mathf.CeilToInt(Mod.Settings.PaddingX * scale); var paddingY = Mathf.CeilToInt(Mod.Settings.PaddingY * scale); var maxWidth = Mathf.CeilToInt(Mod.Settings.WidthMax * scale); var content = new GUIContent(_text); Width = Mathf.CeilToInt(Mathf.Min(font.CalcSize(content).x + (paddingX * 2), maxWidth)); Height = Mathf.CeilToInt(font.CalcHeight(content, Width - (paddingX * 2)) + (paddingY * 2)); var posX = pos.x; var posY = pos.y; if (direction.IsHorizontal) { posY -= Height / 2f; } else { posX -= Width / 2f; } var outer = new Rect(Mathf.CeilToInt(posX), Mathf.CeilToInt(posY), Width, Height); var inner = outer.ContractedBy(paddingX, paddingY); var fade = Mathf.Min(GetFade(), Mouse.IsOver(outer) ? Mod.Settings.OpacityMouseOver.ToPercentageFloat() : 1f); if (fade <= 0f) { return(false); } var backColor = GetColor(false, isSelected).WithAlpha(fade); var foreColor = GetColor(true, isSelected).WithAlpha(fade); var prevColor = GUI.color; GUI.color = backColor; Widgets.DrawAtlas(outer, Textures.Inner); GUI.color = foreColor; Widgets.DrawAtlas(outer, Textures.Outer); GUI.Label(inner, content, font); GUI.color = prevColor; return(true); }
public static bool Settings_ButtonLabeled(this Listing_Standard lister, string header, string buttonLabel, Color highlightColor, float buttonWidth = 30f, bool background = true, bool active = true) { var anchor = Text.Anchor; Color color = GUI.color; Rect rect = lister.GetRect(20f); Rect buttonRect = new Rect(rect.width - buttonWidth, rect.y, buttonWidth, rect.height); Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(rect, header); if (background) { Texture2D atlas = ButtonBGAtlas; if (Mouse.IsOver(buttonRect)) { atlas = ButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = ButtonBGAtlasClick; } } Widgets.DrawAtlas(buttonRect, atlas); } else { GUI.color = Color.white; if (Mouse.IsOver(buttonRect)) { GUI.color = highlightColor; } } if (background) { Text.Anchor = TextAnchor.MiddleCenter; } else { Text.Anchor = TextAnchor.MiddleRight; } bool wordWrap = Text.WordWrap; if (buttonRect.height < Text.LineHeight * 2f) { Text.WordWrap = false; } Widgets.Label(buttonRect, buttonLabel); Text.Anchor = anchor; GUI.color = color; Text.WordWrap = wordWrap; lister.Gap(2f); return(Widgets.ButtonInvisible(buttonRect, false)); }
public static bool Button(Rect rect, string label, bool drawBackground, bool doMouseoverSound, bool active) { var anchor = Text.Anchor; var color = GUI.color; if (drawBackground) { var atlas = TextureButtonBGAtlas; if (Mouse.IsOver(rect)) { atlas = TextureButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = TextureButtonBGAtlasClick; } } Widgets.DrawAtlas(rect, atlas); var indicator = new Rect(rect.xMax - 21, rect.MiddleY() - 4, 11, 8); GUI.DrawTexture(indicator, TextureDropdownIndicator); } if (doMouseoverSound) { MouseoverSounds.DoRegion(rect); } if (!drawBackground) { GUI.color = new Color(0.8f, 0.85f, 1f); if (Mouse.IsOver(rect)) { GUI.color = Widgets.MouseoverOptionColor; } } if (drawBackground) { Text.Anchor = TextAnchor.MiddleCenter; } else { Text.Anchor = TextAnchor.MiddleLeft; } var textRect = new Rect(rect.x, rect.y, rect.width - 12, rect.height); Widgets.Label(textRect, label); Text.Anchor = anchor; GUI.color = color; return(active && Widgets.ButtonInvisible(rect, false)); }
private static bool DrawTabButton(Rect region, string text, string tooltip, bool active = false) { if (!active) { GUI.color = new Color(1f, 1f, 1f, 0.6f); } Widgets.DrawAtlas(region, Widgets.ButtonBGAtlas); GUI.color = Color.white; UiHelper.Label(region, text, TextAnchor.MiddleCenter); TooltipHandler.TipRegion(region, tooltip); bool result = Widgets.ButtonInvisible(region); return(result); }
public virtual void DoButton(Rect rect) { Text.Font = GameFont.Small; string text = def.LabelCap; float num = def.LabelCapWidth; if (num > rect.width - 2f) { text = def.ShortenedLabelCap; num = def.ShortenedLabelCapWidth; } if (Disabled) { Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas); if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect)) { Event.current.Use(); } return; } bool flag = num > 0.85f * rect.width - 1f; Rect rect2 = rect; string label = ((def.Icon == null) ? text : ""); float textLeftMargin = (flag ? 2f : (-1f)); if (Widgets.ButtonTextSubtle(rect2, label, ButtonBarPercent, textLeftMargin, SoundDefOf.Mouseover_Category)) { InterfaceTryActivate(); } if (def.Icon != null) { Vector2 center = rect.center; float num2 = 16f; if (Mouse.IsOver(rect)) { center += new Vector2(2f, -2f); } GUI.DrawTexture(new Rect(center.x - num2, center.y - num2, 32f, 32f), def.Icon); } if (Find.MainTabsRoot.OpenTab != def && !Find.WindowStack.NonImmediateDialogWindowOpen) { UIHighlighter.HighlightOpportunity(rect, def.cachedHighlightTagClosed); } if (Mouse.IsOver(rect) && !def.description.NullOrEmpty()) { TooltipHandler.TipRegion(rect, def.LabelCap + "\n\n" + def.description); } }
public float DrawTooltip(Vector2 pos) { Text.Font = GameFont.Small; string finalText = this.FinalText; Rect bgRect = this.TipRect; bgRect.position = pos; Find.WindowStack.ImmediateWindow(153 * this.signal.uniqueId + 62346, bgRect, WindowLayer.Super, delegate { Rect rect = bgRect.AtZero(); Widgets.DrawAtlas(rect, ActiveTip.TooltipBGAtlas); Text.Font = GameFont.Small; Widgets.Label(rect.ContractedBy(4f), finalText); }, false, false, 1f); return(bgRect.height); }
public static bool Settings_Button(this Listing_Standard lister, string label, Rect rect, Color customColor, bool background = true, bool active = true) { var anchor = Text.Anchor; Color color = GUI.color; if (background) { Texture2D atlas = ButtonBGAtlas; if (Mouse.IsOver(rect)) { atlas = ButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = ButtonBGAtlasClick; } } Widgets.DrawAtlas(rect, atlas); } else { GUI.color = customColor; if (Mouse.IsOver(rect)) { GUI.color = Color.cyan; } } if (background) { Text.Anchor = TextAnchor.MiddleCenter; } else { Text.Anchor = TextAnchor.MiddleLeft; } bool wordWrap = Text.WordWrap; if (rect.height < Text.LineHeight * 2f) { Text.WordWrap = false; } Widgets.Label(rect, label); Text.Anchor = anchor; GUI.color = color; Text.WordWrap = wordWrap; lister.Gap(2f); return(Widgets.ButtonInvisible(rect, false)); }
public static void HighlightOpportunity(Rect rect, string tag) { if (Event.current.type == EventType.Repaint) { for (int i = 0; i < UIHighlighter.liveTags.Count; i++) { Pair <string, int> pair = UIHighlighter.liveTags[i]; if (tag == pair.First && Time.frameCount == pair.Second + 1) { Rect rect2 = rect.ContractedBy(-10f); GUI.color = new Color(1f, 1f, 1f, Pulser.PulseBrightness(1.2f, 0.7f)); Widgets.DrawAtlas(rect2, UIHighlighter.TutorHighlightAtlas); GUI.color = Color.white; } } } }
public virtual void DoButton(Rect rect) { Text.Font = GameFont.Small; Profiler.BeginSample("lab"); string text = this.def.LabelCap; Profiler.EndSample(); float num = this.def.LabelCapWidth; if (num > rect.width - 2f) { text = this.def.ShortenedLabelCap; num = this.def.ShortenedLabelCapWidth; } if ((!this.def.validWithoutMap || this.def == MainButtonDefOf.World) && Find.CurrentMap == null) { Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas); if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect)) { Event.current.Use(); } } else { Profiler.BeginSample("ButtonTextSubtle"); bool flag = num > 0.85f * rect.width - 1f; Rect rect2 = rect; string label = text; float textLeftMargin = (!flag) ? -1f : 2f; if (Widgets.ButtonTextSubtle(rect2, label, this.ButtonBarPercent, textLeftMargin, SoundDefOf.Mouseover_Category, default(Vector2))) { this.InterfaceTryActivate(); } Profiler.EndSample(); if (Find.MainTabsRoot.OpenTab != this.def && !Find.WindowStack.NonImmediateDialogWindowOpen) { UIHighlighter.HighlightOpportunity(rect, this.def.cachedHighlightTagClosed); } if (!this.def.description.NullOrEmpty()) { TooltipHandler.TipRegion(rect, this.def.description); } } }
public void Draw(float x, ref float y, float width) { if (this.shouldDrawInput == null) { this.DrawInput(x, ref y, width); if (this.ToolTip != null) { if (Mouse.IsOver(new Rect(x, y - 32, width, 32))) { Vector2 vector = Text.CalcSize(ToolTip); if (vector.x > 260f) { vector.x = 260f; vector.y = Text.CalcHeight(ToolTip, vector.x); } Rect rect = new Rect(0, 0, vector.x, vector.y); rect = rect.ContractedBy(-4f); Rect rect2 = new Rect(UI.MousePositionOnUI.x, UI.MousePositionOnUIInverted.y + 20, rect.width, rect.height); Text.Font = GameFont.Small; Find.WindowStack.ImmediateWindow(ToolTip.GetHashCode(), rect2, WindowLayer.Super, delegate { Widgets.DrawAtlas(rect, ActiveTip.TooltipBGAtlas); Text.Font = GameFont.Small; Widgets.Label(rect.ContractedBy(4f), ToolTip); }, false, false, 1f); } } } else { ShouldDrawInputResult result = this.shouldDrawInput(this.Parent); if (result.drawInput) { this.DrawInput(x, ref y, width); } else if (result.message != null && result.message.Length > 0) { DrawLabel(x, ref y, width, result.message); } } }
public static bool IconButton(Rect rect, Texture texture, Color baseColor, Color highlightColor, bool enabled) { if (texture == null) { return false; } if (!enabled) { GUI.color = Button.InactiveButtonColor; } else { GUI.color = Color.white; } Texture2D atlas = Button.ButtonBGAtlas; if (enabled && rect.Contains(Event.current.mousePosition)) { atlas = Button.ButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = Button.ButtonBGAtlasClick; } } Widgets.DrawAtlas(rect, atlas); Rect position = new Rect(rect.x + rect.width / 2f - (float)(texture.width / 2), rect.y + rect.height / 2f - (float)(texture.height / 2), (float)texture.width, (float)texture.height); if (!enabled) { GUI.color = Button.InactiveButtonColor; } else { GUI.color = baseColor; } if (enabled && rect.Contains(Event.current.mousePosition)) { GUI.color = highlightColor; } GUI.DrawTexture(position, texture); GUI.color = Color.white; return enabled && Widgets.InvisibleButton(rect); }
public static bool TextButton(Rect rect, string label, bool drawBackground, bool doMouseoverSound, bool enabled) { TextAnchor anchor = Text.Anchor; Color color = GUI.color; GUI.color = ((!enabled) ? Button.InactiveButtonColor : Color.white); if (drawBackground) { Texture2D atlas = Button.ButtonBGAtlas; if (enabled && rect.Contains(Event.current.mousePosition)) { atlas = Button.ButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = Button.ButtonBGAtlasClick; } } Widgets.DrawAtlas(rect, atlas); } if (doMouseoverSound) { MouseoverSounds.DoRegion(rect); } if (!drawBackground && enabled && rect.Contains(Event.current.mousePosition)) { GUI.color = Button.MouseoverOptionColor; } if (drawBackground) { Text.Anchor = TextAnchor.MiddleCenter; } else { Text.Anchor = TextAnchor.MiddleLeft; } Widgets.Label(rect, label); Text.Anchor = anchor; GUI.color = color; return enabled && Widgets.InvisibleButton(rect); }
public virtual void DoButton(Rect rect) { Text.Font = GameFont.Small; string text = def.LabelCap; float num = def.LabelCapWidth; if (num > rect.width - 2f) { text = def.ShortenedLabelCap; num = def.ShortenedLabelCapWidth; } if (Disabled) { Widgets.DrawAtlas(rect, Widgets.ButtonSubtleAtlas); if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect)) { Event.current.Use(); } } else { bool flag = num > 0.85f * rect.width - 1f; Rect rect2 = rect; string label = text; float textLeftMargin = (!flag) ? (-1f) : 2f; if (Widgets.ButtonTextSubtle(rect2, label, ButtonBarPercent, textLeftMargin, SoundDefOf.Mouseover_Category)) { InterfaceTryActivate(); } if (Find.MainTabsRoot.OpenTab != def && !Find.WindowStack.NonImmediateDialogWindowOpen) { UIHighlighter.HighlightOpportunity(rect, def.cachedHighlightTagClosed); } if (!def.description.NullOrEmpty()) { TooltipHandler.TipRegion(rect, def.description); } } }
public static bool TextButton(Rect rect, string label, Color optionColor, float labelAdjustmentX = 0f) { Texture2D atlas = BillDrawer.ButtonBGAtlas; if (rect.Contains(Event.current.mousePosition)) { atlas = BillDrawer.ButtonBGAtlasMouseover; if (Input.GetMouseButton(0)) { atlas = BillDrawer.ButtonBGAtlasClick; } } Widgets.DrawAtlas(rect, atlas); Text.Anchor = TextAnchor.MiddleCenter; Rect rect2 = new Rect(rect); rect2.x += labelAdjustmentX; rect2.y += 1f; Widgets.Label(rect2, label); Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; return(Widgets.InvisibleButton(rect)); }
protected void ShowBackstoryDialog(CustomPawn customPawn, BackstorySlot slot) { Backstory originalBackstory = (slot == BackstorySlot.Childhood) ? customPawn.Childhood : customPawn.Adulthood; Backstory selectedBackstory = originalBackstory; Filter <Backstory> filterToRemove = null; bool filterListDirtyFlag = true; List <Backstory> fullOptionsList = slot == BackstorySlot.Childhood ? this.providerBackstories.GetChildhoodBackstoriesForPawn(customPawn) : this.providerBackstories.GetAdulthoodBackstoriesForPawn(customPawn); List <Backstory> filteredBackstories = new List <Backstory>(fullOptionsList.Count); Dialog_Options <Backstory> dialog = new Dialog_Options <Backstory>(filteredBackstories) { NameFunc = (Backstory backstory) => { return(backstory.TitleCapFor(customPawn.Gender)); }, DescriptionFunc = (Backstory backstory) => { return(backstory.FullDescriptionFor(customPawn.Pawn)); }, SelectedFunc = (Backstory backstory) => { return(selectedBackstory == backstory); }, SelectAction = (Backstory backstory) => { selectedBackstory = backstory; }, CloseAction = () => { if (slot == BackstorySlot.Childhood) { BackstoryUpdated(BackstorySlot.Childhood, selectedBackstory); } else { BackstoryUpdated(BackstorySlot.Adulthood, selectedBackstory); } } }; dialog.DrawHeader = (Rect rect) => { if (filterToRemove != null) { activeFilters.Remove(filterToRemove); filterToRemove = null; filterListDirtyFlag = true; } if (filterListDirtyFlag) { filteredBackstories.Clear(); filteredBackstories.AddRange(fullOptionsList.Where(p => { foreach (var f in activeFilters) { if (f.FilterFunction(p) == false) { return(false); } } return(true); })); filterListDirtyFlag = false; dialog.ScrollToTop(); } float filterHeight = 18; float filterPadding = 4; float maxWidth = rect.width - 32; Vector2 cursor = new Vector2(0, 0); string addFilterLabel = "EdB.PC.Dialog.Backstory.Filter.Add".Translate(); float width = Text.CalcSize(addFilterLabel).x; Rect addFilterRect = new Rect(rect.x, rect.y, width + 30, filterHeight); Widgets.DrawAtlas(addFilterRect, Textures.TextureFilterAtlas1); Text.Font = GameFont.Tiny; if (addFilterRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorText; } Widgets.Label(addFilterRect.InsetBy(10, 0, 20, 0).OffsetBy(0, 1), addFilterLabel); GUI.DrawTexture(new Rect(addFilterRect.xMax - 20, addFilterRect.y + 6, 11, 8), Textures.TextureDropdownIndicator); if (Widgets.ButtonInvisible(addFilterRect, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (var filter in availableFilters) { if (activeFilters.FirstOrDefault((f) => { if (f == filter || f.ConflictsWith(filter)) { return(true); } return(false); }) == null) { list.Add(new FloatMenuOption(filter.LabelFull, () => { activeFilters.Add(filter); filterListDirtyFlag = true; }, MenuOptionPriority.Default, null, null, 0, null, null)); } } Find.WindowStack.Add(new FloatMenu(list, null, false)); } cursor.x += addFilterRect.width + filterPadding; Text.Font = GameFont.Tiny; foreach (var filter in activeFilters) { GUI.color = Style.ColorText; float labelWidth = Text.CalcSize(filter.LabelShort).x; if (cursor.x + labelWidth > maxWidth) { cursor.x = 0; cursor.y += filterHeight + filterPadding; } Rect filterRect = new Rect(cursor.x, cursor.y, labelWidth + 30, filterHeight); Widgets.DrawAtlas(filterRect, Textures.TextureFilterAtlas2); Rect closeButtonRect = new Rect(filterRect.xMax - 15, filterRect.y + 5, 9, 9); if (filterRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorText; } Widgets.Label(filterRect.InsetBy(10, 0, 20, 0).OffsetBy(0, 1), filter.LabelShort); GUI.DrawTexture(closeButtonRect, Textures.TextureButtonCloseSmall); if (Widgets.ButtonInvisible(filterRect)) { filterToRemove = filter; filterListDirtyFlag = true; SoundDefOf.Tick_High.PlayOneShotOnCamera(); } cursor.x += filterRect.width + filterPadding; } Text.Font = GameFont.Small; GUI.color = Color.white; return(cursor.y + filterHeight + 4); }; Find.WindowStack.Add(dialog); }
public override void Resize(Rect rect) { base.Resize(rect); Vector2 padding = new Vector2(12, 12); Vector2 sizeInfoButton = new Vector2(24, 24); Vector2 sizeButton = new Vector2(160, 34); RectRemoveButton = new Rect(PanelRect.HalfWidth() - sizeButton.HalfX(), PanelRect.height - padding.y - sizeButton.y, sizeButton.x, sizeButton.y); Vector2 listSize = new Vector2(); listSize.x = rect.width - padding.x * 2; listSize.y = rect.height - padding.y * 3 - RectRemoveButton.height; float listHeaderHeight = 20; float listBodyHeight = listSize.y - listHeaderHeight; Rect rectTable = new Rect(padding.x, padding.y, listSize.x, listSize.y); RectRow = new Rect(0, 0, rectTable.width, 42); Vector2 nameOffset = new Vector2(10, 0); float columnWidthInfo = 36; float columnWidthIcon = 42; float columnWidthCount = 112; float columnWidthName = RectRow.width - columnWidthInfo - columnWidthIcon - columnWidthCount; table = new WidgetTable <EquipmentSelection>(); table.Rect = rectTable; table.BackgroundColor = Style.ColorPanelBackgroundDeep; table.RowColor = Style.ColorTableRow1; table.AlternateRowColor = Style.ColorTableRow2; table.SelectedRowColor = Style.ColorTableRowSelected; table.SupportSelection = true; table.RowHeight = 42; table.SelectedAction = (EquipmentSelection entry) => { SoundDefOf.TickTiny.PlayOneShotOnCamera(); }; table.DoubleClickAction = (EquipmentSelection entry) => { SoundDefOf.TickHigh.PlayOneShotOnCamera(); if (entry.Count > 0) { EquipmentCountUpdated(entry, entry.Count - 1); } else { EquipmentRemoved(entry); } }; table.AddColumn(new WidgetTable <EquipmentSelection> .Column() { Width = columnWidthInfo, Name = "Info", DrawAction = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .Metadata metadata) => { Rect infoRect = new Rect(columnRect.MiddleX() - sizeInfoButton.HalfX(), columnRect.MiddleY() - sizeInfoButton.HalfY(), sizeInfoButton.x, sizeInfoButton.y); Style.SetGUIColorForButton(infoRect); GUI.DrawTexture(infoRect, Textures.TextureButtonInfo); if (Widgets.ButtonInvisible(infoRect)) { if (entry.StuffDef != null) { Find.WindowStack.Add((Window) new Dialog_InfoCard(entry.ThingDef, entry.StuffDef)); } else { Find.WindowStack.Add((Window) new Dialog_InfoCard(entry.ThingDef)); } } GUI.color = Color.white; } }); table.AddColumn(new WidgetTable <EquipmentSelection> .Column() { Width = columnWidthIcon, Name = "Icon", DrawAction = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .Metadata metadata) => { WidgetEquipmentIcon.Draw(columnRect, entry.Record); } }); table.AddColumn(new WidgetTable <EquipmentSelection> .Column() { Width = columnWidthName, Name = "Name", Label = "Name", DrawAction = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .Metadata metadata) => { columnRect = columnRect.InsetBy(nameOffset.x, 0, 0, 0); GUI.color = Style.ColorText; Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(columnRect, entry.Record.Label); GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; } }); table.AddColumn(new WidgetTable <EquipmentSelection> .Column() { Width = columnWidthCount, Name = "Count", Label = "Count", AdjustForScrollbars = true, DrawAction = (EquipmentSelection entry, Rect columnRect, WidgetTable <EquipmentSelection> .Metadata metadata) => { Rect fieldRect = new Rect(columnRect.x + 17, columnRect.y + 7, 60, 28); Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); if (metadata.rowIndex <= numberFields.Count) { numberFields.Add(new WidgetNumberField() { MaxValue = 100000 }); } WidgetNumberField field = numberFields[metadata.rowIndex]; field.UpdateAction = (int value) => { EquipmentCountUpdated(entry, value); }; field.Draw(fieldRect, entry.Count); } }); }
public virtual bool DoGUI(Rect rect, bool colonistOrdering, FloatMenu floatMenu) { Rect rect2 = rect; rect2.height--; bool flag = !Disabled && Mouse.IsOver(rect2); bool flag2 = false; Text.Font = CurrentFont; Rect rect3 = rect; rect3.xMin += 4f; rect3.xMax = rect.x + 27f; rect3.yMin += 4f; rect3.yMax = rect.y + 27f; if (flag) { rect3.x += 4f; } Rect rect4 = rect; rect4.xMin += HorizontalMargin; rect4.xMax -= HorizontalMargin; rect4.xMax -= 4f; rect4.xMax -= extraPartWidth + IconOffset; rect4.x += IconOffset; if (flag) { rect4.x += 4f; } Rect rect5 = default(Rect); if (extraPartWidth != 0f) { float num = Mathf.Min(Text.CalcSize(Label).x, rect4.width - 4f); rect5 = new Rect(rect4.xMin + num, rect4.yMin, extraPartWidth, 30f); flag2 = Mouse.IsOver(rect5); } if (!Disabled) { MouseoverSounds.DoRegion(rect2); } Color color = GUI.color; if (Disabled) { GUI.color = ColorBGDisabled * color; } else if (flag && !flag2) { GUI.color = ColorBGActiveMouseover * color; } else { GUI.color = ColorBGActive * color; } GUI.DrawTexture(rect, BaseContent.WhiteTex); GUI.color = ((!Disabled) ? ColorTextActive : ColorTextDisabled) * color; if (sizeMode == FloatMenuSizeMode.Tiny) { rect4.y += 1f; } Widgets.DrawAtlas(rect, TexUI.FloatMenuOptionBG); Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(rect4, Label); Text.Anchor = TextAnchor.UpperLeft; GUI.color = iconColor; if (shownItem != null || drawPlaceHolderIcon) { Widgets.DefIcon(rect3, shownItem, null, 1f, drawPlaceHolderIcon); } else if ((bool)itemIcon) { GUI.DrawTexture(rect3, itemIcon); } GUI.color = color; if (extraPartOnGUI != null) { bool num2 = extraPartOnGUI(rect5); GUI.color = color; if (num2) { return(true); } } if (flag && mouseoverGuiAction != null) { mouseoverGuiAction(); } if (tutorTag != null) { UIHighlighter.HighlightOpportunity(rect, tutorTag); } if (Widgets.ButtonInvisible(rect2)) { if (tutorTag != null && !TutorSystem.AllowAction(tutorTag)) { return(false); } Chosen(colonistOrdering, floatMenu); if (tutorTag != null) { TutorSystem.Notify_Event(tutorTag); } return(true); } return(false); }