コード例 #1
0
    public void Save()
    {
        string word;

        if (controller.IsEditSettings) // if the word is being edited (i.e. not new)
        {
            // Check if any changes have been made.
            if (controller.GetCurrentClip() == null && controller.GetImages().Count == 0 && !imageDeleted && (wordTags == wordTagsOriginal))
            {
                loadingAnimPanel.SetActive(false);
                textModal.transform.GetChild(0).GetComponent <Text>().text = MODAL_NO_EDITS;
                EnableErrorModal();
                return;
            }

            word = controller.GetTargetWord();

            if (controller.SaveWordEdits(word, wordTags) || imageDeleted)
            {
                textModal.transform.GetChild(0).GetComponent <Text>().text = string.Format(MODAL_EDIT_TEXT, TidyCase(word));
                loadingAnimPanel.SetActive(false);
                EnableEditModal();
            }
            else
            {
                Debug.Log("VW: There was an error!");
                loadingAnimPanel.SetActive(false);
                EnableErrorModal();
                textModal.transform.GetChild(0).GetComponent <Text>().text = string.Format(MODAL_MISSING_DATA);
            }
        }
        else // the word is new (i.e. not an existing word being edited)
        {
            word = controller.GetTargetWord();

            if (controller.DoesDbEntryExist(word))
            {
                loadingAnimPanel.SetActive(false);
                textModal.transform.GetChild(0).GetComponent <Text>().text = word + " already exists\n\n(Click to try again)";
                EnableErrorModal();
            }
            else
            {
                if (controller.SaveNewWord(word, wordTags) || imageDeleted)
                {
                    //Handle UI changes to notify success and set-up popup for additional options
                    textModal.transform.GetChild(0).GetComponent <Text>().text = string.Format(MODAL_ADD_TEXT, TidyCase(word));
                    loadingAnimPanel.SetActive(false);
                    EnableAddModal();
                }
                else
                {
                    textModal.transform.GetChild(0).GetComponent <Text>().text = "Something went horribly wrong";
                    loadingAnimPanel.SetActive(false);
                    EnableErrorModal();
                    // TODO: add proper error handling
                }
            }
        }
    }