public override void OnPop()
        {
            // Update keybinds only when exiting from a valid configuration
            ControlsConfigManager.Instance.SetAllKeyBindValues();
            InputManager.Instance.SaveKeyBinds();
            ControlsConfigManager.Instance.ResetUnsavedKeybinds();

            DaggerfallJoystickControlsWindow.SaveSettings();
        }
        private void SetDefaults()
        {
            InputManager.Instance.ResetDefaults();

            ControlsConfigManager.Instance.ResetUnsavedKeybinds();
            DaggerfallJoystickControlsWindow.ResetUnsavedSettings();

            UpdateKeybindButtons();
            AllowCancel = true;
        }
        protected override void Setup()
        {
            // Load textures
            nativeTexture = DaggerfallUI.GetTextureFromImg(nativeTextureName);
            if (!nativeTexture)
            {
                throw new Exception("DaggerfallControlsWindow: Could not load native texture.");
            }
            mLookAltTexture = DaggerfallUI.GetTextureFromImg(mLookAltTextureName);

            // Always dim background
            ParentPanel.BackgroundColor = ScreenDimColor;

            // Controls panel
            controlsPanel.HorizontalAlignment = HorizontalAlignment.Center;
            controlsPanel.Size = NativePanel.Size;
            controlsPanel.BackgroundTexture = nativeTexture;
            NativePanel.Components.Add(controlsPanel);

            // Mouse Look Alternative Controls Panel
            mLookAltPanel.Position          = new Vector2(152, 100);
            mLookAltPanel.Size              = new Vector2(168, 45);
            mLookAltPanel.BackgroundTexture = mLookAltTexture;
            controlsPanel.Components.Add(mLookAltPanel);

            #region Tab Buttons

            // Joystick
            Button joystickButton = DaggerfallUI.AddButton(new Rect(0, 190, 80, 10), controlsPanel);
            joystickButton.OnMouseClick += JoystickButton_OnMouseClick;

            // Mouse
            Button mouseButton = DaggerfallUI.AddButton(new Rect(80, 190, 80, 10), controlsPanel);
            mouseButton.BackgroundColor = new Color(0f, 0f, 0f, 1f);
            Texture2D tex;
            if (!TextureReplacement.TryImportTexture("advanced_controls_button", true, out tex))
            {
                tex = Resources.Load <Texture2D>("advanced_controls_button");
            }
            tex.filterMode = FilterMode.Point;
            mouseButton.BackgroundTexture = tex;
            //mouseButton.Label.Text = "ADVANCED";
            mouseButton.OnMouseClick += MouseButton_OnMouseClick;

            // Default
            Button defaultButton = DaggerfallUI.AddButton(new Rect(160, 190, 80, 10), controlsPanel);
            defaultButton.OnMouseClick += DefaultButton_OnMouseClick;

            // Continue
            Button continueButton = DaggerfallUI.AddButton(new Rect(240, 190, 80, 10), controlsPanel);
            continueButton.OnMouseClick += ContinueButton_OnMouseClick;

            #endregion

            #region Keybind Buttons

            currentBindingsButton = DaggerfallUI.AddButton(new Rect(268, 0, 50, 8), controlsPanel);
            currentBindingsButton.Label.ShadowPosition = Vector2.zero;
            currentBindingsButton.Outline.Enabled      = true;
            currentBindingsButton.OnMouseClick        += CurrentBindingsButton_OnMouseClick;
            currentBindingsButton.Label.Text           = ControlsConfigManager.Instance.UsingPrimary ? "Primary" : "Secondary";

            ControlsConfigManager.Instance.ResetUnsavedKeybinds();
            DaggerfallJoystickControlsWindow.ResetUnsavedSettings();

            SetupKeybindButtons(moveKeysOne, 2, 8, 57, 13, true);
            SetupKeybindButtons(moveKeysTwo, 8, 14, 164, 13, true);
            SetupKeybindButtons(modeKeys, 14, 20, 270, 13, true);
            SetupKeybindButtons(magicKeys, 20, 24, 102, 80, true);
            SetupKeybindButtons(weaponKeys, 24, 27, 102, 125, true);
            SetupKeybindButtons(statusKeys, 27, 30, 102, 159, true);
            SetupKeybindButtons(activateKeys, 30, 32, 270, 80, true);
            SetupKeybindButtons(lookKeys, 32, 36, 270, 103, true);
            SetupKeybindButtons(uiKeys, 36, 40, 270, 148, true);

            CheckDuplicates();

            #endregion
        }