quantum-space-buddies/QSB/Utility/UIHelper.cs

34 lines
877 B
C#
Raw Normal View History

2022-06-26 18:38:45 +00:00
using System.Linq;
2021-11-17 23:39:18 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.Utility;
2023-07-28 18:49:30 +00:00
public static class UIHelper
2021-11-17 23:39:18 +00:00
{
2022-03-03 03:46:33 +00:00
public static void ReplaceUI(UITextType key, string text)
2021-11-17 23:39:18 +00:00
{
2022-06-26 11:52:01 +00:00
DebugLog.DebugWrite($"Replacing UI text \"{key}\" with \"{text}\"");
2022-03-03 03:46:33 +00:00
var table = TextTranslation.Get().m_table;
table.theUITable[(int)key] = text;
}
2022-01-31 20:47:00 +00:00
2022-03-03 03:46:33 +00:00
public static UITextType AddToUITable(string text)
{
2022-06-26 18:59:58 +00:00
var hasValue = UITableHasValue(text);
if (hasValue != UITextType.None)
{
return hasValue;
}
2022-03-03 03:46:33 +00:00
var table = TextTranslation.Get().m_table;
var key = table.theUITable.Keys.Max() + 1;
table.theUITable[key] = text;
2022-06-26 11:52:01 +00:00
DebugLog.DebugWrite($"Added text \"{text}\" to the UI table with index {key}");
2022-03-03 03:46:33 +00:00
return (UITextType)key;
2021-11-17 23:39:18 +00:00
}
2022-06-26 11:52:01 +00:00
2022-06-26 18:59:58 +00:00
public static UITextType UITableHasValue(string text)
{
var table = TextTranslation.Get().m_table;
return (UITextType)table.theUITable.FirstOrDefault(x => x.Value == text).Key;
}
}