Firstborn/Assets/Scripts/MyGallery.cs
Schaken-Mods 0698087242 Scene cells are split
all scenes are split, all seems working.
2023-06-19 12:17:45 -05:00

136 lines
4.9 KiB
C#

using System.Collections; //
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;
using System.Text;
using System.IO;
using UnityEngine.UI;
using RPGCreationKit;
using UnityEngine.Networking;
using System.Net; // For the Discord
using System.Drawing;
namespace RPGCreationKit
{
public class MyGallery : MonoBehaviour
{
[Header("Auto fills")]
[SerializeField] private OnlineAccountHandler OAH;
[SerializeField] private GameObject MyGalleryGO;
[SerializeField] private string[] Folders;
[SerializeField] private TextMeshProUGUI[] AvatarNames;
[SerializeField] public GameObject[] Screenshots;
[Header("Avatar")]
[SerializeField] private Transform FoldersContainer;
[SerializeField] List<GameObject> CreatedFolderPrefab;
[SerializeField] public AudioSource source;
[Header("Screenshots")]
[SerializeField] private GameObject FolderPrefab;
[SerializeField] private Transform ImagesContainer;
[SerializeField] public List<GameObject> CreatedImagePrefab;
[Header("Expanded Screenshot")]
[SerializeField] public RawImage BigImage;
[SerializeField] public GameObject BigImageContainer;
[SerializeField] public GameObject BigImageCloseButton;
[SerializeField] private TextMeshProUGUI ImageTitle;
[SerializeField] private TextMeshProUGUI ImageDescription;
[SerializeField] private TextMeshProUGUI FPlace;
[SerializeField] private TextMeshProUGUI FTime;
[SerializeField] private TextMeshProUGUI FExtension;
[SerializeField] public string FileDir;
public void RefreshAvatarList() {
Folders = System.IO.Directory.GetDirectories(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)+@"\My Games\Firstborn\Screenshots","*", System.IO.SearchOption.AllDirectories);
for (int i = 0; i < Folders.Length; i++) {
var NewFolder = Instantiate(FolderPrefab, FoldersContainer);
CreatedFolderPrefab.Add(NewFolder);
string TempAvatarName = Folders[i].Split(new string[] { @"Firstborn\Screenshots\" }, StringSplitOptions.None)[1].Split (@"\")[0].Trim ();
AvatarFolderName NewFolderGO = NewFolder.GetComponent<AvatarFolderName>();
NewFolderGO.FolderPath = Folders[i];
NewFolderGO.ImagesContainer = ImagesContainer;
NewFolderGO.MyGalleryGO = MyGalleryGO;
ButtonSounds BS = NewFolderGO.GetComponent<ButtonSounds>();
BS.source = source;
NewFolderGO.AvatarName.text = TempAvatarName;
}
}
public void RefreshScreenshotList() {
Folders = System.IO.Directory.GetDirectories(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)+@"\My Games\Firstborn\Screenshots","*", System.IO.SearchOption.AllDirectories);
for (int i = 0; i < Folders.Length; i++) {
var NewFolder = Instantiate(FolderPrefab, FoldersContainer);
CreatedFolderPrefab.Add(NewFolder);
string TempAvatarName = Folders[i].Split(new string[] { @"Firstborn\Screenshots\" }, StringSplitOptions.None)[1].Split (@"\")[0].Trim ();
Debug.Log(TempAvatarName);
AvatarFolderName NewFolderGO = NewFolder.GetComponent<AvatarFolderName>();
NewFolderGO.AvatarName.text = TempAvatarName;
}
}
public void ClearAllFolders() {
for (int i = 0; i < CreatedFolderPrefab.Count; i++) {
CreatedFolderPrefab[i].SetActive(false);
}
CreatedFolderPrefab.Clear();
}
public void ExpandImage(RawImage A) {
BigImage.texture = A.texture;
BigImage.SetNativeSize();
BigImage.SizeToParent();
BigImageCloseButton.SetActive(true);
BigImageContainer.SetActive(true);
}
public void PostInformation(FileInfo A) {
string TempName = A.Name.Split("_")[1].Split (".")[0].Trim ();
FPlace.text = TempName;
var CreatedAt = A.CreationTime;
FTime.text = CreatedAt.ToString();
FExtension.text = A.Extension;
}
public void UploadImage() {
StartCoroutine(PostImageA());
}
IEnumerator PostImageA() {
Texture2D textureImg = BigImage.texture as Texture2D;
Byte[] ImageData = System.IO.File.ReadAllBytes(FileDir);
WWWForm content = new WWWForm();
content.AddField("category", "27");
//content.AddBinaryData("image", ImageData, System.IO.Path.GetFileName(FileDir), "image/png");
content.AddField(System.IO.Path.GetFileName(FileDir), Convert.ToBase64String(ImageData));
content.AddField("caption", ImageTitle.text);
content.AddField("filename", Path.GetFileName(FileDir));
content.AddField("description", ImageDescription.text);
using (UnityWebRequest www = UnityWebRequest.Post("https://schaken-mods.com/api/gallery/images", content)) {
www.SetRequestHeader("Authorization", "Bearer " + OAH.BearerID);
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.ConnectionError) {
Debug.Log("Error While Sending TEST: " + www.error);
} else {
string result = www.downloadHandler.text;
string FullTXT = System.Text.RegularExpressions.Regex.Unescape(result);
Debug.Log("TEST: " + FullTXT);
}
}
}
}
}