public TextBox(ScreenManager mgr, int width = 200) { font = mgr.Content.Load<SpriteFont>("MainFont"); textPosition = CalculateTextPosition(); float fontHeight = (font.MeasureString("DS")).Y; this.width = width; height = PAD + (int)fontHeight + PAD; Color[] pixels = new Color[width * height]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.Gray * 0.3f; } boxTexture = new Texture2D(mgr.Game.GraphicsDevice, width, height); boxTexture.SetData<Color>(pixels); int cursorWidth = 2; pixels = new Color[cursorWidth * height]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.White; } cursor = new Texture2D(mgr.Game.GraphicsDevice, cursorWidth, height); cursor.SetData<Color>(pixels); ClearKeys(); }
public LobbyScreen(ScreenManager mgr) { this.mgr = mgr; font = mgr.Content.Load<SpriteFont>("MainFont"); btnBack = new Button("Back", new Vector2(20, 600 - 40 - 49)); btnReady = new Button("Ready", new Vector2(mgr.Width - 40 - Button.Width, 600 - 20 - 49)); btnStart = new Button("Start", new Vector2(mgr.Width - (40 * 2) - (Button.Width * 2), 600 - 20 - 49)); }
// // Constructor // public Client(ScreenManager mgr) { menuScreen = mgr.MenuScreen; lobbyScreen = mgr.LobbyScreen; gameScreen = mgr.GameScreen; Thread thread = new Thread(ClientLoop); thread.IsBackground = true; thread.Start(); }
public Chat(ScreenManager mgr) { Color[] pixels = new Color[width * height]; Color color = Color.Gray * 0.3f; for (int i = 0; i < pixels.Length; i++) { pixels[i] = color; } boxTexture = new Texture2D(mgr.Game.GraphicsDevice, width, height); boxTexture.SetData<Color>(pixels); }
public StatusBar(ScreenManager mgr) { this.mgr = mgr; font = mgr.Content.Load<SpriteFont>("MainFont"); int width = mgr.Width; int height = 40; Color[] pixels = new Color[width * height]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.White; } bgTexture = new Texture2D(mgr.Game.GraphicsDevice, width, height); bgTexture.SetData<Color>(pixels); }
public GameScreen(ScreenManager mgr) { this.mgr = mgr; font = mgr.Content.Load<SpriteFont>("MainFont"); chatBox = new Chat(mgr); Color[] pixels = new Color[activeWidth * activeHeight]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.White; } activeTexture = new Texture2D(mgr.Game.GraphicsDevice, activeWidth, activeHeight); activeTexture.SetData<Color>(pixels); // enum Card { None, Code1, Code2, Code3, Code4, Code6 = 6, Bug, Debug, Hacker, Crash, SickDay, Virus } List<Texture2D> textures = new List<Texture2D>(13); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Blank")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Code1")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Code2")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Code3")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Code4")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Blank")); // Not used textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Code6")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Bug")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Debug")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Hacker")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Crash")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\SickDay")); textures.Add(mgr.Content.Load<Texture2D>(@"Cards\Virus")); cardTextures = textures.ToArray(); cardWidth = cardTextures[0].Width; cardHeight = cardTextures[0].Height; btnDiscard = new Button("Discard", new Vector2(20, 600 - 20 - cardHeight + 17)); }
protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. batch = new SpriteBatch(GraphicsDevice); g = Globals.Get(); g["game"] = this; g["mgr"] = mgr; g["MainFont"] = Content.Load<SpriteFont>("MainFont"); g["Button-Normal"] = Content.Load<Texture2D>("Button-Normal"); g["Button-Hover"] = Content.Load<Texture2D>("Button-Hover"); g["buttonWidth"] = ((Texture2D)g["Button-Normal"]).Width; g["buttonHeight"] = ((Texture2D)g["Button-Normal"]).Height; mgr = new ScreenManager(this); #if FPS_COUNTER fps = new FPS(Content, Window.ClientBounds, FPS.Display.BottomRight); #endif }
// // Constructor // public MenuScreen(ScreenManager mgr) { // Create all the buttons btnHost = new Button("Host", new Vector2(40, 80)); btnHost.Click += btnHost_Click; btnJoin = new Button("Join", new Vector2(40, 140)); btnJoin.Click += btnJoin_Click; btnCredits = new Button("Credits", new Vector2(40, 200)); btnCredits.Click += btnCredits_Click; btnQuit = new Button("Quit", new Vector2(40, 600 - 40 - 49)); btnQuit.Click += btnQuit_Click; //string boxText = "I know what you're thinking. \"Did he fire six shots or only five?\" Well, to tell you the truth, in all this excitement I kind of lost track myself. But being as this is a .44 Magnum, the most powerful handgun in the world, and would blow your head clean off, you've got to ask yourself one question: Do I feel lucky? Well, do ya, punk?"; string boxText = "What would you like for your nickname?"; int boxWidth = 500; nameBoxCancel = new Button("Back", Vector2.Zero); nameBoxOK = new Button("Accept", Vector2.Zero); Button[] btns = new Button[] { nameBoxOK, nameBoxCancel }; nameBoxText = new TextBox(mgr, boxWidth - 40); // nameBox = new Window(mgr, boxText, boxWidth, btns, nameBoxText); boxText = "What is your host's IP address?"; ipBoxCancel = new Button("Back", Vector2.Zero); ipBoxOK = new Button("Join", Vector2.Zero); btns = new Button[] { ipBoxOK, ipBoxCancel }; ipBoxText = new IPBox(mgr, boxWidth - 40); // ipBox = new Window(mgr, boxText, boxWidth, btns, ipBoxText); boxText = "Created by Derek, of course!"; creditsBoxOK = new Button("Okay", Vector2.Zero); btns = new Button[] { creditsBoxOK }; // creditsBox = new Window(mgr, boxText, boxWidth, btns); this.mgr = mgr; }
public Window(ScreenManager mgr, string text, int width, Button[] buttons, ITextBox textbox) { // Load font font = mgr.Content.Load<SpriteFont>("MainFont"); textBox = textbox; // Starts at top left and rotates clockwise boxTextures = new Texture2D[8] { mgr.Content.Load<Texture2D>(@"Box\Box-Top-Left"), mgr.Content.Load<Texture2D>(@"Box\Box-Top"), mgr.Content.Load<Texture2D>(@"Box\Box-Top-Right"), mgr.Content.Load<Texture2D>(@"Box\Box-Right"), mgr.Content.Load<Texture2D>(@"Box\Box-Bottom-Right"), mgr.Content.Load<Texture2D>(@"Box\Box-Bottom"), mgr.Content.Load<Texture2D>(@"Box\Box-Bottom-Left"), mgr.Content.Load<Texture2D>(@"Box\Box-Left") }; // // Dimensions // screenWidth = mgr.Width; screenHeight = mgr.Height; boxWidth = width; //boxHeight needs to be calculated cornerWidth = boxTextures[0].Width; cornerHeight = boxTextures[0].Height; // // Calculate boxHeight // Vector2 textDim = font.MeasureString(text); int innerBoxWidth = boxWidth - (PAD * 2); // Need word wrap? if (textDim.X > innerBoxWidth) { string[] tokens = text.Split(' '); StringBuilder lineBuilder = new StringBuilder(); for (int i = 0; i < tokens.Length; i++) { lineBuilder.Append(tokens[i]); textDim = font.MeasureString(lineBuilder.ToString()); lineBuilder.Append(" "); // Breaking point? if (textDim.X > innerBoxWidth) { // Remove last token (and space) because it went over boxWidth lineBuilder.Remove(lineBuilder.Length - (tokens[i].Length + 1), tokens[i].Length + 1); // Save newly-created line lines.Add(lineBuilder.ToString()); // Clear for next line lineBuilder.Clear(); // Start new line with last word that didn't fit (and space) lineBuilder.Append(tokens[i]); lineBuilder.Append(" "); } } // Add left over as last line lines.Add(lineBuilder.ToString()); } // No word wrap needed else { lines.Add(text); } // Add up all of this stuff to get the total height: // number of lines of text * the height of a text letter // + box padding * 4 (top, middle, ... , middle, bottom) // + the height of a button // + the height of a textbox int textBoxHeight = 0; if (textBox != null) textBoxHeight = textBox.GetHeight() + (PAD * 2); boxHeight = (lines.Count * (int)textDim.Y) + (PAD * 3) + Button.Height + textBoxHeight; x1 = (screenWidth - boxWidth) / 2; x2 = x1 + boxWidth; y1 = (screenHeight - boxHeight) / 2; y2 = y1 + boxHeight; // // Buttons // this.btns = buttons; if (btns.Length >= 1) { btns[0].Position = new Vector2(x2 - PAD - Button.Width, y2 - PAD - Button.Height); if (btns.Length == 2) { btns[1].Position = new Vector2(x1 + PAD, y2 - PAD - Button.Height); } } if (textBox != null) textBox.SetPosition(new Vector2(x1 + PAD, y2 - (PAD * 3) - Button.Height - textBox.GetHeight())); // Corners boxPositions[0] = new Vector2(x1, y1); boxPositions[2] = new Vector2(x2 - cornerWidth, y1); boxPositions[4] = new Vector2(x2 - cornerWidth, y2 - cornerHeight); boxPositions[6] = new Vector2(x1, y2 - cornerHeight); linePositions = new Vector2[lines.Count]; for (int i = 0; i < linePositions.Length; i++) { linePositions[i] = new Vector2(x1 + PAD, y1 + PAD + (i * (int)textDim.Y)); } // screenOverlay Color[] pixels = new Color[screenWidth * screenHeight]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = screenOverlayColor; } screenOverlay = new Texture2D(mgr.Game.GraphicsDevice, screenWidth, screenHeight); screenOverlay.SetData<Color>(pixels); // boxBackground pixels = new Color[boxWidth * boxHeight]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = boxBackgroundColor; } boxBackground = new Texture2D(mgr.Game.GraphicsDevice, boxWidth, boxHeight); boxBackground.SetData<Color>(pixels); }
public Window(ScreenManager mgr, string text, int width, Button[] buttons) : this(mgr, text, width, buttons, null) { }