Skip to content

Commit

Permalink
Add the badge icon in the profile screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Dec 29, 2023
1 parent 17a30c1 commit 559c863
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 18 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from kivy.uix.screenmanager import (
ScreenManager,
NoTransition,
Screen,
Screen
)
from kivy.uix.widget import Widget
from kivy.core.window import Window
Expand All @@ -27,7 +27,7 @@
### Local imports ###

from tools.path import (
PATH_IMAGES,
PATH_IMAGES
)
from tools.constants import (
MOBILE_MODE,
Expand Down
Binary file added resources/images/badges/beginner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion screens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
ThreeStars,
SideImageButton,
RoundedButtonImage,
ExperienceCounter
ExperienceCounter,
CircleIconButton
)

# Import the screens
Expand Down
2 changes: 1 addition & 1 deletion screens/custom_widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
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

from screens.custom_widgets.circle_icon_button import CircleIconButton
25 changes: 25 additions & 0 deletions screens/custom_widgets/circle_icon_button.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#:kivy 2.2.1

<-CircleIconButton>:

fit_mode: "cover" # the image will be cropped at the right spot

canvas:
Color:
rgba: self.color
StencilPush
RoundedRectangle:
pos: self.pos
size: self.size
radius: [100]
StencilUse
Rectangle:
texture: self.texture
size: self.norm_image_size
pos: self.center_x - self.norm_image_size[0] / 2., self.center_y - self.norm_image_size[1] / 2.
StencilUnUse
RoundedRectangle:
pos: self.pos
size: self.size
radius: [100]
StencilPop
54 changes: 54 additions & 0 deletions screens/custom_widgets/circle_icon_button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Module to create custom buttons with round transparent white background.
"""

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

### Kivy imports ###
from kivy.uix.image import Image
from kivy.uix.behaviors import ButtonBehavior
from kivy.properties import (
BooleanProperty
)

### Local imports ###

from tools.constants import (
OPACITY_ON_BUTTON_PRESS
)

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


class CircleIconButton(ButtonBehavior, Image):
"""
A custom button with a white round rectangle background.
"""

disable_button = BooleanProperty()

def __init__(
self,
release_function=lambda: 1 + 1,
**kwargs):
super().__init__(**kwargs)
self.always_release = True
self.release_function = release_function
self.bind(disable_button=self.bind_function)

def bind_function(self, base_widget, value):
pass

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

6 changes: 3 additions & 3 deletions screens/custom_widgets/custom_progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def __init__(
**kwargs):
super().__init__(**kwargs)

self.bind(primary_color = self.my_function)
self.bind(secondary_color = self.my_function)
self.bind(primary_color = self.bind_function)
self.bind(secondary_color = self.bind_function)
self.value = value

def my_function(self, base_widget, value):
def bind_function(self, base_widget, value):
pass
10 changes: 8 additions & 2 deletions screens/custom_widgets/rounded_button_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
StringProperty,
NumericProperty,
ObjectProperty,
BooleanProperty,
BooleanProperty
)

Expand All @@ -39,6 +40,7 @@ class RoundedButtonImage(ButtonBehavior, RelativeLayout):
image_path = StringProperty()
colors = ObjectProperty()
radius = NumericProperty(20)
disable_button = BooleanProperty()

def __init__(
self,
Expand All @@ -50,11 +52,15 @@ def __init__(
self.image_path = image_path
self.colors = colors
self.always_release = True
self.bind(disable_button=self.bind_function)

def bind_function(self, base_widget, value):
pass

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

def on_release(self):
if not self.disabled:
if not self.disable_button:
self.opacity = 1
9 changes: 9 additions & 0 deletions screens/profile.kv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#: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
Expand All @@ -24,6 +25,14 @@
pos_hint: {"bottom":0,"left":0}
selected: "profile"

# Badge for the status
CircleIconButton:
source: PATH_BADGES + root.user_status + ".png"
pos_hint: {"center_x":0.25, "center_y":0.75}
size_hint: (0.2, None)
height: self.width
disable_button: True

# Status and level
Label:
text: root.user_status
Expand Down
13 changes: 4 additions & 9 deletions screens/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
### Local imports ###

from tools.path import (
PATH_BACKGROUNDS
PATH_BACKGROUNDS
)
from tools.constants import (
USER_DATA,
Expand Down Expand Up @@ -49,17 +49,12 @@ def __init__(self, **kwargs) -> None:
THEMES_DICT[current_theme_image]["image"],
**kwargs)

self.user_status = USER_DATA.user_profile["status"]
self.user_level = "Level " + str(USER_DATA.user_profile["level"])
self.theme_colors = USER_DATA.settings["current_theme_colors"]

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

def on_enter(self, *args):
self.coins_count = USER_DATA.user_profile["coins"]
self.user_level = "Level " + str(USER_DATA.user_profile["level"])
current_theme_image = USER_DATA.settings["current_theme_image"]
self.theme_colors = USER_DATA.settings["current_theme_colors"]
self.user_status = USER_DATA.user_profile["status"]
self.set_back_image_path(
PATH_BACKGROUNDS + THEMES_DICT[current_theme_image]["image"])
return super().on_enter(*args)
1 change: 1 addition & 0 deletions tools/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Path for the resources
PATH_IMAGES = PATH_RESOURCES_FOLDER + "images/"
PATH_BACKGROUNDS = PATH_IMAGES + "backgrounds/"
PATH_BADGES = PATH_IMAGES + "badges/"
PATH_SOUNDS = PATH_RESOURCES_FOLDER + "sounds/"
PATH_MUSICS = PATH_RESOURCES_FOLDER + "musics/"
PATH_FONTS = PATH_RESOURCES_FOLDER + "fonts/"
Expand Down

0 comments on commit 559c863

Please sign in to comment.