Beispiel #1
0
    public List <baseGroceryItemSO> SearchCategoriesSTT(string sentence)
    {
        Dictionary <baseGroceryItemSO.GROCERY_ID, baseGroceryItemSO> groceryList = GroceryItemDatabase.Instance.GetGroceryScriptableObjectDict();

        List <baseGroceryItemSO> groceryWithKeyWords = new List <baseGroceryItemSO>();

        foreach (KeyValuePair <baseGroceryItemSO.GROCERY_ID, baseGroceryItemSO> entry in groceryList)
        {
            baseGroceryItemSO groceryItem = entry.Value;
            if (groceryItem == null)
            {
                continue;
            }

            List <string> groceryKeyword = groceryItem.GetKeywordsString();
            foreach (string keyword in groceryKeyword)
            {
                if (sentence.Contains(keyword))
                {
                    groceryWithKeyWords.Add(groceryItem);
                    break;
                }
            }
        }

        return(groceryWithKeyWords);
    }
Beispiel #2
0
    public void SetNewItemDetail(baseGroceryItemSO.GROCERY_ID newItemID)
    {
        baseGroceryItemSO newItem = GroceryItemDatabase.Instance.GetGroceryItem(newItemID);

        currentItem = newItem;

        m_ItemName.text    = newItem.GetItemName();
        m_ItemPrice.text   = "$" + newItem.GetItemPrice().ToString();
        m_ItemImage.sprite = newItem.GetItemImage();

        if (!newItem.IsItemEdible())
        {
            m_ItemNutritionParent.SetActive(false);
            m_ItemDietary.gameObject.SetActive(false);
            return;
        }
        if (!newItem.IsItemHalal() && !newItem.IsItemHealthierChoice())
        {
            m_ItemDietary.gameObject.SetActive(false);
        }
        else
        {
            m_ItemDietary.SetHalal(newItem.IsItemHalal());
            m_ItemDietary.SetHealhier(newItem.IsItemHealthierChoice());
        }

        m_ItemEnergy.text       = newItem.GetNutrition_Energy().ToString() + "kcal";
        m_ItemTransfat.text     = newItem.GetNutrition_TransFat().ToString() + "g";
        m_ItemSaturatedFat.text = newItem.GetNutrition_SaturatedFat().ToString() + "g";
        m_ItemCholesterol.text  = newItem.GetNutrition_Cholesterol().ToString() + "mg";
        m_ItemSodium.text       = newItem.GetNutrition_Sodium().ToString() + "mg";
        m_ItemProtein.text      = newItem.GetNutrition_Protein().ToString() + "g";
        m_ItemCarbohydrate.text = newItem.GetNutrition_Carbohydrate().ToString() + "g";
        m_ItemDietaryFibre.text = newItem.GetNutrition_DietaryFibre().ToString() + "g";
    }
Beispiel #3
0
    public void Init(baseGroceryItemSO.GROCERY_ID groceryID)
    {
        m_GroceryID = groceryID;

        baseGroceryItemSO groceryInfo = GroceryItemDatabase.Instance.GetGroceryItem(m_GroceryID);

        m_GroceryImage.sprite = groceryInfo.GetItemImage();
        m_GorceryName.text    = groceryInfo.GetItemName();
    }
Beispiel #4
0
    public void AssignSO(baseGroceryItemSO scriptableObject)
    {
        if (m_SOReference != null)
        {
            return;
        }
        m_SOReference = scriptableObject;

        m_ItemCounter = 1;
        UpdateTextCounter();
        m_ItemNameText.text = m_SOReference.GetItemName();
        m_ItemImage.sprite  = m_SOReference.GetItemImage();
    }
Beispiel #5
0
    public void Init(baseGroceryItemSO groceryItem)
    {
        if (groceryItem == null)
        {
            return;
        }

        // Set up the prefab
        m_ItemName.GetComponent <TextMeshProUGUI>().text = groceryItem.GetItemName();
        m_ItemImage.GetComponent <Image>().sprite        = groceryItem.GetItemImage();

        // Store the grocery item data
        itemData = groceryItem;
    }
Beispiel #6
0
    public void ToggleCanvas(bool newValue)
    {
        m_CanvasCom.enabled = newValue;

        //// If it came from the home UI
        //if (HomeUI.Instance.currentScene == App_Scenes.HomeUI)
        //{

        //}
        //// if it came from search UI
        //else if (HomeUI.Instance.currentScene == App_Scenes.Search)
        //{

        //}

        // closing the page
        if (newValue == false)
        {
            currentItem = null;
        }
    }
Beispiel #7
0
    public List <baseGroceryItemSO> SearchGroceriesSTT(string sentence)
    {
        Dictionary <baseGroceryItemSO.GROCERY_ID, baseGroceryItemSO> groceryList = GroceryItemDatabase.Instance.GetGroceryScriptableObjectDict();

        List <baseGroceryItemSO> groceryWithKeyWords = new List <baseGroceryItemSO>();

        foreach (KeyValuePair <baseGroceryItemSO.GROCERY_ID, baseGroceryItemSO> entry in groceryList)
        {
            baseGroceryItemSO groceryItem = entry.Value;
            if (groceryItem == null)
            {
                continue;
            }

            string groceryName = groceryItem.GetItemName().ToLower();
            if (sentence.Contains(groceryName.ToLower()))
            {
                groceryWithKeyWords.Add(groceryItem);
            }
        }

        return(groceryWithKeyWords);
    }
Beispiel #8
0
 public void OpenItemDetails(baseGroceryItemSO itemData)
 {
     ToggleCanvas(true);
     SetNewItemDetail(itemData.GetEnumID());
     //HomeUI.Instance.currentScene = App_Scenes.ItemCanvas;
 }
Beispiel #9
0
    private void Update()
    {
        switch (currState) //OnStateUpdate
        {
        case FlowStates.state_travelRestrictions:
            if (speechToText.text.Contains("yes") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_whatTravelRestrictions);
            }
            else if (speechToText.text.Contains("no") && speechToText.text.Contains("Final"))
            {
                mWillingToTravel = -1;
                ChangeState(FlowStates.state_dietryRestrictions);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_whatTravelRestrictions:
            if (char.IsDigit(speechToText.text[0]) && speechToText.text.Contains("Final"))
            {
                string tempDigit = "";
                foreach (char c in speechToText.text)
                {
                    if (char.IsDigit(c))
                    {
                        tempDigit += c;
                    }
                    else
                    {
                        break;
                    }
                }
                mWillingToTravel = int.Parse(tempDigit);
                ChangeState(FlowStates.state_dietryRestrictions);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_dietryRestrictions:
            if (speechToText.text.Contains("hello") && speechToText.text.Contains("Final"))     //halal is detected as hello in the ibm stt
            {
                amHalal = true;
                ChangeState(FlowStates.state_confirmSettings);
            }
            else if (speechToText.text.Contains("no") && speechToText.text.Contains("Final"))
            {
                amHalal = false;
                ChangeState(FlowStates.state_confirmSettings);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_confirmSettings:
            if (speechToText.text.Contains("yes") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_addItems);
            }
            else if (speechToText.text.Contains("no") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_travelRestrictions);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_addItems:
            if (!waitingOnResponse)
            {
                List <baseGroceryItemSO> itemsByName     = ItemFinder.Instance.SearchGroceriesSTT(speechToText.text);
                List <baseGroceryItemSO> itemsByCategory = ItemFinder.Instance.SearchCategoriesSTT(speechToText.text);
                List <baseGroceryItemSO> itemsSearched   = new List <baseGroceryItemSO>();


                foreach (baseGroceryItemSO item in itemsByName)
                {
                    foreach (baseGroceryItemSO categoryItem in itemsByCategory)
                    {
                        if (categoryItem == item)
                        {
                            if (amHalal && !item.IsItemHalal())
                            {
                                continue;
                            }
                            itemsSearched.Add(item);
                        }
                    }
                }
                if (itemsSearched.Count == 0)
                {
                    foreach (baseGroceryItemSO item in itemsByName)
                    {
                        if (amHalal && !item.IsItemHalal())
                        {
                            continue;
                        }
                        itemsSearched.Add(item);
                    }
                    foreach (baseGroceryItemSO item in itemsByCategory)
                    {
                        if (amHalal && !item.IsItemHalal())
                        {
                            continue;
                        }
                        itemsSearched.Add(item);
                    }
                }
                if (itemsSearched.Count == 0)
                {
                    speechToText.text = "";
                    TTSManager.Instance.TextToSpeech("Sorry, I could not find any matches from your search, please try again.");
                }
                else if (itemsSearched.Count == 1)
                {
                    itemSearched = itemsSearched[0];
                    ChangeState(FlowStates.state_verifyItems);
                }
                else
                {
                    string temp = "I have found multiple items";
                    foreach (baseGroceryItemSO item in itemsSearched)
                    {
                        temp += ". ";
                        temp += item.GetItemName();
                    }
                    temp += ". Which item would you like? You can also search for something else if you'd like.";
                    TTSManager.Instance.TextToSpeech(temp);
                }
                waitingOnResponse = true;
                speechToText.text = "default";
            }
            else if (speechToText.text.Contains("Final"))
            {
                waitingOnResponse = false;
            }
            break;

        case FlowStates.state_verifyItems:
            if (char.IsDigit(speechToText.text[0]) && speechToText.text.Contains("Final"))
            {
                string tempDigit = "";
                foreach (char c in speechToText.text)
                {
                    if (char.IsDigit(c))
                    {
                        tempDigit += c;
                    }
                    else
                    {
                        break;
                    }
                }
                amountBought = int.Parse(tempDigit);

                // If they bought more than 1 item
                if (amountBought > 1)
                {
                    // Add it for how many times they wanted it
                    for (int i = 0; i < amountBought; ++i)
                    {
                        ShoppingCart.Instance.AddItem(itemSearched.GetEnumID());
                    }
                }
                else
                {
                    // They only wanted one
                    ShoppingCart.Instance.AddItem(itemSearched.GetEnumID());
                }

                //add amountBought amount of itemSearched into cart (function)
                itemSearched.SetAmountInCart(amountBought);
                itemsBought.Add(itemSearched);
                //Hardcode
                if (itemSearched.GetItemName() == "Milk")
                {
                    milkBought = true;
                }
                ChangeState(FlowStates.state_continueOrCheckout);
            }
            else if (speechToText.text.Contains("one") && speechToText.text.Contains("Final"))
            {
                itemSearched.SetAmountInCart(1);
                itemsBought.Add(itemSearched);
                //Hardcode
                if (itemSearched.GetItemName() == "Milk")
                {
                    milkBought = true;
                }
                ChangeState(FlowStates.state_continueOrCheckout);
            }
            else if (speechToText.text.Contains("no") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_addItems);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_continueOrCheckout:
            if (speechToText.text.Contains("yes") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_addItems);
            }
            else if (speechToText.text.Contains("no") && speechToText.text.Contains("Final"))
            {
                // Open up the cart page here
                ShoppingCart.Instance.ToggleCartView();

                ChangeState(FlowStates.state_verifyCart);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_verifyCart:
            if (speechToText.text.Contains("yes") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_addOrRemove);
            }
            else if (speechToText.text.Contains("no") && speechToText.text.Contains("Final"))
            {
                // Change to Store Selective
                ShoppingCart.Instance.SelectStorePressed();

                ChangeState(FlowStates.state_storeSuggestion);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_addOrRemove:
            if (speechToText.text.Contains("add") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_addItems);
            }
            else if (speechToText.text.Contains("remove") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_removeItems);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_removeItems:
            if (!waitingOnResponse)
            {
                List <baseGroceryItemSO> itemsByName     = SearchGroceriesFromCartSTT(speechToText.text);
                List <baseGroceryItemSO> itemsByCategory = SearchCategoriesFromCartSTT(speechToText.text);
                List <baseGroceryItemSO> itemsSearched   = new List <baseGroceryItemSO>();

                foreach (baseGroceryItemSO item in itemsByName)
                {
                    foreach (baseGroceryItemSO categoryItem in itemsByCategory)
                    {
                        if (categoryItem == item)
                        {
                            itemsSearched.Add(item);
                        }
                    }
                }
                if (itemsSearched.Count == 0)
                {
                    itemsSearched = itemsByName;
                    foreach (baseGroceryItemSO item in itemsByCategory)
                    {
                        itemsSearched.Add(item);
                    }
                }
                if (itemsSearched.Count == 0)
                {
                    speechToText.text = "";
                    TTSManager.Instance.TextToSpeech("Sorry, I could not find any matches from your search, please try again.");
                }
                else if (itemsSearched.Count == 1)
                {
                    itemSearched = itemsSearched[0];
                    ChangeState(FlowStates.state_verifyRemoveItems);
                }
                else
                {
                    string temp = "I have found multiple items";
                    foreach (baseGroceryItemSO item in itemsSearched)
                    {
                        temp += ". ";
                        temp += item.GetItemName();
                    }
                    temp += ". Which item would you like to remove? You can also search for something else if you'd like.";
                    TTSManager.Instance.TextToSpeech(temp);
                }
                waitingOnResponse = true;
                speechToText.text = "default";
            }
            else if (speechToText.text.Contains("Final"))
            {
                waitingOnResponse = false;
            }
            break;

        case FlowStates.state_verifyRemoveItems:
            if (char.IsDigit(speechToText.text[0]) && speechToText.text.Contains("Final"))
            {
                string tempDigit = "";
                foreach (char c in speechToText.text)
                {
                    if (char.IsDigit(c))
                    {
                        tempDigit += c;
                    }
                    else
                    {
                        break;
                    }
                }
                amountBought = int.Parse(tempDigit);
                //remove amountBought amount of itemSearched into cart (function)
                itemSearched.SetAmountInCart(itemSearched.GetAmountInCart() - amountBought);
                if (itemSearched.GetAmountInCart() <= 0)
                {
                    itemsBought.Remove(itemSearched);
                    //Hardcode
                    if (itemSearched.GetItemName() == "Milk")
                    {
                        milkBought = false;
                    }
                }
                ChangeState(FlowStates.state_verifyCart);
            }
            else if (speechToText.text.Contains("one") && speechToText.text.Contains("Final"))
            {
                //remove amountBought amount of itemSearched into cart (function)
                itemSearched.SetAmountInCart(itemSearched.GetAmountInCart() - 1);
                if (itemSearched.GetAmountInCart() <= 0)
                {
                    itemsBought.Remove(itemSearched);
                    //Hardcode
                    if (itemSearched.GetItemName() == "Milk")
                    {
                        milkBought = false;
                    }
                }
                ChangeState(FlowStates.state_verifyCart);
            }
            else if (speechToText.text.Contains("no") && speechToText.text.Contains("Final"))
            {
                ChangeState(FlowStates.state_removeItems);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_storeSuggestion:
            if (speechToText.text.Contains("prime") && speechToText.text.Contains("Final"))
            {
                //function to plan route
                //Hardcode
                nexChosen = false;
                ChangeState(FlowStates.state_planRoute);
            }
            else if (speechToText.text.Contains("next") && speechToText.text.Contains("Final"))     //nex is not a word, next is closest
            {
                //function to plan route
                //Hardcode
                nexChosen = true;
                ChangeState(FlowStates.state_planRoute);
            }
            else if ((speechToText.text.Contains("repeat") || speechToText.text.Contains("again")) && speechToText.text.Contains("Final"))
            {
                ChangeState(currState);
            }
            break;

        case FlowStates.state_planRoute:
            break;

        default:
            break;
        }
    }