Exemple #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (take_screen_shot)
            {
                renderTarget = new RenderTarget2D(GraphicsDevice, screen_size.X, screen_size.Y);
                GraphicsDevice.SetRenderTarget(renderTarget);
            }
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);
            Vector2 size = new Vector2();

            switch (gstate)
            {
            case 10:     //title screen
                menu.draw_menu(spriteBatch, display);
                break;

            case 60:
                saved_players.draw_list(spriteBatch, display);
                break;

            case 70:
                saved_players.draw_create_chracter(spriteBatch, display, input);
                break;

            case 90:    //server choosing world to use or to create a new world.
                world_manager.draw_choosing_menu(spriteBatch, display);
                break;

            case 91:    //choosing the world to create
                world_definition_manager.draw_choosing_menu(spriteBatch, display);
                break;

            case 92:    //creating a new world... show status text.
                world_definition_manager.creating_draw(spriteBatch, display);
                break;

            case 95:    //client waiting to connect
                size = display.font.MeasureString("Waiting for Initialization");
                display.draw_text(spriteBatch, display.font, "@11Waiting for Initialization", (int)((screen_size.X / 2) - (size.X / 2)), (int)screen_size.Y / 2, screen_size.X);
                break;

            case 100:     //in-game
                Vector2 mouse_world_pos = new Vector2(world.top_left.X + input.mouse_now.X, world.top_left.Y + input.mouse_now.Y);
                if (game_my_user_id != -1)
                {
                    world.total_fps.stop();
                    world.total_fps.start();
                    world.frame_render_time.start();
                    if (settings.use_hardware_lighting)
                    {
                        lighting.draw_scene(spriteBatch, display, world, input, GraphicsDevice);
                    }
                    else
                    {
                        world.draw_world(game_my_user_id, spriteBatch, display, input);
                    }
                    display.draw_fade_text(spriteBatch, world.top_left);
                    world.draw_hud(game_my_user_id, spriteBatch, display, input);
                    world.frame_render_time.stop();
                }
                else
                {
                    size = display.font.MeasureString("Waiting for Initialization");
                    display.draw_text(spriteBatch, display.font, "@11Waiting for Initialization", (int)((screen_size.X / 2) - (size.X / 2)), (int)screen_size.Y / 2, screen_size.X);
                }
                if (draw_debug && world.players.Count > 0)
                {
                    //display.draw_text(spriteBatch, "@00" + network_server.udp_server.Statistics.ToString(), 4, 155, screen_size.X, false);
                    display.draw_text(spriteBatch, "@00" + world.ToString(), 4, 155, screen_size.X, false);
                    string  stats    = world.frame_render_time.ToString();
                    Vector2 size_str = display.middle_font.MeasureString(stats);
                    display.draw_text(spriteBatch, display.middle_font, "@07" + stats, screen_size.X - (int)size_str.X, screen_size.Y - (int)size_str.Y, screen_size.X);

                    stats    = world.water_update_time.ToString();
                    size_str = display.middle_font.MeasureString(stats);
                    display.draw_text(spriteBatch, display.middle_font, "@07" + stats, screen_size.X - (int)size_str.X, screen_size.Y - (int)size_str.Y - 30, screen_size.X);

                    stats    = world.light_time.ToString();
                    size_str = display.middle_font.MeasureString(stats);
                    display.draw_text(spriteBatch, display.middle_font, "@07" + stats, screen_size.X - (int)size_str.X, screen_size.Y - (int)size_str.Y - 60, screen_size.X);

                    stats    = world.updating.ToString();
                    size_str = display.middle_font.MeasureString(stats);
                    display.draw_text(spriteBatch, display.middle_font, "@07" + stats, screen_size.X - (int)size_str.X, screen_size.Y - (int)size_str.Y - 90, screen_size.X);

                    stats    = world.total_fps.ToString();
                    size_str = display.middle_font.MeasureString(stats);
                    display.draw_text(spriteBatch, display.middle_font, "@07" + stats, screen_size.X - (int)size_str.X, screen_size.Y - (int)size_str.Y - 120, screen_size.X);

                    stats    = world.world_generation.ToString();
                    size_str = display.middle_font.MeasureString(stats);
                    display.draw_text(spriteBatch, display.middle_font, "@07" + stats, screen_size.X - (int)size_str.X, screen_size.Y - (int)size_str.Y - 150, screen_size.X);

                    stats    = world.flowing_blocks.ToString();
                    size_str = display.middle_font.MeasureString(stats);
                    display.draw_text(spriteBatch, display.middle_font, "@07" + stats, screen_size.X - (int)size_str.X, screen_size.Y - (int)size_str.Y - 180, screen_size.X);
                }
                if (world.players.Count > 0 && settings.show_ping && play_type != "Single Player")
                {
                    string  stats    = "";
                    Vector2 size_str = new Vector2();

                    if (game_server)
                    {
                        stats    = "Hosting";
                        size_str = display.small_font.MeasureString(stats);
                        display.draw_text(spriteBatch, display.small_font, Display.color_code + "00Hosting", screen_size.X - (int)size_str.X, 0, 220);
                    }
                    else if (network_client.udp_client.Connections.Count > 0)
                    {
                        stats    = "ping: " + Math.Round(network_client.udp_client.Connections[0].AverageRoundtripTime * 1000f, 1).ToString() + "ms";
                        size_str = display.small_font.MeasureString(stats);
                        display.draw_text(spriteBatch, display.small_font, Display.color_code + "00" + stats, screen_size.X - (int)size_str.X, 0, 120);
                    }
                    else
                    {
                        stats    = "ping: DISCONNECTED";
                        size_str = display.small_font.MeasureString(stats);
                        display.draw_text(spriteBatch, display.small_font, Display.color_code + "00ping: @07DISCONNECTED", screen_size.X - (int)size_str.X, 0, 220);
                    }
                }
                break;
            }
            display.draw_messages(spriteBatch, input);
            if (draw_debug)
            {
                display.draw_text_with_outline(spriteBatch, display.small_font, Display.color_code + "00" + debug, 4, 204, screen_size.X, AccColors.Adamantium);
            }
            spriteBatch.Draw(display.sprites, new Rectangle(input.mouse_now.X, input.mouse_now.Y, (int)(16.0 * 2), (int)(16.0 * 2)), display.mouse, Color.White);
            spriteBatch.End();

            if (take_screen_shot)
            {
                GraphicsDevice.SetRenderTarget(null);
                try
                {
                    System.IO.Directory.CreateDirectory(@"screenshots");
                }
                catch
                {
                }
                System.IO.StreamWriter w = new System.IO.StreamWriter(@"screenshots/screenshot_" + DateTime.Now.Ticks.ToString() + ".png");
                renderTarget.SaveAsPng(w.BaseStream, screen_size.X, screen_size.Y);
                w.Close();
                Exilania.display.add_message("@05Screenshot Saved.");
                if (settings.use_hardware_lighting)
                {
                    /*w = new System.IO.StreamWriter(@"screenshots/screenshot_" + DateTime.Now.Ticks.ToString() + "lights.png");
                     * lighting.lightsTarget.SaveAsPng(w.BaseStream, lighting.lightsTarget.Width, lighting.lightsTarget.Height);
                     * w.Close();*/
                }
                take_screen_shot = false;
                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);
                spriteBatch.Draw(renderTarget, new Vector2(0, 0), Color.White);
                spriteBatch.End();
            }
            base.Draw(gameTime);
        }