2021-04-08 20:09:59 +08:00
|
|
|
|
using ET;
|
|
|
|
|
using FairyGUI;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-05-05 13:36:19 +08:00
|
|
|
|
using ET.EventType;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
using UnityEngine;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class MainUIAwakSyatem : AwakeSystem<MainUI>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(MainUI self)
|
|
|
|
|
{
|
|
|
|
|
self.Awake();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MainUI : Entity
|
|
|
|
|
{
|
|
|
|
|
public static FUI_MainUI ui;
|
|
|
|
|
private static Dictionary<long, int> unitListIndexDic = new Dictionary<long, int>();
|
|
|
|
|
public void Awake()
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene = this.ZoneScene();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ui = GetParent<FUI_MainUI>();
|
|
|
|
|
AddComponent<MainUIGlobalText>();
|
|
|
|
|
AwakeAsync().Coroutine();
|
|
|
|
|
frameClickMap.UnitInfo = new UnitPosInfo();
|
|
|
|
|
}
|
|
|
|
|
private async ETVoid AwakeAsync()
|
|
|
|
|
{
|
|
|
|
|
//!初始化格子和设置
|
|
|
|
|
await InitMainUISlotAndSetting(ui);
|
|
|
|
|
|
|
|
|
|
//!+聊天相关以及注册事件
|
|
|
|
|
InitChatFunction(ui);
|
|
|
|
|
//!+头像点击事件
|
|
|
|
|
ui.m_mineHeadInfo.m_btn.onRightClick.Set( () =>
|
|
|
|
|
{
|
|
|
|
|
});
|
2021-04-20 00:25:04 +08:00
|
|
|
|
ui.m_txtUID.text = $"uid: {zoneScene.GetComponent<GlobalVariable>().MyId}";
|
2021-04-08 20:09:59 +08:00
|
|
|
|
//!+自动战斗
|
|
|
|
|
ui.m_btnAuto.onClick.Set(async () =>
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_AutoBattle ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_AutoBattle>(new C2M_AutoBattle(){isAuto = ui.m_btnAuto.selected});
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//!隐藏玩家
|
|
|
|
|
ui.m_btnDisOther.onClick.Set(HideUnitComponent.SetDisOther);
|
|
|
|
|
|
|
|
|
|
//!行动值
|
|
|
|
|
ui.m_btnBuyEnergy.self.onClick.Set(async () =>
|
|
|
|
|
{
|
|
|
|
|
|
2021-04-20 00:25:04 +08:00
|
|
|
|
await SessionComponentHelper.TipCall(this.zoneScene, new C2M_GetAddEnergyPrice { }, (M2C_GetAddEnergyPrice query) =>
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
string str = $"是否花费{query.Price / 10000}金币增加[u][b]100[/b][/u]行动值?";
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return (str, new C2M_AddEnergy());
|
|
|
|
|
},
|
|
|
|
|
(M2C_AddEnergy ret) => { }
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
//!邮件
|
|
|
|
|
ui.m_btnMail.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.MailUI_Open
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
//!排行榜
|
|
|
|
|
ui.m_btnRank.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.RankingUI_Open
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
//!组队
|
|
|
|
|
ui.m_btnTeam.onClick.Set(async () =>
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
await SessionComponentHelper.TipCall(this.zoneScene, new C2M_GetOpenRemoteStore { }, (M2C_GetOpenRemoteStore query) =>
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
string str = $"是否花费{query.Price / 10000}金币打开远程仓库?";
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return (str, new C2M_OpenRemoteStore());
|
|
|
|
|
},
|
|
|
|
|
(M2C_OpenRemoteStore ret) =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenStoreUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene(),
|
|
|
|
|
ignoreInfo = true
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//!退出游戏
|
|
|
|
|
ui.m_btnExit.onClick.Set(() =>
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
FUI_TipUI tip = TipHelper.OpenUI("是否退出游戏?", tipType: TipType.Double);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
tip.m_btnYes.self.onClick.Set(ET.Init.Quit);
|
|
|
|
|
});
|
|
|
|
|
//!退出战斗
|
|
|
|
|
ui.m_btnQuitBattle.onClick.Set(() =>
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
FUI_TipUI tip = TipHelper.OpenUI("是否退出战斗?", tipType: TipType.Double);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
tip.m_btnYes.self.onClick.Set(() =>
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<SessionComponent>().Session.Send(new C2M_QuitBattle());
|
2021-04-08 20:09:59 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
//!挂机
|
2021-05-05 13:36:19 +08:00
|
|
|
|
// ui.m_btnBattleIdle.onClick.Set(() =>
|
|
|
|
|
// {
|
|
|
|
|
// if (ui.m_btnBattleIdle.selected)
|
|
|
|
|
// {
|
|
|
|
|
// BattleHelper.StartBattleIdle(zoneScene,(selected) =>
|
|
|
|
|
// {
|
|
|
|
|
// ui.m_btnBattleIdle.selected = selected;
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// BattleHelper.EndBattleIdle(zoneScene,(selected) =>
|
|
|
|
|
// {
|
|
|
|
|
// ui.m_btnBattleIdle.selected = selected;
|
|
|
|
|
// }).Coroutine();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
ui.m_btnActive.onClick.Set(() =>
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-05-05 13:36:19 +08:00
|
|
|
|
Game.EventSystem.Publish(new OpenActiveUI(){zoneScene = this.zoneScene});
|
2021-04-08 20:09:59 +08:00
|
|
|
|
});
|
|
|
|
|
//!查看状态Buff
|
|
|
|
|
ui.m_btnStateBuff.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenMainStoryAIUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//!+人物UI
|
|
|
|
|
ui.m_FunctionList.GetChild("人物").asButton.onClick.Set(() =>
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<GlobalVariable>().IsMineCharacter = true;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenCharacterUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
//!+技能UI
|
|
|
|
|
ui.m_FunctionList.GetChild("技能").asButton.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenSkillUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
//!+背包UI
|
|
|
|
|
ui.m_FunctionList.GetChild("背包").asButton.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenBagUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
//!+任务
|
|
|
|
|
ui.m_FunctionList.GetChild("任务").asButton.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.TaskUI_Open
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
ui.m_FunctionList.GetChild("社交").asButton.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenFriendUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
2021-04-09 00:48:56 +08:00
|
|
|
|
ui.m_FunctionList.GetChild("宠物").asButton.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenPetUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ui.m_FunctionList.GetChild("商城").asButton.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.OpenMarketUI
|
|
|
|
|
{
|
|
|
|
|
zoneScene = ui.ZoneScene()
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 00:25:04 +08:00
|
|
|
|
private async ETTask InitMainUISlotAndSetting(FUI_MainUI ui)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_GetMainUISetting m2cGetMainUISetting = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetMainUISetting>(new C2M_GetMainUISetting());
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ui.m_btnAuto.selected = m2cGetMainUISetting.IsAutoSkill;
|
|
|
|
|
ui.m_btnDisOther.selected = m2cGetMainUISetting.IsDisplayOthers;
|
|
|
|
|
//!初始化格子
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateMainUISlot
|
|
|
|
|
{
|
|
|
|
|
list = m2cGetMainUISetting.MainUISlotList
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
//!设置格子事件
|
|
|
|
|
{
|
|
|
|
|
int slotCount = ui.m_mainUISlotList.numChildren;
|
|
|
|
|
for (int i = 0; i < slotCount; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = i;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
GButton btn = ui.m_mainUISlotList.GetChildAt(i).asButton;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
//!放入事件
|
|
|
|
|
btn.onDrop.Set1(async content =>
|
|
|
|
|
{
|
|
|
|
|
if (content.data is UIDragArgs args)
|
|
|
|
|
{
|
|
|
|
|
int btnIndex = args.index;
|
|
|
|
|
//!放入道具
|
|
|
|
|
if (args.uiType == UIDragArgs.UIType.Bag)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(btnIndex, out ClientItemData data))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (data.ItemType != ItemType.GoodsItem)
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI("只能放入道具,请重新拖拽!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_DropItem ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_DropItem>(new C2M_DropItem() { SlotId = index, BagIndex = btnIndex });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateMainUISlot
|
|
|
|
|
{
|
|
|
|
|
list = ret.MainUISlotList
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
//!放入技能
|
|
|
|
|
if (args.uiType == UIDragArgs.UIType.Skill)
|
|
|
|
|
{
|
|
|
|
|
int skillId = args.index;
|
|
|
|
|
if (skillId == 0)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"skill Id == 0 when drop the skill into the slot if main ui!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//item.icon = DragDropManager.inst.dragAgent.icon;
|
|
|
|
|
//var skilldata = skillitemUI.GetComponent<ClientSkillData>();
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_DropSkill ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_DropSkill>(new C2M_DropSkill() { SkillId = skillId, SlotId = index });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateMainUISlot
|
|
|
|
|
{
|
|
|
|
|
list = ret.MainUISlotList
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
args.Release();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//!取下事件
|
|
|
|
|
btn.onRightClick.Set1(async content =>
|
|
|
|
|
{
|
|
|
|
|
//!取下技能
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainUISlot mainUISlot = MainUISlotComponent.Instance.Get(index);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (mainUISlot.MainUIType == MainUIType.SkillSlot)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_DropSkill ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_DropSkill>(new C2M_DropSkill() { SlotId = index });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateMainUISlot
|
|
|
|
|
{
|
|
|
|
|
list = ret.MainUISlotList
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//!取下道具
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_DropItem ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_DropItem>(new C2M_DropItem() { SlotId = index, BagIndex = -1 });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateMainUISlot
|
|
|
|
|
{
|
|
|
|
|
list = ret.MainUISlotList
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//!点击事件
|
|
|
|
|
btn.onClick.Set1(async content =>
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
MainUISlot mainUISlot = MainUISlotComponent.Instance.Get(index);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (mainUISlot.MainUIType == MainUIType.SkillSlot)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_UseMainUISkill ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_UseMainUISkill>(new C2M_UseMainUISkill() { SlotId = index });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
//TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_UseMainUIGoods ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_UseMainUIGoods>(new C2M_UseMainUIGoods() { SlotId = index });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
|
|
|
|
|
{
|
|
|
|
|
list=ret.BagMapList
|
|
|
|
|
});
|
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.UpdateMainUISlot
|
|
|
|
|
{
|
|
|
|
|
list = ret.MainUISlotList
|
|
|
|
|
}).Coroutine();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static ChatContiator chatContiator;
|
|
|
|
|
private static ChatType chatType;
|
|
|
|
|
private static long tagetChatId;
|
|
|
|
|
|
|
|
|
|
public static ChatContiator GetChatContiator => chatContiator = chatContiator ?? new ChatContiator();
|
|
|
|
|
public static FUI_LabelGlobalText GlobalText => ui?.m_txtGlobal;
|
|
|
|
|
public class ChatContiator
|
|
|
|
|
{
|
|
|
|
|
private readonly List<(ChatType, string, string, string)> contentList;
|
|
|
|
|
|
|
|
|
|
private const int MaxContentCount = 100;
|
|
|
|
|
|
|
|
|
|
private GList gList;
|
|
|
|
|
public ChatContiator()
|
|
|
|
|
{
|
|
|
|
|
contentList = new List<(ChatType, string, string, string)>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitChatContentList(GList gList)
|
|
|
|
|
{
|
|
|
|
|
this.gList = gList;
|
|
|
|
|
gList.SetVirtual();
|
|
|
|
|
gList.itemRenderer = ListItemRender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(ChatType chatType, string senderName, string content)
|
|
|
|
|
{
|
|
|
|
|
if (contentList.Count >= MaxContentCount)
|
|
|
|
|
{
|
|
|
|
|
contentList.RemoveAt(0);
|
|
|
|
|
}
|
|
|
|
|
contentList.Add((chatType, $"{DateTime.Now:HH:mm:ss}", senderName, content));
|
|
|
|
|
ShowChatContentList();
|
|
|
|
|
}
|
|
|
|
|
public void Refresh(ChatType _chatType = ChatType.NoneChat)
|
|
|
|
|
{
|
|
|
|
|
contentList.Clear();
|
|
|
|
|
var dic = ChatMessageComponent.Instance.messageDic;
|
|
|
|
|
if(dic.TryGetValue(chatType,out var list))
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (ChatMessageComponent.MessageInfo item in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
contentList.Add((chatType,item.time, item.name, item.content));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ShowChatContentList();
|
|
|
|
|
if(_chatType!= ChatType.NoneChat && chatType!= _chatType)
|
|
|
|
|
{
|
|
|
|
|
SwitchRedPoint((int)(_chatType - 1), true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowChatContentList()
|
|
|
|
|
{
|
|
|
|
|
gList.numItems = contentList.Count;
|
|
|
|
|
gList.RefreshVirtualList();
|
|
|
|
|
//!强制展示
|
|
|
|
|
ForceShowChatBoard();
|
|
|
|
|
gList.ScrollToView(gList.numItems - 1, true);
|
|
|
|
|
}
|
|
|
|
|
private void ListItemRender(int index, GObject item)
|
|
|
|
|
{
|
|
|
|
|
FUI_LabelChatItem labelItem = FUI_LabelChatItem.GetFormPool(ui, item);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
(ChatType chatType, string time, string senderName, string content) = contentList[index];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
labelItem.m_txtType.text = $"[color={GetStrColorByChatType(chatType)}][{GetStrByChatType(chatType)} {time}][/color]";
|
|
|
|
|
labelItem.m_txtContent.text = $"[color=#ff9900][u]{senderName}[/u]:[/color]{content}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private enum ChatBoardState { Short, High, None }
|
|
|
|
|
|
|
|
|
|
private static ChatBoardState chatBoardState;
|
|
|
|
|
private static void SwitchRedPoint(int index,bool value)
|
|
|
|
|
{
|
|
|
|
|
ui.m_chatList.GetChildAt(index).asButton.GetChild("imgCicle").visible = value;
|
|
|
|
|
}
|
2021-04-20 00:25:04 +08:00
|
|
|
|
private void InitChatFunction(FUI_MainUI ui)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
GetChatContiator.InitChatContentList(ui.m_chatContentList);
|
|
|
|
|
chatType = ChatType.Normal;
|
|
|
|
|
chatBoardState = ChatBoardState.Short;
|
|
|
|
|
//!初始化
|
|
|
|
|
ui.m_txtChatType.text = GetStrByChatType(chatType);
|
|
|
|
|
ui.m_chatList.selectedIndex = 0;
|
|
|
|
|
ui.m_chat.selectedIndex = (int)chatBoardState;
|
|
|
|
|
//!频道选择
|
|
|
|
|
ui.m_chatList.onClickItem.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
chatType = (ChatType)ui.m_chatList.selectedIndex + 1;
|
|
|
|
|
ui.m_txtChatType.text = GetStrByChatType(chatType);
|
|
|
|
|
tagetChatId = 0;
|
|
|
|
|
GetChatContiator.Refresh();
|
|
|
|
|
SwitchRedPoint((int)(chatType - 1), false);
|
|
|
|
|
});
|
|
|
|
|
//!展示聊天版按钮
|
|
|
|
|
ui.m_btnChatReceive.onClick.Set(() =>
|
|
|
|
|
{
|
|
|
|
|
int value = (int)chatBoardState;
|
|
|
|
|
value++;
|
|
|
|
|
if (value > (int)ChatBoardState.None)
|
|
|
|
|
{
|
|
|
|
|
value = 0;
|
|
|
|
|
}
|
|
|
|
|
chatBoardState = (ChatBoardState)value;
|
|
|
|
|
ui.m_chat.selectedIndex = value;
|
|
|
|
|
if (chatBoardState != ChatBoardState.None)
|
|
|
|
|
ui.m_chatContentList.ScrollToView(ui.m_chatContentList.numItems - 1, true);
|
|
|
|
|
});
|
|
|
|
|
//!发送按钮
|
|
|
|
|
ui.m_btnChatSend.onClick.Set(SendChat);
|
|
|
|
|
//!回车发送
|
|
|
|
|
ui.m_inptChatContent.onSubmit.Set(SendChat);
|
|
|
|
|
|
|
|
|
|
async void SendChat()
|
|
|
|
|
{
|
|
|
|
|
if (chatType == ChatType.System) return;
|
|
|
|
|
if (chatType == ChatType.Private && tagetChatId==0) return;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
string content = ui.m_inptChatContent.text;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (ui.m_inptChatContent.text.IsNullOrEmpty()) return;
|
|
|
|
|
//!过滤非法字符
|
|
|
|
|
content = IllegalWordHelper.Filter(content);
|
|
|
|
|
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_RequestChat ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_RequestChat>(new C2M_RequestChat { Type = chatType, Content = content, Id = tagetChatId });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ui.m_inptChatContent.text = null;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
ClientUnitCharacter clientCharacter = ClientUnitCharacterComponent.Instance.Get(zoneScene.GetComponent<GlobalVariable>().MyId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
ChatMessageComponent.Instance.Add(new ChatMessageComponent.MessageInfo
|
|
|
|
|
{
|
|
|
|
|
name = clientCharacter.NickName,
|
|
|
|
|
type = chatType,
|
|
|
|
|
content = content,
|
|
|
|
|
time = $"{DateTime.Now:HH:mm:ss}"
|
|
|
|
|
});
|
|
|
|
|
GetChatContiator.Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static void ForceShowChatBoard()
|
|
|
|
|
{
|
|
|
|
|
if (chatBoardState == ChatBoardState.High) return;
|
|
|
|
|
chatBoardState = ChatBoardState.Short;
|
|
|
|
|
ui.m_chat.selectedIndex = (int)chatBoardState;
|
|
|
|
|
}
|
|
|
|
|
private static string GetStrByChatType(ChatType chatType)
|
|
|
|
|
{
|
|
|
|
|
switch (chatType)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case ChatType.Normal:
|
|
|
|
|
return "普通";
|
|
|
|
|
case ChatType.Team:
|
|
|
|
|
return "组队";
|
|
|
|
|
case ChatType.Family:
|
|
|
|
|
return "家族";
|
|
|
|
|
case ChatType.Camp:
|
|
|
|
|
return "阵营";
|
|
|
|
|
case ChatType.World:
|
|
|
|
|
return "世界";
|
|
|
|
|
case ChatType.Private:
|
|
|
|
|
return "私聊";
|
|
|
|
|
case ChatType.System:
|
|
|
|
|
return "系统";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static string GetStrColorByChatType(ChatType chatType)
|
|
|
|
|
{
|
|
|
|
|
switch (chatType)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case ChatType.Normal:
|
|
|
|
|
return "#FFFFFF";
|
|
|
|
|
case ChatType.Team:
|
|
|
|
|
return "#0000FF";
|
|
|
|
|
case ChatType.Family:
|
|
|
|
|
return "#00FF00";
|
|
|
|
|
case ChatType.Camp:
|
|
|
|
|
return "#FFFF00";
|
|
|
|
|
case ChatType.World:
|
|
|
|
|
return "#00FFFF";
|
|
|
|
|
case ChatType.Private:
|
|
|
|
|
return "#FF00FF";
|
|
|
|
|
case ChatType.System:
|
|
|
|
|
return "#990000";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 私聊
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
public static void PrivateChat(long id)
|
|
|
|
|
{
|
|
|
|
|
chatType = ChatType.Private;
|
|
|
|
|
tagetChatId = id;
|
|
|
|
|
ui.m_txtChatType.text = GetStrByChatType(chatType);
|
|
|
|
|
ui.m_inptChatContent.RequestFocus();
|
|
|
|
|
}
|
|
|
|
|
public static void ChangeEnergy(int energy)
|
|
|
|
|
{
|
|
|
|
|
ui.m_txtEnergy.text = energy + string.Empty;
|
|
|
|
|
}
|
|
|
|
|
private static Frame_ClickMap frameClickMap = new Frame_ClickMap();
|
2021-04-20 00:25:04 +08:00
|
|
|
|
private Scene zoneScene;
|
|
|
|
|
|
|
|
|
|
public static void ClearUnitList()
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
unitListIndexDic.Clear();
|
|
|
|
|
ui.m_unitNameList.RemoveChildrenToPool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddUnit(long id, string job, string name)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
var zoneScene = ui.ZoneScene();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
GButton btn = ui.m_unitNameList.AddItemFromPool().asButton;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
btn.title = $"{job} {name}";
|
|
|
|
|
unitListIndexDic[id] = ui.m_unitNameList.GetChildIndex(btn);
|
|
|
|
|
btn.onClick.Set1(async context =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
long unitId = id;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
if (unitId == zoneScene.GetComponent<GlobalVariable>().MyId) return;
|
|
|
|
|
Unit unit = zoneScene.GetComponent<UnitComponent>().Get(unitId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (context.inputEvent.isDoubleClick)
|
|
|
|
|
{
|
|
|
|
|
if (unit.UnitType == UnitType.NPC)
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
M2C_ClickNPC ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ClickNPC>(new C2M_ClickNPC() { NPCId = unit.ConfigId });
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (!ret.Message.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
TipHelper.OpenUI(ret.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (unit.UnitType == UnitType.TransPoint)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<GlobalVariable>().SelectUnitId = unitId;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
Game.EventSystem.Publish(new ET.EventType.ClickOtherPlayer
|
|
|
|
|
{
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene = zoneScene
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}).Coroutine();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Vector3 pos = unit.Position;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
if (!unit.IsFight)
|
|
|
|
|
{
|
|
|
|
|
frameClickMap.UnitInfo.X = pos.x;
|
|
|
|
|
frameClickMap.UnitInfo.Y = pos.y;
|
|
|
|
|
frameClickMap.UnitInfo.YAngle = pos.x >= unit.Position.x ? 0 : 180;
|
2021-04-20 00:25:04 +08:00
|
|
|
|
zoneScene.GetComponent<SessionComponent>().Session.Send(frameClickMap);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public static void RemoveUnit(long id)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
if (!unitListIndexDic.TryGetValue(id, out int index))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
Log.Error($"dic not has the key = {id}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (index == -1)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"index==-1 where id = {id}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
unitListIndexDic.Remove(id);
|
|
|
|
|
ui.m_unitNameList.RemoveChildToPoolAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ChangePing(int ping)
|
|
|
|
|
{
|
|
|
|
|
if (ui)
|
|
|
|
|
ui.m_txtPing.text = $"ping:{ping}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#region 测试日志
|
|
|
|
|
#if TEST
|
|
|
|
|
public static class Test
|
|
|
|
|
{
|
|
|
|
|
public static void Log(string msg)
|
|
|
|
|
{
|
|
|
|
|
MainUI.GetChatContiator.Add(ChatType.System, "本地", msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|