Beispiel #1
0
        ///
        /// <summary>
        ///		Performs a draw tick on the game object.
        /// </summary>
        ///
        /// <param name="gameTime">Time passed since the last call to Draw.</param>
        ///
        protected override void Draw(GameTime gameTime)
        {
            // Clear the screen.
            GraphicsDevice.Clear(new Color(126, 192, 238));

            // Begin the spritebatch, getting ready for the scaled sprites to be drawn onto the screen.
            spriteBatch.Begin(
                SpriteSortMode.BackToFront,
                BlendState.AlphaBlend,
                SamplerState.PointClamp,
                DepthStencilState.Default,
                RasterizerState.CullCounterClockwise);

            GraphicsDevice.BlendState = BlendState.NonPremultiplied;


            if (gameState.Equals(GameState.Running) ||
                gameState.Equals(GameState.RunningInventory))
            {
                // Draw the world!!
                if (world != null)
                {
                    world.draw(graphics, basicEffect, camera);
                }
            }

            if (gameState.Equals(GameState.Running))
            {
                // Draw the tile cursor.
                if (tileCursorEnabled)
                {
                    Tile.renderTile(
                        graphics,
                        basicEffect,
                        camera,
                        tileCursorPosition.X,
                        tileCursorPosition.Y,
                        world.tiles[tileCursorPosition.X, tileCursorPosition.Y].heights,
                        TextureResources.tileCursorTexture,
                        Tile.HEIGHT_STEP / 2.0F);
                }

                // Draw the mouse cursor.
                spriteBatch.Draw(TextureResources.cursorTexture,
                                 new Vector2(graphics.PreferredBackBufferWidth / 2.0F, graphics.PreferredBackBufferHeight / 2.0F),
                                 null,
                                 Color.White,
                                 0.0F,
                                 new Vector2(16.0F),
                                 1.0F,
                                 SpriteEffects.None,
                                 0.0F);
            }

            if (gameState.Equals(GameState.Running) ||
                gameState.Equals(GameState.RunningInventory))
            {
                // Draw the context menu
                if (contextMenu != null)
                {
                    contextMenu.draw(spriteBatch, FontResources.interfaceFont, graphics);
                }
            }


            if (gameState.Equals(GameState.Running))
            {
                // Draw the little menu thing at the top of the screen which shows the current tile.
                {
                    InterfaceHelper.drawWindow(
                        spriteBatch,
                        new Rectangle((graphics.PreferredBackBufferWidth / 2) - 100,
                                      -40 + (int)indicatorOffset,
                                      200,
                                      30),
                        1.0F,
                        0.5F);

                    if (tileCursorEnabled)
                    {
                        String  tileName     = world.tiles[tileCursorPosition.X, tileCursorPosition.Y].getName();
                        Vector2 tileNameSize = FontResources.interfaceFont.MeasureString(tileName);

                        spriteBatch.DrawString(FontResources.interfaceFont,
                                               tileName,
                                               new Vector2((graphics.PreferredBackBufferWidth / 2.0F) - (tileNameSize.X / 2.0F),
                                                           (-40.0F + indicatorOffset) + 6.0F),
                                               Color.Black);
                    }
                }
            }

            if (gameState.Equals(GameState.Running) ||
                gameState.Equals(GameState.RunningInventory))
            {
                // Draw the notifications.
                if (notifications.Count >= 1)
                {
                    notifications[0].draw(spriteBatch, graphics);
                }


                // Draw the action window.
                {
                    InterfaceHelper.drawWindow(
                        spriteBatch,
                        new Rectangle(5, graphics.PreferredBackBufferHeight - 105, 300, 100),
                        0.80F,
                        0.5F);

                    spriteBatch.Draw(
                        TextureResources.contextMenuTexture,
                        new Rectangle(15, graphics.PreferredBackBufferHeight - 40, 280, 25),
                        InterfaceHelper.REGION_BAR_GREYSCALE,
                        Color.White,
                        0.0F,
                        Vector2.Zero,
                        SpriteEffects.None,
                        0.4F);

                    if (currentAction == null)
                    {
                        spriteBatch.DrawString(
                            FontResources.interfaceFont,
                            System.Environment.UserName,
                            new Vector2(20.0F, graphics.PreferredBackBufferHeight - 90.0F),
                            Color.Black);
                    }

                    if (currentAction != null)
                    {
                        spriteBatch.DrawString(
                            FontResources.interfaceFont,
                            currentAction.action.getName() + "...",
                            new Vector2(20.0F, graphics.PreferredBackBufferHeight - 90.0F),
                            Color.Black,
                            0.0F,
                            Vector2.Zero,
                            1.0F,
                            SpriteEffects.None,
                            0.0F);

                        spriteBatch.Draw(
                            TextureResources.contextMenuTexture,
                            new Rectangle(15, graphics.PreferredBackBufferHeight - 40, (int)(currentAction.getPercentageCompleted() * 280.0F), 25),
                            InterfaceHelper.REGION_BAR,
                            Color.White,
                            0.0F,
                            Vector2.Zero,
                            SpriteEffects.None,
                            0.25F);

                        String  percentageString     = (int)Math.Round(currentAction.getPercentageCompleted() * 100.0F) + "%";
                        Vector2 percentageStringSize = FontResources.interfaceFont.MeasureString(percentageString);

                        spriteBatch.DrawString(
                            FontResources.interfaceFont,
                            percentageString,
                            new Vector2(15.0F + (280.0F / 2.0F) - (percentageStringSize.X / 2.0F),
                                        graphics.PreferredBackBufferHeight - 35.0F),
                            Color.Black);
                    }
                }
            }


            if (gameState.Equals(GameState.Unfocused))
            {
                FontResources.drawStringWithShadow(spriteBatch, FontResources.interfaceFont, "Click to focus!", new Vector2(20.0F, 20.0F), Color.White);
            }


            if (gameState.Equals(GameState.RunningInventory) ||
                gameState.Equals(GameState.Running))
            {
                if (m.LeftButton.Equals(ButtonState.Released) && m.RightButton.Equals(ButtonState.Released))
                {
                    canSelectItem = true;
                }

                Container.draw(
                    Container.WindowStyle.Inventory,
                    ref world.player.inventory,
                    graphics,
                    spriteBatch,
                    "Inventory");
            }


            if (gameState.Equals(GameState.Connecting))
            {
                String connectingString = "";
                switch (client.ConnectionStatus)
                {
                case NetConnectionStatus.None:
                case NetConnectionStatus.Disconnected:
                    connectingString = "Looking for the server." + new String('.', connectionAttempts);
                    break;

                case NetConnectionStatus.InitiatedConnect:
                    connectingString = "Establishing a connection with the server." + new String('.', connectionAttempts);
                    break;

                case NetConnectionStatus.Connected:
                    connectingString = "Connected to the server!";
                    break;

                default:
                    connectingString = "Please wait." + new String('.', connectionAttempts);
                    break;
                }

                drawCentralNotification(connectingString);
            }

            if (gameState.Equals(GameState.ConnectionFailed))
            {
                drawCentralNotification("Connection failed after " + connectionAttempts + " attempts :(");
            }


            // Debug String.
            FontResources.drawStringWithShadow(spriteBatch, FontResources.interfaceFont, GAME_NAME + " " + GAME_VERSION, new Vector2(3.0F, 3.0F), Color.White);
            FontResources.drawStringWithShadow(spriteBatch, FontResources.interfaceFont, Math.Round(ping, 1) + " ms", new Vector2(3.0F, 33.0F), Color.White);


            // End the spritebatch.
            spriteBatch.End();


            base.Draw(gameTime);
        }