Commit 7a96766f authored by Stas Verberkt's avatar Stas Verberkt
Browse files

Implemented KGameDifficulty, added dialog KGameThemeSelector

svn path=/trunk/playground/games/ktron/; revision=822205
parent fb30d06f
......@@ -5,21 +5,14 @@ find_package(KDE4 REQUIRED)
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
add_definitions (-DQT3_SUPPORT -DQT3_SUPPORT_WARNINGS)
include(KDE4Defaults)
include(MacroLibrary)
#include(ConvenienceLibs.cmake)
#include(ManualStuff.cmake)
#include(ConfigureChecks.cmake)
include_directories(${CMAKE_SOURCE_DIR}/libkdegames ${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} )
add_subdirectory(pics)
add_subdirectory(themes)
########### next target ###############
......@@ -46,30 +39,3 @@ install(TARGETS ktron ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES ktron.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
install(FILES ktron.kcfg DESTINATION ${KCFG_INSTALL_DIR})
install(FILES ktronui.rc DESTINATION ${DATA_INSTALL_DIR}/ktron)
#original Makefile.am contents follow:
#SUBDIRS=pics
#
#bin_PROGRAMS = ktron
#INCLUDES = -I$(top_srcdir)/libkdegames $(all_includes)
#
#ktron_SOURCES = ai.ui appearance.ui general.ui tron.cpp player.cpp ktron.cpp main.cpp settings.kcfgc
#ktron_LDFLAGS = $(all_libraries) $(KDE_RPATH)
#ktron_LDADD = $(LIB_KIO) $(LIB_KDEGAMES)
#ktron_DEPENDENCIES = $(LIB_KDEGAMES_DEP)
#
#EXTRA_DIST = ktron.desktop
#
#xdg_apps_DATA = ktron.desktop
#kde_kcfg_DATA = ktron.kcfg
#
#METASOURCES = AUTO
#
#rcdir = $(kde_datadir)/ktron
#rc_DATA = ktronui.rc
#
#messages: rc.cpp
# $(XGETTEXT) *.cpp -o $(podir)/ktron.pot
......@@ -54,70 +54,6 @@
</layout>
</widget>
</item>
<item row="1" column="2" >
<spacer name="spacer2_2" >
<property name="sizeHint" >
<size>
<width>101</width>
<height>20</height>
</size>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textLabel15" >
<property name="text" >
<string>Intelligence:</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="kcfg_Skill" >
<property name="currentIndex" >
<number>1</number>
</property>
<item>
<property name="text" >
<string>Beginner</string>
</property>
</item>
<item>
<property name="text" >
<string>Average</string>
</property>
</item>
<item>
<property name="text" >
<string>Expert</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1" >
<spacer name="spacer2" >
<property name="sizeHint" >
<size>
<width>20</width>
<height>60</height>
</size>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
......
<ui version="4.0" stdsetdef="1" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>General</class>
<widget class="QWidget" name="General" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>379</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>0</number>
</property>
<ui version="4.0" >
<class>General</class>
<widget class="QWidget" name="General" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>379</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>0</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame4" >
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth" >
<number>0</number>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QFrame" name="frame4" >
<property name="frameShape" >
<enum>StyledPanel</enum>
</property>
<property name="frameShadow" >
<enum>Plain</enum>
</property>
<property name="lineWidth" >
<number>0</number>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBox1" >
<property name="title" >
<string>Behavior</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="kcfg_ChangeWinnerColor" >
<property name="text" >
<string>&amp;Show winner by changing color</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_AcceleratorBlocked" >
<property name="text" >
<string>&amp;Disable acceleration</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_OppositeDirCrashes" >
<property name="text" >
<string>&amp;Crash when moving in the opposite direction</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox2" >
<property name="title" >
<string>Player Names</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="1" >
<widget class="QLineEdit" name="kcfg_NamePlayer1" />
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="kcfg_NamePlayer2" />
</item>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel1" >
<property name="text" >
<string>Player 1:</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textLabel2" >
<property name="text" >
<string>Player 2:</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox3" >
<property name="title" >
<string>Speed</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QSlider" name="kcfg_Velocity" >
<property name="minimum" >
<number>1</number>
</property>
<property name="maximum" >
<number>9</number>
</property>
<property name="pageStep" >
<number>1</number>
</property>
<property name="value" >
<number>5</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition" >
<enum>QSlider::TicksRight</enum>
</property>
<property name="tickInterval" >
<number>1</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="textLabel4" >
<property name="text" >
<string>Slow</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel5" >
<property name="text" >
<string>Default</string>
</property>
<property name="alignment" >
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel6" >
<property name="text" >
<string>Fast</string>
</property>
<property name="alignment" >
<set>Qt::AlignVCenter|Qt::AlignRight</set>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="spacer2" >
<property name="sizeHint" >
<size>
<width>20</width>
<height>21</height>
</size>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox1" >
<property name="title" >
<string>Behavior</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="kcfg_ChangeWinnerColor" >
<property name="text" >
<string>&amp;Show winner by changing color</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_AcceleratorBlocked" >
<property name="text" >
<string>&amp;Disable acceleration</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_OppositeDirCrashes" >
<property name="text" >
<string>&amp;Crash when moving in the opposite direction</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<item>
<widget class="QGroupBox" name="groupBox2" >
<property name="title" >
<string>Player Names</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="1" >
<widget class="QLineEdit" name="kcfg_NamePlayer1" />
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="kcfg_NamePlayer2" />
</item>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel1" >
<property name="text" >
<string>Player 1:</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textLabel2" >
<property name="text" >
<string>Player 2:</string>
</property>
<property name="wordWrap" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<resources/>
<connections/>
</ui>
......@@ -23,15 +23,17 @@
#include "ktron.h"
#include <kconfigdialog.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <kstandardgameaction.h>
#include <kapplication.h>
#include <kstatusbar.h>
#include <ktoggleaction.h>
#include <KConfigDialog>
#include <KLocale>
#include <KMessageBox>
#include <KAction>
#include <KActionCollection>
#include <KStandardGameAction>
#include <KApplication>
#include <KStatusBar>
#include <KToggleAction>
#include <KGameThemeSelector>
#include <KGameDifficulty>
// Settings
#include "settings.h"
......@@ -148,11 +150,27 @@ KTron::KTron(QWidget *parent) : KXmlGuiWindow(parent, KDE_DEFAULT_WINDOWFLAGS) {
actionCollection()->addAction(act->objectName(), act);
act = KStandardGameAction::gameNew(tron, SLOT( newGame() ), this);
actionCollection()->addAction(act->objectName(), act);
act = KStandardGameAction::quit(this, SLOT( close() ), this);
act = KStandardGameAction::quit(kapp, SLOT(quit()), this);
actionCollection()->addAction(act->objectName(), act);
act = KStandardAction::preferences(this, SLOT(showSettings()), this);
actionCollection()->addAction(act->objectName(), act);
//difficulty
KGameDifficulty::init(this, tron, SLOT(loadSettings()));
KGameDifficulty::addStandardLevel(KGameDifficulty::VeryEasy);
KGameDifficulty::addStandardLevel(KGameDifficulty::Easy);
KGameDifficulty::addStandardLevel(KGameDifficulty::Medium);
KGameDifficulty::addStandardLevel(KGameDifficulty::Hard);
KGameDifficulty::addStandardLevel(KGameDifficulty::VeryHard);
int skill = Settings::difficulty();
if (skill < (int)KGameDifficulty::VeryEasy || skill > (int)KGameDifficulty::VeryHard) {
KGameDifficulty::setLevel(KGameDifficulty::Easy);
Settings::setDifficulty((int) KGameDifficulty::Easy);
}
else {
KGameDifficulty::setLevel((KGameDifficulty::standardLevel) (skill));
}
setupGUI( KXmlGuiWindow::Keys | StatusBar | Save | Create);
loadSettings();
}
......@@ -226,7 +244,7 @@ void KTron::showWinner(Player winner){
winnerName = playerName[winner];
QString message=i18n("%1 has won!", winnerName);
statusBar()->message(message,MESSAGE_TIME);
statusBar()->showMessage(message);
message = i18n("%1 has won versus %2 with %3 : %4 points!", winnerName, loserName, playerPoints[winner], playerPoints[loser]);
......@@ -251,10 +269,24 @@ void KTron::showSettings(){
dialog->addPage(new General, i18n("General"), "package_settings");
dialog->addPage(new Ai, i18n("A.I."), "personal");
dialog->addPage(new Appearance, i18n("Appearance"), "preferences-desktop-theme-style");
dialog->addPage(new KGameThemeSelector(dialog, Settings::self(), KGameThemeSelector::NewStuffDisableDownload), i18n("Theme"), "games-config-theme");
connect(dialog, SIGNAL(settingsChanged(const QString &)), tron, SLOT(loadSettings()));
connect(dialog, SIGNAL(settingsChanged(const QString &)), this, SLOT(loadSettings()));
dialog->show();
}
/**
* Close KTron
*/
void KTron::close() {
Settings::self()->writeConfig();
}
void KTron::closeEvent(QCloseEvent *event)
{
close();
event->accept();
}
#include "ktron.moc"
......@@ -52,6 +52,10 @@ private:
protected:
/** calls tron->updatePixmap to draw frame in the new colors */
void paletteChange(const QPalette &oldPalette);
virtual void closeEvent(QCloseEvent *);
public slots:
void close();
private slots:
void loadSettings();
......
......@@ -4,6 +4,12 @@
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="ktronrc"/>
<group name="General">
<entry name="Theme" type="String">
<label>The graphical theme to be used.</label>
<default>themes/default.desktop</default>
</entry>
</group>
<group name="Game">
<entry name="Color_Background" type="Color">
<label>The background color of the game.</label>
......@@ -33,19 +39,9 @@
<label>The width of the line.</label>
<default>10</default>
</entry>
<entry name="Velocity" type="Int">
<label>The speed of the line.</label>
<default>5</default>
</entry>
<entry name="Skill" type="Enum">
<label>The skill of the computer player.</label>
<choices>
<choice name="Easy"/>
<choice name="Medium"/>
<choice name="Hard"/>
</choices>
<default>Medium</default>
<entry name="Difficulty" type="Int">
<label>The difficulty level.</label>
<default>30</default>
</entry>
<entry name="Style" type="Enum">
<label>The line style.</label>
......
......@@ -20,10 +20,11 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
****************************************************************************/
#include <kapplication.h>
#include <kimageio.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <KApplication>
#include <KImageIO>
#include <KCmdLineArgs>
#include <KAboutData>
#include <KStandardDirs>
#include "ktron.h"
#include "version.h"
......@@ -45,18 +46,12 @@ int main(int argc, char* argv[])
KApplication a;
KGlobal::locale()->insertCatalog("libkdegames");
// used for loading background pixmaps
KStandardDirs::locateLocal("appdata", "themes/");
KTron *ktron = new KTron();
ktron->show();
if(a.isSessionRestored()){
RESTORE(KTron)
}
else {
KTron *ktron = new KTron();
a.setMainWidget(ktron);
ktron->show();
}
return a.exec();
}
......@@ -2,4 +2,4 @@
File=ktron.kcfg
ClassName=Settings
Singleton=true
Mutators=false
Mutators=true
set(ktron_THEME_SRCS
default.desktop
)
install(FILES ${ktron_THEME_SRCS} DESTINATION ${DATA_INSTALL_DIR}/ktron/themes)
[KGameTheme]
VersionFormat=1
Name=KTron Default Theme
Name[el]=Προκαθορισμένο θέμα KTron
Name[es]=Tema predeterminado para KTron
Name[fa]=چهره پیش‌فرض جواهرات
Name[ga]=Téama Réamhshocraithe KTron
Name[gl]=Tema por omisión de KTron
Name[ja]=KTron 標準テーマ
Name[km]=ស្បែក​លំនាំដើម​របស់ KTrons
Name[lv]=KTron noklusējuma tēma
Name[nds]=KTron-Standardmuster
Name[pt]=Tema Predefinido do KTron
Name[pt_BR]=Tema padrão do KDiamante
Name[sv]=Kdiamant standardtema
Name[tr]=KTron Öntanımlı Teması
Name[uk]=Типова тема КДіаманта
Name[x-test]=xxKTron Default Themexx
Name[zh_CN]=KTron 默认主题
Name[zh_TW]=KTrons 預設主題
Description=Default theme for KTron.
Description[el]=Προκαθορισμένο θέμα για το KTron.
Description[es]=Tema predeterminado para KTron
Description[fa]=چهره پیش‌فرض برای جواهرات
Description[fi]=Oletusteema KTrons-pelille.
Description[ga]=Téama réamhshocraithe le haghaidh KTron.
Description[gl]=O tema predeterminado de KTron.
Description[ja]=KTron の標準テーマ
Description[km]=ស្បែក​លំនាំដើម​សម្រាប់ KTron ។
Description[lv]=KTron noklusējuma tēma priekš KDE4.
Description[nds]=Standardmuster för KTron
Description[pt]=O tema predefinido do KTron.
Description[pt_BR]=Tema padrão do KDiamante para o KDE4
Description[sv]=Standardtema för Kdiamant.
Description[tr]=KTron için öntanımlı tema.
Description[uk]=Типова тема КДіамантів.
Description[x-test]=xxDefault theme for KTron.xx
Description[zh_CN]=为 KTron 设计的默认主题。