Пример #1
0
    public void CreateFilePromptInstance(NewCursorEntry entryForPrompt) // for deleting saved cursors
    {
        CursorSaveDeletePrompt promptClone = Instantiate(promptPrefab, transform) as CursorSaveDeletePrompt;

        promptClone.Initialize(
            entryForPrompt); // Passes a monobehaviour which is a component on a gameobject, allows us to get the InstanceID
    }
Пример #2
0
    public void OnClick_SelectCursorAs(int selection)
    {
        // 1 - normal, 2 - friendly, 3 - enemy
        if (curSelectedCursorEntry == null)
        {
            return;
        }

        switch (selection)
        {
        case 0:
            normalCursor = curSelectedCursorEntry;
            break;

        case 1:
            friendlyCursor = curSelectedCursorEntry;
            break;

        case 2:
            enemyCursor = curSelectedCursorEntry;
            break;
        }

        UpdateIFFCursorPreview(selection);
    }
Пример #3
0
    public void DeleteSavedCursor(NewCursorEntry cursorToDelete)
    {
        string path = Path.Combine(Application.dataPath, "Resources", cursorSaveFolderPathName,
                                   cursorToDelete.GetCursorName);

        if (deleteFiles)
        {
            NewCursorEntry removeEntry;

            if (savedCursors.Find(x => x.Equals(cursorToDelete))) // OVERLOAD == AT NEWCURSORENTRY NOOB
            {
                savedCursors.Remove(cursorToDelete);
            }

            if (removeEntry = cursorEntries.Find(x => x.Equals(cursorToDelete)))
            {
                removeEntry.SetSaveState(SaveState.NotSaved);
            }

            Destroy(cursorToDelete.gameObject);
            File.Delete(path);
            Debug.Log("Deleting file at path: " + path);
        }
        else
        {
            Debug.Log(File.Exists(path) + " | " + path + " | delete files: " + deleteFiles);
        }
    }
Пример #4
0
    private void ReloadCursorsFromSavedCursors()
    {
        foreach (NewCursorEntry savedEntry in savedCursors)
        {
            NewCursorEntry entry;

            if ((entry = cursorEntries.Find(x => x.SavedAsFileName == savedEntry.SavedAsFileName)) != null) // == precedes &&
            {
                // overload the == operator in NewCursorEntry instead
                // just reload it
                entry.SetCursorPreferences(savedEntry);
                entry.SetSaveState(SaveState.Saved);
            }
            else // re-create it i guess
            {
                // Debug.Log("Recreating");
                // Debug.Log(savedEntry.GetCursorName + " | " + savedEntry.GetCursorColor + " | " + savedEntry.GetCursorSprite.name);
                // Debug.Log(cursorEntries.Find(x => x.GetCursorName == savedEntry.GetCursorName && x.SavedAsFileName == savedEntry.SavedAsFileName));

                // Debug.Log(curCursorName + " | " + savedEntry.isSaveEntry + " | " + savedEntry.GetCursorName + " | " + savedEntry.SavedAsFileName);
                // 850 true 850 850
                NewCursorEntry
                    reloadedCursor =
                    CreateCursor();     // instantiates it, adds it to created cursors list, sets preferences and
                // on click but the sprite is created beforehand so this method isn't as resource heavy
                // check if a cursor with the same shit already exists
                // which is technically being done above?


                reloadedCursor.SavedAsFileName = savedEntry.SavedAsFileName;
                reloadedCursor.SetCursorPreferences(savedEntry);
                reloadedCursor.SetSaveState(SaveState.Saved);
            }
        }
    }
 public CursorSaveEntry(NewCursorEntry cursorEntry)
 {
     cursorColor   = cursorEntry.GetCursorColor;
     cursorName    = cursorEntry.GetCursorName;
     textureName   = cursorEntry.GetCursorTexture.name;
     textureItself = cursorEntry.GetCursorTexture;
     spriteItself  = cursorEntry.GetCursorSprite;
 }
    public void ReloadCursorImage()
    {
        NewCursorEntry entry = cursorMenu.NormalCursor;

        customCursorImage.sprite = entry.GetCursorSprite;
        customCursorImage.color  = entry.GetCursorColor;
        customCursorImage.name   = entry.GetCursorName;
    }
Пример #7
0
    public void OnClick_DeselectCursor()
    {
        curSelectedTexture      = null;
        curSelectedTextureEntry = null;
        curSelectedCursorEntry  = null;
        cursorColorPicker.color = cursorColorPicker.startingColor;

        curCursorName = "";

        selectedCursorName.text         = "N/A";
        selectedTextureName.text        = "";
        selectedTextureRawImage.texture = null;
        saveCursorButton.gameObject.SetActive(false);
    }
Пример #8
0
    private void LoadCursor(CursorSaveEntry saveEntry) // Load them into saved stuff
    {
        CursorTextureEntry cursorTexture = textureEntries.Find(x => x.GetTextureName == saveEntry.textureName);

        if (cursorTexture == null)
        {
            Debug.LogError("Can not find texture associated with save entry, texture name: " + saveEntry.textureName);
        }
        else
        {
            Input_CursorNameInput(saveEntry.cursorName);

            curSelectedTexture = cursorTexture.GetTexture;

            Sprite loadedCursorSprite = Sprite.Create(cursorTexture.GetTexture,
                                                      new Rect(0f, 0f, curSelectedTexture.width, curSelectedTexture.height), new Vector2(0.5f, 0.5f),
                                                      pixelsPerUnit);

            // cursorColorPicker.color is throwing an error
            // how f****n fun
            cursorColorPicker.color = saveEntry.cursorColor;
            cursorPreview.sprite    = loadedCursorSprite;

            OnClick_PreviewCursor();

            NewCursorEntry loadedCursor = CreateCursor(false); // Change this to a create method instead?
            loadedCursor.SetSaveState(SaveState.Saved);
            loadedCursor.SavedAsFileName = saveEntry.cursorName;
            loadedCursor.isSaveEntry     = false; // THIS IS THE NORMAL F*****G CURSOR

            #region Creating cursorEntry for savedList, perhaps add an overload for CreateCursor instead?

            NewCursorEntry savedCursor = Instantiate(loadedCursor, savedCursorListContent);
            savedCursor.SetCursorPreferences(loadedCursor);
            savedCursor.SetSaveState(SaveState.Saved);
            savedCursor.isSaveEntry = true; // THIS IS THE F*****G SAVED CURSOR

            Button loadedEntryButton = savedCursor.GetComponent <Button>();
            loadedEntryButton.onClick.AddListener(() => OnClick_SelectCursor(savedCursor));

            #endregion

            if (!savedCursors.Contains(savedCursor))
            {
                savedCursors.Add(savedCursor);
            }
        }
    }
Пример #9
0
    public void JsonSerialize(NewCursorEntry entry) // perhaps rename to savetofile or smth since it doesn't just serialize it but
    {                                               // saves it completely? maybe factorize the method too?
        // Check if it has a previous file name, if it does rename that file to the new name
        string fileName     = entry.GetCursorName;
        string saveFileName = entry.SavedAsFileName == null ? "" : entry.SavedAsFileName;
        string newFileName  = entry.GetCursorName == null ? "" : entry.GetCursorName;

        if (entry.SavedAsFileName != "")
        {
            if (entry.SavedAsFileName != entry.GetCursorName)
            {
                // if the file name isnt the same as the cursor name we have to
                // rename the file to the new cursor name

                // argumentNullException ???
                string oldFilePath = Path.Combine(folderPath, saveFileName); // this returns a null exception
                // because savedAsFileName is empty
                // WHY DOES THIS THROW AN EXCEPTION LOL
                string newFilePath = Path.Combine(folderPath, newFileName);

                if (File.Exists(oldFilePath)) // if it exists rename it, otherwise who cares since
                {                             // it'll just be created again
                    File.Move(oldFilePath, newFilePath);
                }
            }
        }

        CursorSaveEntry saveEntry = new CursorSaveEntry(entry);
        string          json      = JsonUtility.ToJson(saveEntry);
        string          filePath  = Path.Combine(folderPath, entry.GetCursorName);

        if (File.Exists(filePath))
        {
            File.WriteAllText(filePath, json);
        }
        else
        {
            FileStream fileStream = File.Create(filePath);
            fileStream.Close();

            File.WriteAllText(filePath, json);
        }

#if UNITY_EDITOR
        UnityEditor.AssetDatabase.Refresh();
        Debug.Log(json + "\n------------------------------------------");
#endif
    }
Пример #10
0
    private void LoadCursorSave(CursorSaveEntry saveEntry) // Load it into save only
    {
        CursorTextureEntry cursorTexture = textureEntries.Find(x => x.GetTextureName == saveEntry.textureName);

        if (cursorTexture == null)
        {
            Debug.LogError("Can not find texture associated with save entry, texture name: " + saveEntry.textureName);
        }
        else
        {
            Input_CursorNameInput(saveEntry.cursorName);

            curSelectedTexture = cursorTexture.GetTexture;

            Sprite loadedCursorSprite = Sprite.Create(cursorTexture.GetTexture,
                                                      new Rect(0f, 0f, curSelectedTexture.width, curSelectedTexture.height), new Vector2(0.5f, 0.5f),
                                                      pixelsPerUnit);

            // cursorColorPicker.color is throwing an error
            // how f****n fun
            cursorColorPicker.color = saveEntry.cursorColor;
            cursorPreview.sprite    = loadedCursorSprite;

            OnClick_PreviewCursor(); // should work? no?

            NewCursorEntry savedCursor = CreateCursor(true);
            savedCursor.transform.SetParent(savedCursorListContent);
            savedCursor.SetCursorPreferences(savedCursor);
            savedCursor.SetSaveState(SaveState.Saved);
            savedCursor.SavedAsFileName = saveEntry.cursorName;
            savedCursor.isSaveEntry     = true; // THIS IS THE F*****G SAVED CURSOR

            Button loadedEntryButton = savedCursor.GetComponent <Button>();
            loadedEntryButton.onClick.AddListener(() => OnClick_SelectCursor(savedCursor));

            if (!savedCursors.Contains(savedCursor)) // do this beforef
            {
                savedCursors.Add(savedCursor);
            }
        }
    }
Пример #11
0
    // Create an instance via prefab in cursormenucontroller and it initializes it with the instance id of the cursor

    public void Initialize(NewCursorEntry newCursor)
    {
        cursorEntry.SetCursorPreferences(newCursor);
        cursorEntryToDelete = newCursor;
    }
Пример #12
0
    public void OnClick_SelectCursor(NewCursorEntry entry)
    {
        if (!Input.GetKey(KeyCode.LeftControl) || entry.isSaveEntry) // perhaps be able to select multiple entries?
        {
            if (curSelectedCursorEntry)
            {
                curSelectedCursorEntry.GetComponent <Image>().color = Color.white;
            }

            ClearCursorSelectedEntries();
        }

        curSelectedCursorEntry = entry;
        curSelectedCursorEntry.GetComponent <Image>().color = Color.green;

        if (!selectedCursorEntryList.Contains(curSelectedCursorEntry))
        {
            if (!Input.GetKey(KeyCode.LeftControl))
            {
                if (selectedCursorEntryList.Count > 0)
                {
                    ClearCursorSelectedEntries();
                }
            }

            selectedCursorEntryList.Add(entry);
        }

        selectedTextureRawImage.texture = entry.GetCursorTexture;
        selectedTextureName.text        = entry.GetCursorTexture.name;
        cursorColorPicker.color         = entry.GetCursorColor;
        selectedCursorName.text         = entry.GetCursorName;

        curCursorName           = entry.GetCursorName;
        cursorColorPicker.color = entry.GetCursorColor;
        curSelectedTexture      = entry.GetCursorTexture;

        saveCursorButton.gameObject.SetActive(true);

        //if (Input.GetKey(KeyCode.LeftControl))
        //{
        //    if (selectedCursorEntryList.Contains(entry))
        //    {
        //        entry.GetComponent<Image>().color = Color.white;
        //        Debug.Log("Deslected " + entry.name);
        //        selectedCursorEntryList.Remove(entry);
        //    }
        //    else // Not found in queue
        //    {
        //        entry.GetComponent<Image>().color = Color.green;
        //        Debug.Log("Selected " + entry.name);
        //        selectedCursorEntryList.Add(entry);
        //    }
        //}
        //else
        //{
        //    ClearCursorSelectedEntries();
        //}

        // Debug.Log("selecto");

        OnClick_PreviewCursor();
    }
Пример #13
0
 private void SaveCursorEntryToFile(NewCursorEntry entry)
 {
     cursorSaveLoadUtility.JsonSerialize(entry);
     entry.SetSaveState(SaveState.Saved);
     entry.SavedAsFileName = entry.GetCursorName;
 }