示例#1
0
        ///
        /// <summary>
        ///		Loads all game content.
        /// </summary>
        ///
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load all font resources.
            FontResources.loadContent(Content);

            // Load all texture resources.
            TextureResources.loadContent(Content);

            // Load all model resources.
            ModelResources.loadContent(Content);
        }
示例#2
0
        public void draw(
            SpriteBatch spriteBatch,
            GraphicsDeviceManager graphics)
        {
            Vector2 size = FontResources.notificationFont.MeasureString(this.text);

            FontResources.drawStringWithShadow(
                spriteBatch,
                FontResources.notificationFont,
                this.text,
                new Vector2((graphics.PreferredBackBufferWidth / 2.0F) - (size.X / 2.0F),
                            (graphics.PreferredBackBufferHeight / 2.0F) + 250.0F),
                Color.White * opacity);
        }
示例#3
0
        ///
        /// <summary>
        ///		Draw the context menu to the middle of the screen.
        /// </summary>
        ///
        public virtual void draw(
            SpriteBatch spriteBatch,
            SpriteFont interfaceFont,
            GraphicsDeviceManager graphics)
        {
            Rectangle size = this.calculateSize(interfaceFont, graphics);

            size.Location = new Point(size.X - (int)((1.0F - age) * 50.0F), size.Y);

            InterfaceHelper.drawWindowWithArrow(spriteBatch, size, age, 0.2F);


            for (int i = 0; i < actionList.Count; i++)
            {
                Vector2 position = new Vector2(size.X + 20.0F, size.Y + 30.0F + 13.0F + (i * 30.0F));

                if (selectedItem >= 0 && i == selectedItem)
                {
                    spriteBatch.Draw(
                        TextureResources.whiteTexture,
                        new Rectangle(size.Left + 5, size.Y + 5 + 30 + (i * 30), size.Width - 10, 30),
                        null,
                        Color.White,
                        0.0F,
                        Vector2.Zero,
                        SpriteEffects.None,
                        0.1F);
                }

                spriteBatch.DrawString(interfaceFont, actionList[i].getFullString(), position, Color.Black * age);
            }


            // Draw the title of the context menu.
            spriteBatch.Draw(
                TextureResources.whiteTexture,
                new Rectangle(size.Left + 5, size.Y + 5, size.Width - 10, 30),
                null,
                Color.Gray,
                0.0F,
                Vector2.Zero,
                SpriteEffects.None,
                0.1F);
            FontResources.drawStringWithShadow(spriteBatch, interfaceFont, title, new Vector2(size.X + 20.0F, size.Y + 13.0F), Color.White);
        }
示例#4
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);
        }
示例#5
0
        private void RefreshAppearance(
            )
        {
            Widget      widget = Widgets[0];
            FormXObject normalAppearance;
            {
                AppearanceStates normalAppearances = widget.Appearance.Normal;
                normalAppearance = normalAppearances[null];
                if (normalAppearance == null)
                {
                    normalAppearances[null] = normalAppearance = new FormXObject(Document, widget.Box.Size);
                }
            }
            PdfName fontName = null;
            double  fontSize = 0;
            {
                PdfString defaultAppearanceState = DefaultAppearanceState;
                if (defaultAppearanceState == null)
                {
                    // Retrieving the font to define the default appearance...
                    fonts::Font defaultFont     = null;
                    PdfName     defaultFontName = null;
                    {
                        // Field fonts.
                        FontResources normalAppearanceFonts = normalAppearance.Resources.Fonts;
                        foreach (KeyValuePair <PdfName, fonts::Font> entry in normalAppearanceFonts)
                        {
                            if (!entry.Value.Symbolic)
                            {
                                defaultFont     = entry.Value;
                                defaultFontName = entry.Key;
                                break;
                            }
                        }
                        if (defaultFontName == null)
                        {
                            // Common fonts.
                            FontResources formFonts = Document.Form.Resources.Fonts;
                            foreach (KeyValuePair <PdfName, fonts::Font> entry in formFonts)
                            {
                                if (!entry.Value.Symbolic)
                                {
                                    defaultFont     = entry.Value;
                                    defaultFontName = entry.Key;
                                    break;
                                }
                            }
                            if (defaultFontName == null)
                            {
                                //TODO:manage name collision!
                                formFonts[
                                    defaultFontName = new PdfName("default")
                                ] = defaultFont = new fonts::StandardType1Font(
                                    Document,
                                    fonts::StandardType1Font.FamilyEnum.Helvetica,
                                    false,
                                    false
                                    );
                            }
                            normalAppearanceFonts[defaultFontName] = defaultFont;
                        }
                    }
                    bytes::Buffer buffer = new bytes::Buffer();
                    new SetFont(defaultFontName, IsMultiline ? 10 : 0).WriteTo(buffer, Document);
                    widget.BaseDataObject[PdfName.DA] = defaultAppearanceState = new PdfString(buffer.ToByteArray());
                }

                // Retrieving the font to use...
                ContentParser parser = new ContentParser(defaultAppearanceState.ToByteArray());
                foreach (ContentObject content in parser.ParseContentObjects())
                {
                    if (content is SetFont)
                    {
                        SetFont setFontOperation = (SetFont)content;
                        fontName = setFontOperation.Name;
                        fontSize = setFontOperation.Size;
                        break;
                    }
                }
                normalAppearance.Resources.Fonts[fontName] = Document.Form.Resources.Fonts[fontName];
            }

            // Refreshing the field appearance...

            /*
             * TODO: resources MUST be resolved both through the apperance stream resource dictionary and
             * from the DR-entry acroform resource dictionary
             */
            PrimitiveComposer baseComposer = new PrimitiveComposer(normalAppearance);
            BlockComposer     composer     = new BlockComposer(baseComposer);
            ContentScanner    currentLevel = composer.Scanner;
            bool textShown = false;

            while (currentLevel != null)
            {
                if (!currentLevel.MoveNext())
                {
                    currentLevel = currentLevel.ParentLevel;
                    continue;
                }

                ContentObject content = currentLevel.Current;
                if (content is MarkedContent)
                {
                    MarkedContent markedContent = (MarkedContent)content;
                    if (PdfName.Tx.Equals(((BeginMarkedContent)markedContent.Header).Tag))
                    {
                        // Remove old text representation!
                        markedContent.Objects.Clear();
                        // Add new text representation!
                        baseComposer.Scanner = currentLevel.ChildLevel; // Ensures the composer places new contents within the marked content block.
                        ShowText(composer, fontName, fontSize);
                        textShown = true;
                    }
                }
                else if (content is Text)
                {
                    currentLevel.Remove();
                }
                else if (currentLevel.ChildLevel != null)
                {
                    currentLevel = currentLevel.ChildLevel;
                }
            }
            if (!textShown)
            {
                baseComposer.BeginMarkedContent(PdfName.Tx);
                ShowText(composer, fontName, fontSize);
                baseComposer.End();
            }
            baseComposer.Flush();
        }