278 lines
10 KiB
C#
278 lines
10 KiB
C#
using System.Collections.Generic;
|
||
using Logic;
|
||
using Logic.Action;
|
||
using Logic.Audio;
|
||
using Logic.CrashSight;
|
||
using Logic.Multilingual;
|
||
using RuntimeData;
|
||
using TH1_Core.Events;
|
||
using TH1_Logic.Core;
|
||
using TH1_UI.Components;
|
||
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 Transform DiplomacyBaseInfo;
|
||
public Transform ActionArea;
|
||
|
||
|
||
|
||
public TextMeshProUGUI NoMeetText;
|
||
public GameObject RelationSubArea;
|
||
public TextMeshProUGUI RelationText;
|
||
public GameObject RelationBar;
|
||
public RectTransform RelationHandle;
|
||
public HintTrigger RelationHintText;
|
||
public GameObject BubbleChat;
|
||
public TextMeshProUGUI BubbleChatText;
|
||
|
||
public List<Transform> ActionList;
|
||
|
||
|
||
public TextMeshProUGUI OtherRelationTitle;
|
||
public List<UIInfoDiplomacyAvatarMono> OtherRelationAvatarList;
|
||
public Transform OtherRelationRow1;
|
||
public Transform OtherRelationRow2;
|
||
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.GetCountryDiplomacyInfo(selfp.Id, out var dipInfo);
|
||
var dipTable = Table.Instance.DiplomacyDataAssets;
|
||
var forceName = MultilingualManager.Instance.GetMultilingualText(uint.Parse(info.ForceName));
|
||
|
||
//step #1 设置title
|
||
if (Title != null)
|
||
{
|
||
var titleText = (pid == Main.MapData.PlayerMap.SelfPlayerData.Id) ? Table.Instance.DiplomacyDataAssets.DiplomacyUITitleSelf:Table.Instance.DiplomacyDataAssets.DiplomacyUITitle;
|
||
MultilingualManager.Instance.SetUIText(Title,titleText,new List<string>{forceName});
|
||
}
|
||
|
||
//然后进入设置关系和actionArea阶段,这里要分未自身和其他玩家 两个part来处理
|
||
//如果不是真人玩家自身,而是别人
|
||
if (pid != Main.MapData.PlayerMap.SelfPlayerData.Id)
|
||
{
|
||
DiplomacyBaseInfo?.gameObject.SetActive(true);
|
||
ActionArea?.gameObject.SetActive(true);
|
||
//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);
|
||
RelationSubArea.SetActive(false);
|
||
BubbleChat.SetActive(false);
|
||
|
||
}
|
||
//如果对方已经发现了我们
|
||
else
|
||
{
|
||
NoMeetText.gameObject.SetActive(false);
|
||
RelationSubArea.SetActive(true);
|
||
BubbleChat.SetActive(true);
|
||
MultilingualManager.Instance.SetUIText(RelationText,feelingInfo.feelingText);
|
||
MultilingualManager.Instance.SetUIText(BubbleChatText,Table.Instance.DiplomacyDataAssets.GetDiplomacyTextByFeeling((Forces)(player.PlayerForceId),dipInfo.FeelingState));
|
||
RelationText.color = feelingInfo.feelingColor;
|
||
RelationHandle.anchoredPosition = new Vector2(Mathf.Lerp(-330f, -30f, dipInfo.FeelingValue/100f),RelationHandle.anchoredPosition.y);
|
||
}
|
||
|
||
var text = $"<color=yellow>对方认为您:</color><br>"; //({dipInfo.FeelingValue})
|
||
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)
|
||
switch (stt)
|
||
{
|
||
case ActionShowState.Unavailable:
|
||
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.ActionBGUnavailable;
|
||
if(star != null)star.gameObject.SetActive(false);
|
||
if(cost != null)cost.gameObject.SetActive(false);
|
||
break;
|
||
case ActionShowState.Available:
|
||
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.ActionBGAvailable;
|
||
if (star != null)star.gameObject.SetActive(true);
|
||
if (cost != null)
|
||
{
|
||
cost.gameObject.SetActive(true);
|
||
cost.color = Color.white;
|
||
}
|
||
|
||
break;
|
||
case ActionShowState.Expensive:
|
||
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.ActionBGExpensive;
|
||
if (star != null)star.gameObject.SetActive(true);
|
||
if (cost != null)
|
||
{
|
||
cost.gameObject.SetActive(true);
|
||
cost.color = Color.red;
|
||
}
|
||
|
||
break;
|
||
case ActionShowState.Finished:
|
||
tr.GetComponent<Image>().sprite = ResourceCache.Instance.SpriteCache.TechCompleteBackground;
|
||
if (star != null)star.gameObject.SetActive(false);
|
||
if (cost != null)cost.gameObject.SetActive(false);
|
||
break;
|
||
}
|
||
//绑定点击事件
|
||
var btn = tr.GetComponent<Button>();
|
||
if (btn != null)
|
||
{
|
||
btn.onClick.RemoveAllListeners();
|
||
btn.onClick.AddListener(() =>
|
||
{
|
||
//只有轮到我行动的时候,点击才生效
|
||
if (actionParams.MapData.CurPlayer == Main.MapData.PlayerMap.SelfPlayerData)
|
||
{
|
||
actLogic.CompleteExecute(actionParams);
|
||
}
|
||
|
||
//不用关闭窗口,因为执行成功后会通过事件通知这里来关闭
|
||
/*if ()
|
||
//如果成功执行,关闭当前窗口
|
||
closeButton.onClick.Invoke();*/
|
||
});
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//如果是真人玩家自身
|
||
else
|
||
{
|
||
DiplomacyBaseInfo?.gameObject.SetActive(false);
|
||
ActionArea?.gameObject.SetActive(false);
|
||
}
|
||
|
||
//Step #5 设置该玩家和其他玩家的关系
|
||
if (OtherRelationAvatarList != null && OtherRelationRow1 != null && OtherRelationRow2 != null)
|
||
{
|
||
//判断鲁棒性
|
||
if (player.MeetPlayers.Count - 1 > OtherRelationAvatarList.Count) return;
|
||
int rk = 0;
|
||
//设置标题
|
||
|
||
if (OtherRelationTitle != null)
|
||
MultilingualManager.Instance.SetUIText(OtherRelationTitle,
|
||
Table.Instance.DiplomacyDataAssets.DiplomacyUIOtherRelationTitle,new List<string>{forceName});
|
||
|
||
|
||
//依次设置pid对她的每一个pid2的外交关系
|
||
foreach (var pid2 in player.MeetPlayers)
|
||
{
|
||
if (pid2 == pid) continue;
|
||
OtherRelationAvatarList[rk].gameObject.SetActive(true);
|
||
if(!Main.MapData.PlayerMap.GetPlayerDataByPlayerID(pid2,out var player2))continue;
|
||
if (!player2.Alive) continue;
|
||
if(!Table.Instance.PlayerDataAssets.GetPlayerInfo(player2, out var player2Info))continue;
|
||
player.GetCountryDiplomacyInfo(pid2, out var dipInfo2);
|
||
if(!Table.Instance.DiplomacyDataAssets.GetStateInfo(dipInfo2.DiplomacyState, out var stateInfo2))continue;
|
||
|
||
//设置名字、头像、外交状态
|
||
if(Main.MapData.PlayerMap.SelfPlayerData.MeetPlayers.Contains(pid2)){
|
||
MultilingualManager.Instance.SetUIText(OtherRelationAvatarList[rk].Title, player2Info.ForceName);
|
||
if(OtherRelationAvatarList[rk].Avatar != null)
|
||
OtherRelationAvatarList[rk].Avatar.sprite = player2Info.LeaderIllustration;
|
||
if(OtherRelationAvatarList[rk].RelationStateBG != null)
|
||
OtherRelationAvatarList[rk].RelationStateBG.material = stateInfo2.stateBGMat;
|
||
if(OtherRelationAvatarList[rk].RelationStateText)
|
||
MultilingualManager.Instance.SetUIText(OtherRelationAvatarList[rk].RelationStateText ,stateInfo2.stateText);
|
||
}
|
||
else
|
||
{
|
||
MultilingualManager.Instance.SetUIText(OtherRelationAvatarList[rk].Title, Table.Instance.DiplomacyDataAssets.NoMeetPlayerName);
|
||
if(OtherRelationAvatarList[rk].Avatar != null)
|
||
OtherRelationAvatarList[rk].Avatar.sprite = Table.Instance.PlayerDataAssets.CommonPlayerAvatar;
|
||
if(OtherRelationAvatarList[rk].RelationStateBG != null)
|
||
OtherRelationAvatarList[rk].RelationStateBG.material = stateInfo2.stateBGMat;
|
||
if(OtherRelationAvatarList[rk].RelationStateText)
|
||
MultilingualManager.Instance.SetUIText(OtherRelationAvatarList[rk].RelationStateText ,stateInfo2.stateText);
|
||
}
|
||
rk++;
|
||
}
|
||
OtherRelationRow1.gameObject.SetActive(true);
|
||
OtherRelationRow2.gameObject.SetActive(player.MeetPlayers.Count - 1 > 4);
|
||
|
||
for(;rk < OtherRelationAvatarList.Count;rk++)
|
||
OtherRelationAvatarList[rk].gameObject.SetActive(false);
|
||
}
|
||
|
||
|
||
//Step #6 设置BGM
|
||
AudioManager.Instance.PlayMusic(info.MusicName,1f,2f,true);
|
||
}
|
||
|
||
public void CloseView()
|
||
{
|
||
AudioManager.Instance.StopMusic();
|
||
}
|
||
}
|
||
|
||
}
|