Files
ember-keeper/menus/level_selector.py

36 lines
1.6 KiB
Python

import arcade, arcade.gui
from utils.constants import AVAILABLE_LEVELS, button_style
from utils.preload import button_texture, button_hovered_texture
class LevelSelector(arcade.gui.UIView):
def __init__(self, pypresence_client):
super().__init__()
self.pypresence_client = pypresence_client
self.pypresence_client.update(state="Selecting Level...")
self.anchor = self.add_widget(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=5), anchor_x="center", anchor_y="center")
def on_show_view(self):
super().on_show_view()
self.back_button = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=65)
self.back_button.on_click = lambda event: self.main_exit()
self.anchor.add(self.back_button, anchor_x="left", anchor_y="top", align_x=10, align_y=-10)
self.box.add(arcade.gui.UILabel(text="Level Selector", font_size=28))
for n in range(AVAILABLE_LEVELS):
n = n + 1
button = self.box.add(arcade.gui.UITextureButton(text=f"Level {n}", width=self.window.width / 2, height=self.window.height / 10, texture=button_texture, texture_hovered=button_hovered_texture, style=button_style))
button.on_click = lambda event, n=n: self.play_level(n)
def play_level(self, n):
from game.play import Game
self.window.show_view(Game(self.pypresence_client, n))
def main_exit(self):
from menus.main import Main
self.window.show_view(Main(self.pypresence_client))