feat: Enhance layout of level and leaderboard displays for improved readability
This commit is contained in:
parent
b16e8fa218
commit
bcdfb697fd
@ -378,9 +378,12 @@ class LevelingCog(commands.Cog):
|
||||
def __init__(self, target_member: discord.Member, level: int, xp: int, xp_needed: int, next_level: int, bar: str, progress_percent: int):
|
||||
super().__init__()
|
||||
|
||||
current_row = 0
|
||||
|
||||
# Outer container for accent color
|
||||
outer_container = ui.Container(accent_colour=discord.Color.blue())
|
||||
self.add_item(outer_container)
|
||||
self.add_item(outer_container, row=current_row)
|
||||
current_row += 1
|
||||
|
||||
# Prepare thumbnail accessory
|
||||
thumbnail_accessory = None
|
||||
@ -388,15 +391,19 @@ class LevelingCog(commands.Cog):
|
||||
thumbnail_accessory = ui.Thumbnail(media=target_member.display_avatar.url, description="User Avatar")
|
||||
|
||||
# Section to hold content and thumbnail as accessory
|
||||
# Pass accessory in __init__, even if None, to satisfy the constructor
|
||||
section = ui.Section(accessory=thumbnail_accessory)
|
||||
outer_container.add_item(section)
|
||||
self.add_item(section, row=current_row)
|
||||
current_row += 1
|
||||
|
||||
# Add text components to the section
|
||||
section.add_item(ui.TextDisplay(f"**{target_member.display_name}'s Level**"))
|
||||
section.add_item(ui.TextDisplay(f"**Level:** {level}\n**XP:** {xp} / {xp_needed}")) # Combined Level and XP
|
||||
section.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
|
||||
section.add_item(ui.TextDisplay(f"**Progress to Level {next_level}:**\n[{bar}] {progress_percent}%")) # Combined Progress Title and Bar
|
||||
# Add text components, each on its own row
|
||||
self.add_item(ui.TextDisplay(f"**{target_member.display_name}'s Level**"), row=current_row)
|
||||
current_row += 1
|
||||
self.add_item(ui.TextDisplay(f"**Level:** {level}\n**XP:** {xp} / {xp_needed}"), row=current_row)
|
||||
current_row += 1
|
||||
self.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small), row=current_row)
|
||||
current_row += 1
|
||||
self.add_item(ui.TextDisplay(f"**Progress to Level {next_level}:**\n[{bar}] {progress_percent}%"), row=current_row)
|
||||
current_row += 1
|
||||
|
||||
view = LevelCheckView(target, level, xp, xp_needed, next_level, bar, int(progress * 100))
|
||||
await ctx.send(view=view)
|
||||
@ -424,14 +431,20 @@ class LevelingCog(commands.Cog):
|
||||
def __init__(self, guild_name: str, sorted_leaderboard_data: list, guild_members_dict: dict):
|
||||
super().__init__()
|
||||
|
||||
main_container = ui.Container(accent_colour=discord.Color.gold())
|
||||
self.add_item(main_container)
|
||||
current_row = 0
|
||||
|
||||
main_container.add_item(ui.TextDisplay(f"**{guild_name} Level Leaderboard**"))
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
|
||||
main_container = ui.Container(accent_colour=discord.Color.gold())
|
||||
self.add_item(main_container, row=current_row)
|
||||
current_row += 1
|
||||
|
||||
self.add_item(ui.TextDisplay(f"**{guild_name} Level Leaderboard**"), row=current_row)
|
||||
current_row += 1
|
||||
self.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small), row=current_row)
|
||||
current_row += 1
|
||||
|
||||
if not sorted_leaderboard_data:
|
||||
main_container.add_item(ui.TextDisplay("The leaderboard is empty!"))
|
||||
self.add_item(ui.TextDisplay("The leaderboard is empty!"), row=current_row)
|
||||
current_row += 1
|
||||
return
|
||||
|
||||
for i, (user_id, data) in enumerate(sorted_leaderboard_data[:10], 1):
|
||||
@ -439,12 +452,19 @@ class LevelingCog(commands.Cog):
|
||||
if not member:
|
||||
continue
|
||||
|
||||
user_section = ui.Section(accessory=None) # Explicitly pass accessory=None
|
||||
# Each user's entry gets its own section and is added to the view
|
||||
user_section = ui.Section(accessory=None)
|
||||
self.add_item(user_section, row=current_row)
|
||||
current_row += 1
|
||||
|
||||
# Add text components to the user_section (these are children of user_section, not the main view)
|
||||
user_section.add_item(ui.TextDisplay(f"**{i}. {member.display_name}**"))
|
||||
user_section.add_item(ui.TextDisplay(f"Level: {data['level']} | XP: {data['xp']}"))
|
||||
main_container.add_item(user_section)
|
||||
if i < len(sorted_leaderboard_data[:10]): # Add separator between users, but not after the last one
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small, visible=False)) # Invisible separator for spacing
|
||||
|
||||
# Add separator to the view
|
||||
if i < len(sorted_leaderboard_data[:10]):
|
||||
self.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small, visible=False), row=current_row)
|
||||
current_row += 1
|
||||
|
||||
view = LeaderboardView(ctx.guild.name, sorted_data, guild_members)
|
||||
await ctx.send(view=view)
|
||||
|
Loading…
x
Reference in New Issue
Block a user