public override void Render() { WidgetImage renderImage = null; if (ButtonState == LgcyButtonState.Hovered) { renderImage = _hoverImage; } else if (ButtonState == LgcyButtonState.Down) { renderImage = _downImage; } var contentArea = GetContentArea(); if (renderImage != null) { renderImage.SetBounds( new Rectangle( contentArea.X, contentArea.Y - 1, renderImage.GetPreferredSize().Width, renderImage.GetPreferredSize().Height ) ); renderImage.Render(); } var labelSize = _label.GetPreferredSize(); // Center horizontally and vertically within the content area var labelArea = new Rectangle( contentArea.X + (contentArea.Width - labelSize.Width) / 2, contentArea.Y + (contentArea.Height - labelSize.Height) / 2, contentArea.Width = labelSize.Width, contentArea.Height = labelSize.Height ); // Special cases for certain labels if (_stat == Stat.level) { labelArea.X = contentArea.X + 2; } else if (_stat == Stat.initiative_bonus) { labelArea.X = contentArea.X + 1; } _label.SetBounds(labelArea); _label.Render(); }
public void RenderObjectTooltip(IGameViewport viewport, GameObject obj, GameObject observer = null) { var content = UiSystems.Tooltip.GetObjectDescriptionContent(obj, observer); if (content != null) { using var tooltipLabel = new WidgetText(content, "default-tooltip"); tooltipLabel.SetBounds(new Rectangle(0, 0, 300, 300)); var size = tooltipLabel.GetPreferredSize(); var objRect = GameSystems.MapObject.GetObjectRect(viewport, obj); var extents = new Rectangle( objRect.X + (objRect.Width - size.Width) / 2, objRect.Y - size.Height, size.Width, size.Height ); UiSystems.Tooltip.ClampTooltipToScreen(ref extents); tooltipLabel.SetBounds(extents); tooltipLabel.Render(); } }
public override void Render() { WidgetImage renderImage = null; if (ButtonState == LgcyButtonState.Hovered) { renderImage = _hoverImage; } else if (ButtonState == LgcyButtonState.Down) { renderImage = _downImage; } var contentArea = GetContentArea(); if (renderImage != null) { renderImage.SetBounds( new Rectangle( contentArea.X, contentArea.Y - 1, renderImage.GetPreferredSize().Width, renderImage.GetPreferredSize().Height ) ); renderImage.Render(); } var critter = UiSystems.CharSheet.CurrentCritter; _label.Content = critter != null?_valueSupplier(critter) : null; var labelSize = _label.GetPreferredSize(); // Center horizontally and vertically within the content area var labelArea = new Rectangle( contentArea.X + (contentArea.Width - labelSize.Width) / 2, contentArea.Y + (contentArea.Height - labelSize.Height) / 2, contentArea.Width = labelSize.Width, contentArea.Height = labelSize.Height ); _label.SetBounds(labelArea); _label.Render(); }
public override void Render() { InvokeOnBeforeRender(); ApplyAutomaticSizing(); base.Render(); var contentArea = GetContentArea(); string?labelStyle = null; if (mDisabled) { if (_style.DisabledTextStyleId != null) { labelStyle = _style.DisabledTextStyleId; } else { labelStyle = _style.TextStyleId; } } else { if (ButtonState == LgcyButtonState.Down) { if (_style.PressedTextStyleId != null) { labelStyle = _style.PressedTextStyleId; } else if (_style.HoverTextStyleId != null) { labelStyle = _style.HoverTextStyleId; } else { labelStyle = _style.TextStyleId; } } else if (IsActive()) { if (ButtonState == LgcyButtonState.Hovered || ButtonState == LgcyButtonState.Released) { if (_style.HoverTextStyleId != null) { labelStyle = _style.HoverTextStyleId; } else { labelStyle = _style.TextStyleId; } } else { labelStyle = _style.TextStyleId; } } else if (ButtonState == LgcyButtonState.Hovered || ButtonState == LgcyButtonState.Released) { if (_style.HoverTextStyleId != null) { labelStyle = _style.HoverTextStyleId; } else { labelStyle = _style.TextStyleId; } } else { labelStyle = _style.TextStyleId; } } _label.StyleIds = labelStyle != null?ImmutableList.Create(labelStyle) : ImmutableList <string> .Empty; var fr = _frameImage; if (fr != null) { var contentAreaWithMargins = GetContentArea(true); fr.SetBounds(contentAreaWithMargins); fr.Render(); } var image = GetCurrentImage(); if (image != null) { image.SetBounds(contentArea); image.Render(); } _label.SetBounds(contentArea); _label.Render(); }
private bool AbilityScoreMouseHandler(MessageMouseArgs msg, AbilityScoreValueWidget widget) { if (Globals.UiManager.GetMouseCaptureWidget() == widget) { if ((msg.flags & MouseEventFlag.LeftReleased) != 0) { Tig.Mouse.SetCursorDrawCallback(null); Globals.UiManager.UnsetMouseCaptureWidget(widget); widget.IsDragging = false; var widgetUnderCursor = Globals.UiManager.GetWidgetAt(msg.X, msg.Y); if (widgetUnderCursor is AbilityScoreValueWidget otherAbilityScoreValue) { // Swap the two values var tmp = otherAbilityScoreValue.Value; otherAbilityScoreValue.Value = widget.Value; widget.Value = tmp; OnAbilityScoresChanged(); } } return(true); } if (widget.Value == -1) { // Do not allow interaction with unassigned ability scores return(true); } // Allow quickly swapping values between the two columns, but only when we actually have rolled values // (not in point buy mode) if (!_pkt.isPointbuy && (msg.flags & MouseEventFlag.RightClick) != 0) { var destinationPool = widget.IsAssigned ? charGenRolledStats : _pkt.abilityStats; for (var i = 0; i < destinationPool.Length; i++) { if (destinationPool[i] == -1) { destinationPool[i] = widget.Value; widget.Value = -1; OnAbilityScoresChanged(); return(true); } } } else if ((msg.flags & MouseEventFlag.LeftHeld) != 0) { if (!Globals.UiManager.SetMouseCaptureWidget(widget)) { // Something else has the mouse capture right now (how are we getting this message then...?) return(true); } // Figure out where in the widget we got clicked so we can draw the dragged text with the proper offset var globalContentArea = widget.GetContentArea(true); var localX = msg.X - globalContentArea.X; var localY = msg.Y - globalContentArea.Y; _draggedAbilityScoreLabel.Text = widget.Value.ToString(); widget.IsDragging = true; // This will draw the ability score being dragged under the mouse cursor Tig.Mouse.SetCursorDrawCallback((x, y, arg) => { var point = new Point(x, y); point.Offset(-localX, -localY); var contentArea = new Rectangle(point, widget.GetSize()); _draggedAbilityScoreLabel.SetBounds(contentArea); _draggedAbilityScoreLabel.Render(); }); } return(true); }