Skip to content

Commit

Permalink
prototype of scrollview for free mode screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Dec 15, 2023
1 parent 3899dc3 commit 55a1a2a
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 22 deletions.
17 changes: 16 additions & 1 deletion resources/gameplay.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Act1": {
"name": "Act 1 : Tutorial",
"name": "Act 1 - Tutorial",
"1": {
"start_word": "link",
"end_word": "pink",
Expand Down Expand Up @@ -81,5 +81,20 @@
"88k_sol": 3,
"375k_sol": 3
}
},
"Act2": {
"name": "Act 2 - Haunted Forest"
},
"Act3": {
"name": "Act 3 - The Cruise"
},
"Act4": {
"name": "Act 4 - Space Exploration"
},
"Act5": {
"name": "Act 5 - Around the World"
},
"Act6": {
"name": "Act 6 - My Little Poney"
}
}
9 changes: 5 additions & 4 deletions screens/custom_widgets/act_button.kv
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
id: act_title_label
text: root.act_title
pos_hint: {"center_y":0.8, "center_x":0.5}
size: (1,0.5)
font_size: root.parent.font_ratio * root.font_size
size_hint: (1,0.5)
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"
Expand All @@ -28,15 +29,15 @@
id: three_stars
pos_hint: {"center_x":0.35, "center_y":0.25}
size_hint: (0.5,0.5)
stars_number: root.stars_number
nb_stars: root.nb_stars

# Completion
Label:
id: completion_label
text: root.completion_text
pos_hint: {"center_x":0.8, "center_y":0.25}
size_hint: (0.3,0.5)
font_size: root.parent.font_ratio * root.font_size
font_size: root.font_ratio * root.font_size
font_name: root.text_font_name
halign: "center"
valign: "center"
Expand Down
28 changes: 27 additions & 1 deletion screens/custom_widgets/act_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
### Imports ###
###############

### Python imports ###
from typing import Literal

### Kivy imports ###
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.behaviors import ButtonBehavior
Expand Down Expand Up @@ -38,22 +41,45 @@ class ActButton(ButtonBehavior, RelativeLayout):
act_title = StringProperty()
completion_text = StringProperty()
font_size = NumericProperty()
font_ratio = NumericProperty(1)
nb_levels = NumericProperty()
nb_completed_levels = NumericProperty()
stars_number = NumericProperty()
nb_stars = NumericProperty()
text_font_name = StringProperty(PATH_TEXT_FONT)

def __init__(
self,
act_title: str = None,
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=MAIN_BUTTON_FONT_SIZE,
release_function=lambda: 1 + 1,
font_ratio=None,
**kwargs):

if act_title is not None:
self.act_title = act_title
if nb_levels is not None:
self.nb_levels = nb_levels
if nb_completed_levels is not None:
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

super().__init__(**kwargs)
self.release_function = release_function
self.always_release = True
self.text_font_name = text_font_name
self.font_size = font_size
self.bind(nb_completed_levels=self.update_nb_completed_levels)
self.update_nb_completed_levels(None, None)

def update_nb_completed_levels(self, base_widget, value):
self.completion_text = str(
Expand Down
3 changes: 3 additions & 0 deletions screens/custom_widgets/bottom_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def on_kv_post(self, base_widget):
self.selected_rect_size = \
(self.ids[self.selected + "_button"].size_hint[0] * 1.2,
self.ids[self.selected + "_button"].size_hint[1] * 1.2)
else:
self.selected_rect_pos = self.ids["home_button"].pos_hint
self.selected_rect_size = (0, 0)
return super().on_kv_post(base_widget)

def open_home(self):
Expand Down
14 changes: 7 additions & 7 deletions screens/custom_widgets/three_stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ThreeStars(RelativeLayout):
star_color_dict = {1: star_one_color,
2: star_two_color,
3: star_three_color}
stars_number = NumericProperty()
nb_stars = NumericProperty()
primary_color = ListProperty([0.5, 0.5, 0.5, 1.])
secondary_color = ListProperty([1., 1., 1., 1.])

Expand All @@ -42,24 +42,24 @@ def __init__(
self.primary_color = primary_color
self.secondary_color = secondary_color

self.bind(stars_number=self.change_stars_number)
self.bind(nb_stars=self.change_nb_stars)
super().__init__(**kwargs)

def change_stars_number(self, base_widget, value):
def change_nb_stars(self, base_widget, value):
"""
Change the number of stars displayed.
"""

# self.stars_number = stars_number
if self.stars_number > 0:
# self.nb_stars = nb_stars
if self.nb_stars > 0:
self.star_one_color = self.primary_color
else:
self.star_one_color = self.secondary_color
if self.stars_number > 1:
if self.nb_stars > 1:
self.star_two_color = self.primary_color
else:
self.star_two_color = self.secondary_color
if self.stars_number > 2:
if self.nb_stars > 2:
self.star_three_color = self.primary_color
else:
self.star_three_color = self.secondary_color
45 changes: 37 additions & 8 deletions screens/free_mode.kv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#: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
#:import GAMEPLAY_DICT tools.constants.GAMEPLAY_DICT


<FreeModeScreen>:
Expand All @@ -22,12 +23,40 @@
BottomBar:
size_hint: (1, BOTTOM_BAR_HEIGHT)
pos_hint: {"bottom":0,"left":0}
selected: "home"
selected: "none"

ActButton:
size_hint: (0.7,0.15)
pos_hint:{"center_x":0.5,"center_y":0.5}
stars_number: 2
nb_levels: 10
nb_completed_levels: 8
act_title: "Act 1 - Tutorial"
# ActButton:
# size_hint: (0.7,0.15)
# pos_hint:{"center_x":0.5,"center_y":0.5}
# nb_stars: 2
# nb_levels: 10
# nb_completed_levels: 8
# act_title: "Act 1 - Tutorial"

ScrollView:
id: scrollview
pos_hint: {"center_x":0.5, "center_y":0.475}
size_hint: (1,0.7)
do_scroll_x: False



MyScrollViewLayout:
id: scrollview_layout
cols:1
spacing:40
height:0.2*root.height * len(GAMEPLAY_DICT)
# size_hint: (None,None)
# size: self.minimum_size
# top:self.height
# # pos: (100,0)
# pos_hint: {"center_x":0.5}

# # Background
# canvas.before:
# Color:
# rgba: (1,0,0)
# RoundedRectangle:
# pos:self.pos
# size:self.size
# radius:[40,]
48 changes: 47 additions & 1 deletion screens/free_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
### Imports ###
###############

### Kivy imports ###
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.properties import NumericProperty

from tools.path import (
PATH_BACKGROUNDS
)
from tools.constants import (
USER_DATA,
THEMES_DICT
THEMES_DICT,
GAMEPLAY_DICT
)
from tools.kivy_tools import (
ImprovedScreen,
)
from screens.custom_widgets import ActButton


#############
Expand All @@ -31,3 +38,42 @@ def __init__(self, **kwargs) -> None:
back_image_path=PATH_BACKGROUNDS +
THEMES_DICT[current_background_theme]["image"],
**kwargs)
self.fill_scrollview()

def on_pre_enter(self, *args):
for act in self.ACT_BUTTON_DICT:
self.ACT_BUTTON_DICT[act].font_ratio = self.font_ratio
self.ACT_BUTTON_DICT[act].opacity = 1
return super().on_pre_enter(*args)

def on_resize(self, *args):
for act in self.ACT_BUTTON_DICT:
self.ACT_BUTTON_DICT[act].font_ratio = self.font_ratio
return super().on_resize(*args)

def fill_scrollview(self):
# Create the layout
# scrollview_layout = GridLayout(cols=1, row_force_default=True, row_default_height=50,
# pos_hint={'center_x': .5}, size_hint=(None, None))
# scrollview_layout.bind(minimum_size=scrollview_layout.setter('size'))
# scrollview_layout.bind(height=scrollview_layout.setter('top'))
scrollview_layout = self.ids["scrollview_layout"]
# Load the widgets
self.ACT_BUTTON_DICT = {}
for act in GAMEPLAY_DICT:
act_title = GAMEPLAY_DICT[act]["name"]
nb_levels = len(GAMEPLAY_DICT[act]) - 1
if act in USER_DATA.free_mode:
nb_completed_levels = USER_DATA.free_mode[act]
else:
nb_completed_levels = 0
current_act_button = ActButton(
act_title=act_title,
nb_levels=nb_levels,
nb_completed_levels=nb_completed_levels,
nb_stars=0,
font_ratio=self.font_ratio,
opacity=0)
self.ACT_BUTTON_DICT[act] = current_act_button
scrollview_layout.add_widget(self.ACT_BUTTON_DICT[act])
# self.ids["scrollview"].add_widget(scrollview_layout)

0 comments on commit 55a1a2a

Please sign in to comment.