Tanoda
SaveHelpButton.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Text;
6using B83.Win32;
7using GILES;
8using GILES.Interface;
9using UnityEngine;
10using UnityEngine.UI;
11
13{
14
16
17 public TMPro.TMP_InputField inField;
18
19 public override string tooltip { get { return Macro.T("BTN_SAVE_HELP"); } }
20
24 public void OpenSavePanel()
25 {
26 pb_FileDialog dlog = GameObject.Instantiate(dialogPrefab);
27 dlog.SetDirectory(Application.streamingAssetsPath);
28 dlog.isFileBrowser = true;
29 dlog.filePattern = "*.hlp";
30 dlog.AddOnSaveListener(OnSave);
31
32 pb_ModalWindow.SetContent(dlog.gameObject);
33 pb_ModalWindow.SetTitle("BTN_SAVE_HELP");
35 }
36
37 private void OnSave(string path)
38 {
39 var txtColor = inField.textComponent.color;
40 var bgColor = inField.gameObject.GetComponent<Image>().color;
41#if UNITY_WEBGL
42 var fdd = FindObjectOfType<FileDragAndDrop>();
43 fdd.OnFileData(Encoding.UTF8.GetBytes(txtColor.r + ":" + txtColor.g + ":" + txtColor.b + ":" + txtColor.a + ":" + bgColor.r + ":" + bgColor.g + ":" + bgColor.b + ":" + bgColor.a + ":\n" + inField.text), path.Remove(0, path.LastIndexOf("/") + 1) + (path.EndsWith(".hlp") ? "" : ".hlp"), TimeStamp());
44 LoadingManager.instance.HideWindow();
45#else
46 File.WriteAllText(path + (path.EndsWith(".hlp") ? "" : ".hlp"), txtColor.r + ":" + txtColor.g + ":" + txtColor.b + ":" + txtColor.a + ":" + bgColor.r + ":" + bgColor.g + ":" + bgColor.b + ":" + bgColor.a + ":\n" + inField.text);
47
48 var fdd = FindObjectOfType<FileDragAndDrop>();
49 fdd.OnFiles(new List<string>(){path + (path.EndsWith(".hlp") ? "" : ".hlp")}, new POINT(-1,-1));
50#endif
51 StartCoroutine(WaitOneReload());
52 }
53 IEnumerator WaitOneReload()
54 {
55 yield return null;
57 }
58
59 private string TimeStamp()
60 {
61 var now = DateTime.Now;
62 //2020-12-07T09:32:13.398Z
63 return $"{now.Year}-{now.Month:D2}-{now.Day:D2}T{now.Hour:D2}:{now.Minute:D2}:{now.Second:D2}.{now.Millisecond:D3}Z";
64 }
65}
System.Drawing.Image Image
Definition: TestScript.cs:37
string filePattern
If isFileBrowser is true, this string my be used to filter file results (see https://msdn....
void AddOnSaveListener(Callback< string > listener)
void SetDirectory(string directory)
static void SetTitle(string title)
static void SetContent(GameObject prefab)
static pb_PrefabBrowser instance
Definition: Macro.cs:12
static string T(string key)
Definition: Macro.cs:19
pb_FileDialog dialogPrefab
TMPro.TMP_InputField inField
override string tooltip
void OpenSavePanel()
Definition: B83.Win32.cs:38