Fix: système de ticket & arriver-départ
This commit is contained in:
parent
d9afa32828
commit
a169449390
9 changed files with 61 additions and 69 deletions
|
|
@ -93,63 +93,56 @@ class Welcome(commands.Cog):
|
|||
background = Image.open(bg_path)
|
||||
draw = ImageDraw.Draw(background)
|
||||
|
||||
# Charger la police avec support des accents
|
||||
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf"
|
||||
if not os.path.exists(font_path):
|
||||
kuby_logger.warning(f"[Welcome] Police DejaVu introuvable, fallback sur police custom")
|
||||
font_path = os.path.join(self.base_dir, 'custom_font_large.otf')
|
||||
# Charger les polices custom (comme sur EXEMPLE_ARRIVER.png)
|
||||
font_large_path = os.path.join(self.base_dir, 'custom_font_large.otf')
|
||||
font_small_path = os.path.join(self.base_dir, 'custom_font_small.otf')
|
||||
|
||||
font = ImageFont.truetype(font_path, 55)
|
||||
|
||||
# Construire le message à afficher sur la bannière
|
||||
display_message = custom_message if custom_message else "Bienvenue {membre} chez {server}"
|
||||
|
||||
# Remplacer les placeholders
|
||||
try:
|
||||
display_message = display_message.format(
|
||||
membre=username,
|
||||
member=username,
|
||||
server=server_name or "",
|
||||
serveur=server_name or "",
|
||||
username=username,
|
||||
servername=server_name or "",
|
||||
)
|
||||
except Exception:
|
||||
pass # Si placeholders inconnus, garder tel quel
|
||||
# Les 3 lignes de texte à afficher (format identique à l'exemple)
|
||||
line1_text = "BIENVENUE"
|
||||
line2_text = username.upper()
|
||||
line3_text = (server_name or "").upper()
|
||||
|
||||
# Zone de texte disponible (à droite de l'avatar)
|
||||
text_area_left = 280
|
||||
text_area_right = background.width - 20
|
||||
text_area_width = text_area_right - text_area_left
|
||||
text_area_center_x = text_area_left + text_area_width // 2
|
||||
|
||||
# Découper le texte en lignes qui tiennent dans la zone
|
||||
words = display_message.split()
|
||||
lines = []
|
||||
current_line = ""
|
||||
for word in words:
|
||||
test_line = f"{current_line} {word}".strip()
|
||||
bbox = draw.textbbox((0, 0), test_line, font=font)
|
||||
if bbox[2] - bbox[0] <= text_area_width:
|
||||
current_line = test_line
|
||||
else:
|
||||
if current_line:
|
||||
lines.append(current_line)
|
||||
current_line = word
|
||||
if current_line:
|
||||
lines.append(current_line)
|
||||
# Fonction pour trouver la taille de police optimale
|
||||
def fit_font(font_path, text, max_size, max_width):
|
||||
size = max_size
|
||||
while size > 10:
|
||||
font = ImageFont.truetype(font_path, size)
|
||||
bbox = draw.textbbox((0, 0), text, font=font)
|
||||
w = bbox[2] - bbox[0]
|
||||
if w <= max_width:
|
||||
h = bbox[3] - bbox[1]
|
||||
return font, w, h
|
||||
size -= 2
|
||||
font = ImageFont.truetype(font_path, 10)
|
||||
bbox = draw.textbbox((0, 0), text, font=font)
|
||||
return font, bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||
|
||||
wrapped_text = "\n".join(lines)
|
||||
# Adapter chaque ligne à la zone disponible
|
||||
font1, w1, h1 = fit_font(font_large_path, line1_text, 65, text_area_width)
|
||||
font2, w2, h2 = fit_font(font_small_path, line2_text, 35, text_area_width)
|
||||
font3, w3, h3 = fit_font(font_large_path, line3_text, 65, text_area_width)
|
||||
|
||||
# Mesurer le bloc de texte complet
|
||||
bbox = draw.textbbox((0, 0), wrapped_text, font=font)
|
||||
text_width = bbox[2] - bbox[0]
|
||||
text_height = bbox[3] - bbox[1]
|
||||
# Espacement entre les lignes
|
||||
spacing_1_2 = 15 # entre BIENVENUE et username
|
||||
spacing_2_3 = 20 # entre username et nom du serveur
|
||||
total_height = h1 + spacing_1_2 + h2 + spacing_2_3 + h3
|
||||
|
||||
# Centrer le bloc dans la zone disponible
|
||||
text_x = text_area_left + (text_area_width - text_width) // 2
|
||||
text_y = (background.height - text_height) // 2
|
||||
# Centrer verticalement le bloc de 3 lignes
|
||||
start_y = (background.height - total_height) // 2
|
||||
|
||||
draw.text((text_x, text_y), wrapped_text, font=font, fill=(255, 255, 255), align="center")
|
||||
# Dessiner chaque ligne centrée horizontalement dans la zone
|
||||
y = start_y
|
||||
draw.text((text_area_center_x - w1 // 2, y), line1_text, font=font1, fill=(255, 255, 255))
|
||||
y += h1 + spacing_1_2
|
||||
draw.text((text_area_center_x - w2 // 2, y), line2_text, font=font2, fill=(255, 255, 255))
|
||||
y += h2 + spacing_2_3
|
||||
draw.text((text_area_center_x - w3 // 2, y), line3_text, font=font3, fill=(255, 255, 255))
|
||||
|
||||
|
||||
# Ajouter l'avatar
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue