Skip to content

Commit

Permalink
Continue the design of the customization button
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Dec 17, 2023
1 parent a06383f commit db9703e
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 25 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from kivy.core.window import Window
from kivy.clock import Clock

### Module imports ###
### Local imports ###

from tools.path import (
PATH_IMAGES,
Expand Down
1 change: 1 addition & 0 deletions screens/custom_widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from screens.custom_widgets.bottom_bar import BottomBar
from screens.custom_widgets.act_button import ActButton
from screens.custom_widgets.theme_layout import ThemeLayout
from screens.custom_widgets.buy_button import BuyButton
6 changes: 3 additions & 3 deletions screens/custom_widgets/act_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
###############

### Python imports ###

from typing import Literal

### Kivy imports ###

from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.behaviors import ButtonBehavior
from kivy.properties import (
Expand All @@ -18,6 +20,7 @@
)

### Local imports ###

from tools.path import (
PATH_TEXT_FONT
)
Expand Down Expand Up @@ -53,7 +56,6 @@ def __init__(
nb_levels: int = None,
nb_completed_levels: int = None,
nb_stars: Literal[0, 1, 2, 3] = None,
parent=None,
text_font_name=PATH_TEXT_FONT,
font_size=ACT_BUTTON_FONT_SIZE,
release_function=lambda: 1 + 1,
Expand All @@ -68,8 +70,6 @@ def __init__(
self.nb_completed_levels = nb_completed_levels
if nb_stars is not None:
self.nb_stars = nb_stars
if parent is not None:
self.parent = parent
if font_ratio is not None:
self.font_ratio = font_ratio

Expand Down
24 changes: 24 additions & 0 deletions screens/custom_widgets/buy_button.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#:kivy 2.2.1

<BuyButton>:

# Background
canvas.before:
Color:
rgba: self.background_color
RoundedRectangle:
pos:(0,0)
size:self.size
radius:[20,]

# Button title
Label:
text: root.button_title
pos_hint: { "center_x":0.5,"center_y":0.8}
size_hint: (1,0.7)
text_size: (root.width*0.8,None)
font_size: root.font_ratio * root.font_size
font_name: root.text_font_name
halign: "center"
valign: "center"
color: (0,0,0,1)
86 changes: 86 additions & 0 deletions screens/custom_widgets/buy_button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""
Module to create buy and enable buttons
"""


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

### Python imports ###

from typing import Literal

### Kivy imports ###

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

### Local imports ###

from tools.path import (
PATH_TEXT_FONT
)
from tools.constants import (
CUSTOM_BUTTON_BACKGROUND_COLOR,
OPACITY_ON_BUTTON_PRESS,
ACT_BUTTON_FONT_SIZE
)

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


class BuyButton(ButtonBehavior, RelativeLayout):
"""
A button for the customization screen to buy images or colors.
"""

background_color = CUSTOM_BUTTON_BACKGROUND_COLOR
button_title = StringProperty()
font_size = NumericProperty()
font_ratio = NumericProperty(1)
text_font_name = StringProperty(PATH_TEXT_FONT)
has_bought = BooleanProperty()
is_using = BooleanProperty()
price = NumericProperty()

def __init__(
self,
button_title: str = None,
text_font_name=PATH_TEXT_FONT,
font_size=ACT_BUTTON_FONT_SIZE,
has_bought:bool = False,
is_using: bool = False,
price: int = 0,
release_function=lambda: 1 + 1,
font_ratio=None,
**kwargs):

if button_title is not None:
self.button_title = button_title
if font_ratio is not None:
self.font_ratio = font_ratio

self.release_function = release_function
self.has_bought = has_bought
self.is_using = is_using
self.price = price

super().__init__(**kwargs)
self.text_font_name = text_font_name
self.font_size = font_size

def on_press(self):
self.opacity = OPACITY_ON_BUTTON_PRESS

def on_release(self):
self.release_function()
self.opacity = 1

4 changes: 2 additions & 2 deletions screens/custom_widgets/custom_buttons.kv
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
RoundedRectangle:
pos:self.pos
size:self.size
radius:[40,]
radius:[self.radius,]

# Main text
Label:
text: root.text
font_size: root.parent.font_ratio * root.font_size
font_size: root.font_ratio * root.font_size
pos: root.pos
size: root.size
shorten: False
Expand Down
5 changes: 5 additions & 0 deletions screens/custom_widgets/custom_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class CustomButton(ButtonBehavior, Widget):
text = StringProperty()
text_filling_ratio = NumericProperty()
font_size = NumericProperty()
font_ratio = NumericProperty(1)
radius = NumericProperty(40)

def __init__(
self,
Expand All @@ -46,7 +48,10 @@ def __init__(
text_filling_ratio=0.8,
font_size=MAIN_BUTTON_FONT_SIZE,
release_function=lambda: 1 + 1,
font_ratio=None,
**kwargs):
if font_ratio is not None:
self.font_ratio = font_ratio
super().__init__(**kwargs)
self.release_function = release_function
self.always_release = True
Expand Down
2 changes: 1 addition & 1 deletion screens/custom_widgets/custom_progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ObjectProperty
)

### Module imports ###
### Local imports ###

from tools.constants import (
MAIN_COLOR,
Expand Down
2 changes: 1 addition & 1 deletion screens/custom_widgets/custom_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
NumericProperty
)

### Module imports ###
### Local imports ###

from tools.constants import (
CUSTOM_BUTTON_BACKGROUND_COLOR
Expand Down
33 changes: 31 additions & 2 deletions screens/custom_widgets/theme_layout.kv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#:import TITLE_OUTLINE_WIDTH tools.constants.TITLE_OUTLINE_WIDTH
#:import TITLE_OUTLINE_COLOR tools.constants.TITLE_OUTLINE_COLOR
#:set OUTLINE_RECTANGLE 6
#:set TITLE_SIZE_HINT_WIDTH 0.25

<-ThemeLayout>:

Expand Down Expand Up @@ -41,10 +42,38 @@
# Theme title
Label:
text: root.theme_title
pos_hint: { "center_x":0.25,"center_y":0.75}
size_hint: (0.4,0.5)
pos_hint: {"center_x":0.175,"center_y":0.75}
size_hint: (TITLE_SIZE_HINT_WIDTH,0.5)
font_size: root.font_ratio * root.font_size
text_size: (self.width,None)
font_name: root.text_font_name
outline_width: TITLE_OUTLINE_WIDTH
outline_color: TITLE_OUTLINE_COLOR
color: (0,0,0,1)
halign: "center"
valign: "center"

CustomButton:
text: "Preview"
pos_hint: {"center_x":0.175,"center_y":0.25}
size_hint: (TITLE_SIZE_HINT_WIDTH,0.3)
font_size: root.font_ratio * root.font_size * 0.8
radius:10

BuyButton:
button_title: "Image"
pos_hint: {"center_x":0.475,"center_y":0.5}
size_hint: (0.25,0.8)
font_size: 16
font_ratio: root.font_ratio
has_bought: root.has_bought_image
is_using: root.is_using_image

BuyButton:
button_title: "Colors"
pos_hint: {"center_x":0.75,"center_y":0.5}
size_hint: (0.25,0.8)
font_size: 16
font_ratio: root.font_ratio
has_bought: root.has_bought_colors
is_using: root.is_using_colors
9 changes: 7 additions & 2 deletions screens/custom_widgets/theme_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
BooleanProperty
)

### Module imports ###
### Local imports ###

from tools.path import (
PATH_TEXT_FONT
Expand Down Expand Up @@ -44,6 +44,8 @@ class ThemeLayout(Image):
second_color = ObjectProperty()
has_bought_image = BooleanProperty()
has_bought_colors = BooleanProperty()
is_using_image = BooleanProperty()
is_using_colors = BooleanProperty()

def __init__(
self,
Expand All @@ -54,6 +56,8 @@ def __init__(
second_color=SECOND_COLOR,
has_bought_image:bool = False,
has_bought_colors:bool = False,
is_using_image:bool = False,
is_using_colors:bool = False,
font_ratio=None,
**kwargs):

Expand All @@ -68,4 +72,5 @@ def __init__(
self.second_color = second_color
self.has_bought_image = has_bought_image
self.has_bought_colors = has_bought_colors

self.is_using_image = is_using_image
self.is_using_colors = is_using_colors
9 changes: 0 additions & 9 deletions screens/customization.kv
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
pos_hint: {"bottom":0,"left":0}
selected: "customization"

# ThemeLayout:
# theme_title: "Tutorial"
# size_hint: (0.8, 0.2)
# pos_hint: {"center_x": 0.5, "center_y": 0.5}
# font_size: 20
# font_ratio: root.font_ratio
# source: 'resources/images/backgrounds/lake_sunset.jpg'
# fit_mode: 'cover'

ScrollView:
id: scrollview
pos_hint: {"center_x":0.5, "center_y":0.475}
Expand Down
2 changes: 1 addition & 1 deletion screens/customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ def fill_scrollview(self):
current_act_button = ThemeLayout(
theme_title=theme_title,
source=PATH_BACKGROUNDS + THEMES_DICT[theme]["image"],
font_ratio=self.font_ratio)
font_ratio=self.font_ratio*0.8)
self.THEME_LAYOUT_DICT[theme] = current_act_button
scrollview_layout.add_widget(self.THEME_LAYOUT_DICT[theme])
2 changes: 2 additions & 0 deletions screens/home.kv
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
pos_hint: {"center_x":0.5, "center_y":0.6}
text:"Free Mode"
release_function: root.open_free_mode
font_ratio: root.font_ratio

CustomButton:
size_hint: (0.65,0.1)
pos_hint: {"center_x":0.5, "center_y":0.45}
text:"Daily Mode"
font_ratio: root.font_ratio
2 changes: 1 addition & 1 deletion screens/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from kivy.properties import StringProperty

### Module imports ###
### Local imports ###

from tools.path import (
PATH_BACKGROUNDS
Expand Down
2 changes: 1 addition & 1 deletion screens/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from kivy.properties import StringProperty

### Module imports ###
### Local imports ###

from tools.constants import (
USER_DATA,
Expand Down
2 changes: 1 addition & 1 deletion tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from kivy import platform

### Module imports ###
### Local imports ###

from tools.path import (
PATH_USER_DATA,
Expand Down

0 comments on commit db9703e

Please sign in to comment.