feat: Refactor LevelCheckView and LeaderboardView to streamline layout and improve component organization
This commit is contained in:
parent
bb731506b9
commit
f381b3fef1
@ -378,32 +378,27 @@ 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(), row=current_row)
|
||||
self.add_item(outer_container)
|
||||
current_row += 1
|
||||
# Main container for all elements, providing the accent color
|
||||
main_container = ui.Container(accent_colour=discord.Color.blue())
|
||||
self.add_item(main_container) # Add the main container to the view
|
||||
|
||||
# Prepare thumbnail accessory
|
||||
thumbnail_accessory = None
|
||||
if target_member.display_avatar:
|
||||
thumbnail_accessory = ui.Thumbnail(media=target_member.display_avatar.url, description="User Avatar")
|
||||
|
||||
# Section to hold content and thumbnail as accessory
|
||||
section = ui.Section(accessory=thumbnail_accessory, row=current_row)
|
||||
self.add_item(section)
|
||||
current_row += 1
|
||||
# Section to hold the user's name and level/XP, with the thumbnail as accessory
|
||||
# This section will be added to the main_container
|
||||
user_info_section = ui.Section(accessory=thumbnail_accessory)
|
||||
main_container.add_item(user_info_section)
|
||||
|
||||
# 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
|
||||
# Add text components to the user_info_section
|
||||
user_info_section.add_item(ui.TextDisplay(f"**{target_member.display_name}'s Level**"))
|
||||
user_info_section.add_item(ui.TextDisplay(f"**Level:** {level}\n**XP:** {xp} / {xp_needed}"))
|
||||
|
||||
# Add remaining components directly to the main_container
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
|
||||
main_container.add_item(ui.TextDisplay(f"**Progress to Level {next_level}:**\n[{bar}] {progress_percent}%"))
|
||||
|
||||
view = LevelCheckView(target, level, xp, xp_needed, next_level, bar, int(progress * 100))
|
||||
await ctx.send(view=view)
|
||||
@ -431,20 +426,15 @@ class LevelingCog(commands.Cog):
|
||||
def __init__(self, guild_name: str, sorted_leaderboard_data: list, guild_members_dict: dict):
|
||||
super().__init__()
|
||||
|
||||
current_row = 0
|
||||
# Main container for all elements, providing the accent color
|
||||
main_container = ui.Container(accent_colour=discord.Color.gold())
|
||||
self.add_item(main_container) # Add the main container to the view
|
||||
|
||||
main_container = ui.Container(accent_colour=discord.Color.gold(), row=current_row)
|
||||
self.add_item(main_container)
|
||||
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
|
||||
main_container.add_item(ui.TextDisplay(f"**{guild_name} Level Leaderboard**"))
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
|
||||
|
||||
if not sorted_leaderboard_data:
|
||||
self.add_item(ui.TextDisplay("The leaderboard is empty!", row=current_row))
|
||||
current_row += 1
|
||||
main_container.add_item(ui.TextDisplay("The leaderboard is empty!"))
|
||||
return
|
||||
|
||||
for i, (user_id, data) in enumerate(sorted_leaderboard_data[:10], 1):
|
||||
@ -452,19 +442,17 @@ class LevelingCog(commands.Cog):
|
||||
if not member:
|
||||
continue
|
||||
|
||||
# Each user's entry gets its own section and is added to the view
|
||||
user_section = ui.Section(accessory=None, row=current_row)
|
||||
self.add_item(user_section)
|
||||
current_row += 1
|
||||
# Each user's entry gets its own section and is added to the main_container
|
||||
user_section = ui.Section(accessory=None)
|
||||
main_container.add_item(user_section)
|
||||
|
||||
# Add text components to the user_section (these are children of user_section, not the main view)
|
||||
# Add text components to the user_section
|
||||
user_section.add_item(ui.TextDisplay(f"**{i}. {member.display_name}**"))
|
||||
user_section.add_item(ui.TextDisplay(f"Level: {data['level']} | XP: {data['xp']}"))
|
||||
|
||||
# Add separator to the view
|
||||
# Add separator to the main_container
|
||||
if i < len(sorted_leaderboard_data[:10]):
|
||||
self.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small, visible=False, row=current_row))
|
||||
current_row += 1
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small, visible=False))
|
||||
|
||||
view = LeaderboardView(ctx.guild.name, sorted_data, guild_members)
|
||||
await ctx.send(view=view)
|
||||
|
Loading…
x
Reference in New Issue
Block a user