From 3741b8d02986ef98c84f8b90f6e713cdc0f369e0 Mon Sep 17 00:00:00 2001 From: Agathe Date: Thu, 1 Feb 2024 17:36:25 +0100 Subject: [PATCH] Clean the code with go backwards + implement the visit our website + change the name of the current act --- screens/boosters.py | 3 --- screens/classic_mode.kv | 9 --------- screens/classic_mode.py | 7 ------- screens/game.py | 4 ---- screens/levels.kv | 20 +++++++++++++++++++- screens/levels.py | 21 ++++++++++++++++++++- screens/quests.py | 3 --- screens/settings.kv | 1 + screens/settings.py | 15 +++++++++++++++ screens/themes.py | 3 --- tools/kivy_tools/screen.py | 3 +++ 11 files changed, 58 insertions(+), 31 deletions(-) diff --git a/screens/boosters.py b/screens/boosters.py index 9b3d7b2..1e94e9c 100644 --- a/screens/boosters.py +++ b/screens/boosters.py @@ -122,6 +122,3 @@ def buy_booster(self, number: int): None """ pass - - def go_backwards(self): - self.manager.go_to_previous_screen() diff --git a/screens/classic_mode.kv b/screens/classic_mode.kv index 788e0d6..16610ed 100644 --- a/screens/classic_mode.kv +++ b/screens/classic_mode.kv @@ -8,7 +8,6 @@ #: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 -#:import POS_HINT_BACK_ARROW tools.constants.POS_HINT_BACK_ARROW : @@ -21,14 +20,6 @@ outline_color: TITLE_OUTLINE_COLOR color: TEXT_FONT_COLOR - RoundedButtonImage: - image_path: PATH_IMAGES + "left_arrow.png" - pos_hint: POS_HINT_BACK_ARROW - size_hint: (0.1, None) - height: self.width - colors: root.primary_color - on_release: root.go_backwards() - BottomBar: size_hint: (1, BOTTOM_BAR_HEIGHT) pos_hint: {"bottom":0,"left":0} diff --git a/screens/classic_mode.py b/screens/classic_mode.py index dbb5531..43c1eb0 100644 --- a/screens/classic_mode.py +++ b/screens/classic_mode.py @@ -65,18 +65,11 @@ def on_pre_enter(self, *args): self.ACT_BUTTON_DICT[act].secondary_color = self.secondary_color return super().on_pre_enter(*args) - # def on_leave(self, *args): - # self.ids["scrollview_layout"].clear_widgets - # return super().on_leave(*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 go_backwards(self): - self.manager.current = "home" - def fill_scrollview(self): scrollview_layout = self.ids["scrollview_layout"] # Load the widgets diff --git a/screens/game.py b/screens/game.py index db2d187..dd35e49 100644 --- a/screens/game.py +++ b/screens/game.py @@ -288,10 +288,6 @@ def go_to_quests_screen(self): current_dict_kwargs=dict_kwargs, next_dict_kwargs=dict_kwargs) - def go_backwards(self): - self.manager.get_screen("levels").current_act_id = self.current_act_id - self.manager.current = "levels" - def go_to_previous_level(self): print("TODO go to previous level if possible") diff --git a/screens/levels.kv b/screens/levels.kv index fcb2bf4..8a6d7ca 100644 --- a/screens/levels.kv +++ b/screens/levels.kv @@ -11,7 +11,7 @@ : Label: - text: "Classic Mode" + text: root.current_act_name font_name: PATH_TITLE_FONT font_size: TITLE_FONT_SIZE * root.font_ratio pos_hint: {"center_x":0.5, "center_y":0.9} @@ -24,6 +24,24 @@ pos_hint: {"bottom":0,"left":0} selected: "none" + # Back button + RoundedButtonImage: + image_path: PATH_IMAGES + "left_arrow.png" + pos_hint: POS_HINT_BACK_ARROW + size_hint: (0.1, None) + height: self.width + colors: root.primary_color + on_release: root.go_backwards() + + # Button for the quests + RoundedButtonImage: + image_path: PATH_IMAGES + "quests.png" + pos_hint: POS_HINT_RIGHT_TOP_BUTTON + size_hint: (0.1, None) + height: self.width + colors: root.primary_color + on_release: root.go_to_quests_screen() + CustomScrollview: id: custom_scrollview pos_hint: {"center_x":0.5, "center_y":0.475} diff --git a/screens/levels.py b/screens/levels.py index 626bb92..544b795 100644 --- a/screens/levels.py +++ b/screens/levels.py @@ -8,7 +8,10 @@ ### Kivy imports ### -from kivy.properties import ColorProperty +from kivy.properties import ( + ColorProperty, + StringProperty +) ### Local imports ### @@ -39,6 +42,7 @@ class LevelsScreen(ImprovedScreen): primary_color = ColorProperty((0, 0, 0, 1)) secondary_color = ColorProperty((0, 0, 0, 1)) + current_act_name = StringProperty() def __init__(self, **kwargs) -> None: current_theme_image = USER_DATA.settings["current_theme_image"] @@ -57,6 +61,7 @@ def on_pre_enter(self, *args): self.secondary_color = THEMES_DICT[current_theme_colors]["secondary"] self.ids.level_layout.act_id = self.current_act_id self.ids.level_layout.build_layout() + self.current_act_name = "Act " + self.current_act_id.replace("Act", "") return super().on_pre_enter(*args) def on_enter(self, *args): @@ -66,6 +71,20 @@ def on_leave(self, *args): self.ids.level_layout.clear_widgets() return super().on_leave(*args) + def go_to_quests_screen(self): + current_dict_kwargs = { + "current_act_id": self.current_act_id + } + next_dict_kwargs = { + "current_act_id": self.current_act_id, + "current_level_id": None + } + self.manager.go_to_next_screen( + next_screen_name="quests", + current_dict_kwargs=current_dict_kwargs, + next_dict_kwargs=next_dict_kwargs + ) + def open_game_screen(self, level_id): current_dict_kwargs = { "current_act_id": self.current_act_id diff --git a/screens/quests.py b/screens/quests.py index 413c0c7..2fa4bfb 100644 --- a/screens/quests.py +++ b/screens/quests.py @@ -62,6 +62,3 @@ def on_enter(self, *args): self.set_back_image_path( PATH_BACKGROUNDS + THEMES_DICT[current_theme_image]["image"]) return super().on_enter(*args) - - def go_backwards(self): - self.manager.go_to_previous_screen() diff --git a/screens/settings.kv b/screens/settings.kv index 5d512e1..89207c9 100644 --- a/screens/settings.kv +++ b/screens/settings.kv @@ -73,6 +73,7 @@ text: "Visit our website" side_image_source: PATH_IMAGES + "lupa_logo.png" font_ratio: root.font_ratio + release_function: root.open_lupa_website Label: text: root.version_text diff --git a/screens/settings.py b/screens/settings.py index 8297331..e4bd920 100644 --- a/screens/settings.py +++ b/screens/settings.py @@ -10,6 +10,7 @@ import os import random +import webbrowser ### Kivy imports ### @@ -97,3 +98,17 @@ def update_music_volume(self, widget, value): music_volume = value music_mixer.change_volume(music_volume) USER_DATA.settings["music_volume"] = music_volume + + def open_lupa_website(self): + """ + Open LupaDevStudio website. + + Parameters + ---------- + None + + Returns + ------- + None + """ + webbrowser.open("https://lupadevstudio.com", 2) diff --git a/screens/themes.py b/screens/themes.py index 5eb2990..a623d18 100644 --- a/screens/themes.py +++ b/screens/themes.py @@ -69,9 +69,6 @@ def on_resize(self, *args): self.THEME_LAYOUT_DICT[act].font_ratio = self.font_ratio return super().on_resize(*args) - def go_backwards(self): - self.manager.go_to_previous_screen() - def go_to_boosters(self): self.manager.go_to_next_screen( next_screen_name="boosters" diff --git a/tools/kivy_tools/screen.py b/tools/kivy_tools/screen.py index 36dd986..6c3ad7a 100644 --- a/tools/kivy_tools/screen.py +++ b/tools/kivy_tools/screen.py @@ -323,3 +323,6 @@ def change_background_opacity(self, *args): def reload_kwargs(self, dict_kwargs): pass + + def go_backwards(self): + self.manager.go_to_previous_screen()