bool TrySetKeyInOther(KeySettingItem itemToSet, KeyCode newKey, IKeyJoyAccessor accessor, int cur) { tmpIdx[cur] = accessor.FindInArray(mKeySettingLists[cur], newKey); if (tmpIdx[cur] < 0) { return(false); // Can not set because locked } KeyCode oldKey = accessor.Get(itemToSet); if (tmpIdx[cur] > 0) { accessor.Set(mKeySettingLists[cur][tmpIdx[cur] - 1], oldKey); } else { tmpIdx[0] = accessor.FindInArray(mKeySettingLists[0], newKey); if (tmpIdx[0] < 0) { return(false); // Can not set because locked } if (tmpIdx[0] > 0) { if (!TrySetKeyInCommon(mKeySettingLists[0][tmpIdx[0] - 1], oldKey, accessor, (-1 & ~(1 << cur)))) { return(false); } } } accessor.Set(itemToSet, newKey); return(true); }
public KeySettingItem TestConflict(KeySettingItem itemToSet, KeyCode newKey, IKeyJoyAccessor accessor) { int[] masks = new int[] { 0xff, 0x03, 0x05, 0x09, 0x11, 0x21 }; int n = mKeySettingLists.Length; int idx = 0; for (int i = 0; i < n; i++) { if (0 <= System.Array.IndexOf(mKeySettingLists[i], itemToSet)) { for (int j = 0; j < n; j++) { if ((masks[i] & (1 << j)) != 0 && 0 != (idx = accessor.FindInArray(mKeySettingLists[j], newKey))) { if (idx < 0) { idx = -idx; } return(mKeySettingLists[j][idx - 1]); } } } } return(null); }
bool TrySetKeyInCommon(KeySettingItem itemToSet, KeyCode newKey, IKeyJoyAccessor accessor, int conflictMask = -1) { tmpIdx[0] = accessor.FindInArray(mKeySettingLists[0], newKey); if (tmpIdx[0] < 0) { return(false); // Can not set because locked } KeyCode oldKey = accessor.Get(itemToSet); if (tmpIdx[0] > 0) { accessor.Set(mKeySettingLists[0][tmpIdx[0] - 1], oldKey); } else { for (int i = 1; i < 4; i++) { if (((1 << i) & conflictMask) == 0) { tmpIdx[i] = 0; continue; } tmpIdx[i] = accessor.FindInArray(mKeySettingLists[i], newKey); if (tmpIdx[i] < 0) { return(false); // Can not set because locked } } for (int i = 1; i < 4; i++) { if (tmpIdx[i] > 0) { accessor.Set(mKeySettingLists[i][tmpIdx[i] - 1], oldKey); } } } accessor.Set(itemToSet, newKey); return(true); }