Skip to content

Commit

Permalink
create the navigation system with the previous screens
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Feb 1, 2024
1 parent b3119b4 commit 4948344
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 32 deletions.
2 changes: 2 additions & 0 deletions licenses/Licenses.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ The following list includes all the references of the assets used by this applic
- <a href="https://www.flaticon.com/free-icons/google-play-music" title="google play music icons">Google play music icons created by Pixel perfect - Flaticon</a>
- <a href="https://www.flaticon.com/free-icons/art" title="art icons">Art icons created by Freepik - Flaticon</a>
- <a href="https://www.flaticon.com/free-icons/backspace" title="backspace icons">Backspace icons created by Icon Smart - Flaticon</a>
- <a href="https://www.flaticon.com/free-icons/quest" title="quest icons">Quest icons created by Vitaly Gorbachev - Flaticon</a>
- <a href="https://www.flaticon.com/free-icons/achievement" title="achievement icons">Achievement icons created by VectorPortal - Flaticon</a>
- Music by <a href="https://pixabay.com/fr/users/arturaravidimusic-37133175/?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=160360">Artur Aravidi</a> from <a href="https://pixabay.com/music//?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=160360">Pixabay</a>
14 changes: 13 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class WindowManager(ScreenManager):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.transition = NoTransition()
self.list_former_screens = []
self.list_previous_screens = []
current_screen = Screen(name="temp")
self.add_widget(current_screen)
self.current = "temp"
Expand All @@ -64,6 +64,18 @@ def change_all_background_images(self, new_image_path):
screen = self.get_screen(screen_name)
screen.set_back_image_path(new_image_path)

def go_to_previous_screen(self):
if len(self.list_previous_screens) != 0:
previous_screen = self.list_previous_screens.pop()
screen_name = previous_screen[0]
self.get_screen(screen_name).reload_kwargs(previous_screen[1])
self.current = screen_name

def go_to_next_screen(self, next_screen_name, current_dict_kwargs={}, next_dict_kwargs={}):
current_screen_name = self.current
self.list_previous_screens.append((current_screen_name, current_dict_kwargs))
self.get_screen(next_screen_name).reload_kwargs(next_dict_kwargs)
self.current = next_screen_name

class MainApp(App, Widget):
"""
Expand Down
Binary file added resources/images/quests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions screens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
from screens.levels import LevelsScreen
from screens.customization import CustomizationScreen
from screens.game import GameScreen
from screens.quests import QuestsScreen
7 changes: 3 additions & 4 deletions screens/boosters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class BoostersScreen(ImprovedScreen):
coins_count = NumericProperty()
primary_color = ColorProperty((0, 0, 0, 1))
secondary_color = ColorProperty((0, 0, 0, 1))
former_screen = StringProperty()
list_ads = ListProperty()
list_buy = ListProperty()

Expand All @@ -67,9 +66,6 @@ def on_enter(self, *args):
self.build_list_buy()
return super().on_enter(*args)

def go_backwards(self):
self.manager.current = self.former_screen

def build_list_ads(self):
self.list_ads = []
for ad in USER_DATA.ads:
Expand Down Expand Up @@ -126,3 +122,6 @@ def buy_booster(self, number: int):
None
"""
pass

def go_backwards(self):
self.manager.go_to_previous_screen()
8 changes: 6 additions & 2 deletions screens/classic_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,9 @@ def fill_scrollview(self):
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"
dict_kwargs = {
"current_act_id": act_id
}
self.manager.go_to_next_screen(
next_screen_name="levels",
next_dict_kwargs=dict_kwargs)
8 changes: 4 additions & 4 deletions screens/custom_widgets/bottom_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ def open_home(self):
"""
Open the home screen.
"""
self.parent.manager.current = "home"
self.parent.manager.go_to_next_screen(next_screen_name="home")

def open_settings(self):
"""
Open the settings screen.
"""
self.parent.manager.current = "settings"
self.parent.manager.go_to_next_screen(next_screen_name="settings")

def open_customization(self):
"""
Open the customization screen.
"""
self.parent.manager.current = "customization"
self.parent.manager.go_to_next_screen(next_screen_name="customization")

def open_profile(self):
"""
Open the profile screen.
"""
self.parent.manager.current = "profile"
self.parent.manager.go_to_next_screen(next_screen_name="profile")
6 changes: 1 addition & 5 deletions screens/custom_widgets/levels_branchs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ def on_release(self):
if not self.disable_button:
self.opacity = 1
self.get_root_window().children[0].get_screen(
"game").current_act_id = self.parent.act_id
self.get_root_window().children[0].get_screen(
"game").current_level_id = str(self.level_id)
self.get_root_window().children[0].current = "game"

"levels").open_game_screen(str(self.level_id))

class LevelBranch(RelativeLayout):

Expand Down
2 changes: 1 addition & 1 deletion screens/customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def open_musics_screen(self, *_):
pass

def open_themes_screen(self, *_):
self.manager.current = "themes"
self.manager.go_to_next_screen(next_screen_name="themes")
10 changes: 10 additions & 0 deletions screens/game.kv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#:import LETTER_FONT_SIZE tools.constants.LETTER_FONT_SIZE
#:import TEXT_FONT_COLOR tools.constants.TEXT_FONT_COLOR
#:import POS_HINT_BACK_ARROW tools.constants.POS_HINT_BACK_ARROW
#:import POS_HINT_RIGHT_TOP_BUTTON tools.constants.POS_HINT_RIGHT_TOP_BUTTON

<GameScreen>:
Label:
Expand All @@ -27,6 +28,15 @@
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()

# Stars
ThreeStars:
id: three_stars
Expand Down
14 changes: 14 additions & 0 deletions screens/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def __init__(self, **kwargs) -> None:
self.current_act_id: str
self.current_level_id: str

def reload_kwargs(self, dict_kwargs):
self.current_act_id = dict_kwargs["current_act_id"]
self.current_level_id = dict_kwargs["current_level_id"]

def on_pre_enter(self, *args):
# Initialise the current word
self.current_word = self.start_word
Expand Down Expand Up @@ -274,6 +278,16 @@ def disable_submit_button(self):
# self.ids.submit_button.opacity = 0
self.ids.submit_button.disable_button = True

def go_to_quests_screen(self):
dict_kwargs = {
"current_level_id": self.current_level_id,
"current_act_id": self.current_act_id
}
self.manager.go_to_next_screen(
next_screen_name="quests",
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"
Expand Down
2 changes: 1 addition & 1 deletion screens/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def open_classic_mode(self):
"""
Open the classic mode screen.
"""
self.manager.current = "classic_mode"
self.manager.go_to_next_screen(next_screen_name="classic_mode")
21 changes: 17 additions & 4 deletions screens/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def __init__(self, **kwargs) -> None:
back_image_path=PATH_BACKGROUNDS +
THEMES_DICT[current_theme_image]["image"],
**kwargs)
self.current_act_id = ""
self.current_act_id : str

def reload_kwargs(self, dict_kwargs):
self.current_act_id = dict_kwargs["current_act_id"]

def on_pre_enter(self, *args):
current_theme_colors = USER_DATA.settings["current_theme_colors"]
Expand All @@ -63,6 +66,16 @@ def on_leave(self, *args):
self.ids.level_layout.clear_widgets()
return super().on_leave(*args)

def open_game_screen(self):
self.manager.get_screen("game").current_act_id = self.current_act_id
self.manager.current = "game"
def open_game_screen(self, level_id):
current_dict_kwargs = {
"current_act_id": self.current_act_id
}
next_dict_kwargs = {
"current_act_id": self.current_act_id,
"current_level_id": level_id
}
self.manager.go_to_next_screen(
next_screen_name="game",
current_dict_kwargs=current_dict_kwargs,
next_dict_kwargs=next_dict_kwargs
)
6 changes: 5 additions & 1 deletion screens/opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def load_kv_files(self, *_):
BoostersScreen,
LevelsScreen,
CustomizationScreen,
GameScreen
GameScreen,
QuestsScreen
)

screen_files = [file for file in os.listdir(
Expand All @@ -86,6 +87,7 @@ def load_kv_files(self, *_):
self.LevelsScreen = LevelsScreen
self.CustomizationScreen = CustomizationScreen
self.GameScreen = GameScreen
self.QuestsScreen = QuestsScreen

Clock.schedule_once(self.load_other_screens)

Expand All @@ -111,6 +113,8 @@ def load_other_screens(self, *args):
self.manager.add_widget(levels_screen)
game_screen = self.GameScreen(name="game")
self.manager.add_widget(game_screen)
quests_screen = self.QuestsScreen(name="quests")
self.manager.add_widget(quests_screen)
customization_screen = self.CustomizationScreen(name="customization")
self.manager.add_widget(customization_screen)
Clock.schedule_once(self.switch_to_menu)
3 changes: 1 addition & 2 deletions screens/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ def on_enter(self, *args):
return super().on_enter(*args)

def go_to_boosters(self):
self.manager.get_screen("boosters").former_screen = "profile"
self.manager.current = "boosters"
self.manager.go_to_next_screen(next_screen_name="boosters")
33 changes: 33 additions & 0 deletions screens/quests.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#:kivy 2.2.1
#:import PATH_IMAGES tools.path.PATH_IMAGES
#:import PATH_TITLE_FONT tools.path.PATH_TITLE_FONT
#:import TITLE_FONT_SIZE tools.constants.TITLE_FONT_SIZE
#:import TITLE_OUTLINE_WIDTH tools.constants.TITLE_OUTLINE_WIDTH
#:import TITLE_OUTLINE_COLOR tools.constants.TITLE_OUTLINE_COLOR
#: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


<QuestsScreen>:
Label:
text: "Quests"
font_name: PATH_TITLE_FONT
font_size: TITLE_FONT_SIZE * root.font_ratio
pos_hint: {"center_x":0.5, "center_y":0.9}
outline_width: TITLE_OUTLINE_WIDTH
outline_color: TITLE_OUTLINE_COLOR
color: TEXT_FONT_COLOR

BottomBar:
size_hint: (1, BOTTOM_BAR_HEIGHT)
pos_hint: {"bottom":0,"left":0}
selected: "none"

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()
67 changes: 67 additions & 0 deletions screens/quests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Module to create the profile screen.
"""

###############
### Imports ###
###############

### Kivy imports ###

from kivy.properties import (
StringProperty,
ColorProperty
)

### Local imports ###

from tools.path import (
PATH_BACKGROUNDS,
PATH_BADGES
)
from tools.constants import (
USER_DATA,
THEMES_DICT
)
from tools.kivy_tools import (
ImprovedScreen
)


#############
### Class ###
#############


class QuestsScreen(ImprovedScreen):
"""
Class to manage the screen that contains the profile information.
"""

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__(
back_image_path=PATH_BACKGROUNDS +
THEMES_DICT[current_theme_image]["image"],
**kwargs)
self.current_act_id: str
self.current_level_id: str | None

def reload_kwargs(self, dict_kwargs):
self.current_act_id = dict_kwargs["current_act_id"]
self.current_level_id = dict_kwargs["current_level_id"]

def on_enter(self, *args):
current_theme_image = USER_DATA.settings["current_theme_image"]
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"]
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()
7 changes: 4 additions & 3 deletions screens/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ def on_resize(self, *args):
return super().on_resize(*args)

def go_backwards(self):
self.manager.current = "customization"
self.manager.go_to_previous_screen()

def go_to_boosters(self):
self.manager.get_screen("boosters").former_screen = "themes"
self.manager.current = "boosters"
self.manager.go_to_next_screen(
next_screen_name="boosters"
)

def update_coins(self):
self.coins_count = USER_DATA.user_profile["coins"]
Expand Down
1 change: 1 addition & 0 deletions tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def __init__(self) -> None:
CUSTOM_BUTTON_BACKGROUND_COLOR = (1, 1, 1, 0.7)
OPACITY_ON_BUTTON_PRESS = 0.8
POS_HINT_BACK_ARROW = {"x": 0.02, "top": 0.99}
POS_HINT_RIGHT_TOP_BUTTON = {"right": 0.98, "top": 0.99}
RATE_CHANGE_OPACITY = 0.05
DISABLE_BUTTON_COLOR = (0.15, 0.15, 0.15, 1)

Expand Down
7 changes: 3 additions & 4 deletions tools/kivy_tools/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ImprovedScreen(Screen):
"""
Improved Screen class based on the kivy one.
"""

# Create the back image properties
back_image_width = NumericProperty(Window.size[0])
back_image_height = NumericProperty(Window.size[1])
Expand Down Expand Up @@ -222,9 +221,6 @@ def on_enter(self, *args):
# Bind to update attributes when the size of the window is changed
Window.bind(on_resize=self.on_resize)

# Add the screen name to the list of former screens
self.manager.list_former_screens.append(self.name)

# Update the back image size
self.update_back_image_size()

Expand Down Expand Up @@ -324,3 +320,6 @@ def change_background_opacity(self, *args):
else:
Clock.unschedule(self.change_background_opacity, 1/FPS)
self.opacity_state = "main"

def reload_kwargs(self, dict_kwargs):
pass

0 comments on commit 4948344

Please sign in to comment.