Chatroom menu!
This commit is contained in:
2945
Assets/Scenes/ChatroomMenu.unity
Normal file
2945
Assets/Scenes/ChatroomMenu.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/ChatroomMenu.unity.meta
Normal file
7
Assets/Scenes/ChatroomMenu.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6d51f8ef1f7d4f01a8416e468a7ed278
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -2057,142 +2057,6 @@ CanvasRenderer:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1097153681}
|
m_GameObject: {fileID: 1097153681}
|
||||||
m_CullTransparentMesh: 1
|
m_CullTransparentMesh: 1
|
||||||
--- !u!1 &1221390703
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 1221390704}
|
|
||||||
- component: {fileID: 1221390706}
|
|
||||||
- component: {fileID: 1221390705}
|
|
||||||
m_Layer: 5
|
|
||||||
m_Name: Text (TMP)
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!224 &1221390704
|
|
||||||
RectTransform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1221390703}
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 2038556860}
|
|
||||||
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_AnchoredPosition: {x: 0, y: -21.5}
|
|
||||||
m_SizeDelta: {x: 200, y: 50}
|
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
|
||||||
--- !u!114 &1221390705
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1221390703}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
m_Material: {fileID: 0}
|
|
||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
|
||||||
m_RaycastTarget: 1
|
|
||||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
|
||||||
m_Maskable: 1
|
|
||||||
m_OnCullStateChanged:
|
|
||||||
m_PersistentCalls:
|
|
||||||
m_Calls: []
|
|
||||||
m_text: Coming 1.5.1
|
|
||||||
m_isRightToLeft: 0
|
|
||||||
m_fontAsset: {fileID: 11400000, guid: 4fd546dd0900395408d2de20f5025882, type: 2}
|
|
||||||
m_sharedMaterial: {fileID: -1476194838487357290, guid: 4fd546dd0900395408d2de20f5025882, type: 2}
|
|
||||||
m_fontSharedMaterials: []
|
|
||||||
m_fontMaterial: {fileID: 0}
|
|
||||||
m_fontMaterials: []
|
|
||||||
m_fontColor32:
|
|
||||||
serializedVersion: 2
|
|
||||||
rgba: 4278255615
|
|
||||||
m_fontColor: {r: 1, g: 1, b: 0, a: 1}
|
|
||||||
m_enableVertexGradient: 0
|
|
||||||
m_colorMode: 3
|
|
||||||
m_fontColorGradient:
|
|
||||||
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
|
||||||
topRight: {r: 1, g: 1, b: 1, a: 1}
|
|
||||||
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
|
||||||
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
|
||||||
m_fontColorGradientPreset: {fileID: 0}
|
|
||||||
m_spriteAsset: {fileID: 0}
|
|
||||||
m_tintAllSprites: 0
|
|
||||||
m_StyleSheet: {fileID: 0}
|
|
||||||
m_TextStyleHashCode: -1183493901
|
|
||||||
m_overrideHtmlColors: 0
|
|
||||||
m_faceColor:
|
|
||||||
serializedVersion: 2
|
|
||||||
rgba: 4294967295
|
|
||||||
m_fontSize: 16
|
|
||||||
m_fontSizeBase: 16
|
|
||||||
m_fontWeight: 400
|
|
||||||
m_enableAutoSizing: 0
|
|
||||||
m_fontSizeMin: 18
|
|
||||||
m_fontSizeMax: 72
|
|
||||||
m_fontStyle: 0
|
|
||||||
m_HorizontalAlignment: 2
|
|
||||||
m_VerticalAlignment: 512
|
|
||||||
m_textAlignment: 65535
|
|
||||||
m_characterSpacing: 0
|
|
||||||
m_wordSpacing: 0
|
|
||||||
m_lineSpacing: 0
|
|
||||||
m_lineSpacingMax: 0
|
|
||||||
m_paragraphSpacing: 0
|
|
||||||
m_charWidthMaxAdj: 0
|
|
||||||
m_TextWrappingMode: 1
|
|
||||||
m_wordWrappingRatios: 0.4
|
|
||||||
m_overflowMode: 0
|
|
||||||
m_linkedTextComponent: {fileID: 0}
|
|
||||||
parentLinkedComponent: {fileID: 0}
|
|
||||||
m_enableKerning: 0
|
|
||||||
m_ActiveFontFeatures: 6e72656b
|
|
||||||
m_enableExtraPadding: 0
|
|
||||||
checkPaddingRequired: 0
|
|
||||||
m_isRichText: 1
|
|
||||||
m_EmojiFallbackSupport: 1
|
|
||||||
m_parseCtrlCharacters: 1
|
|
||||||
m_isOrthographic: 1
|
|
||||||
m_isCullingEnabled: 0
|
|
||||||
m_horizontalMapping: 0
|
|
||||||
m_verticalMapping: 0
|
|
||||||
m_uvLineOffset: 0
|
|
||||||
m_geometrySortingOrder: 0
|
|
||||||
m_IsTextObjectScaleStatic: 0
|
|
||||||
m_VertexBufferAutoSizeReduction: 0
|
|
||||||
m_useMaxVisibleDescender: 1
|
|
||||||
m_pageToDisplay: 1
|
|
||||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
|
||||||
m_isUsingLegacyAnimationComponent: 0
|
|
||||||
m_isVolumetricText: 0
|
|
||||||
m_hasFontAssetChanged: 0
|
|
||||||
m_baseMaterial: {fileID: 0}
|
|
||||||
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
|
||||||
--- !u!222 &1221390706
|
|
||||||
CanvasRenderer:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1221390703}
|
|
||||||
m_CullTransparentMesh: 1
|
|
||||||
--- !u!1 &1263503579
|
--- !u!1 &1263503579
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -4360,7 +4224,6 @@ RectTransform:
|
|||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1657120008}
|
- {fileID: 1657120008}
|
||||||
- {fileID: 1221390704}
|
|
||||||
m_Father: {fileID: 1266243668}
|
m_Father: {fileID: 1266243668}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
@@ -4420,7 +4283,7 @@ MonoBehaviour:
|
|||||||
m_PressedTrigger: Pressed
|
m_PressedTrigger: Pressed
|
||||||
m_SelectedTrigger: Selected
|
m_SelectedTrigger: Selected
|
||||||
m_DisabledTrigger: Disabled
|
m_DisabledTrigger: Disabled
|
||||||
m_Interactable: 0
|
m_Interactable: 1
|
||||||
m_TargetGraphic: {fileID: 2038556863}
|
m_TargetGraphic: {fileID: 2038556863}
|
||||||
m_OnClick:
|
m_OnClick:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
|
|||||||
239
Assets/Scripts/ChatroomMenu.cs
Normal file
239
Assets/Scripts/ChatroomMenu.cs
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class ChatroomMenu : MonoBehaviour
|
||||||
|
{
|
||||||
|
public TMP_Text statusText;
|
||||||
|
public Button backButton;
|
||||||
|
public Button sendButton;
|
||||||
|
public TMP_InputField messageInputField;
|
||||||
|
public GameObject content;
|
||||||
|
public GameObject sampleObject;
|
||||||
|
private string statusMessage;
|
||||||
|
private Coroutine statusRoutine;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
backButton.onClick.AddListener(async () => await SceneManager.LoadSceneAsync("MainMenu"));
|
||||||
|
sendButton.onClick.AddListener(async () => await HandleMessageSubmit());
|
||||||
|
messageInputField.textComponent.textWrappingMode = TextWrappingModes.Normal;
|
||||||
|
messageInputField.onSubmit.AddListener(async (_) => await HandleMessageSubmit());
|
||||||
|
StartCoroutine(Loop());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSceneUnloaded()
|
||||||
|
{
|
||||||
|
StopAllCoroutines();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator Loop() {
|
||||||
|
while (true) {
|
||||||
|
Refresh();
|
||||||
|
yield return new WaitForSeconds(3f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task HandleMessageSubmit()
|
||||||
|
{
|
||||||
|
var text = messageInputField.text.Clone() as string;
|
||||||
|
messageInputField.text = string.Empty;
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EncryptedWWWForm dataForm = new();
|
||||||
|
dataForm.AddField("content", text);
|
||||||
|
dataForm.AddField("gameSession", PlayerPrefs.GetString("gameSession", ""));
|
||||||
|
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "sendChatroomMessage.php", dataForm.GetWWWForm());
|
||||||
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
|
await request.SendWebRequest();
|
||||||
|
if (request.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string response = SensitiveInfo.Decrypt(request.downloadHandler.text, SensitiveInfo.SERVER_RECEIVE_TRANSFER_KEY);
|
||||||
|
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 "-1":
|
||||||
|
ShowStatus("Authentication error.");
|
||||||
|
break;
|
||||||
|
case "1":
|
||||||
|
StopCoroutine(Loop());
|
||||||
|
StartCoroutine(Loop());
|
||||||
|
content.transform.localPosition = new Vector2(0f, 0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowStatus(string content)
|
||||||
|
{
|
||||||
|
statusMessage = content;
|
||||||
|
if (statusRoutine != null) StopCoroutine(statusRoutine);
|
||||||
|
statusRoutine = StartCoroutine(StatusRoutine());
|
||||||
|
}
|
||||||
|
|
||||||
|
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 new WaitForSeconds(2f);
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
using UnityWebRequest request = UnityWebRequest.Get(SensitiveInfo.SERVER_DATABASE_PREFIX + "getChatroomMessages.php");
|
||||||
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
|
await request.SendWebRequest();
|
||||||
|
if (request.result != UnityWebRequest.Result.Success)
|
||||||
|
{
|
||||||
|
Debug.LogError("Failed to fetch chatroom messages: " + request.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string response = SensitiveInfo.Decrypt(request.downloadHandler.text, SensitiveInfo.SERVER_RECEIVE_TRANSFER_KEY);
|
||||||
|
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 "-1":
|
||||||
|
ShowStatus("Authentication error.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
var split = response.Split(':');
|
||||||
|
if (split[0] == "1")
|
||||||
|
{
|
||||||
|
shouldClear = false;
|
||||||
|
foreach (var row in split[1].Split("|"))
|
||||||
|
{
|
||||||
|
var rowSplit = row.Split(';');
|
||||||
|
var id = rowSplit[0];
|
||||||
|
var username = Encoding.UTF8.GetString(Convert.FromBase64String(rowSplit[1]));
|
||||||
|
var chatContent = Encoding.UTF8.GetString(Convert.FromBase64String(rowSplit[2]));
|
||||||
|
var icon = rowSplit[3];
|
||||||
|
var overlay = rowSplit[4];
|
||||||
|
var uid = rowSplit[5];
|
||||||
|
var birdR = rowSplit[6];
|
||||||
|
var birdG = rowSplit[7];
|
||||||
|
var birdB = rowSplit[8];
|
||||||
|
|
||||||
|
if (content.transform.Find("ChatroomRow_" + id) != null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (content.transform.childCount > 50)
|
||||||
|
{
|
||||||
|
var firstChild = content.transform.GetChild(0);
|
||||||
|
Destroy(firstChild.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
var rowInfo = Instantiate(sampleObject, content.transform);
|
||||||
|
var usernameText = rowInfo.transform.GetChild(0).GetComponent<TMP_Text>();
|
||||||
|
var playerIcon = usernameText.transform.GetChild(0).GetComponent<Image>();
|
||||||
|
var playerOverlayIcon = playerIcon.transform.GetChild(0).GetComponent<Image>();
|
||||||
|
var messageText = rowInfo.transform.GetChild(1).GetComponent<TMP_Text>();
|
||||||
|
|
||||||
|
usernameText.text = username;
|
||||||
|
messageText.text = chatContent;
|
||||||
|
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + icon);
|
||||||
|
if (icon == "1")
|
||||||
|
{
|
||||||
|
playerIcon.sprite = Tools.GetIconForUser(int.Parse(uid));
|
||||||
|
}
|
||||||
|
playerOverlayIcon.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlay);
|
||||||
|
if (overlay == "0")
|
||||||
|
{
|
||||||
|
playerOverlayIcon.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
else if (overlay == "8")
|
||||||
|
{
|
||||||
|
playerOverlayIcon.transform.localPosition = new Vector2(-16.56f, 14.81f);
|
||||||
|
}
|
||||||
|
else if (overlay == "11")
|
||||||
|
{
|
||||||
|
playerOverlayIcon.transform.localPosition = new Vector2(-14.74451f, 20.39122f);
|
||||||
|
}
|
||||||
|
else if (overlay == "13")
|
||||||
|
{
|
||||||
|
playerOverlayIcon.transform.localPosition = new Vector2(-16.54019f, 14.70365f);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
playerIcon.color = new Color32(byte.Parse(birdR), byte.Parse(birdG), byte.Parse(birdB), 255);
|
||||||
|
} catch (Exception)
|
||||||
|
{
|
||||||
|
playerIcon.color = Color.white;
|
||||||
|
}
|
||||||
|
rowInfo.name = "ChatroomRow_" + id;
|
||||||
|
rowInfo.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowStatus("Error fetching messages.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (shouldClear)
|
||||||
|
{
|
||||||
|
foreach (Transform item in content.transform)
|
||||||
|
{
|
||||||
|
if (item.gameObject.activeSelf)
|
||||||
|
{
|
||||||
|
Destroy(item.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/ChatroomMenu.cs.meta
Normal file
2
Assets/Scripts/ChatroomMenu.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0dbd2b8269756e018b7c71d0e878242c
|
||||||
@@ -14,6 +14,9 @@ EditorBuildSettings:
|
|||||||
- enabled: 1
|
- enabled: 1
|
||||||
path: Assets/Scenes/AccountMenu.unity
|
path: Assets/Scenes/AccountMenu.unity
|
||||||
guid: 61d560f45a39646489a33d9e871b5336
|
guid: 61d560f45a39646489a33d9e871b5336
|
||||||
|
- enabled: 1
|
||||||
|
path: Assets/Scenes/ChatroomMenu.unity
|
||||||
|
guid: 6d51f8ef1f7d4f01a8416e468a7ed278
|
||||||
- enabled: 1
|
- enabled: 1
|
||||||
path: Assets/Scenes/GamePlayer.unity
|
path: Assets/Scenes/GamePlayer.unity
|
||||||
guid: 8d9f90781cae8d24c8560dbca7ed6f42
|
guid: 8d9f90781cae8d24c8560dbca7ed6f42
|
||||||
|
|||||||
Reference in New Issue
Block a user