コード例 #1
0
        public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates)
        {
            if (_currentPopup != null)
            {
                _closeContextMenu();
            }

            _currentEntity = entity.Uid;
            _currentPopup  = new Popup();
            _currentPopup.UserInterfaceManager.StateRoot.AddChild(_currentPopup);
            _currentPopup.OnPopupHide += _closeContextMenu;
            var vBox = new VBoxContainer("ButtonBox");

            _currentPopup.AddChild(vBox);

            vBox.AddChild(new Label {
                Text = "Waiting on Server..."
            });
            RaiseNetworkEvent(new VerbSystemMessages.RequestVerbsMessage(_currentEntity));

            var size = vBox.CombinedMinimumSize;
            var box  = UIBox2.FromDimensions(screenCoordinates.Position, size);

            _currentPopup.Open(box);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
    void buildButtons()
    {
        var baseButton = popup.GetNode <Button>("Button");

        baseButton.Visible = false;
        if (buttons != null)
        {
            foreach (Button button in buttons)
            {
                button.QueueFree();
            }
        }
        buttons = new Godot.Collections.Array <Button> {
        };
        var count = 0;

        foreach (Candy candy in candyManager.Candies)
        {
            if (!candy.unlocked)
            {
                continue;
            }
            var countY    = count > 0 ? Convert.ToInt32(Math.Ceiling(Convert.ToSingle(count) / 3f) - 1) : 0;
            var newButton = baseButton.Duplicate() as Button;
            newButton.Visible      = true;
            newButton.RectPosition = new Vector2(baseButton.RectPosition.x + (48 * count) - (48 * 4 * countY), baseButton.RectPosition.y + (48 * countY));
            Label  buttonLabel = newButton.GetNode <Label>("Label");
            Sprite moneySprite = newButton.GetNode <Sprite>("MoneySprite");
            moneySprite.Visible = true;
            buttonLabel.Text    = "" + candy.Cost;
            newButton.Disabled  = candyManager.getBackpackQuantity() == candyManager.maxBackpackQuantity || moneyManager.money < candy.Cost;
            newButton.Icon      = candy.Texture;
            popup.AddChild(newButton);
            count++;
            buttons.Add(newButton);
            newButton.Connect("pressed", this, "purchaseCandy", new Godot.Collections.Array {
                candy
            });
        }
        count = 0;
        foreach (Candy candy in candyManager.Candies)
        {
            int candyQty = candy.onBackpack;
            if (candyQty == 0)
            {
                continue;
            }
            var countY    = count > 0 ? Convert.ToInt32(Math.Ceiling(Convert.ToSingle(count) / 3f) - 1) : 0;
            var newButton = baseButton.Duplicate() as Button;
            newButton.Visible      = true;
            newButton.RectPosition = new Vector2(baseButton.RectPosition.x + (48 * count) - (48 * 4 * countY) + (48 * 5), baseButton.RectPosition.y + (48 * countY));
            Label  buttonLabel = newButton.GetNode <Label>("Label");
            Sprite moneySprite = newButton.GetNode <Sprite>("MoneySprite");
            moneySprite.Visible = false;
            buttonLabel.Text    = "x" + candyQty;
            newButton.Disabled  = candyQty == 0;
            newButton.Icon      = candy.Texture;
            popup.AddChild(newButton);
            count++;
            buttons.Add(newButton);
            newButton.Connect("pressed", this, "sellCandy", new Godot.Collections.Array {
                candy
            });
        }
    }
コード例 #4
0
        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;
                }
            }
        }
コード例 #5
0
    void buildButtons()
    {
        var baseButton = popup.GetNode <Button>("Button");

        baseButton.Visible = false;
        if (buttons != null)
        {
            foreach (Button button in buttons)
            {
                button.QueueFree();
            }
        }
        buttons = new Godot.Collections.Array <Button> {
        };
        var count = 0;

        foreach (Candy candy in candyManager.Candies)
        {
            int candyQty = candy.onBackpack;
            if (candyQty == 0)
            {
                continue;
            }
            var countY    = count > 0 ? Convert.ToInt32(Math.Ceiling(Convert.ToSingle(count) / 3f) - 1) : 0;
            var newButton = baseButton.Duplicate() as Button;
            newButton.Visible      = true;
            newButton.RectPosition = new Vector2(baseButton.RectPosition.x + (48 * count) - (48 * 4 * countY), baseButton.RectPosition.y + (48 * countY));
            Label buttonLabel = newButton.GetNode <Label>("Label");
            buttonLabel.Text   = "x" + candyQty;
            newButton.Disabled = !buttonsEnabled || candyQty == 0 || candyManager.getOnHandQuantity() == candyManager.maxHandQuantity;
            newButton.Icon     = candy.Texture;
            popup.AddChild(newButton);
            count++;
            buttons.Add(newButton);
            newButton.Connect("pressed", this, "moveFromBackpackToHand", new Godot.Collections.Array {
                candy
            });
        }
        count = 0;
        foreach (Candy candy in candyManager.Candies)
        {
            int candyQty = candy.onHand;
            if (candyQty == 0)
            {
                continue;
            }
            var countY    = count > 0 ? Convert.ToInt32(Math.Ceiling(Convert.ToSingle(count) / 3f) - 1) : 0;
            var newButton = baseButton.Duplicate() as Button;
            newButton.Visible      = true;
            newButton.RectPosition = new Vector2(baseButton.RectPosition.x + (48 * count) - (48 * 4 * countY) + (48 * 5), baseButton.RectPosition.y + (48 * countY));
            Label buttonLabel = newButton.GetNode <Label>("Label");
            buttonLabel.Text   = "x" + candyQty;
            newButton.Disabled = !buttonsEnabled || candyQty == 0;
            newButton.Icon     = candy.Texture;
            popup.AddChild(newButton);
            count++;
            buttons.Add(newButton);
            newButton.Connect("pressed", this, "moveFromHandToBackpack", new Godot.Collections.Array {
                candy
            });
        }
    }
コード例 #6
0
ファイル: EventSystem.cs プロジェクト: DrTurtles1313/ldjam-46
 public void GenerateEvent(EventType type, int number)
 {
     popup.PopupCentered();
     currentEvent = (RandomEvent)EventTypes[(int)type][number].Instance();
     popup.AddChild(currentEvent);
 }