public CreateAccountControlSet(KeyboardDispatcher dispatcher,
                                IMainButtonController mainButtonController,
                                IAccountController accountController)
     : base(dispatcher, mainButtonController)
 {
     _accountController = accountController;
 }
Exemple #2
0
        protected override void Initialize()
        {
            IsMouseVisible = true;

            _keyboardDispatcher = new KeyboardDispatcher(Window);

            var form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(Window.Handle);

            form.Location = new System.Drawing.Point(0, 0);

            Graphics.PreferredBackBufferWidth  = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            Graphics.PreferredBackBufferHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            Graphics.IsFullScreen = false;
            Graphics.ApplyChanges();

            _netManager   = new NetManager();
            _inputManager = new InputManager(_netManager);

            MessageHandler.Initialize(
                Content.Load <Texture2D>("BoxTexture"),
                Content.Load <SpriteFont>("BoxFont"),
                Color.Black);

            _camera     = new Camera2D(GraphicsDevice);
            _viewMatrix = _camera.GetViewMatrix();

            base.Initialize();
        }
Exemple #3
0
 protected override void OnActivated()
 {
     if (camera != null && camera.Display != null)
     {
         keyboardDispatcher = camera.Display.KeyboardDispatcher;
     }
 }
 protected IntermediateControlSet(KeyboardDispatcher dispatcher,
                                  IMainButtonController mainButtonController)
     : base(mainButtonController)
 {
     _dispatcher = dispatcher;
     _personSet2 = new Texture2D[8];
     _randomGen  = new Random();
 }
 public LoginPromptControlSet(KeyboardDispatcher dispatcher,
                              IConfigurationProvider configProvider,
                              IMainButtonController mainButtonController,
                              ILoginController loginController)
     : base(configProvider, mainButtonController)
 {
     _dispatcher           = dispatcher;
     _mainButtonController = mainButtonController;
     _loginController      = loginController;
 }
        public TextBoxClickEventHandler(KeyboardDispatcher dispatcher, params IXNATextBox[] subscribers)
        {
            _dispatcher  = dispatcher;
            _subscribers = subscribers;

            foreach (var textBox in _subscribers)
            {
                textBox.OnClicked += OnClicked;
            }
        }
Exemple #7
0
        /// <summary>
        /// Initializes the <see cref="Manager"/> class with the given values.
        /// </summary>
        /// <param name="device">
        /// A <see cref="GraphicsDevice"/> used to create default objects.
        /// </param>
        /// <param name="font">
        /// A <see cref="SpriteFont"/> used as default <see cref="SpriteFont"/>.
        /// </param>
        /// <param name="window">
        /// An instance of <see cref="GameWindow"/> used by XnaForms.
        /// </param>
        public static void Initialize(GraphicsDevice device, SpriteFont font, GameWindow window)
        {
            Manager.graphicsDevice     = device;
            Manager.spriteBatch        = new ComponentSpriteBatch(device);
            Manager.window             = window;
            Manager.keyboardDispatcher = new KeyboardDispatcher(window);
            Texture2D texture = new Texture2D(device, 1, 1);

            texture.SetData <Color>(new[] { Color.White });
            DefaultStyles.Initialize(device, font);
            Manager.IsInitialized = true;
        }
 public LoggedInControlSet(KeyboardDispatcher dispatcher,
                           IMainButtonController mainButtonController,
                           ICharacterInfoPanelFactory characterInfoPanelFactory,
                           ICharacterManagementController characterManagementController,
                           IAccountController accountController)
     : base(dispatcher, mainButtonController)
 {
     _characterInfoPanelFactory     = characterInfoPanelFactory;
     _characterManagementController = characterManagementController;
     _accountController             = accountController;
     _characterInfoPanels           = new List <CharacterInfoPanel>();
 }
Exemple #9
0
 public ChatBox() : base(Game1.viewport.Width / 2 - Game1.tileSize * 12 / 2 - Game1.tileSize, Game1.viewport.Height - Game1.tileSize * 2 - Game1.tileSize / 2, Game1.tileSize * 14, 56, false)
 {
     this.chatBox = new TextBox(Game1.content.Load <Texture2D>("LooseSprites\\chatBox"), null, Game1.smallFont, Color.White);
     this.e       = new TextBoxEvent(this.textBoxEnter);
     this.chatBox.OnEnterPressed       += this.e;
     this.keyboardDispatcher            = Game1.keyboardDispatcher;
     this.keyboardDispatcher.Subscriber = this.chatBox;
     this.chatBox.X        = this.xPositionOnScreen;
     this.chatBox.Y        = this.yPositionOnScreen;
     this.chatBox.Width    = this.width;
     this.chatBox.Height   = 56;
     this.chatBox.Selected = false;
 }
Exemple #10
0
 public CooperativeMenu() : base(Game1.viewport.Width / 2 - Game1.viewport.Width / 5, (int)((float)Game1.viewport.Height * 0.2f + (float)Game1.tileSize), (int)((float)Game1.viewport.Width * 0.4f), (int)((float)Game1.viewport.Height * 0.2f), false)
 {
     this.keyboardDispatcher = Game1.keyboardDispatcher;
     this.textBox            = new TextBox(null, null, Game1.dialogueFont, Color.Black);
     this.textBox.X          = this.xPositionOnScreen;
     this.textBox.Y          = this.yPositionOnScreen;
     this.textBox.Width      = Game1.tileSize * 6;
     this.textBox.Height     = Game1.tileSize * 3;
     this.e = new TextBoxEvent(this.textBoxEnter);
     this.textBox.OnEnterPressed       += this.e;
     this.keyboardDispatcher.Subscriber = this.textBox;
     this.joinGame = new ClickableComponent(new Rectangle(this.xPositionOnScreen, this.height + Game1.tileSize, this.width * 2 / 3, this.height), Game1.content.LoadString("Strings\\StringsFromCSFiles:CooperativeMenu.cs.10318", new object[0]));
     this.hostGame = new ClickableComponent(new Rectangle(this.xPositionOnScreen, this.height * 2 + Game1.tileSize, this.width * 2 / 3, this.height), Game1.content.LoadString("Strings\\StringsFromCSFiles:CooperativeMenu.cs.10319", new object[0]));
 }
Exemple #11
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            this.spriteBatch = new SpriteBatch(GraphicsDevice);
            this.font        = this.Content.Load <SpriteFont>("Courier New");
            Console.Initialize(this, font);
            System.Console.WriteLine("Hello world!");
            System.Console.Error.WriteLine("Hello ");
            System.Console.Error.Write("error!");
            System.Console.Out.Write("Press keys!");
            System.Console.ReadLine();
            KeyboardDispatcher keyboardDispatcher = new KeyboardDispatcher(this.Window);

            keyboardDispatcher.Receiver = new Console();
        }
Exemple #12
0
        protected override bool OnAttached()
        {
            if (!Application.Current.IsEditor)
            {
                var display = this.Managers.RenderManager.ActiveCamera3D.Display;
                if (display != null)
                {
                    this.keyboardDispacher = display.KeyboardDispatcher;

                    if (this.keyboardDispacher != null)
                    {
                        this.keyboardDispacher.KeyUp += this.OnKeyUp;
                    }
                }

                this.animIndex = 2;
                this.CycleAnimation();
            }

            return(base.OnAttached());
        }
        public override void Update(TimeSpan gameTime)
        {
            if (this.keyboardDispatcher == null)
            {
                this.keyboardDispatcher = this.graphicsPresenter.FocusedDisplay?.KeyboardDispatcher;
            }

            if (this.keyboardDispatcher == null)
            {
                return;
            }

            if (this.keyboardDispatcher.IsKeyDown(Keys.Tab))
            {
                for (int i = 0; i < 10; i++)
                {
                    if (this.keyboardDispatcher.ReadKeyState(Keys.D0 + i) == ButtonState.Pressing)
                    {
                        this.currentFakeCommand = (10 * this.currentFakeCommand ?? 0) + i;
                    }
                }
            }
            else if (this.currentFakeCommand.HasValue)
            {
                var index = this.currentFakeCommand.Value;
                this.currentFakeCommand = null;

                if (index < this.voiceCommands.Length)
                {
                    var command = this.voiceCommands[index];
                    Debug.WriteLine($"[{nameof(FakeVoiceCommandService)}] Fake command recognized: [{index}] {command}");
                    this.CommandRecognized?.Invoke(this, command);
                }
                else
                {
                    Debug.WriteLine($"[{nameof(FakeVoiceCommandService)}] Invalid fake command index: {index}");
                }
            }
        }
        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;
        }
Exemple #15
0
        public CreateCharacterDialog(
            INativeGraphicsManager nativeGraphicsManager,
            IGameStateProvider gameStateProvider,
            ICharacterRendererFactory rendererFactory,
            ContentManager contentManager,
            KeyboardDispatcher dispatcher,
            IEOMessageBoxFactory messageBoxFactory,
            IEODialogButtonService eoDialogButtonService)
            : base(gameStateProvider)
        {
            _messageBoxFactory = messageBoxFactory;
            BackgroundTexture  = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 20);

            _charCreateSheet = nativeGraphicsManager.TextureFromResource(GFXTypes.PreLoginUI, 22);

            var cursorTexture = contentManager.Load <Texture2D>("cursor");

            _inputBox = new XNATextBox(new Rectangle(80, 57, 138, 19), Constants.FontSize08, caretTexture: cursorTexture)
            {
                LeftPadding = 5,
                DefaultText = " ",
                Text        = " ",
                MaxChars    = 12,
                Selected    = true,
                TextColor   = ColorConstants.LightBeigeText,
                Visible     = true
            };
            _inputBox.SetParentControl(this);
            dispatcher.Subscriber = _inputBox;

            for (int i = 0; i < _arrowButtons.Length; ++i)
            {
                var btn = new XNAButton(_charCreateSheet,
                                        new Vector2(196, 85 + i * 26),
                                        new Rectangle(185, 38, 19, 19),
                                        new Rectangle(206, 38, 19, 19));
                btn.OnClick += ArrowButtonClick;
                btn.SetParentControl(this);
                _arrowButtons[i] = btn;
            }

            _characterControl = new CreateCharacterControl(rendererFactory)
            {
                DrawPosition = new Vector2(235, 58)
            };
            _characterControl.SetParentControl(this);

            _srcRectangles[0] = new Rectangle(0, 38, 23, 19);
            _srcRectangles[1] = new Rectangle(0, 19, 23, 19);
            _srcRectangles[2] = new Rectangle(0, 0, 23, 19);
            _srcRectangles[3] = new Rectangle(46, 38, 23, 19);

            _ok = new XNAButton(eoDialogButtonService.SmallButtonSheet,
                                new Vector2(157, 195),
                                eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Ok),
                                eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Ok));
            _ok.OnClick += (s, e) => ClickOk();
            _ok.SetParentControl(this);

            _cancel = new XNAButton(eoDialogButtonService.SmallButtonSheet,
                                    new Vector2(250, 195),
                                    eoDialogButtonService.GetSmallDialogButtonOutSource(SmallButton.Cancel),
                                    eoDialogButtonService.GetSmallDialogButtonOverSource(SmallButton.Cancel));
            _cancel.OnClick += (s, e) => Close(XNADialogResult.Cancel);
            _cancel.SetParentControl(this);

            CenterInGameView();
        }
		public EOCreateCharacterDialog(Texture2D cursorTexture, KeyboardDispatcher dispatcher)
		{
			bgTexture = ((EOGame)Game).GFXManager.TextureFromResource(GFXTypes.PreLoginUI, 20);
			_setSize(bgTexture.Width, bgTexture.Height);

			charCreateSheet = ((EOGame)Game).GFXManager.TextureFromResource(GFXTypes.PreLoginUI, 22);

			inputBox = new XNATextBox(new Rectangle(80, 57, 138, 19), cursorTexture, Constants.FontSize08)
			{
				LeftPadding = 5,
				DefaultText = " ",
				MaxChars = 12,
				Selected = true,
				TextColor = Constants.LightBeigeText,
				Visible = true
			};
			inputBox.SetParent(this);
			dispatcher.Subscriber = inputBox;

			//four arrow buttons
			for (int i = 0; i < arrowButtons.Length; ++i)
			{
				XNAButton btn = new XNAButton(charCreateSheet, new Vector2(196, 85 + i * 26), new Rectangle(185, 38, 19, 19), new Rectangle(206, 38, 19, 19))
				{
					Visible = true
				};
				btn.OnClick += ArrowButtonClick;
				btn.SetParent(this);
				arrowButtons[i] = btn;
			}

			charRender = new CharacterRenderer(new Vector2(269, 83), new CharRenderData { gender = 0, hairstyle = 1, haircolor = 0, race = 0 });
			charRender.SetParent(this);
			srcRects[0] = new Rectangle(0, 38, 23, 19);
			srcRects[1] = new Rectangle(0, 19, 23, 19);
			srcRects[2] = new Rectangle(0, 0, 23, 19);
			srcRects[3] = new Rectangle(46, 38, 23, 19);

			//ok/cancel buttons
			XNAButton ok = new XNAButton(smallButtonSheet, new Vector2(157, 195), _getSmallButtonOut(SmallButton.Ok), _getSmallButtonOver(SmallButton.Ok))
			{
				Visible = true
			};
			ok.OnClick += (s, e) =>
			{
				if (inputBox.Text.Length < 4)
				{
					EOMessageBox.Show(DATCONST1.CHARACTER_CREATE_NAME_TOO_SHORT);
					return;
				}

				Close(ok, XNADialogResult.OK);
			};
			ok.SetParent(this);
			dlgButtons.Add(ok);

			XNAButton cancel = new XNAButton(smallButtonSheet, new Vector2(250, 195), _getSmallButtonOut(SmallButton.Cancel), _getSmallButtonOver(SmallButton.Cancel))
			{
				Visible = true
			};
			cancel.OnClick += (s, e) => Close(cancel, XNADialogResult.Cancel);
			cancel.SetParent(this);
			dlgButtons.Add(cancel);

			endConstructor();
		}
Exemple #17
0
        protected override void Initialize()
        {
            try
            {
                //yup. class named the same as a namespace. #whut #rekt
                XNAControls.XNAControls.Initialize(this);
            }
            catch (ArgumentNullException ex)
            {
                MessageBox.Show("Something super weird happened: " + ex.Message);
                Exit();
                return;
            }

            IsMouseVisible = true;
            Dispatcher     = new KeyboardDispatcher(Window);
            ResetPeopleIndices();

            try
            {
                GFXLoader.Initialize(GraphicsDevice);
                World w = World.Instance;                 //set up the world
                w.Init();

                host = World.Instance.Host;
                port = World.Instance.Port;
            }
            catch (WorldLoadException wle)             //could be thrown from World's constructor
            {
                MessageBox.Show(wle.Message, "Error");
                Exit();
                return;
            }
            catch (ConfigStringLoadException csle)
            {
                host = World.Instance.Host;
                port = World.Instance.Port;
                switch (csle.WhichString)
                {
                case ConfigStrings.Host:
                    MessageBox.Show(
                        string.Format("There was an error loading the host/port from the config file. Defaults will be used: {0}:{1}",
                                      host, port),
                        "Config Load Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    break;

                case ConfigStrings.Port:
                    MessageBox.Show(
                        string.Format("There was an error loading the port from the config file. Default will be used: {0}:{1}",
                                      host, port),
                        "Config Load Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    break;
                }
            }
            catch (ArgumentException ex)             //could be thrown from GFXLoader.Initialize
            {
                MessageBox.Show("Error initializing GFXLoader: " + ex.Message, "Error");
                Exit();
                return;
            }

            if (World.Instance.EIF != null && World.Instance.EIF.Version == 0)
            {
                MessageBox.Show("The item pub file you are using is using an older format of the EIF specification. Some features may not work properly. Run the file through a batch processor or use updated pub files.", "Warning");
            }

            GFXTypes curValue = 0;

            try
            {
                Array values = Enum.GetValues(typeof(GFXTypes));
                foreach (GFXTypes value in values)
                {
                    curValue = value;
                    //check for GFX files. Each file has a GFX 1.
                    using (Texture2D throwAway = GFXLoader.TextureFromResource(value, -99))
                    {
                        throwAway.Name = "";                         //no-op to keep resharper happy
                    }
                }
            }
            catch
            {
                MessageBox.Show(string.Format("There was an error loading GFX{0:000}.EGF : {1}. Place all .GFX files in .\\gfx\\", (int)curValue, curValue.ToString()), "Error");
                Exit();
                return;
            }

            try
            {
                SoundManager = new EOSoundManager();
            }
            catch
            {
                MessageBox.Show(string.Format("There was an error initializing the sound manager."), "Error");
                Exit();
                return;
            }

            if (World.Instance.MusicEnabled)
            {
                SoundManager.PlayBackgroundMusic(1);                 //mfx001 == main menu theme
            }

            base.Initialize();
        }
Exemple #18
0
 public static void Init(GameWindow window)
 {
     keyboardDispatcher = new KeyboardDispatcher(window);
 }
		public ChangePasswordDialog(Texture2D cursorTexture, KeyboardDispatcher dispatcher)
		{
			dispatch = dispatcher;

			bgTexture = ((EOGame)Game).GFXManager.TextureFromResource(GFXTypes.PreLoginUI, 21);
			_setSize(bgTexture.Width, bgTexture.Height);

			for (int i = 0; i < inputBoxes.Length; ++i)
			{
				XNATextBox tb = new XNATextBox(new Rectangle(198, 60 + i * 30, 137, 19), cursorTexture, Constants.FontSize08)
				{
					LeftPadding = 5,
					DefaultText = " ",
					MaxChars = i == 0 ? 16 : 12,
					PasswordBox = i > 1,
					Selected = i == 0,
					TextColor = Constants.LightBeigeText,
					Visible = true
				};

				tb.OnTabPressed += (s, e) =>
				{
					List<XNATextBox> list = inputBoxes.ToList();
					int tbIndex = list.FindIndex(txt => txt == s);

					int next = tbIndex + 1 > 3 ? 0 : tbIndex + 1;
					inputBoxes[tbIndex].Selected = false;
					inputBoxes[next].Selected = true;
					dispatch.Subscriber = inputBoxes[next];
				};

				tb.OnClicked += (s, e) =>
				{
					dispatch.Subscriber.Selected = false;
					dispatch.Subscriber = (s as XNATextBox);
					dispatcher.Subscriber.Selected = true;
				};

				tb.SetParent(this);
				inputBoxes[i] = tb;
			}

			dispatch.Subscriber = inputBoxes[0];

			XNAButton ok = new XNAButton(smallButtonSheet, new Vector2(157, 195), _getSmallButtonOut(SmallButton.Ok), _getSmallButtonOver(SmallButton.Ok))
			{
				Visible = true
			};
			ok.OnClick += (s, e) =>
			{ //does some input validation before trying to call Close
				//check that all fields are filled in, otherwise: return
				if (inputBoxes.Any(tb => string.IsNullOrWhiteSpace(tb.Text))) return;

				if (Username != World.Instance.MainPlayer.AccountName)
				{
					EOMessageBox.Show(DATCONST1.CHANGE_PASSWORD_MISMATCH);
					return;
				}

				//check that passwords match, otherwise: return
				if (inputBoxes[2].Text.Length != inputBoxes[3].Text.Length || inputBoxes[2].Text != inputBoxes[3].Text)
				{
					EOMessageBox.Show(DATCONST1.ACCOUNT_CREATE_PASSWORD_MISMATCH);
					return;
				}

				//check that password is > 6 chars, otherwise: return
				if (inputBoxes[2].Text.Length < 6)
				{
					EOMessageBox.Show(DATCONST1.ACCOUNT_CREATE_PASSWORD_TOO_SHORT);
					return;
				}

				Close(ok, XNADialogResult.OK);
			};
			ok.SetParent(this);
			dlgButtons.Add(ok);

			XNAButton cancel = new XNAButton(smallButtonSheet, new Vector2(250, 195), _getSmallButtonOut(SmallButton.Cancel), _getSmallButtonOver(SmallButton.Cancel))
			{
				Visible = true
			};
			cancel.OnClick += (s, e) => Close(cancel, XNADialogResult.Cancel);
			cancel.SetParent(this);
			dlgButtons.Add(cancel);

			endConstructor();
		}
        /// <inheritdoc/>
        protected override void Update(TimeSpan gameTime)
        {
            if (this.mouseDispatcher == null)
            {
                var display = this.Managers.RenderManager.ActiveCamera3D?.Display;

                if (display != null)
                {
                    this.mouseDispatcher    = display.MouseDispatcher;
                    this.keyboardDispatcher = display.KeyboardDispatcher;
                }

                if ((this.mouseDispatcher == null) || (this.keyboardDispatcher == null))
                {
                    return;
                }
            }

            if (this.mouseDispatcher.IsButtonDown(MouseButtons.Left) || this.mouseDispatcher.IsButtonDown(MouseButtons.Right))
            {
                var deltaRotation = this.mouseDispatcher.PositionDelta.ToVector2() * this.OrbitMouseFactor;
                this.theta  += deltaRotation.X;
                this.lambda += deltaRotation.Y;
                this.lambda  = Math.Max(this.MinElevationAngle, Math.Min(this.MaxElevationAngle, this.lambda));
            }

            if (this.keyboardDispatcher.IsKeyDown(Keys.A) || this.keyboardDispatcher.IsKeyDown(Keys.Left))
            {
                this.theta += this.OrbitKeyboardFactor;
            }

            if (this.keyboardDispatcher.IsKeyDown(Keys.D) || this.keyboardDispatcher.IsKeyDown(Keys.Right))
            {
                this.theta -= this.OrbitKeyboardFactor;
            }

            if (this.keyboardDispatcher.IsKeyDown(Keys.W) || this.keyboardDispatcher.IsKeyDown(Keys.Up))
            {
                this.lambda += this.OrbitKeyboardFactor;
                this.lambda  = Math.Max(this.MinElevationAngle, Math.Min(this.MaxElevationAngle, this.lambda));
            }

            if (this.keyboardDispatcher.IsKeyDown(Keys.S) || this.keyboardDispatcher.IsKeyDown(Keys.Down))
            {
                this.lambda -= this.OrbitKeyboardFactor;
                this.lambda  = Math.Max(this.MinElevationAngle, Math.Min(this.MaxElevationAngle, this.lambda));
            }

            if (this.mouseDispatcher.ScrollDelta.Y != 0)
            {
                var deltazoom = this.mouseDispatcher.ScrollDelta.Y * this.ZoomFactor;

                this.zoom -= deltazoom;

                this.zoom = Math.Max(this.MaxZoom, Math.Min(this.MinZoom, this.zoom));
            }

            float elapsedMilliseconds = (float)gameTime.TotalMilliseconds;

            var direction = Quaternion.CreateFromYawPitchRoll(-this.theta, -this.lambda, 0);

            this.Transform.LocalOrientation = Quaternion.SmoothDamp(
                this.Transform.LocalOrientation,
                direction,
                ref this.objectOrbitSmoothDampDeriv,
                this.OrbitSmooth,
                elapsedMilliseconds);

            var localPos = this.targetTransform.LocalPosition;

            localPos.Z = MathHelper.SmoothDamp(
                localPos.Z,
                this.zoom,
                ref this.zoomVelocity,
                this.ZoomSmooth,
                elapsedMilliseconds);
            this.targetTransform.LocalPosition = localPos;
        }
Exemple #21
0
		protected override void Initialize()
		{
			IsMouseVisible = true;
			Dispatcher = new KeyboardDispatcher(Window);
			ResetPeopleIndices();

			if (!InitializeXNAControls() ||
				!InitializeGFXManager() ||
				!InitializeWorld() || 
				!InitializeSoundManager())
				return;

			base.Initialize();
		}
Exemple #22
0
		protected override void Initialize()
		{
			try
			{
				//yup. class named the same as a namespace. #whut #rekt
				XNAControls.XNAControls.Initialize(this);
			}
			catch (ArgumentNullException ex)
			{
				MessageBox.Show("Something super weird happened: " + ex.Message);
				Exit();
				return;
			}

			IsMouseVisible = true;
			Dispatcher = new KeyboardDispatcher(Window);
			ResetPeopleIndices();

			try
			{
				GFXLoader.Initialize(GraphicsDevice);
				World w = World.Instance; //set up the world
				w.Init();

				host = World.Instance.Host;
				port = World.Instance.Port;
			}
			catch (WorldLoadException wle) //could be thrown from World's constructor
			{
				MessageBox.Show(wle.Message, "Error");
				Exit();
				return;
			}
			catch (ConfigStringLoadException csle)
			{
				host = World.Instance.Host;
				port = World.Instance.Port;
				switch (csle.WhichString)
				{
					case ConfigStrings.Host:
						MessageBox.Show(
							string.Format("There was an error loading the host/port from the config file. Defaults will be used: {0}:{1}",
								host, port),
							"Config Load Failed",
							MessageBoxButtons.OK,
							MessageBoxIcon.Warning);
						break;
					case ConfigStrings.Port:
						MessageBox.Show(
							string.Format("There was an error loading the port from the config file. Default will be used: {0}:{1}",
								host, port),
							"Config Load Failed",
							MessageBoxButtons.OK,
							MessageBoxIcon.Warning);
						break;
				}
			}
			catch (ArgumentException ex) //could be thrown from GFXLoader.Initialize
			{
				MessageBox.Show("Error initializing GFXLoader: " + ex.Message, "Error");
				Exit();
				return;
			}

			if(World.Instance.EIF != null && World.Instance.EIF.Version == 0)
			{
				MessageBox.Show("The item pub file you are using is using an older format of the EIF specification. Some features may not work properly. Run the file through a batch processor or use updated pub files.", "Warning");
			}

			GFXTypes curValue = 0;
			try
			{
				Array values = Enum.GetValues(typeof(GFXTypes));
				foreach (GFXTypes value in values)
				{
					curValue = value;
					//check for GFX files. Each file has a GFX 1.
					using (Texture2D throwAway = GFXLoader.TextureFromResource(value, -99))
					{
						throwAway.Name = ""; //no-op to keep resharper happy
					}
				}
			}
			catch
			{
				MessageBox.Show(string.Format("There was an error loading GFX{0:000}.EGF : {1}. Place all .GFX files in .\\gfx\\", (int)curValue, curValue.ToString()), "Error");
				Exit();
				return;
			}

			try
			{
				SoundManager = new EOSoundManager();
			}
			catch
			{
				MessageBox.Show(string.Format("There was an error initializing the sound manager."), "Error");
				Exit();
				return;
			}

			if (World.Instance.MusicEnabled)
			{
				SoundManager.PlayBackgroundMusic(1); //mfx001 == main menu theme
			}
			
			base.Initialize();
		}