Skip to content

Commit

Permalink
ModSettings: Show disabled reason & Feature origin
Browse files Browse the repository at this point in the history
  • Loading branch information
AuriRex committed Oct 19, 2023
1 parent de5705c commit 617ab4e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 41 deletions.
27 changes: 27 additions & 0 deletions TheArchive.Core/Core/FeaturesAPI/FeatureInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ internal class FeatureInternal
internal IEnumerable<FeatureSettingsHelper> Settings => _settingsHelpers;
internal Utils.RundownFlags Rundowns { get; private set; } = Utils.RundownFlags.None;
internal IArchiveLogger FeatureLoggerInstance { get; private set; }
internal Assembly OriginAssembly { get; private set; }

private string _asmGroupName;
internal string AsmGroupName
{
get
{
if(string.IsNullOrEmpty(_asmGroupName))
{
_asmGroupName = OriginAssembly.GetCustomAttribute<ModDefaultFeatureGroupName>()?.DefaultGroupName ?? OriginAssembly.GetName().Name;
}
return _asmGroupName;
}
}
internal string CriticalInfo
{
get
{
if (InternalDisabled)
{
return $"<#F00>DISABLED</color>: {DisabledReason}";
}

return string.Empty;
}
}

private Feature _feature;
private HarmonyLib.Harmony _harmonyInstance;
Expand Down Expand Up @@ -90,6 +116,7 @@ internal void Init(Feature feature)
_feature = feature;

var featureType = _feature.GetType();
OriginAssembly = featureType.Assembly;

_FILogger.Msg(ConsoleColor.Black, "-");
_FILogger.Msg(ConsoleColor.Green, $"Initializing {_feature.Identifier} ...");
Expand Down
73 changes: 36 additions & 37 deletions TheArchive.IL2CPP/Features/Dev/ModSettings.OtherTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,52 +482,62 @@ public class DescriptionPanelData
{
public string Title;
public string Description;
public string CriticalInfo;
public string FeatureOrigin;

public bool HasDescription => !string.IsNullOrWhiteSpace(Description);
}

private CM_ScrollWindow _backgroundPanel;
private TMPro.TextMeshPro _headerText;
private TMPro.TextMeshPro _contentText;
private TMPro.TextMeshPro _infoL1Text;
private TMPro.TextMeshPro _infoL2Text;


public DescriptionPanel()
{
_backgroundPanel = CreateScrollWindow("Description");
_backgroundPanel.transform.localPosition = _backgroundPanel.transform.localPosition + new Vector3(1050, 0, 0);

CreateItem("Header Text", ORANGE, _backgroundPanel.transform, out var headerSWC, out var rectTransHeader, out _headerText);
rectTransHeader.sizeDelta = new Vector2(rectTransHeader.sizeDelta.x * 2, rectTransHeader.sizeDelta.y);

var headerItemGO = GameObject.Instantiate(SettingsItemPrefab, _backgroundPanel.transform);

_headerText = headerItemGO.GetComponentInChildren<CM_SettingsItem>().transform.GetChildWithExactName("Title").GetChildWithExactName("TitleText").gameObject.GetComponent<TMPro.TextMeshPro>();

_headerText.color = ORANGE;

_headerText.SetText("Header Text");

var rectTrans = _headerText.gameObject.GetComponent<RectTransform>();
CreateItem("Content Text", WHITE_GRAY, _backgroundPanel.transform, out var contentSWC, out var rectTransContent, out _contentText);
rectTransContent.sizeDelta = new Vector2(rectTransContent.sizeDelta.x * 2, rectTransContent.sizeDelta.y * 10);

rectTrans.sizeDelta = new Vector2(rectTrans.sizeDelta.x * 2, rectTrans.sizeDelta.y);
CreateItem("Info One", RED, _backgroundPanel.transform, out var infoOneSWC, out var rectTransInfo, out _infoL1Text);
rectTransInfo.sizeDelta = new Vector2(rectTransInfo.sizeDelta.x * 2, rectTransInfo.sizeDelta.y);
rectTransInfo.localPosition = rectTransInfo.localPosition + new Vector3(0, -660, 0);

CreateItem("Info Two", ORANGE, _backgroundPanel.transform, out var infoTwoSWC, out var rectTransInfoTwo, out _infoL2Text);
rectTransInfoTwo.sizeDelta = new Vector2(rectTransInfoTwo.sizeDelta.x * 2, rectTransInfoTwo.sizeDelta.y);
rectTransInfoTwo.localPosition = rectTransInfoTwo.localPosition + new Vector3(0, -640, 0);

var contentItemGO = GameObject.Instantiate(SettingsItemPrefab, _backgroundPanel.transform);
_backgroundPanel.SetContentItems(new List<iScrollWindowContent>()
{
headerSWC,
contentSWC,
infoOneSWC,
infoTwoSWC,
}.ToIL2CPPListIfNecessary(), 5);

_contentText = contentItemGO.GetComponentInChildren<CM_SettingsItem>().transform.GetChildWithExactName("Title").GetChildWithExactName("TitleText").gameObject.GetComponent<TMPro.TextMeshPro>();
AddToAllSettingsWindows(_backgroundPanel);
}

_contentText.color = WHITE_GRAY;
private static void CreateItem(string text, Color col, Transform parent, out iScrollWindowContent scrollWindowContent, out RectTransform rectTrans, out TMPro.TextMeshPro tmp)
{
var settingsItemGO = GameObject.Instantiate(SettingsItemPrefab, parent);

_contentText.SetText("Content Text");
tmp = settingsItemGO.GetComponentInChildren<CM_SettingsItem>().transform.GetChildWithExactName("Title").GetChildWithExactName("TitleText").gameObject.GetComponent<TMPro.TextMeshPro>();

var rectTransContent = _contentText.gameObject.GetComponent<RectTransform>();
tmp.color = col;

rectTransContent.sizeDelta = new Vector2(rectTransContent.sizeDelta.x * 2, rectTransContent.sizeDelta.y * 10);
tmp.SetText(text);

_backgroundPanel.SetContentItems(new List<iScrollWindowContent>()
{
headerItemGO.GetComponentInChildren<iScrollWindowContent>(),
contentItemGO.GetComponentInChildren<iScrollWindowContent>()
}.ToIL2CPPListIfNecessary(), 5);
rectTrans = tmp.gameObject.GetComponent<RectTransform>();

AddToAllSettingsWindows(_backgroundPanel);
scrollWindowContent = settingsItemGO.GetComponentInChildren<iScrollWindowContent>();
}

public void Dispose()
Expand All @@ -549,22 +559,11 @@ public void Show(DescriptionPanelData data)
_contentText.SetText(data.Description);
JankTextMeshProUpdaterOnce.ForceUpdateMesh(_contentText);

// TODO: Include Module/Mod name of feature
// TODO: Include Rundown Constraints
}

public void Show(string title, string content)
{
if (TheColorPicker.IsActive)
return;

_backgroundPanel.gameObject.SetActive(true);

_headerText.SetText(title);
JankTextMeshProUpdaterOnce.ForceUpdateMesh(_headerText);
_infoL1Text.SetText(data.CriticalInfo ?? string.Empty);
JankTextMeshProUpdaterOnce.ForceUpdateMesh(_infoL1Text);

_contentText.SetText(content);
JankTextMeshProUpdaterOnce.ForceUpdateMesh(_contentText);
_infoL2Text.SetText(data.FeatureOrigin ?? string.Empty);
JankTextMeshProUpdaterOnce.ForceUpdateMesh(_infoL2Text);
}

public void Hide()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public static void SetupItemsForSettingsHelper(FeatureSettingsHelper settingsHel
var data = new DescriptionPanel.DescriptionPanelData() {
Title = ss.DisplayName,
Description = ss.Description,
CriticalInfo = ss.Helper.Feature.FeatureInternal.CriticalInfo,
FeatureOrigin = ss.Helper.Feature.FeatureInternal.AsmGroupName,
};
CreateSubMenuControls(subMenu, menuEntryLabelText: ss.DisplayName, placeIntoMenu: placeIntoMenu, descriptionPanelData: data);

Expand Down Expand Up @@ -1145,6 +1147,8 @@ public static void CreateFSHoverAndSetButtonAction(FeatureSetting setting, CM_Se
var data = new DescriptionPanel.DescriptionPanelData() {
Title = setting.DisplayName,
Description = setting.Description,
CriticalInfo = setting.Helper.Feature.FeatureInternal.CriticalInfo,
FeatureOrigin = setting.Helper.Feature.FeatureInternal.AsmGroupName,
};

CreateFSHoverAndSetButtonAction(data, cm_settingsItem, toggleButton_cm_item, buttonAction);
Expand All @@ -1156,8 +1160,8 @@ public static void CreateFSHoverAndSetButtonAction(DescriptionPanel.DescriptionP
{
if (hovering)
{
if (data != null && data.HasDescription)
TheDescriptionPanel.Show(data.Title, data.Description);
if (data != null)
TheDescriptionPanel.Show(data);
}
else
{
Expand Down
11 changes: 9 additions & 2 deletions TheArchive.IL2CPP/Features/Dev/ModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,19 @@ internal static void SetupEntriesForFeature(Feature feature, SubMenu groupSubMen
SetFeatureItemTextAndColor(feature, sub_toggleButton_cm_item, sub_toggleButtonText);
};

var descriptionData = new DescriptionPanel.DescriptionPanelData
{
Title = feature.Name,
Description = feature.Description,
CriticalInfo = feature.FeatureInternal.CriticalInfo,
FeatureOrigin = feature.FeatureInternal.AsmGroupName,
};

var delHover = delegate (int id, bool hovering)
{
if(hovering)
{
if(!string.IsNullOrWhiteSpace(feature.Description))
TheDescriptionPanel.Show(feature.Name, feature.Description);
TheDescriptionPanel.Show(descriptionData);
}
else
{
Expand Down

0 comments on commit 617ab4e

Please sign in to comment.