UI HUGE UPDATE
This commit is contained in:
@@ -0,0 +1,270 @@
|
||||
using System.Text;
|
||||
using Bansonic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TeamShareApplyPanel : MonoBehaviour
|
||||
{
|
||||
[Header("Inputs")]
|
||||
[SerializeField] private InputField schemeNameInputField;
|
||||
[SerializeField] private InputField shareCodeInputField;
|
||||
|
||||
[Header("Buttons")]
|
||||
[SerializeField] private Button copyButton;
|
||||
[SerializeField] private Button applyButton;
|
||||
|
||||
[Header("Config")]
|
||||
[SerializeField] private bool autoRefreshShareCode = true;
|
||||
|
||||
private string lockedVisibleSchemeName;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
BindUiEvents();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
RefreshShareCodeDisplay();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
UnbindUiEvents();
|
||||
}
|
||||
|
||||
public void RefreshShareCodeDisplay()
|
||||
{
|
||||
if (!autoRefreshShareCode || shareCodeInputField == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string shareCode;
|
||||
string errorMessage;
|
||||
if (!TeamShareCodec.TryExportCurrentTeam(GetSchemeNameOrDefault(), out shareCode, out errorMessage))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(errorMessage))
|
||||
{
|
||||
gNotice.error.display(errorMessage);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureLockedVisibleSchemeName();
|
||||
shareCodeInputField.text = ReplaceVisibleSchemeName(shareCode, lockedVisibleSchemeName);
|
||||
}
|
||||
|
||||
public void HandleCopyClicked()
|
||||
{
|
||||
if (shareCodeInputField == null)
|
||||
{
|
||||
gNotice.error.display("\u672a\u914d\u7f6e\u7f16\u961f\u7801\u8f93\u5165\u6846");
|
||||
return;
|
||||
}
|
||||
|
||||
string content = string.IsNullOrWhiteSpace(shareCodeInputField.text) ? string.Empty : shareCodeInputField.text.Trim();
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
RefreshShareCodeDisplay();
|
||||
content = string.IsNullOrWhiteSpace(shareCodeInputField.text) ? string.Empty : shareCodeInputField.text.Trim();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
gNotice.error.display("\u5f53\u524d\u6ca1\u6709\u53ef\u590d\u5236\u7684\u7f16\u961f\u7801");
|
||||
return;
|
||||
}
|
||||
|
||||
GUIUtility.systemCopyBuffer = content;
|
||||
gNotice.recommendation.display("\u5df2\u590d\u5236\u7f16\u961f\u5206\u4eab\u7801");
|
||||
}
|
||||
|
||||
public void HandleApplyClicked()
|
||||
{
|
||||
if (shareCodeInputField == null)
|
||||
{
|
||||
gNotice.error.display("\u672a\u914d\u7f6e\u7f16\u961f\u7801\u8f93\u5165\u6846");
|
||||
return;
|
||||
}
|
||||
|
||||
string content = string.IsNullOrWhiteSpace(shareCodeInputField.text) ? string.Empty : shareCodeInputField.text.Trim();
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
gNotice.error.display("\u8bf7\u8f93\u5165\u7f16\u961f\u5206\u4eab\u7801");
|
||||
return;
|
||||
}
|
||||
|
||||
TeamShareApplyReport report;
|
||||
string errorMessage;
|
||||
if (!TeamShareCodec.TryApplyToCurrentTeam(content, out report, out errorMessage))
|
||||
{
|
||||
gNotice.error.display(string.IsNullOrWhiteSpace(errorMessage) ? "\u7f16\u961f\u7801\u5e94\u7528\u5931\u8d25" : errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
lockedVisibleSchemeName = ExtractVisibleSchemeName(content);
|
||||
if (schemeNameInputField != null && !string.IsNullOrWhiteSpace(report.schemeName))
|
||||
{
|
||||
schemeNameInputField.text = report.schemeName;
|
||||
}
|
||||
|
||||
RefreshShareCodeDisplay();
|
||||
|
||||
if (report != null && report.messages != null && report.messages.Count > 0)
|
||||
{
|
||||
gNotice.error.display(BuildSkipReasonText(report));
|
||||
return;
|
||||
}
|
||||
|
||||
gNotice.recommendation.display("\u5df2\u5e94\u7528\u7f16\u961f\u5206\u4eab\u7801");
|
||||
}
|
||||
|
||||
private void HandleSchemeNameChanged(string _)
|
||||
{
|
||||
RefreshShareCodeDisplay();
|
||||
}
|
||||
|
||||
private void BindUiEvents()
|
||||
{
|
||||
UnbindUiEvents();
|
||||
|
||||
if (copyButton != null)
|
||||
{
|
||||
copyButton.onClick.AddListener(HandleCopyClicked);
|
||||
}
|
||||
|
||||
if (applyButton != null)
|
||||
{
|
||||
applyButton.onClick.AddListener(HandleApplyClicked);
|
||||
}
|
||||
|
||||
if (schemeNameInputField != null)
|
||||
{
|
||||
schemeNameInputField.onValueChanged.AddListener(HandleSchemeNameChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void UnbindUiEvents()
|
||||
{
|
||||
if (copyButton != null)
|
||||
{
|
||||
copyButton.onClick.RemoveListener(HandleCopyClicked);
|
||||
}
|
||||
|
||||
if (applyButton != null)
|
||||
{
|
||||
applyButton.onClick.RemoveListener(HandleApplyClicked);
|
||||
}
|
||||
|
||||
if (schemeNameInputField != null)
|
||||
{
|
||||
schemeNameInputField.onValueChanged.RemoveListener(HandleSchemeNameChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetSchemeNameOrDefault()
|
||||
{
|
||||
if (schemeNameInputField == null || string.IsNullOrWhiteSpace(schemeNameInputField.text))
|
||||
{
|
||||
return TeamShareSnapshot.DefaultSchemeName;
|
||||
}
|
||||
|
||||
return schemeNameInputField.text;
|
||||
}
|
||||
|
||||
private void EnsureLockedVisibleSchemeName()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(lockedVisibleSchemeName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (shareCodeInputField != null && !string.IsNullOrWhiteSpace(shareCodeInputField.text))
|
||||
{
|
||||
lockedVisibleSchemeName = ExtractVisibleSchemeName(shareCodeInputField.text);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lockedVisibleSchemeName))
|
||||
{
|
||||
lockedVisibleSchemeName = GetSchemeNameOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private static string ReplaceVisibleSchemeName(string shareCode, string visibleSchemeName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(shareCode))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
int splitIndex = FindPrefixSplitIndex(shareCode);
|
||||
if (splitIndex < 0)
|
||||
{
|
||||
return shareCode;
|
||||
}
|
||||
|
||||
string safeVisibleName = string.IsNullOrWhiteSpace(visibleSchemeName) ? TeamShareSnapshot.DefaultSchemeName : visibleSchemeName.Trim();
|
||||
return safeVisibleName + shareCode.Substring(splitIndex);
|
||||
}
|
||||
|
||||
private static string ExtractVisibleSchemeName(string shareCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(shareCode))
|
||||
{
|
||||
return TeamShareSnapshot.DefaultSchemeName;
|
||||
}
|
||||
|
||||
int splitIndex = FindPrefixSplitIndex(shareCode);
|
||||
if (splitIndex <= 0)
|
||||
{
|
||||
return TeamShareSnapshot.DefaultSchemeName;
|
||||
}
|
||||
|
||||
return shareCode.Substring(0, splitIndex);
|
||||
}
|
||||
|
||||
private static int FindPrefixSplitIndex(string shareCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(shareCode))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int index = shareCode.IndexOf("-T3", System.StringComparison.Ordinal);
|
||||
if (index >= 0)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
index = shareCode.IndexOf("-TS3", System.StringComparison.Ordinal);
|
||||
if (index >= 0)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
index = shareCode.IndexOf("-BT2", System.StringComparison.Ordinal);
|
||||
if (index >= 0)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
index = shareCode.IndexOf("-BT1", System.StringComparison.Ordinal);
|
||||
return index;
|
||||
}
|
||||
|
||||
private static string BuildSkipReasonText(TeamShareApplyReport report)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append("\u7f16\u961f\u7801\u5df2\u90e8\u5206\u5e94\u7528\uff0c\u4ee5\u4e0b\u5185\u5bb9\u88ab\u8df3\u8fc7\uff1a");
|
||||
|
||||
for (int i = 0; i < report.messages.Count; i++)
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(report.messages[i]);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user