private void Unbind(Action action) { for (int i = 0; i < GameInputMapping.KeyBindings.Length; i++) { BindingEntry bindingEntry = GameInputMapping.KeyBindings[i]; if (bindingEntry.mAction == action) { bindingEntry.mKeyCode = KKeyCode.None; bindingEntry.mModifier = Modifier.None; GameInputMapping.KeyBindings[i] = bindingEntry; } } }
public KInputController AddGamepadController(int gamepad_index) { KInputController kInputController = new KInputController(true); BindingEntry[] bindingEntries = GameInputMapping.GetBindingEntries(); for (int i = 0; i < bindingEntries.Length; i++) { BindingEntry bindingEntry = bindingEntries[i]; kInputController.Bind(BindingEntry.GetGamepadKeyCode(gamepad_index, bindingEntry.mButton), Modifier.None, bindingEntry.mAction); } AddController(kInputController); return(kInputController); }
public static bool GameInputMapping_FindEntry_Prefix(Action mAction, ref BindingEntry __result) { foreach (BindingEntry keyBinding in GameInputMapping.KeyBindings) { if (keyBinding.mAction == mAction) { __result = keyBinding; return(false); } } __result = new BindingEntry(null, GamepadButton.NumButtons, KKeyCode.None, Modifier.None, Action.NumActions, false, false); return(false); }
public void RebindControls() { foreach (KInputController mController in mControllers) { mController.ClearBindings(); BindingEntry[] bindingEntries = GameInputMapping.GetBindingEntries(); for (int i = 0; i < bindingEntries.Length; i++) { BindingEntry bindingEntry = bindingEntries[i]; mController.Bind(bindingEntry.mKeyCode, bindingEntry.mModifier, bindingEntry.mAction); } mController.HandleCancelInput(); } }
public static bool GameInputMapping_CompareActionKeyCodes_Prefix(Action a, Action b, ref bool __result) { BindingEntry entry1 = GameInputMapping.FindEntry(a); BindingEntry entry2 = GameInputMapping.FindEntry(b); if (!(entry1.mAction == Action.NumActions || entry2.mAction == Action.NumActions) && entry1.mKeyCode == entry2.mKeyCode) { __result = entry1.mModifier == entry2.mModifier; return(false); } __result = false; return(false); }
private BindingEntry GetFirstUnbound() { BindingEntry result = default(BindingEntry); for (int i = 0; i < GameInputMapping.KeyBindings.Length; i++) { BindingEntry result2 = GameInputMapping.KeyBindings[i]; if (result2.mKeyCode == KKeyCode.None) { return(result2); } } return(result); }
private BindingEntry GetDuplicatedBinding(string activeScreen, BindingEntry new_binding) { BindingEntry result = default(BindingEntry); for (int i = 0; i < GameInputMapping.KeyBindings.Length; i++) { BindingEntry bindingEntry = GameInputMapping.KeyBindings[i]; if (new_binding.IsBindingEqual(bindingEntry) && (bindingEntry.mGroup == null || bindingEntry.mGroup == activeScreen || bindingEntry.mGroup == "Root" || activeScreen == "Root") && (!(activeScreen == "Root") || !bindingEntry.mIgnoreRootConflics) && (!(bindingEntry.mGroup == "Root") || !new_binding.mIgnoreRootConflics)) { return(bindingEntry); } } return(result); }
private int NumUnboundActions() { int num = 0; for (int i = 0; i < GameInputMapping.KeyBindings.Length; i++) { BindingEntry bindingEntry = GameInputMapping.KeyBindings[i]; if (bindingEntry.mKeyCode == KKeyCode.None && (BuildMenu.UseHotkeyBuildMenu() || !bindingEntry.mIgnoreRootConflics)) { num++; } } return(num); }
public static BindingEntry FindEntry(Action mAction) { BindingEntry[] keyBindings = KeyBindings; for (int i = 0; i < keyBindings.Length; i++) { BindingEntry result = keyBindings[i]; if (result.mAction == mAction) { return(result); } } Debug.Assert(false, "Unbound action " + mAction.ToString()); return(KeyBindings[0]); }
public static BindingEntry[] FindEntriesByKeyCode(KKeyCode keycode) { List <BindingEntry> list = new List <BindingEntry>(); BindingEntry[] keyBindings = KeyBindings; for (int i = 0; i < keyBindings.Length; i++) { BindingEntry item = keyBindings[i]; if (item.mKeyCode == keycode) { list.Add(item); } } return(list.ToArray()); }
private void CollectScreens() { screens.Clear(); for (int i = 0; i < GameInputMapping.KeyBindings.Length; i++) { BindingEntry bindingEntry = GameInputMapping.KeyBindings[i]; if (bindingEntry.mGroup != null && bindingEntry.mRebindable && !screens.Contains(bindingEntry.mGroup)) { if (bindingEntry.mGroup == "Root") { activeScreen = screens.Count; } screens.Add(bindingEntry.mGroup); } } }
protected override void OnPrefabInit() { BindingEntry[] bindingEntries = GameInputMapping.GetBindingEntries(); string text = string.Empty; BindingEntry[] array = bindingEntries; for (int i = 0; i < array.Length; i++) { BindingEntry bindingEntry = array[i]; text += bindingEntry.mAction.ToString(); text += ": "; text += bindingEntry.mKeyCode.ToString(); text += "\n"; } controlLabel.text = text; }
public static HashSet <KeyCode> GetKeyCodes() { HashSet <KeyCode> hashSet = new HashSet <KeyCode>(); BindingEntry[] bindingEntries = GetBindingEntries(); for (int i = 0; i < bindingEntries.Length; i++) { BindingEntry bindingEntry = bindingEntries[i]; if (bindingEntry.mKeyCode < KKeyCode.KleiKeys) { hashSet.Add((KeyCode)bindingEntry.mKeyCode); } } hashSet.Add(KeyCode.LeftAlt); hashSet.Add(KeyCode.LeftControl); hashSet.Add(KeyCode.LeftShift); hashSet.Add(KeyCode.CapsLock); return(hashSet); }
public static void Postfix(ref BindingEntry[] __result) { try { if (State.Config.LogElementsData) { var values = Enum.GetNames(typeof(SimHashes)); Array.Sort(values); string elementsLog = ""; foreach (var name in values) { elementsLog += Environment.NewLine + name; } Common.Logger.Log("Elements list: " + elementsLog); } try { List <BindingEntry> bind = __result.ToList(); BindingEntry entry = new BindingEntry ( "Root", GamepadButton.NumButtons, KKeyCode.F6, Modifier.Alt, (Action)IDs.ToggleMaterialColorOverlayAction, true, true ); bind.Add(entry); __result = bind.ToArray(); } catch (Exception e) { Common.Logger.LogOnce("Keybindings failed:\n", e); throw; } } catch (Exception e) { Common.Logger.LogOnce("Global_GenerateDefaultBindings.Postfix", e); } }
private void GenericComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox cb = sender as ComboBox; // Should never be false if (cb != null) { //bindings[cb.Name].SetValue(bindings[cb.Name].) BindingEntry be = bindings[cb.Name]; if (be.parent != null) { be.fi.SetValue(be.parent.GetValue(Settings.s), cb.SelectedIndex); } else { be.fi.SetValue(Settings.s, cb.SelectedIndex); } } }
private void DrawPicker(Rect position, SerializedProperty property) { int index = EditorGUI.Popup(position, cache.CurrentIndex, cache.CachedOptions); if (index != cache.CurrentIndex) { if (index > 0) { string bindingId = cache.CachedOptionIds[index]; BindingEntry entry = cache.BindingMap[bindingId]; SetBinding(property, entry.Component, entry.PropertyName); } else { SetBinding(property, null, ""); } cache.CurrentIndex = index; } }
/// <summary> /// Adds a key binding to the game for this custom Action. It must be done after mods /// are loaded. /// </summary> /// <param name="binding">The default key binding for this action.</param> internal void AddKeyBinding(PKeyBinding binding) { var currentBindings = GameInputMapping.DefaultBindings; if (binding == null) { throw new ArgumentNullException("binding"); } if (currentBindings != null) { // Only if GameInputMapping is initialized Action action = GetKAction(); bool inBindings = false; int n = currentBindings.Length; for (int i = 0; i < n && !inBindings; i++) { var cb = currentBindings[i]; if (cb.mAction == action) { // Already exists, but it really should not PActionManager.LogKeyBindWarning(("Action {0} already exists; " + "assigned to KeyCode {1}").F(action, cb.mKeyCode)); inBindings = true; break; } } if (!inBindings) { var newBindings = new BindingEntry[n + 1]; Array.Copy(currentBindings, newBindings, n); newBindings[n] = new BindingEntry(PActionManager.CATEGORY, binding. GamePadButton, binding.Key, binding.Modifiers, action, true, false); GameInputMapping.SetDefaultKeyBindings(newBindings); } } else { // Queue into PActionManager PActionManager.Instance.QueueKeyBind(this, binding); } }
public static void LoadBindings() { KeyBindings = (BindingEntry[])DefaultBindings.Clone(); if (File.Exists(BindingsFilename)) { string text = File.ReadAllText(BindingsFilename); if (text != null && !(text == string.Empty)) { BindingEntry[] array = null; try { array = JsonConvert.DeserializeObject <BindingEntry[]>(text); } catch { DebugUtil.LogErrorArgs("Error parsing", BindingsFilename); } if (array != null && array.Length != 0) { for (int i = 0; i < KeyBindings.Length; i++) { BindingEntry bindingEntry = KeyBindings[i]; BindingEntry[] array2 = array; for (int j = 0; j < array2.Length; j++) { BindingEntry bindingEntry2 = array2[j]; if (bindingEntry2.mAction == bindingEntry.mAction && bindingEntry.mRebindable) { BindingEntry bindingEntry3 = bindingEntry; bindingEntry3.mButton = bindingEntry2.mButton; bindingEntry3.mKeyCode = bindingEntry2.mKeyCode; bindingEntry3.mModifier = bindingEntry2.mModifier; KeyBindings[i] = bindingEntry3; break; } } } } } } }
private void Bind(KKeyCode kkey_code, Modifier modifier) { BindingEntry bindingEntry = new BindingEntry(screens[activeScreen], GamepadButton.NumButtons, kkey_code, modifier, actionToRebind, true, ignoreRootConflicts); int num = 0; while (true) { if (num >= GameInputMapping.KeyBindings.Length) { return; } BindingEntry bindingEntry2 = GameInputMapping.KeyBindings[num]; if (bindingEntry2.mRebindable && bindingEntry2.mAction == actionToRebind) { break; } num++; } BindingEntry duplicatedBinding = GetDuplicatedBinding(screens[activeScreen], bindingEntry); GameInputMapping.KeyBindings[num] = bindingEntry; LocText componentInChildren = activeButton.GetComponentInChildren <LocText>(); componentInChildren.text = GetBindingText(bindingEntry); if (duplicatedBinding.mAction != 0 && duplicatedBinding.mAction != actionToRebind) { confirmDialog = Util.KInstantiateUI(confirmPrefab.gameObject, base.transform.gameObject, false).GetComponent <ConfirmDialogScreen>(); string key = "STRINGS.INPUT_BINDINGS." + duplicatedBinding.mGroup.ToUpper() + "." + duplicatedBinding.mAction.ToString().ToUpper(); string arg = Strings.Get(key); string bindingText = GetBindingText(duplicatedBinding); string text = string.Format(UI.FRONTEND.INPUT_BINDINGS_SCREEN.DUPLICATE, arg, bindingText); Unbind(duplicatedBinding.mAction); confirmDialog.PopupConfirmDialog(text, null, null, null, null, null, null, null, null, true); confirmDialog.gameObject.SetActive(true); } Global.Instance.GetInputManager().RebindControls(); waitingForKeyPress = false; actionToRebind = Action.NumActions; activeButton = null; BuildDisplay(); }
public static void Postfix(ref BindingEntry[] __result) { try { List <BindingEntry> bind = __result.ToList(); BindingEntry entry = new BindingEntry( "Root", GamepadButton.NumButtons, KKeyCode.F6, Modifier.Alt, (Action)IDs.ToggleMaterialColorOverlayAction, true, true); bind.Add(entry); __result = bind.ToArray(); } catch (Exception e) { State.Logger.Log("Keybindings failed:\n" + e); throw; } }
private void BuildDisplay() { string text = screens[activeScreen]; string key = "STRINGS.INPUT_BINDINGS." + text.ToUpper() + ".NAME"; screenTitle.text = Strings.Get(key); if (entryPool == null) { entryPool = new UIPool <HorizontalLayoutGroup>(entryPrefab.GetComponent <HorizontalLayoutGroup>()); } DestroyDisplay(); int num = 0; for (int i = 0; i < GameInputMapping.KeyBindings.Length; i++) { BindingEntry binding = GameInputMapping.KeyBindings[i]; if (binding.mGroup == screens[activeScreen] && binding.mRebindable) { GameObject gameObject = entryPool.GetFreeElement(parent, true).gameObject; LocText componentInChildren = gameObject.transform.GetChild(0).GetComponentInChildren <LocText>(); string key2 = "STRINGS.INPUT_BINDINGS." + binding.mGroup.ToUpper() + "." + binding.mAction.ToString().ToUpper(); componentInChildren.text = Strings.Get(key2); LocText key_label = gameObject.transform.GetChild(1).GetComponentInChildren <LocText>(); key_label.text = GetBindingText(binding); KButton button = gameObject.GetComponentInChildren <KButton>(); button.onClick += delegate { waitingForKeyPress = true; actionToRebind = binding.mAction; ignoreRootConflicts = binding.mIgnoreRootConflics; activeButton = button; key_label.text = UI.FRONTEND.INPUT_BINDINGS_SCREEN.WAITING_FOR_INPUT; }; gameObject.transform.SetSiblingIndex(num); num++; } } }
private static void AddBindings(HashedString parent_category, BuildMenu.DisplayInfo display_info, List <BindingEntry> bindings) { if (display_info.data != null) { Type type = display_info.data.GetType(); if (typeof(IList <BuildMenu.DisplayInfo>).IsAssignableFrom(type)) { IList <BuildMenu.DisplayInfo> list = (IList <BuildMenu.DisplayInfo>)display_info.data; foreach (BuildMenu.DisplayInfo item2 in list) { AddBindings(display_info.category, item2, bindings); } } else if (typeof(IList <BuildMenu.BuildingInfo>).IsAssignableFrom(type)) { string str = HashCache.Get().Get(parent_category); TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; string group = textInfo.ToTitleCase(str) + " Menu"; BindingEntry item = new BindingEntry(group, GamepadButton.NumButtons, display_info.keyCode, Modifier.None, display_info.hotkey, true, true); bindings.Add(item); } } }
public static void Postfix(ref BindingEntry[] __result) { if (State.ConfiguratorState.LogElementsData) { State.Logger.Log("Element List:"); var values = Enum.GetNames(typeof(SimHashes)); Array.Sort(values); string elementsLog = ""; foreach (var name in values) { elementsLog += Environment.NewLine + name; //ElementLoader.GetElementIndex(i); //ElementLoader.FindElementByName(i); } State.Logger.Log(elementsLog); } try { List <BindingEntry> bind = __result.ToList(); BindingEntry entry = new BindingEntry( "Root", GamepadButton.NumButtons, KKeyCode.F6, Modifier.Alt, (Action)IDs.ToggleMaterialColorOverlayAction, true, true); bind.Add(entry); __result = bind.ToArray(); } catch (Exception e) { State.Logger.Log("Keybindings failed:\n" + e); throw; } }
public static void SaveBindings() { if (!Directory.Exists(Util.RootFolder())) { Directory.CreateDirectory(Util.RootFolder()); } List <BindingEntry> list = new List <BindingEntry>(); BindingEntry[] keyBindings = KeyBindings; for (int i = 0; i < keyBindings.Length; i++) { BindingEntry bindingEntry = keyBindings[i]; bool flag = false; BindingEntry[] defaultBindings = DefaultBindings; foreach (BindingEntry b in defaultBindings) { if (bindingEntry == b) { flag = true; break; } } if (!flag && bindingEntry.mRebindable) { list.Add(bindingEntry); } } if (list.Count > 0) { string contents = JsonConvert.SerializeObject(list); File.WriteAllText(BindingsFilename, contents); } else if (File.Exists(BindingsFilename)) { File.Delete(BindingsFilename); } }
/// <summary> /// Adds a key binding to the game for this custom Action. It must be done after mods /// are loaded. /// </summary> /// <param name="binding">The default key binding for this action.</param> internal void AddKeyBinding(PKeyBinding binding) { var currentBindings = GameInputMapping.DefaultBindings; if (binding == null) { throw new ArgumentNullException("binding"); } if (currentBindings != null) { Action action = GetKAction(); bool inBindings = false; // Only if GameInputMapping is initialized int n = currentBindings.Length; for (int i = 0; i < n && !inBindings; i++) { if (currentBindings[i].mAction == action) { inBindings = true; break; } } if (!inBindings) { var newBindings = new BindingEntry[n + 1]; Array.Copy(currentBindings, newBindings, n); newBindings[n] = new BindingEntry(PActionManager.CATEGORY, binding. GamePadButton, binding.Key, binding.Modifiers, action, true, false); GameInputMapping.SetDefaultKeyBindings(newBindings); } } else { // Queue into PActionManager PActionManager.Instance.QueueKeyBind(this, binding); } }
/// <summary> /// Gets the action's command as a user-friendly string. Only works if the Steam /// Controller is not in use. /// </summary> /// <param name="inputBinding">The input binding for the command.</param> /// <param name="text">The location where the result will be stored</param> private static void GetActionString(ref BindingEntry inputBinding, StringBuilder text) { var keyCode = inputBinding.mKeyCode; var modifier = inputBinding.mModifier; var modText = MODIFERS; string raw = StringFormatter.ToUpper(GameUtil.GetKeycodeLocalized(keyCode)); if (modifier == Modifier.None) { text.Append(raw); } else { bool first = true; if ((modifier & Modifier.Alt) != 0) { text.Append(modText[0]); first = false; } if ((modifier & Modifier.Ctrl) != 0) { if (!first) { text.Append(" + "); } text.Append(modText[1]); first = false; } if ((modifier & Modifier.Shift) != 0) { if (!first) { text.Append(" + "); } text.Append(modText[2]); first = false; } switch (modifier) { case Modifier.CapsLock: if (!first) { text.Append(" + "); } text.Append(modText[3]); break; case Modifier.Backtick: if (!first) { text.Append(" + "); } text.Append(modText[4]); break; default: break; } text.Append(" + ").Append(raw); } }
/// <summary> /// Called when a binding completes. /// </summary> /// <param name="changed">The completed entry.</param> private void EntryCompleted(BindingEntry entry) { this.Remove(entry); }
/// <summary> /// Removes the specified binding entry and updates the current value. /// </summary> /// <param name="entry">The binding entry to remove.</param> private void Remove(BindingEntry entry) { entry.Dispose(); this.bindings.Remove(entry); this.UpdateValue(); }
private void toolStripButton1_Click(object sender, EventArgs e) { if (!IBMiUtils.IsValueObjectName(objectName.Text)) { MessageBox.Show("Object name is not valid."); objectName.Focus(); return; } if (objectType.Text == "") { MessageBox.Show("Object type is not valid."); objectType.Focus(); return; } if (IBMiUtils.IsValueObjectName(objectLib.Text) == false && objectLib.Text != "*LIBL") { MessageBox.Show("Object library name is not valid."); objectLib.Focus(); return; } if (objectActivation.Text == "") { MessageBox.Show("Object activation is not valid."); objectType.Focus(); return; } BindingEntry Entry = new BindingEntry(); Entry.BindingLib = Library; Entry.BindingObj = Object; Entry.Name = objectName.Text.Trim(); Entry.Library = objectLib.Text.Trim(); Entry.Type = objectType.Text; Entry.Activation = objectActivation.Text; Entry.CreationDate = ""; Entry.CreationTime = ""; string command = "ADDBNDDIRE BNDDIR(" + Library + "/" + Object + ") OBJ((" + Entry.Library + "/" + Entry.Name + " " + Entry.Type + " " + Entry.Activation + "))"; Thread gothread = new Thread((ThreadStart) delegate { if (IBMi.RunCommands(new string[1] { command }) == false) { ListViewItem Item = new ListViewItem(new string[6] { Entry.Name, Entry.Type, Entry.Library, Entry.Activation, Entry.CreationDate, Entry.CreationTime }); Item.Tag = Entry; this.Invoke((MethodInvoker) delegate { entriesList.Items.Add(Item); }); } else { MessageBox.Show("Unable to create binding entry."); } }); gothread.Start(); }