150 lines
5.3 KiB
C#
150 lines
5.3 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using tysdk;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityNative.Sharing;
|
|
|
|
public class EventInviteFriends : MonoBehaviour
|
|
{
|
|
private IUnityNativeSharing adapter;
|
|
|
|
Button btn_close;
|
|
Button btn_mask;
|
|
Button btn_questionmark;
|
|
Image bar;
|
|
GameObject scale;
|
|
TMP_Text text_num;
|
|
RewardItemNew bigReward;
|
|
float rewardWidth;
|
|
RewardItemNew[] smallReward;
|
|
Button btn_invite_link;
|
|
Button btn_invite_fb;
|
|
string inviteLink;
|
|
List<Invite> invites;
|
|
int maxNum;
|
|
int maxIndex;
|
|
Tables tables;
|
|
PlayerItemData playerItemData;
|
|
FriendService friendService;
|
|
private void Awake()
|
|
{
|
|
friendService = GContext.container.Resolve<FriendService>();
|
|
playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
tables = GContext.container.Resolve<Tables>();
|
|
invites = tables.TbInvite.DataList;
|
|
maxIndex = invites.Count - 1;
|
|
maxNum = invites[maxIndex].NumInvite;
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
btn_mask = transform.Find("mask").GetComponent<Button>();
|
|
btn_questionmark = transform.Find("root/btn_questionmark").GetComponent<Button>();
|
|
bar = transform.Find("root/bg_bar/bar").GetComponent<Image>();
|
|
scale = transform.Find("root/bg_bar/bar/scale").gameObject;
|
|
text_num = transform.Find("root/bg_done/text_num").GetComponent<TMP_Text>();
|
|
bigReward = transform.Find("root/bigreward/reward").GetComponent<RewardItemNew>();
|
|
Transform rewardRoot = transform.Find("root/reward");
|
|
rewardWidth = rewardRoot.GetComponent<RectTransform>().rect.width;
|
|
smallReward = rewardRoot.GetComponentsInChildren<RewardItemNew>();
|
|
btn_invite_link = transform.Find("root/btn_invite_link/btn_green").GetComponent<Button>();
|
|
btn_invite_fb = transform.Find("root/btn_invite_fb/btn_green").GetComponent<Button>();
|
|
}
|
|
private void Start()
|
|
{
|
|
int InviteRewardCount = friendService.OnReceiveLinkAward();
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
btn_mask.onClick.AddListener(OnClickClose);
|
|
btn_questionmark.onClick.AddListener(OnClickQuestionmark);
|
|
btn_invite_link.onClick.AddListener(OnClickInviteLink);
|
|
btn_invite_fb.onClick.AddListener(OnClickInviteFB);
|
|
for (int i = 1; i < maxNum; i++)
|
|
{
|
|
var go = Instantiate(scale, bar.transform);
|
|
go.transform.localPosition = new Vector3((i / (float)maxNum - 0.5f) * rewardWidth, 0, 0);
|
|
}
|
|
for (int i = 0; i < maxIndex; i++)
|
|
{
|
|
if (i < smallReward.Length)
|
|
{
|
|
if (string.IsNullOrEmpty(invites[i].GiftIcon))
|
|
{
|
|
var dataItem = playerItemData.GetItemDataOne(invites[i].DropID);
|
|
if (dataItem != null)
|
|
{
|
|
smallReward[i].SetData(dataItem);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
smallReward[i].SetDropIcon(invites[i].GiftIcon, invites[i].DropID);
|
|
}
|
|
smallReward[i].SetReceived(i < InviteRewardCount);
|
|
smallReward[i].transform.localPosition =
|
|
new Vector3((invites[i].NumInvite / (float)maxNum - 0.5f) * rewardWidth, 0, 0);
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(invites[maxIndex].GiftIcon))
|
|
{
|
|
var dataItem = playerItemData.GetItemDataOne(invites[maxIndex].DropID);
|
|
if (dataItem != null)
|
|
{
|
|
bigReward.SetData(dataItem);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bigReward.SetDropIcon(invites[maxIndex].GiftIcon, invites[maxIndex].DropID);
|
|
}
|
|
bigReward.SetReceived(maxIndex < InviteRewardCount);
|
|
int InviteNumber = friendService.InviteLinkNumber;
|
|
if (InviteNumber > maxNum)
|
|
{
|
|
InviteNumber = maxNum;
|
|
}
|
|
bar.fillAmount = InviteNumber / (float)maxNum;
|
|
text_num.text = InviteNumber + "/" + maxNum;
|
|
GenInviteLink();
|
|
}
|
|
async void GenInviteLink()
|
|
{
|
|
inviteLink = "";
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
|
|
inviteLink = await AFHelper.Instance.GenInviteLink(userService.CustomId, userService.UserId);
|
|
}
|
|
void OnClickClose()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.FishingSocialInviteFriendsPopupPanel);
|
|
}
|
|
void OnClickQuestionmark()
|
|
{
|
|
_ = UIManager.Instance.ShowUI(UITypes.FishingSocialInviteFriendsInfoPopupPanel);
|
|
}
|
|
void OnClickInviteLink()
|
|
{
|
|
if (string.IsNullOrEmpty(inviteLink))
|
|
{
|
|
return;
|
|
}
|
|
if (adapter == null)
|
|
{
|
|
adapter = UnityNativeSharing.Create();
|
|
}
|
|
string invite = LocalizationMgr.GetFormatTextValue("Invite_Link", inviteLink);
|
|
adapter.ShareText(invite);
|
|
}
|
|
void OnClickInviteFB()
|
|
{
|
|
if (string.IsNullOrEmpty(inviteLink))
|
|
{
|
|
return;
|
|
}
|
|
string FBInvite_title = LocalizationMgr.GetText("FBInvite_title");
|
|
string FBInvite_content = LocalizationMgr.GetText("FBInvite_content");
|
|
UnityBridgeFunc.FBShareLink(FBInvite_title, FBInvite_content, inviteLink);
|
|
}
|
|
}
|