Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UIScreenshot.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class UIScreenshot : EMono
7{
8 public static UIScreenshot Instance;
9
10 public Image imageFrame;
11
12 public InputField inputName;
13
15
17
18 public bool isDeactivating;
19
20 public static UIScreenshot Create()
21 {
22 return Util.Instantiate<UIScreenshot>("UI/Util/UIScreenshot", EMono.ui);
23 }
24
25 private void Awake()
26 {
27 Instance = this;
28 EMono.ui.Hide(0f);
29 }
30
31 public void Activate(PartialMap partial, DirectoryInfo dir, Action<PartialMap> onSave = null, bool isUpdate = false)
32 {
33 inputName.text = (MapPiece.IsEditor ? GetUniqueName("") : EMono._zone.Name);
34 if (isUpdate)
35 {
36 inputName.text = (MapPiece.IsEditor ? partial.ID : partial.name);
37 }
38 buttonSave.SetOnClick(delegate
39 {
40 isDeactivating = true;
41 SE.Play("camera");
42 GetComponent<CanvasGroup>().alpha = 0f;
43 string text = dir.FullName + "/" + (MapPiece.IsEditor ? inputName.text.IsEmpty("new") : GetUniqueName("user")) + ".mp";
44 if (isUpdate)
45 {
47 {
48 PartialMap.Delete(partial.path);
49 }
50 else
51 {
52 text = partial.path;
53 }
54 }
55 partial.name = inputName.text.IsEmpty(EMono._zone.Name);
56 partial.path = text;
57 File.Copy(PartialMap.PathTemp, text, overwrite: true);
58 SavePreview(text, partial.name, delegate
59 {
60 if ((bool)PartialMapMenu.Instance)
61 {
62 PartialMapMenu.Instance.Refresh();
63 }
64 Deactivate();
65 if (onSave != null)
66 {
67 onSave(partial);
68 }
69 });
70 });
71 string GetUniqueName(string id)
72 {
73 for (int i = 1; i < 999999; i++)
74 {
75 if (!File.Exists(dir.FullName + "/" + id + i + ".mp"))
76 {
77 return id + i;
78 }
79 }
80 return id;
81 }
82 }
83
84 private void Update()
85 {
86 if (isDeactivating)
87 {
89 }
90 else if (EInput.rightMouse.clicked || Input.GetKeyDown(KeyCode.Escape))
91 {
92 Deactivate();
93 }
94 }
95
96 public static void SavePreview(string path, string name, Action onSave)
97 {
98 EMono.core.actionsNextFrame.Add(delegate
99 {
100 EMono.core.actionsNextFrame.Add(delegate
101 {
102 Texture2D texture2D = ScreenCapture.CaptureScreenshotAsTexture();
103 texture2D.filterMode = FilterMode.Point;
104 int num = 300;
105 int num2 = 200;
106 float num3 = (float)num / (float)Screen.width;
107 float num4 = (float)num2 / (float)Screen.height;
108 Vector2 scale = new Vector2(num3, num4);
109 Vector2 offset = new Vector2((1f - num3) * 0.5f, (1f - num4) * 0.5f);
110 RenderTexture renderTexture = new RenderTexture(num, num2, 0);
111 renderTexture.filterMode = FilterMode.Point;
112 renderTexture.Create();
113 RenderTexture active = RenderTexture.active;
114 RenderTexture.active = renderTexture;
115 Graphics.Blit(texture2D, renderTexture, scale, offset);
116 Texture2D texture2D2 = new Texture2D(num, num2, texture2D.format, mipChain: false);
117 texture2D2.filterMode = FilterMode.Point;
118 texture2D2.ReadPixels(new Rect(0f, 0f, num, num2), 0, 0);
119 texture2D2.Apply();
120 RenderTexture.active = active;
121 renderTexture.Release();
122 File.WriteAllBytes(path.GetFullFileNameWithoutExtension() + ".jpg", texture2D2.EncodeToJPG());
123 File.WriteAllText(path.GetFullFileNameWithoutExtension() + ".txt", name);
124 UnityEngine.Object.Destroy(texture2D2);
125 UnityEngine.Object.Destroy(texture2D);
126 UnityEngine.Object.Destroy(renderTexture);
127 onSave?.Invoke();
128 });
129 });
130 }
131
132 public void Deactivate()
133 {
134 UnityEngine.Object.Destroy(base.gameObject);
135 EMono.ui.Show(0f);
136 EInput.Consume();
137 }
138}
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
bool clicked
Definition: ButtonState.cs:37
Definition: EInput.cs:8
static void Consume(int _skipFrame)
Definition: EInput.cs:656
static ButtonState rightMouse
Definition: EInput.cs:351
Definition: EMono.cs:4
static Core core
Definition: EMono.cs:5
static Zone _zone
Definition: EMono.cs:19
static UI ui
Definition: EMono.cs:15
static bool IsEditor
Definition: MapPiece.cs:47
static void Delete(string path)
Definition: PartialMap.cs:507
string path
Definition: PartialMap.cs:68
static string PathTemp
Definition: PartialMap.cs:86
string name
Definition: PartialMap.cs:28
virtual string Name
Definition: Spatial.cs:495
UIButton buttonSave
Definition: UIScreenshot.cs:14
void Awake()
Definition: UIScreenshot.cs:25
InputField inputName
Definition: UIScreenshot.cs:12
void Deactivate()
static UIScreenshot Create()
Definition: UIScreenshot.cs:20
void Activate(PartialMap partial, DirectoryInfo dir, Action< PartialMap > onSave=null, bool isUpdate=false)
Definition: UIScreenshot.cs:31
Image imageFrame
Definition: UIScreenshot.cs:10
void Update()
Definition: UIScreenshot.cs:84
static void SavePreview(string path, string name, Action onSave)
Definition: UIScreenshot.cs:96
bool isDeactivating
Definition: UIScreenshot.cs:18
UIButton buttonCancel
Definition: UIScreenshot.cs:16
static UIScreenshot Instance
Definition: UIScreenshot.cs:8