// --------------------------------------------------------------------------------------------
        protected override SharpUIBase BuildMainPanel()
        {
            SharpUINonDrawingGraphic toReturn = new SharpUINonDrawingGraphic("UIUnitOptionsView");

            toReturn.SetFillSize();

            toReturn.SubscribeToEvent(EEventType.Drag, (object sender, EventSystemEventArgs e) =>
            {
                if (_following == null)
                {
                    return;
                }

                PointerEventData pointerEventData = e.eventData as PointerEventData;

                if (_game.board.RaycastToPlane(pointerEventData.position, out Vector3 dragWorldPos))
                {
                    BoardTile draggingTile = _game.board.GetBoardTileAtPosition(dragWorldPos);
                    if (draggingTile != null && _targetableTiles.Contains(draggingTile))
                    {
                        _currentFacing     = Unit.VectorToFacing(draggingTile.Transform.position - _following.BoardTile.Transform.position);
                        _selectedBoardTile = draggingTile;
                        _following.BoardTile.AddChild(_facingArrow);

                        Quaternion facingRot       = Unit.FacingToRotation(_currentFacing);
                        _facingArrow.LocalRotation = Quaternion.Euler(90f, facingRot.eulerAngles.y - 90f, 0f);
                        _facingArrow.LocalPosition = Vector3.up + (Quaternion.Euler(0f, facingRot.eulerAngles.y - 90f, 0f) * (Vector3.right * 2f));
                    }
                    else
                    {
                        if (_facingArrow.IsBuilt)
                        {
                            _facingArrow.Destroy();
                        }

                        _selectedBoardTile = null;
                        _currentFacing     = _following.Facing;
                    }
                }
            });
            toReturn.SubscribeToEvent(EEventType.Drop, (object sender, EventSystemEventArgs e) =>
            {
                if (_facingArrow.IsBuilt)
                {
                    if (_selectedBoardTile != null)
                    {
                        _listener.OnUseSkillConfirmed(_following, _currentFacing, _selectedBoardTile.Coord);
                    }

                    _facingArrow.Destroy();
                }
                else
                {
                    Hide();
                }
            });

            return(toReturn);
        }
Exemple #2
0
        // --------------------------------------------------------------------------------------------
        protected override SharpUIBase BuildMainPanel()
        {
            _background = new SharpUINonDrawingGraphic($"{_player.name}_Panel");
            _background.RaycastTarget = false;
            _background.SetFixedSize(Size);
            _background.alignment = EAlignment.BottomLeft;
            _background.margin    = new RectOffset(20, 0, 0, 20);

            _heroHealthBar = new SharpUIProgressBar("HeroHealthBar", null, null);
            _heroHealthBar.BackgroundColor = new Color(0f, 0f, 0f, 0.5f);
            _heroHealthBar.FillColor       = Color.green;
            _heroHealthBar.Percent         = 1f;
            _heroHealthBar.SetFixedSize(340, 40);
            _heroHealthBar.alignment = EAlignment.TopRight;
            _heroHealthBar.margin    = new RectOffset(0, 0, 20, 0);
            _background.AddChild(_heroHealthBar);

            _headBackground = new SharpUIMask("HeadBackground", AppManager.AssetManager.Get <Sprite>(AssetPaths.Sprites.CircleWhite2048));
            _headBackground.ShowMaskGraphic = true;
            _headBackground.SetFixedSize((int)Size.y, (int)Size.y);
            _background.AddChild(_headBackground);

            _headSprite = new SharpUIImage("HeadSprite", AppManager.AssetManager.Get <Sprite>(_player.PlayerData.headSpritePath));
            _headSprite.SetFillSize();
            _headBackground.AddChild(_headSprite);

            _sourceLabel = new SharpUITextMeshPro("SourceLabel", _player.Source.ToString());
            _sourceLabel.SetFixedSize(50, 50);
            _sourceLabel.Font = AppManager.AssetManager.Get <TMPro.TMP_FontAsset>(AssetPaths.Fonts.GravityBoldItalic);
            _sourceLabel.AutoSizeFont();
            _sourceLabel.alignment     = EAlignment.BottomLeft;
            _sourceLabel.TextAlignment = TMPro.TextAlignmentOptions.Center;
            _background.AddChild(_sourceLabel);

            _energyMeter = new UIEnergyMeter($"{_player.name}_energy_meter");
            _energyMeter.SetEnergy(_player.Energy, _player.EnergyCap);
            _energyMeter.alignment = EAlignment.TopLeft;
            _energyMeter.margin    = new RectOffset((int)Size.y + 10, 0, 70, 0);
            _background.AddChild(_energyMeter);

            return(_background);
        }
        protected override SharpUIBase BuildMainPanel()
        {
            // use non drawing graphic to block input
            SharpUINonDrawingGraphic toReturn = new SharpUINonDrawingGraphic("UIConfirmationDialog");

            toReturn.SetFillSize();

            toReturn.SubscribeToEvent(EEventType.PointerClick, (object sender, EventSystemEventArgs e) =>
            {
                OnCancelClicked?.Invoke();
            });

            _background = new SharpUIImage($"{toReturn.Name}_bg", null);
            _background.SetFixedSize(Size);
            _background.alignment = EAlignment.MiddleCenter;
            _background.Color     = new Color(0f, 0f, 0f, 0.5f);
            toReturn.AddChild(_background);

            SharpUIHorizontalLayout buttonLayout = new SharpUIHorizontalLayout($"{toReturn.Name}_button_layout");

            buttonLayout.SetFitSize();
            buttonLayout.spacing   = 40;
            buttonLayout.alignment = EAlignment.BottomCenter;
            buttonLayout.margin    = new RectOffset(0, 0, 0, 20);
            _background.AddChild(buttonLayout);

            ChoiceButton okButton = new ChoiceButton(() => { OnOKClicked?.Invoke(); }, $"{toReturn.Name}_ok_button", "OK");

            buttonLayout.AddChild(okButton);

            ChoiceButton cancelButton = new ChoiceButton(() => { OnCancelClicked?.Invoke(); }, $"{toReturn.Name}_cancel_button", "Cancel");

            buttonLayout.AddChild(cancelButton);

            return(toReturn);
        }
        protected override SharpUIBase BuildMainPanel()
        {
            SharpUINonDrawingGraphic toReturn = new SharpUINonDrawingGraphic("UIGameOverView");

            toReturn.SetFillSize();

            SharpUIImage background = new SharpUIImage($"{toReturn.Name}_bg", null);

            background.Color = new Color(0f, 0f, 0f, 0.5f);
            background.SetFixedSize(Size);
            background.alignment = EAlignment.MiddleCenter;
            toReturn.AddChild(background);

            SharpUITextMeshPro gameOverLabel = new SharpUITextMeshPro("GameOverLabel", "Game Over");

            gameOverLabel.SetFillSize(EAxis.X, 0.8f);
            gameOverLabel.SetFixedSize(EAxis.Y, 200);
            gameOverLabel.alignment = EAlignment.TopCenter;
            gameOverLabel.AutoSizeFont();
            gameOverLabel.Font          = AppManager.AssetManager.Get <TMPro.TMP_FontAsset>(AssetPaths.Fonts.GravityBook);
            gameOverLabel.Color         = Color.black;
            gameOverLabel.TextAlignment = TMPro.TextAlignmentOptions.Center;
            gameOverLabel.Color         = Color.white;
            background.AddChild(gameOverLabel);

            List <Player> players = _game.GetWinners();
            StringBuilder sb      = new StringBuilder();

            if (players.Count > 0)
            {
                sb.Append("Winner: ");
            }
            foreach (Player player in players)
            {
                sb.Append(player.name + ", ");
            }

            SharpUITextMeshPro winnerLabel = new SharpUITextMeshPro("WinnerLabel", sb.ToString());

            winnerLabel.SetFillSize(EAxis.X, 0.6f);
            winnerLabel.SetFixedSize(EAxis.Y, 100);
            winnerLabel.margin    = new RectOffset(0, 0, 200, 0);
            winnerLabel.alignment = EAlignment.TopCenter;
            winnerLabel.AutoSizeFont();
            winnerLabel.Font          = AppManager.AssetManager.Get <TMPro.TMP_FontAsset>(AssetPaths.Fonts.GravityItalic);
            winnerLabel.Color         = Color.black;
            winnerLabel.TextAlignment = TMPro.TextAlignmentOptions.Center;
            winnerLabel.Color         = Color.white;
            background.AddChild(winnerLabel);

            SharpUIHorizontalLayout buttonLayout = new SharpUIHorizontalLayout($"{toReturn.Name}_button_layout");

            buttonLayout.SetFillSize(EAxis.X);
            buttonLayout.SetFixedSize(EAxis.Y, (int)ChoiceButton.Size.y);
            buttonLayout.alignment      = EAlignment.BottomCenter;
            buttonLayout.margin         = new RectOffset(0, 0, 0, 20);
            buttonLayout.childAlignment = EAlignment.MiddleCenter;
            background.AddChild(buttonLayout);

            buttonLayout.AddChild(new ChoiceButton("ReturnToStartButton", "Return to Start", () =>
            {
                _listener.OnReturnToStartClicked();
            }));

            return(toReturn);
        }