summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/kpacman/kpacman.cpp4
-rw-r--r--noncore/games/kpacman/kpacmanwidget.cpp5
-rw-r--r--noncore/games/kpacman/portable.h5
-rw-r--r--noncore/games/kpacman/status.cpp1
4 files changed, 8 insertions, 7 deletions
diff --git a/noncore/games/kpacman/kpacman.cpp b/noncore/games/kpacman/kpacman.cpp
index d9d2d69..aee8eea 100644
--- a/noncore/games/kpacman/kpacman.cpp
+++ b/noncore/games/kpacman/kpacman.cpp
@@ -22,213 +22,213 @@ Kpacman::Kpacman(QWidget *parent, const char *name)
: KTMainWindow(parent, name)
{
schemesPopup = new QList<QPopupMenu>;
schemesPopup->setAutoDelete(TRUE);
menu();
m_view = new QWidget( this, "m_view" );
m_view->setBackgroundColor( black );
m_layout = new QGridLayout( m_view );
m_layout->setMargin( 7 );
view = new KpacmanWidget( this, QString(name)+"widget");
m_layout->addWidget( view, 0, 0 );
setCaption( "KPacman" );
view->referee->setFocus();
connect(view->referee, SIGNAL(setScore(int, int)),
view->score, SLOT(setScore(int, int)));
connect(view->referee, SIGNAL(setPoints(int)),
view->score, SLOT(set(int)));
connect(view->referee, SIGNAL(setLifes(int)),
view->status, SLOT(setLifes(int)));
connect(view->referee, SIGNAL(setLevel(int)),
view->status, SLOT(setLevel(int)));
connect(view->referee, SIGNAL(forcedHallOfFame(bool)),
this, SLOT(forcedHallOfFame(bool)));
connect(view->referee, SIGNAL(togglePaused()), this, SLOT(togglePaused()));
connect(view->referee, SIGNAL(toggleNew()), this, SLOT(toggleNew()));
connect(view->score, SIGNAL(toggleNew()), this, SLOT(toggleNew()));
connect(view->score, SIGNAL(forcedHallOfFame(bool)),
this, SLOT(forcedHallOfFame(bool)));
APP_CONFIG_BEGIN( cfg );
focusOutPause = !cfg->readBoolEntry("FocusOutPause", TRUE);
focusInContinue = !cfg->readBoolEntry("FocusInContinue", TRUE);
hideMouseCursor = !cfg->readBoolEntry("HideMouseCursor", TRUE);
APP_CONFIG_END( cfg );
toggleFocusOutPause();
toggleFocusInContinue();
toggleHideMouseCursor();
setCentralWidget( m_view );
}
Kpacman::~Kpacman()
{
APP_CONFIG_BEGIN( cfg );
cfg->writeEntry("FocusOutPause", focusOutPause);
cfg->writeEntry("FocusInContinue", focusInContinue);
cfg->writeEntry("HideMouseCursor", hideMouseCursor);
APP_CONFIG_END( cfg );
delete _menuBar;
}
void Kpacman::menu()
{
gamePopup = new QPopupMenu();
CHECK_PTR( gamePopup );
newID = gamePopup->insertItem(tr("&New"), this, SLOT(newKpacman()),Key_F2);
pauseID = gamePopup->insertItem(tr("&Pause"),
this, SLOT(pauseKpacman()), Key_F3);
hofID = gamePopup->insertItem(tr("&Hall of fame"),
this, SLOT(toggleHallOfFame()), Key_F4);
gamePopup->insertSeparator();
gamePopup->insertItem(tr("&Quit"), this, SLOT(quitKpacman()), CTRL+Key_Q);
gamePopup->setCheckable(TRUE);
optionsPopup = new QPopupMenu();
CHECK_PTR(optionsPopup);
modesPopup = new QPopupMenu();
CHECK_PTR(modesPopup);
hideMouseCursorID = optionsPopup->insertItem(tr("&Hide Mousecursor"),
this, SLOT(toggleHideMouseCursor()),
CTRL+Key_H);
optionsPopup->insertSeparator();
if (lookupSchemes() > 0) {
optionsPopup->insertItem(tr("&Select graphic scheme"), modesPopup);
optionsPopup->insertSeparator();
}
focusOutPauseID = optionsPopup->insertItem(tr("&Pause in Background"),
this, SLOT(toggleFocusOutPause()));
focusInContinueID = optionsPopup->insertItem(tr("&Continue in Foreground"),
this, SLOT(toggleFocusInContinue()));
optionsPopup->insertSeparator();
optionsPopup->insertItem(tr("Change &keys..."), this, SLOT(confKeys()));
-#ifndef QWS
+#ifndef QPE_PORT
QString aboutText = tr("@PACKAGE@ - @VERSION@\n\n"
"Joerg Thoennissen (joe@dsite.de)\n\n"
"A pacman game for the KDE Desktop\n\n"
"The program based on the source of ksnake\n"
"by Michel Filippi (mfilippi@sade.rhein-main.de).\n"
"The design was strongly influenced by the pacman\n"
"(c) 1980 MIDWAY MFG.CO.\n\n"
"I like to thank my girlfriend Elke Krueers for\n"
"the last 10 years of her friendship.\n");
aboutText.replace(QRegExp("@PACKAGE@"), PACKAGE);
aboutText.replace(QRegExp("@VERSION@"), VERSION);
QPopupMenu *helpPopup = helpMenu(aboutText, FALSE);
#endif
//_menuBar = new KMenuBar(this);
//CHECK_PTR( _menuBar );
//_menuBar->insertItem(tr("&Game"), gamePopup);
//_menuBar->insertItem(tr("&Options"), optionsPopup);
//_menuBar->insertSeparator();
-#ifndef QWS
+#ifndef QPE_PORT
_menuBar->insertItem(tr("&Help"), helpPopup);
#endif
}
int Kpacman::lookupSchemes()
{
APP_CONFIG_BEGIN( cfg );
int ModeCount = cfg->readNumEntry("ModeCount", -1);
int Mode = cfg->readNumEntry("Mode", -1);
int SchemeCount = cfg->readNumEntry("SchemeCount");
int Scheme = cfg->readNumEntry("Scheme", -1);
if (SchemeCount == 0 || Scheme == -1) {
QMessageBox::warning(this, tr("Configuration Error"),
tr("There are no schemes defined,\n"
"or no scheme is selected."));
APP_CONFIG_END( cfg );
return 0;
}
connect(modesPopup, SIGNAL(activated(int)), this, SLOT(schemeChecked(int)));
modeID.resize(ModeCount > 0 ? ModeCount : 0);
if (!schemesPopup->isEmpty())
schemesPopup->clear();
SAVE_CONFIG_GROUP( cfg, oldgroup );
QString ModeGroup;
QString ModeName;
for (int m = 0; m < ModeCount; m++) {
ModeGroup.sprintf("Mode %d", m);
cfg->setGroup(ModeGroup);
ModeName = cfg->readEntry("Description", ModeGroup);
QPopupMenu *p = new QPopupMenu;
p->setCheckable(TRUE);
connect(p, SIGNAL(activated(int)), this, SLOT(schemeChecked(int)));
schemesPopup->append(p);
modeID[m] = modesPopup->insertItem(ModeName, schemesPopup->at(m));
modesPopup->setItemEnabled(modeID[m], FALSE);
modesPopup->setItemChecked(modeID[m], m == Mode);
}
schemeID.resize(SchemeCount);
schemeMode.resize(SchemeCount);
QString SchemeGroup;
QString SchemeName;
int SchemeMode;
for (int i = 0; i < SchemeCount; i++) {
SchemeGroup.sprintf("Scheme %d", i);
cfg->setGroup(SchemeGroup);
SchemeName = cfg->readEntry("Description", SchemeGroup);
SchemeMode = cfg->readNumEntry("Mode", -1);
schemeMode[i] = SchemeMode;
if (SchemeMode == -1) {
schemeID[i] = modesPopup->insertItem(SchemeName);
modesPopup->setItemChecked(schemeID[i], i == Scheme);
} else {
schemeID[i] = schemesPopup->at(SchemeMode)->insertItem(SchemeName);
schemesPopup->at(SchemeMode)->
setItemChecked(schemeID[i], i == Scheme);
modesPopup->setItemEnabled(modeID[SchemeMode], TRUE);
}
}
RESTORE_CONFIG_GROUP( cfg, oldgroup );
APP_CONFIG_END( cfg );
return SchemeCount;
}
void Kpacman::quitKpacman()
{
APP_QUIT();
}
void Kpacman::newKpacman()
{
if (!gamePopup->isItemEnabled(hofID))
gamePopup->setItemEnabled(hofID, TRUE);
if (gamePopup->isItemChecked(hofID))
toggleHallOfFame();
if (gamePopup->isItemChecked(pauseID))
pauseKpacman();
view->referee->play();
diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp
index feb782c..cf2aed9 100644
--- a/noncore/games/kpacman/kpacmanwidget.cpp
+++ b/noncore/games/kpacman/kpacmanwidget.cpp
@@ -1,153 +1,158 @@
#include "portable.h"
#if defined( KDE2_PORT )
#include <kapp.h>
#include <kconfig.h>
#include <kstddirs.h>
#include <kpacmanwidget.h>
#include <kpacmanwidget.moc>
#elif defined( QPE_PORT )
#include <qpe/qpeapplication.h>
#include "config.h"
#include "kpacmanwidget.h"
#endif
#include <qmessagebox.h>
#include "bitfont.h"
#include "score.h"
#include "referee.h"
#include "status.h"
KpacmanWidget::KpacmanWidget( QWidget *parent, const char *name)
: QWidget( parent, name )
{
+ score = 0l;
+ referee = 0l;
+ status = 0l;
bitfont = NULL;
fontName = "";
scheme = mode = -1;
confScheme();
score = new Score(this, name, scheme, mode, bitfont);
referee = new Referee( this, name, scheme, mode, bitfont);
status = new Status(this, name, scheme, mode);
setBackgroundColor( black );
}
KpacmanWidget::~KpacmanWidget()
{
}
void KpacmanWidget::confMisc(bool defGroup)
{
APP_CONFIG_BEGIN( cfg );
//KStandardDirs *dirs = KGlobal::dirs();
QString findPath;
if (defGroup || cfg->hasKey("Font")) {
fontName = cfg->readEntry("Font");
if (fontName.left(1) != "/" && fontName.left(1) != "~")
fontName.insert(0, "fonts/");
if (fontName.right(1) == "/")
fontName.append("font.xbm");
//findPath = dirs->findResource("appdata", fontName);
findPath = FIND_APP_DATA( fontName );
if (!findPath.isEmpty())
fontName = findPath;
bitfontFirstChar = cfg->readNumEntry("FontFirstChar", 0x0e);
bitfontLastChar = cfg->readNumEntry("FontLastChar", 0x5f);
}
APP_CONFIG_END( cfg );
}
void KpacmanWidget::confScheme()
{
APP_CONFIG_BEGIN( cfg );
QString lastFontName = fontName;
SAVE_CONFIG_GROUP( cfg, oldgroup );
QString newgroup;
// if not set, read mode and scheme from the configfile
if (mode == -1 && scheme == -1) {
scheme = cfg->readNumEntry("Scheme", -1);
mode = cfg->readNumEntry("Mode", -1);
// if mode is not set in the defGroup-group, lookup the scheme group
if (scheme != -1 || mode == -1) {
newgroup.sprintf("Scheme %d", scheme);
cfg->setGroup(newgroup);
mode = cfg->readNumEntry("Mode", -1);
RESTORE_CONFIG_GROUP( cfg, oldgroup );
}
}
confMisc();
if (mode != -1) {
newgroup.sprintf("Mode %d", mode);
cfg->setGroup(newgroup);
confMisc(FALSE);
}
if (scheme != -1) {
newgroup.sprintf("Scheme %d", scheme);
cfg->setGroup(newgroup);
confMisc(FALSE);
}
if (lastFontName != fontName) {
if (bitfont != 0)
delete bitfont;
bitfont = new Bitfont(fontName, bitfontFirstChar, bitfontLastChar);
if (bitfont->width() == 0 || bitfont->height() == 0) {
QString msg = tr("The bitfont could not be contructed.\n\n"
"The file '@FONTNAME@' does not exist,\n"
"or is of an unknown format.");
msg.replace(QRegExp("@FONTNAME@"), fontName);
// QMessageBox::critical(this, tr("Initialization Error"), msg);
printf("%s\n", msg.data());
}
}
RESTORE_CONFIG_GROUP( cfg, oldgroup );
APP_CONFIG_END( cfg );
}
void KpacmanWidget::setScheme(int Scheme, int Mode)
{
mode = Mode;
scheme = Scheme;
confScheme();
score->setScheme(Scheme, Mode, bitfont);
referee->setScheme(Scheme, Mode, bitfont);
status->setScheme(Scheme, Mode);
score->repaint(FALSE);
referee->repaint(FALSE);
status->repaint(FALSE);
}
void KpacmanWidget::resizeEvent( QResizeEvent * )
{
+ qWarning("Resize");
referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height());
referee->setBackgroundColor(BLACK);
+ if(!status ) return;
status->setGeometry(0, bitfont->height()*3+referee->height(), referee->width(),
status->height());
status->setBackgroundColor(BLACK);
score->setGeometry(0, 0, referee->width(), bitfont->height()*3+referee->height()+status->height());
score->setBackgroundColor(BLACK);
}
diff --git a/noncore/games/kpacman/portable.h b/noncore/games/kpacman/portable.h
index ff0912b..b087be5 100644
--- a/noncore/games/kpacman/portable.h
+++ b/noncore/games/kpacman/portable.h
@@ -1,63 +1,58 @@
/***************************************************************************
portable.h - various bits that ease porting kpacman to other platforms.
Currently KDE2 and Qtopia ports exist.
-------------------
begin : Mon Mar 18 12:35:24 EET 2002
copyright : (C) 2002 by Catalin Climov
email : catalin@climov.com
***************************************************************************/
/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef PORTABLE_H
#define PORTABLE_H
-#ifdef QWS
#define QPE_PORT
-#else
-#define KDE2_PORT
-#define KDE_PORT
-#endif
#if defined( KDE2_PORT )
#define APP kapp
#define APP_CONFIG_BEGIN( cfgname ) KConfig cfgname = kapp->config()
#define APP_CONFIG_END( cfgname ) cfgname->sync()
#define SAVE_CONFIG_GROUP( cfgname, groupname ) QString groupname = configname->group()
#define RESTORE_CONFIG_GROUP( cfgname, groupname ) configname->setGroup( groupname )
#define FIND_APP_DATA( dataname ) KGlobal::dirs()->findResource( "appdata", dataname )
#elif defined( QPE_PORT )
#define i18n( x ) x
#define KTMainWindow QMainWindow
#define KMenuBar QMenuBar
#define KAccel QAccel
#define APP qApp
#define APP_CONFIG_BEGIN( cfgname ) Config* cfgname = new Config("kpacman"); cfgname->setGroup("Default");
#define APP_CONFIG_END( cfgname ) delete cfgname
#define SAVE_CONFIG_GROUP( cfgname, groupname )
#define RESTORE_CONFIG_GROUP( cfgname, groupname ) cfgname->setGroup("Default")
#define FIND_APP_DATA( dataname ) (QPEApplication::qpeDir()+"share/kpacman/"+dataname)
#else
#error "Err, I don't know what platform to compile for (KDE2 or Qtopia)"
#endif
#define APP_QUIT() APP->quit()
#endif // PORTABLE_H
diff --git a/noncore/games/kpacman/status.cpp b/noncore/games/kpacman/status.cpp
index 3453d37..1ef910d 100644
--- a/noncore/games/kpacman/status.cpp
+++ b/noncore/games/kpacman/status.cpp
@@ -1,120 +1,121 @@
#include "portable.h"
#if defined( KDE2_PORT )
#include <kapp.h>
#include <klocale.h>
#include <kstddirs.h>
#include <status.h>
#include <status.moc>
#elif defined( QPE_PORT )
#include <qpe/qpeapplication.h>
#include "config.h"
#include "status.h"
#endif
#include <qpixmap.h>
#include <qbitmap.h>
#include <qstring.h>
#include <qmsgbox.h>
#include <qfileinfo.h>
Status::Status( QWidget *parent, const char *name, int Scheme, int Mode ) :
QWidget( parent, name )
{
+ qWarning("Status::Status");
actualLifes = 0;
actualLevel = 0;
lifesPix = NULL;
levelPix = NULL;
scheme = Scheme;
mode = Mode;
level = 0;
confScheme();
}
QList<QPixmap> *Status::loadPixmap(QWidget *parent, QString pixmapName,
QList<QPixmap> *pixmaps)
{
if (pixmaps == NULL) {
pixmaps = new QList<QPixmap>;
pixmaps->setAutoDelete(TRUE);
}
if (!pixmaps->isEmpty())
pixmaps->clear();
QPixmap PIXMAP(pixmapName);
if (PIXMAP.isNull() || PIXMAP.mask() == NULL) {
QString msg = tr("The pixmap could not be contructed.\n\n"
"The file '@PIXMAPNAME@' does not exist,\n"
"or is of an unknown format.");
msg.replace(QRegExp("@PIXMAPNAME@"), pixmapName);
QMessageBox::information(parent, tr("Initialization Error"),
(const char *) msg);
return 0;
}
int height = PIXMAP.height();
int width = (height == 0) ? 0 : PIXMAP.width()/(PIXMAP.width()/height);
QBitmap BITMAP;
QBitmap MASK;
BITMAP = *PIXMAP.mask();
MASK.resize(width, height);
for (int x = 0; x < PIXMAP.width()/width; x++) {
QPixmap *pixmap = new QPixmap(width, height);
pixmaps->append(pixmap);
bitBlt(pixmap, 0, 0, &PIXMAP, x*width, 0, width, height, CopyROP, TRUE);
bitBlt(&MASK, 0, 0, &BITMAP, x*width, 0, width, height, CopyROP, TRUE);
pixmap->setMask(MASK);
}
return pixmaps;
}
void Status::paintEvent( QPaintEvent *)
{
for (int x = 0; x < actualLifes && !lifesPix->isEmpty(); x++)
bitBlt(this, lifesPix->at(0)->width()+(lifesPix->at(0)->width()*x),
(height()-lifesPix->at(0)->height())/2,
lifesPix->at(0), 0, 0,
lifesPix->at(0)->width(), lifesPix->at(0)->height());
for (int x = 0; x < actualLevel && !levelPix->isEmpty(); x++) {
erase((width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]),
(height()-levelPix->at(x)->height())/2,
levelPix->at(x)->width(), levelPix->at(x)->height());
bitBlt(this, (width()-levelPix->at(x)->width()*2)-(levelPix->at(x)->width()*levelPos[x]),
(height()-levelPix->at(x)->height())/2,
levelPix->at(x), 0, 0,
levelPix->at(x)->width(), levelPix->at(x)->height());
}
}
void Status::initPixmaps()
{
if (lastLifesPixmapName != lifesPixmapName.at(level)) {
lifesPix = loadPixmap(this, lifesPixmapName.at(level), lifesPix);
lastLifesPixmapName = lifesPixmapName.at(level);
}
if (lastLevelPixmapName != levelPixmapName.at(level)) {
levelPix = loadPixmap(this, levelPixmapName.at(level), levelPix);
lastLevelPixmapName = levelPixmapName.at(level);
}
}
QString Status::decodeHexOctString(QString s)
{
QString value;
QString valids;
int pos, xpos = 0, opos = 0;
int v, len, leadin;
const char *ptr;
uchar c;
while (((xpos = s.find(QRegExp("\\\\x[0-9a-fA-F]+"), xpos)) != -1) ||