Skip to content

Commit

Permalink
Create the boosters screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Dec 29, 2023
1 parent fbc440c commit 33cf54b
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 9 deletions.
2 changes: 1 addition & 1 deletion data.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"settings": {
"music_volume": 0.4577702702702703,
"sound_volume": 0.7554835493519442,
"current_theme_image": "lake",
"current_theme_image": "japanese_1",
"current_music": "kids_party",
"current_theme_colors": "japanese_1"
},
Expand Down
1 change: 1 addition & 0 deletions screens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
from screens.customization import CustomizationScreen
from screens.settings import SettingsScreen
from screens.free_mode import FreeModeScreen
from screens.boosters import BoostersScreen
43 changes: 43 additions & 0 deletions screens/boosters.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#:kivy 2.2.1
#:import PATH_IMAGES tools.path.PATH_IMAGES
#:import PATH_BADGES tools.path.PATH_BADGES
#: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


<BoostersScreen>:
Label:
text: "Boosters"
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

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}
selected: "none"

# Coins counter
CoinsCounter:
size_hint: (0.4, 0.07)
pos_hint: {"center_x":0.5, "center_y":0.81}
font_ratio: root.font_ratio
coins_count: root.coins_count
display_plus: False
disable_button: True
61 changes: 61 additions & 0 deletions screens/boosters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Module to create the profile screen.
"""

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

### Kivy imports ###

from kivy.properties import (
ColorProperty,
NumericProperty,
StringProperty
)

### Local imports ###

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


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


class BoostersScreen(ImprovedScreen):
"""
Class to manage the screen with the coins boosters.
"""

coins_count = NumericProperty()
primary_color = ColorProperty((0, 0, 0, 1))
former_screen = StringProperty()

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)

def on_enter(self, *args):
self.coins_count = USER_DATA.user_profile["coins"]
current_theme_image = USER_DATA.settings["current_theme_image"]
self.primary_color = THEMES_DICT[current_theme_image]["primary"]
self.set_back_image_path(
PATH_BACKGROUNDS + THEMES_DICT[current_theme_image]["image"])
return super().on_enter(*args)

def go_backwards(self):
self.manager.current = self.former_screen
2 changes: 1 addition & 1 deletion screens/custom_widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from screens.custom_widgets.bottom_bar import BottomBar
from screens.custom_widgets.act_button import ActButton
from screens.custom_widgets.buy_button import BuyButton
from screens.custom_widgets.coins_count import CoinsCounter
from screens.custom_widgets.coins_counter import CoinsCounter
from screens.custom_widgets.experience_count import ExperienceCounter
from screens.custom_widgets.theme_layout import ThemeLayout
from screens.custom_widgets.rounded_button_image import RoundedButtonImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Label:
text: root.coins_count_text
font_size: root.font_ratio * root.font_size
pos_hint: {"center_x":0.5, "center_y":0.5}
pos_hint: {"center_x":0.5, "center_y":0.5} if root.display_plus else {"center_x":0.65, "center_y":0.5}
size_hint: (1, None)
font_name: root.text_font_name
line_height: 1
Expand All @@ -39,3 +39,4 @@
font_name: root.text_font_name
line_height: 1
color: (0,0,0,1)
opacity: 1 if root.display_plus else 0
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from kivy.uix.behaviors import ButtonBehavior
from kivy.properties import (
StringProperty,
NumericProperty
NumericProperty,
BooleanProperty
)

### Local imports ###
Expand Down Expand Up @@ -39,11 +40,12 @@ class CoinsCounter(ButtonBehavior, RelativeLayout):
coins_count = NumericProperty(-1)
font_size = NumericProperty()
font_ratio = NumericProperty(1)
display_plus = BooleanProperty(True)
disable_button = BooleanProperty(False)

def __init__(
self,
coins_count: int = 0,
button_mode=True,
text_font_name=PATH_TEXT_FONT,
font_size=COINS_COUNT_FONT_SIZE,
release_function=lambda: 1 + 1,
Expand All @@ -52,22 +54,26 @@ def __init__(
if font_ratio is not None:
self.font_ratio = font_ratio
super().__init__(**kwargs)
self.button_mode = button_mode
self.release_function = release_function
self.always_release = True
self.bind(coins_count=self.update_coins_count)
self.bind(display_plus=self.bind_function)
self.bind(disable_button=self.bind_function)
self.coins_count = coins_count
self.text_font_name = text_font_name
self.font_size = font_size

def bind_function(self, base_widget, value):
pass

def update_coins_count(self, base_widget, value):
self.coins_count_text = str(self.coins_count)

def on_press(self):
if self.button_mode:
if not self.disable_button:
self.opacity = OPACITY_ON_BUTTON_PRESS

def on_release(self):
if self.button_mode:
if not self.disable_button:
self.release_function()
self.opacity = 1
1 change: 1 addition & 0 deletions screens/customization.kv
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
pos_hint: {"center_x":0.5, "center_y":0.81}
font_ratio: root.font_ratio
coins_count: root.coins_count
release_function: root.go_to_boosters

# Theme scrollview
ScrollView:
Expand Down
6 changes: 6 additions & 0 deletions screens/customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def __init__(self, **kwargs) -> None:

def on_pre_enter(self, *args):
self.coins_count = USER_DATA.user_profile["coins"]
current_theme_image = USER_DATA.settings["current_theme_image"]
self.primary_color = THEMES_DICT[current_theme_image]["primary"]
return super().on_pre_enter(*args)

def on_resize(self, *args):
Expand All @@ -69,6 +71,10 @@ def go_backwards(self):
# TODO to change
self.manager.current = "home"

def go_to_boosters(self):
self.manager.get_screen("boosters").former_screen = "customization"
self.manager.current = "boosters"

def update_coins(self):
self.coins_count = USER_DATA.user_profile["coins"]

Expand Down
1 change: 1 addition & 0 deletions screens/free_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, **kwargs) -> None:

def on_enter(self, *args):
current_theme_image = USER_DATA.settings["current_theme_image"]
self.primary_color = THEMES_DICT[current_theme_image]["primary"]
self.set_back_image_path(
PATH_BACKGROUNDS + THEMES_DICT[current_theme_image]["image"])
return super().on_enter(*args)
Expand Down
6 changes: 5 additions & 1 deletion screens/opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def load_kv_files(self, *_):
SettingsScreen,
ProfileScreen,
CustomizationScreen,
FreeModeScreen
FreeModeScreen,
BoostersScreen
)

screen_files = [file for file in os.listdir(
Expand All @@ -78,6 +79,7 @@ def load_kv_files(self, *_):
self.ProfileScreen = ProfileScreen
self.CustomizationScreen = CustomizationScreen
self.FreeModeScreen = FreeModeScreen
self.BoostersScreen = BoostersScreen

Clock.schedule_once(self.load_other_screens)

Expand All @@ -97,4 +99,6 @@ def load_other_screens(self, *args):
self.manager.add_widget(customization_screen)
free_mode_screen = self.FreeModeScreen(name="free_mode")
self.manager.add_widget(free_mode_screen)
boosters_screen = self.BoostersScreen(name="boosters")
self.manager.add_widget(boosters_screen)
Clock.schedule_once(self.switch_to_menu)
1 change: 1 addition & 0 deletions screens/profile.kv
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@
pos_hint: {"center_x":0.5, "center_y":0.61}
font_ratio: root.font_ratio
coins_count: root.coins_count
release_function: root.go_to_boosters
4 changes: 4 additions & 0 deletions screens/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ 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_to_boosters(self):
self.manager.get_screen("boosters").former_screen = "profile"
self.manager.current = "boosters"

0 comments on commit 33cf54b

Please sign in to comment.