Skip to content

Commit

Permalink
add a level button
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Jan 8, 2024
1 parent 9a41de1 commit 90c2222
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 11 deletions.
11 changes: 10 additions & 1 deletion screens/classic_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
### Imports ###
###############

### Python imports ###

from functools import partial

### Kivy imports ###

from kivy.properties import (
Expand Down Expand Up @@ -82,6 +86,11 @@ def fill_scrollview(self):
nb_levels=nb_levels,
nb_completed_levels=nb_completed_levels,
nb_stars=0,
font_ratio=self.font_ratio)
font_ratio=self.font_ratio,
release_function=partial(self.open_levels_screen, act))
self.ACT_BUTTON_DICT[act] = current_act_button
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"
1 change: 1 addition & 0 deletions screens/custom_widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
from screens.custom_widgets.circle_icon_button import CircleIconButton
from screens.custom_widgets.round_button import RoundButton
from screens.custom_widgets.booster_layout import BoosterLayout
from screens.custom_widgets.levels_branchs import (LevelButton)
34 changes: 34 additions & 0 deletions screens/custom_widgets/levels_branchs.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#:kivy 2.2.1
#:import PATH_TEXT_FONT tools.path.PATH_TEXT_FONT
#:import LEVEL_ID_FONT_SIZE tools.constants.LEVEL_ID_FONT_SIZE

<LevelButton>:

Widget:
opacity: 0.8
size: root.size
pos: (0,0)
canvas.before:
Color:
rgba: self.parent.primary_color
RoundedRectangle:
pos:(0,0)
size:self.size
radius:[15,]

Label:
id: level_label
text: root.level_label_text
pos_hint: {"center_x":0.5, "center_y":0.65}
font_size: LEVEL_ID_FONT_SIZE * root.font_ratio
font_name: PATH_TEXT_FONT


# Stars
ThreeStars:
id: three_stars
pos_hint: {"center_x":0.5, "center_y":0.25}
size_hint: (0.8,0.45)
nb_stars: root.nb_stars

# <LevelLeftBranch>:
80 changes: 80 additions & 0 deletions screens/custom_widgets/levels_branchs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
Module to create the levels tree for the levels screen.
"""

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

### Kivy imports ###

from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.behaviors import ButtonBehavior
from kivy.properties import (
NumericProperty,
BooleanProperty,
ColorProperty,
StringProperty
)

### Local imports ###
from tools.path import (
PATH_TEXT_FONT
)
from tools.constants import (
GAMEPLAY_DICT,
OPACITY_ON_BUTTON_PRESS
)


###############
### Classes ###
###############

class LevelButton(ButtonBehavior, RelativeLayout):

nb_stars = NumericProperty()
font_ratio = NumericProperty(1)
level_label_text = StringProperty()
primary_color = ColorProperty((0.5, 0.5, 0.5, 1))
secondary_color = ColorProperty((0.2, 0.2, 0.2, 1))
is_unlocked = BooleanProperty(False)
disable_button = BooleanProperty(False)

def __init__(
self,
level_id=0,
release_function=lambda: 1 + 1,
is_unlocked=False,
**kw):
super().__init__(**kw)
self.release_function = release_function
self.always_release = True
self.is_unlocked = is_unlocked
self.level_id = level_id
self.level_label_text = str(level_id)

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

def on_release(self):
if not self.disable_button:
self.release_function()
self.opacity = 1


class LevelBranch(RelativeLayout):
def __init__(
self,
act_id,
branch_id,
**kw):
super().__init__(**kw)
self.act_id = act_id
self.branch_id = branch_id

def build_layout(self):
# Find the number of levels contained in the branch, cannot be greater than 5
nb_levels = ...
self.local_nb_levels = ...
13 changes: 11 additions & 2 deletions screens/custom_widgets/theme_layout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Module to create the act button.
Module to create the theme selection layout.
"""

###############
Expand Down Expand Up @@ -35,7 +35,7 @@

class ThemeLayout(Image):
"""
A layout to display the customization to buy.
A layout to select the image or the colors of a theme.
"""

theme_title = StringProperty()
Expand Down Expand Up @@ -77,6 +77,9 @@ def __init__(
self.font_size = font_size

def update_variables(self):
"""
Update the variables to indicate if a component is selected or unlocked.
"""
if self.theme_key in USER_DATA.unlocked_themes:
self.has_bought_image = USER_DATA.unlocked_themes[self.theme_key]["image"]
self.has_bought_colors = USER_DATA.unlocked_themes[self.theme_key]["colors"]
Expand All @@ -102,6 +105,9 @@ def update_display(self):
self.ids["buy_colors_button"].update_display()

def click_image(self):
"""
Function to select the image of the theme.
"""
if not self.has_bought_image:
bought_sucessfully = USER_DATA.buy_item(
self.theme_key, "image", self.image_price)
Expand All @@ -116,6 +122,9 @@ def click_image(self):
"themes").update_theme_layouts_display()

def click_colors(self):
"""
Function to select the colors of the theme.
"""
if not self.has_bought_colors:
bought_sucessfully = USER_DATA.buy_item(
self.theme_key, "colors", self.colors_price)
Expand Down
10 changes: 9 additions & 1 deletion screens/levels.kv
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<LevelsScreen>:
Label:
text: "Linconym"
text: "Classic Mode"
font_name: PATH_TITLE_FONT
font_size: TITLE_FONT_SIZE * root.font_ratio
pos_hint: {"center_x":0.5, "center_y":0.9}
Expand All @@ -23,3 +23,11 @@
size_hint: (1, BOTTOM_BAR_HEIGHT)
pos_hint: {"bottom":0,"left":0}
selected: "none"

LevelButton:
pos_hint: {"center_x":0.5, "center_y":0.5}
size_hint: (0.15, None)
height: self.width*0.8
font_ratio: root.font_ratio


1 change: 1 addition & 0 deletions screens/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, **kwargs) -> None:
back_image_path=PATH_BACKGROUNDS +
THEMES_DICT[current_theme_image]["image"],
**kwargs)
self.current_act_id = ""

def on_enter(self, *args):
return super().on_enter(*args)
15 changes: 8 additions & 7 deletions screens/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ def update_theme_layouts_display(self):
current_theme_colors = USER_DATA.settings["current_theme_colors"]
self.primary_color = THEMES_DICT[current_theme_colors]["primary"]

# if self.back_image_path != PATH_BACKGROUNDS + new_image:
# Change the background image smoothly for this screen
self.change_background(new_image)

# Change the background image for all screens except this one
self.manager.change_all_background_images(
PATH_BACKGROUNDS + new_image)
if (self.back_image_path != PATH_BACKGROUNDS + new_image and self.opacity_state == "main") \
or (self.second_back_image_path != PATH_BACKGROUNDS + new_image and self.opacity_state == "second"):
# Change the background image smoothly for this screen
self.change_background(new_image)

# Change the background image for all screens except this one
self.manager.change_all_background_images(
PATH_BACKGROUNDS + new_image)

def change_background(self, new_image: str):
"""
Expand Down
1 change: 1 addition & 0 deletions tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def __init__(self) -> None:
EXPERIENCE_FONT_SIZE = 15
POS_HINT_BACK_ARROW = {"x": 0.02, "top": 0.99}
RATE_CHANGE_OPACITY = 0.05
LEVEL_ID_FONT_SIZE = 22

### Musics ###

Expand Down

0 comments on commit 90c2222

Please sign in to comment.