Esempio n. 1
0
        void InitializeKeyboardSettings()
        {
            panelKeys.Controls.Clear();
            var columnWidth = (panelKeys.ClientSize.Width - 20) / 2;

            var tempLabel  = new Label();
            var tempKIC    = new KeyInputControl(Settings.Input.Commands[(int)UserCommands.GameQuit], InputSettings.DefaultCommands[(int)UserCommands.GameQuit]);
            var rowTop     = Math.Max(tempLabel.Margin.Top, tempKIC.Margin.Top);
            var rowHeight  = tempKIC.Height;
            var rowSpacing = rowHeight + tempKIC.Margin.Vertical;

            var lastCategory = "";
            var i            = 0;

            foreach (UserCommands command in Enum.GetValues(typeof(UserCommands)))
            {
                var name       = InputSettings.GetPrettyLocalizedName(command);
                var category   = ParseCategoryFrom(name);
                var descriptor = ParseDescriptorFrom(name);

                if (category != lastCategory)
                {
                    var catlabel = new Label();
                    catlabel.Location  = new Point(tempLabel.Margin.Left, rowTop + rowSpacing * i);
                    catlabel.Size      = new Size(columnWidth - tempLabel.Margin.Horizontal, rowHeight);
                    catlabel.Text      = category;
                    catlabel.TextAlign = ContentAlignment.MiddleCenter;
                    catlabel.Font      = new Font(catlabel.Font, FontStyle.Bold);
                    panelKeys.Controls.Add(catlabel);

                    lastCategory = category;
                    ++i;
                }

                var label = new Label();
                label.Location  = new Point(tempLabel.Margin.Left, rowTop + rowSpacing * i);
                label.Size      = new Size(columnWidth - tempLabel.Margin.Horizontal, rowHeight);
                label.Text      = descriptor;
                label.TextAlign = ContentAlignment.MiddleRight;
                panelKeys.Controls.Add(label);

                var keyInputControl = new KeyInputControl(Settings.Input.Commands[(int)command], InputSettings.DefaultCommands[(int)command]);
                keyInputControl.Location = new Point(columnWidth + tempKIC.Margin.Left, rowTop + rowSpacing * i);
                keyInputControl.Size     = new Size(columnWidth - tempKIC.Margin.Horizontal, rowHeight);
                keyInputControl.ReadOnly = true;
                keyInputControl.Tag      = command;
                panelKeys.Controls.Add(keyInputControl);
                toolTip1.SetToolTip(keyInputControl, catalog.GetString("Click to change this key"));

                ++i;
            }
        }
Esempio n. 2
0
        public KeyInputEditControl(KeyInputControl control)
        {
            InitializeComponent();

            // Windows 2000 and XP should use 8.25pt Tahoma, while Windows
            // Vista and later should use 9pt "Segoe UI". We'll use the
            // Message Box font to allow for user-customizations, though.
            Font = SystemFonts.MessageBoxFont;

            // Use a lambda here so we can capture the 'control' variable
            // only for as long as needed to set our location/size.
            Load += (object sender, EventArgs e) =>
            {
                Location = control.Parent.PointToScreen(control.Location);
                Size     = control.Size;
                textBox.Focus();
                HookKeyboard();
            };

            FormClosed += (object sender, FormClosedEventArgs e) =>
            {
                UnhookKeyboard();
            };

            LiveInput  = control.UserInput;
            IsModifier = LiveInput.IsModifier;
            var parts = LiveInput.PersistentDescriptor.Split(',');

            if (parts.Length >= 5)
            {
                ScanCode   = int.Parse(parts[0]);
                VirtualKey = (Xna.Keys) int.Parse(parts[1]);
                Shift      = parts[2] != "0";
                Control    = parts[3] != "0";
                Alt        = parts[4] != "0";
            }
            UpdateText();
        }