Files

70 lines
4.5 KiB
PowerShell

# Builds GUI\HUD\button-states-v2\rewards-states.png from shop-states.png: the bag icon is painted over with the
# button's own red face (per-row colours sampled from the face's left/right edges), then the gift art is drawn on it.
$root = "C:\Users\писикакич\my-project\ornament-generator-rng\Ornament-Generator-RNG\GUI"
Add-Type -ReferencedAssemblies System.Drawing -TypeDefinition @"
using System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D;
public static class RB {
static bool Face(Color c) { return c.A > 200 && c.R > 60 && c.G < 75 && c.B < 80; }
public static string Run(string src, string gift, string dst) {
var bmp = new Bitmap(src); var log = "";
int W = bmp.Width / 3, H = bmp.Height; int L0 = 0, R0 = 0;
using (var g = Graphics.FromImage(bmp)) {
g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic;
var giftImg = Image.FromFile(gift);
for (int f = 0; f < 3; f++) {
int ox = f * W, cy = H / 2;
int L = -1, R = -1;
for (int x = ox; x < ox + W / 2; x++) if (Face(bmp.GetPixel(x, cy))) { L = x; break; }
for (int x = ox + W - 1; x > ox + W / 2; x--) if (Face(bmp.GetPixel(x, cy))) { R = x; break; }
if (f == 0) { L0 = L - ox; R0 = R - ox; }
if (f == 2) { L = ox + L0; R = ox + R0; } // pressed state: dark face, same geometry as the normal one
int T = L - ox, B = R - ox; // the face is a square
int side = R - L; int rad = side / 7; int m = 3;
log += string.Format("frame{0}: L={1} R={2} T={3} B={4}; ", f, L, R, T, B);
// per-row face colours from the left / right face edge (rows outside the sampled band reuse the nearest one)
var left = new Color[H]; var right = new Color[H];
int lo = T + rad, hi = B - rad;
for (int y = 0; y < H; y++) {
int yy = Math.Max(lo, Math.Min(hi, y));
int sr = 0, sg = 0, sb = 0, tr = 0, tg = 0, tb = 0, n = 0;
for (int k = -6; k <= 6; k++) { int y2 = Math.Max(lo, Math.Min(hi, yy + k)); var p = bmp.GetPixel(L + 10, y2); var q = bmp.GetPixel(R - 10, y2);
sr += p.R; sg += p.G; sb += p.B; tr += q.R; tg += q.G; tb += q.B; n++; }
left[y] = Color.FromArgb(sr / n, sg / n, sb / n); right[y] = Color.FromArgb(tr / n, tg / n, tb / n);
}
for (int y = T + m; y <= B - m; y++) {
for (int x = L + m; x <= R - m; x++) {
// rounded rectangle test
int dx = Math.Max(0, Math.Max(L + rad - x, x - (R - rad))), dy = Math.Max(0, Math.Max(T + rad - y, y - (B - rad)));
if (dx * dx + dy * dy > (rad - m) * (rad - m)) continue;
var c = bmp.GetPixel(x, y);
bool snow = (y < T + side * 0.22) && (x < L + side * 0.33 || x > R - side * 0.33) && c.R > 190 && c.G > 190 && c.B > 190;
if (snow) continue;
double t = (double)(x - L) / side;
var a = left[y]; var b = right[y];
// slight bulge: brighter towards the middle, like the glossy face
double k = 1.0 + 0.10 * Math.Sin(Math.PI * t);
int r = (int)Math.Min(255, (a.R + (b.R - a.R) * t) * k), gg = (int)Math.Min(255, (a.G + (b.G - a.G) * t) * k), bb = (int)Math.Min(255, (a.B + (b.B - a.B) * t) * k);
bmp.SetPixel(x, y, Color.FromArgb(255, r, gg, bb));
}
}
// soft gloss band at the top of the face
using (var path = new GraphicsPath()) {
var gr = new Rectangle(L + side / 10, T + side / 14, side * 8 / 10, side / 3);
path.AddEllipse(gr);
using (var br = new LinearGradientBrush(gr, Color.FromArgb(34, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), 90f)) g.FillPath(br, path);
}
// the gift
int gs = (int)(side * 0.86);
g.DrawImage(giftImg, new Rectangle(L + (side - gs) / 2, T + (B - T - gs) / 2 + side / 30, gs, gs));
}
}
bmp.Save(dst, ImageFormat.Png); bmp.Dispose();
return log;
}
}
"@
[RB]::Run("$root\HUD\button-states-v2\shop-states.png", "$root\магазин\components\decor_gift.png", "$root\HUD\button-states-v2\rewards-states.png")
$i = [System.Drawing.Image]::FromFile("$root\HUD\button-states-v2\rewards-states.png"); $b = New-Object System.Drawing.Bitmap 900, 300
$g = [System.Drawing.Graphics]::FromImage($b); $g.DrawImage($i, 0, 0, 900, 300); $g.Dispose(); $i.Dispose()
$b.Save("C:\Users\писикакич\my-project\ornament-generator-rng\Ornament-Generator-RNG\tools\rewards_small.png"); $b.Dispose()