public async Task <ActionResult> AddPrediction([FromBody] PredictionItem prediction) { _context.PredictionItems.Add(prediction); await _context.SaveChangesAsync(); return(Ok()); }
private void FillPredictionItemsWithCommands(List <ICommand> a_commandList) { int predictionItemsCount = _predictionItems.Count; // Best Size used for sizing of Vector2 itemSize = _predictionItemTemplate.Rect.sizeDelta; float bestWidth = itemSize.x; for (int i = 0; i < a_commandList.Count; ++i) { ICommand predictedCommand = a_commandList[i]; int itemIdx = predictionItemsCount - 1 - i; if (itemIdx < 0 || itemIdx >= predictionItemsCount) { continue; } _currentString.Clear(); PredictionItem item = _predictionItems[itemIdx]; _currentString.Append(predictedCommand.Name); if (predictedCommand.ArgCount != 0) { _currentString.Append(" - "); for (int j = 0; j < predictedCommand.ArgCount; ++j) { _currentString.Append(predictedCommand.GetArgName(j)); if (j + 1 < predictedCommand.ArgCount) { _currentString.Append(", "); } } } item.Text.text = _currentString.ToString(); float width = item.Text.GetPreferredValues().x + 10f; if (width > bestWidth) { bestWidth = width; } item.Image.canvasRenderer.cull = false; item.Text.canvasRenderer.cull = false; _currentString.Clear(); } itemSize.x = bestWidth; for (int i = 0; i < _predictionItems.Count; ++i) { _predictionItems[i].Rect.sizeDelta = itemSize; } }
/// <summary> /// Creates the Predictive Text Object as the last sibling /// </summary> private void CreatePredictionObject() { // Create Prediction Object GameObject predictionGO = Instantiate(_inputText.gameObject, _inputText.transform.parent); predictionGO.transform.SetAsLastSibling(); predictionGO.name = "TXT_Prediction"; _predictionText = predictionGO.GetComponent <TMPro.TextMeshProUGUI>(); SetPredictionText(""); _predictionTransform = (RectTransform)predictionGO.transform; _predictionText.color = _predictionTextColour; // Update its position UpdatePredictionObjectOffset(); // Calculate Max Prediction Items our root can hold. RectTransform itemRect = _predictionItemTemplate.transform as RectTransform; if (itemRect != null) { float itemSize = itemRect.sizeDelta.y; float rootSize = _predictionItemRoot.rect.size.y; int maxItems = Mathf.FloorToInt(rootSize / itemSize); _predictionItems = new List <PredictionItem>(maxItems); _predictionCommands = new List <ICommand>(maxItems + 1); for (int i = 0; i < maxItems; ++i) { PredictionItem item = Instantiate(_predictionItemTemplate, _predictionItemRoot); Color color = KDebug.GetVisualData.PrimaryColor; bool IsEven = i % 2 == 0; float alpha = IsEven ? 0.85f : 1f; color.a = alpha; item.BaseColor = color; item.Image.color = item.BaseColor; item.Text.color = KDebug.GetVisualData.PrimaryTextColor; item.gameObject.SetActive(true); _predictionItems.Add(item); } } else { _predictionCommands = new List <ICommand>(3); throw new NullReferenceException("Item Rect is null!"); } }
public async Task <ActionResult> DeletePrediction(int predictionId) { PredictionItem prediction = await _context.PredictionItems.FindAsync(predictionId); if (prediction == null) { return(NotFound($"Could not found Prediction with Id {predictionId}")); } _context.PredictionItems.Remove(prediction); await _context.SaveChangesAsync(); return(Ok()); }
private void ResetPredictionItems() { for (int i = 0; i < _predictionItems.Count; ++i) { PredictionItem item = _predictionItems[i]; item.Image.color = item.BaseColor; item.Image.canvasRenderer.cull = true; item.Text.canvasRenderer.cull = true; //item.gameObject.SetActive(false); item.Rect.sizeDelta = _predictionItemTemplate.Rect.sizeDelta; } _predictionCommands.Clear(); _selectedPredictionItem = 0; SelectPredictionItem(_selectedPredictionItem); }
private void SelectPredictionItem(int a_id) { // Deselect Previous PredictionItem item = GetPredictionItem(_selectedPredictionItem); if (item != null) { item.Image.color = item.BaseColor; } // Highlight new item = GetPredictionItem(a_id); if (item != null) { item.Image.color = KDebug.GetVisualData.SecondaryColor; _selectedPredictionItem = a_id; int predictedCommandCount = _predictionCommands.Count; if (predictedCommandCount > 0 && _selectedPredictionItem < predictedCommandCount) { ICommand command = _predictionCommands[_selectedPredictionItem]; if (command != null) { string input = _inputField.text; string[] inputStrings = input.Split(' '); string predictionText = command.Name.Substring(inputStrings[0].Length, command.Name.Length - inputStrings[0].Length); SetPredictionText(predictionText); _currentCommand = command; } } } else { _selectedPredictionItem = -1; } }