forked from Shardstone/trail-into-darkness
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Jovian.PopupSystem.UI;
|
|
using UnityEngine;
|
|
|
|
namespace Jovian.PopupSystem {
|
|
public struct PopupContentBuilder {
|
|
readonly PopupReference view;
|
|
|
|
public PopupContentBuilder(PopupReference view) {
|
|
this.view = view;
|
|
}
|
|
|
|
public PopupContentBuilder AddHeader(string text) {
|
|
var header = view.GetHeader();
|
|
header.text = text;
|
|
return this;
|
|
}
|
|
|
|
public PopupContentBuilder AddText(string text) {
|
|
var label = view.GetText();
|
|
label.text = text;
|
|
return this;
|
|
}
|
|
|
|
public PopupContentBuilder AddText(string text, string hexColor) {
|
|
var label = view.GetText();
|
|
var prefix = hexColor.Length > 0 && hexColor[0] == '#' ? "" : "#";
|
|
label.text = $"<color={prefix}{hexColor}>{text}</color>";
|
|
return this;
|
|
}
|
|
|
|
public PopupContentBuilder AddStat(string label, int value) {
|
|
var (labelText, valueText) = view.GetStat();
|
|
labelText.text = label;
|
|
valueText.text = value.ToString();
|
|
return this;
|
|
}
|
|
|
|
public PopupContentBuilder AddStat(string label, string value) {
|
|
var (labelText, valueText) = view.GetStat();
|
|
labelText.text = label;
|
|
valueText.text = value;
|
|
return this;
|
|
}
|
|
|
|
public PopupContentBuilder AddImage(Sprite sprite, float height = 64f) {
|
|
var image = view.GetImage();
|
|
image.sprite = sprite;
|
|
var rt = (RectTransform)image.transform;
|
|
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
|
|
return this;
|
|
}
|
|
|
|
public PopupContentBuilder AddSeparator() {
|
|
view.GetSeparator();
|
|
return this;
|
|
}
|
|
}
|
|
}
|