12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"tcli": {
"version": "0.2.3",
"commands": [
"tcli"
]
}
}
}
20 changes: 20 additions & 0 deletions .editorconfig
@@ -0,0 +1,20 @@
root = true

[*.cs]
indent_size = 4
indent_style = space
tab_width = 4

end_of_line = crlf
insert_final_newline = true

dotnet_diagnostic.SA1101.severity = none
dotnet_diagnostic.SA1309.severity = none

[**/Patch/**.cs]
dotnet_diagnostic.SA1313.severity = none
dotnet_diagnostic.SA1600.severity = none

[{MyPluginInfo.cs,IgnoresAccessChecksToAttribute.cs}]
dotnet_diagnostic.SA1633.severity = none
generated_code = true
@@ -1,7 +1,7 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET
name: Build

on:
push:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -360,4 +360,6 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

.idea/
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

[unreleased]: https://github.com/Commander-Cat101/ContentSettings/compare/v1.0.0...HEAD
20 changes: 0 additions & 20 deletions ContentSettings/API/Patches/SaveSettingsPatch.cs

This file was deleted.

38 changes: 0 additions & 38 deletions ContentSettings/API/Patches/SettingsPageOpenPatch.cs

This file was deleted.

26 changes: 0 additions & 26 deletions ContentSettings/API/Patches/SettingsTabSelectModdedPatch.cs

This file was deleted.

120 changes: 89 additions & 31 deletions ContentSettings/API/SettingsLoader.cs
@@ -1,47 +1,105 @@
using System;
// -----------------------------------------------------------------------
// <copyright file="SettingsLoader.cs" company="ContentSettings">
// Copyright (c) ContentSettings. All rights reserved.
// Licensed under the GPL-3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace ContentSettings.API;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Zorro.Settings;
using TMPro;
using UnityEngine.Localization.PropertyVariants;

namespace ContentSettings.API
/// <summary>
/// Settings loader for custom settings belonging to mods.
/// </summary>
public static class SettingsLoader
{
public static class SettingsLoader
private static readonly DefaultSettingsSaveLoad SaveLoader = new ();

private static readonly List<Setting> Settings = new ();

/// <summary>
/// Register a custom setting.
/// </summary>
/// <remarks>This will apply the loaded value of the setting immediately. See <see cref="Setting.ApplyValue"/>.</remarks>
/// <param name="setting">The setting to register.</param>
public static void RegisterSetting(Setting setting)
{
internal static DefaultSettingsSaveLoad SaveLoader = new DefaultSettingsSaveLoad();
Settings.Add(setting);
setting.Load(SaveLoader);
setting.ApplyValue();
}

internal static List<Setting> Settings = new List<Setting>();
internal static void LoadSettingsMenu(SettingsMenu menu)
/// <summary>
/// Loads the settings into the settings menu.
/// </summary>
/// <param name="menu">The settings menu to load the settings into.</param>
internal static void LoadSettingsMenu(SettingsMenu menu)
{
foreach (var settingsCell in menu.m_cells)
{
foreach (SettingsCell settingsCell in menu.m_cells)
{
GameObject.Destroy(settingsCell.gameObject);
}
menu.m_cells.Clear();
SettingsHandler settingsHandler = GameHandler.Instance.SettingsHandler;
List<Setting> settings = Settings;
for (int i = 0; i < settings.Count; i++)
{
Setting setting = settings[i];
SettingsCell component = GameObject.Instantiate<GameObject>(menu.m_settingsCell, menu.m_settingsContainer).GetComponent<SettingsCell>();
component.Setup(setting, settingsHandler);
menu.m_cells.Add(component);
}
Object.Destroy(settingsCell.gameObject);
}

internal static void SaveSettings()
menu.m_cells.Clear();

var settingsHandler = GameHandler.Instance.SettingsHandler;
var settings = Settings;

foreach (var setting in settings)
{
foreach (var setting in Settings)
{
setting.Save(SaveLoader);
}
var component = Object.Instantiate(menu.m_settingsCell, menu.m_settingsContainer).GetComponent<SettingsCell>();
component.Setup(setting, settingsHandler);
menu.m_cells.Add(component);
}
public static void RegisterSetting(Setting setting)
}

/// <summary>
/// Saves all registered settings.
/// </summary>
internal static void SaveSettings()
{
foreach (var setting in Settings)
{
Settings.Add(setting);
setting.Load(SaveLoader);
setting.Save(SaveLoader);
}
}

/// <summary>
/// Creates the settings tab for the modded settings.
/// </summary>
/// <param name="menu">The settings menu to create the tab in.</param>
/// <exception cref="System.Exception">Thrown when the existing tab to create the modded settings tab from is not found.</exception>
internal static void CreateSettings(SettingsMenu menu)
{
var settingsTabs = menu.transform.Find("Content")?.Find("TABS");
if (settingsTabs == null)
{
throw new System.Exception("Failed to find settings tab.");
}

if (settingsTabs.Find("MODDED") != null)
{
return;
}

var existingTab = settingsTabs.GetChild(0)?.gameObject;
if (existingTab == null)
{
throw new System.Exception("Failed to find existing tab.");
}

var customSettingsTab = Object.Instantiate(existingTab, settingsTabs, true);
customSettingsTab.name = "MODDED";

var customSettingsTabText = customSettingsTab.transform.GetChild(1);
Object.Destroy(customSettingsTabText.GetComponent<GameObjectLocalizer>());
customSettingsTabText.GetComponent<TextMeshProUGUI>().SetText("MODDED");

LoadSettingsMenu(menu);
}
}
25 changes: 25 additions & 0 deletions ContentSettings/ContentSettings.cs
@@ -0,0 +1,25 @@
// -----------------------------------------------------------------------
// <copyright file="ContentSettings.cs" company="ContentSettings">
// Copyright (c) ContentSettings. All rights reserved.
// Licensed under the GPL-3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace ContentSettings;

using BepInEx;
using HarmonyLib;

/// <summary>
/// The main Content Settings plugin class
/// </summary>
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class ContentSettings : BaseUnityPlugin
{
private Harmony Harmony { get; } = new (MyPluginInfo.PLUGIN_GUID);

private void Awake()
{
Harmony.PatchAll();
}
}