public void PlaceBindings() { // Clear the existing binding images ClearAllBindings(); // Get the latest bindings from the binding manager var newestBindings = m_bindingManager.KeyBindings; // Create portraits for all of the bindings foreach (KeyValuePair <KeyCode, Call_Individual> bindPair in newestBindings) { // Determine the index for the placement in the UI int uiKeyIndex = m_keyboardLayout.GetIndexFromKeyCode(bindPair.Key); // Toggle the main keyboard letter so that it appears if the slot is empty but hides if a caller is in it m_keyboardLetters[uiKeyIndex].gameObject.SetActive(bindPair.Value == null); // If this binding isn't set, turn the key back on and then move on if (bindPair.Value == null) { continue; } // Otherwise, determine which which caller the portrait should represent Call_Individual caller = bindPair.Value; // Now, spawn a new portrait on the right UI key and set it up with the caller object GameObject portraitObj = Instantiate(m_callerUIPrefab, m_keyPortraitParents[uiKeyIndex]); Call_Individual_UI uiComp = portraitObj.GetComponent <Call_Individual_UI>(); uiComp.InitWithData(caller); } }
//--- Methods ---// public void InitWithData(Call_Individual _refCaller) { // Store the refernce to the caller object for later m_refCaller = _refCaller; // Update the UI UpdateUI(); }
public void DeselectCaller(Call_Individual _caller) { // Set the caller's selected value _caller.IsSelected = false; // Remove the caller from the selected list m_selectedCallers.Remove(_caller); }
public void SelectCaller(Call_Individual _caller) { // Set the caller's selected value _caller.IsSelected = true; // Add the caller to the selected list m_selectedCallers.Add(_caller); }
public void BindCallerToKey(KeyCode _bindKey, Call_Individual _caller) { if (_bindKey == KeyCode.None) { Debug.Log("NONE"); } // Bind the caller to the given key m_keyBindings[_bindKey] = _caller; // Ensure the caller slot is actually filled. It could be empty if (_caller != null) { _caller.BoundKeyCode = _bindKey; } }
public bool AddCaller(Call_Individual _newCaller) { // Ensure this will work if (!CheckForAdd()) { return(false); } // Tell the caller they now belong to this room _newCaller.CurrentRoom = m_roomName; // Add the caller to the list m_callersInRoom.Add(_newCaller); // Invoke the event to indicate the room has changed m_OnRoomCallersChanged.Invoke(); // Return true to indicate the add worked return(true); }
public bool RemoveCaller(Call_Individual _callerToRemove) { // Perform a check to ensure this will work if (!CheckForRemoval(_callerToRemove)) { return(false); } // Remove the caller from the list m_callersInRoom.Remove(_callerToRemove); // The caller is now temporarily unassigned but should be re-assigned when being placed in another room _callerToRemove.CurrentRoom = Room_Name.Unassigned; // Invoke the event to indicate the room has changed m_OnRoomCallersChanged.Invoke(); // Return true to indicate everything worked return(true); }
public void HandleLetterKeyPressed(KeyCode _alphabetKey) { // If in swap mode, we should prepare to switch the bindings if (m_isInSwapMode) { // If this is the first alphabet key pressed since entering swap mode, we should store it so we can prepare to swap next time if (m_keyToSwap == KeyCode.None) { // Store the key so that next time, we are able to actually perform the swap m_keyToSwap = _alphabetKey; } else { // Hold the caller temporarily so we can perform a swap Call_Individual tempCaller = m_keyBindings[m_keyToSwap]; // Swap the bindings BindCallerToKey(m_keyToSwap, m_keyBindings[_alphabetKey]); BindCallerToKey(_alphabetKey, tempCaller); // Invoke the event since the key bindings have changed m_OnBindingsChanged.Invoke(); // Clear the held swap key m_keyToSwap = KeyCode.None; } } else if (m_groupToBind != null) // Otherwise, if the player selected a call group in the backlog, we should be binding those mappings { // We should check if the binding is currently open. If it isn't, we should back out if (!CheckIfBindingOpen(_alphabetKey)) { return; } // Grab the individual callers from the bound group List <Call_Individual> callers = m_groupToBind.CallParticipants; // Loop through and find the next one that needs a binding for (int i = 0; i < callers.Count; i++) { // Grab the caller reference var caller = callers[i]; // If the caller is already bound, we can move on to the next one if (caller.BoundKeyCode != KeyCode.None) { continue; } // Otherwise, we can go ahead and perform the binding BindCallerToKey(_alphabetKey, caller); // Invoke the event since the key bindings have changed m_OnBindingsChanged.Invoke(); // We should also mark the caller as selected to make it easier to move it around after SelectCaller(caller); // We now also need to move the caller into the waiting room m_roomManager.TransferCallers(new List <Call_Individual> { caller }, Room_Name.Waiting); // If this is the last caller, then the group is fully bound and we can unlink it if (i == callers.Count - 1) { // The group is no longer in bind mode m_groupToBind.IsInBindMode = false; // Stop tracking the group m_groupToBind = null; } // Finally, we should break the loop to prevent binding the next caller to the same key break; } } else // Otherwise, the player is selecting / deselecting a caller { // Grab the call participant reference associated with the keycode Call_Individual caller = m_keyBindings[_alphabetKey]; // Check if there is an actual caller bound to that key if (caller != null) { // If the caller is currently unselected, we should select them and vice versa if (m_selectedCallers.Contains(caller)) { DeselectCaller(caller); } else { SelectCaller(caller); } } } }
public bool CheckForRemoval(Call_Individual _callerToRemove) { // Return true if the caller is in the room, false otherwise return(m_callersInRoom.Contains(_callerToRemove)); }