private static void addData(Aircraft.Action command, MemoryStream stream, params Object[] args) { BinaryWriter writer = new BinaryWriter(stream); writer.Write((byte)command); if (args.Length > 0) { foreach (Object s in args) { if (s is byte) { writer.Write((byte)s); } else if (s is String) { writer.Write((String)s); } else { throw new ArrayTypeMismatchException("The supplied value is not of a supported type."); } } } //if args writer.Flush(); }
public static void addDeferred(Aircraft.Action command, String id, params Object[] args) { ClientRecord cr = senders[id]; addData(command, cr.deferred, args); cr.deferredCount++; }
//returns an array which holds all keys that have the specified //key as their .real properties. public static KeyData[] getAllAssignmentsFor(long k, Aircraft.Action exclude) { KeyData[] theKeys = new KeyData[keysData.Length]; int index = 0; KeyData kd; for (index = 0; index < keysData.Length; index++) { kd = keysData[index]; if (index + 1 != (int)exclude && k == kd.real) { theKeys[index] = kd; index++; } } if (index == 0) { return(null); } else { KeyData[] dest = new KeyData[index + 1]; theKeys.CopyTo(dest, 0); return(dest); } }
////Returns true if another modifier for this same key assignment is pressed, ////false otherwise public static bool isModifierHeldFor(Aircraft.Action a) { if (keysData[(int)a - 1].modifier > 0) { if (DXInput.isKeyHeldDown((Key)keysData[(int)a - 1].modifier)) { return(true); } } return(false); }
public static long[] getKey(Aircraft.Action key, bool fromJS) { if (!fromJS) { return((keysData[(int)key - 1].real == 0) ? null : keysData[(int)key - 1].toArray()); } else { return((joystickData[(int)key - 1].real == -2) ? null : joystickData[(int)key - 1].toArray()); } }
public static bool readFromFile() { try { if (!File.Exists(keyMapFile)) { initialize(); return(true); } BinaryReader s = new BinaryReader(new FileStream(keyMapFile, FileMode.Open)); int i = 0; for (i = 0; i <= keysData.Length - 1; i++) { addKey((Aircraft.Action)s.ReadInt32() + 1, (Key)s.ReadInt64(), (Key)s.ReadInt64()); } s.Close(); s = null; if (!File.Exists(joystickKeymapFile)) { return(true); //loaded keyboard, but js doesn't exist } s = new BinaryReader(new FileStream(joystickKeymapFile, FileMode.Open)); for (i = 0; i <= joystickData.Length - 1; i++) { Aircraft.Action a = (Aircraft.Action)s.ReadInt32() + 1; s.ReadInt64(); int k = (int)s.ReadInt64(); addKey(a, k); } return(true); } catch { initialize(); return(false); } }
public static void clearJSAssignment(Aircraft.Action a) { addKey(a, -1); }
public static void clearKeyboardAssignment(Aircraft.Action a) { addKey(a, Key.Unknown); }
//Overloaded. Reads key data from keyboard. public static long[] getKey(Aircraft.Action key) { return(getKey(key, false)); }
public static void addKey(Aircraft.Action key, Key m, Key r) { keysData[(int)key - 1].modifier = (long)m; keysData[(int)key - 1].real = (long)r; }
//Overloaded. For use with a keyboard only. //Sets modifier to 0 (eg. none) public static void addKey(Aircraft.Action key, Key value) { keysData[(int)key - 1].real = (long)value; keysData[(int)key - 1].modifier = -1; }
//this method should only be called by a joystick setup. public static void addKey(Aircraft.Action key, int value) { joystickData[(int)key - 1].real = value; joystickData[(int)key - 1].modifier = 0; }
/// <summary> /// Defines a key-binding for menus. /// </summary> /// <param name="a">The Aircraft.Action to associate to this binding.</param> /// <param name="f">A reference to the function that will handle the action. This parameter should be an ExtraItemFunction delegate, and will be called by the menu to execute the encapsulated method.</param> public ExtraItem(Aircraft.Action a, ExtraItemFunction f) { m_a = a; m_f = f; }