From 55a1a2a944541b75aa71e6b15c8b0c43a75da406 Mon Sep 17 00:00:00 2001 From: LupaDevStudio Date: Fri, 15 Dec 2023 16:58:55 +0100 Subject: [PATCH] prototype of scrollview for free mode screen --- resources/gameplay.json | 17 +++++++++- screens/custom_widgets/act_button.kv | 9 ++--- screens/custom_widgets/act_button.py | 28 +++++++++++++++- screens/custom_widgets/bottom_bar.py | 3 ++ screens/custom_widgets/three_stars.py | 14 ++++---- screens/free_mode.kv | 45 ++++++++++++++++++++----- screens/free_mode.py | 48 ++++++++++++++++++++++++++- 7 files changed, 142 insertions(+), 22 deletions(-) diff --git a/resources/gameplay.json b/resources/gameplay.json index f696a5e..30d526f 100644 --- a/resources/gameplay.json +++ b/resources/gameplay.json @@ -1,6 +1,6 @@ { "Act1": { - "name": "Act 1 : Tutorial", + "name": "Act 1 - Tutorial", "1": { "start_word": "link", "end_word": "pink", @@ -81,5 +81,20 @@ "88k_sol": 3, "375k_sol": 3 } + }, + "Act2": { + "name": "Act 2 - Haunted Forest" + }, + "Act3": { + "name": "Act 3 - The Cruise" + }, + "Act4": { + "name": "Act 4 - Space Exploration" + }, + "Act5": { + "name": "Act 5 - Around the World" + }, + "Act6": { + "name": "Act 6 - My Little Poney" } } \ No newline at end of file diff --git a/screens/custom_widgets/act_button.kv b/screens/custom_widgets/act_button.kv index 7586c47..761fcc5 100644 --- a/screens/custom_widgets/act_button.kv +++ b/screens/custom_widgets/act_button.kv @@ -16,8 +16,9 @@ id: act_title_label text: root.act_title pos_hint: {"center_y":0.8, "center_x":0.5} - size: (1,0.5) - font_size: root.parent.font_ratio * root.font_size + size_hint: (1,0.5) + text_size: (root.width*0.8,None) + font_size: root.font_ratio * root.font_size font_name: root.text_font_name halign: "center" valign: "center" @@ -28,7 +29,7 @@ id: three_stars pos_hint: {"center_x":0.35, "center_y":0.25} size_hint: (0.5,0.5) - stars_number: root.stars_number + nb_stars: root.nb_stars # Completion Label: @@ -36,7 +37,7 @@ text: root.completion_text pos_hint: {"center_x":0.8, "center_y":0.25} size_hint: (0.3,0.5) - font_size: root.parent.font_ratio * root.font_size + font_size: root.font_ratio * root.font_size font_name: root.text_font_name halign: "center" valign: "center" diff --git a/screens/custom_widgets/act_button.py b/screens/custom_widgets/act_button.py index bb1cdf0..b6b28cf 100644 --- a/screens/custom_widgets/act_button.py +++ b/screens/custom_widgets/act_button.py @@ -6,6 +6,9 @@ ### Imports ### ############### +### Python imports ### +from typing import Literal + ### Kivy imports ### from kivy.uix.relativelayout import RelativeLayout from kivy.uix.behaviors import ButtonBehavior @@ -38,22 +41,45 @@ class ActButton(ButtonBehavior, RelativeLayout): act_title = StringProperty() completion_text = StringProperty() font_size = NumericProperty() + font_ratio = NumericProperty(1) nb_levels = NumericProperty() nb_completed_levels = NumericProperty() - stars_number = NumericProperty() + nb_stars = NumericProperty() + text_font_name = StringProperty(PATH_TEXT_FONT) def __init__( self, + act_title: str = None, + nb_levels: int = None, + nb_completed_levels: int = None, + nb_stars: Literal[0, 1, 2, 3] = None, + parent=None, text_font_name=PATH_TEXT_FONT, font_size=MAIN_BUTTON_FONT_SIZE, release_function=lambda: 1 + 1, + font_ratio=None, **kwargs): + + if act_title is not None: + self.act_title = act_title + if nb_levels is not None: + self.nb_levels = nb_levels + if nb_completed_levels is not None: + self.nb_completed_levels = nb_completed_levels + if nb_stars is not None: + self.nb_stars = nb_stars + if parent is not None: + self.parent = parent + if font_ratio is not None: + self.font_ratio = font_ratio + super().__init__(**kwargs) self.release_function = release_function self.always_release = True self.text_font_name = text_font_name self.font_size = font_size self.bind(nb_completed_levels=self.update_nb_completed_levels) + self.update_nb_completed_levels(None, None) def update_nb_completed_levels(self, base_widget, value): self.completion_text = str( diff --git a/screens/custom_widgets/bottom_bar.py b/screens/custom_widgets/bottom_bar.py index 76cbf8b..ef62ba2 100644 --- a/screens/custom_widgets/bottom_bar.py +++ b/screens/custom_widgets/bottom_bar.py @@ -42,6 +42,9 @@ def on_kv_post(self, base_widget): self.selected_rect_size = \ (self.ids[self.selected + "_button"].size_hint[0] * 1.2, self.ids[self.selected + "_button"].size_hint[1] * 1.2) + else: + self.selected_rect_pos = self.ids["home_button"].pos_hint + self.selected_rect_size = (0, 0) return super().on_kv_post(base_widget) def open_home(self): diff --git a/screens/custom_widgets/three_stars.py b/screens/custom_widgets/three_stars.py index a7574d3..eb1051f 100644 --- a/screens/custom_widgets/three_stars.py +++ b/screens/custom_widgets/three_stars.py @@ -29,7 +29,7 @@ class ThreeStars(RelativeLayout): star_color_dict = {1: star_one_color, 2: star_two_color, 3: star_three_color} - stars_number = NumericProperty() + nb_stars = NumericProperty() primary_color = ListProperty([0.5, 0.5, 0.5, 1.]) secondary_color = ListProperty([1., 1., 1., 1.]) @@ -42,24 +42,24 @@ def __init__( self.primary_color = primary_color self.secondary_color = secondary_color - self.bind(stars_number=self.change_stars_number) + self.bind(nb_stars=self.change_nb_stars) super().__init__(**kwargs) - def change_stars_number(self, base_widget, value): + def change_nb_stars(self, base_widget, value): """ Change the number of stars displayed. """ - # self.stars_number = stars_number - if self.stars_number > 0: + # self.nb_stars = nb_stars + if self.nb_stars > 0: self.star_one_color = self.primary_color else: self.star_one_color = self.secondary_color - if self.stars_number > 1: + if self.nb_stars > 1: self.star_two_color = self.primary_color else: self.star_two_color = self.secondary_color - if self.stars_number > 2: + if self.nb_stars > 2: self.star_three_color = self.primary_color else: self.star_three_color = self.secondary_color diff --git a/screens/free_mode.kv b/screens/free_mode.kv index fded959..8889c09 100644 --- a/screens/free_mode.kv +++ b/screens/free_mode.kv @@ -7,6 +7,7 @@ #:import PATH_TEXT_FONT tools.path.PATH_TEXT_FONT #:import TEXT_FONT_COLOR tools.constants.TEXT_FONT_COLOR #:import BOTTOM_BAR_HEIGHT tools.constants.BOTTOM_BAR_HEIGHT +#:import GAMEPLAY_DICT tools.constants.GAMEPLAY_DICT : @@ -22,12 +23,40 @@ BottomBar: size_hint: (1, BOTTOM_BAR_HEIGHT) pos_hint: {"bottom":0,"left":0} - selected: "home" + selected: "none" - ActButton: - size_hint: (0.7,0.15) - pos_hint:{"center_x":0.5,"center_y":0.5} - stars_number: 2 - nb_levels: 10 - nb_completed_levels: 8 - act_title: "Act 1 - Tutorial" \ No newline at end of file + # ActButton: + # size_hint: (0.7,0.15) + # pos_hint:{"center_x":0.5,"center_y":0.5} + # nb_stars: 2 + # nb_levels: 10 + # nb_completed_levels: 8 + # act_title: "Act 1 - Tutorial" + + ScrollView: + id: scrollview + pos_hint: {"center_x":0.5, "center_y":0.475} + size_hint: (1,0.7) + do_scroll_x: False + + + + MyScrollViewLayout: + id: scrollview_layout + cols:1 + spacing:40 + height:0.2*root.height * len(GAMEPLAY_DICT) + # size_hint: (None,None) + # size: self.minimum_size + # top:self.height + # # pos: (100,0) + # pos_hint: {"center_x":0.5} + + # # Background + # canvas.before: + # Color: + # rgba: (1,0,0) + # RoundedRectangle: + # pos:self.pos + # size:self.size + # radius:[40,] diff --git a/screens/free_mode.py b/screens/free_mode.py index 02b7d72..9cca775 100644 --- a/screens/free_mode.py +++ b/screens/free_mode.py @@ -6,16 +6,23 @@ ### Imports ### ############### +### Kivy imports ### +from kivy.core.window import Window +from kivy.uix.gridlayout import GridLayout +from kivy.properties import NumericProperty + from tools.path import ( PATH_BACKGROUNDS ) from tools.constants import ( USER_DATA, - THEMES_DICT + THEMES_DICT, + GAMEPLAY_DICT ) from tools.kivy_tools import ( ImprovedScreen, ) +from screens.custom_widgets import ActButton ############# @@ -31,3 +38,42 @@ def __init__(self, **kwargs) -> None: back_image_path=PATH_BACKGROUNDS + THEMES_DICT[current_background_theme]["image"], **kwargs) + self.fill_scrollview() + + def on_pre_enter(self, *args): + for act in self.ACT_BUTTON_DICT: + self.ACT_BUTTON_DICT[act].font_ratio = self.font_ratio + self.ACT_BUTTON_DICT[act].opacity = 1 + return super().on_pre_enter(*args) + + def on_resize(self, *args): + for act in self.ACT_BUTTON_DICT: + self.ACT_BUTTON_DICT[act].font_ratio = self.font_ratio + return super().on_resize(*args) + + def fill_scrollview(self): + # Create the layout + # scrollview_layout = GridLayout(cols=1, row_force_default=True, row_default_height=50, + # pos_hint={'center_x': .5}, size_hint=(None, None)) + # scrollview_layout.bind(minimum_size=scrollview_layout.setter('size')) + # scrollview_layout.bind(height=scrollview_layout.setter('top')) + scrollview_layout = self.ids["scrollview_layout"] + # Load the widgets + self.ACT_BUTTON_DICT = {} + for act in GAMEPLAY_DICT: + act_title = GAMEPLAY_DICT[act]["name"] + nb_levels = len(GAMEPLAY_DICT[act]) - 1 + if act in USER_DATA.free_mode: + nb_completed_levels = USER_DATA.free_mode[act] + else: + nb_completed_levels = 0 + current_act_button = ActButton( + act_title=act_title, + nb_levels=nb_levels, + nb_completed_levels=nb_completed_levels, + nb_stars=0, + font_ratio=self.font_ratio, + opacity=0) + self.ACT_BUTTON_DICT[act] = current_act_button + scrollview_layout.add_widget(self.ACT_BUTTON_DICT[act]) + # self.ids["scrollview"].add_widget(scrollview_layout)