public static MenuTextBox MenuTextBoxFromComponent(ClickableComponent component, TextBox textBox, IClickableMenu menu, string label = null)
        {
            MenuTextBox menuTextBox = new MenuTextBox();

            menuTextBox.menu           = menu;
            menuTextBox.StardewTextBox = textBox;
            menuTextBox.SetActionFromComponent(component, label);
            return(menuTextBox);
        }
Example #2
0
        public AccessCharacterCreationMenu(StardewValley.Menus.CharacterCustomization characterCustomization) : base(characterCustomization)
        {
            TextBox GetTextBox(string name) =>
            ModEntry.GetHelper().Reflection.GetField <TextBox>(characterCustomization, name).GetValue();

            MenuItem menuItem;

            foreach (var button in characterCustomization.genderButtons)
            {
                menuItem              = MenuItem.MenuItemFromComponent(button, characterCustomization);
                menuItem.Label        = button.name;
                menuItem.TextOnAction = "Gender set to " + menuItem.Label;
                AddItem(menuItem);
            }

            menuItem       = MenuTextBox.MenuTextBoxFromComponent(characterCustomization.nameBoxCC, GetTextBox("nameBox"), characterCustomization);
            menuItem.Label = "Character name";
            AddItem(menuItem);
            menuItem              = MenuTextBox.MenuTextBoxFromComponent(characterCustomization.farmnameBoxCC, GetTextBox("farmnameBox"), characterCustomization);
            menuItem.Label        = "Farm name";
            menuItem.TextOnAction = "farm";
            AddItem(menuItem);
            menuItem       = MenuTextBox.MenuTextBoxFromComponent(characterCustomization.favThingBoxCC, GetTextBox("favThingBox"), characterCustomization);
            menuItem.Label = "Favourite thing";
            AddItem(menuItem);

            ClickableComponent catButton = null;

            foreach (ClickableComponent comp in characterCustomization.rightSelectionButtons)
            {
                if (comp.name.Equals("Pet"))
                {
                    catButton = comp;
                }
            }
            if (catButton != null)
            {
                MenuItem petButton = MenuItem.MenuItemFromComponent(catButton, characterCustomization);
                petButton.Label = "change pet";
                petButton.speakOnClickAction -= petButton.DefaultSpeakOnClickAction;
                string breedToString()
                {
                    if (Game1.player.catPerson)
                    {
                        switch (Game1.player.whichPetBreed)
                        {
                        case 0: return("orange cat");

                        case 1: return("grey cat");

                        case 2: return("yellow cat");

                        default: return("unknown");
                        }
                    }
                    else
                    {
                        switch (Game1.player.whichPetBreed)
                        {
                        case 0: return("Laprador Retriever");

                        case 1: return("German Shepherd");

                        case 2: return("Bloodhound");

                        default: return("unknown");
                        }
                    }
                }

                petButton.speakOnClickAction += () => { TextToSpeech.Speak("selected " + breedToString() + " as pet"); };
                AddItem(petButton);
            }
            else
            {
                ModEntry.Log("couldn't find pet button", LogLevel.Error);
            }


            menuItem       = MenuItem.MenuItemFromComponent(characterCustomization.skipIntroButton, characterCustomization);
            menuItem.Label = "skip intro";
            menuItem.speakOnClickAction -= menuItem.DefaultSpeakOnClickAction;
            menuItem.speakOnClickAction += () =>
            {
                bool skipIntro = ModEntry.GetHelper().Reflection.GetField <bool>(characterCustomization, "skipIntro").GetValue();
                TextToSpeech.Speak(skipIntro ? "skipping intro" : "playing intro");
            };
            AddItem(menuItem);

            foreach (ClickableTextureComponent comp in characterCustomization.farmTypeButtons)
            {
                menuItem              = MenuItem.MenuItemFromComponent(comp, characterCustomization);
                menuItem.Label        = comp.name + " farm type";
                menuItem.TextOnAction = "selected " + comp.name + " farm type";
                menuItem.Description  = comp.hoverText.Split('_')[1];
                AddItem(menuItem);
            }

            menuItem       = MenuItem.MenuItemFromComponent(characterCustomization.okButton, characterCustomization);
            menuItem.Label = "start game";
            menuItem.speakOnClickAction -= menuItem.DefaultSpeakOnClickAction;
            menuItem.speakOnClickAction += () =>
            {
                if (characterCustomization.canLeaveMenu())
                {
                    TextToSpeech.Speak("starting new game");
                }
                else
                {
                    TextToSpeech.Speak("enter character name, farm name, and favourite thing first");
                }
            };
            AddItem(menuItem);

            menuItem              = MenuItem.MenuItemFromComponent(characterCustomization.backButton, StardewValley.Game1.activeClickableMenu);
            menuItem.Label        = "back to title";
            menuItem.TextOnAction = AccessTitleMenu.Title();
            AddItem(menuItem);
        }