Elin Decompiled Documentation EA 23.303 Nightly
Loading...
Searching...
No Matches
LayerPixelPaint.cs
Go to the documentation of this file.
1using System;
3using SFB;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class LayerPixelPaint : ELayer
8{
10
11 public GridLayoutGroup layoutColors;
12
14
15 public Action onApply;
16
17 private void Update()
18 {
19 if (Input.GetKeyDown(KeyCode.Escape))
20 {
21 Close();
22 }
23 }
24
25 public void SetCanvas(TraitCanvas c)
26 {
27 onApply = delegate
28 {
29 c.owner.PlaySound(c.owner.material.GetSoundImpact());
31 Thing thing = c.owner.Split(1);
32 thing.c_textureData = paint.tex.EncodeToPNG();
33 thing.isModified = true;
34 thing.ClearPaintSprite();
35 thing.GetPaintSprite();
36 thing.renderer.RefreshSprite();
37 Close();
38 };
39 paint.scale = c.SizeGrid;
40 paint.size = new Vector2Int(c.Width, c.Height);
41 InitPaint();
42 if (c.owner.c_textureData != null)
43 {
44 paint.tex.LoadImage(c.owner.c_textureData);
45 }
46 paint.imageMask.texture = c.owner.GetSprite().texture;
47 paint.imageMask.SetNativeSize();
48 paint.imagePreview.SetNativeSize();
49 }
50
51 public void InitPaint()
52 {
53 UIItem t = layoutColors.CreateMold<UIItem>();
54 for (int i = 0; i < 8; i++)
55 {
56 UIItem item = Util.Instantiate(t, layoutColors);
57 int _i = i;
58 item.button1.icon.color = IntColor.FromInt(ELayer.core.config.colors[_i]);
59 item.button1.SetOnClick(delegate
60 {
61 picker.SelectColor(item.button1.icon.color);
62 });
63 item.button2.SetOnClick(delegate
64 {
65 item.button1.icon.color = picker.SelectedColor;
67 SE.Tab();
68 });
69 }
70 layoutColors.RebuildLayout();
71 windows[0].AddBottomButton("apply", delegate
72 {
73 onApply?.Invoke();
74 });
75 windows[0].AddBottomButton("loadImage", delegate
76 {
77 DialogLoad(delegate
78 {
79 });
80 });
81 windows[0].AddBottomButton("cancel", delegate
82 {
83 Close();
84 });
85 paint.Init();
86 }
87
88 public void DialogLoad(Action onLoad = null)
89 {
91 {
92 string[] array = StandaloneFileBrowser.OpenFilePanel("Load PNG Image", CorePath.CustomDrawing, "png", multiselect: false);
93 if (array.Length != 0)
94 {
95 Texture2D texture2D = IO.LoadPNG(array[0]);
96 if (texture2D != null)
97 {
98 int num = (paint.size.x - texture2D.width) / 2;
99 int num2 = (paint.size.y - texture2D.height) / 2;
100 if (num < 0)
101 {
102 num = 0;
103 }
104 if (num2 < 0)
105 {
106 num2 = 0;
107 }
108 for (int i = 0; i < texture2D.height && i < paint.size.y; i++)
109 {
110 for (int j = 0; j < texture2D.width && j < paint.size.x; j++)
111 {
112 paint.tex.SetPixel(num + j, num2 + i, texture2D.GetPixel(j, i));
113 }
114 }
115 paint.tex.Apply();
116 SE.Change();
117 UnityEngine.Object.Destroy(texture2D);
118 }
119 }
120 });
121 }
122}
AnimeID
Definition: AnimeID.cs:2
void WaitForEndOfFrame(Action action)
Definition: BaseCore.cs:61
void PlayAnime(AnimeID id, bool force)
void RefreshSprite()
Thing Split(int a)
Definition: Card.cs:3568
SourceMaterial.Row material
Definition: Card.cs:2091
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6459
Sprite GetPaintSprite()
Definition: Card.cs:7401
virtual Sprite GetSprite(int dir=0)
Definition: Card.cs:6378
byte[] c_textureData
Definition: Card.cs:1969
CardRenderer renderer
Definition: Card.cs:64
void ClearPaintSprite()
Definition: Card.cs:7391
int[] colors
Definition: CoreConfig.cs:633
static string CustomDrawing
Definition: CorePath.cs:210
CoreConfig config
Definition: Core.cs:70
Definition: ELayer.cs:4
static Core core
Definition: ELayer.cs:7
void SelectColor(Color newColor)
Definition: ColorPicker.cs:218
static int ToInt(ref Color c)
Definition: IntColor.cs:24
static Color32 FromInt(int i)
Definition: IntColor.cs:15
PixelPaint paint
GridLayoutGroup layoutColors
ColorPicker picker
void DialogLoad(Action onLoad=null)
void SetCanvas(TraitCanvas c)
List< Window > windows
Definition: Layer.cs:116
virtual void Close()
Definition: Layer.cs:463
RawImage imagePreview
Definition: PixelPaint.cs:11
void Init()
Definition: PixelPaint.cs:94
Texture2D tex
Definition: PixelPaint.cs:23
RawImage imageMask
Definition: PixelPaint.cs:13
static string[] OpenFilePanel(string title, string directory, string extension, bool multiselect)
Definition: Thing.cs:8
virtual int Width
Definition: TraitCanvas.cs:14
virtual int SizeGrid
Definition: TraitCanvas.cs:18
virtual int Height
Definition: TraitCanvas.cs:16
Card owner
Definition: Trait.cs:28
Definition: UIItem.cs:5