Exemplo n.º 1
0
    private void DebugDrawHoverWidget()
    {
        IWidget widget = _gameWorldController.View.WidgetEventDispatcher.MouseOverWidget;

        if (widget != null)
        {
            Vector3 boxUL =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX, widget.WorldY, 0.0f);
            Vector3 boxUR =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX + widget.Width, widget.WorldY, 0.0f);
            Vector3 boxLR =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX + widget.Width, widget.WorldY + widget.Height, 0.0f);
            Vector3 boxLL =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX, widget.WorldY + widget.Height, 0.0f);

            Debug.DrawLine(boxUL, boxUR, Color.red);
            Debug.DrawLine(boxUR, boxLR, Color.red);
            Debug.DrawLine(boxLR, boxLL, Color.red);
            Debug.DrawLine(boxLL, boxUL, Color.red);

            _widgetLabel.SetLocalPosition(widget.WorldX + (widget.Width / 2.0f), widget.WorldY + (widget.Height / 2.0f));
            _widgetLabel.Text    = widget.GetType().Name;
            _widgetLabel.Visible = true;
        }
    }
Exemplo n.º 2
0
    private void DebugDrawTestVisibility()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point3d startWorldPos = entity.Position;

            Point2d endPixelPos = GetMousePixelPosition();
            Point3d endWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(endPixelPos);

            // Draw the target nav cell
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef startNavRef = navMesh.ComputeNavRefAtPoint(startWorldPos);
                NavRef endNavRef   = navMesh.ComputeNavRefAtPoint(endWorldPos);

                if (startNavRef.IsValid && endNavRef.IsValid)
                {
                    bool  canSee     = navMesh.NavRefCanSeeOtherNavRef(startNavRef, endNavRef);
                    Color debugColor = canSee ? Color.green : Color.red;

                    // Draw a box around the nav cell
                    {
                        Point3d endCenterWorldPos = navMesh.ComputeNavCellCenter((uint)endNavRef.NavCellIndex);
                        Point2d endCenterPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(endCenterWorldPos);
                        float   halfWidth         = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                        Vector3 boxUL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxUR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxLR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);
                        Vector3 boxLL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);

                        Debug.DrawLine(boxUL, boxUR, debugColor);
                        Debug.DrawLine(boxUR, boxLR, debugColor);
                        Debug.DrawLine(boxLR, boxLL, debugColor);
                        Debug.DrawLine(boxLL, boxUL, debugColor);
                    }

                    // Update the visibility status label
                    _visibilityStatusLabel.Text = canSee ? "VISIBLE" : "INVISIBLE";
                    _visibilityStatusLabel.SetLocalPosition(endPixelPos.x, endPixelPos.y);
                    _visibilityStatusLabel.Color   = debugColor;
                    _visibilityStatusLabel.Visible = true;

                    // Render the ray-cast line
                    {
                        Vector3 startVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(startWorldPos);
                        Vector3 endVertex   = ClientGameConstants.ConvertRoomPositionToVertexPosition(endWorldPos);

                        Debug.DrawLine(startVertex, endVertex, debugColor);
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
    public void Start()
    {
        SessionData sessionData = SessionData.GetInstance();

        // Create the root widget group
        m_rootWidgetGroup = new WidgetGroup(null, gamePanelStyle.Width, gamePanelStyle.Height, 0.0f, 0.0f);
        m_rootWidgetGroup.SetWidgetEventListener(this);

        // Background for the game info
        ImageWidget gamePanel =
            new ImageWidget(
                m_rootWidgetGroup,
                gamePanelStyle.Width,
                gamePanelStyle.Height,
                gamePanelStyle.Background,
                0.0f, 0.0f);

        float statsLabelWidth = (gamePanel.Width - 2 * BORDER_WIDTH) / 2 - 3;
        float statsX          = 10;
        float statsY          = 10;

        // Owner Name
        LabelWidget ownerNameLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Owner Name:");

        ownerNameLabel.Alignment = TextAnchor.UpperRight;
        m_ownerNameLabel         =
            new LabelWidget(
                m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT,
                statsX + statsLabelWidth, statsY, sessionData.UserName);
        m_ownerNameLabel.Text = "";

        // Game name
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget gameNameLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Game Name:");

        gameNameLabel.Alignment = TextAnchor.UpperRight;
        m_gameNameTextField     = new TextEntryWidget(m_rootWidgetGroup,
                                                      statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, "");

        // IRC Server
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCServerLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Server:");

        IRCServerLabel.Alignment = TextAnchor.UpperRight;
        m_IRCServerTextField     = new TextEntryWidget(m_rootWidgetGroup,
                                                       statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, "");
        m_IRCServerTextField.Text = ServerConstants.DEFAULT_IRC_SERVER;

        // IRC Port
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCPortLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Port:");

        IRCPortLabel.Alignment = TextAnchor.UpperRight;
        m_IRCPortTextField     = new TextEntryWidget(m_rootWidgetGroup,
                                                     statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, "");
        m_IRCPortTextField.Restrict  = @"[^0-9]";
        m_IRCPortTextField.MaxLength = 6;
        m_IRCPortTextField.Text      = ServerConstants.DEFAULT_IRC_PORT.ToString();

        // IRC Enabled
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCEnabledLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Enabled:");

        IRCEnabledLabel.Alignment  = TextAnchor.UpperRight;
        m_IRCEnabledToggle         = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY);
        m_IRCEnabledToggle.Enabled = true;

        // IRC Encryption Enabled
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCEncryptionEnabledLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Encryption Enabled:");

        IRCEncryptionEnabledLabel.Alignment  = TextAnchor.UpperRight;
        m_IRCEncryptionEnabledToggle         = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY);
        m_IRCEncryptionEnabledToggle.Enabled = true;

        // Creation status
        m_statusLabel = new LabelWidget(m_rootWidgetGroup, gamePanel.Width, STATS_LABEL_HEIGHT, 0.0f, 0.0f, "");
        m_statusLabel.SetLocalPosition(0, gamePanel.Height - m_statusLabel.Height - BORDER_WIDTH);
        m_statusLabel.Alignment = TextAnchor.UpperCenter;

        // Create button
        m_createButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Create");
        m_createButton.SetLocalPosition(gamePanel.Width / 3 - m_createButton.Width / 2, m_statusLabel.LocalY - m_createButton.Height - 5);

        // Cancel button
        m_cancelButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Cancel");
        m_cancelButton.SetLocalPosition((2 * gamePanel.Width) / 3 - m_cancelButton.Width / 2, m_statusLabel.LocalY - m_cancelButton.Height - 5);

        // Center the group info widgets
        m_rootWidgetGroup.SetLocalPosition(Screen.width / 2 - gamePanel.Width / 2, Screen.height / 2 - gamePanel.Height / 2);
    }
Exemplo n.º 4
0
    private void DebugDrawTestPath()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point2d mousePixelPos = GetMousePixelPosition();
            Point3d mouseWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(mousePixelPos);

            // Draw the target nav cell
            string targetLabel = "";
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef navRef = navMesh.ComputeNavRefAtPoint(mouseWorldPos);

                if (navRef.IsValid)
                {
                    Point3d centerWorldPos = navMesh.ComputeNavCellCenter((uint)navRef.NavCellIndex);
                    Point2d centerPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(centerWorldPos);
                    float   halfWidth      = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                    Vector3 boxUL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxUR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxLR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y + halfWidth, 0.0f);
                    Vector3 boxLL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y + halfWidth, 0.0f);

                    Debug.DrawLine(boxUL, boxUR, Color.blue);
                    Debug.DrawLine(boxUR, boxLR, Color.blue);
                    Debug.DrawLine(boxLR, boxLL, Color.blue);
                    Debug.DrawLine(boxLL, boxUL, Color.blue);

                    targetLabel = "\nNavCell=" + navRef.NavCellIndex.ToString();
                }

                // Attempt to compute a path from the active player to the mouse
                _pathComputer.BlockingPathRequest(navMesh, roomKey, entity.Position, mouseWorldPos);

                // Update the path status label
                {
                    if (_pathComputer.ResultCode == PathComputer.eResult.success)
                    {
                        _pathStatusLabel.Text  = "VALID" + targetLabel;
                        _pathStatusLabel.Color = Color.green;
                    }
                    else
                    {
                        _pathStatusLabel.Text  = _pathComputer.ResultCode + targetLabel;
                        _pathStatusLabel.Color = Color.red;
                    }

                    _pathStatusLabel.SetLocalPosition(mousePixelPos.x, mousePixelPos.y);
                    _pathStatusLabel.Visible = true;
                }

                // Render the raw path
                for (int stepIndex = 1; stepIndex < _pathComputer.FinalPath.Count; stepIndex++)
                {
                    Point3d previousPoint      = _pathComputer.FinalPath[stepIndex - 1].StepPoint;
                    Point3d currentPoint       = _pathComputer.FinalPath[stepIndex].StepPoint;
                    Vector3 previousPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(previousPoint);
                    Vector3 currentPixelPoint  = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentPoint);

                    Debug.DrawLine(previousPixelPoint, currentPixelPoint, Color.green);
                }
            }
        }
    }
Exemplo n.º 5
0
    public void Start()
    {
        SessionData sessionData = SessionData.GetInstance();

        // Create the root widget group
        m_rootWidgetGroup = new WidgetGroup(null, gamePanelStyle.Width, gamePanelStyle.Height, 0.0f, 0.0f);
        m_rootWidgetGroup.SetWidgetEventListener(this);

        // Background for the game info
        ImageWidget gamePanel =
            new ImageWidget(
                m_rootWidgetGroup,
                gamePanelStyle.Width,
                gamePanelStyle.Height,
                gamePanelStyle.Background,
                0.0f, 0.0f);

        float statsLabelWidth = (gamePanel.Width - 2 * BORDER_WIDTH) / 2 - 3;
        float statsX = 10;
        float statsY = 10;

        // Owner Name
        LabelWidget ownerNameLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Owner Name:");
        ownerNameLabel.Alignment = TextAnchor.UpperRight;
        m_ownerNameLabel =
            new LabelWidget(
                m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT,
                statsX + statsLabelWidth, statsY, sessionData.UserName);
        m_ownerNameLabel.Text = "";

        // Game name
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget gameNameLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Game Name:");
        gameNameLabel.Alignment = TextAnchor.UpperRight;
        m_gameNameTextField = new TextEntryWidget(m_rootWidgetGroup,
            statsLabelWidth, STATS_LABEL_HEIGHT, statsX+statsLabelWidth, statsY, "");

        // IRC Server
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCServerLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Server:");
        IRCServerLabel.Alignment = TextAnchor.UpperRight;
        m_IRCServerTextField = new TextEntryWidget(m_rootWidgetGroup,
            statsLabelWidth, STATS_LABEL_HEIGHT, statsX+statsLabelWidth, statsY, "");
        m_IRCServerTextField.Text = ServerConstants.DEFAULT_IRC_SERVER;

        // IRC Port
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCPortLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Port:");
        IRCPortLabel.Alignment = TextAnchor.UpperRight;
        m_IRCPortTextField = new TextEntryWidget(m_rootWidgetGroup,
            statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, "");
        m_IRCPortTextField.Restrict = @"[^0-9]";
        m_IRCPortTextField.MaxLength = 6;
        m_IRCPortTextField.Text = ServerConstants.DEFAULT_IRC_PORT.ToString();

        // IRC Enabled
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCEnabledLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Enabled:");
        IRCEnabledLabel.Alignment = TextAnchor.UpperRight;
        m_IRCEnabledToggle = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY);
        m_IRCEnabledToggle.Enabled = true;

        // IRC Encryption Enabled
        statsY += STATS_LABEL_HEIGHT;
        LabelWidget IRCEncryptionEnabledLabel =
            new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Encryption Enabled:");
        IRCEncryptionEnabledLabel.Alignment = TextAnchor.UpperRight;
        m_IRCEncryptionEnabledToggle = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY);
        m_IRCEncryptionEnabledToggle.Enabled = true;

        // Creation status
        m_statusLabel = new LabelWidget(m_rootWidgetGroup, gamePanel.Width, STATS_LABEL_HEIGHT, 0.0f, 0.0f, "");
        m_statusLabel.SetLocalPosition(0, gamePanel.Height - m_statusLabel.Height - BORDER_WIDTH);
        m_statusLabel.Alignment = TextAnchor.UpperCenter;

        // Create button
        m_createButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Create");
        m_createButton.SetLocalPosition(gamePanel.Width/3 - m_createButton.Width/2, m_statusLabel.LocalY - m_createButton.Height - 5);

        // Cancel button
        m_cancelButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Cancel");
        m_cancelButton.SetLocalPosition((2*gamePanel.Width)/3 - m_cancelButton.Width/2, m_statusLabel.LocalY - m_cancelButton.Height - 5);

        // Center the group info widgets
        m_rootWidgetGroup.SetLocalPosition(Screen.width / 2 - gamePanel.Width / 2, Screen.height / 2 - gamePanel.Height / 2);
    }