diff --git a/assets/icon/dtr-256.png b/assets/icon/dtr-256.png new file mode 100644 index 0000000..9c5c84d Binary files /dev/null and b/assets/icon/dtr-256.png differ diff --git a/assets/icon/dtr-512.png b/assets/icon/dtr-512.png new file mode 100644 index 0000000..206da48 Binary files /dev/null and b/assets/icon/dtr-512.png differ diff --git a/assets/icon/dtr.ico b/assets/icon/dtr.ico new file mode 100644 index 0000000..e5f8302 Binary files /dev/null and b/assets/icon/dtr.ico differ diff --git a/assets/icon/dtr.rc b/assets/icon/dtr.rc new file mode 100644 index 0000000..99f41d8 --- /dev/null +++ b/assets/icon/dtr.rc @@ -0,0 +1,2 @@ +// icone de l'executable (launcher, jeu) : rc /fo dtr.res dtr.rc +1 ICON "dtr.ico" diff --git a/assets/icon/social-preview.png b/assets/icon/social-preview.png new file mode 100644 index 0000000..42fa0c6 Binary files /dev/null and b/assets/icon/social-preview.png differ diff --git a/launcher/build.rs b/launcher/build.rs new file mode 100644 index 0000000..18833b6 --- /dev/null +++ b/launcher/build.rs @@ -0,0 +1,58 @@ +//! Icône de l'exécutable : compile assets/icon/dtr.rc avec rc.exe du SDK Windows (installé avec les +//! Build Tools) et lie la ressource. Sans rc.exe, le launcher se compile quand même, sans icône. + +use std::path::{Path, PathBuf}; +use std::process::Command; + +fn find_rc() -> Option { + if let Some(p) = std::env::var_os("RC").map(PathBuf::from).filter(|p| p.is_file()) { + return Some(p); + } + let arch = if cfg!(target_arch = "aarch64") { "arm64" } else { "x64" }; + for base in ["ProgramFiles(x86)", "ProgramFiles"] { + let Some(b) = std::env::var_os(base) else { continue }; + let bin = Path::new(&b).join("Windows Kits").join("10").join("bin"); + let Ok(rd) = std::fs::read_dir(&bin) else { continue }; + // la version la plus récente qui contient rc.exe + let mut found: Vec = rd + .flatten() + .map(|e| e.path().join(arch).join("rc.exe")) + .filter(|p| p.is_file()) + .collect(); + found.sort(); + if let Some(p) = found.pop() { + return Some(p); + } + } + None +} + +fn main() { + let icon_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("assets").join("icon"); + println!("cargo:rerun-if-changed={}", icon_dir.join("dtr.rc").display()); + println!("cargo:rerun-if-changed={}", icon_dir.join("dtr.ico").display()); + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") + || std::env::var("CARGO_CFG_TARGET_ENV").as_deref() != Ok("msvc") + { + return; + } + let Some(rc) = find_rc() else { + println!("cargo:warning=rc.exe introuvable (SDK Windows) : launcher sans icone d'executable"); + return; + }; + let res = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("dtr.res"); + let ok = Command::new(&rc) + .current_dir(&icon_dir) + .arg("/nologo") + .arg("/fo") + .arg(&res) + .arg("dtr.rc") + .status() + .map(|s| s.success()) + .unwrap_or(false); + if ok { + println!("cargo:rustc-link-arg-bins={}", res.display()); + } else { + println!("cargo:warning=echec de rc.exe : launcher sans icone d'executable"); + } +} diff --git a/launcher/src/art.rs b/launcher/src/art.rs index 5e03c19..aae7c7d 100644 --- a/launcher/src/art.rs +++ b/launcher/src/art.rs @@ -333,34 +333,6 @@ pub fn logo(dir: &Path) -> Option { Some(img.to_rgba(x, y, w, h, |_, c| (lum(c) as u32 * 4).min(255) as u8)) } -/// icône : premier curseur de POINTER.PCX (fond = couleur du coin bas droit), agrandi en 32×32 -pub fn icon(dir: &Path) -> Option { - let img = decode_pcx(&read(dir, "POINTER.PCX")?)?; - let bg = img.px[img.w * img.h - 1]; - // premier sprite : en haut à gauche, jusqu'à la première ligne vide - let mut h = 0; - while h < img.h && img.px[h * img.w..h * img.w + 24.min(img.w)].iter().any(|&p| p != bg) { - h += 1; - } - let sub = Indexed { w: img.w, h: h.max(1), px: img.px[..img.w * h.max(1)].to_vec(), pal: img.pal }; - let (x, y, w, h) = bbox(&sub, |i, _| i != bg)?; - let side = w.max(h); - let src = sub.to_rgba(x, y, w, h, |i, _| if i == bg { 0 } else { 255 }); - let n = 32; - let mut px = vec![0u8; n * n * 4]; - let (ox, oy) = ((side - w) / 2, (side - h) / 2); - for ty in 0..n { - for tx in 0..n { - let (sx, sy) = (tx * side / n, ty * side / n); - if sx >= ox && sy >= oy && sx - ox < w && sy - oy < h { - let s = ((sy - oy) * w + (sx - ox)) * 4; - px[(ty * n + tx) * 4..][..4].copy_from_slice(&src.px[s..s + 4]); - } - } - } - Some(Rgba { w: n, h: n, px }) -} - #[cfg(test)] mod tests { #[test] diff --git a/launcher/src/main.rs b/launcher/src/main.rs index a7e7ed5..dd33a28 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -700,10 +700,6 @@ impl App { .map(|(i, b)| self.ctx.load_texture(format!("backdrop{i}"), to_image(b), opts)) .collect(); self.art.logo = art::logo(&dir).map(|l| self.ctx.load_texture("logo", to_image(&l), opts)); - if let Some(ic) = art::icon(&dir) { - let data = egui::IconData { rgba: ic.px, width: ic.w as u32, height: ic.h as u32 }; - self.ctx.send_viewport_cmd(egui::ViewportCommand::Icon(Some(Arc::new(data)))); - } } fn mods_dir(&self) -> Option { @@ -1749,6 +1745,15 @@ impl eframe::App for App { } } +/// icône de la fenêtre : assets/icon/dtr-256.png (tools/make_icon.py), intégrée à l'exécutable +fn window_icon() -> egui::IconData { + let png = include_bytes!("../../assets/icon/dtr-256.png"); + match mods::decode_png(std::io::Cursor::new(&png[..])) { + Some(i) => egui::IconData { rgba: i.px, width: i.w as u32, height: i.h as u32 }, + None => egui::IconData::default(), + } +} + fn main() -> eframe::Result { let cfg = Config::load(); let size = if cfg.win_w >= 760 && cfg.win_h >= 600 { @@ -1761,6 +1766,7 @@ fn main() -> eframe::Result { .with_title("DoubleTroubleRecomp") .with_inner_size(size) .with_maximized(cfg.maximized) + .with_icon(window_icon()) .with_min_inner_size([760.0, 600.0]), ..Default::default() }; diff --git a/launcher/src/mods.rs b/launcher/src/mods.rs index 6aa9d91..bae372d 100644 --- a/launcher/src/mods.rs +++ b/launcher/src/mods.rs @@ -117,7 +117,11 @@ pub fn hd_image(mods: &[Mod], disabled: &[String], pcx: &str) -> Option /// PNG → RGBA 8 bits pub fn load_png(path: &Path) -> Option { - let f = std::io::BufReader::new(std::fs::File::open(path).ok()?); + decode_png(std::io::BufReader::new(std::fs::File::open(path).ok()?)) +} + +/// PNG (lecteur quelconque) → RGBA 8 bits +pub fn decode_png(f: R) -> Option { let mut dec = png::Decoder::new(f); dec.set_transformations(png::Transformations::normalize_to_color8()); let mut reader = dec.read_info().ok()?; diff --git a/tools/make_icon.py b/tools/make_icon.py new file mode 100644 index 0000000..cb47cd7 --- /dev/null +++ b/tools/make_icon.py @@ -0,0 +1,138 @@ +r"""Génère l'icône du projet (« DT » dédoublé, façon BD) dans assets/icon/. + + python tools/make_icon.py + +Demande pygame (pip install pygame-ce). Produit : + dtr.ico 16 à 256 px (sans l'étiquette RECOMP sous 48 px, illisible) + dtr-512.png avatar du dépôt (Gitea) + dtr-256.png icône de la fenêtre du launcher (sans l'étiquette : lisible en petit) + social-preview.png aperçu social GitHub (1280×640) + dtr.rc ressource Windows (icône de l'exe) +Aucune image du jeu : seulement la police Bangers (SIL OFL) du launcher. +""" +import io +import math +import os +import struct + +import pygame + +ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") +FONT = os.path.join(ROOT, "launcher", "assets", "fonts", "Bangers-Regular.ttf") +OUT = os.path.join(ROOT, "assets", "icon") +Y, BK, P1, P2, PINK = (255, 210, 0), (0, 0, 0), (31, 27, 56), (74, 58, 140), (255, 51, 102) +N = 512 + + +def outlined(text, size, color, ow, shadow=0): + f = pygame.font.Font(FONT, size) + base, o = f.render(text, True, color), f.render(text, True, BK) + s = pygame.Surface((base.get_width() + 2 * ow + shadow, base.get_height() + 2 * ow + shadow), pygame.SRCALPHA) + for dx in range(-ow, ow + 1): + for dy in range(-ow, ow + 1): + if dx * dx + dy * dy <= ow * ow: + if shadow: + s.blit(o, (ow + dx + shadow, ow + dy + shadow)) + s.blit(o, (ow + dx, ow + dy)) + s.blit(base, (ow, ow)) + return s + + +def rays(w, h, cx, cy, n, alpha): + r = pygame.Surface((w, h), pygame.SRCALPHA) + big = 2 * max(w, h) + for k in range(n): + a0 = k * 2 * math.pi / n + a1 = a0 + math.pi / n + pygame.draw.polygon(r, (255, 210, 0, alpha), [(cx, cy), (cx + big * math.cos(a0), cy + big * math.sin(a0)), + (cx + big * math.cos(a1), cy + big * math.sin(a1))]) + return r + + +def gradient(w, h): + s = pygame.Surface((w, h), pygame.SRCALPHA) + for y in range(h): + t = y / h + pygame.draw.line(s, [int(P2[i] + (P1[i] - P2[i]) * t) for i in range(3)], (0, y), (w, y)) + return s + + +def icon(with_tag): + s = gradient(N, N) + s.blit(rays(N, N, N / 2, N / 2, 24, 34), (0, 0)) + mask = pygame.Surface((N, N), pygame.SRCALPHA) + pygame.draw.rect(mask, (255, 255, 255, 255), (4, 4, N - 8, N - 8), border_radius=96) + s.blit(mask, (0, 0), special_flags=pygame.BLEND_RGBA_MIN) + pygame.draw.rect(s, BK, (4, 4, N - 8, N - 8), 18, border_radius=96) + size, dy = (340, -26) if with_tag else (390, 0) + echo = pygame.transform.rotate(outlined("DT", size, PINK, 14), -6) + s.blit(echo, echo.get_rect(center=(N // 2 + 34, N // 2 + dy + 20))) + t = pygame.transform.rotate(outlined("DT", size, Y, 14, 12), 4) + s.blit(t, t.get_rect(center=(N // 2 - 16, N // 2 + dy))) + if with_tag: + f = pygame.font.Font(FONT, 64) + lab = f.render("RECOMP", True, BK) + r = pygame.Rect(0, 0, lab.get_width() + 44, lab.get_height() + 4) + r.center = (N // 2, 410) + pygame.draw.rect(s, BK, r.move(6, 6), border_radius=26) + pygame.draw.rect(s, Y, r, border_radius=26) + pygame.draw.rect(s, BK, r, 7, border_radius=26) + s.blit(lab, lab.get_rect(center=(r.centerx, r.centery + 2))) + return s + + +def png_bytes(surf): + b = io.BytesIO() + pygame.image.save(surf, b, "png") + return b.getvalue() + + +def write_ico(path, images): + """ICO avec des entrées PNG (format accepté par Windows Vista et suivants, et par rc.exe).""" + head = struct.pack("= 256 else size + entries += struct.pack("= 48 else small, (sz, sz)))) for sz in sizes] + write_ico(os.path.join(OUT, "dtr.ico"), imgs) + pygame.image.save(full, os.path.join(OUT, "dtr-512.png")) + pygame.image.save(pygame.transform.smoothscale(small, (256, 256)), os.path.join(OUT, "dtr-256.png")) + pygame.image.save(social(full), os.path.join(OUT, "social-preview.png")) + with open(os.path.join(OUT, "dtr.rc"), "w", encoding="ascii", newline="\r\n") as f: + f.write("// icone de l'executable (launcher, jeu) : rc /fo dtr.res dtr.rc\n1 ICON \"dtr.ico\"\n") + print("ok :", OUT) + + +if __name__ == "__main__": + main()