public void Update() { foreach (BaseScreen foundscreen in Screens) { if (foundscreen.State == ScreenState.Shutdown) { removeScreens.Add(foundscreen); } else { foundscreen.Focused = false; } } // Remove dead screens foreach (BaseScreen foundscreen in removeScreens) { Screens.Remove(foundscreen); } removeScreens.Clear(); // Add new screens foreach (BaseScreen foundscreen in newScreens) { Screens.Add(foundscreen); } newScreens.Clear(); // Check screen focus if (Screens.Count > 0) { for (int i = Screens.Count - 1; i >= 0; i += -1) { if (Screens[i].GrabFocus) { Screens[i].Focused = true; break; } } } if (GV.WindowFocused) { // Handle Input for focused screen foreach (BaseScreen foundscreen in Screens) { foundscreen.Update(); foundscreen.HandleInput(); } if (UserInput.KeyPressed(Keys.F1)) { showFPS = !showFPS; } if (UserInput.KeyPressed(Keys.F2)) { showFullLog = !showFullLog; } foreach (Logging _log in logList) { _log.Update(); if (_log.CanRemove()) { logList.Remove(_log); totalLogList.Add(_log.message); break; } } } }
// Draw Screens public void Draw() { foreach (BaseScreen foundscreen in Screens) { if (foundscreen.State == ScreenState.Active) { foundscreen.Draw(); } } if (showFPS) { if (GV.GameTime.TotalGameTime.TotalMilliseconds >= fpsTimer) { fps = fpsCounter; fpsTimer = GV.GameTime.TotalGameTime.TotalMilliseconds + 1000; fpsCounter = 1; fpsText = "Fps: " + fps; fpsY = GV.GameSize.Height - (int)Fonts.SystemBold.MeasureString(fpsText).Y; if (fps > 50) { colour = Color.LightGreen; } else if (fps > 30) { colour = Color.White; } else if (fps > 25) { colour = Color.Yellow; } else { colour = Color.Red; } } else { fpsCounter += 1; } GV.SpriteBatch.Begin(); GV.SpriteBatch.DrawString(Fonts.SystemBold, fpsText, new Vector2(0, fpsY), colour); GV.SpriteBatch.End(); } if (!showFullLog) { //Draw Loglist for (int x = 0; x <= logList.Count - 1; x++) { Vector2 _sMeasure = Fonts.SystemBold.MeasureString(logList[x].message); GV.SpriteBatch.Begin(); GV.SpriteBatch.DrawString(Fonts.SystemBold, logList[x].message, new Vector2((GV.GameSize.Width - _sMeasure.X) - 25, ((GV.GameSize.Height - _sMeasure.Y) - 25) - (x * 20)), Color.White * logList[x].alpha); GV.SpriteBatch.End(); } } else { if (UserInput.KeyDown(Keys.PageDown)) { logStartPos += 1; if (logStartPos > totalLogList.Count) { logStartPos = totalLogList.Count; } } if (UserInput.KeyDown(Keys.PageUp)) { logStartPos -= 1; if (logStartPos < 0) { logStartPos = 0; } } int _restrict = 0; //Draw the full Log list for (int x = logStartPos; x <= totalLogList.Count - 1; x++) { Vector2 _sMeasure = Fonts.SystemBold.MeasureString(totalLogList[x]); GV.SpriteBatch.Begin(); GV.SpriteBatch.DrawString(Fonts.SystemBold, totalLogList[x], new Vector2((GV.GameSize.Width - _sMeasure.X) - 25, 25 + (x * 20)), Color.White); GV.SpriteBatch.End(); _restrict += 1; if (_restrict > 33) { break; } } } }