176 lines
6.0 KiB
C#
176 lines
6.0 KiB
C#
using System.Collections.Generic;
|
|
using Logic.Action;
|
|
using Logic.CrashSight;
|
|
using Logic.Multilingual;
|
|
using RuntimeData;
|
|
using TH1_Core.Events;
|
|
using TH1_Logic.Core;
|
|
using TH1_UI.HintUI;
|
|
using TH1Resource;
|
|
using TMPro;
|
|
using UI.HintUI;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TH1_UI.View.Info
|
|
{
|
|
public class UIInfoDiplomacyView : Base.View
|
|
{
|
|
public Button closeButton;
|
|
public TextMeshProUGUI Title;
|
|
public Image Avatar;
|
|
public Image WarStateBG;
|
|
public TextMeshProUGUI WarStateText;
|
|
|
|
public TextMeshProUGUI NoMeetText;
|
|
public TextMeshProUGUI RelationText;
|
|
public GameObject RelationBar;
|
|
public RectTransform RelationHandle;
|
|
public HintTrigger RelationHintText;
|
|
public GameObject BubbleChat;
|
|
public TextMeshProUGUI BubbleChatText;
|
|
|
|
public List<Transform> ActionList;
|
|
|
|
|
|
public ViDelegateAssisstant.Dele OnBtnCloseClick;
|
|
|
|
protected override void InitStart()
|
|
{
|
|
base.InitStart();
|
|
closeButton.onClick.RemoveAllListeners();
|
|
closeButton.onClick.AddListener(() => { OnBtnCloseClick.Invoke(); });
|
|
}
|
|
|
|
public void SetContent(uint pid)
|
|
{
|
|
if (!Main.MapData.PlayerMap.GetPlayerDataByPlayerID(pid, out var player)) return;
|
|
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out var info)) return;
|
|
var selfp = Main.MapData.PlayerMap.SelfPlayerData;
|
|
player.DiplomacyData.GetCountryDiplomacyInfo(selfp.Id, out var dipInfo);
|
|
var dipTable = Table.Instance.DiplomacyDataAssets;
|
|
|
|
//step #1 设置title
|
|
if (Title != null && Title.gameObject.GetComponent<MultilingualTextMono>() != null)
|
|
{
|
|
var mid = Title.gameObject.GetComponent<MultilingualTextMono>().ID;
|
|
var forceName = MultilingualManager.Instance.GetMultilingualText(uint.Parse(info.ForceName));
|
|
MultilingualManager.Instance.SetUIText(Title,mid.ToString(),new List<string>(){forceName});
|
|
}
|
|
|
|
//step #2 设置avatar和warstate
|
|
if (Avatar != null)
|
|
Avatar.sprite = info.LeaderIllustration;
|
|
if (WarStateBG != null && WarStateText!= null && dipTable.GetStateInfo(dipInfo.DiplomacyState,out var stateInfo))
|
|
{
|
|
WarStateBG.material = stateInfo.stateBGMat;
|
|
MultilingualManager.Instance.SetUIText(WarStateText,stateInfo.stateText) ;
|
|
}
|
|
|
|
//step #3 设置relation
|
|
if (NoMeetText != null && RelationHandle != null && RelationText != null && RelationBar != null && dipTable.GetFeelingInfo(dipInfo.FeelingState,out var feelingInfo))
|
|
{
|
|
//如果对方还未发现我们
|
|
if (dipInfo.DiplomacyState == DiplomacyState.NoDiplomacy)
|
|
{
|
|
NoMeetText.gameObject.SetActive(true);
|
|
RelationBar.SetActive(false);
|
|
RelationText.gameObject.SetActive(false);
|
|
}
|
|
//如果对方已经发现了我们
|
|
else
|
|
{
|
|
NoMeetText.gameObject.SetActive(false);
|
|
RelationBar.SetActive(true);
|
|
RelationText.gameObject.SetActive(true);
|
|
MultilingualManager.Instance.SetUIText(RelationText,feelingInfo.feelingText);
|
|
RelationText.color = feelingInfo.feelingColor;
|
|
RelationHandle.anchoredPosition = new Vector2(Mathf.Lerp(-330f, -30f, dipInfo.FeelingValue/100f),RelationHandle.anchoredPosition.y);
|
|
}
|
|
|
|
var text = "<color=yellow>对方认为您:</color><br>";
|
|
foreach (var op in dipInfo.FeelingStrategyList)
|
|
{
|
|
if (!Table.Instance.DiplomacyDataAssets.GetFeelingStragegyInfo(op, out var stgInfo)) continue;
|
|
text += $"<color=#{ColorUtility.ToHtmlStringRGB(stgInfo.FeelingStrategyColor)}>";
|
|
text += MultilingualManager.Instance.GetMultilingualText(uint.Parse(stgInfo.FeelingStrategyTitle));
|
|
text += "</color>:";
|
|
text += MultilingualManager.Instance.GetMultilingualText(uint.Parse(stgInfo.FeelingStrategyDesc));
|
|
text += "<br>";
|
|
}
|
|
|
|
RelationHintText.DataProvider.Text = text;
|
|
|
|
}
|
|
|
|
//step #4 设置Action List
|
|
foreach (var tr in ActionList)
|
|
if (tr.GetComponent<ActionIdMono>() != null)
|
|
{
|
|
var act = tr.GetComponent<ActionIdMono>().ActionId;
|
|
var actionParams = new CommonActionParams(
|
|
mapData: Main.MapData,
|
|
playerData: Main.MapData.PlayerMap.SelfPlayerData,
|
|
targetPlayer:player,
|
|
mainObjectType: MainObjectType.Player);
|
|
var actLogic = ActionLogicFactory.GetActionLogic(act);
|
|
//先设置是否显示按钮
|
|
tr.gameObject.SetActive(false);
|
|
if (actLogic.CheckShow(actionParams))
|
|
{
|
|
tr.gameObject.SetActive(true);
|
|
|
|
//决定具体显示按钮为什么颜色
|
|
var stt = actLogic.CheckShowState(actionParams);
|
|
var img = tr.GetComponent<Image>();
|
|
var star = tr.Find("Coin");
|
|
var cost = tr.Find("Cost")?.GetComponent<TextMeshProUGUI>();
|
|
if(img != null && star != null && cost != null)
|
|
switch (stt)
|
|
{
|
|
case ActionShowState.Unavailable:
|
|
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.ActionBGUnavailable;
|
|
star.gameObject.SetActive(false);
|
|
cost.gameObject.SetActive(false);
|
|
break;
|
|
case ActionShowState.Available:
|
|
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.ActionBGAvailable;
|
|
star.gameObject.SetActive(true);
|
|
cost.gameObject.SetActive(true);
|
|
cost.color = Color.white;
|
|
break;
|
|
case ActionShowState.Expensive:
|
|
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.ActionBGExpensive;
|
|
star.gameObject.SetActive(true);
|
|
cost.gameObject.SetActive(true);
|
|
cost.color = Color.red;
|
|
break;
|
|
case ActionShowState.Finished:
|
|
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.TechCompleteBackground;
|
|
star.gameObject.SetActive(false);
|
|
cost.gameObject.SetActive(false);
|
|
break;
|
|
}
|
|
//绑定点击事件
|
|
var btn = tr.GetComponent<Button>();
|
|
if (btn != null)
|
|
{
|
|
btn.onClick.RemoveAllListeners();
|
|
btn.onClick.AddListener(() =>
|
|
{
|
|
//如果成功执行,关闭当前窗口
|
|
if (actLogic.Execute(actionParams, false))
|
|
closeButton.onClick.Invoke();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
//Step #5 设置该玩家和其他玩家的关系
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|