forked from metnias/GreyScreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorMagic.cs
More file actions
184 lines (171 loc) · 6.47 KB
/
ColorMagic.cs
File metadata and controls
184 lines (171 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using RWCustom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace GreyScreen
{
public static class ColorMagic
{
public static Texture2D ClonePaletteTexture(Texture2D orig)
{
Texture2D t = new Texture2D(orig.width, orig.height, TextureFormat.ARGB32, false);
for (int v = 0; v < orig.height; v++)
{
for (int u = 0; u < orig.width; u++)
{
t.SetPixel(u, v, orig.GetPixel(u, v));
}
}
t.Apply();
return t;
}
public static Texture2D GreyMagic(Texture2D orig)
{
Texture2D t = ClonePaletteTexture(orig);
Color c = GreyPlugin.maskColor.Value;
//Shade
List<ColorID> ids = new List<ColorID>
{
ColorID.Sky,
ColorID.Fog,
//ColorID.Black,
//ColorID.Item,
ColorID.DeepWaterClose,
ColorID.DeepWaterFar,
ColorID.WaterSurfaceClose,
ColorID.WaterSurfaceFar,
ColorID.Effect1CloseShaded,
ColorID.Effect1FarShaded,
ColorID.Effect2CloseShaded,
ColorID.Effect2FarShaded,
ColorID.Effect1CloseLit,
ColorID.Effect1FarLit,
ColorID.Effect2CloseLit,
ColorID.Effect2FarLit,
ColorID.WaterSurfaceHighlight,
ColorID.SkyBloomObsolete
};
for (int p = 0; p < 2; p++)
{
for (int r = 0; r < 32; r++)
{
SetColor(p, ColorID.Rainbow, c, ref t, r);
}
for (int k = 0; k < 30; k++)
{
SetColor(p, ColorID.Terrain0, c, ref t, k);
SetColor(p, ColorID.Terrain1, c, ref t, k);
SetColor(p, ColorID.Terrain2, c, ref t, k); //close
SetColor(p, ColorID.Terrain3, c, ref t, k);
SetColor(p, ColorID.Terrain4, c, ref t, k);
SetColor(p, ColorID.Terrain5, c, ref t, k); //far
}
for (int d = ids.Count - 1; d >= 0; d--)
{
SetColor(p, ids[d], c, ref t);
}
SetColor(p, ColorID.FogAmount, Color.black, ref t);
}
t.Apply();
return t;
}
public static Color GetColor(int rain, ColorID id, Texture2D palette, int offset = 0)
{
IntVector2 uv = ColorUV[id];
return palette.GetPixel(uv.x + offset, uv.y + rain * 8);
}
public static void SetColor(int rain, ColorID id, Color color, ref Texture2D palette, int offset = 0)
{
IntVector2 uv = ColorUV[id];
palette.SetPixel(uv.x + offset, uv.y + rain * 8, color);
}
public static HSLColor RGBtoHSL(Color C)
{
RXColorHSL rx = RXColor.HSLFromColor(C);
HSLColor result = new HSLColor
{
hue = rx.h,
saturation = rx.s,
lightness = rx.l
};
return result;
}
public enum ColorID
{
Sky,
Fog,
Black,
Item,
DeepWaterClose,
DeepWaterFar,
WaterSurfaceClose,
WaterSurfaceFar,
WaterSurfaceHighlight,
FogAmount,
Shortcut1,
Shortcut2,
Shortcut3,
ShortcutSymbol,
SkyBloomObsolete,
RoomDarkness,
RainPalette,
Rainbow,
Effect1CloseLit,
Effect1CloseShaded,
Effect1FarLit,
Effect1FarShaded,
Effect2CloseLit,
Effect2CloseShaded,
Effect2FarLit,
Effect2FarShaded,
Terrain0,
Terrain1,
Terrain2,
Terrain3,
Terrain4,
Terrain5
}
public static Dictionary<ColorID, IntVector2> ColorUV;
public static void GenerateColorUV()
{
Dictionary<ColorID, IntVector2> dict = new Dictionary<ColorID, IntVector2>
{
{ ColorID.Sky, new IntVector2(0, 7) },
{ ColorID.Fog, new IntVector2(1, 7) },
{ ColorID.Black, new IntVector2(2, 7) },
{ ColorID.Item, new IntVector2(3, 7) },
{ ColorID.DeepWaterClose, new IntVector2(4, 7) },
{ ColorID.DeepWaterFar, new IntVector2(5, 7) },
{ ColorID.WaterSurfaceClose, new IntVector2(6, 7) },
{ ColorID.WaterSurfaceFar, new IntVector2(7, 7) },
{ ColorID.WaterSurfaceHighlight, new IntVector2(8, 7) },
{ ColorID.FogAmount, new IntVector2(9, 7) },
{ ColorID.Shortcut1, new IntVector2(10, 7) },
{ ColorID.Shortcut2, new IntVector2(11, 7) },
{ ColorID.Shortcut3, new IntVector2(12, 7) },
{ ColorID.ShortcutSymbol, new IntVector2(13, 7) },
{ ColorID.SkyBloomObsolete, new IntVector2(29, 7) },
{ ColorID.RoomDarkness, new IntVector2(30, 7) },
{ ColorID.RainPalette, new IntVector2(31, 7) },
{ ColorID.Rainbow, new IntVector2(0, 6) },
{ ColorID.Terrain0, new IntVector2(0, 5) },
{ ColorID.Terrain1, new IntVector2(0, 4) },
{ ColorID.Terrain2, new IntVector2(0, 3) },
{ ColorID.Terrain3, new IntVector2(0, 2) },
{ ColorID.Terrain4, new IntVector2(0, 1) },
{ ColorID.Terrain5, new IntVector2(0, 0) },
{ ColorID.Effect1CloseLit, new IntVector2(30, 6) },
{ ColorID.Effect1CloseShaded, new IntVector2(31, 6) },
{ ColorID.Effect1FarLit, new IntVector2(30, 5) },
{ ColorID.Effect1FarShaded, new IntVector2(31, 5) },
{ ColorID.Effect2CloseLit, new IntVector2(30, 4) },
{ ColorID.Effect2CloseShaded, new IntVector2(31, 4) },
{ ColorID.Effect2FarLit, new IntVector2(30, 3) },
{ ColorID.Effect2FarShaded, new IntVector2(31, 3) }
};
ColorUV = dict;
}
}
}