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 } } } }
IEnumerator DownloadWordPictures(string word) { Debug.Log("starting picture download for " + word); string[] urls = { "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "1.png", "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "2.png", "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "3.png", "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "4.png", "https://matthewriddett.com/static/mludlc/pictures/" + word + "/" + word + "5.png" }; foreach (string url in urls) { using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(url)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Texture2D myTexture = ((DownloadHandlerTexture)www.downloadHandler).texture; controller.SetCurrentTexture(myTexture); if (controller.IsTextureSet()) { controller.AddNewTexture(); } myTexture = null; } } } controller.SaveNewWord(tempWordName, tempWordTags); Debug.Log("Done downloading word: " + tempWordName); controller.ClearTextureList(); doneImageDownload = true; }