public async void DoExamine(IEntity entity) { CloseTooltip(); var popupPos = _inputManager.MouseScreenPosition; // Actually open the tooltip. _examineTooltipOpen = new Popup(); _userInterfaceManager.StateRoot.AddChild(_examineTooltipOpen); var panel = new PanelContainer(); panel.AddStyleClass(StyleClassEntityTooltip); panel.ModulateSelfOverride = Color.LightGray.WithAlpha(0.90f); _examineTooltipOpen.AddChild(panel); //panel.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide); var vBox = new VBoxContainer(); panel.AddChild(vBox); var hBox = new HBoxContainer { SeparationOverride = 5 }; vBox.AddChild(hBox); if (entity.TryGetComponent(out ISpriteComponent sprite)) { hBox.AddChild(new SpriteView { Sprite = sprite }); } hBox.AddChild(new Label { Text = entity.Name, SizeFlagsHorizontal = Control.SizeFlags.FillExpand, }); const float minWidth = 300; var size = Vector2.ComponentMax((minWidth, 0), panel.CombinedMinimumSize); popupPos += Vector2.ComponentMin(Vector2.Zero, _userInterfaceManager.StateRoot.Size - (size + popupPos)); _examineTooltipOpen.Open(UIBox2.FromDimensions(popupPos, size)); if (entity.Uid.IsClientSide()) { return; } // Ask server for extra examine info. RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity.Uid)); ExamineSystemMessages.ExamineInfoResponseMessage response; try { _requestCancelTokenSource = new CancellationTokenSource(); response = await AwaitNetMessage <ExamineSystemMessages.ExamineInfoResponseMessage>(_requestCancelTokenSource .Token); } catch (TaskCanceledException) { return; } finally { _requestCancelTokenSource = null; } foreach (var msg in response.Message.Tags.OfType <FormattedMessage.TagText>()) { if (!string.IsNullOrWhiteSpace(msg.Text)) { var richLabel = new RichTextLabel(); richLabel.SetMessage(response.Message); vBox.AddChild(richLabel); break; } } //_examineTooltipOpen.Position += Vector2.ComponentMin(Vector2.Zero,_userInterfaceManager.StateRoot.Size - (panel.Size + _examineTooltipOpen.Position)); }
public async void DoExamine(IEntity entity) { const float minWidth = 300; CloseTooltip(); var popupPos = _userInterfaceManager.MousePositionScaled; // Actually open the tooltip. _examineTooltipOpen = new Popup(); _userInterfaceManager.ModalRoot.AddChild(_examineTooltipOpen); var panel = new PanelContainer(); panel.AddStyleClass(StyleClassEntityTooltip); panel.ModulateSelfOverride = Color.LightGray.WithAlpha(0.90f); _examineTooltipOpen.AddChild(panel); //panel.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide); var vBox = new VBoxContainer(); panel.AddChild(vBox); var hBox = new HBoxContainer { SeparationOverride = 5 }; vBox.AddChild(hBox); if (entity.TryGetComponent(out ISpriteComponent sprite)) { hBox.AddChild(new SpriteView { Sprite = sprite }); } hBox.AddChild(new Label { Text = entity.Name, HorizontalExpand = true, }); panel.Measure(Vector2.Infinity); var size = Vector2.ComponentMax((minWidth, 0), panel.DesiredSize); _examineTooltipOpen.Open(UIBox2.FromDimensions(popupPos, size)); FormattedMessage message; if (entity.Uid.IsClientSide()) { message = GetExamineText(entity, _playerManager.LocalPlayer.ControlledEntity); } else { // Ask server for extra examine info. RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity.Uid)); ExamineSystemMessages.ExamineInfoResponseMessage response; try { _requestCancelTokenSource = new CancellationTokenSource(); response = await AwaitNetworkEvent <ExamineSystemMessages.ExamineInfoResponseMessage>(_requestCancelTokenSource .Token); } catch (TaskCanceledException) { return; } finally { _requestCancelTokenSource = null; } message = response.Message; } foreach (var msg in message.Tags.OfType <FormattedMessage.TagText>()) { if (!string.IsNullOrWhiteSpace(msg.Text)) { var richLabel = new RichTextLabel(); richLabel.SetMessage(message); vBox.AddChild(richLabel); break; } } }