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