Skip to content

Commit

Permalink
improve settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Nov 16, 2023
1 parent fe51254 commit 6bece82
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
1 change: 1 addition & 0 deletions licenses/dinosaur_icon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="https://www.flaticon.com/free-icons/dinosaur" title="dinosaur icons">Dinosaur icons created by Smashicons - Flaticon</a>
Binary file added resources/new_logo_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/new_logo_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions screens/game.kv
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
# Event background
ImageWithTextButton:
id: event
source: PATH_IMAGES + "event_background.png"
source: PATH_IMAGES + "event_background.jpg"
size_hint: center_img_width, center_img_height
pos_hint: {"center_x": 0.5, "center_y": center_img_center_y}
allow_stretch: True
Expand Down Expand Up @@ -358,7 +358,7 @@
# Answer
ImageWithText:
id: answer
source: PATH_IMAGES + "answer_background.png"
source: PATH_IMAGES + "answer_background.jpg"
size_hint: center_img_width, center_img_height
pos_hint: {"center_x": 0.5, "center_y": center_img_center_y}
allow_stretch: True
Expand All @@ -374,4 +374,14 @@
pos_hint: {"center_x": 0.5, "center_y": 0.15}
allow_stretch: True
keep_ratio: True
release_function: root.go_to_next_card
release_function: root.go_to_next_card

# Rewind button
ImageWithTextButton:
id: rewind_button
source: PATH_IMAGES + "rewind_button.png"
size_hint: 0.1, None
pos_hint: {"center_x": 0.9, "center_y": 0.5}
allow_stretch: True
keep_ratio: True
release_function: root.rewind
3 changes: 3 additions & 0 deletions screens/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,6 @@ def start_day(self, *_):
else:
self.update_display_resources()
self.manager.current = "game_over"

def rewind(self):
pass
7 changes: 4 additions & 3 deletions screens/settings.kv
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
id: sound_slider
min: 0
max: 1
value: 0.5
value: root.sound_volume_value
pos_hint: {"center_x":0.75, "center_y": 0.4}
size_hint: 0.3, 0.1

Expand All @@ -35,7 +35,7 @@
id: music_slider
min: 0
max: 1
value: 0.5
value: root.music_volume_value
pos_hint: {"center_x":0.75, "center_y": 0.6}
size_hint: 0.3, 0.1

Expand All @@ -48,11 +48,12 @@
outline_color: (1,1,1,1)

Button:
id: apply_music_settings
id: apply_music_settings_button
text: root.apply_label
pos_hint: {"center_x":0.75, "center_y": 0.225}
size_hint: 0.3, 0.1
font_size: 20*root.font_ratio
on_release: root.apply_music_settings

### Language ###
Label:
Expand Down
32 changes: 32 additions & 0 deletions screens/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
DICT_LANGUAGE_NAME_TO_CODE,
TEXT
)
from tools import (
music_mixer,
sound_mixer
)


class SettingsScreen(ImprovedScreen):
Expand All @@ -41,13 +45,19 @@ class SettingsScreen(ImprovedScreen):
enter_code_label = StringProperty()
validate_label = StringProperty()

sound_volume_value = NumericProperty(0.5)
music_volume_value = NumericProperty(0.5)

def __init__(self, **kw):
super().__init__(
back_image_path=PATH_IMAGES + "settings_background.jpg",
font_name=PATH_TEXT_FONT,
**kw)

def load_labels(self):
"""
Load the text labels of the screen.
"""
self.sound_volume_label = TEXT.settings["sound_volume"]
self.music_volume_label = TEXT.settings["music_volume"]
self.apply_label = TEXT.settings["apply"]
Expand All @@ -57,11 +67,21 @@ def load_labels(self):
self.validate_label = TEXT.settings["validate"]

def on_enter(self, *args):
# Load the labels
self.load_labels()
# Set the values of the language spinner
self.values_language_list = LANGUAGES_LIST
return super().on_enter(*args)

def change_language(self, language_name):
"""
Change the language of the game interface.
Parameters
----------
language_name : str
Name of the language.
"""
language_code = DICT_LANGUAGE_NAME_TO_CODE[language_name]
USER_DATA.language = language_code
TEXT.change_language(language_code)
Expand All @@ -71,4 +91,16 @@ def go_to_menu(self):
"""
Go back to the main menu.
"""

self.manager.current = "menu"

def apply_music_settings(self):
"""
Apply the music settings choosed by the user using the sliders.
"""

music_mixer.change_volume(self.music_volume_value)
sound_mixer.change_volume(self.sound_volume_value)

USER_DATA.music_volume = self.music_volume_value
USER_DATA.sound_effects_volume = self.sound_volume_value
1 change: 1 addition & 0 deletions tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(self) -> None:
self.endings = data["endings"]
self.music_volume = data["music_volume"]
self.sound_effects_volume = data["sound_effects_volume"]
self.ads_enabled = data["ads_enabled"]


USER_DATA = UserData()
Expand Down

0 comments on commit 6bece82

Please sign in to comment.