From a36a50464cdcfc1a22e0254057bebdc0f1a9e543 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Wed, 22 Feb 2017 23:53:21 -0500 Subject: [PATCH] Build up settings and main menu for justCheckers. --- justcheckers/app.py | 22 +++++++++ justcheckers/justcheckers.kv | 29 ++++++++++- justcheckers/ui/menu_view.py | 93 ------------------------------------ 3 files changed, 49 insertions(+), 95 deletions(-) delete mode 100644 justcheckers/ui/menu_view.py diff --git a/justcheckers/app.py b/justcheckers/app.py index 2be8338..da51390 100644 --- a/justcheckers/app.py +++ b/justcheckers/app.py @@ -5,6 +5,7 @@ Main application for justCheckers :license: GPL v3+ """ +import json import logging import os import sys @@ -21,11 +22,32 @@ LOG = logging.getLogger(__name__) class JustCheckersApp(App): title = 'justCheckers' icon = 'images/icon.png' + use_kivy_settings = False def on_start(self): log_system_and_game_info() super(JustCheckersApp, self).on_start() + def build_config(self, config): + config.setdefaults('Theme', {'theme': 'Sunset', 'background': 'Sunset'}) + + def build_settings(self, settings): + # TODO: Add turn options for music and volume. + game_settings = [{ + "type": "options", + "title": "Board Theme", + "section": "Theme", + "key": "theme", + "options": ["Sunset", "Basic"] + }, { + "type": "options", + "title": "Background", + "section": "Theme", + "key": "background", + "options": ["Sunset", "Basic"] + }] + settings.add_json_panel("justCheckers Settings", self.config, data=json.dumps(game_settings)) + def log_system_and_game_info(): """Logs information about the game and system running the game.""" diff --git a/justcheckers/justcheckers.kv b/justcheckers/justcheckers.kv index cde3060..b3bd567 100644 --- a/justcheckers/justcheckers.kv +++ b/justcheckers/justcheckers.kv @@ -11,18 +11,43 @@ ScreenManager: source: 'images/backdrop.jpg' BoxLayout: orientation: "vertical" + Image: + source: 'images/frosted_logo.png' + size_hint_y: 0.5 Label: - text: "justCheckers {} - Main Menu".format(justcheckers.__version__) + text: "Version {}".format(justcheckers.__version__) + size_hint_y: 0.1 Button: text: "New Game" + size_hint_x: 0.9 + size_hint_y: 0.1 on_press: root.manager.transition.direction = 'left' root.manager.current = 'game' Button: - text: "Credits" + text: "Open Game" + disabled: True + size_hint_y: 0.1 + Button: + text: "Save Game" + disabled: True + size_hint_y: 0.1 + Button: + text: "About Game" + size_hint_y: 0.1 on_press: root.manager.transition.direction = 'left' root.manager.current = 'info' + Button: + text: "Settings" + size_hint_y: 0.1 + on_press: + app.open_settings() + Button: + text: "Exit" + size_hint_y: 0.1 + on_press: + app.stop() : diff --git a/justcheckers/ui/menu_view.py b/justcheckers/ui/menu_view.py deleted file mode 100644 index eba3cf9..0000000 --- a/justcheckers/ui/menu_view.py +++ /dev/null @@ -1,93 +0,0 @@ -# -# Copyright (c) 2014 Dorian Pula -# -# justCheckers is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, -# or (at your option) any later version. -# -# justCheckers is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with justCheckers. If not, see . -# -# Please share and enjoy! -# - -from PySide import QtCore -from PySide import QtGui - -from justcheckers.ui import util - - -class MainMenuView(QtGui.QWidget): - """Main menu for the game.""" - - # TODO Setup functional testing with PySide.QtTest - - def __init__(self): - super(MainMenuView, self).__init__() - self.setup_components() - - def setup_components(self): - """Setup the components that make up the widget.""" - self.init_justcheckers_logo() - - self.new_game = self.create_menu_button('&New Game', enabled=True) - self.new_game.clicked.connect(self.switch_to_game_view) - - self.open_game = self.create_menu_button('&Open Game') - self.save_game = self.create_menu_button('&Save Game') - - self.about_game = self.create_menu_button('About Game', enabled=True) - self.about_game.clicked.connect(self.switch_to_about_view) - - self.settings = self.create_menu_button('Settings') - - self.exit_button = self.create_menu_button('Exit', enabled=True) - self.exit_button.clicked.connect(self.exit_app) - - widget_layout = QtGui.QVBoxLayout(self) - widget_layout.addStretch() - widget_layout.addWidget(self.logo_label) - widget_layout.addStretch() - widget_layout.addWidget(self.new_game) - widget_layout.addWidget(self.open_game) - widget_layout.addWidget(self.save_game) - widget_layout.addWidget(self.about_game) - widget_layout.addWidget(self.settings) - widget_layout.addWidget(self.exit_button) - widget_layout.addStretch() - self.setLayout(widget_layout) - - def init_justcheckers_logo(self): - """Initializes and places the logo as a header on top of the menu.""" - logo_pixmap = QtGui.QPixmap(util.path_to_asset('frosted_logo.png')) - view_size = self.size() - logo_pixmap = logo_pixmap.scaledToWidth(view_size.width()) - - self.logo_label = QtGui.QLabel('justCheckers', self) - self.logo_label.setPixmap(logo_pixmap) - self.logo_label.setAlignment(QtCore.Qt.AlignCenter) - - def create_menu_button(self, label, enabled=False): - """Creates a menu button with a consistent look & feel.""" - menu_button = QtGui.QPushButton(label, self) - menu_button.setFixedHeight(50) - menu_button.setEnabled(enabled) - return menu_button - - @staticmethod - def exit_app(): - """Exits the application.""" - QtCore.QCoreApplication.instance().exit() - - # TODO Remove magic numbers - def switch_to_about_view(self): - self.parentWidget().setCurrentIndex(1) - - def switch_to_game_view(self): - self.parentWidget().setCurrentIndex(2)