|
@@ -1,28 +1,44 @@
|
|
|
-using System;
|
|
|
-using UnityEngine;
|
|
|
+using UnityEngine;
|
|
|
using UnityEngine.UI;
|
|
|
+using UnityEngine.EventSystems;
|
|
|
|
|
|
+using System;
|
|
|
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 int RecordLastIndex;
|
|
|
+ public static int RecordFirstIndex;
|
|
|
+ public static bool RecordFlag;
|
|
|
+ public static Vector3 RecordPosition;
|
|
|
+
|
|
|
+ public static bool IsPlayer;
|
|
|
+ public static bool PullLock;
|
|
|
+ public static bool UpdateLock;
|
|
|
+ public static bool IsPanelOpen;
|
|
|
+
|
|
|
+ public static int PlayerLastIndex=-1;
|
|
|
+ public static int VisiteeLastIndex=-1;
|
|
|
+ public static int PlayerFirstIndex;
|
|
|
+ public static int VisiteeFirstIndex;
|
|
|
+ public static int PlayerCommentPage;
|
|
|
+ public static int VisiteeCommentPage;
|
|
|
|
|
|
public static Text PraiseText;
|
|
|
public static Button PraiseBtn;
|
|
|
+ public static DateTime CommentTime;
|
|
|
+ public static InputField InputField;
|
|
|
public static ScrollRectPlus ScrollRectPlus;
|
|
|
|
|
|
- public static bool IsPlayer;
|
|
|
- public static float PraiseTimer;
|
|
|
- public static List<List<string>> PlayerCommentDatas;
|
|
|
- public static List<List<string>> VisiteeCommentDatas;
|
|
|
+ public static float PraiseTimer = 5;
|
|
|
+ public static float CommentTimer = 0;
|
|
|
+ public static List<List<string>> PlayerCommentDatas = new List<List<string>>();
|
|
|
+ public static List<List<string>> VisiteeCommentDatas = new List<List<string>>();
|
|
|
|
|
|
#endregion
|
|
|
|
|
@@ -33,14 +49,29 @@ public class ManaSocial : Regist
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ CommentTimer += Time.deltaTime;
|
|
|
+
|
|
|
+ if (CommentTimer >= 10)
|
|
|
+ {
|
|
|
+ CommentTimer = 0;
|
|
|
+
|
|
|
+ if (!IsPanelOpen)
|
|
|
+ {
|
|
|
+ UpdatePage(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
PraiseTimer += Time.deltaTime;
|
|
|
|
|
|
- if (PraiseTimer >= 10)
|
|
|
+ if (PraiseTimer >= 5)
|
|
|
{
|
|
|
+ //index += 1;
|
|
|
+ //Debug.Log(index);
|
|
|
+ //ManaServer.AddComment(ManaServer.SerialNumber, ManaServer.SerialNumber, index.ToString(), CommentType.Garden);
|
|
|
+
|
|
|
PraiseTimer = 0;
|
|
|
|
|
|
PraiseText.text = ManaServer.PraiseAmt.ToString();
|
|
|
- ManaServer.GetComment(ManaServer.SerialNumber, "0", CommentType.Garden, data => { InputCommentData(true, data); });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -48,6 +79,7 @@ public class ManaSocial : Regist
|
|
|
{
|
|
|
PraiseText = ManaReso.Get<Text>("C_PraiseText");
|
|
|
PraiseBtn = ManaReso.Get<Button>("C_Praise");
|
|
|
+ InputField = ManaReso.Get<InputField>("Q_InputField");
|
|
|
ScrollRectPlus = ManaReso.Get<ScrollRectPlus>("Q_ScrollRect");
|
|
|
|
|
|
ScrollRectPlus.onValueChanged.AddListener(OnScroll);
|
|
@@ -85,9 +117,28 @@ public class ManaSocial : Regist
|
|
|
|
|
|
public static void InputCommentData(bool isPlayer, JsonData jsonData)
|
|
|
{
|
|
|
+ Auxiliary.Instance.DelayCall
|
|
|
+ (
|
|
|
+ () =>
|
|
|
+ {
|
|
|
+ PullLock = false;
|
|
|
+ },
|
|
|
+ 1
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!jsonData.Inst_Object.ContainsKey("l"))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (jsonData["l"].Count == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (isPlayer)
|
|
|
{
|
|
|
- PlayerCommentDatas = new List<List<string>>();
|
|
|
+ PlayerCommentPage++;
|
|
|
|
|
|
foreach (JsonData commentData in jsonData["l"])
|
|
|
{
|
|
@@ -96,7 +147,7 @@ public class ManaSocial : Regist
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- VisiteeCommentDatas = new List<List<string>>();
|
|
|
+ VisiteeCommentPage++;
|
|
|
|
|
|
foreach (JsonData commentData in jsonData["l"])
|
|
|
{
|
|
@@ -105,104 +156,328 @@ public class ManaSocial : Regist
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void InitializeCommentPanel(bool isPlayer)
|
|
|
+
|
|
|
+ public static void NextPage(bool isPlayer, bool isDownload)
|
|
|
{
|
|
|
- for (int i = 0; i < ManaReso.Get("Q_Grid").childCount; i++)
|
|
|
+ Debug.Log("NextPage");
|
|
|
+ if (isPlayer)
|
|
|
+ {
|
|
|
+ int saveAmt = 0;
|
|
|
+ int updateAmt = Mathf.Min(15, PlayerCommentDatas.Count - PlayerLastIndex - 1);
|
|
|
+
|
|
|
+ for (int i = 0; i < updateAmt; i++)
|
|
|
+ {
|
|
|
+ if (ScrollRectPlus.content.childCount >= 20)
|
|
|
+ {
|
|
|
+ saveAmt++;
|
|
|
+ ManaReso.Save(ScrollRectPlus.content.GetChild(0).gameObject);
|
|
|
+ PlayerFirstIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ PlayerLastIndex++;
|
|
|
+
|
|
|
+ ManaReso.GetCommentItem(PlayerCommentDatas[PlayerLastIndex][0], PlayerCommentDatas[PlayerLastIndex][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ int offset = isDownload ? 1 : 0;
|
|
|
+ float scaleFactor = isDownload ? ScrollRectPlus.GetComponent<Image>().canvas.scaleFactor : 1;
|
|
|
+
|
|
|
+ if (saveAmt > 0)
|
|
|
+ {
|
|
|
+ ScrollRectPlus.content.position += new Vector3(0, -(saveAmt - offset) * 120 * scaleFactor, 0);
|
|
|
+ ScrollRectPlus.AddContentOffset(new Vector3(0, -(saveAmt - offset) * 120 * scaleFactor, 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- ManaReso.Save(ManaReso.Get("Q_Grid").GetChild(i));
|
|
|
+ int saveAmt = 0;
|
|
|
+ int updateAmt = Mathf.Min(15, VisiteeCommentDatas.Count - VisiteeLastIndex - 1);
|
|
|
+
|
|
|
+ for (int i = 0; i < updateAmt; i++)
|
|
|
+ {
|
|
|
+ if (ScrollRectPlus.content.childCount >= 20)
|
|
|
+ {
|
|
|
+ saveAmt++;
|
|
|
+ ManaReso.Save(ScrollRectPlus.content.GetChild(0).gameObject);
|
|
|
+ VisiteeFirstIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ VisiteeLastIndex++;
|
|
|
+
|
|
|
+ ManaReso.GetCommentItem(VisiteeCommentDatas[VisiteeLastIndex][0], VisiteeCommentDatas[VisiteeLastIndex][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ int offset = isDownload ? 1 : 0;
|
|
|
+ float scaleFactor = isDownload ? ScrollRectPlus.GetComponent<Image>().canvas.scaleFactor : 1;
|
|
|
+
|
|
|
+ if (saveAmt > 0)
|
|
|
+ {
|
|
|
+ ScrollRectPlus.content.position += new Vector3(0, -(saveAmt - offset) * 120 * scaleFactor, 0);
|
|
|
+ ScrollRectPlus.AddContentOffset(new Vector3(0, -(saveAmt - offset) * 120 * scaleFactor, 0));
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ public static void PreviousPage(bool isPlayer)
|
|
|
+ {
|
|
|
if (isPlayer)
|
|
|
{
|
|
|
- IsPlayer = true;
|
|
|
- GetCommentItem(6, PlayerCommentDatas);
|
|
|
+ if (PlayerCommentDatas.Count > 20 && PlayerFirstIndex > 0)
|
|
|
+ {
|
|
|
+ int revertAmt = Mathf.Min(15, PlayerFirstIndex);
|
|
|
+ Debug.Log("PreviousPage");
|
|
|
+ for (int i = 0; i < revertAmt; i++)
|
|
|
+ {
|
|
|
+ ManaReso.Save(ScrollRectPlus.content.GetChild(19));
|
|
|
+ CommentItem commentItem = ManaReso.GetCommentItem(PlayerCommentDatas[PlayerFirstIndex - 1][0], PlayerCommentDatas[PlayerFirstIndex - 1][1]);
|
|
|
+ commentItem.transform.SetAsFirstSibling();
|
|
|
+
|
|
|
+ PlayerLastIndex--;
|
|
|
+ PlayerFirstIndex--;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (revertAmt > 0)
|
|
|
+ {
|
|
|
+ ScrollRectPlus.content.position += new Vector3(0, revertAmt*120, 0);
|
|
|
+ ScrollRectPlus.AddContentOffset(new Vector3(0, revertAmt*120, 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- IsPlayer = false;
|
|
|
- GetCommentItem(6, VisiteeCommentDatas);
|
|
|
- }
|
|
|
+ if (VisiteeCommentDatas.Count > 20 && VisiteeFirstIndex > 0)
|
|
|
+ {
|
|
|
+ int revertAmt = Mathf.Min(15, VisiteeFirstIndex);
|
|
|
+ Debug.Log("Revertpage");
|
|
|
+ for (int i = 0; i < revertAmt; i++)
|
|
|
+ {
|
|
|
+ ManaReso.Save(ScrollRectPlus.content.GetChild(19));
|
|
|
+ CommentItem commentItem = ManaReso.GetCommentItem(VisiteeCommentDatas[VisiteeFirstIndex - 1][0], VisiteeCommentDatas[VisiteeFirstIndex - 1][1]);
|
|
|
+ commentItem.transform.SetAsFirstSibling();
|
|
|
+
|
|
|
+ VisiteeLastIndex--;
|
|
|
+ VisiteeFirstIndex--;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (revertAmt > 0)
|
|
|
+ {
|
|
|
+ ScrollRectPlus.content.position += new Vector3(0, revertAmt * 120, 0);
|
|
|
+ ScrollRectPlus.AddContentOffset(new Vector3(0, revertAmt * 120, 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public static void UpdateCommentPanel(int direction)
|
|
|
+
|
|
|
+ public static void PullPage(bool isPlayer)
|
|
|
{
|
|
|
- if (IsPlayer)
|
|
|
+ PullLock = true;
|
|
|
+ UpdateLock = false;
|
|
|
+ Debug.Log("PullPage");
|
|
|
+
|
|
|
+ if (isPlayer)
|
|
|
{
|
|
|
- UpdateCommentItem(direction, PlayerCommentDatas);
|
|
|
+ ManaServer.GetComment
|
|
|
+ (
|
|
|
+ ManaServer.SerialNumber,
|
|
|
+ (PlayerCommentPage + 1).ToString(),
|
|
|
+ CommentType.Garden,
|
|
|
+ data =>
|
|
|
+ {
|
|
|
+ if (!UpdateLock)
|
|
|
+ {
|
|
|
+ InputCommentData(IsPlayer, data);
|
|
|
+ NextPage(IsPlayer, true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PullLock = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- UpdateCommentItem(direction, VisiteeCommentDatas);
|
|
|
+ ManaServer.GetComment
|
|
|
+ (
|
|
|
+ ManaServer.SerialNumber,
|
|
|
+ (VisiteeCommentPage + 1).ToString(),
|
|
|
+ CommentType.Garden,
|
|
|
+ data =>
|
|
|
+ {
|
|
|
+ if (!UpdateLock)
|
|
|
+ {
|
|
|
+ InputCommentData(IsPlayer, data);
|
|
|
+ NextPage(IsPlayer, true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PullLock = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void GetCommentItem(int amt, List<List<string>> commentDatas)
|
|
|
+ public static void ClearComment()
|
|
|
{
|
|
|
- if (commentDatas == null)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
+ int childAmt = ScrollRectPlus.content.childCount;
|
|
|
|
|
|
- for (int i = 0; i < amt; i++)
|
|
|
+ for (int i = 0; i < childAmt; i++)
|
|
|
{
|
|
|
- if (i < PlayerCommentDatas.Count)
|
|
|
- {
|
|
|
- FirstCommentIndex = 0;
|
|
|
- LastCommentIndex = i;
|
|
|
- ManaReso.GetCommentItem(PlayerCommentDatas[i][0], PlayerCommentDatas[i][1]);
|
|
|
- }
|
|
|
+ ManaReso.Save(ScrollRectPlus.content.GetChild(0));
|
|
|
}
|
|
|
+
|
|
|
+ ScrollRectPlus.verticalNormalizedPosition = 1;
|
|
|
}
|
|
|
|
|
|
- public static void UpdateCommentItem(int direction, List<List<string>> commentDatas)
|
|
|
+ public static void UpdatePage(bool isPlayer)
|
|
|
{
|
|
|
- if (commentDatas.Count-1 == LastCommentIndex)
|
|
|
+ UpdateLock = true;
|
|
|
+
|
|
|
+ ClearComment();
|
|
|
+
|
|
|
+ if (isPlayer)
|
|
|
{
|
|
|
- return;
|
|
|
- }
|
|
|
+ Debug.Log("UpdatePlayer");
|
|
|
+
|
|
|
+ PlayerFirstIndex = 0;
|
|
|
+ PlayerLastIndex = -1;
|
|
|
+ PlayerCommentPage = 0;
|
|
|
+ PlayerCommentDatas = new List<List<string>>();
|
|
|
|
|
|
- LastCommentIndex += 1;
|
|
|
+ ManaServer.GetComment(ManaServer.SerialNumber, "1", CommentType.Garden, data => { InputCommentData(true, data); NextPage(true, true); });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log("UpdateVisitee");
|
|
|
|
|
|
- ManaReso.Save(ManaReso.Get("Q_Grid").GetChild(0).gameObject);
|
|
|
- ManaReso.GetCommentItem(commentDatas[LastCommentIndex][0], commentDatas[LastCommentIndex][1]);
|
|
|
+ VisiteeFirstIndex = 0;
|
|
|
+ VisiteeLastIndex = -1;
|
|
|
+ VisiteeCommentPage = 0;
|
|
|
+ VisiteeCommentDatas = new List<List<string>>();
|
|
|
|
|
|
- ScrollRectPlus.AddContentOffset(new Vector2(0, -120));
|
|
|
+ ManaServer.GetComment(ManaVisit.VisiteeSerialNumber, "1", CommentType.Garden, data => { InputCommentData(false, data); NextPage(false, true); });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- static bool Lock;
|
|
|
+
|
|
|
public static void OnScroll(Vector2 position)
|
|
|
{
|
|
|
- if (Lock)
|
|
|
+ if (PullLock)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (position.y < 0.5f)
|
|
|
+ if (position.y >= 1)
|
|
|
+ {
|
|
|
+ PreviousPage(IsPlayer);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (position.y <= 0)
|
|
|
{
|
|
|
- Lock = true;
|
|
|
- UpdateCommentPanel(1);
|
|
|
+ if (IsPlayer)
|
|
|
+ {
|
|
|
+ if (PlayerLastIndex == PlayerCommentDatas.Count - 1)
|
|
|
+ {
|
|
|
+ PullPage(true);
|
|
|
+ }
|
|
|
+ else if (PlayerLastIndex < PlayerCommentDatas.Count - 1)
|
|
|
+ {
|
|
|
+ NextPage(true, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (VisiteeLastIndex == VisiteeCommentDatas.Count - 1)
|
|
|
+ {
|
|
|
+ PullPage(false);
|
|
|
+ }
|
|
|
+ else if (VisiteeLastIndex < VisiteeCommentDatas.Count - 1)
|
|
|
+ {
|
|
|
+ NextPage(false, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void OpenCommentPanel()
|
|
|
+ public static void Comment()
|
|
|
{
|
|
|
- ManaReso.Get("Q_CommentBK").TweenForCG();
|
|
|
-
|
|
|
- ManaReso.SetActive("Q_InputBK", ManaVisit.InVisit);
|
|
|
-
|
|
|
- if (ManaVisit.InVisit)
|
|
|
+ if ((DateTime.Now - CommentTime).TotalSeconds > 30)
|
|
|
{
|
|
|
- InitializeCommentPanel(false);
|
|
|
+ CommentTime = DateTime.Now;
|
|
|
+
|
|
|
+ ManaServer.AddComment(ManaServer.SerialNumber, ManaVisit.VisiteeSerialNumber, InputField.text, CommentType.Garden);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- InitializeCommentPanel(true);
|
|
|
+ Bubble.Show(Language.GetStr("UI", "Q_CommentTip"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void OpenCommentPanel()
|
|
|
+ {
|
|
|
+ ManaReso.Get("Q_CommentBK").TweenForCG();
|
|
|
+
|
|
|
+ ManaReso.SetActive("Q_InputBK", ManaVisit.InVisit);
|
|
|
+
|
|
|
+ IsPlayer = !ManaVisit.InVisit;
|
|
|
+ IsPanelOpen = true;
|
|
|
+ }
|
|
|
+
|
|
|
public static void CloseCommentPanel()
|
|
|
{
|
|
|
ManaReso.Get("Q_CommentBK").TweenBacCG();
|
|
|
+ IsPanelOpen = false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void Record()
|
|
|
+ {
|
|
|
+ if (IsPlayer)
|
|
|
+ {
|
|
|
+ RecordFlag = true;
|
|
|
+ RecordLastIndex = PlayerLastIndex;
|
|
|
+ RecordFirstIndex = PlayerFirstIndex;
|
|
|
+ RecordPosition = ScrollRectPlus.content.position;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Recover()
|
|
|
+ {
|
|
|
+ if (RecordFlag)
|
|
|
+ {
|
|
|
+ RecordFlag = false;
|
|
|
+
|
|
|
+ OpenCommentPanel();
|
|
|
+
|
|
|
+ ClearComment();
|
|
|
+
|
|
|
+ PlayerLastIndex = -1;
|
|
|
+ PlayerFirstIndex = 0;
|
|
|
+
|
|
|
+ int antiCrush = 0;
|
|
|
+
|
|
|
+ while (PlayerFirstIndex != RecordFirstIndex || PlayerLastIndex != RecordLastIndex)
|
|
|
+ {
|
|
|
+ if (antiCrush > 10000)
|
|
|
+ {
|
|
|
+ throw new Exception("Crush");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ScrollRectPlus.content.childCount >= 20)
|
|
|
+ {
|
|
|
+ ManaReso.Save(ScrollRectPlus.content.GetChild(0).gameObject);
|
|
|
+ PlayerFirstIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ PlayerLastIndex++;
|
|
|
+
|
|
|
+ ManaReso.GetCommentItem(PlayerCommentDatas[PlayerLastIndex][0], PlayerCommentDatas[PlayerLastIndex][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ ScrollRectPlus.content.position = RecordPosition;
|
|
|
+ }
|
|
|
}
|
|
|
}
|