Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Preferences Menu Pages #4081

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

KoloInDaCrib
Copy link
Contributor

Does this PR close any issues? If so, link them below.

#4043

Briefly describe the issue(s) fixed.

Overhauled most of the things from the preference menu, whoops! Anyways yeah adding custom options/modifying pre-existing options shouldn't be a hassle now! Oh and also to switch pages just press Q or E probably should've put that somewhere but oh well!

Include any relevant screenshots or videos.

2025-02-01.13-01-15.mp4

disclaimer: the "test#" item does not come with this pr and has been temporarily added as a demonstration

@Lasercar
Copy link
Contributor

Lasercar commented Feb 1, 2025

This issue #3844 would be closed by this PR.

@KoloInDaCrib
Copy link
Contributor Author

This issue #3844 would be closed by this PR.

I don't really think it would, this doesn't have to do anything with experimental features, it just makes it so that the preferences menu has a support for pages, which in turn, can make the preferences menu more organized

@Lasercar
Copy link
Contributor

Lasercar commented Feb 1, 2025

I don't really think it would, this doesn't have to do anything with experimental features, it just makes it so that the preferences menu has a support for pages, which in turn, can make the preferences menu more organized

Well, my thinking is, are there currently any experimental features that would go into a preferences submenu using this? If not, then there's not much point leaving this #3844 issue up.

@AbnormalPoof AbnormalPoof added type: enhancement Involves an enhancement or new feature. status: pending triage Awaiting review. topic: polish Involves minor polish to the UI or gameplay. size: large A large pull request with more than 100 changes. pr: haxe PR modifies game code. and removed large labels Feb 1, 2025
@KoloInDaCrib
Copy link
Contributor Author

Well, my thinking is, are there currently any experimental features that would go into a preferences submenu using this? If not, then there's not much point leaving the issue up.

This PR was done in order to satisfy a suggestion that I've linked all the way above. It requested a support for multiple pages in the preferences menu for mods that are willing to append custom options/configurations without making the preference menu look unorganized and messy.

For instance, let's say that I wanted to add an option to disable a function of my mod without unloading the entire thing. Normally it would appear at the bottom of the options, looking rather unorganized with the rest of them. It wouldn't be too bad on it's own but you have to consider some players are willing to play with dozens of mods that also add custom options to the preferences menu, which, without proper organization, is just going to give anyone looking at the preferences menu a headache.
That's what this PR aims to solve. Lack of organization due to lack of pages. Alongside that, this PR also makes the creations of options data-driven, i.e. with an object like {type: "checkbox", name: "PreferenceNameHere"} for the sake of convenience.

Also, I genuinely don't see how experimental features would be implemented - that would require the game to update almost weekly, which is practically impossible for a team of independent developers. But that's a topic for another time.

Copy link
Collaborator

@AbnormalPoof AbnormalPoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good so far! I do have some questions though:

  1. How would mods create custom preferences with this new system?
  2. How can mods add additional pages?

Also, it'd be nice if there was a sort of UI element at the top that showed you the current page (i.e "BASE GAME")!

@KoloInDaCrib
Copy link
Contributor Author

KoloInDaCrib commented Feb 1, 2025

I'd imagine creating new pages like this

event.targetState.pages.get("preferences").preferencePages.push(
{
 name: "UrNameHere",
 itemDatas: [] //add your preferences here, constructed like in the DEFAULT_PREFERENCES variable
});

Also, sure, I'll add the preference page name field i also gotta change FlxTypedSpriteGroup to FlxSpriteGroup since I have just now remembered that HScript doesn't like the < > brackets

@AbnormalPoof
Copy link
Collaborator

AbnormalPoof commented Feb 1, 2025

FYI HScript can't import FlxSpriteGroup since it's not a class.

I'd imagine FlxTypedSpriteGroup would work fine since HScript doesn't do type-checking.
Screenshot 2025-02-01 at 12 47 35 PM

@KoloInDaCrib
Copy link
Contributor Author

I've changed the system so that when creating the pages you no longer need the items and prefItems fields, as they are now automatically generated, that should hopefully help actually create pages lol

Copy link
Collaborator

@AbnormalPoof AbnormalPoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested this out on a mod and it doesn't appear to work...

  override function onStateChangeEnd(event:StateChangeScriptEvent):Void
  {
    super.onStateChangeEnd(event);
    // Options Menu stuff
    if (event.targetState is OptionsState)
    {
      var prefs = event.targetState.pages.get("preferences");
      if (prefs != null)
      {
        prefs.preferencePages.push({
          name: "Funker Selector",
          itemDatas: [
            {
              type: "checkbox",
              name: "Simplify UI",
              desc: "Simplifies the UI and disables character sprite caching.",
              onChange: function(value:Dynamic) {
                FS_SaveDataHandler.scriptCall('setPreference', ["potatoMode", value]);
              },
              defaultValue: FS_SaveDataHandler.scriptCall('getPreference', ["potatoMode"])
            }
          ]
        });
      }
    }
  }

Screenshot 2025-02-01 at 1 36 33 PM

@AbnormalPoof AbnormalPoof added topic: mods Related to the creation or use of mods. and removed topic: polish Involves minor polish to the UI or gameplay. labels Feb 1, 2025
@KoloInDaCrib
Copy link
Contributor Author

KoloInDaCrib commented Feb 1, 2025

Just tested this out on a mod and it doesn't appear to work...

Ran a bit of testing and apparently this happens because when the preference page is generated with new() it also generates the items, however the script appends the data after the items are generated, which allows the page the be scrolled to but since it has no items, the game crashes. Should be an easy fix though

Edit: done and dusted! tested with the same script you provided
also thanks again for playtesting it more than I did!

actually make this moddable lmao
Copy link
Collaborator

@AbnormalPoof AbnormalPoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peak

10.out.of.10.mp4

Code snippet:

  override function onStateChangeEnd(event:StateChangeScriptEvent):Void
  {
    super.onStateChangeEnd(event);
    // Options Menu stuff
    if (event.targetState is OptionsState)
    {
      event.targetState.pages.get("preferences").preferencePages.push({
        name: "FUNKER SELECTOR",
        itemDatas: [
          {
            type: "checkbox",
            name: "Simplify UI",
            desc: "Simplifies the UI and disables character sprite caching.",
            onChange: function(value:Dynamic) {
              FS_SaveDataHandler.scriptCall('setPreference', ["potatoMode", value]);
            },
            defaultValue: FS_SaveDataHandler.scriptCall('getPreference', ["potatoMode"])
          },
          {
            type: "checkbox",
            name: "Preload Sprites",
            desc: "Whether to preload the character sprites or not. Will cause lag on the Character Selection Menu if off!",
            onChange: function(value:Dynamic) {
              FS_SaveDataHandler.scriptCall('setPreference', ["preloadSprites", value]);
              if (value)
              {
                FS_CharacterDataHandler.scriptCall("cacheJSONSparrows");
              }
              else
              {
                // Remove the JSON Characters from memory when the user disables the option.
                FS_CharacterDataHandler.scriptCall("purgeJSONSparrowCache");
              }
            },
            defaultValue: FS_SaveDataHandler.scriptCall('getPreference', ["preloadSprites"])
          },
          {
            type: "enum",
            name: "Menu SFX",
            desc: "Change the SFX used for the Character Menu.",
            values: ["funkin" => "Funkin' Main Menu", "charSelect" => "Funkin' Character Select"],
            onChange: function(value:Dynamic) {
              FS_SaveDataHandler.scriptCall('setPreference', ["preferredSFX", value]);
              if (value == "charSelect")
              {
                FunkinSound.playOnce(Paths.sound('CS_confirm'));
              }
              else
              {
                FunkinSound.playOnce(Paths.sound('confirmMenu'));
              }
            },
            defaultValue: FS_SaveDataHandler.scriptCall('getPreference', ["preferredSFX"])
          },
          {
            type: "checkbox",
            name: "DJ Replacement",
            desc: "When enabled, the Freeplay DJ can be swapped out for the currently selected character's own DJ.",
            onChange: function(value:Dynamic) {
              FS_SaveDataHandler.scriptCall('setPreference', ["djSwapping", value]);
            },
            defaultValue: FS_SaveDataHandler.scriptCall('getPreference', ["djSwapping"])
          }
        ]
      });
    }
  }

@AbnormalPoof AbnormalPoof removed the Haxe label Feb 1, 2025
@Lasercar
Copy link
Contributor

Lasercar commented Feb 4, 2025

Once I get some changeable options in the updated screenshot plugin, I'll use this stuff and put the options on a separate page (though ofc only when it's all been merged and such).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: haxe PR modifies game code. size: large A large pull request with more than 100 changes. status: pending triage Awaiting review. topic: mods Related to the creation or use of mods. type: enhancement Involves an enhancement or new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants