Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions GenericModConfigMenu/Framework/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public void AddSectionTitle(IManifest mod, Func<string> text, Func<string> toolt
modConfig.AddOption(new SectionTitleModOption(text, tooltip, modConfig));
}

/// <inheritdoc />
public void AddSubHeader(IManifest mod, Func<string> text)
{
mod ??= this.mod;
this.AssertNotNull(text);

ModConfig modConfig = this.ConfigManager.Get(mod, assert: true);
modConfig.AddOption(new SectionSubHeaderModOption(text, modConfig));
}

/// <inheritdoc />
public void AddParagraph(IManifest mod, Func<string> text)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace GenericModConfigMenu.Framework.ModOption
{
/// <summary>A mod option which renders a sub-header in a config section.</summary>
internal class SectionSubHeaderModOption : ReadOnlyModOption
{
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="text">The title text to show in the form.</param>
/// <param name="mod">The mod config UI that contains this option.</param>
public SectionSubHeaderModOption(Func<string> text, ModConfig mod)
: base(text, null, mod) { }
}
}
9 changes: 9 additions & 0 deletions GenericModConfigMenu/Framework/SpecificModConfigMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ public SpecificModConfigMenu(ModConfig config, int scrollSpeed, string page, Act
optionElement = null;
break;

case SectionSubHeaderModOption _:
label.LocalPosition = new Vector2(-8, 0);
label.Bold = true;
label.Scale = 0.75f;
if (name == "")
label = null;
optionElement = null;
break;

case PageLinkModOption option:
label.Bold = true;
label.Callback = _ => this.OpenPage(option.PageId);
Expand Down
6 changes: 6 additions & 0 deletions GenericModConfigMenu/IGenericModConfigMenuApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public interface IGenericModConfigMenuApi
/// <param name="tooltip">The tooltip text shown when the cursor hovers on the title, or <c>null</c> to disable the tooltip.</param>
void AddSectionTitle(IManifest mod, Func<string> text, Func<string> tooltip = null);

/// <summary>Add a subheader at the current position in the form.</summary>
/// <remarks>Larger than paragraph, smaller than title.</remarks>
/// <param name="mod">The mod's manifest.</param>
/// <param name="text">The title text shown in the form.</param>
void AddSubHeader(IManifest mod, Func<string> text);

/// <summary>Add a paragraph of text at the current position in the form.</summary>
/// <param name="mod">The mod's manifest.</param>
/// <param name="text">The paragraph text to display.</param>
Expand Down
20 changes: 15 additions & 5 deletions SpaceShared/UI/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ class Label : Element
** Accessors
*********/
public bool Bold { get; set; } = false;
public float NonBoldScale { get; set; } = 1f; // Only applies when Bold = false
public float NonBoldScale
{
get => this.Scale;
set => this.Scale = value;
} // Maintained for compatibility

public bool NonBoldShadow { get; set; } = true; // Only applies when Bold = false
public Color IdleTextColor { get; set; } = Game1.textColor;
public Color HoverTextColor { get; set; } = Game1.unselectedOptionColor;

public SpriteFont Font { get; set; } = Game1.dialogueFont; // Only applies when Bold = false

public float Scale => this.Bold ? 1f : this.NonBoldScale;
public float Scale { get; set; } = 1.0f;

public string String { get; set; }

Expand Down Expand Up @@ -57,7 +62,7 @@ public override void Update(bool isOffScreen = false)
/// <summary>Measure the label's rendered dialogue text size.</summary>
public Vector2 Measure()
{
return Label.MeasureString(this.String, this.Bold, scale: this.Bold ? 1f : this.NonBoldScale, font: this.Font);
return Label.MeasureString(this.String, this.Bold, scale: this.Scale, font: this.Font);
}

/// <inheritdoc />
Expand All @@ -68,17 +73,22 @@ public override void Draw(SpriteBatch b)

bool altColor = this.Hover && this.Callback != null;
if (this.Bold)
{
float originalTextScale = SpriteText.fontPixelZoom;
SpriteText.fontPixelZoom *= this.Scale;
SpriteText.drawString(b, this.String, (int)this.Position.X, (int)this.Position.Y, layerDepth: 1, color: altColor ? SpriteText.color_Gray : null);
SpriteText.fontPixelZoom = originalTextScale;
}
else
{
Color col = altColor ? this.HoverTextColor : this.IdleTextColor;
if (col.A <= 0)
return;

if (this.NonBoldShadow)
Utility.drawTextWithShadow(b, this.String, this.Font, this.Position, col, this.NonBoldScale);
Utility.drawTextWithShadow(b, this.String, this.Font, this.Position, col, this.Scale);
else
b.DrawString(this.Font, this.String, this.Position, col, 0f, Vector2.Zero, this.NonBoldScale, SpriteEffects.None, 1);
b.DrawString(this.Font, this.String, this.Position, col, 0f, Vector2.Zero, this.Scale, SpriteEffects.None, 1);
}
}

Expand Down