Skip to content

Commit

Permalink
continue working on level branches
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Jan 20, 2024
1 parent 63de0e8 commit 126c1ef
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 33 deletions.
Binary file added design/LinconymGame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 30 additions & 1 deletion screens/custom_widgets/levels_branchs.kv
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,33 @@
size_hint: (0.8,0.45)
nb_stars: root.nb_stars

# <LevelLeftBranch>:
<StraightBranch>:
# canvas.before:
# Color:
# rgba: (1,1,1,0.5)
# Rectangle:
# pos:self.pos
# size:self.size
canvas:
Color:
rgba: self.color
Line:
# points: [(self.x,self.top),(self.right,self.top),(self.x,self.y),(self.right,self.y)]
points: [self.x, self.center_y,self.right, self.center_y]
width: 2
cap: "none"

<CurveBranchTop>:
# canvas.before:
# Color:
# rgba: (1,1,1,0.5)
# Rectangle:
# pos:self.pos
# size:self.size
canvas:
Color:
rgba: self.color
Line:
width: 2
bezier: [self.x, self.top,self.center_x, self.top,self.center_x, self.y]
cap: "none"
90 changes: 86 additions & 4 deletions screens/custom_widgets/levels_branchs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,52 @@
### Imports ###
###############

### Python imports ###

from math import ceil

### Kivy imports ###

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

### Local imports ###

from tools.kivy_tools.tools_kivy import MyScrollViewLayout

from tools.constants import (
USER_DATA,
GAMEPLAY_DICT,
OPACITY_ON_BUTTON_PRESS,
MAX_NB_LEVELS_PER_BRANCH,
LEVEL_BUTTON_SIZE_HINT,
LEVEL_BUTTON_SPACING,
LEVEL_BUTTON_SIDE_OFFSET
LEVEL_BUTTON_SIDE_OFFSET,
LEVEL_BUTTON_RELATIVE_HEIGHT
)


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


class StraightBranch(Widget):
color = ColorProperty()


class CurveBranchTop(Widget):
color = ColorProperty()


class LevelButton(ButtonBehavior, RelativeLayout):

nb_stars = NumericProperty()
Expand Down Expand Up @@ -73,6 +92,8 @@ def on_release(self):
class LevelBranch(RelativeLayout):

font_ratio = NumericProperty()
primary_color = ColorProperty((0.5, 0.5, 0.5, 1))
secondary_color = ColorProperty((0.2, 0.2, 0.2, 1))

def __init__(
self,
Expand Down Expand Up @@ -110,7 +131,7 @@ def compute_level_button_pos_hint(self, local_id: int):
else:
center_x = 1 - (LEVEL_BUTTON_SIDE_OFFSET + (LEVEL_BUTTON_SIZE_HINT + LEVEL_BUTTON_SPACING) *
local_id + LEVEL_BUTTON_SIZE_HINT / 2)
if local_id == 0:
if local_id + 1 < MAX_NB_LEVELS_PER_BRANCH:
pos_hint["top"] = 1
else:
pos_hint["y"] = 0
Expand All @@ -126,6 +147,7 @@ def build_layout(self):
self.local_nb_levels = min(
nb_levels - self.branch_id * MAX_NB_LEVELS_PER_BRANCH, 4)
for local_id in range(self.local_nb_levels):
# Create the level button
level_id = local_id + 1 + self.branch_id * MAX_NB_LEVELS_PER_BRANCH
level_key = str(level_id)
level_pos_hint = self.compute_level_button_pos_hint(local_id)
Expand All @@ -139,5 +161,65 @@ def build_layout(self):
is_unlocked=level_is_unlocked,
nb_stars=level_nb_stars,
pos_hint=level_pos_hint,
size_hint=(LEVEL_BUTTON_SIZE_HINT, 0.4))
size_hint=(LEVEL_BUTTON_SIZE_HINT, LEVEL_BUTTON_RELATIVE_HEIGHT))
self.add_widget(level_button)
# Create the branch
if level_id < nb_levels:

if level_is_unlocked:
branch_color = self.primary_color
else:
branch_color = self.secondary_color
if self.branch_id % 2 == 0:
if local_id + 2 < MAX_NB_LEVELS_PER_BRANCH:
branch_size_hint = (
LEVEL_BUTTON_SPACING, LEVEL_BUTTON_RELATIVE_HEIGHT)
branch_pos_hint = {
"center_x": level_pos_hint["center_x"] + LEVEL_BUTTON_SPACING / 2 + LEVEL_BUTTON_SIZE_HINT / 2}
branch_pos_hint["top"] = level_pos_hint["top"]
branch = StraightBranch(
size_hint=branch_size_hint,
pos_hint=branch_pos_hint,
color=branch_color)
elif local_id + 2 == MAX_NB_LEVELS_PER_BRANCH:
branch_pos_hint = {
"x": level_pos_hint["center_x"] + LEVEL_BUTTON_SIZE_HINT / 2,
"top": level_pos_hint["top"] - LEVEL_BUTTON_RELATIVE_HEIGHT / 2}
branch_size_hint = (
LEVEL_BUTTON_SPACING + LEVEL_BUTTON_SIZE_HINT / 2, LEVEL_BUTTON_RELATIVE_HEIGHT / 2 + (1 - 2 * LEVEL_BUTTON_RELATIVE_HEIGHT))
branch = CurveBranchTop(
size_hint=branch_size_hint,
pos_hint=branch_pos_hint,
color=branch_color)
else:
continue
self.add_widget(branch)
else:
pass


class LevelLayout(MyScrollViewLayout):

font_ratio = NumericProperty()
primary_color = ColorProperty((0.5, 0.5, 0.5, 1))
secondary_color = ColorProperty((0.2, 0.2, 0.2, 1))
nb_branches = NumericProperty()

def __init__(
self,
act_id="Act1",
**kw):
super().__init__(**kw)
self.act_id = act_id
self.cols = 1
self.spacing = 40
self.build_layout()

def build_layout(self):
nb_levels = len(GAMEPLAY_DICT[self.act_id]) - 1
self.nb_branches = ceil(nb_levels / MAX_NB_LEVELS_PER_BRANCH)
for branch_id in range(self.nb_branches):
level_branch = LevelBranch(
act_id=self.act_id,
branch_id=branch_id)
self.add_widget(level_branch)
26 changes: 21 additions & 5 deletions screens/levels.kv
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,24 @@
# font_ratio: root.font_ratio
# on_release: root.open_game_screen()

LevelBranch:
pos_hint: {"center_x":0.5, "center_y":0.5}
size_hint: (1, 0.15)
height: self.width*0.8
font_ratio: root.font_ratio
# LevelBranch:
# pos_hint: {"center_x":0.5, "center_y":0.5}
# size_hint: (1, 0.15)
# height: self.width*0.8
# font_ratio: root.font_ratio
# primary_color: root.primary_color
# secondary_color: root.secondary_color

CustomScrollview:
id: custom_scrollview
pos_hint: {"center_x":0.49, "center_y":0.475}
size_hint: (0.98,0.7)
bar_color: root.primary_color
bar_inactive_color: root.secondary_color

LevelLayout:
id: level_layout
height: 0.15*root.height * self.nb_branches
padding: (0.05*root.width, 0,0.05*root.width,40)
primary_color: root.primary_color
secondary_color: root.secondary_color
17 changes: 16 additions & 1 deletion screens/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
### Imports ###
###############

### Kivy imports ###

from kivy.properties import ColorProperty

### Local imports ###

from tools.path import (
PATH_BACKGROUNDS
)
Expand All @@ -31,6 +37,9 @@ class LevelsScreen(ImprovedScreen):
Class to manage the levels screen which allow the user to select a level inside an act.
"""

primary_color = ColorProperty((0, 0, 0, 1))
secondary_color = ColorProperty((0, 0, 0, 1))

def __init__(self, **kwargs) -> None:
current_theme_image = USER_DATA.settings["current_theme_image"]
super().__init__(
Expand All @@ -39,9 +48,15 @@ def __init__(self, **kwargs) -> None:
**kwargs)
self.current_act_id = ""

def on_pre_enter(self, *args):
current_theme_colors = USER_DATA.settings["current_theme_colors"]
self.primary_color = THEMES_DICT[current_theme_colors]["primary"]
self.secondary_color = THEMES_DICT[current_theme_colors]["secondary"]
return super().on_pre_enter(*args)

def on_enter(self, *args):
return super().on_enter(*args)

def open_game_screen(self):
self.manager.get_screen("game").current_act_id = self.current_act_id
self.manager.current = "game"
22 changes: 0 additions & 22 deletions screens/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,6 @@ class SettingsScreen(ImprovedScreen):

version_text = StringProperty()

# def add_sliders(self):
# self.sound_slider = CustomSlider(
# min=0,
# max=1,
# value=USER_DATA.settings["sound_volume"],
# size_hint=(0.7, 0.06),
# pos_hint={"center_x": 0.5, "center_y": 0.59})
# self.add_widget(self.sound_slider)
# self.sound_slider.bind(value=self.update_sound_volume)
# self.music_slider = CustomSlider(
# min=0,
# max=1,
# value=USER_DATA.settings["sound_volume"],
# size_hint=(0.7, 0.06),
# pos_hint={"center_x": 0.5, "center_y": 0.59})
# self.add_widget(self.music_slider)
# self.music_slider.bind(value=self.update_music_volume)

# def destroy_sliders(self):
# self.remove_widget(self.sound_slider)
# self.remove_widget(self.music_slider)

def __init__(self, **kwargs) -> None:
current_theme_image = USER_DATA.settings["current_theme_image"]
self.version_text = "Version " + str(__version__)
Expand Down
2 changes: 2 additions & 0 deletions tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def __init__(self) -> None:

MAX_NB_LEVELS_PER_BRANCH = 4
LEVEL_BUTTON_SIZE_HINT = 0.15
LEVEL_BUTTON_RELATIVE_HEIGHT = 0.45
LEVEL_BRANCH_RELATIVE_HEIGHT = 0.2
LEVEL_BUTTON_SPACING = (1 - (MAX_NB_LEVELS_PER_BRANCH + 1)
* LEVEL_BUTTON_SIZE_HINT) / MAX_NB_LEVELS_PER_BRANCH
LEVEL_BUTTON_SIDE_OFFSET = LEVEL_BUTTON_SIZE_HINT + LEVEL_BUTTON_SPACING
Expand Down

0 comments on commit 126c1ef

Please sign in to comment.