public DCSButtonBind toDCSButtonBind() { DCSButtonBind dbb = new DCSButtonBind(); dbb.key = JButton; if (JButton.Length < 1 || Joystick.Length < 1) { return(null); } if (dbb.reformers == null) { dbb.reformers = new List <string>(); } for (int i = 0; i < AllReformers.Count; ++i) { if (AllReformers[i].Length > 0) { string[] parts = AllReformers[i].Split('§'); if (parts.Length == 3) { dbb.reformers.Add(parts[0]); Modifier m = new Modifier(); m.name = parts[0]; m.device = parts[1]; m.sw = false; m.key = parts[2]; dbb.modifiers.Add(m); } } } return(dbb); }
public static Bind GetBindFromButtonElement(DCSButtonBind dab, string id, string joystick, string plane) { Relation r = new Relation(); Bind b = new Bind(r); r.ISAXIS = false; string shorten = MainStructure.ShortenDeviceName(joystick); string relationName = shorten + dab.key; if (dab.modifiers != null) { foreach (Modifier m in dab.modifiers) { relationName = m.name + relationName; string reform = m.name + "§" + m.device + "§" + m.key; if (!b.AllReformers.Contains(reform)) { b.AllReformers.Add(reform); } } } r.NAME = relationName; b.JButton = dab.key; b.Joystick = joystick; r.AddNode(id, plane); return(b); }
public DCSButtonBind Copy() { DCSButtonBind result = new DCSButtonBind(); result.key = key; for (int i = 0; i < reformers.Count; ++i) { result.reformers.Add(reformers[i]); } for (int i = 0; i < modifiers.Count; ++i) { result.modifiers.Add(modifiers[i]); } return(result); }
public void RemoveKey(string key, bool onlyIfDefault = false) { if (!onlyIfDefault) { List <string> toRemove = new List <string>(); foreach (KeyValuePair <string, DCSLuaDiffsAxisElement> kvp in axisDiffs) { for (int i = kvp.Value.added.Count - 1; i >= 0; i--) { if (kvp.Value.added[i].key == key) { if (kvp.Value.removed.Count == 0 && kvp.Value.added.Count == 1) { if (!toRemove.Contains(kvp.Key)) { toRemove.Add(kvp.Key); } } else { kvp.Value.added.RemoveAt(i); } } } } for (int i = 0; i < toRemove.Count; ++i) { axisDiffs.Remove(toRemove[i]); } toRemove.Clear(); foreach (KeyValuePair <string, DCSLuaDiffsButtonElement> kvp in keyDiffs) { for (int i = kvp.Value.added.Count - 1; i >= 0; i--) { if (kvp.Value.added[i].key == key) { if (kvp.Value.removed.Count == 0 && kvp.Value.added.Count == 1) { if (!toRemove.Contains(kvp.Key)) { toRemove.Add(kvp.Key); } } else { kvp.Value.added.RemoveAt(i); } } } } for (int i = 0; i < toRemove.Count; ++i) { axisDiffs.Remove(toRemove[i]); } } DCSLuaInput defs = getDefaultBinds(); foreach (KeyValuePair <string, DCSLuaDiffsAxisElement> kvp in defs.axisDiffs) { foreach (DCSAxisBind kvpa in kvp.Value.removed) { if (kvpa.key == key) { if (!axisDiffs.ContainsKey(kvp.Key)) { axisDiffs.Add(kvp.Key, new DCSLuaDiffsAxisElement()); axisDiffs[kvp.Key].Keyname = kvp.Key; } DCSLuaDiffsAxisElement element = axisDiffs[kvp.Key]; bool found = false; for (int i = 0; i < element.removed.Count; ++i) { if (element.removed[i].key == key) { found = true; break; } } if (!found) { DCSAxisBind dab = new DCSAxisBind(); dab.key = key; element.removed.Add(dab); } } } } foreach (KeyValuePair <string, DCSLuaDiffsButtonElement> kvp in defs.keyDiffs) { foreach (DCSButtonBind kvpa in kvp.Value.removed) { if (kvpa.key == key) { if (!keyDiffs.ContainsKey(kvp.Key)) { keyDiffs.Add(kvp.Key, new DCSLuaDiffsButtonElement()); keyDiffs[kvp.Key].Keyname = kvp.Key; } DCSLuaDiffsButtonElement element = keyDiffs[kvp.Key]; bool found = false; for (int i = 0; i < element.removed.Count; ++i) { if (element.removed[i].key == key) { found = true; break; } } if (!found) { DCSButtonBind dab = new DCSButtonBind(); dab.key = key; element.removed.Add(dab); } } } } }
public void AnalyzeRawLuaInput(string content) { if (!content.Contains('{')) { return; } string cleaned = MainStructure.GetContentBetweenSymbols(content, "{", "}"); Dictionary <object, object> dct = MainStructure.CreateAttributeDictFromLua(content); if (dct.ContainsKey("axisDiffs")) { foreach (KeyValuePair <object, object> kvp in (Dictionary <object, object>)dct["axisDiffs"]) { DCSLuaDiffsAxisElement current = new DCSLuaDiffsAxisElement(); current.Keyname = (string)kvp.Key; if (axisDiffs.ContainsKey(current.Keyname)) { axisDiffs[current.Keyname] = current; } else { axisDiffs.Add(current.Keyname, current); } if (((Dictionary <object, object>)kvp.Value).ContainsKey("name")) { current.Title = (string)((Dictionary <object, object>)kvp.Value)["name"]; } if (((Dictionary <object, object>)kvp.Value).ContainsKey("added")) { Dictionary <object, object> dictAdded = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["added"]; foreach (KeyValuePair <object, object> kvpAdded in dictAdded) { if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("key")) { DCSAxisBind dab = new DCSAxisBind(); dab.key = (string)((Dictionary <object, object>)kvpAdded.Value)["key"]; if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("filter")) { DCSAxisFilter daf = new DCSAxisFilter(); dab.filter = daf; daf.deadzone = (double)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["deadzone"]; daf.inverted = (bool)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["invert"]; daf.slider = (bool)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["slider"]; daf.saturationX = (double)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["saturationX"]; daf.saturationY = (double)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["saturationY"]; foreach (KeyValuePair <object, object> kvpCurve in (Dictionary <object, object>)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["curvature"]) { daf.curviture.Add((double)kvpCurve.Value); } } if (!current.doesAddedContainKey(dab.key)) { current.added.Add(dab); current.removeItemFromRemoved(dab.key); } } } } if (((Dictionary <object, object>)kvp.Value).ContainsKey("removed")) { Dictionary <object, object> dictRemoved = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["removed"]; foreach (KeyValuePair <object, object> kvpRemoved in dictRemoved) { if (((Dictionary <object, object>)kvpRemoved.Value).ContainsKey("key")) { DCSAxisBind dab = new DCSAxisBind(); dab.key = (string)((Dictionary <object, object>)kvpRemoved.Value)["key"]; if (!current.doesRemovedContainKey(dab.key)) { current.removed.Add(dab); current.removeItemFromAdded(dab.key); } } } } } } if (dct.ContainsKey("keyDiffs")) { foreach (KeyValuePair <object, object> kvp in (Dictionary <object, object>)dct["keyDiffs"]) { DCSLuaDiffsButtonElement current = new DCSLuaDiffsButtonElement(); current.Keyname = (string)kvp.Key; if (keyDiffs.ContainsKey(current.Keyname)) { keyDiffs[current.Keyname] = current; } else { keyDiffs.Add(current.Keyname, current); } if (((Dictionary <object, object>)kvp.Value).ContainsKey("name")) { current.Title = (string)((Dictionary <object, object>)kvp.Value)["name"]; } if (((Dictionary <object, object>)kvp.Value).ContainsKey("added")) { Dictionary <object, object> dictAdded = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["added"]; foreach (KeyValuePair <object, object> kvpAdded in dictAdded) { if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("key")) { DCSButtonBind dab = new DCSButtonBind(); dab.key = (string)((Dictionary <object, object>)kvpAdded.Value)["key"]; if (!current.doesAddedContainKey(dab.key)) { current.added.Add(dab); current.removeItemFromRemoved(dab.key); } if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("reformers")) { foreach (KeyValuePair <object, object> kvpReformers in (Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["reformers"]) { if (!dab.reformers.Contains((string)kvpReformers.Value)) { dab.reformers.Add((string)kvpReformers.Value); } } } } } } if (((Dictionary <object, object>)kvp.Value).ContainsKey("removed")) { Dictionary <object, object> dictRemoved = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["removed"]; foreach (KeyValuePair <object, object> kvpRemoved in dictRemoved) { if (((Dictionary <object, object>)kvpRemoved.Value).ContainsKey("key")) { DCSButtonBind dab = new DCSButtonBind(); dab.key = (string)((Dictionary <object, object>)kvpRemoved.Value)["key"]; if (!current.doesRemovedContainKey(dab.key)) { current.removed.Add(dab); current.removeItemFromAdded(dab.key); } } } } } } }