Beispiel #1
0
        protected override void OnUpdate(float dt)
        {
            if (m_justPressed >= 0)
            {
                m_justPressed = -1;
                UpdateColours();
            }

            // Update status text
            if (Visible)
            {
                m_statusText[0].String = string.Format("FPS: {0:F0}Hz Tris/Calls: {1}/{2}", App.FPS, RenderStats.Triangles, RenderStats.DrawCalls);

                var level = (m_game.CurrentState is LevelState) ? ((LevelState)m_game.CurrentState).LevelLoadPath : null;
                m_statusText[1].String = (level != null) ? level : "";

                var cameraTransInv = m_game.Camera.Transform;
                MathUtils.FastInvert(ref cameraTransInv);

                var cameraPos = Vector3.TransformPosition(Vector3.Zero, cameraTransInv);
                if (m_game.CurrentState is LevelState)
                {
                    var levelTransInv = ((LevelState)m_game.CurrentState).Level.Transform;
                    MathUtils.FastInvert(ref levelTransInv);
                    cameraPos = Vector3.TransformPosition(cameraPos, levelTransInv);
                }
                m_statusText[2].String = string.Format("{0:N2},{1:N2},{2:N2}", cameraPos.X, cameraPos.Y, cameraPos.Z);
            }

            // Update log
            if (Visible)
            {
                string[] log = App.RecentLog.ToArray();
                for (int i = 0; i < m_recentLogText.Length; ++i)
                {
                    var logIndex = i - (m_recentLogText.Length - log.Length);
                    if (logIndex >= 0)
                    {
                        var text  = log[logIndex];
                        var error = text.ToLowerInvariant().Contains("error");
                        m_recentLogText[i].String = text;
                        m_recentLogText[i].Colour = error ? UIColours.Important : UIColours.Text;
                    }
                    else
                    {
                        m_recentLogText[i].String = "";
                    }
                }
            }

            // Handle option selection
            if (Screen.Keyboard.Keys[Key.F1].Pressed)
            {
                Visible = !Visible;
                if (Visible)
                {
                    GC.Collect();
                }
                m_justPressed = 1;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F2].Pressed)
            {
                m_pendingScreenshot = m_game.QueueScreenshot();
                m_justPressed       = 2;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F3].Pressed)
            {
                m_game.RenderUI = !m_game.RenderUI;
                m_justPressed   = 3;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F4].Pressed)
            {
                m_game.UseDebugCamera = !m_game.UseDebugCamera;
                m_justPressed         = 4;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F5].Pressed)
            {
                App.Log("Reloading assets");
                Assets.ReloadAll();
                TextureAtlas.ReloadAll();
                LuaAnimation.ReloadAll();
                var state = m_game.CurrentState;
                if (state is LevelState)
                {
                    ((LevelState)state).OnReloadAssets();
                }
                GC.Collect();
                m_justPressed = 5;
                UpdateColours();
                App.Log("Assets reloaded", LogLevel.User);
            }
            if (Screen.Keyboard.Keys[Key.F6].Pressed)
            {
                if (m_game.Language.IsDebug)
                {
                    var desiredLanguageCode = m_game.Network.LocalUser.Language;
                    if (m_game.User.Settings.Language != "system")
                    {
                        desiredLanguageCode = m_game.User.Settings.Language;
                    }
                    m_game.Language = Language.GetMostSimilarTo(desiredLanguageCode);
                }
                else
                {
                    m_game.Language = Language.Get("languages/debug.lang");
                }
                var state = m_game.CurrentState;
                if (state is LevelState)
                {
                    ((LevelState)state).OnReloadAssets();
                }
                m_justPressed = 6;
                UpdateColours();
            }
            if (Screen.Keyboard.Keys[Key.F11].Pressed)
            {
                m_game.Window.Fullscreen        = !m_game.Window.Fullscreen;
                m_game.User.Settings.Fullscreen = m_game.Window.Fullscreen;
                m_game.User.Settings.Save();
                m_justPressed = 7;
                UpdateColours();
            }

            // Handle requested screenshots
            if (m_pendingScreenshot != null && m_pendingScreenshot.Status != Status.Waiting)
            {
                if (m_pendingScreenshot.Status == Status.Complete)
                {
                    var screenshot = m_pendingScreenshot.Result;
                    screenshot.Save(
                        Path.Combine(
                            App.SavePath,
                            Path.Combine("screenshots", DateTime.Now.ToString("s").Replace(":", "-") + ".png")
                            )
                        );
                    screenshot.Dispose();
                }
                m_pendingScreenshot = null;
            }
        }