mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Add wiki components to modifiers
This commit is contained in:
1 parent
d0138936be
commit
5e6645ff3b
2 files changed
+135
-1
No files matched your search
@@ -1,8 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Translation;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace MiraAPI.Modifiers;
|
||||
|
||||
@@ -44,16 +52,134 @@ public abstract class BaseModifier : IOptionable
|
||||
x => x.InternalModifiers.Exists(y => y.TypeId == TypeId))
|
||||
?? throw new InvalidOperationException("Modifier is not registered.");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the id part used to build the modifier's translation keys. It is recommended to simply call it what the modifier is, as other mods may utilize it.
|
||||
/// </summary>
|
||||
public virtual string IdPart => GetType().Name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the id part used to build the modifier's translation keys. It is recommended to call it ModGuid.Modifier.Type.
|
||||
/// </summary>
|
||||
public virtual string IdPrefix => GetType().Namespace!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the modifier name.
|
||||
/// </summary>
|
||||
public abstract string ModifierName { get; }
|
||||
public virtual string ModifierName => MiraLocaleManager.Get(ModifierNameLocale);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the modifier's name id for localization.
|
||||
/// </summary>
|
||||
public virtual string ModifierNameLocale => MiraLocaleManager.BuildTranslationId(IdPrefix, IdPart);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the medium description of the modifier. Used in the modifier guide and options menu.
|
||||
/// </summary>
|
||||
public virtual string ModifierMedDescription => MiraLocaleManager.Get(ModifierMedDescriptionLocale, GetDescription());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the modifier's medium description id for localization.
|
||||
/// </summary>
|
||||
public virtual string ModifierMedDescriptionLocale => MiraLocaleManager.BuildTranslationId(IdPrefix, IdPart, "MedDescription");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the wiki description of the modifier. Used in the wiki and normally appends the options text as well.
|
||||
/// </summary>
|
||||
public virtual string ModifierWikiDescription => MiraLocaleManager.Get(ModifierWikiDescriptionLocale, GetDescription()) +
|
||||
Helpers.GetOptionsText(GetType());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the modifier's wiki description id for localization.
|
||||
/// </summary>
|
||||
public virtual string ModifierWikiDescriptionLocale => MiraLocaleManager.BuildTranslationId(IdPrefix, IdPart, "WikiDescription");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the category of the modifier. Used in the wiki.
|
||||
/// </summary>
|
||||
public virtual string ModifierCategoryTitle => MiraLocaleManager.Get("Modifier");
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the modifier is forcibly shown or disabled in the wiki screen.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the modifier is always displayed, otherwise <see langword="false"/> if it is never displayable, or <see langword="null"/> if it is dictated by amount and chance.</returns>
|
||||
public virtual bool? ForceShowModifierOnWiki => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the information to display in the wiki.
|
||||
/// </summary>
|
||||
/// <param name="guide">The guide object.</param>
|
||||
/// <param name="titleText">The title text object.</param>
|
||||
/// <param name="parent">The scroller parent.</param>
|
||||
/// <returns>The <see cref="GameObject"/> of the wiki.</returns>
|
||||
public virtual GameObject GetAdvancedWiki(MatchInfoGuide guide, TextMeshPro titleText, Scroller parent)
|
||||
{
|
||||
parent.ScrollToTop();
|
||||
var obj = Helpers.CreateAdvancedWikiTab(
|
||||
guide,
|
||||
ModifierNameLocale,
|
||||
ModifierName + $" ({ModifierCategoryTitle})",
|
||||
ModifierWikiDescription,
|
||||
titleText,
|
||||
out var desc);
|
||||
var num = 0;
|
||||
if (WikiAbilities.Count != 0)
|
||||
{
|
||||
var grid = Object.Instantiate(parent.Inner, obj.transform);
|
||||
var layoutGroup = grid.GetComponent<GridLayoutGroup>();
|
||||
layoutGroup.startAxis = GridLayoutGroup.Axis.Vertical;
|
||||
layoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
|
||||
layoutGroup.spacing = new Vector2(0.75f, 0.4f);
|
||||
grid.DestroyChildren();
|
||||
foreach (var ability in WikiAbilities)
|
||||
{
|
||||
num++;
|
||||
var panel = Object.Instantiate(
|
||||
guide.MatchInfoRolePanelPrefab,
|
||||
grid);
|
||||
panel.roleCount.text = ability.AbilityType;
|
||||
panel.roleCount.transform.localPosition += new Vector3(-0.04f, 0);
|
||||
panel.roleName.text = ability.Name;
|
||||
panel.roleName.transform.localPosition += new Vector3(-0.04f, 0);
|
||||
panel.roleDescription.text = ability.Description;
|
||||
panel.roleDescription.rectTransform.sizeDelta = new Vector2(2.601f, 0.8f);
|
||||
panel.roleDescription.transform.localPosition += new Vector3(0, -0.1f);
|
||||
panel.roleIcon.sprite = ability.Icon.LoadAsset();
|
||||
panel.roleIcon.SetSizeLimit(0.13f);
|
||||
|
||||
panel.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50);
|
||||
panel.roleName.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f);
|
||||
panel.roleDescription.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f);
|
||||
panel.roleCount.fontMaterial.SetFloat(panel.STENCIL_NAME, 50f);
|
||||
panel.roleIcon.transform.localScale = new Vector3(3.5f, 3.5f, 1f);
|
||||
}
|
||||
|
||||
grid.localPosition = new Vector3(-3.9f, 1.1f - desc.textBounds.size.y, 0f);
|
||||
grid.localScale = new Vector3(1.3f, 1.3f, 1);
|
||||
}
|
||||
|
||||
obj.transform.SetParent(parent.Inner.transform);
|
||||
obj.transform.localPosition = new Vector3(0f, 0f, 0f);
|
||||
parent.SetYBoundsMax(Mathf.Clamp(desc.textBounds.size.y - 2 + Mathf.Ceil(num / 2f) * 1.45f, 0f, 999f));
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of abilities or other similar information to display below the text of a modifier's wiki page.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
public virtual List<AdvancedWikiAbilityDescription> WikiAbilities => [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the modifier icon. Useless if <see cref="HideOnUi"/> is <see langword="true"/>.
|
||||
/// </summary>
|
||||
public virtual LoadableAsset<Sprite>? ModifierIcon => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="TMP_SpriteAsset"/> for the Modifier Icon.
|
||||
/// </summary>
|
||||
[HideFromIl2Cpp]
|
||||
public virtual TMP_SpriteAsset IconTmp => null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the modifier is hidden on the UI. Will be hidden either way if no description is provided.
|
||||
/// </summary>
|
||||
@@ -69,6 +195,11 @@ public abstract class BaseModifier : IOptionable
|
||||
/// </summary>
|
||||
public virtual Color FreeplayFileColor => Color.gray;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Color"/> of the modifier, used in the wiki and other UI outside freeplay.
|
||||
/// </summary>
|
||||
public virtual Color GeneralColor => FreeplayFileColor;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the modifier is unique. If <see langword="true"/>, the player can only have one instance of this modifier.
|
||||
/// </summary>
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace MiraAPI.Modifiers.Types;
|
||||
[MiraIgnore]
|
||||
public abstract class GameModifier : BaseModifier
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override bool? ForceShowModifierOnWiki => null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool ShowInFreeplay => true;
|
||||
|
||||
|
||||
Reference in new issue
Block a user