Esempio n. 1
0
    private IEnumerator LaunchMod()
    {
        // First: make sure the mod is still here and can be opened
        if (!new DirectoryInfo(Path.Combine(FileLoader.DataRoot, "Mods/" + modDirs[CurrentSelectedMod].Name + "/Lua/Encounters/")).Exists ||
            !File.Exists(Path.Combine(FileLoader.DataRoot, "Mods/" + modDirs[CurrentSelectedMod].Name + "/Lua/Encounters/" + StaticInits.ENCOUNTER + ".lua")))
        {
            HandleErrors();
            yield break;
        }

        // Dim the background to indicate loading
        ModBackground.GetComponent <Image>().color = new Color(1f, 1f, 1f, 0.1875f);

        // Store the current position of the scrolly bit
        encounterListScroll = content.GetComponent <RectTransform>().anchoredPosition.y;

        yield return(new WaitForEndOfFrame());

        StaticInits.Initialized = false;
        try {
            StaticInits.InitAll(true);
            if (UnitaleUtil.firstErrorShown)
            {
                throw new Exception();
            }
            Debug.Log("Loading " + StaticInits.ENCOUNTER);
            GlobalControls.isInFight = true;
            DiscordControls.StartBattle(modDirs[CurrentSelectedMod].Name, StaticInits.ENCOUNTER);
            SceneManager.LoadScene("Battle");
        } catch (Exception e) {
            ModBackground.GetComponent <Image>().color = new Color(1f, 1f, 1f, 0.25f);
            Debug.LogError("An error occured while loading a mod:\n" + e.Message + "\n\n" + e.StackTrace);
        }
    }
Esempio n. 2
0
    // Goes to the next or previous mod with a little scrolling animation.
    // -1 for left, 1 for right
    private void ScrollMods(int dir)
    {
        // First, determine if the next mod should be shown
        bool animate = modDirs.Count > 1;

        //if ((dir == -1 && CurrentSelectedMod > 0) || (dir == 1 && CurrentSelectedMod < modDirs.Count - 1)) {

        // If the new mod is being shown, start the animation!
        if (!animate)
        {
            return;
        }
        animationTimer = dir / 10f;
        animationDone  = false;

        // Enable the "ANIM" assets
        AnimContainer.SetActive(true);
        AnimContainer.transform.localPosition               = new Vector2(0, 0);
        AnimModBackground.GetComponent <Image>().sprite     = ModBackground.GetComponent <Image>().sprite;
        AnimModTitleShadow.GetComponent <Text>().text       = ModTitleShadow.GetComponent <Text>().text;
        AnimModTitle.GetComponent <Text>().text             = ModTitle.GetComponent <Text>().text;
        AnimEncounterCountShadow.GetComponent <Text>().text = EncounterCountShadow.GetComponent <Text>().text;
        AnimEncounterCount.GetComponent <Text>().text       = EncounterCount.GetComponent <Text>().text;

        // Move all real assets to the side
        ModBackground.transform.Translate(640 * dir, 0, 0);
        ModTitleShadow.transform.Translate(640 * dir, 0, 0);
        ModTitle.transform.Translate(640 * dir, 0, 0);
        EncounterCountShadow.transform.Translate(640 * dir, 0, 0);
        EncounterCount.transform.Translate(640 * dir, 0, 0);

        // Actually choose the new mod
        CurrentSelectedMod = (CurrentSelectedMod + dir) % modDirs.Count;
        if (CurrentSelectedMod < 0)
        {
            CurrentSelectedMod += modDirs.Count;
        }

        ShowMod(CurrentSelectedMod);
    }
Esempio n. 3
0
    // Opens the scrolling interface and lets the user browse their mods.
    private void modFolderMiniMenu()
    {
        // Hide the mod list button
        btnList.SetActive(false);

        // Automatically select the current mod when the mod list appears
        selectedItem = CurrentSelectedMod + 1;

        // Give the back button its function
        GameObject back = content.transform.Find("Back").gameObject;

        back.GetComponent <Button>().onClick.RemoveAllListeners();
        back.GetComponent <Button>().onClick.AddListener(() => {
            // Reset the encounter box's position
            modListScroll = 0.0f;
            modFolderSelection();
        });

        // Make clicking the background exit this menu
        ModBackground.GetComponent <Button>().onClick.RemoveAllListeners();
        ModBackground.GetComponent <Button>().onClick.AddListener(() => {
            if (!animationDone)
            {
                return;
            }
            // Store the encounter box's position so it can be remembered upon exiting a mod
            modListScroll = content.GetComponent <RectTransform>().anchoredPosition.y;
            modFolderSelection();
        });
        // Show the encounter selection box
        encounterBox.SetActive(true);
        // Move the encounter box to the stored position, for easier mod browsing
        content.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, modListScroll);

        int count = -1;

        foreach (DirectoryInfo mod in modDirs)
        {
            count += 1;

            // Create a button for each mod
            GameObject button = Instantiate(back);

            //set parent and name
            button.transform.SetParent(content.transform);
            button.name = "ModButton";

            //set position
            button.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 100 - (count + 1) * 30);

            //set color
            button.GetComponent <Image>().color                        = new Color(0.75f, 0.75f, 0.75f, 0.5f);
            button.GetComponent <MenuButton>().NormalColor             = new Color(0.75f, 0.75f, 0.75f, 0.5f);
            button.GetComponent <MenuButton>().HoverColor              = new Color(0.75f, 0.75f, 0.75f, 1f);
            button.transform.Find("Fill").GetComponent <Image>().color = new Color(0.5f, 0.5f, 0.5f, 0.5f);

            //set text
            button.transform.Find("Text").GetComponent <Text>().text = mod.Name;
            if (GlobalControls.crate)
            {
                button.transform.Find("Text").GetComponent <Text>().text = Temmify.Convert(mod.Name, true);
            }

            //finally, set function!
            int tempCount = count;

            button.GetComponent <Button>().onClick.RemoveAllListeners();
            button.GetComponent <Button>().onClick.AddListener(() => {
                // Store the encounter box's position so it can be remembered upon exiting a mod
                modListScroll = content.GetComponent <RectTransform>().anchoredPosition.y;

                CurrentSelectedMod = tempCount;
                modFolderSelection();
                ShowMod(CurrentSelectedMod);
            });
        }
    }
Esempio n. 4
0
    // Shows the list of available encounters in a mod.
    private void encounterSelection()
    {
        //hide the mod list button
        btnList.SetActive(false);

        //automatically choose "back"
        selectedItem = 0;

        // Make clicking the background exit the encounter selection screen
        ModBackground.GetComponent <Button>().onClick.RemoveAllListeners();
        ModBackground.GetComponent <Button>().onClick.AddListener(() => {
            if (animationDone)
            {
                modFolderSelection();
            }
        });
        //show the encounter selection box
        encounterBox.SetActive(true);
        //reset the encounter box's position
        content.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0);

        //give the back button its function
        GameObject back = content.transform.Find("Back").gameObject;

        back.GetComponent <Button>().onClick.RemoveAllListeners();
        back.GetComponent <Button>().onClick.AddListener(modFolderSelection);

        DirectoryInfo di = new DirectoryInfo(Path.Combine(FileLoader.DataRoot, "Mods/" + StaticInits.MODFOLDER + "/Lua/Encounters"));

        if (!di.Exists || di.GetFiles().Length <= 0)
        {
            return;
        }
        FileInfo[] encounterFiles = di.GetFiles("*.lua");

        int count = 0;

        foreach (FileInfo encounter in encounterFiles)
        {
            count += 1;

            //create a button for each encounter file
            GameObject button = Instantiate(back);

            //set parent and name
            button.transform.SetParent(content.transform);
            button.name = "EncounterButton";

            //set position
            button.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 100 - count * 30);

            //set color
            button.GetComponent <Image>().color                        = new Color(0.75f, 0.75f, 0.75f, 0.5f);
            button.GetComponent <MenuButton>().NormalColor             = new Color(0.75f, 0.75f, 0.75f, 0.5f);
            button.GetComponent <MenuButton>().HoverColor              = new Color(0.75f, 0.75f, 0.75f, 1f);
            button.transform.Find("Fill").GetComponent <Image>().color = new Color(0.5f, 0.5f, 0.5f, 0.5f);

            // set text
            button.transform.Find("Text").GetComponent <Text>().text = Path.GetFileNameWithoutExtension(encounter.Name);
            if (GlobalControls.crate)
            {
                button.transform.Find("Text").GetComponent <Text>().text = Temmify.Convert(Path.GetFileNameWithoutExtension(encounter.Name), true);
            }

            //finally, set function!
            string filename = Path.GetFileNameWithoutExtension(encounter.Name);

            int tempCount = count;

            button.GetComponent <Button>().onClick.RemoveAllListeners();
            button.GetComponent <Button>().onClick.AddListener(() => {
                selectedItem          = tempCount;
                StaticInits.ENCOUNTER = filename;
                StartCoroutine(LaunchMod());
            });
        }
    }
Esempio n. 5
0
    // Used to animate scrolling left or right.
    private void Update()
    {
        // Animation updating section
        if (AnimContainer.activeSelf)
        {
            animationTimer = animationTimer > 0 ? Mathf.Floor(animationTimer + 1) : Mathf.Ceil(animationTimer - 1);

            int distance = (int)((20 - Mathf.Abs(animationTimer)) * 3.4 * -Mathf.Sign(animationTimer));

            AnimContainer.transform.Translate(distance, 0, 0);
            ModContainer.transform.Translate(distance, 0, 0);

            if (Mathf.Abs(animationTimer) == 20)
            {
                AnimContainer.SetActive(false);

                // Manual movement because I can't change the movement multiplier to a precise enough value
                ModContainer.transform.Translate((int)(2 * -Mathf.Sign(animationTimer)), 0, 0);

                animationTimer = 0;
                animationDone  = true;
            }
        }

        // Prevent scrolling too far in the encounter box
        if (encounterBox.activeSelf)
        {
            if (content.GetComponent <RectTransform>().anchoredPosition.y < -200)
            {
                content.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, -200);
            }
            else if (content.GetComponent <RectTransform>().anchoredPosition.y > (content.transform.childCount - 1) * 30)
            {
                content.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, (content.transform.childCount - 1) * 30);
            }
        }

        // Detect hovering over the Exit button and handle fading
        if (ScreenResolution.mousePosition.x / ScreenResolution.displayedSize.x * 640 < 70 && Input.mousePosition.y / ScreenResolution.displayedSize.y * 480 > 450 && ExitButtonAlpha < 1f)
        {
            ExitButtonAlpha += 0.05f;
            ExitText.color   = new Color(1f, 1f, 1f, ExitButtonAlpha);
            ExitShadow.color = new Color(0f, 0f, 0f, ExitButtonAlpha);
        }
        else if (ExitButtonAlpha > 0.5f)
        {
            ExitButtonAlpha -= 0.05f;
            ExitText.color   = new Color(1f, 1f, 1f, ExitButtonAlpha);
            ExitShadow.color = new Color(0f, 0f, 0f, ExitButtonAlpha);
        }

        // Detect hovering over the Options button and handle fading
        if (GlobalControls.modDev)
        {
            if (ScreenResolution.mousePosition.x / ScreenResolution.displayedSize.x * 640 > 550 && Input.mousePosition.y / ScreenResolution.displayedSize.y * 480 > 450 && OptionsButtonAlpha < 1f)
            {
                OptionsButtonAlpha += 0.05f;
                OptionsText.color   = new Color(1f, 1f, 1f, OptionsButtonAlpha);
                OptionsShadow.color = new Color(0f, 0f, 0f, OptionsButtonAlpha);
            }
            else if (OptionsButtonAlpha > 0.5f)
            {
                OptionsButtonAlpha -= 0.05f;
                OptionsText.color   = new Color(1f, 1f, 1f, OptionsButtonAlpha);
                OptionsShadow.color = new Color(0f, 0f, 0f, OptionsButtonAlpha);
            }
        }

        // Controls:

        ////////////////// Main: ////////////////////////////////////
        //    Z or Return: Start encounter (if mod has only one    //
        //                 encounter), or open encounter list      //
        //     Shift or X: Return to Disclaimer screen             //
        //        Up or C: Open the mod list                       //
        //           Left: Scroll left                             //
        //          Right: Scroll right                            //
        ////////////////// Encounter or Mod list: ///////////////////
        //    Z or Return: Start an encounter, or select a mod     //
        //     Shift or X: Exit                                    //
        //             Up: Move up                                 //
        //           Down: Move down                               //
        /////////////////////////////////////////////////////////////

        // Main controls:
        if (!encounterBox.activeSelf)
        {
            if (animationDone)
            {
                //scroll left
                if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    ScrollMods(-1);
                }
                //scroll right
                else if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    ScrollMods(1);
                }
                //open the mod list
                else if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.C))
                {
                    modFolderMiniMenu();
                    content.transform.GetChild(selectedItem).GetComponent <MenuButton>().StartAnimation(1);
                    // Open the encounter list or start the encounter (if there is only one encounter)
                }
                else if (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.Return))
                {
                    ModBackground.GetComponent <Button>().onClick.Invoke();
                }
                //content.transform.GetChild(selectedItem).GetComponent<MenuButton>().StartAnimation(1);
            }

            // Return to the Disclaimer screen
            if (Input.GetKeyDown(KeyCode.X) || Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
            {
                btnExit.GetComponent <Button>().onClick.Invoke();
            }
            // Encounter or Mod List controls:
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow))
            {
                // Store previous value of selectedItem
                int previousSelectedItem = selectedItem;

                //move up
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    selectedItem -= 1;
                }
                //move down
                else if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    selectedItem += 1;
                }

                // Keep the selector in-bounds!
                if (selectedItem < 0)
                {
                    selectedItem = content.transform.childCount - 1;
                }
                else if (selectedItem > content.transform.childCount - 1)
                {
                    selectedItem = 0;
                }

                // Update the buttons!

                // Animate the old button
                GameObject previousButton = content.transform.GetChild(previousSelectedItem).gameObject;
                previousButton.GetComponent <MenuButton>().StartAnimation(-1);
                //previousButton.spriteState = SpriteState.

                // Animate the new button
                GameObject newButton = content.transform.GetChild(selectedItem).gameObject;
                newButton.GetComponent <MenuButton>().StartAnimation(1);

                // Scroll to the newly chosen button if it is hidden!
                float buttonTopEdge    = -newButton.GetComponent <RectTransform>().anchoredPosition.y + 100;
                float buttonBottomEdge = -newButton.GetComponent <RectTransform>().anchoredPosition.y + 100 + 30;

                float topEdge    = content.GetComponent <RectTransform>().anchoredPosition.y;
                float bottomEdge = content.GetComponent <RectTransform>().anchoredPosition.y + 230;

                //button is above the top of the scrolly bit
                if (topEdge > buttonTopEdge)
                {
                    content.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, buttonTopEdge);
                }
                //button is below the bottom of the scrolly bit
                else if (bottomEdge < buttonBottomEdge)
                {
                    content.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, buttonBottomEdge - 230);
                }
            }

            // Exit
            if (Input.GetKeyDown(KeyCode.X) || Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
            {
                ModBackground.GetComponent <Button>().onClick.Invoke();
            }
            // Select the mod or encounter
            else if (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.Return))
            {
                content.transform.GetChild(selectedItem).gameObject.GetComponent <Button>().onClick.Invoke();
            }
        }
    }
Esempio n. 6
0
    // Shows a mod's "page".
    private void ShowMod(int id)
    {
        // Error handler
        // If current index is now out of range OR currently selected mod is not present:
        if (CurrentSelectedMod < 0 || CurrentSelectedMod > modDirs.Count - 1 ||
            !new DirectoryInfo(Path.Combine(FileLoader.DataRoot, "Mods/" + modDirs[CurrentSelectedMod].Name + "/Lua/Encounters")).Exists ||
            new DirectoryInfo(Path.Combine(FileLoader.DataRoot, "Mods/" + modDirs[CurrentSelectedMod].Name + "/Lua/Encounters")).GetFiles("*.lua").Length == 0)
        {
            HandleErrors();
            return;
        }

        // Update currently selected mod folder
        StaticInits.MODFOLDER = modDirs[id].Name;

        // Make clicking the background go to the encounter select screen
        ModBackground.GetComponent <Button>().onClick.RemoveAllListeners();
        ModBackground.GetComponent <Button>().onClick.AddListener(() => {
            if (animationDone)
            {
                encounterSelection();
            }
        });

        // Update the background
        var ImgComp = ModBackground.GetComponent <Image>();

        // First, check if we already have this mod's background loaded in memory
        if (bgs.ContainsKey(modDirs[CurrentSelectedMod].Name))
        {
            ImgComp.sprite = bgs[modDirs[CurrentSelectedMod].Name];
        }
        else
        {
            // if not, find it and store it
            try {
                Sprite thumbnail = SpriteUtil.FromFile(FileLoader.pathToModFile("Sprites/preview.png"));
                ImgComp.sprite = thumbnail;
            } catch {
                try {
                    Sprite bg = SpriteUtil.FromFile(FileLoader.pathToModFile("Sprites/bg.png"));
                    ImgComp.sprite = bg;
                } catch { ImgComp.sprite = SpriteUtil.FromFile("Sprites/black.png"); }
            }
            bgs.Add(modDirs[CurrentSelectedMod].Name, ImgComp.sprite);
        }

        // Get all encounters in the mod's Encounters folder
        DirectoryInfo di         = new DirectoryInfo(Path.Combine(FileLoader.ModDataPath, "Lua/Encounters"));
        List <string> encounters = di.GetFiles("*.lua").Select(f => Path.GetFileNameWithoutExtension(f.Name)).ToList();

        // Update the text
        ModTitle.GetComponent <Text>().text = modDirs[id].Name;
        // Crate your frisk version
        if (GlobalControls.crate)
        {
            ModTitle.GetComponent <Text>().text = Temmify.Convert(modDirs[id].Name, true);
        }
        ModTitleShadow.GetComponent <Text>().text = ModTitle.GetComponent <Text>().text;

        // List # of encounters, or name of encounter if there is only one
        if (encounters.Count == 1)
        {
            EncounterCount.GetComponent <Text>().text = encounters[0];
            // crate your frisk version
            if (GlobalControls.crate)
            {
                EncounterCount.GetComponent <Text>().text = Temmify.Convert(encounters[0], true);
            }

            // Make clicking the bg directly open the encounter
            ModBackground.GetComponent <Button>().onClick.RemoveAllListeners();
            ModBackground.GetComponent <Button>().onClick.AddListener(() => {
                if (!animationDone)
                {
                    return;
                }
                StaticInits.ENCOUNTER = encounters[0];
                StartCoroutine(LaunchMod());
            });
        }
        else
        {
            EncounterCount.GetComponent <Text>().text = "Has " + encounters.Count + " encounters";
            // crate your frisk version
            if (GlobalControls.crate)
            {
                EncounterCount.GetComponent <Text>().text = "HSA " + encounters.Count + " ENCUOTNERS";
            }
        }
        EncounterCountShadow.GetComponent <Text>().text = EncounterCount.GetComponent <Text>().text;

        // Update the color of the arrows
        if (CurrentSelectedMod == 0 && modDirs.Count == 1)
        {
            BackText.color = new Color(0.25f, 0.25f, 0.25f, 1f);
        }
        else
        {
            BackText.color = new Color(1f, 1f, 1f, 1f);
        }
        if (CurrentSelectedMod == modDirs.Count - 1 && modDirs.Count == 1)
        {
            NextText.color = new Color(0.25f, 0.25f, 0.25f, 1f);
        }
        else
        {
            NextText.color = new Color(1f, 1f, 1f, 1f);
        }
    }