Build up settings and main menu for justCheckers.
This commit is contained in:
parent
eddfac271a
commit
a36a50464c
|
@ -5,6 +5,7 @@ Main application for justCheckers
|
||||||
:license: GPL v3+
|
:license: GPL v3+
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -21,11 +22,32 @@ LOG = logging.getLogger(__name__)
|
||||||
class JustCheckersApp(App):
|
class JustCheckersApp(App):
|
||||||
title = 'justCheckers'
|
title = 'justCheckers'
|
||||||
icon = 'images/icon.png'
|
icon = 'images/icon.png'
|
||||||
|
use_kivy_settings = False
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
log_system_and_game_info()
|
log_system_and_game_info()
|
||||||
super(JustCheckersApp, self).on_start()
|
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():
|
def log_system_and_game_info():
|
||||||
"""Logs information about the game and system running the game."""
|
"""Logs information about the game and system running the game."""
|
||||||
|
|
|
@ -11,18 +11,43 @@ ScreenManager:
|
||||||
source: 'images/backdrop.jpg'
|
source: 'images/backdrop.jpg'
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
orientation: "vertical"
|
orientation: "vertical"
|
||||||
|
Image:
|
||||||
|
source: 'images/frosted_logo.png'
|
||||||
|
size_hint_y: 0.5
|
||||||
Label:
|
Label:
|
||||||
text: "justCheckers {} - Main Menu".format(justcheckers.__version__)
|
text: "Version {}".format(justcheckers.__version__)
|
||||||
|
size_hint_y: 0.1
|
||||||
Button:
|
Button:
|
||||||
text: "New Game"
|
text: "New Game"
|
||||||
|
size_hint_x: 0.9
|
||||||
|
size_hint_y: 0.1
|
||||||
on_press:
|
on_press:
|
||||||
root.manager.transition.direction = 'left'
|
root.manager.transition.direction = 'left'
|
||||||
root.manager.current = 'game'
|
root.manager.current = 'game'
|
||||||
Button:
|
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:
|
on_press:
|
||||||
root.manager.transition.direction = 'left'
|
root.manager.transition.direction = 'left'
|
||||||
root.manager.current = 'info'
|
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()
|
||||||
|
|
||||||
|
|
||||||
<GameScreen@Screen>:
|
<GameScreen@Screen>:
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
#
|
|
||||||
# Copyright (c) 2014 Dorian Pula <dorian.pula@amber-penguin-software.ca>
|
|
||||||
#
|
|
||||||
# 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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
# 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)
|
|
Loading…
Reference in New Issue