KAZIK/build/installer/PokerGameSetup/SlideShow.cs

498 lines
13 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace PokerGameSetup;
internal sealed class SlideShow : Control
{
private struct Particle
{
public float X;
public float Y;
public float Speed;
public float Size;
public float Alpha;
public float SwayOffset;
}
private readonly Image[] frames;
private readonly string[] captions = new string[8]
{
"Вечер в казино",
"Покерные баталии",
"Лаунж и живая музыка",
"Блэкджек с дилером",
"Комната предсказательницы",
"Европейская рулетка",
"Боулинг и мини-игры",
"Игровые автоматы"
};
private readonly string[] tags = new string[8]
{
"3D HALL RAYCASTER",
"TEXAS HOLD'EM",
"CABARET & LOUNGE",
"BLACKJACK 21",
"NEURAL TAROT AI",
"ROULETTE WHEEL",
"CLUB ACTIVITIES",
"SLOTS 777"
};
private readonly Particle[] particles;
private readonly Stopwatch clock = Stopwatch.StartNew();
private double lastTimeSeconds;
private int currentSlide;
private int prevSlide;
private float transitionAlpha = 1.0f;
private double slideStayTimer;
private bool hoveredLeftArrow;
private bool hoveredRightArrow;
private int hoveredCapsule = -1;
public SlideShow()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
Cursor = Cursors.Default;
Assembly assembly = Assembly.GetExecutingAssembly();
frames = ((IEnumerable<string>)(from n in assembly.GetManifestResourceNames()
where n.StartsWith("slide.")
orderby n
select n)).Select((Func<string, Image>)((string n) =>
{
using Stream stream = assembly.GetManifestResourceStream(n);
using Image original = Image.FromStream(stream);
return new Bitmap(original);
})).ToArray();
Random rnd = new Random(42);
particles = new Particle[32];
for (int i = 0; i < particles.Length; i++)
{
particles[i] = new Particle
{
X = (float)rnd.NextDouble(),
Y = (float)rnd.NextDouble(),
Speed = 0.02f + (float)rnd.NextDouble() * 0.04f,
Size = 1.5f + (float)rnd.NextDouble() * 3.5f,
Alpha = 40f + (float)rnd.NextDouble() * 90f,
SwayOffset = (float)rnd.NextDouble() * 6.28f
};
}
lastTimeSeconds = clock.Elapsed.TotalSeconds;
}
protected override void Dispose(bool disposing)
{
if (disposing && frames != null)
{
foreach (Image image in frames)
{
image?.Dispose();
}
}
base.Dispose(disposing);
}
public void AdvanceTime()
{
double now = clock.Elapsed.TotalSeconds;
double delta = now - lastTimeSeconds;
lastTimeSeconds = now;
if (delta < 0 || delta > 0.5)
{
delta = 0.033;
}
// Advance transition crossfade
if (transitionAlpha < 1.0f)
{
transitionAlpha = Math.Min(1.0f, transitionAlpha + (float)(delta * 2.8));
}
// Auto advance slide every 6 seconds
slideStayTimer += delta;
if (slideStayTimer >= 6.0)
{
NextSlide();
}
Invalidate();
}
public void GoToSlide(int index)
{
if (frames.Length == 0) return;
int clamped = Math.Max(0, Math.Min(frames.Length - 1, index));
if (clamped == currentSlide && transitionAlpha >= 1.0f) return;
prevSlide = currentSlide;
currentSlide = clamped;
transitionAlpha = 0.0f;
slideStayTimer = 0.0;
Invalidate();
}
public void NextSlide()
{
if (frames.Length == 0) return;
GoToSlide((currentSlide + 1) % frames.Length);
}
public void PrevSlide()
{
if (frames.Length == 0) return;
GoToSlide((currentSlide - 1 + frames.Length) % frames.Length);
}
private Rectangle GetLeftArrowRect()
{
return new Rectangle(18, (Height - 64) / 2, 46, 64);
}
private Rectangle GetRightArrowRect()
{
return new Rectangle(Width - 64, (Height - 64) / 2, 46, 64);
}
private Rectangle GetCapsuleRect(int index)
{
int startX = 35;
int curX = startX;
int count = frames.Length;
for (int i = 0; i < count; i++)
{
int w = (i == currentSlide) ? 38 : 18;
if (i == index)
{
return new Rectangle(curX, Height - 38, w, 8);
}
curX += w + 8;
}
return Rectangle.Empty;
}
private int HitTestCapsule(Point pt)
{
int count = frames.Length;
for (int i = 0; i < count; i++)
{
Rectangle r = GetCapsuleRect(i);
Rectangle hit = new Rectangle(r.Left - 4, Height - 52, r.Width + 8, 36);
if (hit.Contains(pt))
{
return i;
}
}
return -1;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
bool oldLeft = hoveredLeftArrow;
bool oldRight = hoveredRightArrow;
int oldCap = hoveredCapsule;
hoveredLeftArrow = GetLeftArrowRect().Contains(e.Location);
hoveredRightArrow = GetRightArrowRect().Contains(e.Location);
hoveredCapsule = HitTestCapsule(e.Location);
if (hoveredLeftArrow || hoveredRightArrow || hoveredCapsule >= 0)
{
Cursor = Cursors.Hand;
}
else
{
Cursor = Cursors.Default;
}
if (oldLeft != hoveredLeftArrow || oldRight != hoveredRightArrow || oldCap != hoveredCapsule)
{
Invalidate();
}
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
hoveredLeftArrow = false;
hoveredRightArrow = false;
hoveredCapsule = -1;
Cursor = Cursors.Default;
Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button != MouseButtons.Left) return;
if (GetLeftArrowRect().Contains(e.Location))
{
PrevSlide();
return;
}
if (GetRightArrowRect().Contains(e.Location))
{
NextSlide();
return;
}
int cap = HitTestCapsule(e.Location);
if (cap >= 0)
{
GoToSlide(cap);
return;
}
}
private void DrawFrame(Graphics g, Image image, float opacity)
{
if (image == null) return;
float scale = Math.Max((float)Width / (float)image.Width, (float)(Height - 170) / (float)image.Height) * 1.02f;
int dw = (int)((float)image.Width * scale);
int dh = (int)((float)image.Height * scale);
Rectangle destRect = new Rectangle((Width - dw) / 2, 90 + (Height - 170 - dh) / 2, dw, dh);
using ImageAttributes attr = new ImageAttributes();
ColorMatrix matrix = new ColorMatrix();
matrix.Matrix33 = Math.Max(0f, Math.Min(1f, opacity));
attr.SetColorMatrix(matrix);
g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attr);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(Color.FromArgb(10, 14, 16));
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;
// 1. Draw slide frames with smooth crossfade
if (frames.Length > 0)
{
if (transitionAlpha < 1.0f && prevSlide >= 0 && prevSlide < frames.Length)
{
DrawFrame(g, frames[prevSlide], 1.0f);
}
if (currentSlide >= 0 && currentSlide < frames.Length)
{
DrawFrame(g, frames[currentSlide], transitionAlpha);
}
}
// 2. Atmospheric Gold Dust Particles
double totalSec = clock.Elapsed.TotalSeconds;
float tFloat = (float)totalSec;
for (int i = 0; i < particles.Length; i++)
{
float py = (particles[i].Y - tFloat * particles[i].Speed) % 1.0f;
if (py < 0) py += 1.0f;
float px = particles[i].X + (float)Math.Sin(tFloat * 1.5f + particles[i].SwayOffset) * 0.03f;
if (px < 0) px += 1.0f;
if (px > 1) px -= 1.0f;
float screenX = px * Width;
float screenY = py * Height;
int alpha = (int)particles[i].Alpha;
using (SolidBrush pBrush = new SolidBrush(Color.FromArgb(alpha, 245, 218, 140)))
{
g.FillEllipse(pBrush, screenX, screenY, particles[i].Size, particles[i].Size);
}
}
// 3. Top subtle vignette
using (LinearGradientBrush topGrad = new LinearGradientBrush(new Rectangle(0, 0, Width, 190), Color.FromArgb(240, 12, 16, 18), Color.Transparent, 90f))
{
g.FillRectangle(topGrad, 0, 0, Width, 190);
}
// 4. Bottom rich vignette
using (LinearGradientBrush btmGrad = new LinearGradientBrush(new Rectangle(0, Height - 260, Width, 260), Color.Transparent, Color.FromArgb(250, 10, 14, 16), 90f))
{
g.FillRectangle(btmGrad, 0, Height - 260, Width, 260);
}
// 5. Left separator line
using (Pen pen = new Pen(Color.FromArgb(50, 229, 190, 112), 1f))
{
g.DrawLine(pen, 0, 0, 0, Height);
}
// 6. Header Badge
using (SolidBrush badgeBrush = new SolidBrush(Color.FromArgb(40, 229, 190, 112)))
{
Rectangle headerBadge = new Rectangle(35, 30, 205, 22);
using (GraphicsPath bp = CreateRoundedRectangle(headerBadge, 4))
{
g.FillPath(badgeBrush, bp);
using (Pen bpPen = new Pen(Color.FromArgb(120, 229, 190, 112), 1f))
{
g.DrawPath(bpPen, bp);
}
}
}
using (SolidBrush brush3 = new SolidBrush(InstallerForm.Gold))
{
using Font font = new Font("Segoe UI", 8.5f, FontStyle.Bold);
g.DrawString("✦ ВНУТРИ ASSEMBLER CASINO ✦", font, brush3, 42f, 33f);
}
// 7. Slide Tag
string tag = tags[currentSlide % tags.Length];
using (SolidBrush tagBrush = new SolidBrush(Color.FromArgb(200, 165, 90)))
{
using Font tagFont = new Font("Segoe UI", 9f, FontStyle.Bold);
g.DrawString("◆ " + tag, tagFont, tagBrush, 37f, Height - 160);
}
// 8. Slide Caption
string caption = captions[currentSlide % captions.Length];
using (SolidBrush shadowBrush = new SolidBrush(Color.FromArgb(190, 0, 0, 0)))
{
using Font font2 = new Font("Georgia", 26f, FontStyle.Bold);
g.DrawString(caption, font2, shadowBrush, 39f, Height - 134);
}
using (SolidBrush brush4 = new SolidBrush(InstallerForm.Paper))
{
using Font font2 = new Font("Georgia", 26f, FontStyle.Bold);
g.DrawString(caption, font2, brush4, 37f, Height - 136);
}
// 9. Subtitle
using (SolidBrush brush5 = new SolidBrush(Color.FromArgb(160, 175, 170)))
{
using Font font3 = new Font("Segoe UI", 9.5f);
g.DrawString("Настоящие игровые кадры · Чистый x86 MASM Ассемблер", font3, brush5, 37f, Height - 88);
}
// 10. Navigation Capsules
int count = frames.Length;
for (int i = 0; i < count; i++)
{
bool isActive = (i == currentSlide);
bool isHov = (i == hoveredCapsule);
Rectangle capRect = GetCapsuleRect(i);
using (GraphicsPath cp = CreateRoundedRectangle(capRect, 4))
{
Color capColor;
if (isActive)
{
capColor = InstallerForm.Gold;
}
else if (isHov)
{
capColor = Color.FromArgb(200, 240, 220);
}
else
{
capColor = Color.FromArgb(60, 72, 70);
}
using (SolidBrush capBrush = new SolidBrush(capColor))
{
g.FillPath(capBrush, cp);
}
if (isActive)
{
using (Pen capGlow = new Pen(Color.FromArgb(120, 255, 235, 160), 2f))
{
g.DrawPath(capGlow, cp);
}
}
else if (isHov)
{
using (Pen hovBorder = new Pen(Color.FromArgb(180, 229, 190, 112), 1f))
{
g.DrawPath(hovBorder, cp);
}
}
}
}
// 11. Left & Right Arrow Buttons (Always visible!)
DrawArrowButton(g, GetLeftArrowRect(), isLeft: true, hoveredLeftArrow);
DrawArrowButton(g, GetRightArrowRect(), isLeft: false, hoveredRightArrow);
}
private void DrawArrowButton(Graphics g, Rectangle rect, bool isLeft, bool isHov)
{
using (GraphicsPath path = CreateRoundedRectangle(rect, 8))
{
Color bgColor = isHov ? Color.FromArgb(200, 36, 42, 46) : Color.FromArgb(120, 18, 22, 25);
using (SolidBrush bg = new SolidBrush(bgColor))
{
g.FillPath(bg, path);
}
Color borderColor = isHov ? Color.FromArgb(255, 235, 160) : Color.FromArgb(110, 180, 150, 95);
using (Pen border = new Pen(borderColor, isHov ? 1.8f : 1.2f))
{
g.DrawPath(border, path);
}
// Arrow Chevron
Color arrowColor = isHov ? Color.FromArgb(255, 245, 205) : InstallerForm.Gold;
using (Pen arrowPen = new Pen(arrowColor, 2.8f))
{
arrowPen.StartCap = LineCap.Round;
arrowPen.EndCap = LineCap.Round;
int cx = rect.X + rect.Width / 2;
int cy = rect.Y + rect.Height / 2;
if (isLeft)
{
g.DrawLine(arrowPen, cx + 4, cy - 10, cx - 4, cy);
g.DrawLine(arrowPen, cx - 4, cy, cx + 4, cy + 10);
}
else
{
g.DrawLine(arrowPen, cx - 4, cy - 10, cx + 4, cy);
g.DrawLine(arrowPen, cx + 4, cy, cx - 4, cy + 10);
}
}
}
}
private static GraphicsPath CreateRoundedRectangle(Rectangle r, int d)
{
GraphicsPath path = new GraphicsPath();
if (d <= 0)
{
path.AddRectangle(r);
return path;
}
int x = r.X;
int y = r.Y;
int w = r.Width;
int h = r.Height;
path.AddArc(x, y, d, d, 180, 90);
path.AddArc(x + w - d, y, d, d, 270, 90);
path.AddArc(x + w - d, y + h - d, d, d, 0, 90);
path.AddArc(x, y + h - d, d, d, 90, 90);
path.CloseFigure();
return path;
}
}