mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-02-17 01:22:18 +00:00
controls configuration done.
This commit is contained in:
parent
d284a2cd5e
commit
fc2685a0b5
9 changed files with 256 additions and 12 deletions
|
@ -10,6 +10,7 @@ shortcuts
|
|||
zoomin = 65530;
|
||||
zoomout = 65531;
|
||||
configuration = 116;
|
||||
closemap = 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\ActionAttribute.cs" />
|
||||
<Compile Include="Controls\KeyControl.cs" />
|
||||
<Compile Include="Editing\EditMode.cs" />
|
||||
<Compile Include="Editing\FrozenOverviewMode.cs" />
|
||||
<Compile Include="Editing\ViewClassicMode.cs" />
|
||||
|
|
|
@ -120,6 +120,14 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
ctrl = key & ((int)Keys.Control | (int)Keys.Shift | (int)Keys.Alt);
|
||||
button = key & ~((int)Keys.Control | (int)Keys.Shift | (int)Keys.Alt);
|
||||
|
||||
// When the button is a control key, then remove the control itsself
|
||||
if((button == (int)Keys.ControlKey) ||
|
||||
(button == (int)Keys.ShiftKey))
|
||||
{
|
||||
ctrl = 0;
|
||||
key = key & ~((int)Keys.Control | (int)Keys.Shift | (int)Keys.Alt);
|
||||
}
|
||||
|
||||
// Determine control prefix
|
||||
if(ctrl != 0) ctrlprefix = conv.ConvertToString(key);
|
||||
|
||||
|
|
|
@ -138,6 +138,17 @@ namespace CodeImp.DoomBuilder.Controls
|
|||
return list;
|
||||
}
|
||||
|
||||
// This saves the control settings
|
||||
public void SaveSettings()
|
||||
{
|
||||
// Go for all actions
|
||||
foreach(KeyValuePair<string, Action> a in actions)
|
||||
{
|
||||
// Write to configuration
|
||||
General.Settings.WriteSetting("shortcuts." + a.Key, a.Value.ShortcutKey);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Shortcut Keys
|
||||
|
|
57
Source/Controls/KeyControl.cs
Normal file
57
Source/Controls/KeyControl.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CodeImp.DoomBuilder.Controls
|
||||
{
|
||||
internal struct KeyControl
|
||||
{
|
||||
#region ================== Variables
|
||||
|
||||
public int key;
|
||||
public string name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor / Disposer
|
||||
|
||||
// Constructor
|
||||
public KeyControl(Keys key, string name)
|
||||
{
|
||||
// Initialize
|
||||
this.key = (int)key;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public KeyControl(SpecialKeys key, string name)
|
||||
{
|
||||
// Initialize
|
||||
this.key = (int)key;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public KeyControl(int key, string name)
|
||||
{
|
||||
// Initialize
|
||||
this.key = key;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
// Returns name
|
||||
public override string ToString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -337,6 +337,9 @@ namespace CodeImp.DoomBuilder
|
|||
mainwindow.Dispose();
|
||||
actions.Dispose();
|
||||
|
||||
// Save action controls
|
||||
actions.SaveSettings();
|
||||
|
||||
// Save game configuration settings
|
||||
foreach(ConfigurationInfo ci in configs) ci.SaveSettings();
|
||||
|
||||
|
|
13
Source/Interface/ConfigForm.Designer.cs
generated
13
Source/Interface/ConfigForm.Designer.cs
generated
|
@ -273,6 +273,7 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.columncontrolkey});
|
||||
this.listactions.FullRowSelect = true;
|
||||
this.listactions.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
|
||||
this.listactions.HideSelection = false;
|
||||
this.listactions.Location = new System.Drawing.Point(11, 11);
|
||||
this.listactions.Margin = new System.Windows.Forms.Padding(8);
|
||||
this.listactions.MultiSelect = false;
|
||||
|
@ -281,6 +282,7 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.listactions.Size = new System.Drawing.Size(275, 350);
|
||||
this.listactions.Sorting = System.Windows.Forms.SortOrder.Ascending;
|
||||
this.listactions.TabIndex = 0;
|
||||
this.listactions.TabStop = false;
|
||||
this.listactions.UseCompatibleStateImageBehavior = false;
|
||||
this.listactions.View = System.Windows.Forms.View.Details;
|
||||
this.listactions.MouseUp += new System.Windows.Forms.MouseEventHandler(this.listactions_MouseUp);
|
||||
|
@ -322,8 +324,10 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.actioncontrol.FormattingEnabled = true;
|
||||
this.actioncontrol.Location = new System.Drawing.Point(23, 189);
|
||||
this.actioncontrol.Name = "actioncontrol";
|
||||
this.actioncontrol.Size = new System.Drawing.Size(184, 22);
|
||||
this.actioncontrol.Size = new System.Drawing.Size(197, 22);
|
||||
this.actioncontrol.TabIndex = 8;
|
||||
this.actioncontrol.TabStop = false;
|
||||
this.actioncontrol.SelectedIndexChanged += new System.EventHandler(this.actioncontrol_SelectedIndexChanged);
|
||||
//
|
||||
// actiontitle
|
||||
//
|
||||
|
@ -340,10 +344,12 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
//
|
||||
this.actioncontrolclear.Location = new System.Drawing.Point(193, 130);
|
||||
this.actioncontrolclear.Name = "actioncontrolclear";
|
||||
this.actioncontrolclear.Size = new System.Drawing.Size(72, 25);
|
||||
this.actioncontrolclear.Size = new System.Drawing.Size(63, 25);
|
||||
this.actioncontrolclear.TabIndex = 6;
|
||||
this.actioncontrolclear.TabStop = false;
|
||||
this.actioncontrolclear.Text = "Clear";
|
||||
this.actioncontrolclear.UseVisualStyleBackColor = true;
|
||||
this.actioncontrolclear.Click += new System.EventHandler(this.actioncontrolclear_Click);
|
||||
//
|
||||
// actionkey
|
||||
//
|
||||
|
@ -351,6 +357,9 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
this.actionkey.Name = "actionkey";
|
||||
this.actionkey.Size = new System.Drawing.Size(163, 20);
|
||||
this.actionkey.TabIndex = 5;
|
||||
this.actionkey.TabStop = false;
|
||||
this.actionkey.TextChanged += new System.EventHandler(this.actionkey_TextChanged);
|
||||
this.actionkey.KeyDown += new System.Windows.Forms.KeyEventHandler(this.actionkey_KeyDown);
|
||||
//
|
||||
// actiondescription
|
||||
//
|
||||
|
|
|
@ -32,6 +32,12 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
{
|
||||
public partial class ConfigForm : DelayedForm
|
||||
{
|
||||
#region ================== Variables
|
||||
|
||||
private bool allowapplycontrol = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor
|
||||
|
||||
// Constructor
|
||||
|
@ -50,17 +56,39 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
// Create item
|
||||
item = listactions.Items.Add(a.Name, a.Title, 0);
|
||||
item.SubItems.Add(Action.GetShortcutKeyDesc(a.ShortcutKey));
|
||||
item.SubItems[1].Tag = a.ShortcutKey;
|
||||
}
|
||||
|
||||
// Fill combobox with special controls
|
||||
actioncontrol.Items.Add(Keys.LButton);
|
||||
actioncontrol.Items.Add(Keys.MButton);
|
||||
actioncontrol.Items.Add(Keys.RButton);
|
||||
actioncontrol.Items.Add(Keys.XButton1);
|
||||
actioncontrol.Items.Add(Keys.XButton2);
|
||||
actioncontrol.Items.Add(SpecialKeys.MScrollUp);
|
||||
actioncontrol.Items.Add(SpecialKeys.MScrollDown);
|
||||
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.LButton, "LButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.MButton, "MButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.RButton, "RButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton1, "XButton1"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton2, "XButton2"));
|
||||
actioncontrol.Items.Add(new KeyControl(SpecialKeys.MScrollUp, "ScrollUp"));
|
||||
actioncontrol.Items.Add(new KeyControl(SpecialKeys.MScrollDown, "ScrollDown"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.LButton | Keys.Shift, "Shift+LButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.MButton | Keys.Shift, "Shift+MButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.RButton | Keys.Shift, "Shift+RButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton1 | Keys.Shift, "Shift+XButton1"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton2 | Keys.Shift, "Shift+XButton2"));
|
||||
actioncontrol.Items.Add(new KeyControl((int)SpecialKeys.MScrollUp | (int)Keys.Shift, "Shift+ScrollUp"));
|
||||
actioncontrol.Items.Add(new KeyControl((int)SpecialKeys.MScrollDown | (int)Keys.Shift, "Shift+ScrollDown"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.LButton | Keys.Control, "Ctrl+LButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.MButton | Keys.Control, "Ctrl+MButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.RButton | Keys.Control, "Ctrl+RButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton1 | Keys.Control, "Ctrl+XButton1"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton2 | Keys.Control, "Ctrl+XButton2"));
|
||||
actioncontrol.Items.Add(new KeyControl((int)SpecialKeys.MScrollUp | (int)Keys.Control, "Ctrl+ScrollUp"));
|
||||
actioncontrol.Items.Add(new KeyControl((int)SpecialKeys.MScrollDown | (int)Keys.Control, "Ctrl+ScrollDown"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.LButton | Keys.Shift | Keys.Control, "Ctrl+Shift+LButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.MButton | Keys.Shift | Keys.Control, "Ctrl+Shift+MButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.RButton | Keys.Shift | Keys.Control, "Ctrl+Shift+RButton"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton1 | Keys.Shift | Keys.Control, "Ctrl+Shift+XButton1"));
|
||||
actioncontrol.Items.Add(new KeyControl(Keys.XButton2 | Keys.Shift | Keys.Control, "Ctrl+Shift+XButton2"));
|
||||
actioncontrol.Items.Add(new KeyControl((int)SpecialKeys.MScrollUp | (int)Keys.Shift | (int)Keys.Control, "Ctrl+Shift+ScrollUp"));
|
||||
actioncontrol.Items.Add(new KeyControl((int)SpecialKeys.MScrollDown | (int)Keys.Shift | (int)Keys.Control, "Ctrl+Shift+ScrollDown"));
|
||||
|
||||
// Fill list of configurations
|
||||
foreach(ConfigurationInfo ci in General.Configs)
|
||||
{
|
||||
|
@ -70,6 +98,9 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
|
||||
// Fill combobox with nodebuilders
|
||||
confignodebuilder.Items.AddRange(General.Nodebuilders.ToArray());
|
||||
|
||||
// Done
|
||||
allowapplycontrol = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -80,22 +111,43 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
private void listactions_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
||||
{
|
||||
Action action;
|
||||
KeyControl keycontrol;
|
||||
int key;
|
||||
|
||||
// Anything selected?
|
||||
if(listactions.SelectedItems.Count > 0)
|
||||
{
|
||||
// Begin updating
|
||||
allowapplycontrol = false;
|
||||
|
||||
// Get the selected action
|
||||
action = General.Actions[listactions.SelectedItems[0].Name];
|
||||
key = (int)listactions.SelectedItems[0].SubItems[1].Tag;
|
||||
|
||||
// Enable panel
|
||||
actioncontrolpanel.Enabled = true;
|
||||
actiontitle.Text = action.Title;
|
||||
actiondescription.Text = action.Description;
|
||||
actioncontrol.SelectedIndex = -1;
|
||||
actionkey.Text = "";
|
||||
|
||||
// See if the key is in the combobox
|
||||
for(int i = 0; i < actioncontrol.Items.Count; i++)
|
||||
{
|
||||
// Select it when the key is found here
|
||||
keycontrol = (KeyControl)actioncontrol.Items[i];
|
||||
if(keycontrol.key == key) actioncontrol.SelectedIndex = i;
|
||||
}
|
||||
|
||||
// Otherwise display the key in the textbox
|
||||
if(actioncontrol.SelectedIndex == -1)
|
||||
actionkey.Text = Action.GetShortcutKeyDesc(key);
|
||||
|
||||
// Focus to the input box
|
||||
actionkey.Focus();
|
||||
|
||||
// Done
|
||||
allowapplycontrol = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,8 +170,100 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
private void listactions_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
listactions_KeyUp(sender, new KeyEventArgs(Keys.None));
|
||||
|
||||
// Focus to the input box
|
||||
actionkey.Focus();
|
||||
}
|
||||
|
||||
// Key combination pressed
|
||||
private void actionkey_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
int key = (int)e.KeyData;
|
||||
e.SuppressKeyPress = true;
|
||||
|
||||
// Leave when not allowed to update
|
||||
if(!allowapplycontrol) return;
|
||||
|
||||
// Anything selected?
|
||||
if(listactions.SelectedItems.Count > 0)
|
||||
{
|
||||
// Begin updating
|
||||
allowapplycontrol = false;
|
||||
|
||||
// Deselect anything from the combobox
|
||||
actioncontrol.SelectedIndex = -1;
|
||||
|
||||
// Apply the key combination
|
||||
listactions.SelectedItems[0].SubItems[1].Text = Action.GetShortcutKeyDesc(key);
|
||||
listactions.SelectedItems[0].SubItems[1].Tag = key;
|
||||
actionkey.Text = Action.GetShortcutKeyDesc(key);
|
||||
|
||||
// Done
|
||||
allowapplycontrol = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Key combination displayed
|
||||
private void actionkey_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
// Cursor to the end
|
||||
actionkey.SelectionStart = actionkey.Text.Length;
|
||||
actionkey.SelectionLength = 0;
|
||||
}
|
||||
|
||||
// Special key selected
|
||||
private void actioncontrol_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
KeyControl key;
|
||||
|
||||
// Leave when not allowed to update
|
||||
if(!allowapplycontrol) return;
|
||||
|
||||
// Anything selected?
|
||||
if((actioncontrol.SelectedIndex > -1) && (listactions.SelectedItems.Count > 0))
|
||||
{
|
||||
// Begin updating
|
||||
allowapplycontrol = false;
|
||||
|
||||
// Remove text from textbox
|
||||
actionkey.Text = "";
|
||||
|
||||
// Get the key control
|
||||
key = (KeyControl)actioncontrol.SelectedItem;
|
||||
|
||||
// Apply the key combination
|
||||
listactions.SelectedItems[0].SubItems[1].Text = Action.GetShortcutKeyDesc(key.key);
|
||||
listactions.SelectedItems[0].SubItems[1].Tag = key.key;
|
||||
|
||||
// Focus to the input box
|
||||
actionkey.Focus();
|
||||
|
||||
// Done
|
||||
allowapplycontrol = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear clicked
|
||||
private void actioncontrolclear_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Begin updating
|
||||
allowapplycontrol = false;
|
||||
|
||||
// Clear textbox and combobox
|
||||
actionkey.Text = "";
|
||||
actioncontrol.SelectedIndex = -1;
|
||||
|
||||
// Apply the key combination
|
||||
listactions.SelectedItems[0].SubItems[1].Text = "";
|
||||
listactions.SelectedItems[0].SubItems[1].Tag = (int)0;
|
||||
|
||||
// Focus to the input box
|
||||
actionkey.Focus();
|
||||
|
||||
// Done
|
||||
allowapplycontrol = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Configuration Panel
|
||||
|
@ -235,6 +379,10 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
// OK clicked
|
||||
private void apply_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Apply control keys to actions
|
||||
foreach(ListViewItem item in listactions.Items)
|
||||
General.Actions[item.Name].SetShortcutKey((int)item.SubItems[1].Tag);
|
||||
|
||||
// Apply configuration items
|
||||
foreach(ConfigurationInfo ci in listconfigs.Items)
|
||||
{
|
||||
|
@ -245,7 +393,7 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
if(string.Compare(ci.Filename, oci.Filename) == 0) oci.Apply(ci);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Close
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Hide();
|
||||
|
|
|
@ -512,7 +512,13 @@ namespace CodeImp.DoomBuilder.Interface
|
|||
{
|
||||
// Show configuration dialog
|
||||
ConfigForm cfgform = new ConfigForm();
|
||||
cfgform.ShowDialog(this);
|
||||
if(cfgform.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
// Update shortcut keys in menus
|
||||
ApplyShortcutKeys();
|
||||
}
|
||||
|
||||
// Done
|
||||
cfgform.Dispose();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue