From c57115ae9371e6011b9fc7ffcbb408aaa867df35 Mon Sep 17 00:00:00 2001 From: LupaDevStudio Date: Mon, 11 Dec 2023 11:14:05 +0100 Subject: [PATCH] start creating the home screen with the bottom bar --- README.md | 6 +- data.json | 2 +- main.kv | 3 + main.py | 16 ++-- resources/images/{user.png => profile.png} | Bin resources/themes.json | 6 +- screens/__init__.py | 9 ++ screens/custom_widgets/__init__.py | 6 ++ screens/custom_widgets/bottom_bar.kv | 47 ++++++++++ screens/custom_widgets/bottom_bar.py | 22 +++++ screens/customization.kv | 0 screens/customization.py | 0 screens/home.kv | 24 +++++ screens/home.py | 32 +++++++ screens/opening.py | 99 +++++++++++++++++++++ screens/profile.kv | 0 screens/profile.py | 0 screens/settings.kv | 0 screens/settings.py | 0 tools/basic_tools/image.py | 12 ++- tools/constants.py | 13 ++- tools/kivy_tools/__init__.py | 4 +- tools/kivy_tools/image_button.py | 17 ++++ tools/kivy_tools/screen.kv | 3 +- tools/path.py | 6 +- 25 files changed, 305 insertions(+), 22 deletions(-) rename resources/images/{user.png => profile.png} (100%) create mode 100644 screens/__init__.py create mode 100644 screens/custom_widgets/__init__.py create mode 100644 screens/custom_widgets/bottom_bar.kv create mode 100644 screens/custom_widgets/bottom_bar.py create mode 100644 screens/customization.kv create mode 100644 screens/customization.py create mode 100644 screens/home.kv create mode 100644 screens/home.py create mode 100644 screens/opening.py create mode 100644 screens/profile.kv create mode 100644 screens/profile.py create mode 100644 screens/settings.kv create mode 100644 screens/settings.py create mode 100644 tools/kivy_tools/image_button.py diff --git a/README.md b/README.md index ada5bac..6f371d2 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,15 @@ This game is licensed under the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License](https://creativecommons.org/licenses/by-nc-sa/4.0/). -## Gameplay + ## Distribution -This game is available on the PlayStore. + + +This game is not distributed yet. ## Authors diff --git a/data.json b/data.json index 14e3895..3550cd7 100644 --- a/data.json +++ b/data.json @@ -14,7 +14,7 @@ "settings": { "sound_volume": 0.5, "music_volume": 0.5, - "current_background_theme": "", + "current_background_theme": "japanese_1", "current_music": "", "current_palette_theme": "" } diff --git a/main.kv b/main.kv index e69de29..b67627b 100644 --- a/main.kv +++ b/main.kv @@ -0,0 +1,3 @@ +#:kivy 2.2.1 + +WindowManager: diff --git a/main.py b/main.py index ed7d794..6afd8d0 100644 --- a/main.py +++ b/main.py @@ -10,12 +10,11 @@ ### Python imports ### -import os -import platform -os_name = platform.system() -if os_name == "Windows": - os.environ['KIVY_TEXT'] = 'pil' -print("Python packages loaded") +# import os +# import platform +# os_name = platform.system() +# if os_name == "Windows": +# os.environ['KIVY_TEXT'] = 'pil' ### Kivy imports ### @@ -28,7 +27,6 @@ from kivy.uix.widget import Widget from kivy.core.window import Window from kivy.clock import Clock -print("Kivy packages loaded") ### Module imports ### @@ -43,8 +41,6 @@ ) import screens.opening -print("Local packages loaded") - ############### ### General ### @@ -63,7 +59,6 @@ def __init__(self, **kwargs): current_screen = Screen(name="temp") self.add_widget(current_screen) self.current = "temp" - print("WindowManager initialised") class MainApp(App, Widget): @@ -121,4 +116,5 @@ def on_start(self): # Run the application if __name__ == "__main__": + Window.size = (480, 854) MainApp().run() diff --git a/resources/images/user.png b/resources/images/profile.png similarity index 100% rename from resources/images/user.png rename to resources/images/profile.png diff --git a/resources/themes.json b/resources/themes.json index e06a49b..9d76c91 100644 --- a/resources/themes.json +++ b/resources/themes.json @@ -1,7 +1,9 @@ { - "theme_1": { + "japanese_1": { "primary": "", "secondary": "", - "image": "" + "image": "pagode.jpg", + "price": 0, + "name": "" } } \ No newline at end of file diff --git a/screens/__init__.py b/screens/__init__.py new file mode 100644 index 0000000..a961dd0 --- /dev/null +++ b/screens/__init__.py @@ -0,0 +1,9 @@ +""" +Package to manage the screens of the application +""" + +############### +### Imports ### +############### + +from screens.home import HomeScreen diff --git a/screens/custom_widgets/__init__.py b/screens/custom_widgets/__init__.py new file mode 100644 index 0000000..5689155 --- /dev/null +++ b/screens/custom_widgets/__init__.py @@ -0,0 +1,6 @@ +""" +Package to manage the custom widgets included in the screens. +""" + + +from screens.custom_widgets.bottom_bar import BottomBar diff --git a/screens/custom_widgets/bottom_bar.kv b/screens/custom_widgets/bottom_bar.kv new file mode 100644 index 0000000..de8245b --- /dev/null +++ b/screens/custom_widgets/bottom_bar.kv @@ -0,0 +1,47 @@ +#:kivy 2.2.1 +#:import PATH_IMAGES tools.path.PATH_IMAGES + +: + + canvas.before: + # Background + Color: + rgba: self.background_color + Rectangle: + pos: self.pos + size: self.size + + # Separation bar + Color: + rgba: self.separation_color + Rectangle: + pos: (0,self.height) + size: (self.width, self.separation_height) + + # Home button + ImageButton: + source: PATH_IMAGES + "home.png" + size_hint: root.button_width, root.button_height + pos_hint: {"center_x":0.125, "center_y":0.5} + # release_function: root.manager.current = "home" + + # Customization button + ImageButton: + source: PATH_IMAGES + "customization.png" + size_hint: root.button_width, root.button_height + pos_hint: {"center_x":0.375, "center_y":0.5} + # release_function: root.manager.current = "customization" + + # Profile button + ImageButton: + source: PATH_IMAGES + "profile.png" + size_hint: root.button_width, root.button_height + pos_hint: {"center_x":0.625, "center_y":0.5} + # release_function: root.manager.current = "customization" + + # Settings button + ImageButton: + source: PATH_IMAGES + "settings.png" + size_hint: root.button_width, root.button_height + pos_hint: {"center_x":0.875, "center_y":0.5} + # release_function: root.manager.current = "customization" diff --git a/screens/custom_widgets/bottom_bar.py b/screens/custom_widgets/bottom_bar.py new file mode 100644 index 0000000..e36cc8a --- /dev/null +++ b/screens/custom_widgets/bottom_bar.py @@ -0,0 +1,22 @@ +""" +Module to create the bottom bar with the buttons. +""" + +############### +### Imports ### +############### + +from kivy.uix.relativelayout import RelativeLayout +from tools.kivy_tools import ImageButton + +############# +### Class ### +############# + + +class BottomBar(RelativeLayout): + background_color = (0, 0, 0, 0.5) + separation_color = (1, 1, 1, 1) + separation_height = 3 + button_width = 0.15 + button_height = 0.7 diff --git a/screens/customization.kv b/screens/customization.kv new file mode 100644 index 0000000..e69de29 diff --git a/screens/customization.py b/screens/customization.py new file mode 100644 index 0000000..e69de29 diff --git a/screens/home.kv b/screens/home.kv new file mode 100644 index 0000000..7db331a --- /dev/null +++ b/screens/home.kv @@ -0,0 +1,24 @@ +#:kivy 2.2.1 +#:import PATH_IMAGES tools.path.PATH_IMAGES +#: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 +#:import TITLE_OUTLINE_COLOR tools.constants.TITLE_OUTLINE_COLOR +#: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 + + +: + Label: + text: "Linconym" + font_name: PATH_TITLE_FONT + font_size: TITLE_FONT_SIZE * root.font_ratio + pos_hint: {"center_x":0.5, "center_y":0.9} + outline_width: TITLE_OUTLINE_WIDTH + outline_color: TITLE_OUTLINE_COLOR + color: TEXT_FONT_COLOR + + BottomBar: + size_hint: (1, BOTTOM_BAR_HEIGHT) + pos_hint: {"bottom":0,"left":0} \ No newline at end of file diff --git a/screens/home.py b/screens/home.py new file mode 100644 index 0000000..52290a3 --- /dev/null +++ b/screens/home.py @@ -0,0 +1,32 @@ +""" +Module to create the home screen. +""" + +############### +### Imports ### +############### + +from tools.path import ( + PATH_BACKGROUNDS +) +from tools.constants import ( + USER_DATA, + THEMES_DICT +) +from screens.custom_widgets import BottomBar +from tools.kivy_tools import ImprovedScreen, ImageButton + + +############# +### Class ### +############# + + +class HomeScreen(ImprovedScreen): + + def __init__(self, **kwargs) -> None: + current_background_theme = USER_DATA.settings["current_background_theme"] + super().__init__( + back_image_path=PATH_BACKGROUNDS + + THEMES_DICT[current_background_theme]["image"], + **kwargs) diff --git a/screens/opening.py b/screens/opening.py new file mode 100644 index 0000000..b113645 --- /dev/null +++ b/screens/opening.py @@ -0,0 +1,99 @@ +""" +Module for the opening screen. +""" + +############### +### Imports ### +############### + +import os +from threading import Thread +from tools.kivy_tools import ImprovedScreen +from tools.path import ( + PATH_IMAGES +) +from kivy.clock import Clock +from kivy.lang import Builder +from kivy.uix.label import Label + + +class OpeningScreen(ImprovedScreen): + """ + Screen of Opening. + """ + + def __init__(self, **kw): + super().__init__( + back_image_path=PATH_IMAGES + "opening.jpg", + **kw) + self.opacity_state = -1 + self.opacity_rate = 0.03 + self.label = Label(text="", pos_hint={ + "bottom": 1, "left": 1}) + self.add_widget(self.label) + + def update(self, *args): + self.label.opacity += self.opacity_state * self.opacity_rate + if self.label.opacity < 0 or self.label.opacity > 1: + self.opacity_state = -self.opacity_state + + def on_enter(self, *args): + print("enter opening screen") + # Schedule the update for the text opacity effect + Clock.schedule_interval(self.update, 1 / 60) + + return super().on_enter(*args) + + def on_pre_leave(self, *args): + # Unschedule the clock update + Clock.unschedule(self.update, 1 / 60) + + return super().on_leave(*args) + + def launch_thread(self, *_): + thread = Thread(target=self.load_kv_files) + thread.start() + + def load_kv_files(self, *_): + from screens import ( + HomeScreen) + + screen_files = [file for file in os.listdir( + "screens") if file.endswith(".kv")] + for file in screen_files: + Builder.load_file(f"screens/{file}", encoding="utf-8") + widget_files = [file for file in os.listdir( + "screens/custom_widgets") if file.endswith(".kv")] + for file in widget_files: + Builder.load_file( + f"screens/custom_widgets/{file}", encoding="utf-8") + + self.HomeScreen = HomeScreen + + Clock.schedule_once(self.load_other_screens) + + def switch_to_menu(self, *args): + self.manager.current = "home" + + def load_other_screens(self, *args): + + ### Load the kv files of the screens ### + home_screen = self.HomeScreen(name="home") + self.manager.add_widget(home_screen) + # game_screen = self.GameScreen(name="game") + # self.manager.add_widget(game_screen) + # settings_screen = self.SettingsScreen(name="settings") + # self.manager.add_widget(settings_screen) + # game_over_screen = self.GameOverScreen(name="game_over") + # self.manager.add_widget(game_over_screen) + # achievements_screen = self.AchievementsScreen(name="achievements") + # self.manager.add_widget(achievements_screen) + # tutorial_screen = self.TutorialScreen(name="tutorial") + # self.manager.add_widget(tutorial_screen) + # help_screen = self.HelpScreen(name="help") + # self.manager.add_widget(help_screen) + # Preload screens + # Clock.schedule_once(self.manager.get_screen("game").preload) + # Clock.schedule_once(self.manager.get_screen("game_over").preload) + # self.manager.current = "menu" + Clock.schedule_once(self.switch_to_menu) diff --git a/screens/profile.kv b/screens/profile.kv new file mode 100644 index 0000000..e69de29 diff --git a/screens/profile.py b/screens/profile.py new file mode 100644 index 0000000..e69de29 diff --git a/screens/settings.kv b/screens/settings.kv new file mode 100644 index 0000000..e69de29 diff --git a/screens/settings.py b/screens/settings.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/basic_tools/image.py b/tools/basic_tools/image.py index 3d2b64d..4873a15 100644 --- a/tools/basic_tools/image.py +++ b/tools/basic_tools/image.py @@ -52,6 +52,12 @@ def get_image_size(file_path): return (img.width, img.height) +class MockImageMetadata(): + def __init__(self, width, height) -> None: + self.width = width + self.height = height + + def get_image_metadata(file_path): """ Return an `Image` object for a given img file content - no external @@ -63,7 +69,11 @@ def get_image_metadata(file_path): Returns: Image: (path, type, file_size, width, height) """ - size = os.path.getsize(file_path) + try: + size = os.path.getsize(file_path) + except FileNotFoundError: + print(f"Warning, {file_path} not found") + return MockImageMetadata(100, 100) # be explicit with open arguments - we need binary mode with io.open(file_path, "rb") as input: diff --git a/tools/constants.py b/tools/constants.py index 503ba14..b1b12c9 100644 --- a/tools/constants.py +++ b/tools/constants.py @@ -30,7 +30,8 @@ PATH_WORDS_34K, PATH_WORDS_88K, PATH_WORDS_375K, - PATH_GAMEPLAY + PATH_GAMEPLAY, + PATH_THEMES ) from tools.basic_tools import ( load_json_file, @@ -137,8 +138,14 @@ def __init__(self) -> None: self.PRIMARY = (0, 0, 0, 1) self.SECONDARY = (0, 0, 0, 1) +### Graphics ### + TEXT_FONT_COLOR = (0, 0, 0, 1) +TITLE_FONT_SIZE = 45 +TITLE_OUTLINE_WIDTH = 2 +TITLE_OUTLINE_COLOR = (1, 1, 1, 1) +BOTTOM_BAR_HEIGHT = 0.12 ### Musics ### @@ -183,3 +190,7 @@ def __init__(self) -> None: ### Levels ### GAMEPLAY_DICT = load_json_file(PATH_GAMEPLAY) + +### Themes ### + +THEMES_DICT = load_json_file(PATH_THEMES) diff --git a/tools/kivy_tools/__init__.py b/tools/kivy_tools/__init__.py index 1a5138a..963ab62 100644 --- a/tools/kivy_tools/__init__.py +++ b/tools/kivy_tools/__init__.py @@ -17,6 +17,7 @@ from tools.kivy_tools.screen import ImprovedScreen from tools.kivy_tools.image_with_text import ImageWithText from tools.kivy_tools.image_with_text_button import ImageWithTextButton +from tools.kivy_tools.image_button import ImageButton ############### ### Process ### @@ -36,4 +37,5 @@ Builder.load_file(PATH_KIVY_FOLDER + "image_with_text.kv", encoding="utf-8") # Build the kv file for image with text and button -Builder.load_file(PATH_KIVY_FOLDER + "image_with_text_button.kv", encoding="utf-8") +Builder.load_file(PATH_KIVY_FOLDER + + "image_with_text_button.kv", encoding="utf-8") diff --git a/tools/kivy_tools/image_button.py b/tools/kivy_tools/image_button.py new file mode 100644 index 0000000..46b231e --- /dev/null +++ b/tools/kivy_tools/image_button.py @@ -0,0 +1,17 @@ +from kivy.uix.image import Image +from kivy.uix.behaviors import ButtonBehavior + + +class ImageButton(ButtonBehavior, Image): + def __init__(self, source="", release_function=lambda: 1 + 1, **kwargs): + super().__init__(**kwargs) + self.release_function = release_function + self.source = source + self.fit_mode = "contain" + + def on_press(self): + self.opacity = 0.8 + + def on_release(self): + self.release_function() + self.opacity = 1 diff --git a/tools/kivy_tools/screen.kv b/tools/kivy_tools/screen.kv index 849b75c..99fbf3c 100644 --- a/tools/kivy_tools/screen.kv +++ b/tools/kivy_tools/screen.kv @@ -11,6 +11,5 @@ disabled: root.back_image_disabled opacity: root.back_image_opacity pos_hint: {"center_x":0.5,"center_y":0.5} - allow_stretch: True - keep_ratio: True + fit_mode: "cover" anim_delay: 0.0166 \ No newline at end of file diff --git a/tools/path.py b/tools/path.py index 896afdd..84f853f 100644 --- a/tools/path.py +++ b/tools/path.py @@ -15,15 +15,17 @@ # Path for the resources PATH_IMAGES = PATH_RESOURCES_FOLDER + "images/" +PATH_BACKGROUNDS = PATH_IMAGES + "backgrounds/" PATH_SOUNDS = PATH_RESOURCES_FOLDER + "sounds/" PATH_MUSICS = PATH_RESOURCES_FOLDER + "musics/" PATH_FONTS = PATH_RESOURCES_FOLDER + "fonts/" PATH_GAMEPLAY = PATH_RESOURCES_FOLDER + "gameplay.json" -PATH_PALETTES = PATH_RESOURCES_FOLDER + "palette.json" +PATH_THEMES = PATH_RESOURCES_FOLDER + "themes.json" PATH_WORDS_375K = PATH_RESOURCES_FOLDER + "english_words_375k.txt" PATH_WORDS_10K = PATH_RESOURCES_FOLDER + "english_words_10k.txt" PATH_WORDS_34K = PATH_RESOURCES_FOLDER + "english_words_34k.txt" PATH_WORDS_88K = PATH_RESOURCES_FOLDER + "english_words_88k.txt" # Path for the fonts -PATH_TEXT_FONT = PATH_FONTS + "Oxanium-ExtraBold.ttf" +PATH_TEXT_FONT = PATH_FONTS + "Oxanium-Bold.ttf" +PATH_TITLE_FONT = PATH_FONTS + "Oxanium-ExtraBold.ttf"