Skip to content

Commit

Permalink
start creating the home screen with the bottom bar
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Dec 11, 2023
1 parent 8ba676e commit c57115a
Show file tree
Hide file tree
Showing 25 changed files with 305 additions and 22 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!-- ## Gameplay -->



## Distribution

This game is available on the PlayStore.
<!-- This game is available on the PlayStore. -->

This game is not distributed yet.

## Authors

Expand Down
2 changes: 1 addition & 1 deletion data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
Expand Down
3 changes: 3 additions & 0 deletions main.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#:kivy 2.2.1

WindowManager:
16 changes: 6 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

Expand All @@ -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 ###

Expand All @@ -43,8 +41,6 @@
)
import screens.opening

print("Local packages loaded")


###############
### General ###
Expand All @@ -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):
Expand Down Expand Up @@ -121,4 +116,5 @@ def on_start(self):

# Run the application
if __name__ == "__main__":
Window.size = (480, 854)
MainApp().run()
File renamed without changes
6 changes: 4 additions & 2 deletions resources/themes.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"theme_1": {
"japanese_1": {
"primary": "",
"secondary": "",
"image": ""
"image": "pagode.jpg",
"price": 0,
"name": ""
}
}
9 changes: 9 additions & 0 deletions screens/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Package to manage the screens of the application
"""

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

from screens.home import HomeScreen
6 changes: 6 additions & 0 deletions screens/custom_widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Package to manage the custom widgets included in the screens.
"""


from screens.custom_widgets.bottom_bar import BottomBar
47 changes: 47 additions & 0 deletions screens/custom_widgets/bottom_bar.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#:kivy 2.2.1
#:import PATH_IMAGES tools.path.PATH_IMAGES

<BottomBar>:

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"
22 changes: 22 additions & 0 deletions screens/custom_widgets/bottom_bar.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added screens/customization.kv
Empty file.
Empty file added screens/customization.py
Empty file.
24 changes: 24 additions & 0 deletions screens/home.kv
Original file line number Diff line number Diff line change
@@ -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


<HomeScreen>:
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}
32 changes: 32 additions & 0 deletions screens/home.py
Original file line number Diff line number Diff line change
@@ -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)
99 changes: 99 additions & 0 deletions screens/opening.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file added screens/profile.kv
Empty file.
Empty file added screens/profile.py
Empty file.
Empty file added screens/settings.kv
Empty file.
Empty file added screens/settings.py
Empty file.
12 changes: 11 additions & 1 deletion tools/basic_tools/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ###

Expand Down Expand Up @@ -183,3 +190,7 @@ def __init__(self) -> None:
### Levels ###

GAMEPLAY_DICT = load_json_file(PATH_GAMEPLAY)

### Themes ###

THEMES_DICT = load_json_file(PATH_THEMES)
Loading

0 comments on commit c57115a

Please sign in to comment.