diff --git a/justcheckers/ui/InfoActivity.java b/justcheckers/ui/InfoActivity.java deleted file mode 100644 index 106be39..0000000 --- a/justcheckers/ui/InfoActivity.java +++ /dev/null @@ -1,104 +0,0 @@ -/***************************************************************************** - InfoActivity.java - The activity that provides built-in information. - ***************************************************************************** - - ***************************************************************************** - This file is part of justCheckers. - - 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 . - *****************************************************************************/ - -package org.justcheckers.android; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.justcheckers.common.GlobalConstants; - -import android.app.Activity; -import android.os.Bundle; -import android.util.Log; -import android.widget.TextView; - -public class InfoActivity extends Activity { - - private int flagInformationToDisplay; - - //TODO: Clean this up into something more modularized. - @Override - protected void onCreate(Bundle savedInstanceState) { - - super.onCreate(savedInstanceState); - - // Setup the user interface for the main menu. - this.setContentView(R.layout.info_screen); - - // Figure out which text to load. The default - if (savedInstanceState != null) { - this.flagInformationToDisplay = - savedInstanceState.getInt(GlobalConstants.EXTRA_INFORMATION_DISPLAY_FLAG); - - } else { - Bundle extras = this.getIntent().getExtras(); - if (extras != null) { - this.flagInformationToDisplay = - extras.getInt(GlobalConstants.EXTRA_INFORMATION_DISPLAY_FLAG); - } - } - - // Load the right text. - int rawInfoRes = 0; - if (this.flagInformationToDisplay == GlobalConstants.FLAG_INFORMATION_DISPLAY_ABOUT_US) { - rawInfoRes = R.raw.readme; - } else if (this.flagInformationToDisplay == GlobalConstants.FLAG_INFORMATION_DISPLAY_LICENSE) { - rawInfoRes = R.raw.gpl_3_license; - } else { - rawInfoRes = R.raw.readme; - } - - // Read the raw document into a string. - InputStream docInfoStream = this.getResources().openRawResource(rawInfoRes); - BufferedReader reader = new BufferedReader(new InputStreamReader(docInfoStream)); - String result = "Text here"; - - try { - // Gather all the data. - StringBuilder buildDoc = new StringBuilder(); - String docLine = reader.readLine(); - - while (docLine != null) { - buildDoc.append(docLine + "\n"); - docLine = reader.readLine(); - } - - result = buildDoc.toString(); - - } catch (IOException e) { - Log.e("InfoActivity", "Input error: " + e.getMessage()); - } - - TextView infoText = (TextView) this.findViewById(R.id.info_text); - infoText.setText(result); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putInt(GlobalConstants.EXTRA_INFORMATION_DISPLAY_FLAG, - this.flagInformationToDisplay); - } - -} diff --git a/justcheckers/ui/info_screen.xml b/justcheckers/ui/info_screen.xml deleted file mode 100644 index a8e3561..0000000 --- a/justcheckers/ui/info_screen.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/justcheckers/ui/info_view.py b/justcheckers/ui/info_view.py new file mode 100644 index 0000000..cc10068 --- /dev/null +++ b/justcheckers/ui/info_view.py @@ -0,0 +1,84 @@ +# +# 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! +# + +import codecs + +import markdown +from PySide import QtGui +from PySide import QtWebKit + +from justcheckers.ui import util + + +class InfoView(QtGui.QWidget): + """Info viewer for the game's license, etc.""" + + # TODO Setup functional testing with PySide.QtTest + + def __init__(self): + super(InfoView, self).__init__() + self.setup_components() + + def setup_components(self): + + self.info_viewer = QtWebKit.QWebView(self) + about_html = self.generate_html_from_markdown('readme.txt') + self.info_viewer.setHtml(about_html) + + exit_button = QtGui.QPushButton('Back to Menu', self) + exit_button.setFixedHeight(50) + exit_button.clicked.connect(self.switch_to_menu_view) + + credits_button = QtGui.QPushButton('Credits', self) + credits_button.setFixedHeight(50) + credits_button.clicked.connect(self.display_about_info) + + license_button = QtGui.QPushButton('License', self) + license_button.setFixedHeight(50) + license_button.clicked.connect(self.display_license_info) + + widget_layout = QtGui.QVBoxLayout(self) + widget_layout.addWidget(self.info_viewer) + + button_row = QtGui.QHBoxLayout(self) + button_row.addWidget(exit_button) + button_row.addWidget(credits_button) + button_row.addWidget(license_button) + + widget_layout.addLayout(button_row) + + self.setLayout(widget_layout) + + def switch_to_menu_view(self): + self.parentWidget().setCurrentIndex(0) + + def display_about_info(self): + about_html = self.generate_html_from_markdown('readme.txt') + self.info_viewer.setHtml(about_html) + + def display_license_info(self): + license_html = self.generate_html_from_markdown('gpl_3_license.txt') + self.info_viewer.setHtml(license_html) + + def generate_html_from_markdown(self, filename): + file_path = util.path_to_asset(filename, asset_type=util.TEXT_ASSETS) + with codecs.open(file_path, mode='r', encoding='utf-8') as markdown_file: + text = markdown_file.read() + return markdown.markdown(text) + diff --git a/justcheckers/ui/menu_view.py b/justcheckers/ui/menu_view.py index 8a5babf..e55aa59 100644 --- a/justcheckers/ui/menu_view.py +++ b/justcheckers/ui/menu_view.py @@ -40,7 +40,9 @@ class MainMenuView(QtGui.QWidget): 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') + self.about_game = self.create_menu_button('About Game', enabled=True) + self.about_game.clicked.connect(self.switch_to_about_view) + # TODO Add links to site and display license inside about game widget. self.settings = self.create_menu_button('Settings') self.exit_button = self.create_menu_button('Exit', enabled=True) @@ -80,3 +82,6 @@ class MainMenuView(QtGui.QWidget): def exit_app(): """Exits the application.""" QtCore.QCoreApplication.instance().exit() + + def switch_to_about_view(self): + self.parentWidget().setCurrentIndex(1) diff --git a/justcheckers/ui/strings.xml b/justcheckers/ui/strings.xml deleted file mode 100644 index ae56be5..0000000 --- a/justcheckers/ui/strings.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - justCheckers - 0.2-alpha - http://justcheckers.org/ - - American/Standard - European - Canadian - - diff --git a/justcheckers/ui/window.py b/justcheckers/ui/window.py index 66fdb0b..883e267 100644 --- a/justcheckers/ui/window.py +++ b/justcheckers/ui/window.py @@ -20,6 +20,7 @@ from PySide import QtGui +from justcheckers.ui.info_view import InfoView from justcheckers.ui.menu_view import MainMenuView from justcheckers.ui import util @@ -48,6 +49,7 @@ class DesktopGameWindow(QtGui.QMainWindow): """Setup the components that make up the widget.""" self.view_stack = QtGui.QStackedWidget() self.view_stack.addWidget(MainMenuView()) + self.view_stack.addWidget(InfoView()) self.setCentralWidget(self.view_stack) def center(self): diff --git a/requirements.txt b/requirements.txt index ab89713..aa30fc3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ # User interface PySide==1.2.2 +Markdown==2.4.1 # Core logic enum34==0.9.19