| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using Cysharp.Threading.Tasks; |
| | | using DG.Tweening; |
| | | using System.Text; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | |
| | | [SerializeField] Text guildNameText; |
| | | [SerializeField] Text guildMemberCountText; |
| | | [SerializeField] Button rankBtn; |
| | | |
| | | |
| | | |
| | | [SerializeField] Button storeBtn; |
| | | [SerializeField] RichText talkInfoText; |
| | | [SerializeField] Button talkBtn; |
| | | [SerializeField] Button talkBtn1; |
| | | [SerializeField] Button requestBtn; |
| | | |
| | | |
| | | //NPC对话相关 |
| | | [Header("行商必须放第一个")] |
| | | [SerializeField] HeroSkinModel[] funcNPCs; |
| | | [SerializeField] Transform[] talkRects; |
| | | [SerializeField] Text[] talkTexts; |
| | | |
| | | //行商特殊处理 |
| | | [SerializeField] Transform hawkerRect; |
| | | [SerializeField] Transform pos1; |
| | | [SerializeField] Transform pos2; |
| | | [SerializeField] UIHeroController hawkerModel; |
| | | |
| | | protected override void InitComponent() |
| | | { |
| | |
| | | |
| | | requestBtn.AddListener(() => |
| | | { |
| | | // UIManager.Instance.OpenWindow<GuildRequestWin>(); |
| | | UIManager.Instance.OpenWindow<GuildApplyListWin>(); |
| | | }); |
| | | |
| | | |
| | | guildHawkerBtn.AddListener(OpenHawker); |
| | | storeBtn.AddListener(() => |
| | | { |
| | | StoreModel.Instance.selectStoreFuncType = StoreFunc.Guild; |
| | | UIManager.Instance.OpenWindow<StoreBaseWin>(); |
| | | }); |
| | | rankBtn.AddListener(() => |
| | | { |
| | | UIManager.Instance.OpenWindow<GuildRankWin>(); |
| | | }); |
| | | InitHawker(); |
| | | talkBtn.AddListener(OnClickTalkButton); |
| | | talkBtn1.AddListener(OnClickTalkButton); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if (PlayerDatas.Instance.fairyData.fairy == null) |
| | | return; |
| | | GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; |
| | | |
| | | GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; |
| | | GlobalTimeEvent.Instance.fiveSecondEvent += OnFiveSecondEvent; |
| | | ChatManager.Instance.OnUpdateTalkEvent += OnUpdateTalkEvent; |
| | | PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo; |
| | | Display(); |
| | | } |
| | | |
| | | protected override void OnPreClose() |
| | | { |
| | | GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; |
| | | GlobalTimeEvent.Instance.fiveSecondEvent -= OnFiveSecondEvent; |
| | | ChatManager.Instance.OnUpdateTalkEvent -= OnUpdateTalkEvent; |
| | | PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo; |
| | | } |
| | | |
| | | void OnRefreshFairyInfo() |
| | | { |
| | | ShowGuildInfo(); |
| | | } |
| | | |
| | | private void OnUpdateTalkEvent(ChatChannel channel, TalkData data, bool isSendBullet) |
| | | { |
| | | if (channel != ChatChannel.Guild) |
| | | return; |
| | | ShowTalkInfo(); |
| | | } |
| | | |
| | | void Display() |
| | | { |
| | | ShowGuildInfo(); |
| | | ShowHawkerTime(); |
| | | ShowTalkInfo(); |
| | | } |
| | | |
| | | void OnSecondEvent() |
| | | { |
| | | ShowHawkerTime(); |
| | | ShowHawkerTime(true); |
| | | } |
| | | |
| | | void ShowGuildInfo() |
| | | { |
| | | emblemCell.Display(PlayerDatas.Instance.fairyData.fairy.EmblemID, PlayerDatas.Instance.fairyData.fairy.EmblemWord, 0.5f); |
| | | requestBtn.SetActive(PlayerDatas.Instance.fairyData.HasFairy && PlayerDatas.Instance.fairyData.IsCanFunc(LimitFunc.CanCall)); |
| | | emblemCell.Display(PlayerDatas.Instance.fairyData.fairy.EmblemID, PlayerDatas.Instance.fairyData.fairy.EmblemWord, 0.8f); |
| | | guildNameText.text = PlayerDatas.Instance.fairyData.fairy.FamilyName; |
| | | var config = FamilyConfig.Get(PlayerDatas.Instance.fairyData.fairy.FamilyLV); |
| | | guildMemberCountText.text = PlayerDatas.Instance.fairyData.fairy.MemberCount + "/" + config.MemberMax; |
| | |
| | | |
| | | void OpenHawker() |
| | | { |
| | | if (TimeUtility.GetToTenClockSeconds() > 0) |
| | | if (TimeUtility.GetToTheHourSeconds() > 0) |
| | | { |
| | | SysNotifyMgr.Instance.ShowTip("GuildSys17"); |
| | | return; |
| | |
| | | UIManager.Instance.OpenWindow<GuildHawkerWin>(); |
| | | } |
| | | |
| | | void ShowHawkerTime() |
| | | void ShowHawkerTime(bool modelPlay = false) |
| | | { |
| | | var toTenSeconds = TimeUtility.GetToTenClockSeconds(); |
| | | var toTenSeconds = TimeUtility.GetToTheHourSeconds(); |
| | | if (toTenSeconds > 0) |
| | | { |
| | | guildHawkerTimeText.text = TimeUtility.SecondsToHMS(toTenSeconds); |
| | | guildHawkerInfo.SetActive(true); |
| | | var addStr = new string('.', (int)Time.time % 4); |
| | | guildHawkerInfo.text = Language.Get("Guild_72") + addStr; |
| | | if (modelPlay) |
| | | HawkerMove(false); |
| | | } |
| | | else |
| | | { |
| | | guildHawkerTimeText.text = TimeUtility.SecondsToHMS((int)(TimeUtility.GetTodayEndTime() - TimeUtility.ServerNow).TotalSeconds); |
| | | guildHawkerInfo.SetActive(false); |
| | | if (modelPlay) |
| | | HawkerMove(true); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | void InitHawker() |
| | | { |
| | | if (FuncNPCManager.Instance.isHawkerStandBy) |
| | | { |
| | | hawkerRect.localPosition = pos1.localPosition; |
| | | } |
| | | else |
| | | { |
| | | hawkerRect.localPosition = pos2.localPosition; |
| | | } |
| | | // hawkerModel.PlayAnimation("zoulu", true); |
| | | } |
| | | |
| | | //isShow true走出来,false走出去 |
| | | void HawkerMove(bool isShow) |
| | | { |
| | | if (isShow == FuncNPCManager.Instance.isHawkerShowNow) |
| | | { |
| | | return; |
| | | } |
| | | FuncNPCManager.Instance.isHawkerShowNow = isShow; |
| | | hawkerModel.PlayAnimation("zoulu", true); |
| | | FuncNPCManager.Instance.isHawkerStandBy = false; |
| | | hawkerModel.transform.localScale = new Vector3(isShow ? Math.Abs(hawkerModel.transform.localScale.x) : -Math.Abs(hawkerModel.transform.localScale.x), hawkerModel.transform.localScale.y, hawkerModel.transform.localScale.z); |
| | | hawkerRect.DOLocalMove(isShow ? pos1.localPosition : pos2.localPosition, 1f).onComplete = () => |
| | | { |
| | | hawkerModel.PlayAnimation("idle", true); |
| | | |
| | | FuncNPCManager.Instance.isHawkerStandBy = isShow; |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //NPC对话相关 |
| | | void OnFiveSecondEvent() |
| | | { |
| | | var index = FuncNPCManager.Instance.GetRandomGuildNpcTalk(); |
| | | if (index == -1) |
| | | { |
| | | return; |
| | | } |
| | | var talk = FuncNPCManager.Instance.GetGuildTalk(funcNPCs[index].heroSkinID); |
| | | if (talk != null) |
| | | { |
| | | talkTexts[index].text = Language.Get(talk); |
| | | talkRects[index].SetActive(true); |
| | | } |
| | | |
| | | var npc = funcNPCs[index].GetModel(); |
| | | npc.PlayAnimation("hanhua", true); |
| | | Talk(index).Forget(); |
| | | } |
| | | |
| | | async UniTask Talk(int index) |
| | | { |
| | | await UniTask.Delay(5000); |
| | | talkRects[index].SetActive(false); |
| | | var npc = funcNPCs[index].GetModel(); |
| | | npc.PlayAnimation("idle", true); |
| | | } |
| | | |
| | | public void OnClickTalkButton() |
| | | { |
| | | ChatManager.Instance.nowChatTab = ChatChannel.Guild; |
| | | ChatManager.Instance.nowChatChannel = ChatChannel.Guild; |
| | | UIManager.Instance.OpenWindow<ChatWin>(); |
| | | } |
| | | |
| | | public string GetGuildChatAreaContent(TalkData talkData) |
| | | { |
| | | int type = ChatManager.Instance.GetTalkDataType(talkData); |
| | | if (type == 0) |
| | | { |
| | | return Language.Get("L1100", Language.Get("Chat13"), talkData.Content); |
| | | } |
| | | else if (type == 1) |
| | | { |
| | | return Language.Get("L1100", Language.Get("Chat13"), talkData.Content); |
| | | } |
| | | else |
| | | { |
| | | return Language.Get("L1100", talkData.Name, talkData.Content); |
| | | } |
| | | } |
| | | |
| | | public Color32 GetGuildChatAreaColor(TalkData talkData) |
| | | { |
| | | int type = ChatManager.Instance.GetTalkDataType(talkData); |
| | | if (type == 2) |
| | | { |
| | | return ChatManager.Instance.areaMyColor; |
| | | } |
| | | else |
| | | { |
| | | return ChatManager.Instance.areaOtherColor; |
| | | } |
| | | } |
| | | |
| | | List<TalkData> showTalkDatas = new List<TalkData>(); |
| | | void ShowTalkInfo() |
| | | { |
| | | if (!ChatManager.Instance.TryGetTalkData(ChatChannel.Guild, out List<TalkData> datas) || datas.IsNullOrEmpty()) |
| | | { |
| | | talkInfoText.text = string.Empty; |
| | | return; |
| | | } |
| | | showTalkDatas.Clear(); |
| | | |
| | | // 从后向前遍历,找到最后两条玩家消息(过滤掉系统消息和日期消息) |
| | | int count = 0; |
| | | for (int i = datas.Count - 1; i >= 0 && count < 2; i--) |
| | | { |
| | | TalkData data = datas[i]; |
| | | // 只保留玩家消息:非系统消息且非日期消息 |
| | | if (!data.isSystem && !data.isDate) |
| | | { |
| | | showTalkDatas.Insert(0, data); // 插入到列表开头以保持时间顺序 |
| | | count++; |
| | | } |
| | | } |
| | | |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (int i = 0; i < showTalkDatas.Count; i++) |
| | | { |
| | | TalkData data = showTalkDatas[i]; |
| | | stringBuilder.Append(UIHelper.AppendColor(GetGuildChatAreaColor(data), GetGuildChatAreaContent(data))); |
| | | stringBuilder.AppendLine(); |
| | | } |
| | | |
| | | talkInfoText.text = stringBuilder.ToString(); |
| | | } |
| | | |
| | | } |