123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- using UnityEngine.EventSystems;
- public class ManaSocial : Regist
- {
- #region Variable
- public static int LastCommentIndex;
- public static int FirstCommentIndex;
- public static Text PraiseText;
- public static Button PraiseBtn;
- public static ScrollRectPlus ScrollRectPlus;
- public static bool IsPlayer;
- public static float PraiseTimer;
- public static List<List<string>> PlayerCommentDatas;
- public static List<List<string>> VisiteeCommentDatas;
- #endregion
- public void Update()
- {
- if (ManaVisit.InVisit)
- {
- return;
- }
- PraiseTimer += Time.deltaTime;
- if (PraiseTimer >= 10)
- {
- PraiseTimer = 0;
- PraiseText.text = ManaServer.PraiseAmt.ToString();
- ManaServer.GetComment(ManaServer.SerialNumber, "0", CommentType.Garden, data => { InputCommentData(true, data); });
- }
- }
- public override void RegistValueA()
- {
- PraiseText = ManaReso.Get<Text>("C_PraiseText");
- PraiseBtn = ManaReso.Get<Button>("C_Praise");
- ScrollRectPlus = ManaReso.Get<ScrollRectPlus>("Q_ScrollRect");
- ScrollRectPlus.onValueChanged.AddListener(OnScroll);
- }
- public static void Praise()
- {
- if (ManaVisit.InVisit)
- {
- PraiseText.text = (int.Parse(PraiseText.text) + 1).ToString();
- ManaServer.Praise(ManaServer.SerialNumber, ManaVisit.VisiteeSerialNumber);
- DisablePraise();
- }
- else
- {
- DisablePraise();
- }
- }
- public static void EnablePraise()
- {
- PraiseBtn.image.color = Color.white;
- PraiseBtn.interactable = true;
- }
- public static void DisablePraise()
- {
- PraiseBtn.image.color = Lib.Pink;
- PraiseBtn.interactable = false;
- }
- public static void InputCommentData(bool isPlayer, JsonData jsonData)
- {
- if (isPlayer)
- {
- PlayerCommentDatas = new List<List<string>>();
- foreach (JsonData commentData in jsonData["l"])
- {
- PlayerCommentDatas.Add(new List<string>() { commentData["s"].ToString(), commentData["c"].ToString() });
- }
- }
- else
- {
- VisiteeCommentDatas = new List<List<string>>();
- foreach (JsonData commentData in jsonData["l"])
- {
- VisiteeCommentDatas.Add(new List<string>() { commentData["s"].ToString(), commentData["c"].ToString() });
- }
- }
- }
- public static void InitializeCommentPanel(bool isPlayer)
- {
- for (int i = 0; i < ManaReso.Get("Q_Grid").childCount; i++)
- {
- ManaReso.Save(ManaReso.Get("Q_Grid").GetChild(i));
- }
- if (isPlayer)
- {
- IsPlayer = true;
- GetCommentItem(6, PlayerCommentDatas);
- }
- else
- {
- IsPlayer = false;
- GetCommentItem(6, VisiteeCommentDatas);
- }
- }
- public static void UpdateCommentPanel(int direction)
- {
- if (IsPlayer)
- {
- UpdateCommentItem(direction, PlayerCommentDatas);
- }
- else
- {
- UpdateCommentItem(direction, VisiteeCommentDatas);
- }
- }
- public static void GetCommentItem(int amt, List<List<string>> commentDatas)
- {
- if (commentDatas == null)
- {
- return;
- }
- for (int i = 0; i < amt; i++)
- {
- if (i < PlayerCommentDatas.Count)
- {
- FirstCommentIndex = 0;
- LastCommentIndex = i;
- ManaReso.GetCommentItem(PlayerCommentDatas[i][0], PlayerCommentDatas[i][1]);
- }
- }
- }
- public static void UpdateCommentItem(int direction, List<List<string>> commentDatas)
- {
- if (commentDatas.Count-1 == LastCommentIndex)
- {
- return;
- }
- LastCommentIndex += 1;
- ManaReso.Save(ManaReso.Get("Q_Grid").GetChild(0).gameObject);
- ManaReso.GetCommentItem(commentDatas[LastCommentIndex][0], commentDatas[LastCommentIndex][1]);
- ScrollRectPlus.AddContentOffset(new Vector2(0, -120));
- }
- static bool Lock;
- public static void OnScroll(Vector2 position)
- {
- if (Lock)
- {
- return;
- }
- if (position.y < 0.5f)
- {
- Lock = true;
- UpdateCommentPanel(1);
- }
- }
- public static void OpenCommentPanel()
- {
- ManaReso.Get("Q_CommentBK").TweenForCG();
- ManaReso.SetActive("Q_InputBK", ManaVisit.InVisit);
- if (ManaVisit.InVisit)
- {
- InitializeCommentPanel(false);
- }
- else
- {
- InitializeCommentPanel(true);
- }
- }
- public static void CloseCommentPanel()
- {
- ManaReso.Get("Q_CommentBK").TweenBacCG();
- }
- }
|