diff --git a/design/LinconymGame.png b/design/LinconymGame.png new file mode 100644 index 0000000..c10da14 Binary files /dev/null and b/design/LinconymGame.png differ diff --git a/screens/custom_widgets/levels_branchs.kv b/screens/custom_widgets/levels_branchs.kv index ef903f1..accbf9a 100644 --- a/screens/custom_widgets/levels_branchs.kv +++ b/screens/custom_widgets/levels_branchs.kv @@ -31,4 +31,33 @@ size_hint: (0.8,0.45) nb_stars: root.nb_stars -# : +: + # canvas.before: + # Color: + # rgba: (1,1,1,0.5) + # Rectangle: + # pos:self.pos + # size:self.size + canvas: + Color: + rgba: self.color + Line: + # points: [(self.x,self.top),(self.right,self.top),(self.x,self.y),(self.right,self.y)] + points: [self.x, self.center_y,self.right, self.center_y] + width: 2 + cap: "none" + +: + # canvas.before: + # Color: + # rgba: (1,1,1,0.5) + # Rectangle: + # pos:self.pos + # size:self.size + canvas: + Color: + rgba: self.color + Line: + width: 2 + bezier: [self.x, self.top,self.center_x, self.top,self.center_x, self.y] + cap: "none" diff --git a/screens/custom_widgets/levels_branchs.py b/screens/custom_widgets/levels_branchs.py index bd71d5a..0fbad91 100644 --- a/screens/custom_widgets/levels_branchs.py +++ b/screens/custom_widgets/levels_branchs.py @@ -6,18 +6,27 @@ ### Imports ### ############### +### Python imports ### + +from math import ceil + ### Kivy imports ### +from kivy.uix.widget import Widget from kivy.uix.relativelayout import RelativeLayout from kivy.uix.behaviors import ButtonBehavior from kivy.properties import ( NumericProperty, BooleanProperty, ColorProperty, - StringProperty + StringProperty, + ListProperty ) ### Local imports ### + +from tools.kivy_tools.tools_kivy import MyScrollViewLayout + from tools.constants import ( USER_DATA, GAMEPLAY_DICT, @@ -25,7 +34,8 @@ MAX_NB_LEVELS_PER_BRANCH, LEVEL_BUTTON_SIZE_HINT, LEVEL_BUTTON_SPACING, - LEVEL_BUTTON_SIDE_OFFSET + LEVEL_BUTTON_SIDE_OFFSET, + LEVEL_BUTTON_RELATIVE_HEIGHT ) @@ -33,6 +43,15 @@ ### Classes ### ############### + +class StraightBranch(Widget): + color = ColorProperty() + + +class CurveBranchTop(Widget): + color = ColorProperty() + + class LevelButton(ButtonBehavior, RelativeLayout): nb_stars = NumericProperty() @@ -73,6 +92,8 @@ def on_release(self): class LevelBranch(RelativeLayout): font_ratio = NumericProperty() + primary_color = ColorProperty((0.5, 0.5, 0.5, 1)) + secondary_color = ColorProperty((0.2, 0.2, 0.2, 1)) def __init__( self, @@ -110,7 +131,7 @@ def compute_level_button_pos_hint(self, local_id: int): else: center_x = 1 - (LEVEL_BUTTON_SIDE_OFFSET + (LEVEL_BUTTON_SIZE_HINT + LEVEL_BUTTON_SPACING) * local_id + LEVEL_BUTTON_SIZE_HINT / 2) - if local_id == 0: + if local_id + 1 < MAX_NB_LEVELS_PER_BRANCH: pos_hint["top"] = 1 else: pos_hint["y"] = 0 @@ -126,6 +147,7 @@ def build_layout(self): self.local_nb_levels = min( nb_levels - self.branch_id * MAX_NB_LEVELS_PER_BRANCH, 4) for local_id in range(self.local_nb_levels): + # Create the level button level_id = local_id + 1 + self.branch_id * MAX_NB_LEVELS_PER_BRANCH level_key = str(level_id) level_pos_hint = self.compute_level_button_pos_hint(local_id) @@ -139,5 +161,65 @@ def build_layout(self): is_unlocked=level_is_unlocked, nb_stars=level_nb_stars, pos_hint=level_pos_hint, - size_hint=(LEVEL_BUTTON_SIZE_HINT, 0.4)) + size_hint=(LEVEL_BUTTON_SIZE_HINT, LEVEL_BUTTON_RELATIVE_HEIGHT)) self.add_widget(level_button) + # Create the branch + if level_id < nb_levels: + + if level_is_unlocked: + branch_color = self.primary_color + else: + branch_color = self.secondary_color + if self.branch_id % 2 == 0: + if local_id + 2 < MAX_NB_LEVELS_PER_BRANCH: + branch_size_hint = ( + LEVEL_BUTTON_SPACING, LEVEL_BUTTON_RELATIVE_HEIGHT) + branch_pos_hint = { + "center_x": level_pos_hint["center_x"] + LEVEL_BUTTON_SPACING / 2 + LEVEL_BUTTON_SIZE_HINT / 2} + branch_pos_hint["top"] = level_pos_hint["top"] + branch = StraightBranch( + size_hint=branch_size_hint, + pos_hint=branch_pos_hint, + color=branch_color) + elif local_id + 2 == MAX_NB_LEVELS_PER_BRANCH: + branch_pos_hint = { + "x": level_pos_hint["center_x"] + LEVEL_BUTTON_SIZE_HINT / 2, + "top": level_pos_hint["top"] - LEVEL_BUTTON_RELATIVE_HEIGHT / 2} + branch_size_hint = ( + LEVEL_BUTTON_SPACING + LEVEL_BUTTON_SIZE_HINT / 2, LEVEL_BUTTON_RELATIVE_HEIGHT / 2 + (1 - 2 * LEVEL_BUTTON_RELATIVE_HEIGHT)) + branch = CurveBranchTop( + size_hint=branch_size_hint, + pos_hint=branch_pos_hint, + color=branch_color) + else: + continue + self.add_widget(branch) + else: + pass + + +class LevelLayout(MyScrollViewLayout): + + font_ratio = NumericProperty() + primary_color = ColorProperty((0.5, 0.5, 0.5, 1)) + secondary_color = ColorProperty((0.2, 0.2, 0.2, 1)) + nb_branches = NumericProperty() + + def __init__( + self, + act_id="Act1", + **kw): + super().__init__(**kw) + self.act_id = act_id + self.cols = 1 + self.spacing = 40 + self.build_layout() + + def build_layout(self): + nb_levels = len(GAMEPLAY_DICT[self.act_id]) - 1 + self.nb_branches = ceil(nb_levels / MAX_NB_LEVELS_PER_BRANCH) + for branch_id in range(self.nb_branches): + level_branch = LevelBranch( + act_id=self.act_id, + branch_id=branch_id) + self.add_widget(level_branch) diff --git a/screens/levels.kv b/screens/levels.kv index f915824..04b7ea3 100644 --- a/screens/levels.kv +++ b/screens/levels.kv @@ -31,8 +31,24 @@ # font_ratio: root.font_ratio # on_release: root.open_game_screen() - LevelBranch: - pos_hint: {"center_x":0.5, "center_y":0.5} - size_hint: (1, 0.15) - height: self.width*0.8 - font_ratio: root.font_ratio \ No newline at end of file + # LevelBranch: + # pos_hint: {"center_x":0.5, "center_y":0.5} + # size_hint: (1, 0.15) + # height: self.width*0.8 + # font_ratio: root.font_ratio + # primary_color: root.primary_color + # secondary_color: root.secondary_color + + CustomScrollview: + id: custom_scrollview + pos_hint: {"center_x":0.49, "center_y":0.475} + size_hint: (0.98,0.7) + bar_color: root.primary_color + bar_inactive_color: root.secondary_color + + LevelLayout: + id: level_layout + height: 0.15*root.height * self.nb_branches + padding: (0.05*root.width, 0,0.05*root.width,40) + primary_color: root.primary_color + secondary_color: root.secondary_color \ No newline at end of file diff --git a/screens/levels.py b/screens/levels.py index 4e29bc1..c1795bc 100644 --- a/screens/levels.py +++ b/screens/levels.py @@ -6,6 +6,12 @@ ### Imports ### ############### +### Kivy imports ### + +from kivy.properties import ColorProperty + +### Local imports ### + from tools.path import ( PATH_BACKGROUNDS ) @@ -31,6 +37,9 @@ class LevelsScreen(ImprovedScreen): Class to manage the levels screen which allow the user to select a level inside an act. """ + primary_color = ColorProperty((0, 0, 0, 1)) + secondary_color = ColorProperty((0, 0, 0, 1)) + def __init__(self, **kwargs) -> None: current_theme_image = USER_DATA.settings["current_theme_image"] super().__init__( @@ -39,9 +48,15 @@ def __init__(self, **kwargs) -> None: **kwargs) self.current_act_id = "" + def on_pre_enter(self, *args): + current_theme_colors = USER_DATA.settings["current_theme_colors"] + self.primary_color = THEMES_DICT[current_theme_colors]["primary"] + self.secondary_color = THEMES_DICT[current_theme_colors]["secondary"] + return super().on_pre_enter(*args) + def on_enter(self, *args): return super().on_enter(*args) - + def open_game_screen(self): self.manager.get_screen("game").current_act_id = self.current_act_id self.manager.current = "game" diff --git a/screens/settings.py b/screens/settings.py index 6fc25d4..8297331 100644 --- a/screens/settings.py +++ b/screens/settings.py @@ -51,28 +51,6 @@ class SettingsScreen(ImprovedScreen): version_text = StringProperty() - # def add_sliders(self): - # self.sound_slider = CustomSlider( - # min=0, - # max=1, - # value=USER_DATA.settings["sound_volume"], - # size_hint=(0.7, 0.06), - # pos_hint={"center_x": 0.5, "center_y": 0.59}) - # self.add_widget(self.sound_slider) - # self.sound_slider.bind(value=self.update_sound_volume) - # self.music_slider = CustomSlider( - # min=0, - # max=1, - # value=USER_DATA.settings["sound_volume"], - # size_hint=(0.7, 0.06), - # pos_hint={"center_x": 0.5, "center_y": 0.59}) - # self.add_widget(self.music_slider) - # self.music_slider.bind(value=self.update_music_volume) - - # def destroy_sliders(self): - # self.remove_widget(self.sound_slider) - # self.remove_widget(self.music_slider) - def __init__(self, **kwargs) -> None: current_theme_image = USER_DATA.settings["current_theme_image"] self.version_text = "Version " + str(__version__) diff --git a/tools/constants.py b/tools/constants.py index 7e2b708..ace0689 100644 --- a/tools/constants.py +++ b/tools/constants.py @@ -204,6 +204,8 @@ def __init__(self) -> None: MAX_NB_LEVELS_PER_BRANCH = 4 LEVEL_BUTTON_SIZE_HINT = 0.15 +LEVEL_BUTTON_RELATIVE_HEIGHT = 0.45 +LEVEL_BRANCH_RELATIVE_HEIGHT = 0.2 LEVEL_BUTTON_SPACING = (1 - (MAX_NB_LEVELS_PER_BRANCH + 1) * LEVEL_BUTTON_SIZE_HINT) / MAX_NB_LEVELS_PER_BRANCH LEVEL_BUTTON_SIDE_OFFSET = LEVEL_BUTTON_SIZE_HINT + LEVEL_BUTTON_SPACING