rlranft Posted June 23, 2015 Share Posted June 23, 2015 Technically, it's only an "improvement" if you're going to take advantage of it.It's always bugged me that the control mapping "data" is jammed into the middle of /scripts/gui/optionsDlg.cs - just a big array definition sitting in the middle of the script. Then I decided I wanted a little editor to let me modify it easily - you know, add a remap for crouch or something. So I pulled it out of there and made it into its own script file all by itself and added an exec() to the top of optionsDlg.cs. Then I made a stupid-simple C# application that would load and edit the / pairs from that file. Now, I just fire up the little app, add or remove pairs, and save.Here's the meat of the tool source - it's a Windows Forms C# application, and I've added a couple of comments to tell you what controls I used. It's tiny:using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace T3DKeyMapMod { public partial class Form1 : Form { private String m_keyMapPath; private Dictionary m_keyMap; public Form1() { InitializeComponent(); m_keyMapPath = ""; m_keyMap = new Dictionary(); } private void openToolStripMenuItem_Click(object sender, EventArgs e) { if(fbdOpenProject.ShowDialog() == System.Windows.Forms.DialogResult.OK) // fbd is a FolderBrowserDialog { // use path to extrapolate the location of the keymap.cs file m_keyMapPath = fbdOpenProject.SelectedPath + @"\game\scripts\gui\keymap.cs"; loadKeyMap(); } } private void loadKeyMap() { using (StreamReader sr = new StreamReader(m_keyMapPath)) { String line = ""; String key = ""; String method = ""; while (!sr.EndOfStream) { line = sr.ReadLine(); if (line.Equals("$RemapCount = 0;") || line.Equals("$RemapCount++;")) continue; if (line.Contains("$RemapName")) { key = line.Replace("$RemapName[$RemapCount] = \"", ""); key = key.Replace("\";", ""); } if(line.Contains("$RemapCmd")) { method = line.Replace("$RemapCmd[$RemapCount] = \"", ""); method = method.Replace("\";", ""); m_keyMap.Add(key, method); key = ""; method = ""; } } } dgvKeyMap.Rows.Clear(); // dgv is a DataGridView foreach(String key in m_keyMap.Keys) { dgvKeyMap.Rows.Add(new object[]{key, m_keyMap[key]}); } } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if(m_keyMapPath != "") { label1.Focus(); m_keyMap.Clear(); foreach (DataGridViewRow row in dgvKeyMap.Rows) { if (row.Cells[0].Value == null) continue; m_keyMap.Add(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString()); } using (StreamWriter sr = new StreamWriter(m_keyMapPath)) { sr.WriteLine("$RemapCount = 0;"); foreach(KeyValuePair entry in m_keyMap) { sr.WriteLine("$RemapName[$RemapCount] = \"" + entry.Key + "\";"); sr.WriteLine("$RemapCmd[$RemapCount] = \"" + entry.Value + "\";"); sr.WriteLine("$RemapCount++;"); } } } } private void dgvKeyMap_Leave(object sender, EventArgs e) { dgvKeyMap.EndEdit(); } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } private void dgvKeyMap_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { DataGridViewRow row = new DataGridViewRow(); DataGridView obj = (DataGridView)sender; int index = obj.SelectedRows[0].Index + 1; if (index == dgvKeyMap.Rows.Count) dgvKeyMap.Rows.Add(row); else dgvKeyMap.Rows.Insert(index, row); } } } Not exactly a "how-to," but it is pretty simple. And even though it's something that only really needs to be fiddled with rarely it was just really sort of annoying to me to have to find that array definition almost literally in the middle of that damned script file.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.