/// <summary> /// Sets up Local Server Dialog. It also sends out the subnet broadcast here searching for any available servers on this subnet. /// </summary> public override void LoadContent() { base.LoadContent(); //The Okay Button here Acts as the "Ready" button for the Server Lobby Btn_Ok.Clicked += new EventHandler<vxGuiItemClickEventArgs>(Btn_Ok_Clicked); //The Cancel Button is Naturally the 'Back' button Btn_Cancel.Clicked += new EventHandler<vxGuiItemClickEventArgs>(Btn_Cancel_Clicked); ScrollPanel = new vxScrollPanel( new Vector2( this.ArtProvider.BoundingGUIRectangle.X + this.ArtProvider.Padding.X, this.ArtProvider.BoundingGUIRectangle.Y + this.ArtProvider.Padding.Y), (int)(this.ArtProvider.BoundingGUIRectangle.Width - this.ArtProvider.Padding.X * 2), (int)(this.ArtProvider.BoundingGUIRectangle.Height - Btn_Ok.BoundingRectangle.Height - this.ArtProvider.Padding.Y * 3)); ScrollPanel.ScrollBarWidth = 15; //Setup Client Events vxEngine.ClientManager.OtherPlayerConnected += ClientManager_OtherPlayerConnected; vxEngine.ClientManager.OtherPlayerDisconnected += ClientManager_OtherPlayerDisconnected; InternalvxGUIManager.Add(ScrollPanel); //Set up the Server Code if (vxEngine.NetworkedGameRoll == vxEnumNetworkPlayerRole.Server) { Vector2 viewportSize = new Vector2(vxEngine.GraphicsDevice.Viewport.Width, vxEngine.GraphicsDevice.Viewport.Height); //Create The New Server Button Btn_LaunchServer = new vxButton(vxEngine, "Launch Game", new Vector2(viewportSize.X / 2 - 115, viewportSize.Y / 2 + 20)); //Set the Button's Position relative too the background rectangle. Btn_LaunchServer.Position = new Vector2( this.ArtProvider.BoundingGUIRectangle.X, this.ArtProvider.BoundingGUIRectangle.Y) + new Vector2( vxEngine.vxGUITheme.Padding.X * 2, this.ArtProvider.BoundingGUIRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight - vxEngine.vxGUITheme.Padding.Y * 2); Btn_LaunchServer.Clicked += Btn_LaunchServer_Clicked; ; InternalvxGUIManager.Add(Btn_LaunchServer); //Now Start The Server vxEngine.ServerManager.Start(); //Now Connect to it's self if it's the Server NetOutgoingMessage approval = vxEngine.ClientManager.CreateMessage(); approval.Write("secret"); vxEngine.ClientManager.Connect(NetUtility.Resolve("localhost").ToString(), vxEngine.ServerManager.Server.Configuration.Port, approval); } //vxEngine.NetworkedGameRoll == vxEnumNetworkPlayerRole.Client //The Server acts as a Client as well, so no need for an 'else if' block here. Btn_Ok.Text = "Not Ready"; }
/// <summary> /// Sets up Local Server Dialog. It also sends out the subnet broadcast here searching for any available servers on this subnet. /// </summary> public override void LoadContent() { base.LoadContent(); Vector2 viewportSize = new Vector2(vxEngine.GraphicsDevice.Viewport.Width, vxEngine.GraphicsDevice.Viewport.Height); //Create The New Server Button Btn_CreateNewLocalServer = new vxButton(vxEngine, "Create New Local Server", new Vector2(viewportSize.X / 2 - 115, viewportSize.Y / 2 + 20)); //Set the Button's Position relative too the background rectangle. Btn_CreateNewLocalServer.Position = new Vector2( this.ArtProvider.BoundingGUIRectangle.X, this.ArtProvider.BoundingGUIRectangle.Y) + new Vector2( vxEngine.vxGUITheme.Padding.X * 2, this.ArtProvider.BoundingGUIRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight - vxEngine.vxGUITheme.Padding.Y * 2); Btn_CreateNewLocalServer.Clicked += Btn_CreateNewLocalServer_Clicked; InternalvxGUIManager.Add(Btn_CreateNewLocalServer); //The Okay Button here Selects the Selected Server in the List Btn_Ok.Clicked += new EventHandler <vxGuiItemClickEventArgs>(Btn_Ok_Clicked); //The Cancel Button is Naturally the 'Back' button Btn_Cancel.Clicked += new EventHandler <vxGuiItemClickEventArgs>(Btn_Cancel_Clicked); //The Apply Button here is used to start a New Server Btn_Apply.Clicked += Btn_Refresh_Clicked;// new EventHandler<vxGuiItemClickEventArgs>(Btn_Refresh_Clicked); Btn_Apply.Text = "Refresh"; ScrollPanel = new vxScrollPanel( new Vector2( this.ArtProvider.BoundingGUIRectangle.X + this.ArtProvider.Padding.X, this.ArtProvider.BoundingGUIRectangle.Y + this.ArtProvider.Padding.Y), (int)(this.ArtProvider.BoundingGUIRectangle.Width - this.ArtProvider.Padding.X * 2), (int)(this.ArtProvider.BoundingGUIRectangle.Height - Btn_Ok.BoundingRectangle.Height - this.ArtProvider.Padding.Y * 3)); ScrollPanel.ScrollBarWidth = 15; InternalvxGUIManager.Add(ScrollPanel); //Initialise the network client vxEngine.ClientManager.Init(); //Now setup the Event Handlers vxEngine.ClientManager.DiscoverySignalResponseRecieved += ClientManager_DiscoverySignalResponseRecieved; //By Default, The Game will start looking for other networked games as a client. vxEngine.NetworkedGameRoll = vxEnumNetworkPlayerRole.Client; //Finally at the end, send out a pulse of discovery signals vxConsole.WriteLine("Sending Discovery Signal..."); SendDiscoverySignal(); }
/// <summary> /// Loads graphics content for this screen. This uses the shared ContentManager /// provided by the Game class, so the content will remain loaded forever. /// Whenever a subsequent MessageBoxScreen tries to load this same content, /// it will just get back another reference to the already loaded data. /// </summary> public override void LoadContent() { InternalvxGUIManager = new vxGuiManager(); this.ArtProvider = (vxDialogArtProvider)vxEngine.vxGUITheme.ArtProviderForDialogs.Clone(); //And just so that all is set up properly, resize anything based off of current resolution scale. ArtProvider.SetBounds(); viewportSize = new Vector2(vxEngine.GraphicsDevice.Viewport.Width, vxEngine.GraphicsDevice.Viewport.Height); Btn_Apply = new vxButton(vxEngine, btn_Apply_text, new Vector2(viewportSize.X / 2 - 115, viewportSize.Y / 2 + 20)); Btn_Ok = new vxButton(vxEngine, btn_ok_text, new Vector2(viewportSize.X / 2 - 115, viewportSize.Y / 2 + 20)); Btn_Cancel = new vxButton(vxEngine, btn_ok_Cancel, new Vector2(viewportSize.X / 2 + 15, viewportSize.Y / 2 + 20)); //Btn_Apply.Clicked += new EventHandler<vxGuiItemClickEventArgs>(Btn_Apply_Clicked); Btn_Ok.Clicked += new EventHandler <vxGuiItemClickEventArgs>(Btn_Ok_Clicked); Btn_Cancel.Clicked += new EventHandler <vxGuiItemClickEventArgs>(Btn_Cancel_Clicked); if (ButtonTypes == vxEnumButtonTypes.OkApplyCancel) { InternalvxGUIManager.Add(Btn_Apply); } InternalvxGUIManager.Add(Btn_Ok); InternalvxGUIManager.Add(Btn_Cancel); spriteBatch = vxEngine.SpriteBatch; font = vxEngine.vxGUITheme.Font; //Reset Gui Item Positions Based off of Background Rectangle Btn_Apply.Position = new Vector2( this.ArtProvider.BoundingGUIRectangle.X, this.ArtProvider.BoundingGUIRectangle.Y) + this.ArtProvider.PosOffset + new Vector2( this.ArtProvider.BoundingGUIRectangle.Width - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultWidth * 3 - vxEngine.vxGUITheme.Padding.X * 3, this.ArtProvider.BoundingGUIRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight * 2 - vxEngine.vxGUITheme.Padding.Y * 2); Btn_Ok.Position = new Vector2( this.ArtProvider.BoundingGUIRectangle.X, this.ArtProvider.BoundingGUIRectangle.Y) + this.ArtProvider.PosOffset + new Vector2( this.ArtProvider.BoundingGUIRectangle.Width - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultWidth * 2 - vxEngine.vxGUITheme.Padding.X * 2, this.ArtProvider.BoundingGUIRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight * 2 - vxEngine.vxGUITheme.Padding.Y * 2); Btn_Cancel.Position = new Vector2( this.ArtProvider.BoundingGUIRectangle.X, this.ArtProvider.BoundingGUIRectangle.Y) + this.ArtProvider.PosOffset + new Vector2( this.ArtProvider.BoundingGUIRectangle.Width - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultWidth - vxEngine.vxGUITheme.Padding.X, this.ArtProvider.BoundingGUIRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight * 2 - vxEngine.vxGUITheme.Padding.Y * 2); }
public virtual void Draw(object guiItem) { vxButton button = (vxButton)guiItem; this.Font = vxEngine.vxGUITheme.Font; //Set Width and Height button.Width = Math.Max(this.DefaultWidth, (int)(this.Font.MeasureString(button.Text).X + Padding.X * 2)); button.Height = Math.Max(this.DefaultHeight, (int)(this.Font.MeasureString(button.Text).Y + Padding.Y * 2)); //Update Rectangle button.BoundingRectangle = new Rectangle( (int)(button.Position.X - Padding.X), (int)(button.Position.Y - Padding.Y / 2), button.Width, button.Height); Rectangle BorderRectangle = new Rectangle( (int)(button.Position.X - Padding.X) - BorderWidth, (int)(button.Position.Y - Padding.Y / 2) - BorderWidth, button.Width + BorderWidth * 2, button.Height + BorderWidth * 2); //Draw Button if (DoBorder) { vxEngine.SpriteBatch.Draw(BackgroundImage, BorderRectangle, Color.Black * Opacity); } vxEngine.SpriteBatch.Draw(BackgroundImage, button.BoundingRectangle, (button.HasFocus ? this.BackgroundHoverColour : this.BackgroundColour) * Opacity); vxEngine.SpriteBatch.DrawString(this.Font, button.Text, new Vector2( button.Position.X + button.Width / 2 - this.Font.MeasureString(button.Text).X / 2 - Padding.X, button.Position.Y + button.Height / 2 - this.Font.MeasureString(button.Text).Y / 2), TextColour * Opacity); }
/// <summary> /// Loads graphics content for this screen. This uses the shared ContentManager /// provided by the Game class, so the content will remain loaded forever. /// Whenever a subsequent MessageBoxScreen tries to load this same content, /// it will just get back another reference to the already loaded data. /// </summary> public override void LoadContent() { xGUIManager = new vxGuiManager(); SetButtonText(); Vector2 viewportSize = new Vector2(vxEngine.GraphicsDevice.Viewport.Width, vxEngine.GraphicsDevice.Viewport.Height); //Setup Buttons Btn_Apply = new vxButton(vxEngine, btn_Apply_text, new Vector2(viewportSize.X / 2 - 115, viewportSize.Y / 2 + 20)); Btn_Apply.Clicked += Btn_Apply_Clicked; Btn_Ok = new vxButton(vxEngine, btn_ok_text, new Vector2(viewportSize.X / 2 - 115, viewportSize.Y / 2 + 20)); Btn_Ok.Clicked += Btn_Ok_Clicked; Btn_Cancel = new vxButton(vxEngine, btn_ok_Cancel, new Vector2(viewportSize.X / 2 + 15, viewportSize.Y / 2 + 20)); Btn_Cancel.Clicked += Btn_Cancel_Clicked; if (ButtonTypes == vxEnumButtonTypes.OkApplyCancel) { xGUIManager.Add(Btn_Apply); } xGUIManager.Add(Btn_Ok); xGUIManager.Add(Btn_Cancel); spriteBatch = vxEngine.SpriteBatch; font = vxEngine.vxGUITheme.Font; // Center the message text in the viewport. viewport = vxEngine.GraphicsDevice.Viewport; textTitleSize = font.MeasureString(Title); textSize = font.MeasureString(message); textPosition = (viewportSize - textSize) / 2; textTitlePosition = textPosition - new Vector2(0, 2 * vPad + textTitleSize.Y); //Set Gui Item Positions int length = Math.Max(vxEngine.vxGUITheme.ArtProviderForButtons.DefaultWidth * 2 + (int)vxEngine.vxGUITheme.Padding.X * 2, (int)textSize.X); backgroundRectangle = new Rectangle( (int)textPosition.X - hPad, (int)textPosition.Y - vPad, length + hPad * 2, (int)textSize.Y + vPad + vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight + vPad * 2); TitleRectangle = new Rectangle( (int)textPosition.X - hPad, (int)textPosition.Y - (int)textTitleSize.Y - vPad * 2 - 5, length + hPad * 2, (int)textTitleSize.Y + vPad); SpriteFont ButtonFont = vxEngine.vxGUITheme.ArtProviderForButtons.Font; Btn_Apply.Position = new Vector2(backgroundRectangle.X, backgroundRectangle.Y) + new Vector2( backgroundRectangle.Width - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultWidth * 3 - vxEngine.vxGUITheme.Padding.X * 3, backgroundRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight - vxEngine.vxGUITheme.Padding.Y * 2); Btn_Ok.Position = new Vector2(backgroundRectangle.X, backgroundRectangle.Y) + new Vector2( backgroundRectangle.Width - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultWidth * 2 - vxEngine.vxGUITheme.Padding.X * 2, backgroundRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight - vxEngine.vxGUITheme.Padding.Y * 2); Btn_Cancel.Position = new Vector2(backgroundRectangle.X, backgroundRectangle.Y) + new Vector2( backgroundRectangle.Width - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultWidth - vxEngine.vxGUITheme.Padding.X, backgroundRectangle.Height - vxEngine.vxGUITheme.ArtProviderForButtons.DefaultHeight - vxEngine.vxGUITheme.Padding.Y * 2); this.ArtProvider = (vxMessageBoxArtProvider)vxEngine.vxGUITheme.ArtProviderForMessageBoxes.Clone(); }