Finish chatroom
This commit is contained in:
@@ -966,7 +966,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 0}
|
||||
m_Sprite: {fileID: 21300000, guid: 517f61beffc1245a0a3f7907c7c93eb0, type: 3}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
@@ -1920,47 +1920,6 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!21 &225059705
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: UI/RoundedCorners/RoundedCorners
|
||||
m_Shader: {fileID: 4800000, guid: 0bd2ec5d73751e34a814274a454bec41, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _ColorMask: 15
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UseUIAlphaClip: 0
|
||||
m_Colors:
|
||||
- _OuterUV: {r: 0, g: 0, b: 1, a: 1}
|
||||
- _WidthHeightRadius: {r: 1180, g: 75, b: 20, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!1 &231554130
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2410,6 +2369,47 @@ CanvasRenderer:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 247980821}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!21 &249407231
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: UI/RoundedCorners/RoundedCorners
|
||||
m_Shader: {fileID: 4800000, guid: 0bd2ec5d73751e34a814274a454bec41, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _ColorMask: 15
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UseUIAlphaClip: 0
|
||||
m_Colors:
|
||||
- _OuterUV: {r: 0, g: 0, b: 1, a: 1}
|
||||
- _WidthHeightRadius: {r: 1180, g: 75, b: 20, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!1 &258129472
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -4882,47 +4882,6 @@ MonoBehaviour:
|
||||
invert: 0
|
||||
addMore: {r: 0, g: 0, b: 0, a: 0}
|
||||
reverseAdd: 0
|
||||
--- !u!21 &560411584
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: UI/RoundedCorners/RoundedCorners
|
||||
m_Shader: {fileID: 4800000, guid: 0bd2ec5d73751e34a814274a454bec41, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _ColorMask: 15
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UseUIAlphaClip: 0
|
||||
m_Colors:
|
||||
- _OuterUV: {r: 0, g: 0, b: 1, a: 1}
|
||||
- _WidthHeightRadius: {r: 1180, g: 75, b: 20, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!1 &591098545
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -6178,7 +6137,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &726248163
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -6193,10 +6152,10 @@ RectTransform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1301936380}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 1100, y: 160}
|
||||
m_SizeDelta: {x: -80, y: -570}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &726248164
|
||||
MonoBehaviour:
|
||||
@@ -6250,7 +6209,7 @@ MonoBehaviour:
|
||||
m_fontWeight: 400
|
||||
m_enableAutoSizing: 1
|
||||
m_fontSizeMin: 1
|
||||
m_fontSizeMax: 128
|
||||
m_fontSizeMax: 64
|
||||
m_fontStyle: 0
|
||||
m_HorizontalAlignment: 2
|
||||
m_VerticalAlignment: 512
|
||||
@@ -6867,7 +6826,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
|
||||
m_Material: {fileID: 225059705}
|
||||
m_Material: {fileID: 249407231}
|
||||
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
@@ -7104,7 +7063,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 6534417478244952628, guid: dbf71fe5f2caad1409da64bdbb781eb5, type: 3}
|
||||
m_Sprite: {fileID: 21300000, guid: 517f61beffc1245a0a3f7907c7c93eb0, type: 3}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
@@ -7122,6 +7081,88 @@ CanvasRenderer:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 928270038}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!21 &931340537
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: UI/RoundedCorners/RoundedCorners
|
||||
m_Shader: {fileID: 4800000, guid: 0bd2ec5d73751e34a814274a454bec41, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _ColorMask: 15
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UseUIAlphaClip: 0
|
||||
m_Colors:
|
||||
- _OuterUV: {r: 0, g: 0, b: 1, a: 1}
|
||||
- _WidthHeightRadius: {r: 1180, g: 75, b: 20, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!21 &943778468
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: UI/RoundedCorners/RoundedCorners
|
||||
m_Shader: {fileID: 4800000, guid: 0bd2ec5d73751e34a814274a454bec41, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _ColorMask: 15
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UseUIAlphaClip: 0
|
||||
m_Colors:
|
||||
- _OuterUV: {r: 0, g: 0, b: 1, a: 1}
|
||||
- _WidthHeightRadius: {r: 1180, g: 75, b: 20, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!1 &971230925
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -7187,7 +7228,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
|
||||
m_Material: {fileID: 1209760313}
|
||||
m_Material: {fileID: 931340537}
|
||||
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
@@ -7974,7 +8015,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
|
||||
m_Material: {fileID: 560411584}
|
||||
m_Material: {fileID: 943778468}
|
||||
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
@@ -8014,47 +8055,6 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier: Nobi.UiRoundedCorners::Nobi.UiRoundedCorners.ImageWithRoundedCorners
|
||||
radius: 10
|
||||
image: {fileID: 1208331055}
|
||||
--- !u!21 &1209760313
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: UI/RoundedCorners/RoundedCorners
|
||||
m_Shader: {fileID: 4800000, guid: 0bd2ec5d73751e34a814274a454bec41, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _ColorMask: 15
|
||||
- _Stencil: 0
|
||||
- _StencilComp: 8
|
||||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _UseUIAlphaClip: 0
|
||||
m_Colors:
|
||||
- _OuterUV: {r: 0, g: 0, b: 1, a: 1}
|
||||
- _WidthHeightRadius: {r: 1180, g: 75, b: 20, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
--- !u!1 &1301936379
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -9749,7 +9749,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 6534417478244952628, guid: dbf71fe5f2caad1409da64bdbb781eb5, type: 3}
|
||||
m_Sprite: {fileID: 21300000, guid: 517f61beffc1245a0a3f7907c7c93eb0, type: 3}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
@@ -10295,7 +10295,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &1748769838
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -11148,7 +11148,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &1940562851
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -11767,7 +11767,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &2042548466
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MikeSchweitzer.WebSocket;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -15,18 +15,12 @@ using UnityEngine.UI;
|
||||
|
||||
public class ChatroomMenu : MonoBehaviour
|
||||
{
|
||||
private readonly static WaitForSeconds _waitForSeconds2 = new(2f);
|
||||
private readonly static WaitForSeconds _waitForSeconds3 = new(3f);
|
||||
[SerializeField] private TMP_Text statusText;
|
||||
[SerializeField] private Button backButton;
|
||||
[SerializeField] private Button sendButton;
|
||||
[SerializeField] private TMP_InputField messageInputField;
|
||||
[SerializeField] private GameObject content;
|
||||
[SerializeField] private GameObject sampleObject;
|
||||
private string statusMessage;
|
||||
private Coroutine statusRoutine;
|
||||
private Coroutine refreshLoopRoutine;
|
||||
private bool shouldScrollToBottom = true;
|
||||
[SerializeField] private Button downButton;
|
||||
[SerializeField] private ProfileMenu profilePrefab;
|
||||
|
||||
@@ -45,7 +39,146 @@ public class ChatroomMenu : MonoBehaviour
|
||||
[SerializeField] private Button reportMessagePanelExitButton;
|
||||
[SerializeField] private Button reportMessagePanelSubmitButton;
|
||||
[SerializeField] private TMP_InputField reportMessagePanelReportReason;
|
||||
[SerializeField] private Dictionary<string, string> customIcons;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
WebsocketHandler.Instance._Connection.StateChanged += OnStateChanged;
|
||||
WebsocketHandler.Instance._Connection.MessageReceived += OnMessageReceived;
|
||||
if (WebsocketHandler.Instance._Connection.State == WebSocketState.Connected)
|
||||
{
|
||||
statusText.text = "Loading messages";
|
||||
RequestInfoMessage msg = new()
|
||||
{
|
||||
kind = "chatroom_messages"
|
||||
};
|
||||
WebsocketHandler.Instance._Connection.AddOutgoingMessage(JsonUtility.ToJson(msg));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStateChanged(WebSocketConnection connection, WebSocketState oldState, WebSocketState newState)
|
||||
{
|
||||
if (newState == WebSocketState.Connected)
|
||||
{
|
||||
statusText.text = "Loading messages";
|
||||
RequestInfoMessage msg = new()
|
||||
{
|
||||
kind = "chatroom_messages"
|
||||
};
|
||||
WebsocketHandler.Instance._Connection.AddOutgoingMessage(JsonUtility.ToJson(msg));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMessageReceived(WebSocketConnection connection, WebSocketMessage message)
|
||||
{
|
||||
if (message.String != null && connection.State == WebSocketState.Connected)
|
||||
{
|
||||
JToken data = JToken.Parse(message.String);
|
||||
if (data["for"] != null)
|
||||
{
|
||||
if (data["for"].ToString() == "info_request:chatroom_messages")
|
||||
{
|
||||
var userId = BazookaManager.Instance.GetAccountID();
|
||||
foreach (Transform item in content.transform)
|
||||
{
|
||||
if (!item.gameObject.activeSelf) continue;
|
||||
Destroy(item.gameObject);
|
||||
break;
|
||||
}
|
||||
foreach (var chatMessage in data["data"].ToObject<ChatroomMessage[]>())
|
||||
{
|
||||
InsertMessage(chatMessage, userId);
|
||||
}
|
||||
statusText.text = "";
|
||||
StartCoroutine(ScrollToBottom());
|
||||
CustomIconLoader.Init(FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None));
|
||||
}
|
||||
else if (data["for"].ToString() == "upload:chatroom_message")
|
||||
{
|
||||
var userId = BazookaManager.Instance.GetAccountID();
|
||||
var chatMessage = data["data"].ToObject<ChatroomMessage>();
|
||||
Destroy(content.transform.GetChild(1).gameObject);
|
||||
InsertMessage(chatMessage, userId);
|
||||
CustomIconLoader.Init(FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None));
|
||||
}
|
||||
else if (data["for"].ToString() == "delete:chatroom_message")
|
||||
{
|
||||
Destroy(content.transform.Find("ChatroomRow_" + data["data"]["id"].ToString() ?? "").gameObject);
|
||||
if (data["data"]["fillerMessage"].ToString() != null)
|
||||
{
|
||||
var userId = BazookaManager.Instance.GetAccountID();
|
||||
var chatMessage = data["data"]["fillerMessage"].ToObject<ChatroomMessage>();
|
||||
var row = InsertMessage(chatMessage, userId);
|
||||
row.transform.SetSiblingIndex(1);
|
||||
CustomIconLoader.Init(FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None));
|
||||
}
|
||||
}
|
||||
else if (data["for"].ToString() == "edit:chatroom_message")
|
||||
{
|
||||
if (data["data"]["newContent"].ToString() != null)
|
||||
{
|
||||
content.transform.Find("ChatroomRow_" + data["data"]["id"].ToString()).transform.GetChild(3).GetComponent<TMP_Text>().text = data["data"]["newContent"].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameObject InsertMessage(ChatroomMessage message, BigInteger? localUserId)
|
||||
{
|
||||
var obj = content.transform.Find("ChatroomRow_" + message.ID);
|
||||
|
||||
var rowInfo = Instantiate(sampleObject, content.transform);
|
||||
rowInfo.transform.SetSiblingIndex(content.transform.childCount - 1);
|
||||
var bgImg = rowInfo.transform.GetChild(0).GetComponent<Image>();
|
||||
var usernameText = rowInfo.transform.GetChild(1).GetComponent<TMP_Text>();
|
||||
var playerIcon = rowInfo.transform.GetChild(2).GetComponent<Image>();
|
||||
var playerIconButton = rowInfo.transform.GetChild(2).GetComponent<Button>();
|
||||
var playerOverlayIcon = playerIcon.transform.GetChild(0).GetComponent<Image>();
|
||||
var messageText = rowInfo.transform.GetChild(3).GetComponent<TMP_Text>();
|
||||
var optionsButton = rowInfo.transform.GetChild(4).GetComponent<Button>();
|
||||
|
||||
usernameText.text = message.Username;
|
||||
messageText.text = Encoding.UTF8.GetString(Convert.FromBase64String(message.Content));
|
||||
if (message.CustomIcon == null)
|
||||
{
|
||||
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + message.Icon);
|
||||
if (message.Icon == 1) playerIcon.sprite = Tools.GetIconForUser(message.UserID);
|
||||
playerOverlayIcon.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + message.Overlay);
|
||||
if (message.Overlay != 0) playerOverlayIcon.gameObject.SetActive(true);
|
||||
if (message.Overlay == 8) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.56f, 14.81f);
|
||||
else if (message.Overlay == 11) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-14.74451f, 20.39122f);
|
||||
else if (message.Overlay == 13) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.54019f, 14.70365f);
|
||||
try
|
||||
{
|
||||
playerIcon.color = new Color(message.BirdColor[0] / 255f, message.BirdColor[1] / 255f, message.BirdColor[2] / 255f);
|
||||
playerOverlayIcon.color = new Color(message.OverlayColor[0] / 255f, message.OverlayColor[1] / 255f, message.OverlayColor[2] / 255f);
|
||||
}
|
||||
catch
|
||||
{
|
||||
playerIcon.color = Color.white;
|
||||
playerOverlayIcon.color = Color.white;
|
||||
}
|
||||
}
|
||||
else playerIcon.gameObject.AddComponent<WaitingForCustomIcon>().ID = message.CustomIcon;
|
||||
playerIconButton.onClick.AddListener(async () =>
|
||||
{
|
||||
var clone = Instantiate(profilePrefab.gameObject, profilePrefab.gameObject.transform.parent);
|
||||
clone.SetActive(true);
|
||||
await clone.GetComponent<ProfileMenu>().Init(message.UserID);
|
||||
});
|
||||
optionsButton.onClick.AddListener(() => OptionsButtonClick(message, localUserId ?? 0));
|
||||
rowInfo.name = "ChatroomRow_" + message.ID;
|
||||
var entryComponet = rowInfo.AddComponent<ChatroomMenuEntry>();
|
||||
entryComponet.Init(bgImg, optionsButton);
|
||||
rowInfo.SetActive(true);
|
||||
return rowInfo;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
WebsocketHandler.Instance._Connection.StateChanged -= OnStateChanged;
|
||||
WebsocketHandler.Instance._Connection.MessageReceived -= OnMessageReceived;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -54,23 +187,18 @@ public class ChatroomMenu : MonoBehaviour
|
||||
{
|
||||
sendButton.interactable = false;
|
||||
messageInputField.interactable = false;
|
||||
ShowStatus("Warning: You are not logged in. Please log in to send messages.");
|
||||
}
|
||||
sendButton.onClick.AddListener(async () => await HandleMessageSubmit());
|
||||
sendButton.onClick.AddListener(HandleMessageSubmit);
|
||||
downButton.onClick.AddListener(() => StartCoroutine(ScrollToBottom()));
|
||||
messageInputField.textComponent.textWrappingMode = TextWrappingModes.Normal;
|
||||
messageInputField.onSubmit.AddListener(async (_) => await HandleMessageSubmit());
|
||||
refreshLoopRoutine = StartCoroutine(Loop());
|
||||
messageInputField.onSubmit.AddListener(_ => HandleMessageSubmit());
|
||||
|
||||
optionsPanelExitButton.onClick.AddListener(() =>
|
||||
{
|
||||
optionsPanel.SetActive(false);
|
||||
selectedMessageForOptions = null;
|
||||
});
|
||||
optionsPanelDeleteButton.onClick.AddListener(async () =>
|
||||
{
|
||||
if (selectedMessageForOptions != null) await HandleDelete();
|
||||
});
|
||||
optionsPanelDeleteButton.onClick.AddListener(() => { if (selectedMessageForOptions != null) HandleMessageDelete(); });
|
||||
optionsPanelDeleteButton.onClick.AddListener(optionsPanelExitButton.onClick.Invoke);
|
||||
optionsPanelEditButton.onClick.AddListener(() =>
|
||||
{
|
||||
@@ -91,7 +219,7 @@ public class ChatroomMenu : MonoBehaviour
|
||||
});
|
||||
editMessageChildSubmitButton.onClick.AddListener(async () =>
|
||||
{
|
||||
await HandleEdit();
|
||||
HandleMessageEdit();
|
||||
editMessagePanelCurrent = null;
|
||||
Destroy(editMessage);
|
||||
selectedMessageForOptions = null;
|
||||
@@ -109,43 +237,24 @@ public class ChatroomMenu : MonoBehaviour
|
||||
if (selectedMessageForOptions.CustomIcon == null)
|
||||
{
|
||||
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + selectedMessageForOptions.Icon);
|
||||
if (selectedMessageForOptions.Icon == 1)
|
||||
{
|
||||
playerIcon.sprite = Tools.GetIconForUser(selectedMessageForOptions.UserID);
|
||||
}
|
||||
if (selectedMessageForOptions.Icon == 1) playerIcon.sprite = Tools.GetIconForUser(selectedMessageForOptions.UserID);
|
||||
playerOverlayIcon.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + selectedMessageForOptions.Overlay);
|
||||
if (selectedMessageForOptions.Overlay == 0)
|
||||
{
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
else if (selectedMessageForOptions.Overlay == 8)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.56f, 14.81f);
|
||||
}
|
||||
else if (selectedMessageForOptions.Overlay == 11)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-14.74451f, 20.39122f);
|
||||
}
|
||||
else if (selectedMessageForOptions.Overlay == 13)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.54019f, 14.70365f);
|
||||
}
|
||||
if (selectedMessageForOptions.Overlay != 0) playerOverlayIcon.gameObject.SetActive(true);
|
||||
if (selectedMessageForOptions.Overlay == 8) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.56f, 14.81f);
|
||||
else if (selectedMessageForOptions.Overlay == 11) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-14.74451f, 20.39122f);
|
||||
else if (selectedMessageForOptions.Overlay == 13) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.54019f, 14.70365f);
|
||||
try
|
||||
{
|
||||
playerIcon.color = new Color(selectedMessageForOptions.BirdColor[0] / 255f, selectedMessageForOptions.BirdColor[1] / 255f, selectedMessageForOptions.BirdColor[2] / 255f);
|
||||
playerOverlayIcon.color = new Color(selectedMessageForOptions.OverlayColor[0] / 255f, selectedMessageForOptions.OverlayColor[1] / 255f, selectedMessageForOptions.OverlayColor[2] / 255f);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
playerIcon.color = Color.white;
|
||||
playerOverlayIcon.color = Color.white;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Tools.RenderFromBase64(customIcons[selectedMessageForOptions.CustomIcon], playerIcon);
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
else playerIcon.gameObject.AddComponent<WaitingForCustomIcon>().ID = selectedMessageForOptions.CustomIcon;
|
||||
|
||||
rowInfo = editMessageChild.GetChild(3);
|
||||
usernameText = rowInfo.transform.GetChild(2).GetComponent<TMP_Text>();
|
||||
@@ -160,46 +269,29 @@ public class ChatroomMenu : MonoBehaviour
|
||||
if (selectedMessageForOptions.CustomIcon == null)
|
||||
{
|
||||
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + selectedMessageForOptions.Icon);
|
||||
if (selectedMessageForOptions.Icon == 1)
|
||||
{
|
||||
playerIcon.sprite = Tools.GetIconForUser(selectedMessageForOptions.UserID);
|
||||
}
|
||||
if (selectedMessageForOptions.Icon == 1) playerIcon.sprite = Tools.GetIconForUser(selectedMessageForOptions.UserID);
|
||||
playerOverlayIcon.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + selectedMessageForOptions.Overlay);
|
||||
if (selectedMessageForOptions.Overlay == 0)
|
||||
{
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
else if (selectedMessageForOptions.Overlay == 8)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.56f, 14.81f);
|
||||
}
|
||||
else if (selectedMessageForOptions.Overlay == 11)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-14.74451f, 20.39122f);
|
||||
}
|
||||
else if (selectedMessageForOptions.Overlay == 13)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.54019f, 14.70365f);
|
||||
}
|
||||
if (selectedMessageForOptions.Overlay != 0) playerOverlayIcon.gameObject.SetActive(true);
|
||||
if (selectedMessageForOptions.Overlay == 8) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.56f, 14.81f);
|
||||
else if (selectedMessageForOptions.Overlay == 11) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-14.74451f, 20.39122f);
|
||||
else if (selectedMessageForOptions.Overlay == 13) playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.54019f, 14.70365f);
|
||||
try
|
||||
{
|
||||
playerIcon.color = new Color(selectedMessageForOptions.BirdColor[0] / 255f, selectedMessageForOptions.BirdColor[1] / 255f, selectedMessageForOptions.BirdColor[2] / 255f);
|
||||
playerOverlayIcon.color = new Color(selectedMessageForOptions.OverlayColor[0] / 255f, selectedMessageForOptions.OverlayColor[1] / 255f, selectedMessageForOptions.OverlayColor[2] / 255f);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
playerIcon.color = Color.white;
|
||||
playerOverlayIcon.color = Color.white;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Tools.RenderFromBase64(customIcons[selectedMessageForOptions.CustomIcon], playerIcon);
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
else playerIcon.gameObject.AddComponent<WaitingForCustomIcon>().ID = selectedMessageForOptions.CustomIcon;
|
||||
|
||||
optionsPanel.SetActive(false);
|
||||
editMessage.SetActive(true);
|
||||
|
||||
CustomIconLoader.Init(FindObjectsByType<WaitingForCustomIcon>(FindObjectsSortMode.None));
|
||||
});
|
||||
optionsPanelReportButton.onClick.AddListener(() =>
|
||||
{
|
||||
@@ -216,7 +308,7 @@ public class ChatroomMenu : MonoBehaviour
|
||||
reportMessagePanelSubmitButton.onClick.AddListener(async () =>
|
||||
{
|
||||
reportMessagePanel.SetActive(false);
|
||||
await HandleReport();
|
||||
await HandleMessageReport();
|
||||
editMessagePanelCurrent = null;
|
||||
selectedMessageForOptions = null;
|
||||
});
|
||||
@@ -227,79 +319,74 @@ public class ChatroomMenu : MonoBehaviour
|
||||
optionsPanelCopyButton.onClick.AddListener(optionsPanelExitButton.onClick.Invoke);
|
||||
}
|
||||
|
||||
IEnumerator Loop()
|
||||
void HandleMessageSubmit()
|
||||
{
|
||||
while (true)
|
||||
if (messageInputField.text.Trim() == string.Empty) return;
|
||||
sendButton.interactable = false;
|
||||
backButton.interactable = false;
|
||||
messageInputField.interactable = false;
|
||||
UploadMessage msg = new()
|
||||
{
|
||||
Refresh();
|
||||
yield return _waitForSeconds3;
|
||||
}
|
||||
kind = "chatroom_message",
|
||||
data = new JObject()
|
||||
{
|
||||
["content"] = messageInputField.text,
|
||||
["auth"] = BazookaManager.Instance.GetAccountSession()
|
||||
}
|
||||
};
|
||||
WebsocketHandler.Instance._Connection.AddOutgoingMessage(JsonConvert.SerializeObject(msg));
|
||||
sendButton.interactable = true;
|
||||
backButton.interactable = true;
|
||||
messageInputField.text = string.Empty;
|
||||
messageInputField.interactable = true;
|
||||
StartCoroutine(ScrollToBottom());
|
||||
}
|
||||
|
||||
async Task HandleMessageSubmit()
|
||||
void HandleMessageDelete()
|
||||
{
|
||||
if (!sendButton.interactable || messageInputField.text.Trim().Length == 0) return;
|
||||
backButton.interactable = false;
|
||||
var text = messageInputField.text.Clone() as string;
|
||||
messageInputField.text = string.Empty;
|
||||
if (string.IsNullOrEmpty(text))
|
||||
DeleteMessage msg = new()
|
||||
{
|
||||
return;
|
||||
}
|
||||
kind = "chatroom_message",
|
||||
data = new JObject()
|
||||
{
|
||||
["id"] = (int)selectedMessageForOptions.ID,
|
||||
["auth"] = BazookaManager.Instance.GetAccountSession()
|
||||
}
|
||||
};
|
||||
WebsocketHandler.Instance._Connection.AddOutgoingMessage(JsonConvert.SerializeObject(msg));
|
||||
StartCoroutine(ScrollToBottom());
|
||||
}
|
||||
|
||||
void HandleMessageEdit()
|
||||
{
|
||||
var newContent = editMessagePanelCurrent.transform.GetChild(0).GetChild(4).GetComponent<TMP_InputField>().text;
|
||||
selectedMessageForOptions.Content = newContent;
|
||||
EditMessage msg = new()
|
||||
{
|
||||
kind = "chatroom_message",
|
||||
data = new JObject()
|
||||
{
|
||||
["id"] = (int)selectedMessageForOptions.ID,
|
||||
["newContent"] = newContent,
|
||||
["auth"] = BazookaManager.Instance.GetAccountSession()
|
||||
}
|
||||
};
|
||||
WebsocketHandler.Instance._Connection.AddOutgoingMessage(JsonConvert.SerializeObject(msg));
|
||||
StartCoroutine(ScrollToBottom());
|
||||
}
|
||||
|
||||
async Task HandleMessageReport()
|
||||
{
|
||||
WWWForm dataForm = new();
|
||||
dataForm.AddField("content", text);
|
||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/sendChatroomMessage.php", dataForm);
|
||||
dataForm.AddField("id", selectedMessageForOptions.ID.ToString());
|
||||
dataForm.AddField("reason", reportMessagePanelReportReason.text);
|
||||
using UnityWebRequest request = UnityWebRequest.Post(Endpoints.CHATROOM_REPORT_MESSAGE_ENDPOINT, dataForm);
|
||||
request.SetRequestHeader("Authorization", BazookaManager.Instance.GetAccountSession());
|
||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||
await request.SendWebRequest();
|
||||
if (request.downloadHandler.text == null)
|
||||
{
|
||||
backButton.interactable = true;
|
||||
return;
|
||||
}
|
||||
string response = request.downloadHandler.text;
|
||||
if (response == "-999")
|
||||
{
|
||||
ShowStatus("Server error while fetching data");
|
||||
}
|
||||
else if (response == "-998")
|
||||
{
|
||||
ShowStatus("Client version too outdated to access servers");
|
||||
}
|
||||
else if (response == "-997")
|
||||
{
|
||||
ShowStatus("Encryption/decryption issues");
|
||||
}
|
||||
else if (response == "-996")
|
||||
{
|
||||
ShowStatus("Can't send requests on self-built instance");
|
||||
}
|
||||
else
|
||||
{
|
||||
var jsonResponse = JObject.Parse(response);
|
||||
if ((bool)jsonResponse["success"])
|
||||
{
|
||||
shouldScrollToBottom = true;
|
||||
StopCoroutine(refreshLoopRoutine);
|
||||
refreshLoopRoutine = StartCoroutine(Loop());
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowStatus((string)jsonResponse["message"]);
|
||||
}
|
||||
}
|
||||
backButton.interactable = true;
|
||||
}
|
||||
|
||||
void ShowStatus(string content)
|
||||
{
|
||||
statusMessage = content;
|
||||
if (statusRoutine != null) StopCoroutine(statusRoutine);
|
||||
statusRoutine = StartCoroutine(StatusRoutine());
|
||||
StartCoroutine(ScrollToBottom());
|
||||
}
|
||||
|
||||
async void Update()
|
||||
@@ -316,246 +403,6 @@ public class ChatroomMenu : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator StatusRoutine()
|
||||
{
|
||||
statusText.gameObject.SetActive(true);
|
||||
statusText.text = statusMessage;
|
||||
statusText.color = new Color(statusText.color.r, statusText.color.g, statusText.color.b, 0f);
|
||||
|
||||
float t = 0f;
|
||||
while (t < 0.5f)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float a = t / 0.5f;
|
||||
statusText.color = new Color(statusText.color.r, statusText.color.g, statusText.color.b, a);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
yield return _waitForSeconds2;
|
||||
|
||||
t = 0f;
|
||||
while (t < 0.5f)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float a = 1f - (t / 0.5f);
|
||||
statusText.color = new Color(statusText.color.r, statusText.color.g, statusText.color.b, a);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
statusText.gameObject.SetActive(false);
|
||||
statusText.text = "";
|
||||
statusRoutine = null;
|
||||
}
|
||||
|
||||
async void Refresh()
|
||||
{
|
||||
if (isPaused) return;
|
||||
using UnityWebRequest request = UnityWebRequest.Get(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/getChatroomMessages.php");
|
||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||
await request.SendWebRequest();
|
||||
if (request.downloadHandler.text == null)
|
||||
{
|
||||
Debug.LogError("Failed to fetch chatroom messages: " + request.error);
|
||||
return;
|
||||
}
|
||||
string response = request.downloadHandler.text;
|
||||
var shouldClear = true;
|
||||
switch (response)
|
||||
{
|
||||
case "-999":
|
||||
ShowStatus("Server error while fetching data");
|
||||
break;
|
||||
case "-998":
|
||||
ShowStatus("Client version too outdated to access servers");
|
||||
break;
|
||||
case "-997":
|
||||
ShowStatus("Encryption/decryption issues");
|
||||
break;
|
||||
case "-996":
|
||||
ShowStatus("Can't send requests on self-built instance");
|
||||
break;
|
||||
default:
|
||||
shouldClear = false;
|
||||
var jsonResponse = JObject.Parse(response);
|
||||
var messages = jsonResponse["messages"].ToObject<ChatroomMessage[]>();
|
||||
customIcons = jsonResponse["customIcons"].ToObject<Dictionary<string, string>>();
|
||||
var localUserId = BazookaManager.Instance.GetAccountID();
|
||||
var sortedMessages = messages.OrderBy(m => m.ID).ToArray();
|
||||
for (int i = 0; i < sortedMessages.Length; i++)
|
||||
{
|
||||
var message = sortedMessages[i];
|
||||
var obj = content.transform.Find("ChatroomRow_" + message.ID);
|
||||
if (message.Deleted)
|
||||
{
|
||||
if (obj != null) Destroy(obj.gameObject);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
var txt = obj.GetChild(3).GetComponent<TMP_Text>();
|
||||
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(message.Content));
|
||||
if (txt.text != decoded) txt.text = decoded;
|
||||
var btn = obj.GetChild(4).GetComponent<Button>();
|
||||
if (!btn.interactable)
|
||||
{
|
||||
btn.interactable = true;
|
||||
btn.onClick.AddListener(() => OptionsButtonClick(message, localUserId ?? 0));
|
||||
}
|
||||
obj.SetSiblingIndex(i);
|
||||
}
|
||||
int activeCount = content.transform.Cast<Transform>().Count(t => t.gameObject.activeSelf);
|
||||
if (activeCount > 50)
|
||||
{
|
||||
int toRemove = activeCount - 50;
|
||||
foreach (Transform item in content.transform)
|
||||
{
|
||||
if (!item.gameObject.activeSelf) continue;
|
||||
Destroy(item.gameObject);
|
||||
toRemove--;
|
||||
if (toRemove <= 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
var rowInfo = Instantiate(sampleObject, content.transform);
|
||||
rowInfo.transform.SetSiblingIndex(content.transform.childCount - 1);
|
||||
var bgImg = rowInfo.transform.GetChild(0).GetComponent<Image>();
|
||||
var usernameText = rowInfo.transform.GetChild(1).GetComponent<TMP_Text>();
|
||||
var playerIcon = rowInfo.transform.GetChild(2).GetComponent<Image>();
|
||||
var playerIconButton = rowInfo.transform.GetChild(2).GetComponent<Button>();
|
||||
var playerOverlayIcon = playerIcon.transform.GetChild(0).GetComponent<Image>();
|
||||
var messageText = rowInfo.transform.GetChild(3).GetComponent<TMP_Text>();
|
||||
var optionsButton = rowInfo.transform.GetChild(4).GetComponent<Button>();
|
||||
|
||||
usernameText.text = message.Username;
|
||||
messageText.text = Encoding.UTF8.GetString(Convert.FromBase64String(message.Content));
|
||||
if (message.CustomIcon == null)
|
||||
{
|
||||
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + message.Icon);
|
||||
if (message.Icon == 1)
|
||||
{
|
||||
playerIcon.sprite = Tools.GetIconForUser(message.UserID);
|
||||
}
|
||||
playerOverlayIcon.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + message.Overlay);
|
||||
if (message.Overlay == 0)
|
||||
{
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
else if (message.Overlay == 8)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.56f, 14.81f);
|
||||
}
|
||||
else if (message.Overlay == 11)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-14.74451f, 20.39122f);
|
||||
}
|
||||
else if (message.Overlay == 13)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.54019f, 14.70365f);
|
||||
}
|
||||
try
|
||||
{
|
||||
playerIcon.color = new Color(message.BirdColor[0] / 255f, message.BirdColor[1] / 255f, message.BirdColor[2] / 255f);
|
||||
playerOverlayIcon.color = new Color(message.OverlayColor[0] / 255f, message.OverlayColor[1] / 255f, message.OverlayColor[2] / 255f);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
playerIcon.color = Color.white;
|
||||
playerOverlayIcon.color = Color.white;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Tools.RenderFromBase64(customIcons[message.CustomIcon], playerIcon);
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
playerIconButton.onClick.AddListener(async () =>
|
||||
{
|
||||
var clone = Instantiate(profilePrefab.gameObject, profilePrefab.gameObject.transform.parent);
|
||||
clone.SetActive(true);
|
||||
await clone.GetComponent<ProfileMenu>().Init(message.UserID);
|
||||
});
|
||||
optionsButton.onClick.AddListener(() => OptionsButtonClick(message, localUserId ?? 0));
|
||||
rowInfo.name = "ChatroomRow_" + message.ID;
|
||||
var entryComponet = rowInfo.AddComponent<ChatroomMenuEntry>();
|
||||
entryComponet.Init(bgImg, optionsButton);
|
||||
rowInfo.SetActive(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (shouldClear)
|
||||
{
|
||||
foreach (Transform item in content.transform)
|
||||
{
|
||||
if (!item.gameObject.activeSelf) continue;
|
||||
Destroy(item.gameObject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shouldScrollToBottom)
|
||||
{
|
||||
shouldScrollToBottom = false;
|
||||
StartCoroutine(ScrollToBottom());
|
||||
}
|
||||
}
|
||||
|
||||
async Task HandleDelete()
|
||||
{
|
||||
WWWForm dataForm = new();
|
||||
dataForm.AddField("id", selectedMessageForOptions.ID.ToString());
|
||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/deleteChatroomMessage.php", dataForm);
|
||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||
await request.SendWebRequest();
|
||||
shouldScrollToBottom = true;
|
||||
StopCoroutine(refreshLoopRoutine);
|
||||
refreshLoopRoutine = StartCoroutine(Loop());
|
||||
}
|
||||
|
||||
async Task HandleEdit()
|
||||
{
|
||||
var newContent = editMessagePanelCurrent.transform.GetChild(0).GetChild(4).GetComponent<TMP_InputField>().text;
|
||||
selectedMessageForOptions.Content = newContent;
|
||||
WWWForm dataForm = new();
|
||||
dataForm.AddField("id", selectedMessageForOptions.ID.ToString());
|
||||
dataForm.AddField("content", newContent);
|
||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/editChatroomMessage.php", dataForm);
|
||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||
await request.SendWebRequest();
|
||||
shouldScrollToBottom = true;
|
||||
StopCoroutine(refreshLoopRoutine);
|
||||
refreshLoopRoutine = StartCoroutine(Loop());
|
||||
var button = content.transform.Find("ChatroomRow_" + selectedMessageForOptions.ID).GetChild(4).GetComponent<Button>();
|
||||
button.onClick.RemoveAllListeners();
|
||||
button.interactable = false;
|
||||
}
|
||||
|
||||
async Task HandleReport()
|
||||
{
|
||||
WWWForm dataForm = new();
|
||||
dataForm.AddField("id", selectedMessageForOptions.ID.ToString());
|
||||
dataForm.AddField("reason", reportMessagePanelReportReason.text);
|
||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/reportChatroomMessage.php", dataForm);
|
||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||
await request.SendWebRequest();
|
||||
shouldScrollToBottom = true;
|
||||
StopCoroutine(refreshLoopRoutine);
|
||||
refreshLoopRoutine = StartCoroutine(Loop());
|
||||
}
|
||||
|
||||
IEnumerator ScrollToBottom()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
@@ -25,4 +25,5 @@ public class Endpoints
|
||||
public const string ACCOUNT_CHANGE_PASSWORD_ENDPOINT = ACCOUNT_ENDPOINT + "/change-password";
|
||||
public const string ACCOUNT_FORGOT_USERNAME_ENDPOINT = BASE_URL + "/account/forgot-username";
|
||||
public const string ACCOUNT_FORGOT_PASSWORD_ENDPOINT = BASE_URL + "/account/forgot-password";
|
||||
public const string CHATROOM_REPORT_MESSAGE_ENDPOINT = BASE_URL + "/chatroom/report";
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class ChatroomMessage
|
||||
public string Username { get; set; }
|
||||
|
||||
[Preserve]
|
||||
[JsonProperty("userid")]
|
||||
[JsonProperty("userId")]
|
||||
public BigInteger UserID { get; set; }
|
||||
|
||||
[Preserve]
|
||||
@@ -37,10 +37,6 @@ public class ChatroomMessage
|
||||
[JsonProperty("overlayColor")]
|
||||
public int[] OverlayColor { get; set; }
|
||||
|
||||
[Preserve]
|
||||
[JsonProperty("deleted")]
|
||||
public bool Deleted { get; set; }
|
||||
|
||||
[Preserve]
|
||||
[JsonProperty("customIcon")]
|
||||
public string CustomIcon { get; set; }
|
||||
|
||||
11
Assets/Scripts/WSMessages/DeleteMessage.cs
Normal file
11
Assets/Scripts/WSMessages/DeleteMessage.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
[Serializable]
|
||||
public class DeleteMessage
|
||||
{
|
||||
public string type = "delete";
|
||||
public string kind;
|
||||
public JObject data;
|
||||
public long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
||||
2
Assets/Scripts/WSMessages/DeleteMessage.cs.meta
Normal file
2
Assets/Scripts/WSMessages/DeleteMessage.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56d6abb8593b14dc4b11d1309aac867e
|
||||
11
Assets/Scripts/WSMessages/EditMessage.cs
Normal file
11
Assets/Scripts/WSMessages/EditMessage.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
[Serializable]
|
||||
public class EditMessage
|
||||
{
|
||||
public string type = "edit";
|
||||
public string kind;
|
||||
public JObject data;
|
||||
public long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
||||
2
Assets/Scripts/WSMessages/EditMessage.cs.meta
Normal file
2
Assets/Scripts/WSMessages/EditMessage.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03f5f0a52e5744db9b2f5d77244d6271
|
||||
11
Assets/Scripts/WSMessages/UploadMessage.cs
Normal file
11
Assets/Scripts/WSMessages/UploadMessage.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
[Serializable]
|
||||
public class UploadMessage
|
||||
{
|
||||
public string type = "upload";
|
||||
public string kind;
|
||||
public JObject data;
|
||||
public long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
||||
2
Assets/Scripts/WSMessages/UploadMessage.cs.meta
Normal file
2
Assets/Scripts/WSMessages/UploadMessage.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a983ca9bb6c784740b4e38c2cb90711a
|
||||
Reference in New Issue
Block a user