Icone du projet (DT dedouble) : .ico, avatar, apercu social ; integree a l'exe et a la fenetre du launcher
- tools/make_icon.py genere assets/icon/ (police Bangers, aucune image du jeu) - launcher/build.rs compile dtr.rc avec rc.exe du SDK Windows (sans dependance) - la fenetre du launcher prend dtr-256.png au lieu du curseur du jeu Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
de55ddbfc6
commit
61d5806492
10 files changed
+213
-33
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
@@ -0,0 +1,2 @@
|
|||||||
|
// icone de l'executable (launcher, jeu) : rc /fo dtr.res dtr.rc
|
||||||
|
1 ICON "dtr.ico"
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
@@ -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<PathBuf> {
|
||||||
|
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<PathBuf> = 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -333,34 +333,6 @@ pub fn logo(dir: &Path) -> Option<Rgba> {
|
|||||||
Some(img.to_rgba(x, y, w, h, |_, c| (lum(c) as u32 * 4).min(255) as u8))
|
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<Rgba> {
|
|
||||||
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
+10
-4
@@ -700,10 +700,6 @@ impl App {
|
|||||||
.map(|(i, b)| self.ctx.load_texture(format!("backdrop{i}"), to_image(b), opts))
|
.map(|(i, b)| self.ctx.load_texture(format!("backdrop{i}"), to_image(b), opts))
|
||||||
.collect();
|
.collect();
|
||||||
self.art.logo = art::logo(&dir).map(|l| self.ctx.load_texture("logo", to_image(&l), opts));
|
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<PathBuf> {
|
fn mods_dir(&self) -> Option<PathBuf> {
|
||||||
@@ -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 {
|
fn main() -> eframe::Result {
|
||||||
let cfg = Config::load();
|
let cfg = Config::load();
|
||||||
let size = if cfg.win_w >= 760 && cfg.win_h >= 600 {
|
let size = if cfg.win_w >= 760 && cfg.win_h >= 600 {
|
||||||
@@ -1761,6 +1766,7 @@ fn main() -> eframe::Result {
|
|||||||
.with_title("DoubleTroubleRecomp")
|
.with_title("DoubleTroubleRecomp")
|
||||||
.with_inner_size(size)
|
.with_inner_size(size)
|
||||||
.with_maximized(cfg.maximized)
|
.with_maximized(cfg.maximized)
|
||||||
|
.with_icon(window_icon())
|
||||||
.with_min_inner_size([760.0, 600.0]),
|
.with_min_inner_size([760.0, 600.0]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,7 +117,11 @@ pub fn hd_image(mods: &[Mod], disabled: &[String], pcx: &str) -> Option<PathBuf>
|
|||||||
|
|
||||||
/// PNG → RGBA 8 bits
|
/// PNG → RGBA 8 bits
|
||||||
pub fn load_png(path: &Path) -> Option<crate::art::Rgba> {
|
pub fn load_png(path: &Path) -> Option<crate::art::Rgba> {
|
||||||
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<R: std::io::BufRead + std::io::Seek>(f: R) -> Option<crate::art::Rgba> {
|
||||||
let mut dec = png::Decoder::new(f);
|
let mut dec = png::Decoder::new(f);
|
||||||
dec.set_transformations(png::Transformations::normalize_to_color8());
|
dec.set_transformations(png::Transformations::normalize_to_color8());
|
||||||
let mut reader = dec.read_info().ok()?;
|
let mut reader = dec.read_info().ok()?;
|
||||||
|
|||||||
@@ -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("<HHH", 0, 1, len(images))
|
||||||
|
entries, data = b"", b""
|
||||||
|
offset = 6 + 16 * len(images)
|
||||||
|
for size, blob in images:
|
||||||
|
b = 0 if size >= 256 else size
|
||||||
|
entries += struct.pack("<BBBBHHII", b, b, 0, 0, 1, 32, len(blob), offset + len(data))
|
||||||
|
data += blob
|
||||||
|
with open(path, "wb") as f:
|
||||||
|
f.write(head + entries + data)
|
||||||
|
|
||||||
|
|
||||||
|
def social(full):
|
||||||
|
W, H = 1280, 640
|
||||||
|
s = gradient(W, H)
|
||||||
|
s.blit(rays(W, H, 330, H / 2, 36, 26), (0, 0))
|
||||||
|
ic = pygame.transform.smoothscale(full, (400, 400))
|
||||||
|
s.blit(ic, (130, 120))
|
||||||
|
x0 = 600
|
||||||
|
t = outlined("DOUBLE TROUBLE", 118, Y, 6, 8)
|
||||||
|
s.blit(t, (x0, 150))
|
||||||
|
r = outlined("RECOMP", 118, (255, 255, 255), 6, 8)
|
||||||
|
s.blit(r, (x0, 265))
|
||||||
|
sub = outlined("Bud Tucker in Double Trouble (1996)", 40, (255, 255, 255), 3, 3)
|
||||||
|
s.blit(sub, (x0 + 4, 400))
|
||||||
|
sub2 = outlined("C natif · 1080p à 4K · pack HD · mods", 40, Y, 3, 3)
|
||||||
|
s.blit(sub2, (x0 + 4, 452))
|
||||||
|
pygame.draw.rect(s, (74, 58, 140), s.get_rect(), 8)
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
pygame.init()
|
||||||
|
os.makedirs(OUT, exist_ok=True)
|
||||||
|
full, small = icon(True), icon(False)
|
||||||
|
sizes = [16, 24, 32, 48, 64, 128, 256]
|
||||||
|
imgs = [(sz, png_bytes(pygame.transform.smoothscale(full if sz >= 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()
|
||||||
Reference in new issue
Block a user