133 lines
3.5 KiB
C#
133 lines
3.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Logic.Multilingual;
|
|
using TH1_Logic.Core;
|
|
using TH1_Logic.Net;
|
|
using TH1_Logic.Steam;
|
|
using TH1_UI.View.Outside;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIOutsideSelectAvatarMono : MonoBehaviour
|
|
{
|
|
|
|
|
|
public Image AvatarImg;
|
|
public GameObject ChatBox;
|
|
public Button Button;
|
|
public TextMeshProUGUI ChatText;
|
|
public TextMeshProUGUI Title;
|
|
public GameObject SelectBG;
|
|
public Empire PlayerEmpire => _playerEmpire;
|
|
public bool IsRandom => _isRandom;
|
|
|
|
private Action<Empire> _onButtonClick;
|
|
private Action<UIOutsideSelectAvatarMono> _onRandomButtonClick;
|
|
private Empire _playerEmpire;
|
|
private bool _hasChatContent;
|
|
private bool _isRandom;
|
|
|
|
|
|
|
|
public void SetContent(Empire t,Action<Empire> OnButtonClick)
|
|
{
|
|
_isRandom = false;
|
|
_playerEmpire = t;
|
|
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(t.Civ, t.Force, out var info)) return;
|
|
AvatarImg.sprite = info.LeaderAvatar;
|
|
_onButtonClick = OnButtonClick;
|
|
_onRandomButtonClick = null;
|
|
var startChat = info.GetRandomStartChat();
|
|
_hasChatContent = startChat != "0" && !string.IsNullOrEmpty(startChat);
|
|
ChatBox.SetActive(false);
|
|
if (_hasChatContent)
|
|
{
|
|
MultilingualManager.Instance.SetUIText(ChatText, startChat);
|
|
}
|
|
SetTextOrRaw(Title, info.ForceName);
|
|
SelectBG.SetActive(false);
|
|
Button.onClick.RemoveAllListeners();
|
|
Button.onClick.AddListener(()=>
|
|
{
|
|
SetShow();
|
|
_onButtonClick.Invoke(_playerEmpire);
|
|
});
|
|
}
|
|
|
|
public void SetRandomContent(Sprite randomAvatar, string titleText, Action<UIOutsideSelectAvatarMono> onButtonClick)
|
|
{
|
|
_isRandom = true;
|
|
_playerEmpire = default;
|
|
if (AvatarImg != null) AvatarImg.sprite = randomAvatar;
|
|
_onButtonClick = null;
|
|
_onRandomButtonClick = onButtonClick;
|
|
_hasChatContent = false;
|
|
if (ChatBox != null) ChatBox.SetActive(false);
|
|
SetTextOrRaw(Title, titleText);
|
|
if (SelectBG != null) SelectBG.SetActive(false);
|
|
Button.onClick.RemoveAllListeners();
|
|
Button.onClick.AddListener(() =>
|
|
{
|
|
SetShow();
|
|
_onRandomButtonClick?.Invoke(this);
|
|
});
|
|
}
|
|
|
|
private static void SetTextOrRaw(TextMeshProUGUI text, string value)
|
|
{
|
|
if (text == null) return;
|
|
|
|
var multilingual = text.gameObject.GetComponent<MultilingualTextMono>();
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
if (multilingual != null)
|
|
{
|
|
multilingual.ID = 0;
|
|
multilingual.Ban = true;
|
|
}
|
|
text.text = string.Empty;
|
|
return;
|
|
}
|
|
|
|
if (uint.TryParse(value, out _))
|
|
{
|
|
if (multilingual != null) multilingual.Ban = false;
|
|
MultilingualManager.Instance.SetUIText(text, value);
|
|
return;
|
|
}
|
|
|
|
if (multilingual != null)
|
|
{
|
|
multilingual.ID = 0;
|
|
multilingual.Ban = true;
|
|
}
|
|
text.text = value;
|
|
}
|
|
|
|
public void SetShow()
|
|
{
|
|
ChatBox.SetActive(_hasChatContent);
|
|
SelectBG.SetActive(true);
|
|
}
|
|
|
|
public void SetHide()
|
|
{
|
|
ChatBox.SetActive(false);
|
|
SelectBG.SetActive(false);
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|