]> Shamusworld >> Repos - warehouse-man-deluxe/blobdiff - src/mainwin.cpp
Converted from Qt4 to Qt5.
[warehouse-man-deluxe] / src / mainwin.cpp
index 8ba6ded2db6e07ebb5d185aa7d54f2927601d68c..18f78b3ca9bb7146dfe198103213339aed28e314 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <stdlib.h>                    // For rand()
 #include <time.h>                      // For time()
+#include "gameboard.h"
+#include "editorwindow.h"      // Actual mouse/drawing window
 #include "gamewidget.h"                // Actual mouse/drawing window
 //#include "resource.h"
 //#include "optiondlg.h"               // Options dialog class
 
 MainWin::MainWin()
 {
+       // We create the EditorWindow 1st because the GameWidget will crash if there
+       // is no level data loaded...
+       editorWindow = new EditorWindow(this);
        gameWidget = new GameWidget(this);
        setCentralWidget(gameWidget);
        gameWidget->setFocusPolicy(Qt::StrongFocus);    // Without this, it gets no keys
        setWindowTitle("Warehouse Man Deluxe");
        setWindowIcon(QIcon(":/wmd-icon.png"));
 
-       newGame = CreateAction(tr("&New"), tr("New Game"), tr("Start a new game of Warehouse Man Deluxe"), QIcon(), QKeySequence(tr("ctrl+n")));
-//     connect(newGame, SIGNAL(triggered()), this, SLOT(OnNewGame()));
+       editorWindow->show();
 
-       gamePlay = CreateAction(tr("&Play"), tr(""), tr(""), QIcon(), QKeySequence(tr("ctrl+a")));
-//     connect(gamePlay, SIGNAL(triggered()), this, SLOT(OnGamePlay()));
+       newGame = CreateAction(tr("&New"), tr("New Game"), tr("Start a new game of Warehouse Man Deluxe"), QIcon(), QKeySequence(tr("ctrl+n")));
+       connect(newGame, SIGNAL(triggered()), this, SLOT(HandleNewGame()));
 
-       helpUndo = CreateAction(tr("&Undo"), tr(""), tr(""), QIcon(), QKeySequence(tr("ctrl+z")));
-//     connect(helpUndo, SIGNAL(triggered()), this, SLOT(OnHelpUndo()));
+       undoAction = CreateAction(tr("&Undo"), tr(""), tr(""), QIcon(), QKeySequence(tr("ctrl+z")));
+       connect(undoAction, SIGNAL(triggered()), this, SLOT(HandleUndo()));
 
        resetLevel = CreateAction(tr("&Reset Level"), tr("Reset Level"), tr("Start the current level over"), QIcon(), QKeySequence(tr("ctrl+r")));
-       connect(resetLevel, SIGNAL(triggered()), this, SLOT(ResetCurrentLevel()));
+       connect(resetLevel, SIGNAL(triggered()), this, SLOT(HandleReset()));
+
+       skipLevel = CreateAction(tr("&Skip Level"), tr("Skip Level"), tr("Skip the current level"), QIcon(), QKeySequence(tr("ctrl+k")));
+       connect(skipLevel, SIGNAL(triggered()), this, SLOT(HandleSkipLevel()));
 
        gameOptions = CreateAction(tr("&Options..."), tr("Options"), tr("Configure Warehouse Man Deluxe's options"), QIcon(), QKeySequence(tr("ctrl+o")));
 //     connect(gameOptions, SIGNAL(triggered()), this, SLOT(OnGameOptions()));
@@ -57,12 +64,18 @@ MainWin::MainWin()
 //     connect(gameBoard, SIGNAL(UpdateScore(int)), this, SLOT(OnUpdateScore(int)));
        connect(gameWidget, SIGNAL(GameWasWon()), this, SLOT(WeHaveAWinner()));
 
+       // Connect editor to game widget...
+       connect(editorWindow, SIGNAL(SetupLevel(Level *)), gameWidget,
+               SLOT(HandlePlayGameFromEditor(Level *)));
+
+
        QMenu * menu = menuBar()->addMenu(tr("&Game"));
        menu->addAction(newGame);
        menu->addSeparator();
-       menu->addAction(gamePlay);
-       menu->addAction(helpUndo);
+//     menu->addAction(gamePlay);
+       menu->addAction(undoAction);
        menu->addAction(resetLevel);
+       menu->addAction(skipLevel);
        menu->addSeparator();
        menu->addAction(gameOptions);
        menu->addAction(gameStats);
@@ -78,6 +91,8 @@ MainWin::MainWin()
        QSettings settings("Underground Software", "Warehouse Man Deluxe");
        QPoint mainWinPosition = settings.value("pos", QPoint(200, 100)).toPoint();
        move(mainWinPosition);
+       QSize mainWinSize = settings.value("size", QSize(500, 500)).toSize();
+       resize(mainWinSize);
 
 /*     nCardBack = settings.value("CardBack", BACK4).toInt();
        m_nBackground = settings.value("Background", 0).toInt();
@@ -118,6 +133,7 @@ MainWin::MainWin()
 MainWin::~MainWin()
 {
 //     ShutDownAudio();
+       delete editorWindow;
 }
 
 
@@ -167,6 +183,7 @@ void MainWin::closeEvent(QCloseEvent * event)
 
        QSettings settings("Underground Software", "Warehouse Man Deluxe");
        settings.setValue("pos", pos());
+       settings.setValue("size", size());
 
 /*
        settings.setValue("CardBack", nCardBack);
@@ -206,7 +223,7 @@ void MainWin::OnUpdateScore(int n)
                s = QString(tr("Score: %1")).arg(n);
 
        gameBoard->score->setText(s);
-printf("OUS: n=%i, s=%s\n", n, s.toAscii().data());
+printf("OUS: n=%i, s=%s\n", n, s.toUtf8().data());
 }
 */
 
@@ -265,9 +282,17 @@ void MainWin::ResetGame(void)
 }
 
 
+void MainWin::HandleNewGame(void)
+{
+//     ResetGame();
+       gameWidget->level = 0;
+       gameWidget->NextLevel();
+}
+
+
 void MainWin::AboutGame(void)
 {
-       QMessageBox::about(this, tr("About Warehouse Man Deluxe"), tr("Warehouse Man Deluxe Version 1.0\n\nCopyright © 2014 Underground Software\n\nWritten by James L. Hammons"));
+       QMessageBox::about(this, tr("About Warehouse Man Deluxe"), tr("Warehouse Man Deluxe Version 1.0\n\nCopyright (C) 2014 Underground Software\n\nWritten by James Hammons"));
 }
 
 
@@ -278,12 +303,24 @@ void MainWin::WeHaveAWinner(void)
 }
 
 
-void MainWin::ResetCurrentLevel(void)
+void MainWin::HandleReset(void)
 {
        gameWidget->ResetLevel();
 }
 
 
+void MainWin::HandleSkipLevel(void)
+{
+       gameWidget->NextLevel();
+}
+
+
+void MainWin::HandleUndo(void)
+{
+       gameWidget->UndoLastMove();
+}
+
+
 #if 0
 void MainWin::OnNewGame(void) 
 {
@@ -377,7 +414,7 @@ void MainWin::OnGameStats(void)
 }
 
 
-void MainWin::OnHelpUndo(void)
+void MainWin::OnundoAction(void)
 {
        if (m_bCanUndo)
        {