forked from Shardstone/trail-into-darkness
added documentation, fixed some bugs
This commit is contained in:
@@ -2,25 +2,42 @@ using Jovian.PopupSystem.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Jovian.PopupSystem {
|
||||
/// <summary>
|
||||
/// Fluent API struct for building popup content. Operates directly on cached elements
|
||||
/// inside a <see cref="PopupReference"/> — no intermediate allocations. Received in
|
||||
/// the build callback passed to <see cref="IPopupSystem.Show"/>.
|
||||
/// </summary>
|
||||
public struct PopupContentBuilder {
|
||||
readonly PopupReference view;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a builder targeting the given popup reference.
|
||||
/// </summary>
|
||||
public PopupContentBuilder(PopupReference view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a header text element (bold, larger font).
|
||||
/// </summary>
|
||||
public PopupContentBuilder AddHeader(string text) {
|
||||
var header = view.GetHeader();
|
||||
header.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a body text element.
|
||||
/// </summary>
|
||||
public PopupContentBuilder AddText(string text) {
|
||||
var label = view.GetText();
|
||||
label.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a colored body text element. Hex color can be with or without the # prefix.
|
||||
/// </summary>
|
||||
public PopupContentBuilder AddText(string text, string hexColor) {
|
||||
var label = view.GetText();
|
||||
var prefix = hexColor.Length > 0 && hexColor[0] == '#' ? "" : "#";
|
||||
@@ -28,6 +45,9 @@ namespace Jovian.PopupSystem {
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a stat row with a label and integer value.
|
||||
/// </summary>
|
||||
public PopupContentBuilder AddStat(string label, int value) {
|
||||
var (labelText, valueText) = view.GetStat();
|
||||
labelText.text = label;
|
||||
@@ -35,6 +55,9 @@ namespace Jovian.PopupSystem {
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a stat row with a label and string value.
|
||||
/// </summary>
|
||||
public PopupContentBuilder AddStat(string label, string value) {
|
||||
var (labelText, valueText) = view.GetStat();
|
||||
labelText.text = label;
|
||||
@@ -42,6 +65,9 @@ namespace Jovian.PopupSystem {
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an image element with the given sprite and optional height.
|
||||
/// </summary>
|
||||
public PopupContentBuilder AddImage(Sprite sprite, float height = 64f) {
|
||||
var image = view.GetImage();
|
||||
image.sprite = sprite;
|
||||
@@ -50,6 +76,9 @@ namespace Jovian.PopupSystem {
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a horizontal separator line.
|
||||
/// </summary>
|
||||
public PopupContentBuilder AddSeparator() {
|
||||
view.GetSeparator();
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user