protected override void LoadContent()
        {
            int screenWidth = GraphicsDevice.Viewport.Width;
            int screenHeight = GraphicsDevice.Viewport.Height;

            black = new Texture2D(GraphicsDevice, 1, 1);
            black.SetData(new[] { Color.Black });

            bones = Engine.AnglerGame.Content.Load<Texture2D>("fishBones");

            pauseMenu = new XNAMenu(Game, new Rectangle(screenWidth / 2 - 150, screenHeight / 2 - 100, 280, 150))
            {
                ForeColor = SD.Color.FromArgb(165, 165, 165),
                HighlightColor = SD.Color.White,
                BackgroundColor = SD.Color.FromArgb(125, 0, 0, 0),
                BorderColor = SD.Color.FromArgb(200, 50, 50, 50),
                Font = new SD.Font("Calibri", 20),
                RenderingHint = SD.Text.TextRenderingHint.SingleBitPerPixelGridFit,
                SelectionEmphasisTexture = bones,
                ItemHeight = 40,
                Visible = false
            };
            pauseMenu.SelectionChanged += (o, e) => { FXCollection.SoundEffects[SoundEffects.Blip].Play(); };

            pauseMenu.AddMenuItem("Toggle Music", (o, e) =>
            {
                if (Engine.AnglerGame.GamePaused)
                {
                    FXCollection.SoundEffects[SoundEffects.Select].Play();

                    if (!FXCollection.Songs[Songs.InGame].Playing)
                        FXCollection.Songs[Songs.InGame].Play();
                    else
                    {
                        foreach (LoopedSoundPlayer player in FXCollection.Songs)
                        {
                            if (player.Playing)
                                player.Stop();
                        }
                    }
                }
            });
            pauseMenu.AddMenuItem("Log Out", (o, e) =>
                {
                    if (Engine.AnglerGame.GamePaused)
                    {
                        FXCollection.SoundEffects[SoundEffects.Select].Play();

                        pauseMenu.SelectedIndex = 0;
                        Engine.AnglerGame.GamePaused = false;
                        World.MainPlayer.SendToServer(ServerAction.ClientLogout);
                    }
                });
            pauseMenu.AddMenuItem("Quit Game", (o, e) =>
            {
                if (Engine.AnglerGame.GamePaused)
                {
                    FXCollection.SoundEffects[SoundEffects.Select].Play();
                    System.Threading.Tasks.Task.Factory.StartNew(() =>
                        {
                            System.Threading.Thread.Sleep(300); // Make sure the select sound plays
                            Engine.Game.Exit();
                        });
                }
            });

            base.LoadContent();
        }
예제 #2
0
        protected override void LoadContent()
        {
            // Load textures, map and sounds
            Tileset ts = new Tileset();

            try
            {
                ts.LoadFromStream(typeof(Map).Assembly.GetManifestResourceStream("GameClassLibrary.game.tileset"));

                FXCollection.Textures = new List <Texture2D>();
                for (int i = 0; i < ts.Images.Images.Count; i++)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        ts.Images.Images[i].Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        FXCollection.Textures.Add(Texture2D.FromStream(GraphicsDevice, ms));
                    }
                }

                // Load sounds
                FXCollection.Songs        = new List <LoopedSoundPlayer>();
                FXCollection.SoundEffects = new List <SoundEffectInstance>();
                FXCollection.Songs[Songs.PreGame = FXCollection.Load <SoundEffect>("Audio\\Music\\titleSong")].Overlap       = new TimeSpan(0, 0, 0, 0, 1500);
                FXCollection.Songs[Songs.InGame = FXCollection.Load <SoundEffect>("Audio\\Music\\inGameBackground")].Overlap = new TimeSpan(0, 0, 0, 0, 2500);
                SoundEffects.Select  = FXCollection.Load <SoundEffectInstance>("Audio\\SoundEffects\\pop");
                SoundEffects.Collect = FXCollection.Load <SoundEffectInstance>("Audio\\SoundEffects\\boop");
                SoundEffects.Blip    = FXCollection.Load <SoundEffectInstance>("Audio\\SoundEffects\\blip");
            }
            catch
            {
                throw new Exception("There was a problem loading a resource!");
            }

            // Create audio zones for enemies
            for (int i = 1; i < World.Players.Count; i++)
            {
                Player e = World.Players[i];

                if (e is Enemy)
                {
                    // Temporary - just use the color red for enemies, rather than an actual texture
                    Texture2D texture = new Texture2D(GraphicsDevice, 1, 1);
                    texture.SetData(new[] { Color.Red });
                    FXCollection.Textures.Add(texture);

                    World.Players[i].CurrentGraphicIndex = FXCollection.Textures.Count - 1;
                    audioManager.AddZone(new EnemyAudioZone(e as Enemy, FXCollection.Load <SoundEffectInstance>("Audio\\Music\\tone"), 200));
                }
            }

            World.LightsFX = new LightsFX(
                Content.Load <Effect>("Effects\\resolveShadowsEffect"),
                Content.Load <Effect>("Effects\\reductionEffect"),
                Content.Load <Effect>("Effects\\2xMultiBlend"));

            // Eventually, the lower four lines graphics will be pulled from the tileset
            World.MainPlayer.BackGraphicIndex  = FXCollection.Load <Texture2D>("back_sprite");
            World.MainPlayer.FrontGraphicIndex = FXCollection.Load <Texture2D>("front_sprite");
            World.MainPlayer.LeftGraphicIndex  = FXCollection.Load <Texture2D>("left_sprite");
            World.MainPlayer.RightGraphicIndex = FXCollection.Load <Texture2D>("right_sprite");

            World.MainPlayer.CurrentGraphicIndex = World.MainPlayer.FrontGraphicIndex;

            KeyboardDispatcher = new KeyboardDispatcher(Window);

            inGamePanel      = new XNAComponentPanel(this);
            loginPanel       = new XNAComponentPanel(this);
            registerPanel    = new XNAComponentPanel(this);
            preGameMenuPanel = new XNAComponentPanel(this);
            howToPlayPanel   = new XNAComponentPanel(this);
            backgroundPanel  = new XNAComponentPanel(this);

            int screenWidth  = GraphicsDevice.Viewport.Width;
            int screenHeight = GraphicsDevice.Viewport.Height;

            Texture2D[] textboxTextures = new Texture2D[4]
            {
                Content.Load <Texture2D>("textboxBack"),
                Content.Load <Texture2D>("textboxLeft"),
                Content.Load <Texture2D>("textboxRight"),
                Content.Load <Texture2D>("textboxCaret")
            };

            // Background image with ripple effect
            background = new Background(this, Content.Load <Texture2D>("titleBackground"));
            RippleEffect rippleEffect = new RippleEffect(backgroundPanel);

            loginPanel.Components.Add(rippleEffect);
            registerPanel.Components.Add(rippleEffect);
            preGameMenuPanel.Components.Add(rippleEffect);
            howToPlayPanel.Components.Add(rippleEffect);

            PreGameMenu = new XNAMenu(this, new Rectangle(screenWidth / 2 - 150, screenHeight / 2 - 100, 300, 200))
            {
                ForeColor      = SD.Color.FromArgb(25, 50, 150),
                HighlightColor = SD.Color.FromArgb(4, 4, 99),
                Font           = new SD.Font("Calibri", 36),
                RenderingHint  = SD.Text.TextRenderingHint.SingleBitPerPixelGridFit,
                ItemHeight     = 60
            };
            PreGameMenu.SelectionChanged += (o, e) => { FXCollection.SoundEffects[SoundEffects.Blip].Play(); };
            PreGameMenu.AddMenuItem("Log In", (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Select].Play();
                World.GameState = GameState.Login;
            });
            PreGameMenu.AddMenuItem("Create Account", (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Select].Play();
                World.GameState = GameState.Register;
            });
            PreGameMenu.AddMenuItem("How to Play", (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Select].Play();

                World.GameState = GameState.HowToPlay;
            });
            PreGameMenu.AddMenuItem("Quit Game", (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Select].Play();
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    System.Threading.Thread.Sleep(300);                     // Make sure the select sound plays
                    Exit();
                });
            });

            XNAPictureBox titlePicture = new XNAPictureBox(this, new Rectangle(100, screenHeight / 2 - 50, screenWidth - 200, 200))
            {
                StretchMode = StretchMode.CenterInFrame,
                Texture     = Content.Load <Texture2D>("logo")
            };

            loginPanel.Components.Add(titlePicture);
            registerPanel.Components.Add(titlePicture);
            preGameMenuPanel.Components.Add(titlePicture);
            howToPlayPanel.Components.Add(titlePicture);

            //temporary action objects that are used to construct the member TextBoxEvent variables
            Action <object, EventArgs> loginEvent;
            Action <object, EventArgs> registerEvent;

            // Login event
            loginEvent = (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Select].Play();

                World.GameState = GameState.LoggingIn;

                World.MainPlayer.SendToServer(ServerAction.ClientLogin,
                                              new LoginData(usernameTextbox.Text, passwordTextbox.Text));
            };

            loginTBEvent = new TextBoxEvent(loginEvent);

            // Register event
            registerEvent = (o, e) =>
            {
                if (passwordTextbox.Text == confirmPasswordTextbox.Text)
                {
                    FXCollection.SoundEffects[SoundEffects.Select].Play();

                    World.GameState = GameState.Registering;

                    World.MainPlayer.SendToServer(ServerAction.ClientCreateAcc,
                                                  new LoginData(usernameTextbox.Text, passwordTextbox.Text));
                }
                else
                {
                    FXCollection.SoundEffects[SoundEffects.Select].Play();

                    XNADialog errDlg = new XNADialog(this, "Passwords do not match.", "Error creating account!");
                    errDlg.CloseAction = (param) => { FXCollection.SoundEffects[SoundEffects.Select].Play(); };
                }
            };

            XNALabel howToPlayText = new XNALabel(this, new Rectangle(screenWidth / 4, screenHeight / 2 - 80, screenWidth / 2, 300));

            howToPlayText.Text = Resources.HowToPlayText;
            howToPlayText.Font = new SD.Font("Calibri", 16);
            howToPlayPanel.Components.Add(howToPlayText);

            XNAHyperLink backHyperlink = new XNAHyperLink(
                this,
                new Rectangle(3 * screenWidth / 4 - 50, screenHeight / 2 + 75, 50, 30),
                "Arial", 12.0f,
                SD.FontStyle.Bold,
                SD.Text.TextRenderingHint.SingleBitPerPixelGridFit);

            backHyperlink.DrawOrder      = (int)RenderOrder.UILayer;
            backHyperlink.ForeColor      = SD.Color.FromArgb(139, 95, 71);
            backHyperlink.HighlightColor = SD.Color.FromArgb(150, 139, 95, 71);
            backHyperlink.Text           = "Back";
            backHyperlink.TextAlign      = System.Drawing.ContentAlignment.MiddleRight;
            backHyperlink.OnClick       += (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Select].Play();
                World.GameState = GameState.PregameMenu;
            };
            howToPlayPanel.Components.Add(backHyperlink);

            registerTBEvent = new TextBoxEvent(registerEvent);

            subscribeToUsernameBox = (object sender, EventArgs e) => { usernameTextbox.Selected = true; KeyboardDispatcher.Subscriber = usernameTextbox; };
            subscribeToPasswordBox = (object sender, EventArgs e) => { passwordTextbox.Selected = true; KeyboardDispatcher.Subscriber = passwordTextbox; };
            subscribeToConfirmBox  = (object sender, EventArgs e) => { confirmPasswordTextbox.Selected = true; KeyboardDispatcher.Subscriber = confirmPasswordTextbox; };

            // Update error message event
            World.MainPlayer.UpdateErrorMessage += (o, e) =>
            {
                //close any open dialog
                XNADialog errMsg = new XNADialog(this, e.Message, e.Caption);
                if (!(o as ConnectedPlayer).Connected)
                {
                    errMsg.CloseAction += (bool success) =>
                    {
                        FXCollection.SoundEffects[SoundEffects.Select].Play();
                        this.Exit();
                    }
                }
                ;
            };

            World.MainPlayer.BacteriaCollect += (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Collect].Play();

                overlayRenderer.RenderBacteriaCount();
            };

            // Username field
            usernameTextbox             = new XNATextBox(this, new Rectangle(screenWidth / 2 - 100, screenHeight / 2 - 70, 200, 30), textboxTextures, "Arial", 12.0f);
            usernameTextbox.DrawOrder   = (int)RenderOrder.UILayer;
            usernameTextbox.MaxChars    = 30;
            usernameTextbox.DefaultText = "Username";
            usernameTextbox.Clicked    += subscribeToUsernameBox;
            subscribeToUsernameBox(usernameTextbox);
            usernameTextbox.OnTabPressed += subscribeToPasswordBox;
            loginPanel.Components.Add(usernameTextbox);
            registerPanel.Components.Add(usernameTextbox);

            // Password field
            passwordTextbox             = new XNATextBox(this, new Rectangle(screenWidth / 2 - 100, screenHeight / 2 - 20, 200, 30), textboxTextures, "Arial", 12.0f);
            passwordTextbox.DrawOrder   = (int)RenderOrder.UILayer;
            passwordTextbox.MaxChars    = 30;
            passwordTextbox.DefaultText = "Password";
            passwordTextbox.PasswordBox = true;
            passwordTextbox.Clicked    += subscribeToPasswordBox;
            loginPanel.Components.Add(passwordTextbox);
            registerPanel.Components.Add(passwordTextbox);

            // Confirm password field
            confirmPasswordTextbox                 = new XNATextBox(this, new Rectangle(screenWidth / 2 - 100, screenHeight / 2 + 30, 200, 30), textboxTextures, "Arial", 12.0f);
            confirmPasswordTextbox.DrawOrder       = (int)RenderOrder.UILayer;
            confirmPasswordTextbox.MaxChars        = 30;
            confirmPasswordTextbox.DefaultText     = "Confirm Password";
            confirmPasswordTextbox.PasswordBox     = true;
            confirmPasswordTextbox.Clicked        += subscribeToConfirmBox;
            confirmPasswordTextbox.OnTabPressed   += subscribeToUsernameBox;
            confirmPasswordTextbox.OnEnterPressed += new TextBoxEvent(registerEvent);
            registerPanel.Components.Add(confirmPasswordTextbox);

            Texture2D[] loginButtonTextures = new Texture2D[2]
            {
                Content.Load <Texture2D>("button"),
                Content.Load <Texture2D>("buttonHover")
            };

            XNAButton loginButton = new XNAButton(this, new Vector2(screenWidth / 2 + 20, screenHeight / 2 + 30), "Login");

            loginButton.DrawOrder = (int)RenderOrder.UILayer;
            loginButton.OnClick  += new XNAButton.ButtonClickEvent(loginEvent);
            loginPanel.Components.Add(loginButton);

            XNAButton registerButton = new XNAButton(this, new Vector2(screenWidth / 2 + 20, screenHeight / 2 + 80), "Register");

            registerButton.DrawOrder = (int)RenderOrder.UILayer;
            registerButton.OnClick  += new XNAButton.ButtonClickEvent(registerEvent);
            registerPanel.Components.Add(registerButton);

            cancelHyperlink = new XNAHyperLink(
                this,
                new Rectangle(screenWidth / 2 - 95, screenHeight / 2 + 80, 100, 30),
                "Arial", 12.0f,
                SD.FontStyle.Bold,
                SD.Text.TextRenderingHint.SingleBitPerPixelGridFit);
            cancelHyperlink.DrawOrder      = (int)RenderOrder.UILayer;
            cancelHyperlink.ForeColor      = SD.Color.FromArgb(139, 95, 71);
            cancelHyperlink.HighlightColor = SD.Color.FromArgb(150, 139, 95, 71);
            cancelHyperlink.Text           = "Cancel";
            cancelHyperlink.TextAlign      = System.Drawing.ContentAlignment.MiddleLeft;
            cancelHyperlink.OnClick       += (o, e) =>
            {
                FXCollection.SoundEffects[SoundEffects.Select].Play();
                World.GameState = GameState.PregameMenu;
            };
            registerPanel.Components.Add(cancelHyperlink);
            loginPanel.Components.Add(cancelHyperlink);

            // Map renderer
            MapRenderer mapRenderer = new MapRenderer(this, World.CurrentMap);

            inGamePanel.Components.Add(mapRenderer);

            // NPC rendering engine
            GraphicEngine npcEngine = new GraphicEngine(this, RenderOrder.NPCLayer);

            GraphicsEngineComponent.CreateAndAdd <MinorPlayerRenderer>(npcEngine);
            inGamePanel.Components.Add(npcEngine);

            // Overlay rendering engine
            GraphicEngine overlayEngine = new GraphicEngine(this, RenderOrder.OverlayLayer);

            overlayRenderer = GraphicsEngineComponent.CreateAndAdd <OverlayRenderer>(overlayEngine);
            inGamePanel.Components.Add(overlayEngine);

            // Audio manager
            inGamePanel.Components.Add(audioManager = new AudioManager(this));

            // Input handler
            InputHandler = new InputHandler(this);
            inGamePanel.Components.Add(InputHandler);
            InputHandler.ChatBoxClosing += (o, e) =>
            {
                if (ShowChatPrompt && chatRenderer.MessageBox.Text != "")
                {
                    World.MainPlayer.SendToServer(ServerAction.ClientSay, new TalkData(chatRenderer.MessageBox.Text));
                    chatRenderer.MessageBox.Text = "";
                }
            };
            InputHandler.RemoveTilde += () =>
            {
                chatRenderer.MessageBox.Text = chatRenderer.MessageBox.Text.TrimEnd('`');
            };

            // Main Player
            inGamePanel.Components.Add(MainPlayer = new PlayerComponent(this, World.MainPlayer));

            // Pause menu
            GraphicEngine pauseMenuEngine = new GraphicEngine(this, RenderOrder.PauseMenuLayer);

            GraphicsEngineComponent.CreateAndAdd <PauseMenuRenderer>(pauseMenuEngine);
            inGamePanel.Components.Add(pauseMenuEngine);

            // Chat
            GraphicEngine chatEngine = new GraphicEngine(this, RenderOrder.ChatLayer);

            chatRenderer = GraphicsEngineComponent.CreateAndAdd <ChatRenderer>(chatEngine);
            inGamePanel.Components.Add(chatEngine);

            World.GameState = GameState.PregameMenu;
        }
예제 #3
0
        protected override void LoadContent()
        {
            int screenWidth  = GraphicsDevice.Viewport.Width;
            int screenHeight = GraphicsDevice.Viewport.Height;

            black = new Texture2D(GraphicsDevice, 1, 1);
            black.SetData(new[] { Color.Black });

            bones = Engine.AnglerGame.Content.Load <Texture2D>("fishBones");

            pauseMenu = new XNAMenu(Game, new Rectangle(screenWidth / 2 - 150, screenHeight / 2 - 100, 280, 150))
            {
                ForeColor                = SD.Color.FromArgb(165, 165, 165),
                HighlightColor           = SD.Color.White,
                BackgroundColor          = SD.Color.FromArgb(125, 0, 0, 0),
                BorderColor              = SD.Color.FromArgb(200, 50, 50, 50),
                Font                     = new SD.Font("Calibri", 20),
                RenderingHint            = SD.Text.TextRenderingHint.SingleBitPerPixelGridFit,
                SelectionEmphasisTexture = bones,
                ItemHeight               = 40,
                Visible                  = false
            };
            pauseMenu.SelectionChanged += (o, e) => { FXCollection.SoundEffects[SoundEffects.Blip].Play(); };

            pauseMenu.AddMenuItem("Toggle Music", (o, e) =>
            {
                if (Engine.AnglerGame.GamePaused)
                {
                    FXCollection.SoundEffects[SoundEffects.Select].Play();

                    if (!FXCollection.Songs[Songs.InGame].Playing)
                    {
                        FXCollection.Songs[Songs.InGame].Play();
                    }
                    else
                    {
                        foreach (LoopedSoundPlayer player in FXCollection.Songs)
                        {
                            if (player.Playing)
                            {
                                player.Stop();
                            }
                        }
                    }
                }
            });
            pauseMenu.AddMenuItem("Log Out", (o, e) =>
            {
                if (Engine.AnglerGame.GamePaused)
                {
                    FXCollection.SoundEffects[SoundEffects.Select].Play();

                    pauseMenu.SelectedIndex      = 0;
                    Engine.AnglerGame.GamePaused = false;
                    World.MainPlayer.SendToServer(ServerAction.ClientLogout);
                }
            });
            pauseMenu.AddMenuItem("Quit Game", (o, e) =>
            {
                if (Engine.AnglerGame.GamePaused)
                {
                    FXCollection.SoundEffects[SoundEffects.Select].Play();
                    System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        System.Threading.Thread.Sleep(300);                                 // Make sure the select sound plays
                        Engine.Game.Exit();
                    });
                }
            });

            base.LoadContent();
        }