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

implement custom ui #7

Merged
merged 1 commit into from
Jan 2, 2025
Merged

Conversation

art0007i
Copy link
Contributor

@art0007i art0007i commented Oct 6, 2024

I added the ability for custom mods to make their own ui.

How to use for people who want to add custom ui in their mod:

  1. Make your mod a partial class.
  2. Add ModSettingsStub.cs to your project, and change the namespace and classname to match your mod.
  3. Write code inside the ModSettings_BuildModUi function
ModSettingsStub.cs
using Elements.Core;
using FrooxEngine;
using FrooxEngine.UIX;
using ResoniteModLoader;
using System;

namespace ExampleMod
{
    public partial class ExampleMod
    {
        /// <summary>
        /// Gives you a UIBuilder which allows you to create custom ui within your page.<br/>
        /// It's setup with default RadiantUI styles (<see cref="RadiantUI_Constants.SetupDefaultStyle"/>)<br/>
        /// The PreferredHeight is set to <see cref="ModSettings_GetHeight"/>, please respect this value when building your UI.<br/>
        /// The UI builder is located within a VerticalLayout with a spacing of 4 with ForceExpandWidth set to true.<br/>
        /// The vertical layout also has a ContentSizeFitter with VerticalFit set to PreferredSize
        /// </summary>
        /// <param name="ui"></param>
        public void ModSettings_BuildModUi(UIBuilder ui)
        {
            ui.Button("hi");
            ModSettings_BuildDefaultFields(this, ui);
            ui.Button("hello");
        }

        /// <summary>
        /// Gets the height that a single config item should be in your settings page.<br/>
        /// This value can be changed on a per user basis in the ModSettings config.
        /// </summary>
        /// <returns></returns>
        public static float ModSettings_GetHeight()
        {
            throw new NotImplementedException("It's a stub.");
        }
        /// <summary>
        /// Gets the color that every other item should have, null if items shouldn't be highlighted.
        /// </summary>
        public static colorX? ModSettings_GetHighlightColor()
        {
            throw new NotImplementedException("It's a stub.");
        }
        /// <summary>
        /// Builds all of the fields present in the config menu by default.<br/>
        /// Use this method when you want to add something to the page before/after the default UI.
        /// </summary>
        public static void ModSettings_BuildDefaultFields(ResoniteModBase mod, UIBuilder ui)
        {
            throw new NotImplementedException("It's a stub.");
        }

        /// <summary>
        /// Builds a singular field using the provided <see cref="ModConfigurationKey"/><br/>
        /// When building multiple fields you are expected to add a highlight to every other field with the color obtained using <see cref="ModSettings_GetHighlightColor"/><br/>
        /// If the highlight color is null then you don't have to add highlighting
        /// </summary>
        public static Slot ModSettings_BuildDefaultField(ResoniteModBase mod, UIBuilder ui, ModConfigurationKey key)
        {
            throw new NotImplementedException("It's a stub.");
        }
    }
}

@art0007i
Copy link
Contributor Author

@badhaloninja can I your get opinion on this.

@art0007i art0007i changed the title working custom ui draft implement custom ui Dec 18, 2024
@badhaloninja badhaloninja merged commit 0688ba8 into badhaloninja:master Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants