Exemplo n.º 1
0
    /// <summary>
    /// Sets up the GMCM for this mod.
    /// </summary>
    /// <param name="sender">SMAPI.</param>
    /// <param name="e">event args.</param>
    private void SetUpConfig(object?sender, GameLaunchedEventArgs e)
    {
        GMCMHelper helper = new(this.Monitor, this.Helper.Translation, this.Helper.ModRegistry, this.ModManifest);

        if (!helper.TryGetAPI())
        {
            return;
        }
        helper.Register(
            reset: () =>
        {
            Config = new();
            AssetEditor.Invalidate();
        },
            save: () =>
        {
            this.Helper.WriteConfig(Config);
            AssetEditor.Invalidate();
        });
        foreach (PropertyInfo property in typeof(ModConfig).GetProperties())
        {
            if (property.PropertyType == typeof(bool))
            {
                helper.AddBoolOption(
                    property: property,
                    getConfig: () => Config);
            }
        }
        helper.AddPageHere("CheatyStuff", I18n.CheatyStuffTitle);
        foreach (PropertyInfo property in typeof(ModConfig).GetProperties())
        {
            if (property.PropertyType == typeof(float))
            {
                helper.AddFloatOption(
                    property: property,
                    getConfig: () => Config,
                    min: 0f,
                    max: 1f,
                    interval: 0.01f);
            }
        }
    }