-rw-r--r-- | noncore/games/kpacman/kpacman.cpp | 23 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacman.h | 18 | ||||
-rw-r--r-- | noncore/games/kpacman/kpacmanwidget.cpp | 9 | ||||
-rw-r--r-- | noncore/games/kpacman/referee.cpp | 4 | ||||
-rw-r--r-- | noncore/games/kpacman/score.cpp | 61 |
5 files changed, 14 insertions, 101 deletions
diff --git a/noncore/games/kpacman/kpacman.cpp b/noncore/games/kpacman/kpacman.cpp index 7df6ef0..d9d2d69 100644 --- a/noncore/games/kpacman/kpacman.cpp +++ b/noncore/games/kpacman/kpacman.cpp @@ -1,121 +1,116 @@ #include "portable.h" #if defined( KDE2_PORT ) #include <kpacman.h> #include <kpacman.moc> #include <kcolordlg.h> #elif defined( QPE_PORT ) #include <qmenubar.h> #include "config.h" #include <qapplication.h> #include "kpacman.h" #endif #include <qkeycode.h> #include <qcolor.h> #include <qstring.h> #include <qpopmenu.h> #include <qmsgbox.h> Kpacman::Kpacman(QWidget *parent, const char *name) : KTMainWindow(parent, name) { schemesPopup = new QList<QPopupMenu>; schemesPopup->setAutoDelete(TRUE); menu(); - view = new KpacmanWidget( this, QString(name)+"widget"); + m_view = new QWidget( this, "m_view" ); + m_view->setBackgroundColor( black ); + m_layout = new QGridLayout( m_view ); + m_layout->setMargin( 7 ); -#ifndef QWS - setFixedSize(view->width(), view->height()); -#else - setCaption( "Kpacman" ); -#endif + 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(); -#ifndef QWS - menuBar->show(); - view->show(); - setMenu(menuBar); - setView(view); -#else - setCentralWidget( view ); -#endif + 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())); diff --git a/noncore/games/kpacman/kpacman.h b/noncore/games/kpacman/kpacman.h index d7de9de..2c1de70 100644 --- a/noncore/games/kpacman/kpacman.h +++ b/noncore/games/kpacman/kpacman.h @@ -1,95 +1,83 @@ #ifndef KPACMAN_H #define KPACMAN_H #ifdef HAVE_CONFIG_H #include <config.h> #endif #include "portable.h" -#if defined( KDE2_PORT ) -#include <kapp.h> -#include <klocale.h> -#include <ktmainwindow.h> -#include <kmenubar.h> -#elif defined( QPE_PORT ) #include <qmainwindow.h> class QMenuBar; -#endif - #include <qregexp.h> #include "kpacmanwidget.h" #include <qpopmenu.h> #include <qlist.h> #include <qfileinf.h> +#include <qlayout.h> -#if defined( KDE2_PORT ) -#include <referee.h> -#include <status.h> -#include <score.h> -#include <keys.h> -#elif defined( QPE_PORT ) #include "referee.h" #include "status.h" #include "score.h" #include "keys.h" -#endif class Kpacman : public KTMainWindow { Q_OBJECT public: Kpacman(QWidget *parent = 0, const char *name = 0); virtual ~Kpacman(); public slots: void forcedHallOfFame(bool); private slots: void newKpacman(); void pauseKpacman(); void toggleHallOfFame(); void toggleNew(); void togglePaused(); void quitKpacman(); void schemeChecked(int); void toggleFocusOutPause(); void toggleFocusInContinue(); void toggleHideMouseCursor(); void confKeys(); protected: private: KpacmanWidget *view; void menu(); int lookupSchemes(); + QGridLayout *m_layout; + QWidget *m_view; KMenuBar *_menuBar; QPopupMenu *gamePopup; QPopupMenu *optionsPopup; QPopupMenu *modesPopup; QList<QPopupMenu> *schemesPopup; int newID; int pauseID; int hofID; QArray<int> modeID; QArray<int> schemeID; QArray<int> schemeMode; int focusOutPauseID; int focusInContinueID; int hideMouseCursorID; bool focusOutPause; bool focusInContinue; bool hideMouseCursor; }; #endif // KPACMAN_H diff --git a/noncore/games/kpacman/kpacmanwidget.cpp b/noncore/games/kpacman/kpacmanwidget.cpp index 215dcda..feb782c 100644 --- a/noncore/games/kpacman/kpacmanwidget.cpp +++ b/noncore/games/kpacman/kpacmanwidget.cpp @@ -1,88 +1,84 @@ #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 ) { 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); -#ifndef QWS - setFixedSize(referee->width(), bitfont->height()*3 + referee->height() + status->height()); -#else setBackgroundColor( black ); -#endif } 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); @@ -93,70 +89,65 @@ void KpacmanWidget::confScheme() 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); -#ifndef QWS - setFixedSize(referee->width(), - bitfont->height()*3 + referee->height() + status->height()); -#endif - score->repaint(FALSE); referee->repaint(FALSE); status->repaint(FALSE); } void KpacmanWidget::resizeEvent( QResizeEvent * ) { referee->setGeometry(0, bitfont->height()*3, referee->width(), referee->height()); referee->setBackgroundColor(BLACK); 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/referee.cpp b/noncore/games/kpacman/referee.cpp index 70916f0..81f331b 100644 --- a/noncore/games/kpacman/referee.cpp +++ b/noncore/games/kpacman/referee.cpp @@ -686,100 +686,100 @@ void Referee::confScheme() confMisc(FALSE); confTiming(FALSE); confScoring(FALSE); } fillMapName(); RESTORE_CONFIG_GROUP( cfg, oldgroup ); APP_CONFIG_END( cfg ); } void Referee::setScheme(int Scheme, int Mode, Bitfont *font) { mode = Mode; scheme = Scheme; confScheme(); pix->setScheme(scheme, mode, font); pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); for (Monster *m = monsters->first(); m != 0; m = monsters->next()) if (m) m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) if (e) e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); if (gameState.testBit(Introducing)) for (int i = 0; i < (gameState.testBit(Init) ? timerCount : 15); i++) introPaint(i); setFixedSize(pix->levelPix().size()); repaint(); } void Referee::keyPressEvent( QKeyEvent *k ) { uint key = k->key(); #ifdef QWS // "OK" => new game if ( key == Key_F33 || key == Key_F2 || key == Key_Enter ) play(); else if ( !gameState.testBit(Playing) && - key == Key_Up || + ( key == Key_Up || key == Key_Down || key == Key_Right || - key == Key_Left ) + key == Key_Left )) play(); // "Space" => pause //else if ( key == Key_Space || key == Key_F3 ) // pause(); // "Menu" => hall of fame //else if ( key == Key_F11 || key == Key_F4 ) // toggleHallOfFame(); #endif if (gameState.testBit(Paused) || gameState.testBit(HallOfFame) || gameState.testBit(Demonstration) || gameState.testBit(Dying) || gameState.testBit(Ready) || gameState.testBit(LevelDone) || !gameState.testBit(Playing)) return; if (key == UpKey) pacman->setDirection(N); else if (key == DownKey) pacman->setDirection(S); else if (key == RightKey) pacman->setDirection(E); else if (key == LeftKey) pacman->setDirection(W); #ifdef CHEATS else if (key == Key_L) { printf("levelUp()\n"); levelUp(); } else if (key == Key_F) { printf("fruit->move(TRUE)\n"); fruit->move(TRUE); repaint(FALSE); } else if (key == Key_E) { printf("setLifes(++lifes)\n"); emit setLifes(++lifes); } #endif else { k->ignore(); return; } k->accept(); } void Referee::score(int p) { if (!gameState.testBit(Playing)) return; if ((points += p) < 0) points = 0; emit setPoints(points); if (points >= nextExtraLifeScore) { diff --git a/noncore/games/kpacman/score.cpp b/noncore/games/kpacman/score.cpp index 17dbf0a..b3ff3d9 100644 --- a/noncore/games/kpacman/score.cpp +++ b/noncore/games/kpacman/score.cpp @@ -433,124 +433,96 @@ void Score::setScore(int level, int player) cursor.x = 14; cursor.y = 11+lastScore; cursor.chr = hallOfFame[lastScore].name.at(cursor.x-14); // startTimer(cursorBlinkMS); setFocus(); } /* * Read the highscores, if no file or a file shorter than 4 bytes (versions before 0.2.4 stores only * the points of one highscore) exists - the highscores were initialized with default values. */ void Score::read() { if (highscoreFile.exists() && highscoreFile.size() > 4) { if (highscoreFile.open(IO_ReadOnly)) { QDataStream s(&highscoreFile); char *name; for (int i = 0; i < 10; i++) { s >> hallOfFame[i].points >> hallOfFame[i].levels >> hallOfFame[i].duration >> hallOfFame[i].moment >> name; hallOfFame[i].name = QString::fromLatin1(name); delete(name); } highscoreFile.close(); } } else { for (int i = 0; i < 10; i++) { hallOfFame[i].points = 5000; hallOfFame[i].levels = 0; hallOfFame[i].duration = QTime(); hallOfFame[i].moment = QDateTime(); hallOfFame[i].name = "???"; } // write(); } for (int i = 0; i < 10; i++) for (uint j = 0; j < hallOfFame[i].name.length(); j++) if (hallOfFame[i].name.at(j) < bitfont->firstChar() || hallOfFame[i].name.at(j) > bitfont->lastChar()) hallOfFame[i].name.at(j) = hallOfFame[i].name.at(j).upper(); HighScore = hallOfFame[0].points; } void Score::write() { -#ifndef QWS - if (!highscoreFile.exists() && highscoreFile.name() == systemHighscoreFileInfo.filePath()) - KMessageBox::information(0, - tr("You're going to create the highscore-file\n" - "'%1'\n" - "for your maschine, that should be used systemwide.\n" - "\n" - "To grant access to the other users, set the appropriate rights (a+w)\n" - "on that file or ask your systemadministator for that favor.\n" - "\n" - "To use a different directory or filename for the highscores," - "specify them in the configfile (kpacmanrc:highscoreFilePath)." - ).arg(systemHighscoreFileInfo.filePath())); - - if (highscoreFile.name() == privateHighscoreFileInfo.filePath()) - KMessageBox::information(0, - tr("You're using a private highscore-file, that's mostly because of\n" - "missing write-access to the systemwide file\n" - "'%1' .\n" - "\n" - "Ask your systemadministrator for granting you access to that file,\n" - "by setting the appropriate rights (a+w) on it.\n" - "\n" - "To use a different directory or filename for the highscores," - "specify them in the configfile (kpacmanrc:highscoreFilePath)." - ).arg(systemHighscoreFileInfo.filePath()), - QString::null, "PrivateHighscore"); -#endif if (highscoreFile.open(IO_WriteOnly)) { QDataStream s(&highscoreFile); for (int i = 0; i < 10; i++) s << hallOfFame[i].points << hallOfFame[i].levels << hallOfFame[i].duration << hallOfFame[i].moment << hallOfFame[i].name.latin1(); highscoreFile.close(); } } void Score::setPause(bool Paused) { paused = Paused; QRect r = bitfont->rect(tr("PAUSED")); r.moveCenter(QPoint(this->width()/2, this->height()/2)); repaint(r, TRUE); // repaint 1UP or 2UP repaint(FALSE); } void Score::end() { if (paused) { QTimer::singleShot(afterPauseMS, this, SLOT(end())); return; } // repaint 1UP or 2UP lastPlayer = -1; repaint(FALSE); emit forcedHallOfFame(FALSE); } /* * Return the date in a formatted QString. The format can be changed using internationalization * of the string "YY/MM/DD". Invalid QDate's where returned as "00/00/00". */ QString Score::formatDate(QDate date) { QString s = tr("@YY@/@MM@/@DD@"); QString dd; dd.sprintf("%02d", date.isValid() ? date.year() % 100 : 0); s.replace(QRegExp("@YY@"), dd); dd.sprintf("%02d", date.isValid() ? date.month() : 0); s.replace(QRegExp("@MM@"), dd); @@ -560,83 +532,50 @@ QString Score::formatDate(QDate date) return s; } QRect Score::rect(int col, float row, QString str, int align) { QRect r = bitfont->rect(str); r.moveBy(x(col), y(row)); int dx = 0; int dy = 0; if (align & AlignLeft || align & AlignRight) { dx = (str.length()-1) * (bitfont->width()/2); if (align & AlignRight) dx *= -1; } if (align & AlignTop || align & AlignBottom) { dy = bitfont->height()/2; if (align & AlignBottom) dy *= -1; } if (dx != 0 || dy != 0) r.moveBy(dx, dy); return r; } int Score::x(int col) { return col*bitfont->width(); } int Score::y(float row) { return (int) (row*(bitfont->height()+bitfont->height()/4)); } /** * Ermittelt die zu benutzende "highscore"-Datei, in die auch geschrieben werden kann. * Über den "highscoreFilePath"-KConfig-Eintrag, kann abweichend von der Standardlokation * der Standort der "highscore"-Datei spezifiziert werden. * Wenn die systemweite "highscore"-Datei nicht beschrieben werden kann, wird mit einer * privaten Datei gearbeitet. */ QFileInfo Score::locateHighscoreFilePath() { -#ifndef QWS - QFileInfo systemHighscoreDirPath; - QStringList systemHighscoreDirs; - - // Schreibfähige "private" highscore-Datei ermitteln für den fallback. - privateHighscoreFileInfo.setFile(KGlobal::dirs()->saveLocation("appdata")+highscoreName); - - // FilePath aus der Konfigurationsdatei benutzen - systemHighscoreFileInfo.setFile(cfg->readEntry("HighscoreFilePath")); - - // Kein Wert aus der Konfiguration erhalten, dann die "system"-Datei suchen. - if (systemHighscoreFileInfo.filePath().isEmpty()) - systemHighscoreDirs = KGlobal::dirs()->resourceDirs("appdata"); - else - systemHighscoreDirs = QStringList(systemHighscoreFileInfo.filePath()); - - for (QStringList::Iterator i = systemHighscoreDirs.begin(); i != systemHighscoreDirs.end(); ++i) { - - systemHighscoreFileInfo.setFile(*i); - if (systemHighscoreFileInfo.fileName().isEmpty()) - systemHighscoreFileInfo.setFile(systemHighscoreFileInfo.dirPath()+"/"+highscoreName); - - // privateHighscoreFileInfo für die "system" Suche ignorieren - if (systemHighscoreFileInfo.filePath() != privateHighscoreFileInfo.filePath()) - if (!systemHighscoreFileInfo.exists()) { - systemHighscoreDirPath.setFile(systemHighscoreFileInfo.dirPath()); - if (systemHighscoreDirPath.exists() && systemHighscoreDirPath.isWritable()) - return systemHighscoreFileInfo; - } else - if (systemHighscoreFileInfo.isWritable()) - return systemHighscoreFileInfo; - } -#endif return privateHighscoreFileInfo; } |