Commit b584b1b7 authored by Roney Gomes's avatar Roney Gomes

The new KGrView and KGrScene classes has been moved to KGoldRunner and now are...

The new KGrView and KGrScene classes has been moved to KGoldRunner and now are available for use. Only a small set of functionalities is present, since the scene is not fully connected to the game engine.

svn path=/branches/work/kgoldrunner-qgv/; revision=1310605
parent 3c4c2c2c
......@@ -2,6 +2,7 @@
########### next target ###############
set(kgoldrunner_SRCS
kgrview.cpp
kgrscene.cpp
kgrplayfield.cpp
kgrsprite.cpp
......
......@@ -17,9 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************/
#include "kgrscene.h"
#include "kgoldrunner.h"
#include "kgrrenderer.h" // IDW test
#include <QApplication>
#include <QDesktopWidget>
......@@ -55,8 +53,10 @@
#include <libkdegames_capabilities.h> //defines KGAUDIO_BACKEND_OPENAL (or not)
#include "kgrcanvas.h"
#include "kgrgame.h"
#include "kgrview.h"
#include "kgrscene.h"
#include "kgrrenderer.h"
// Shorthand for references to actions.
#define ACTION(x) (actionCollection()->action(x))
......@@ -92,20 +92,21 @@ KGoldrunner::KGoldrunner()
/******************************************************************************/
// Base the size of playing-area and widgets on the monitor resolution.
int dw = QApplication::desktop()->width();
// int dw = QApplication::desktop()->width();
// Need to consider the height, for widescreen displays (eg. 1280x768).
int dh = QApplication::desktop()->height();
// int dh = QApplication::desktop()->height();
double scale = 1.0;
/* double scale = 1.0;
if ((dw > 800) && (dh > 600)) { // More than 800x600.
scale = 1.25; // Scale 1.25:1.
}
if ((dw > 1024) && (dh > 768)) { // More than 1024x768.
scale = 1.75; // Scale 1.75:1.
}
view = new KGrCanvas (this, scale);
game = new KGrGame (view, systemDataDir, userDataDir);
} */
view = new KGrView (this);
game = new KGrGame (view, systemDataDir, userDataDir);
// Initialise the lists of games (i.e. collections of levels).
if (! game->initGameLists()) {
......@@ -113,9 +114,6 @@ KGoldrunner::KGoldrunner()
return; // If no game files, abort.
}
kDebug() << "Calling view->setBaseScale() ...";
view->setBaseScale(); // Set scale for level-titles font.
/******************************************************************************/
/************************* SET UP THE USER INTERFACE ************************/
/******************************************************************************/
......@@ -126,8 +124,8 @@ KGoldrunner::KGoldrunner()
// Tell the KMainWindow that the KGrCanvas object is the main widget.
setCentralWidget (view);
m_scene = new KGrScene; //IDW test.
m_renderer = new KGrRenderer (m_scene); // IDW test.
scene = view->gameScene ();
renderer = scene->renderer ();
// Set up our actions (menu, toolbar and keystrokes) ...
setupActions();
......@@ -140,15 +138,12 @@ KGoldrunner::KGoldrunner()
setupGUI (static_cast<StandardWindowOption> (Default &
(~StatusBar) & (~ToolBar) & (~Keys)));
// Find the theme-files and generate the Themes menu.
setupThemes();
// Set up a status bar (after setupGUI(), to show USER's choice of keys).
initStatusBar();
// Connect the game actions to the menu and toolbar displays.
connect (game, SIGNAL (quitGame()), SLOT (close()));
connect (game, SIGNAL (setEditMenu(bool)), SLOT (setEditMenu(bool)));
// connect (game, SIGNAL (setEditMenu(bool)), SLOT (setEditMenu(bool)));
connect (game, SIGNAL (hintAvailable(bool)), SLOT (adjustHintAction(bool)));
connect (game, SIGNAL (setAvail(const char*,bool)),
......@@ -304,7 +299,7 @@ void KGoldrunner::setupActions()
/**************************************************************************/
QSignalMapper * editMapper = new QSignalMapper (this);
connect (editMapper, SIGNAL (mapped(int)), game, SLOT (editActions(int)));
// connect (editMapper, SIGNAL (mapped(int)), game, SLOT (editActions(int)));
tempMapper = editMapper;
// Create a Level
......@@ -373,7 +368,7 @@ void KGoldrunner::setupActions()
themes->setToolTip (i18n ("Change the graphics theme..."));
themes->setWhatsThis (i18n ("Alter the visual appearance of the runners "
"and background scene..."));
connect (themes, SIGNAL(triggered(bool)), m_renderer, SLOT(selectTheme()));
connect (themes, SIGNAL (triggered (bool)), this, SLOT (changeTheme ()));
/**************************************************************************/
/**************************** SETTINGS MENU ****************************/
......@@ -551,7 +546,7 @@ void KGoldrunner::setupActions()
// Key_O, "dig_right"
// Key_U, "dig_left"
setupEditToolbarActions(); // Uses pixmaps from "view".
// setupEditToolbarActions(); // Uses pixmaps from "view".
// Authors' debugging aids, effective when Pause is hit. Options include
// stepping through the animation, toggling a debug patch or log messages
......@@ -719,56 +714,6 @@ void KGoldrunner::viewFullScreen (bool activation)
KToggleFullScreenAction::setFullScreen (this, activation);
}
void KGoldrunner::setupThemes()
{
// Look for themes in files "---/share/apps/kgoldrunner/themes/*.desktop".
KGlobal::dirs()->addResourceType ("theme", "data",
QString (KCmdLineArgs::aboutData()->appName()) + QString ("/themes/"));
QStringList themeFilepaths = KGlobal::dirs()->findAllResources
("theme", "*.desktop", KStandardDirs::NoDuplicates); // Find files.
KConfigGroup gameGroup (KGlobal::config(), "KDEGame"); // Get prev theme.
QString currentThemeFilepath = gameGroup.readEntry ("ThemeFilepath", "");
kDebug()<< "Config() Theme" << currentThemeFilepath;
QSignalMapper * themeMapper = new QSignalMapper (this);
connect (themeMapper, SIGNAL (mapped(QString)),
this, SLOT (changeTheme(QString)));
KToggleAction * newTheme; // Action for a theme.
QString actionName; // Name of the theme.
QList<QAction *> themeList; // Themes for menu.
QActionGroup * themeGroup = new QActionGroup (this);
themeGroup->setExclusive (true); // Exclusive toggles.
foreach (const QString &filepath, themeFilepaths) { // Read each theme-file.
KConfig theme (filepath, KConfig::SimpleConfig);// Extract theme-name.
KConfigGroup group = theme.group ("KGameTheme"); // Translated.
actionName = group.readEntry ("Name", i18n ("Missing Name"));
newTheme = new KToggleAction (actionName, this);
themeGroup->addAction (newTheme); // Add to toggle-group.
if ((currentThemeFilepath == filepath) || // If theme prev chosen
((currentThemeFilepath.isEmpty()) && // or it is the default
(filepath.indexOf ("default") >= 0)) ||
((filepath == themeFilepaths.last()) &&
(themeGroup->checkedAction() == 0))) { // or last in the list,
game->setInitialTheme (filepath); // tell graphics init.
newTheme->setChecked (true); // and mark it as chosen
}
connect (newTheme, SIGNAL(triggered(bool)), themeMapper, SLOT(map()));
themeMapper->setMapping (newTheme, filepath); // Add path to signal.
themeList.append (newTheme); // Theme --> menu list.
}
unplugActionList ("theme_list");
plugActionList ("theme_list", themeList); // Insert list in menu.
}
/******************************************************************************/
/********************** SLOTS FOR STATUS BAR UPDATES ************************/
/******************************************************************************/
......@@ -807,7 +752,7 @@ void KGoldrunner::showLives (long newLives)
tmp = tmp.rightJustified (3, '0');
tmp.insert (0, i18n (" Lives: "));
tmp.append (" ");
view->updateLives(newLives);
// view->updateLives(newLives);
statusBar()->changeItem (tmp, ID_LIVES);
}
......@@ -819,7 +764,7 @@ void KGoldrunner::showScore (long newScore)
tmp = tmp.rightJustified (7, '0');
tmp.insert (0, i18n (" Score: "));
tmp.append (" ");
view->updateScore(newScore);
// view->updateScore(newScore);
statusBar()->changeItem (tmp, ID_SCORE);
}
......@@ -883,7 +828,7 @@ void KGoldrunner::setAvail (const char * actionName, const bool onOff)
((KAction *) ACTION (actionName))->setEnabled (onOff);
}
void KGoldrunner::setEditMenu (bool on_off)
/* void KGoldrunner::setEditMenu (bool on_off)
{
saveEdits->setEnabled (on_off);
......@@ -896,8 +841,8 @@ void KGoldrunner::setEditMenu (bool on_off)
if (on_off){
// Set the editToolbar icons to the current tile-size.
kDebug() << "ToolBar icon size:" << view->getPixmap (BRICK).size();
toolBar ("editToolbar")->setIconSize (view->getPixmap (BRICK).size());
kDebug() << "ToolBar icon size:" << scene->tileSize ();
toolBar ("editToolbar")->setIconSize (scene->tileSize ());
// Set the editToolbar icons up with pixmaps of the current theme.
setEditIcon ("brickbg", BRICK);
......@@ -917,30 +862,25 @@ void KGoldrunner::setEditMenu (bool on_off)
else {
toolBar ("editToolbar")->hide();
}
}
} */
void KGoldrunner::setEditIcon (const QString & actionName, const char iconType)
/* void KGoldrunner::setEditIcon (const QString & actionName, const char iconType)
{
((KToggleAction *) (actionCollection()->action (actionName)))->
setIcon (KIcon (view->getPixmap (iconType)));
}
setIcon (KIcon (renderer->getPixmap (iconType)));
} */
/******************************************************************************/
/******************* SLOTS FOR MENU AND KEYBOARD ACTIONS *******************/
/******************************************************************************/
void KGoldrunner::changeTheme (const QString & themeFilepath)
void KGoldrunner::changeTheme ()
{
if (view->changeTheme (themeFilepath)) {
if (game->inEditMode()) {
setEditMenu (true);
}
}
else {
KGrMessage::information (this, i18n ("Theme Not Loaded"),
i18n ("Cannot load the theme you selected. It is not "
"in the required graphics format (SVG)."));
}
renderer->selectTheme ();
/* if (game->inEditMode()) {
setEditMenu (true);
} */
}
void KGoldrunner::saveProperties (KConfigGroup & /* config - unused */)
......@@ -1058,7 +998,7 @@ bool KGoldrunner::queryClose()
/********************** MAKE A TOOLBAR FOR THE EDITOR **********************/
/******************************************************************************/
void KGoldrunner::setupEditToolbarActions()
/* void KGoldrunner::setupEditToolbarActions()
{
QSignalMapper * editToolbarMapper = new QSignalMapper (this);
connect (editToolbarMapper, SIGNAL (mapped(int)),
......@@ -1142,7 +1082,7 @@ void KGoldrunner::setupEditToolbarActions()
editButtons->addAction (nugget);
brick->setChecked (true);
}
} */
QSize KGoldrunner::sizeHint() const
{
......
......@@ -40,9 +40,9 @@ class KAction;
class KToggleAction;
class KGrGame;
class KGrCanvas;
class KGrView;
class KGrScene;
class KGrRenderer;
class KGrScene; // RNY test.
/**
* This class serves as the main window for KGoldrunner. It handles the
......@@ -78,8 +78,6 @@ protected:
void keyReleaseEvent (QKeyEvent * event);
private:
KGrScene * m_scene; // IDW test.
bool identifyMoveAction (QKeyEvent * event, bool pressed);
protected:
......@@ -104,7 +102,7 @@ private slots:
void KGoldrunner_2();
// Slot to change the graphics theme.
void changeTheme (const QString & themeFilepath);
void changeTheme ();
void optionsConfigureKeys();
......@@ -114,8 +112,8 @@ private slots:
void gameFreeze (bool); // Status feedback on Pause state.
void adjustHintAction (bool); // Enable/disable "Hint" action.
void setEditMenu (bool on_off); // Enable/disable "Save Edits" action.
void setEditIcon (const QString & actionName, const char iconType);
// void setEditMenu (bool on_off); // Enable/disable "Save Edits" action.
// void setEditIcon (const QString & actionName, const char iconType);
void viewFullScreen (bool activation);
QSize sizeHint() const;
......@@ -123,8 +121,7 @@ private slots:
private:
void setupActions();
void initStatusBar();
void setupEditToolbarActions();
void setupThemes();
// void setupEditToolbarActions();
QSignalMapper * tempMapper; // Temporary pointer.
......@@ -153,12 +150,14 @@ private:
bool startupOK;
KGrCanvas * view;
KGrGame * game;
KGrRenderer * m_renderer;
bool frozen;
KGrGame * game;
KGrView * view;
KGrScene * scene;
KGrRenderer * renderer;
bool frozen;
bool getDirectories(); // Get directory paths, as below.
QString systemHTMLDir; // Where the manual is stored.
QString systemDataDir; // Where the system levels are stored.
QString userDataDir; // Where the user levels are stored.
......
......@@ -27,9 +27,6 @@
<Action name="create_game" />
<Action name="edit_game" />
</Menu>
<Menu name="themes" > <text>&amp;Themes</text>
<ActionList name="theme_list" />
</Menu>
<Menu name="settings" >
<Action append="save_merge" name="select_theme" />
<Action append="save_merge" name="options_sounds" />
......
......@@ -26,6 +26,7 @@
#include "kgrsprite.h"
#include <QLabel>
#include <QDebug>
#include <QCursor>
#include <QMouseEvent>
......@@ -304,6 +305,9 @@ void KGrCanvas::drawTheScene (bool changePixmaps)
// Adjust lives position to center them in the display
deltaW = (sections * imgW - w) / 2;
livesPos.rx() -= deltaW;
qDebug() << "Score position:" << m_scoreDisplay->pos();
qDebug() << "Lives position:" << m_livesDisplay->pos();
}
m_scoreText->moveTo (scorePos);
m_livesText->moveTo (livesPos);
......@@ -995,7 +999,7 @@ KGameCanvasPixmap * KGrCanvas::makeBorderElement(QList< QPixmap >frameTiles,
KGameCanvasPixmap * KGrCanvas::makeDisplay (QList< QPixmap > tiles, int w)
{
int sections = 1 + numSections(w, imgW);
int sections = 1 + numSections(w, imgW);
int width = (sections + 2) * imgW;
QPixmap pix (width, imgH);
pix.fill(QColor(0, 0, 0, 0));
......@@ -1006,7 +1010,7 @@ KGameCanvasPixmap * KGrCanvas::makeDisplay (QList< QPixmap > tiles, int w)
p.drawPixmap (x, 0, tiles.at(1));
}
p.drawPixmap (sections * imgW, 0, tiles.at(2));
p.end();
KGameCanvasPixmap *element = new KGameCanvasPixmap (this);
element->setPixmap (pix);
......
......@@ -21,7 +21,8 @@
#include "kgrgame.h"
#include "kgrcanvas.h"
#include "kgrview.h"
#include "kgrscene.h"
#include "kgrselector.h"
// KGoldrunner loads and plays .ogg files and requires OpenAL + SndFile > v0.21.
......@@ -31,7 +32,7 @@
#include "kgrsounds.h"
#endif
#include "kgreditor.h"
// #include "kgreditor.h"
#include "kgrlevelplayer.h"
#include "kgrdialog.h"
#include "kgrgameio.h"
......@@ -82,9 +83,9 @@
/*********************** KGOLDRUNNER GAME CLASS *************************/
/******************************************************************************/
KGrGame::KGrGame (KGrCanvas * theView,
KGrGame::KGrGame (KGrView * theView,
const QString & theSystemDir, const QString & theUserDir)
:
:
QObject (theView), // Game is destroyed if view closes.
levelPlayer (0),
recording (0),
......@@ -101,8 +102,8 @@ KGrGame::KGrGame (KGrCanvas * theView,
effects (0),
fx (NumSounds),
soundOn (false),
stepsOn (false),
editor (0)
stepsOn (false)
// editor (0)
{
dbgLevel = 0;
......@@ -246,7 +247,7 @@ void KGrGame::gameActions (const int action)
}
}
void KGrGame::editActions (const int action)
/* void KGrGame::editActions (const int action)
{
bool editOK = true;
bool newEditor = (editor) ? false : true;
......@@ -301,7 +302,7 @@ void KGrGame::editActions (const int action)
setPlayback (false);
if (levelPlayer) {
endLevel (NORMAL);
view->deleteAllSprites();
// view->deleteAllSprites();
}
emit showLives (0);
......@@ -334,9 +335,9 @@ void KGrGame::editActions (const int action)
gameGroup.writeEntry ("Level_" + prefix, level);
gameGroup.sync(); // Ensure that the entry goes to disk.
}
}
} */
void KGrGame::editToolbarActions (const int action)
/* void KGrGame::editToolbarActions (const int action)
{
// If game-editor is inactive or action-code is not recognised, do nothing.
if (editor) {
......@@ -362,7 +363,7 @@ void KGrGame::editToolbarActions (const int action)
break;
}
}
}
} */
void KGrGame::settings (const int action)
{
......@@ -488,7 +489,7 @@ void KGrGame::initGame()
<< gameList.at (gameIndex)->name << level;
kDebug() << "Calling the first view->changeTheme() ...";
view->changeTheme (initialThemeFilepath);
// view->changeTheme (initialThemeFilepath);
setPlayback ( gameGroup.readEntry ("StartingDemo", true));
if (playback && (startDemo (SYSTEM, mainDemoName, 1))) {
......@@ -604,7 +605,7 @@ void KGrGame::startInstantReplay()
// Terminate current play.
delete levelPlayer;
levelPlayer = 0;
view->deleteAllSprites();
// view->deleteAllSprites();
// Redisplay the starting score and lives.
lives = recording->lives;
......@@ -804,7 +805,7 @@ void KGrGame::runReplay (const int action,
void KGrGame::newGame (const int lev, const int newGameIndex)
{
view->goToBlack();
// view->goToBlack();
KGrGameData * gameData = gameList.at (newGameIndex);
level = lev;
......@@ -828,11 +829,11 @@ bool KGrGame::playLevel (const Owner fileOwner, const QString & prefix,
const int levelNo, const bool newLevel)
{
// If the game-editor is active, terminate it.
if (editor) {
/* if (editor) {
emit setEditMenu (false); // Disable edit menu items and toolbar.
delete editor;
editor = 0;
}
} */
// If there is a level being played, kill it, with no win/lose result.
if (levelPlayer) {
......@@ -841,15 +842,15 @@ bool KGrGame::playLevel (const Owner fileOwner, const QString & prefix,
// Clean up any sprites remaining from a previous level. This is done late,
// so that the player has a little time to observe how the level ended.
view->deleteAllSprites();
// view->deleteAllSprites();
// Set up to record or play back: load either level-data or recording-data.
if (! initRecordingData (fileOwner, prefix, levelNo)) {
return false;
}
view->setLevel (levelNo); // Switch and render background if reqd.
view->fadeIn(); // Then run the fade-in animation.
// view->setLevel (levelNo); // Switch and render background if reqd.
// view->fadeIn(); // Then run the fade-in animation.
startScore = score; // The score we will save, if asked.
// Create a level player, initialised and ready for play or replay to start.
......@@ -862,7 +863,7 @@ bool KGrGame::playLevel (const Owner fileOwner, const QString & prefix,
emit hintAvailable (levelHint.length() > 0);
// Re-draw the playfield frame, level title and figures.
view->setTitle (getTitle());
// view->setTitle (getTitle());
// If we are starting a new level, save it in the player's config file.
if (newLevel && (level != 0)) { // But do not save the "ENDE" level.
......@@ -1022,24 +1023,24 @@ void KGrGame::herosDead()
void KGrGame::finalBreath()
{
dbk << "Connecting fadeFinished()";
connect (view, SIGNAL (fadeFinished()), this, SLOT (repeatLevel()));
// connect (view, SIGNAL (fadeFinished()), this, SLOT (repeatLevel()));
dbk << "Calling view->fadeOut()";
view->fadeOut();
// view->fadeOut();
}
void KGrGame::repeatLevel()
{
disconnect (view, SIGNAL (fadeFinished()), this, SLOT (repeatLevel()));
// disconnect (view, SIGNAL (fadeFinished()), this, SLOT (repeatLevel()));
// Avoid re-starting if the player selected edit before the time was up.
if (! editor) {
// if (! editor) {
if (playback) {
runNextDemoLevel();
}
else if (playLevel (owner, prefix, level, (! NewLevel))) {
levelPlayer->prepareToPlay();
}
}
// }
freeze (ProgramPause, false); // Unfreeze, but don't move yet.
}
......@@ -1048,14 +1049,14 @@ void KGrGame::levelCompleted()
playSound (CompletedSound);
dbk << "Connecting fadeFinished()";
connect (view, SIGNAL (fadeFinished()), this, SLOT (goUpOneLevel()));
// connect (view, SIGNAL (fadeFinished()), this, SLOT (goUpOneLevel()));
dbk << "Calling view->fadeOut()";
view->fadeOut();
// view->fadeOut();
}
void KGrGame::goUpOneLevel()
{
disconnect (view, SIGNAL (fadeFinished()), this, SLOT (goUpOneLevel()));
// disconnect (view, SIGNAL (fadeFinished()), this, SLOT (goUpOneLevel()));
lives++; // Level completed: gain another life.
emit showLives (lives);
......@@ -1141,10 +1142,10 @@ void KGrGame::setTimeScale (const int action)
}
}
bool KGrGame::inEditMode()
/* bool KGrGame::inEditMode()
{
return (editor != 0); // Return true if the game-editor is active.
}
} */
void KGrGame::toggleSoundsOnOff (const int action)
{
......@@ -1295,7 +1296,7 @@ void KGrGame::setPlayback (const bool onOff)
emit setAvail ("increase_speed", enableDisable);
emit setAvail ("decrease_speed", enableDisable);
}
view->showReplayMessage (onOff);
// view->showReplayMessage (onOff);
playback = onOff;
}
......@@ -1331,9 +1332,9 @@ void KGrGame::kbControl (const int dirn, const bool pressed)
{
dbk2 << "Keystroke setting direction" << dirn << "pressed" << pressed;
if (editor) {
/* if (editor) {
return;
}
} */
if (playback) {
levelPlayer->interruptPlayback(); // Will emit interruptDemo().
return;
......@@ -1384,13 +1385,13 @@ void KGrGame::kbControl (const int dirn, const bool pressed)
void KGrGame::saveGame() // Save game ID, score and level.
{
if (editor) {
/* if (editor) {
myMessage (view, i18n ("Save Game"),
i18n ("Sorry, you cannot save your game play while you are editing. "
"Please try menu item \"%1\".",
i18n ("&Save Edits...")));
return;
}
} */
if (playback) {
return; // Avoid saving in playback mode.
}
......@@ -1526,7 +1527,7 @@ void KGrGame::loadGame (const int game, const int lev)
bool KGrGame::saveOK()
{
return (editor ? (editor->saveOK()) : true);
return true; // (editor ? (editor->saveOK()) : true);
}
/******************************************************************************/
......@@ -1651,8 +1652,8 @@ void KGrGame::checkHighScore()
hsn-> setWindowTitle (i18n ("Save High Score"));
QPoint p = view->mapToGlobal (QPoint (0,0));
hsn-> move (p.x() + 50, p.y() + 50);
// QPoint p = view->mapToGlobal (QPoint (0,0));
// hsn-> move (p.x() + 50, p.y() + 50);
OK-> setShortcut (Qt::Key_Return);