aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/cge2/cge2.h66
-rw-r--r--engines/cge2/cge2_main.cpp23
-rw-r--r--engines/cge2/cge2_main.h15
-rw-r--r--engines/cge2/module.mk3
-rw-r--r--engines/cge2/vmenu.cpp154
-rw-r--r--engines/cge2/vmenu.h86
6 files changed, 307 insertions, 40 deletions
diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h
index db79c64d7c..17d68fb221 100644
--- a/engines/cge2/cge2.h
+++ b/engines/cge2/cge2.h
@@ -60,31 +60,50 @@ class EventManager;
class Font;
class Map;
-#define kScrWidth 320
-#define kScrHeight 240
-#define kScrDepth 480
-#define kPanHeight 40
-#define kWorldHeight (kScrHeight - kPanHeight)
-#define kMaxFile 128
-#define kPathMax 128
-#define kDimMax 8
-#define kWayMax 10
-#define kPocketMax 4
-#define kSceneMax 100
-#define kMaxPoint 4
-#define kInfoX 160
-#define kInfoY -11
-#define kInfoW 180
-#define kPocketsWidth 59
-#define kLineMax 512
+#define kScrWidth 320
+#define kScrHeight 240
+#define kScrDepth 480
+#define kPanHeight 40
+#define kWorldHeight (kScrHeight - kPanHeight)
+#define kMaxFile 128
+#define kPathMax 128
+#define kDimMax 8
+#define kWayMax 10
+#define kPocketMax 4
+#define kSceneMax 100
+#define kMaxPoint 4
+#define kInfoX 160
+#define kInfoY -11
+#define kInfoW 180
+#define kPocketsWidth 59
+#define kLineMax 512
-#define kExitOkText 40
-#define kCrackedText 44
-#define kOffUseCount 130
-#define kOffUseText 131
+#define kIntroExt ".I80"
+#define kTabName "CGE.TAB"
+#define kPocketFull 170
+#define kGameFrameDelay (750 / 50)
+#define kGameTickDelay (750 / 62)
-#define kSysTimeRate 6 // 12 Hz
-#define kBlinkRate 4 // 3 Hz
+#define kMusicRef 122
+#define kPowerRef 123
+#define kDvolRef 124
+#define kMvolRef 125
+#define kRef 126
+#define kBusyRef 127
+#define kCapRef 128
+#define kVoxRef 129
+
+#define kExitOkText 40
+#define kCrackedText 44
+#define kOffUseCount 130
+#define kOffUseText 131
+
+#define kSysTimeRate 6 // 12 Hz
+#define kBlinkRate 4 // 3 Hz
+
+#define kQuitTitle 200
+#define kQuitText 201
+#define kNoQuitText 202
enum CallbackType {
kNullCB = 0, kQGame, kXScene, kSoundSetVolume
@@ -149,6 +168,7 @@ public:
int sgn(long n);
int mapCross(const V2D &a, const V2D &b);
Sprite *spriteAt(V2D pos);
+ void keyClick();
void optionTouch(int opt, uint16 mask);
void switchColorMode();
diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp
index f16f0ce340..34e7cfe50f 100644
--- a/engines/cge2/cge2_main.cpp
+++ b/engines/cge2/cge2_main.cpp
@@ -35,6 +35,7 @@
#include "cge2/spare.h"
#include "cge2/events.h"
#include "cge2/map.h"
+#include "cge2/vmenu.h"
namespace CGE2 {
@@ -1075,7 +1076,27 @@ void CGE2Engine::switchMusic() {
}
void CGE2Engine::quit() {
- warning("STUB: CGE2Engine::quit()");
+ Common::Array<Choice *> quitMenu; // Deleted in VMenu's destructor.
+ quitMenu.push_back(new StartCountDownChoice(this));
+ quitMenu.push_back(new ResetQSwitchChoice(this));
+
+ if (_commandHandler->idle()) {
+ if (VMenu::_addr) {
+ _commandHandlerTurbo->addCommand(kCmdKill, -1, 0, VMenu::_addr);
+ ResetQSwitchChoice rqsChoice(this);
+ rqsChoice.proc();
+ } else {
+ quitMenu[0]->_text = _text->getText(kQuitText);
+ quitMenu[1]->_text = _text->getText(kNoQuitText);
+ (new VMenu(this, quitMenu, V2D(this, -1, -1), kCBMnu))->setName(_text->getText(kQuitTitle));
+ _commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 0, nullptr);
+ keyClick();
+ }
+ }
+}
+
+void CGE2Engine::keyClick() {
+ _commandHandlerTurbo->addCommand(kCmdSound, -1, 5, nullptr);
}
void CGE2Engine::setVolume(int idx, int cnt) {
diff --git a/engines/cge2/cge2_main.h b/engines/cge2/cge2_main.h
index e59c6f0b45..d6f2371964 100644
--- a/engines/cge2/cge2_main.h
+++ b/engines/cge2/cge2_main.h
@@ -32,21 +32,6 @@
namespace CGE2 {
-#define kIntroExt ".I80"
-#define kTabName "CGE.TAB"
-#define kPocketFull 170
-#define kGameFrameDelay (750 / 50)
-#define kGameTickDelay (750 / 62)
-
-#define kMusicRef 122
-#define kPowerRef 123
-#define kDvolRef 124
-#define kMvolRef 125
-#define kRef 126
-#define kBusyRef 127
-#define kCapRef 128
-#define kVoxRef 129
-
class System : public Sprite {
public:
int _funDel;
diff --git a/engines/cge2/module.mk b/engines/cge2/module.mk
index dc74de5ed6..9a6e0cb595 100644
--- a/engines/cge2/module.mk
+++ b/engines/cge2/module.mk
@@ -14,7 +14,8 @@ MODULE_OBJS = \
spare.o \
talk.o \
events.o \
- map.o
+ map.o \
+ vmenu.o
# This module can be built as a plugin
ifeq ($(ENABLE_CGE2), DYNAMIC_PLUGIN)
diff --git a/engines/cge2/vmenu.cpp b/engines/cge2/vmenu.cpp
new file mode 100644
index 0000000000..55ddc2aec0
--- /dev/null
+++ b/engines/cge2/vmenu.cpp
@@ -0,0 +1,154 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This code is based on original Sfinx source code
+ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon
+ */
+
+#include "cge2/cge2.h"
+#include "cge2/vmenu.h"
+#include "cge2/events.h"
+
+namespace CGE2 {
+
+void StartCountDownChoice::proc() {
+ _vm->switchScene(-1);
+}
+
+void ResetQSwitchChoice::proc() {
+ _vm->_commandHandlerTurbo->addCommand(kCmdSeq, kPowerRef, 1, nullptr);
+ _vm->keyClick();
+}
+
+MenuBar::MenuBar(CGE2Engine *vm, uint16 w, byte *c) : Talk(vm) {
+ _color = c;
+ int h = kFontHigh + 2 * kMenuBarVerticalMargin, i = (w += 2 * kMenuBarHorizontalMargin) * h;
+ uint8 *p = new uint8[i];
+ uint8 *p1;
+ uint8 *p2;
+ uint8 lt = _color[kLt];
+ uint8 rb = _color[kRb];
+ BitmapPtr b;
+
+ memset(p + w, kPixelTransp, i - 2 * w);
+ memset(p, lt, w);
+ memset(p + i - w, rb, w);
+ p1 = p;
+ p2 = p + i - 1;
+ for (i = 0; i < h; i++) {
+ *p1 = lt;
+ *p2 = rb;
+ p1 += w;
+ p2 -= w;
+ }
+ b = new Bitmap[1];
+ b[0] = Bitmap(vm, w, h, p);
+ delete[] p;
+ setShapeList(b, 1);
+ _flags._slav = true;
+ _flags._tran = true;
+ _flags._kill = true;
+}
+
+VMenu *VMenu::_addr = nullptr;
+
+VMenu::VMenu(CGE2Engine *vm, Common::Array<Choice *> list, V2D pos, ColorBank col)
+ : Talk(vm, vmGather(list), kTBRect, col), _menu(list), _bar(nullptr), _items(list.size()), _vm(vm) {
+ delete[] _vmgt; // Lefotver of vmGather.
+
+ _addr = this;
+ _recent = -1;
+ _flags._kill = true;
+
+ if (pos.x < 0 || pos.y < 0)
+ center();
+ else
+ gotoxyz(V2D(_vm, pos.x - _siz.x / 2, pos.y - (kTextVMargin + kFontHigh / 2)));
+
+ _vm->_vga->_showQ->append(this);
+ _bar = new MenuBar(_vm, _siz.x - 2 * kTextHMargin, _color);
+ _bar->gotoxyz(V2D(_vm, _pos2D.x, _pos2D.y + kTextVMargin - kMenuBarVerticalMargin));
+ _vm->_vga->_showQ->append(_bar);
+}
+
+char *VMenu::vmGather(Common::Array<Choice *> list) {
+ int len = 0;
+ int h = 0;
+
+ for (int i = 0; i < list.size(); i++) {
+ len += strlen(list[i]->_text);
+ ++h;
+ }
+ _vmgt = new char[len + h];
+ if (_vmgt) {
+ *_vmgt = '\0';
+ for (int i = 0; i < list.size(); i++) {
+ if (*_vmgt)
+ strcat(_vmgt, "|");
+ strcat(_vmgt, list[i]->_text);
+ ++h;
+ }
+ }
+ return _vmgt;
+}
+
+
+VMenu::~VMenu() {
+ _addr = nullptr;
+
+ for (int i = 0; i < _menu.size(); i++) {
+ delete _menu[i];
+ }
+}
+
+void VMenu::touch(uint16 mask, V2D pos, Common::KeyCode keyCode) {
+ int h = kFontHigh + kTextLineSpace;
+ int n = 0;
+ bool ok = false;
+
+ if (_items) {
+ Sprite::touch(mask, pos, keyCode);
+
+ pos.y -= kTextVMargin - 1;
+ if (pos.y >= 0) {
+ if (pos.x < 0)
+ pos.x = -pos.x;
+ n = pos.y / h;
+ if (n < _items)
+ ok = (pos.x <= (_siz.x >> 1) - kTextHMargin);
+ else
+ n = _items - 1;
+ }
+
+ _bar->gotoxyz(V2D(_vm, _pos2D.x, _pos2D.y + kTextVMargin + n * h - kMenuBarVerticalMargin));
+ n = _items - 1 - n;
+
+ if (ok && (mask & kMouseLeftUp)) {
+ _items = 0;
+ _vm->_commandHandlerTurbo->addCommand(kCmdKill, -1, 0, this);
+ _menu[_recent = n]->proc();
+ }
+ }
+}
+
+} // End of namespace CGE2
diff --git a/engines/cge2/vmenu.h b/engines/cge2/vmenu.h
new file mode 100644
index 0000000000..c988e1ed2b
--- /dev/null
+++ b/engines/cge2/vmenu.h
@@ -0,0 +1,86 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This code is based on original Sfinx source code
+ * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon
+ */
+
+#ifndef CGE2_VMENU_H
+#define CGE2_VMENU_H
+
+#define kMenuBarVerticalMargin 1
+#define kMenuBarHorizontalMargin 3
+#define kLt 3
+#define kRb 1
+
+#include "cge2/talk.h"
+
+namespace CGE2 {
+
+class Choice {
+protected:
+ CGE2Engine *_vm;
+public:
+ char *_text;
+ virtual void proc() = 0;
+
+ Choice(CGE2Engine *vm) : _vm(vm), _text(nullptr) {}
+};
+
+class StartCountDownChoice : public Choice {
+public:
+ StartCountDownChoice(CGE2Engine *vm) : Choice(vm) {}
+ void proc();
+};
+
+class ResetQSwitchChoice : public Choice {
+public:
+ ResetQSwitchChoice(CGE2Engine *vm) : Choice(vm) {}
+ void proc();
+};
+
+class MenuBar : public Talk {
+public:
+ MenuBar(CGE2Engine *vm, uint16 w, byte *c);
+};
+
+class VMenu : public Talk {
+ CGE2Engine *_vm;
+
+ uint16 _items;
+ Common::Array<Choice *> _menu;
+public:
+ char *_vmgt;
+ static VMenu *_addr;
+ int _recent;
+ MenuBar *_bar;
+
+ VMenu(CGE2Engine *vm, Common::Array<Choice *> list, V2D pos, ColorBank col);
+ ~VMenu(void);
+ void touch(uint16 mask, V2D pos, Common::KeyCode keyCode);
+ char *vmGather(Common::Array<Choice *> list);
+};
+
+} // End of namespace CGE2
+
+#endif // CGE2_VMENU_H