diff --git a/screens/classic_mode.py b/screens/classic_mode.py index 505e89d..e7e7e30 100644 --- a/screens/classic_mode.py +++ b/screens/classic_mode.py @@ -6,6 +6,10 @@ ### Imports ### ############### +### Python imports ### + +from functools import partial + ### Kivy imports ### from kivy.properties import ( @@ -82,6 +86,11 @@ def fill_scrollview(self): nb_levels=nb_levels, nb_completed_levels=nb_completed_levels, nb_stars=0, - font_ratio=self.font_ratio) + font_ratio=self.font_ratio, + release_function=partial(self.open_levels_screen, act)) self.ACT_BUTTON_DICT[act] = current_act_button scrollview_layout.add_widget(self.ACT_BUTTON_DICT[act]) + + def open_levels_screen(self, act_id): + self.manager.get_screen("levels").current_act_id = act_id + self.manager.current = "levels" diff --git a/screens/custom_widgets/__init__.py b/screens/custom_widgets/__init__.py index 259a5a4..c0a0a9f 100644 --- a/screens/custom_widgets/__init__.py +++ b/screens/custom_widgets/__init__.py @@ -20,3 +20,4 @@ from screens.custom_widgets.circle_icon_button import CircleIconButton from screens.custom_widgets.round_button import RoundButton from screens.custom_widgets.booster_layout import BoosterLayout +from screens.custom_widgets.levels_branchs import (LevelButton) diff --git a/screens/custom_widgets/levels_branchs.kv b/screens/custom_widgets/levels_branchs.kv new file mode 100644 index 0000000..ef903f1 --- /dev/null +++ b/screens/custom_widgets/levels_branchs.kv @@ -0,0 +1,34 @@ +#:kivy 2.2.1 +#:import PATH_TEXT_FONT tools.path.PATH_TEXT_FONT +#:import LEVEL_ID_FONT_SIZE tools.constants.LEVEL_ID_FONT_SIZE + +: + + Widget: + opacity: 0.8 + size: root.size + pos: (0,0) + canvas.before: + Color: + rgba: self.parent.primary_color + RoundedRectangle: + pos:(0,0) + size:self.size + radius:[15,] + + Label: + id: level_label + text: root.level_label_text + pos_hint: {"center_x":0.5, "center_y":0.65} + font_size: LEVEL_ID_FONT_SIZE * root.font_ratio + font_name: PATH_TEXT_FONT + + + # Stars + ThreeStars: + id: three_stars + pos_hint: {"center_x":0.5, "center_y":0.25} + size_hint: (0.8,0.45) + nb_stars: root.nb_stars + +# : diff --git a/screens/custom_widgets/levels_branchs.py b/screens/custom_widgets/levels_branchs.py new file mode 100644 index 0000000..bee494e --- /dev/null +++ b/screens/custom_widgets/levels_branchs.py @@ -0,0 +1,80 @@ +""" +Module to create the levels tree for the levels screen. +""" + +############### +### Imports ### +############### + +### Kivy imports ### + +from kivy.uix.relativelayout import RelativeLayout +from kivy.uix.behaviors import ButtonBehavior +from kivy.properties import ( + NumericProperty, + BooleanProperty, + ColorProperty, + StringProperty +) + +### Local imports ### +from tools.path import ( + PATH_TEXT_FONT +) +from tools.constants import ( + GAMEPLAY_DICT, + OPACITY_ON_BUTTON_PRESS +) + + +############### +### Classes ### +############### + +class LevelButton(ButtonBehavior, RelativeLayout): + + nb_stars = NumericProperty() + font_ratio = NumericProperty(1) + level_label_text = StringProperty() + primary_color = ColorProperty((0.5, 0.5, 0.5, 1)) + secondary_color = ColorProperty((0.2, 0.2, 0.2, 1)) + is_unlocked = BooleanProperty(False) + disable_button = BooleanProperty(False) + + def __init__( + self, + level_id=0, + release_function=lambda: 1 + 1, + is_unlocked=False, + **kw): + super().__init__(**kw) + self.release_function = release_function + self.always_release = True + self.is_unlocked = is_unlocked + self.level_id = level_id + self.level_label_text = str(level_id) + + def on_press(self): + if not self.disable_button: + self.opacity = OPACITY_ON_BUTTON_PRESS + + def on_release(self): + if not self.disable_button: + self.release_function() + self.opacity = 1 + + +class LevelBranch(RelativeLayout): + def __init__( + self, + act_id, + branch_id, + **kw): + super().__init__(**kw) + self.act_id = act_id + self.branch_id = branch_id + + def build_layout(self): + # Find the number of levels contained in the branch, cannot be greater than 5 + nb_levels = ... + self.local_nb_levels = ... diff --git a/screens/custom_widgets/theme_layout.py b/screens/custom_widgets/theme_layout.py index ae186a4..c2211c1 100644 --- a/screens/custom_widgets/theme_layout.py +++ b/screens/custom_widgets/theme_layout.py @@ -1,5 +1,5 @@ """ -Module to create the act button. +Module to create the theme selection layout. """ ############### @@ -35,7 +35,7 @@ class ThemeLayout(Image): """ - A layout to display the customization to buy. + A layout to select the image or the colors of a theme. """ theme_title = StringProperty() @@ -77,6 +77,9 @@ def __init__( self.font_size = font_size def update_variables(self): + """ + Update the variables to indicate if a component is selected or unlocked. + """ if self.theme_key in USER_DATA.unlocked_themes: self.has_bought_image = USER_DATA.unlocked_themes[self.theme_key]["image"] self.has_bought_colors = USER_DATA.unlocked_themes[self.theme_key]["colors"] @@ -102,6 +105,9 @@ def update_display(self): self.ids["buy_colors_button"].update_display() def click_image(self): + """ + Function to select the image of the theme. + """ if not self.has_bought_image: bought_sucessfully = USER_DATA.buy_item( self.theme_key, "image", self.image_price) @@ -116,6 +122,9 @@ def click_image(self): "themes").update_theme_layouts_display() def click_colors(self): + """ + Function to select the colors of the theme. + """ if not self.has_bought_colors: bought_sucessfully = USER_DATA.buy_item( self.theme_key, "colors", self.colors_price) diff --git a/screens/levels.kv b/screens/levels.kv index 2ce154d..21253b6 100644 --- a/screens/levels.kv +++ b/screens/levels.kv @@ -11,7 +11,7 @@ : Label: - text: "Linconym" + text: "Classic Mode" font_name: PATH_TITLE_FONT font_size: TITLE_FONT_SIZE * root.font_ratio pos_hint: {"center_x":0.5, "center_y":0.9} @@ -23,3 +23,11 @@ size_hint: (1, BOTTOM_BAR_HEIGHT) pos_hint: {"bottom":0,"left":0} selected: "none" + + LevelButton: + pos_hint: {"center_x":0.5, "center_y":0.5} + size_hint: (0.15, None) + height: self.width*0.8 + font_ratio: root.font_ratio + + diff --git a/screens/levels.py b/screens/levels.py index ddb8352..2348148 100644 --- a/screens/levels.py +++ b/screens/levels.py @@ -37,6 +37,7 @@ def __init__(self, **kwargs) -> None: back_image_path=PATH_BACKGROUNDS + THEMES_DICT[current_theme_image]["image"], **kwargs) + self.current_act_id = "" def on_enter(self, *args): return super().on_enter(*args) diff --git a/screens/themes.py b/screens/themes.py index ed426d4..56d65e0 100644 --- a/screens/themes.py +++ b/screens/themes.py @@ -92,13 +92,14 @@ def update_theme_layouts_display(self): current_theme_colors = USER_DATA.settings["current_theme_colors"] self.primary_color = THEMES_DICT[current_theme_colors]["primary"] - # if self.back_image_path != PATH_BACKGROUNDS + new_image: - # Change the background image smoothly for this screen - self.change_background(new_image) - - # Change the background image for all screens except this one - self.manager.change_all_background_images( - PATH_BACKGROUNDS + new_image) + if (self.back_image_path != PATH_BACKGROUNDS + new_image and self.opacity_state == "main") \ + or (self.second_back_image_path != PATH_BACKGROUNDS + new_image and self.opacity_state == "second"): + # Change the background image smoothly for this screen + self.change_background(new_image) + + # Change the background image for all screens except this one + self.manager.change_all_background_images( + PATH_BACKGROUNDS + new_image) def change_background(self, new_image: str): """ diff --git a/tools/constants.py b/tools/constants.py index deaa6d9..307a17a 100644 --- a/tools/constants.py +++ b/tools/constants.py @@ -198,6 +198,7 @@ def __init__(self) -> None: EXPERIENCE_FONT_SIZE = 15 POS_HINT_BACK_ARROW = {"x": 0.02, "top": 0.99} RATE_CHANGE_OPACITY = 0.05 +LEVEL_ID_FONT_SIZE = 22 ### Musics ###