Commit 2d265207 authored by Ian Wadham's avatar Ian Wadham

Re-factor and re-integrate the GUI for the game-actions and settings. Drop...

Re-factor and re-integrate the GUI for the game-actions and settings.  Drop the actions to change the game-rules independently of the selected game.  Re-implement the actions to change the game-speed.

svn path=/branches/work/kgoldrunner/; revision=947746
parent 748afd56
This diff is collapsed.
......@@ -50,8 +50,6 @@ class KGrHero;
* menus, toolbars, and status bars.
*
* @short Main window class
* @author $AUTHOR <$EMAIL>
* @version $APP_VERSION
*/
class KGoldrunner : public KXmlGuiWindow
{
......@@ -97,37 +95,10 @@ private slots:
// An extension of the constructor. Gives us two scans of the event queue.
void KGoldrunner_2();
// Slot to pause or restart the game.
void stopStart();
// Slot to change the graphics theme.
void changeTheme (const QString & themeFilepath);
// Local slots to set mouse/keyboard or laptop-hybrid control of the hero.
void setMouseMode();
void setKeyBoardMode();
void setLaptopMode();
// Local slots to set game speed.
void normalSpeed();
void beginSpeed();
void champSpeed();
void incSpeed();
void decSpeed();
// Slots to set Traditional or KGoldrunner rules.
void setTradRules();
void setKGrRules();
// void optionsShowToolbar();
// void optionsShowStatusbar();
void optionsConfigureKeys();
// void optionsConfigureToolbars();
// void optionsPreferences();
// void newToolbarConfig();
void changeStatusbar (const QString& text);
void changeCaption (const QString& text);
void showLevel (int); // Show the current level number.
void showLives (long); // Show how many lives are remaining.
......@@ -135,7 +106,6 @@ private slots:
void gameFreeze (bool); // Status feedback on freeze/unfreeze.
void adjustHintAction (bool); // Enable/disable "Hint" action.
void markRuleType (char ruleType); // Check game's rule type in the menu.
void setEditMenu (bool on_off); // Enable/disable "Save Edits" action.
void setEditIcon (const QString & actionName, const char iconType);
void viewFullScreen (bool activation);
......@@ -148,22 +118,35 @@ private:
void setupEditToolbarActions();
void setupThemes();
QSignalMapper * editMapper; // Editior-actions mapper.
QSignalMapper * kbMapper; // Keyboard game-control mapper.
QSignalMapper * dbgMapper; // Debugging-key mapper.
QSignalMapper * tempMapper; // Temporary pointer.
QAction * gameAction (const QString & name, const int code,
const QString & text, const QString & toolTip,
const QString & whatsThis, const QKeySequence & key);
QAction * editAction (const QString & name, const int code,
const QString & text, const QString & toolTip,
const QString & whatsThis);
void keyControl (const QString & name, const QString & text,
const QKeySequence & shortcut, const int code);
private:
KToggleAction * settingAction (const QString & name,
const int code,
const QString & text,
const QString & toolTip,
const QString & whatsThis);
KToggleAction * editToolbarAction
(const QString & name, const char code,
const QString & shortText, const QString & text,
const QString & toolTip, const QString & whatsThis);
void keyControl (const QString & name, const QString & text,
const QKeySequence & shortcut, const int code);
bool startupOK;
KGrCanvas * view;
KGrGame * game;
bool frozen;
bool getDirectories(); // Get directory paths, as below.
QString systemHTMLDir; // Where the manual is stored.
......@@ -173,33 +156,17 @@ private:
QAction * saveGame; // Save game, level, lives and score.
// A KAction is needed here, to get access to KShortcut::setAlternate().
// IDW KAction * myPause; // Pause or resume the game.
// TODO - KAction * myPause; // Pause or resume the game.
QAction * myPause; // Pause or resume the game.
QString pauseKeys; // Keystroke names to put in status bar.
QAction * hintAction; // Display a hint, if available.
KAction * killHero; // Kill hero (disabled during edits).
QAction * killHero; // Kill hero (disabled during edits).
QAction * highScore; // High scores (disabled during edits).
QAction * saveEdits; // Save a level that has been edited.
KToggleFullScreenAction *fullScreen; // Show Full Screen Mode on menu.
KToggleAction * setMouse; // Show mouse/keyboard mode on menu.
KToggleAction * setKeyboard; // Show mouse/keyboard mode on menu.
KToggleAction * setLaptop; // Show mouse/keyboard mode on menu.
KToggleAction * tradRules; // Set Traditional rules.
KToggleAction * kgrRules; // Set KGoldrunner rules.
KToggleAction * setSounds; // enable/disable sound effects.
// OBSOLESCENT - 18/1/09 KGrHero * hero; // Pointer to the hero.
// KToggleAction * m_toolbarAction;
// KToggleAction * m_statusbarAction;
KToolBar * editToolbar; // Toolbar for creating/editing levels.
KToggleAction * m_defaultEditAct;
};
#endif // _KGOLDRUNNER_H_
......@@ -32,9 +32,6 @@
<Action append="save_merge" name="champion_speed" />
<Action append="save_merge" name="increase_speed" />
<Action append="save_merge" name="decrease_speed" />
<Separator append="save_merge" />
<Action append="save_merge" name="trad_rules" />
<Action append="save_merge" name="kgr_rules" />
</Menu>
<Menu name="help" >
<Action name="tutorial" />
......
......@@ -71,6 +71,7 @@ KGrGame::KGrGame (KGrCanvas * theView,
{
newLevel = true; // Next level will be a new one.
loading = true; // Stop input until it is loaded.
settings (NORMAL_SPEED);
gameFrozen = true;
modalFreeze = false;
......@@ -116,6 +117,31 @@ bool KGrGame::logging = false; // Start game with dynamic logging OFF.
void KGrGame::gameActions (int action)
{
switch (action) {
case NEW:
kDebug() << "NEW signal:" << action;
startAnyLevel();
break;
case LOAD:
kDebug() << "LOAD signal:" << action;
loadGame();
break;
case SAVE_GAME:
kDebug() << "SAVE_GAME signal:" << action;
saveGame();
break;
case PAUSE:
kDebug() << "PAUSE signal:" << action;
if (! gameFrozen) {
freeze();
}
else {
unfreeze();
}
break;
case HIGH_SCORE:
kDebug() << "HIGH_SCORE signal:" << action;
showHighScores();
break;
case HINT:
kDebug() << "HINT signal:" << action;
showHint();
......@@ -229,11 +255,37 @@ void KGrGame::editToolbarActions (int action)
editor->setEditObj (action);
break;
default:
break;
break;
}
}
}
void KGrGame::settings (int action)
{
switch (action) {
case PLAY_SOUNDS:
kDebug() << "PLAY_SOUNDS signal:" << action;
toggleSoundsOnOff();
break;
case MOUSE:
case KEYBOARD:
case LAPTOP:
kDebug() << "Control-mode signal:" << action;
setControlMode (action);
break;
case NORMAL_SPEED:
case BEGINNER_SPEED:
case CHAMPION_SPEED:
case INC_SPEED:
case DEC_SPEED:
kDebug() << "Speed-setting signal:" << action;
setTimeScale (action);
break;
default:
break;
}
}
void KGrGame::setInitialTheme (const QString & themeFilepath)
{
initialThemeFilepath = themeFilepath;
......@@ -275,7 +327,6 @@ void KGrGame::initGame()
kDebug() << "Calling the first view->changeTheme() ...";
view->changeTheme (initialThemeFilepath);
emit markRuleType (gameData->rules);
newGame (level, gameIndex);
}
......@@ -584,7 +635,7 @@ void KGrGame::goUpOneLevel()
newLevel = false;
}
void KGrGame::setControlMode (const Control mode)
void KGrGame::setControlMode (const int mode)
{
controlMode = mode;
if (levelPlayer) {
......@@ -592,6 +643,34 @@ void KGrGame::setControlMode (const Control mode)
}
}
void KGrGame::setTimeScale (const int action)
{
switch (action) {
case NORMAL_SPEED:
timeScale = 10;
break;
case BEGINNER_SPEED:
timeScale = 5;
break;
case CHAMPION_SPEED:
timeScale = 15;
break;
case INC_SPEED:
timeScale = (timeScale < 20) ? timeScale + 1 : 20;
break;
case DEC_SPEED:
timeScale = (timeScale > 2) ? timeScale - 1 : 2;
break;
default:
break;
}
if (levelPlayer) {
kDebug() << "setTimeScale" << (timeScale * 0.1);
levelPlayer->setTimeScale (timeScale * 0.1);
}
}
bool KGrGame::inMouseMode()
{
return (controlMode == MOUSE);
......@@ -607,12 +686,14 @@ bool KGrGame::isLoading()
return (loading); // Return true if a level is being loaded.
}
void KGrGame::setPlaySounds (bool on_off)
void KGrGame::toggleSoundsOnOff()
{
KConfigGroup gameGroup (KGlobal::config(), "KDEGame");
gameGroup.writeEntry ("Sound", on_off);
bool soundOnOff = gameGroup.readEntry ("Sound", false);
soundOnOff = (! soundOnOff);
gameGroup.writeEntry ("Sound", soundOnOff);
#ifdef ENABLE_SOUND_SUPPORT
effects->setMuted (!on_off);
effects->setMuted (! soundOnOff);
#endif
}
......@@ -710,7 +791,6 @@ void KGrGame::startTutorial()
// Start the tutorial.
gameData = gameList.at (index);
owner = gameData->owner;
emit markRuleType (gameData->rules);
gameIndex = index;
level = 1;
newGame (level, gameIndex);
......@@ -764,6 +844,8 @@ int KGrGame::loadLevel (int levelNo)
char rulesCode = gameList.at(gameIndex)->rules;
levelPlayer->init (view, controlMode, rulesCode, &levelData);
kDebug() << "setTimeScale" << (timeScale * 0.1);
levelPlayer->setTimeScale (timeScale * 0.1);
// If there is a name, translate the UTF-8 coded QByteArray right now.
levelName = (levelData.name.size() > 0) ?
......@@ -1072,7 +1154,6 @@ void KGrGame::loadGame() // Re-load game, score and level.
}
if (found) {
// Set the rules for the selected game.
emit markRuleType (gameData->rules);
lev = s.mid (28, 3).toInt();
newGame (lev, gameIndex); // Re-start the selected game.
showTutorialMessages (level);
......
......@@ -71,8 +71,6 @@ public:
QString getDirectory (Owner o);
inline bool isFrozen() { return gameFrozen; }
// Flags to control author's debugging aids.
static bool bugFix;
static bool logging;
......@@ -83,6 +81,7 @@ public slots:
void gameActions (int action);
void editActions (int action);
void editToolbarActions (int action);
void settings (int action);
void initGame(); // Do the game object's first painting.
......@@ -90,10 +89,11 @@ public slots:
void startAnyLevel(); // Start any game from any level.
void startNextLevel(); // Start next level of current game.
void setPlaySounds (bool on_off); // Set sound enabled or disabled.
void toggleSoundsOnOff(); // Set sound enabled or disabled.
// Set mouse, keyboard or laptop-hybrid control of the hero.
void setControlMode (const Control mode);
void setControlMode (const int mode);
void setTimeScale (const int action);
void startLevel (int startingAt, int requestedLevel);
void newGame (const int lev, const int gameIndex);
......@@ -126,7 +126,6 @@ signals:
void setEditMenu (bool); // Enable/Disable edit menu items.
void defaultEditObj(); // Set default edit-toolbar button.
void markRuleType (char); // Mark KGoldrunner/Traditional rules.
void gameFreeze (bool); // Do visual feedback in the GUI.
void quitGame(); // Used for Quit option in Quick Start.
......@@ -167,6 +166,7 @@ private:
KGrCanvas * view; // Where the game is displayed.
QString systemDataDir; // System games are stored here.
QString userDataDir; // User games are stored here.
int timeScale; // The speed of the game (2-20).
int level; // Current play/edit level.
QString levelName; // Level name (optional).
......@@ -215,7 +215,7 @@ public slots:
private:
KGrEditor * editor; // The level-editor object.
Control controlMode; // How to control the hero (e.g. K/B or mouse).
int controlMode; // How to control the hero (e.g. K/B or mouse).
/******************************************************************************/
/*********************** GAME PROPERTIES AND METHODS **********************/
......
......@@ -48,15 +48,6 @@ const char EDIT_TEST = '2';
const char FIELDWIDTH = 28;
const char FIELDHEIGHT = 20;
/* Action times ... */
#define NSPEED 12
#define MAXSPEED NSPEED * 2
#define MINSPEED NSPEED / 4
#define BEGINSPEED NSPEED / 2
#define NOVICESPEED (3 * NSPEED) / 4
#define CHAMPSPEED (3 * NSPEED) / 2
// TODO - Probably belongs in kgrrulebook.h. That is the only place it is used.
typedef struct {
int hwalk;
......@@ -102,9 +93,6 @@ const char TraditionalRules = 'T';
const char KGoldrunnerRules = 'K';
const char ScavengerRules = 'S';
/// Modes for controlling the hero in KGoldrunner.
enum Control {MOUSE, KEYBOARD, LAPTOP};
/// Centralised message functions: implementations in kgrdialog.cpp.
class QWidget;
class KGrMessage
......@@ -145,9 +133,16 @@ public:
QByteArray hint; ///< Level hint (optional).
};
enum GameAction {HINT, KILL_HERO};
enum EditAction {CREATE_LEVEL, EDIT_ANY, SAVE_EDITS, MOVE_LEVEL, DELETE_LEVEL,
CREATE_GAME, EDIT_GAME};
enum GameAction {NEW, LOAD, SAVE_GAME, PAUSE, HIGH_SCORE, HINT, KILL_HERO};
enum EditAction {CREATE_LEVEL, EDIT_ANY, SAVE_EDITS, MOVE_LEVEL,
DELETE_LEVEL, CREATE_GAME, EDIT_GAME};
enum Setting {PLAY_SOUNDS, // Sound effects on/off.
MOUSE, KEYBOARD, LAPTOP, // Game-control modes.
NORMAL_SPEED, BEGINNER_SPEED, // Preset game-speeds.
CHAMPION_SPEED,
INC_SPEED, DEC_SPEED}; // Adjustments of speed.
const int ConcreteWall = 1;
......
......@@ -32,7 +32,6 @@
#include "kgrrulebook.h"
#include "kgrlevelgrid.h"
#include "kgrrunner.h"
#include "kgrtimer.h"
KGrLevelPlayer::KGrLevelPlayer (QObject * parent)
:
......@@ -66,7 +65,7 @@ KGrLevelPlayer::~KGrLevelPlayer()
// }
}
void KGrLevelPlayer::init (KGrCanvas * view, const Control mode,
void KGrLevelPlayer::init (KGrCanvas * view, const int mode,
const char rulesCode, const KGrLevelData * levelData)
{
// Create the internal model of the level-layout.
......
......@@ -24,9 +24,7 @@
#include <QTime> // IDW testing
#include "kgrglobals.h"
// class QTimer;
class KGrTimer;
#include "kgrtimer.h"
class KGrLevelGrid;
class KGrRuleBook;
......@@ -87,7 +85,7 @@ public:
* starting positions of hero, enemies and gold.
*/
void init (KGrCanvas * view,
const Control mode,
const int mode,
const char rulesCode,
const KGrLevelData * levelData);
......@@ -103,7 +101,7 @@ public:
* @param mode The new input-mode to use to control the hero: mouse,
* keyboard or hybrid touchpad and keyboard mode.
*/
inline void setControlMode (const Control mode) { controlMode = mode; }
inline void setControlMode (const int mode) { controlMode = mode; }
/**
* Set a point for the hero to aim at when using mouse or touchpad control.
......@@ -228,6 +226,15 @@ public:
*/
void pause (bool stop);
/**
* Sets the overall speed of gameplay.
*
* @param timeScale Value 1.0 is for normal speed. Range is 0.2 to 2.0.
* 0.5 is for beginner speed: 1.5 for champion speed.
*/
inline void setTimeScale (const float timeScale)
{ timer->setScale (timeScale); }
/**
* Implement author's debugging aids, which are activated only if the level
* is paused and the KConfig file contains group Debugging with setting
......@@ -274,7 +281,7 @@ private:
int heroId;
QList<KGrEnemy *> enemies;
Control controlMode;
int controlMode;
int levelWidth;
int levelHeight;
......
......@@ -186,7 +186,7 @@ HeroStatus KGrHero::run (const int scaledTime)
// Start the running animation (repeating).
emit startAnimation (spriteId, true, gridI, gridJ,
interval * pointsPerCell,
(interval * pointsPerCell * TickTime) / scaledTime,
nextDirection, nextAnimation);
currAnimation = nextAnimation;
currDirection = nextDirection;
......@@ -427,7 +427,7 @@ void KGrEnemy::run (const int scaledTime)
// Start the running animation (repeating).
emit startAnimation (spriteId, true, gridI, gridJ,
interval * pointsPerCell,
(interval * pointsPerCell * TickTime) / scaledTime,
nextDirection, nextAnimation);
currAnimation = nextAnimation;
currDirection = nextDirection;
......
......@@ -113,7 +113,6 @@ bool KGrSLDialog::selectLevel (int & selectedGame, int & selectedLevel)
// owner = gameData->owner;
// gameIndex = selectedGame;
// Set default rules for selected game.
// TODO - emit markRuleType (gameData->rules);
break;
}
......
......@@ -25,11 +25,11 @@ KGrTimer::KGrTimer (QObject * parent, int pTickTime, float pScale)
t (QTime()),
ticker (new QTimer (parent)),
tickTime (pTickTime),
scaledTime ((pScale * tickTime) + 0.5),
tickCount (0),
halfTick (pTickTime / 2),
expectedTime (0)
{
setScale (pScale);
connect (ticker, SIGNAL (timeout ()), this, SLOT (internalSlot()));
ticker->start (tickTime);
t.start();
......
......@@ -32,6 +32,8 @@ public:
void pause();
void resume();
void step();
inline void setScale (const float pScale)
{ scaledTime = (pScale * tickTime) + 0.5; }
signals:
void tick (bool missed, int pScaledTime);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment