diff options
-rw-r--r-- | engines/macventure/controls.cpp | 77 | ||||
-rw-r--r-- | engines/macventure/controls.h | 105 | ||||
-rw-r--r-- | engines/macventure/dialog.cpp | 39 | ||||
-rw-r--r-- | engines/macventure/dialog.h | 33 | ||||
-rw-r--r-- | engines/macventure/gui.cpp | 30 | ||||
-rw-r--r-- | engines/macventure/gui.h | 124 | ||||
-rw-r--r-- | engines/macventure/macventure.cpp | 3 | ||||
-rw-r--r-- | engines/macventure/macventure.h | 1 | ||||
-rw-r--r-- | engines/macventure/module.mk | 5 | ||||
-rw-r--r-- | engines/macventure/prebuilt_dialogs.h | 97 | ||||
-rw-r--r-- | engines/macventure/script.h | 2 | ||||
-rw-r--r-- | engines/macventure/text.h | 3 |
12 files changed, 316 insertions, 203 deletions
diff --git a/engines/macventure/controls.cpp b/engines/macventure/controls.cpp new file mode 100644 index 0000000000..f467d72de6 --- /dev/null +++ b/engines/macventure/controls.cpp @@ -0,0 +1,77 @@ +/* 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. +* +*/ + +#include "macventure/gui.h" + +namespace MacVenture { +CommandButton::CommandButton() { + _gui = nullptr; +} + +CommandButton::CommandButton(ControlData data, Gui *g) { + _data = data; + _gui = g; + _selected = false; +} + +void CommandButton::draw(Graphics::ManagedSurface &surface) const { + + uint colorFill = _selected ? kColorBlack : kColorWhite; + uint colorText = _selected ? kColorWhite : kColorBlack; + + surface.fillRect(_data.bounds, colorFill); + surface.frameRect(_data.bounds, kColorBlack); + + if (_data.titleLength > 0) { + const Graphics::Font &font = _gui->getCurrentFont(); + Common::String title(_data.title); + font.drawString( + &surface, + title, + _data.bounds.left, + _data.bounds.top, + _data.bounds.right - _data.bounds.left, + colorText, + Graphics::kTextAlignCenter); + } +} + +bool CommandButton::isInsideBounds(const Common::Point point) const { + return _data.bounds.contains(point); +} + +const ControlData& CommandButton::getData() const { + return _data; +} + +void CommandButton::select() { + _selected = true; +} + +void CommandButton::unselect() { + _selected = false; +} + +bool CommandButton::isSelected() { + return _selected; +} +} diff --git a/engines/macventure/controls.h b/engines/macventure/controls.h new file mode 100644 index 0000000000..a780f6328b --- /dev/null +++ b/engines/macventure/controls.h @@ -0,0 +1,105 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_CONTROLS_H +#define MACVENTURE_CONTROLS_H + +namespace MacVenture { + +class Gui; + +enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc) + kControlExitBox = 0, + kControlExamine = 1, + kControlOpen = 2, + kControlClose = 3, + kControlSpeak = 4, + kControlOperate = 5, + kControlGo = 6, + kControlHit = 7, + kControlConsume = 8, + kControlClickToContinue = 9 +}; + +enum ControlAction { // HACK, figure out a way to put it in engine + kNoCommand = 0, + kStartOrResume = 1, + kClose = 2, + kTick = 3, + kActivateObject = 4, + kMoveObject = 5, + kConsume = 6, + kExamine = 7, + kGo = 8, + kHit = 9, + kOpen = 10, + kOperate = 11, + kSpeak = 12, + kBabble = 13, + kTargetName = 14, + kDebugObject = 15, + kClickToContinue = 16 +}; +struct ControlData { + Common::Rect bounds; + uint16 scrollValue; + uint8 visible; + uint16 scrollMax; + uint16 scrollMin; + uint16 cdef; + ControlAction refcon; + ControlType type; + uint8 titleLength; + char* title; + uint16 border; +}; + +class CommandButton { + +enum { + kCommandsLeftPadding = 0, + kCommandsTopPadding = 0 +}; + +public: + + CommandButton(); + + CommandButton(ControlData data, Gui *g); + ~CommandButton() {} + + void draw(Graphics::ManagedSurface &surface) const; + bool isInsideBounds(const Common::Point point) const; + const ControlData& getData() const; + void select(); + void unselect(); + bool isSelected(); + +private: + bool _selected; + ControlData _data; + Gui *_gui; +}; + +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/dialog.cpp b/engines/macventure/dialog.cpp index ba489d4bad..a6c1e78a6f 100644 --- a/engines/macventure/dialog.cpp +++ b/engines/macventure/dialog.cpp @@ -23,47 +23,8 @@ #include "common/system.h" #include "macventure/dialog.h" - namespace MacVenture { -// Prebuilt dialogs - -enum { - // HACK - kMaxPrebuiltDialogElements = 10 -}; - -struct PrebuiltDialog { - Common::Rect bounds; - PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; -}; - -PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { - - {/* kSaveAsDialog */ - Common::Rect(0, 146, 456, 254), - { - {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, - {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, - {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, - {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - }, - - { /* kSpeakDialog */ - Common::Rect(20, 92, 400, 200), - { - {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, - {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, - {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - } - -}; Dialog::Dialog(Gui *gui, Common::Point pos, uint width, uint height) : _gui(gui), _bounds(Common::Rect(pos.x, pos.y, pos.x + width, pos.y + height)) {} diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index e773956b09..66d68e358e 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -26,44 +26,13 @@ #include "graphics/macgui/macwindowmanager.h" #include "macventure/macventure.h" -#include "macventure/gui.h" - +#include "macventure/prebuilt_dialogs.h" namespace MacVenture { using namespace Graphics::MacGUIConstants; class Gui; - class DialogElement; -enum DialogAction { - kDANone, - kDACloseDialog, - kDASubmit, - kDASaveAs -}; - -enum PrebuiltDialogs { - kSaveAsDialog = 0, - kSpeakDialog = 1, - kPrebuiltDialogCount -}; - -enum PrebuiltElementType { - kDEPlainText, - kDEButton, - kDETextInput, - kDEEnd -}; - -struct PrebuiltDialogElement { - PrebuiltElementType type; - Common::String title; - DialogAction action; - Common::Point position; - uint width; - uint height; -}; - class Dialog { public: Dialog(Gui *gui, Common::Point pos, uint width, uint height); diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d38a7a5c3d..d8db6656e5 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -20,14 +20,14 @@ * */ + #include "common/file.h" +#include "common/timer.h" +#include "common/system.h" #include "image/bmp.h" -#include "macventure/macventure.h" #include "macventure/gui.h" - -#include "common/timer.h" -#include "common/system.h" +#include "macventure/dialog.h" namespace MacVenture { @@ -36,12 +36,12 @@ namespace MacVenture { enum MenuAction; enum { - kCursorWidth = 2, // HACK Arbitrary width to test + kCursorWidth = 2, kCursorHeight = 2 }; enum { - kExitButtonWidth = 10, // HACK Arbitrary width to test + kExitButtonWidth = 10, kExitButtonHeight = 10 }; @@ -802,10 +802,20 @@ void Gui::printText(const Common::String & text) { _consoleText->printLine(text, _outConsoleWindow->getDimensions().width()); } +void Gui::showPrebuiltDialog(PrebuiltDialogs type) { + closeDialog(); + _dialog = new Dialog(this, type); +} + +bool Gui::isDialogOpen() { + return _dialog != nullptr; +} + void Gui::setTextInput(Common::String str) { _engine->setTextInput(str); } + void Gui::closeDialog() { delete _dialog; _dialog = nullptr; @@ -815,9 +825,7 @@ void Gui::getTextFromUser() { if (_dialog) { delete _dialog; } - _dialog = new Dialog(this, kSpeakDialog); - // Hack to pause the engine - _engine->clickToContinue(); + showPrebuiltDialog(kSpeakDialog); } void Gui::loadGame(int slot) { @@ -1046,8 +1054,7 @@ void Gui::handleMenuAction(MenuAction action) { break; case MacVenture::kMenuActionSaveAs: debug("MacVenture Menu Action: Save As"); - // HACK this should be wrapped in a function - _dialog = new Dialog(this, kSaveAsDialog); + showPrebuiltDialog(kSaveAsDialog); break; case MacVenture::kMenuActionQuit: debug("MacVenture Menu Action: Quit"); @@ -1140,6 +1147,7 @@ void Gui::invertWindowColors(WindowReference winID) { } } + bool Gui::tryCloseWindow(WindowReference winID) { WindowData data = findWindowData(winID); if (winID < 0x80) { // Inventory window diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index b03ca2afe9..eb929cfcdd 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -29,9 +29,12 @@ #include "graphics/font.h" +#include "macventure/macventure.h" #include "macventure/container.h" #include "macventure/image.h" +#include "macventure/prebuilt_dialogs.h" #include "macventure/dialog.h" +#include "macventure/controls.h" namespace MacVenture { @@ -114,53 +117,6 @@ struct WindowData { bool updateScroll; }; -enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc) - kControlExitBox = 0, - kControlExamine = 1, - kControlOpen = 2, - kControlClose = 3, - kControlSpeak = 4, - kControlOperate = 5, - kControlGo = 6, - kControlHit = 7, - kControlConsume = 8, - kControlClickToContinue = 9 -}; - -enum ControlAction { // HACK, figure out a way to put it in engine - kNoCommand = 0, - kStartOrResume = 1, - kClose = 2, - kTick = 3, - kActivateObject = 4, - kMoveObject = 5, - kConsume = 6, - kExamine = 7, - kGo = 8, - kHit = 9, - kOpen = 10, - kOperate = 11, - kSpeak = 12, - kBabble = 13, - kTargetName = 14, - kDebugObject = 15, - kClickToContinue = 16 -}; - -struct ControlData { - Common::Rect bounds; - uint16 scrollValue; - uint8 visible; - uint16 scrollMax; - uint16 scrollMin; - uint16 cdef; - ControlAction refcon; - ControlType type; - uint8 titleLength; - char* title; - uint16 border; -}; - struct BorderBounds { uint16 leftOffset; uint16 topOffset; @@ -204,6 +160,7 @@ public: void updateWindow(WindowReference winID, bool containerOpen); void invertWindowColors(WindowReference winID); + WindowReference createInventoryWindow(ObjID objRef); bool tryCloseWindow(WindowReference winID); @@ -223,8 +180,6 @@ public: void processCursorTick(); - //bool processClickObject(ObjID obj, WindowReference win, Common::Event event, bool canDrag); - const WindowData& getWindowData(WindowReference reference); const Graphics::Font& getCurrentFont(); @@ -248,6 +203,9 @@ public: void printText(const Common::String &text); //Dialog interactions + void showPrebuiltDialog(PrebuiltDialogs type); + bool isDialogOpen(); + void getTextFromUser(); void setTextInput(Common::String str); void closeDialog(); @@ -428,74 +386,6 @@ private: }; -class CommandButton { - -enum { - kCommandsLeftPadding = 0, - kCommandsTopPadding = 0 -}; - -public: - - CommandButton() { - _gui = nullptr; - } - - CommandButton(ControlData data, Gui *g) { - _data = data; - _gui = g; - _selected = false; - } - ~CommandButton() {} - - void draw(Graphics::ManagedSurface &surface) const { - - uint colorFill = _selected ? kColorBlack : kColorWhite; - uint colorText = _selected ? kColorWhite : kColorBlack; - - surface.fillRect(_data.bounds, colorFill); - surface.frameRect(_data.bounds, kColorBlack); - - if (_data.titleLength > 0) { - const Graphics::Font &font = _gui->getCurrentFont(); - Common::String title(_data.title); - font.drawString( - &surface, - title, - _data.bounds.left, - _data.bounds.top, - _data.bounds.right - _data.bounds.left, - colorText, - Graphics::kTextAlignCenter); - } - } - - bool isInsideBounds(const Common::Point point) const { - return _data.bounds.contains(point); - } - - const ControlData& getData() const { - return _data; - } - - void select() { - _selected = true; - } - - void unselect() { - _selected = false; - } - - bool isSelected() { - return _selected; - } - -private: - bool _selected; - ControlData _data; - Gui *_gui; -}; - class ConsoleText { public: diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 9d437612f0..6cb6db5d42 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -126,7 +126,7 @@ Common::Error MacVentureEngine::run() { if (_gameState != kGameStateQuitting) { - if (_prepared) { + if (_prepared && !_gui->isDialogOpen()) { _prepared = false; if (!_halted) @@ -148,6 +148,7 @@ Common::Error MacVentureEngine::run() { if (_gameState == kGameStateWinnig || _gameState == kGameStateLosing) { endGame(); + return Common::kNoError; } } _gui->draw(); diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 167abcc351..9d1677dd6b 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -39,6 +39,7 @@ #include "macventure/hufflists.h" #include "macventure/stringtable.h" #include "macventure/script.h" +#include "controls.h" struct ADGameDescription; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 813677c33c..66039d4c9f 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -3,13 +3,14 @@ MODULE := engines/macventure MODULE_OBJS := \ image.o \ detection.o \ - gui.o \ object.o \ text.o \ world.o \ script.o \ macventure.o \ - dialog.o + gui.o \ + dialog.o \ + controls.o MODULE_DIRS += \ engines/macventure diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h new file mode 100644 index 0000000000..34df91e51b --- /dev/null +++ b/engines/macventure/prebuilt_dialogs.h @@ -0,0 +1,97 @@ + +/* 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. +* +*/ + +#ifndef MACVENTURE_PREBUIT_DIALOGS_H +#define MACVENTURE_PREBUIT_DIALOGS_H + +namespace MacVenture { +enum DialogAction { + kDANone, + kDACloseDialog, + kDASubmit, + kDASaveAs +}; + +enum PrebuiltDialogs { + kSaveAsDialog = 0, + kSpeakDialog = 1, + kPrebuiltDialogCount +}; + +enum PrebuiltElementType { + kDEPlainText, + kDEButton, + kDETextInput, + kDEEnd +}; + +struct PrebuiltDialogElement { + PrebuiltElementType type; + Common::String title; + DialogAction action; + Common::Point position; + uint width; + uint height; +}; + + +// Prebuilt dialogs +enum { + // HACK + kMaxPrebuiltDialogElements = 10 +}; + +struct PrebuiltDialog { + Common::Rect bounds; + PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; +}; + +PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { + + {/* kSaveAsDialog */ + Common::Rect(0, 146, 456, 254), + { + {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, + {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, + {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, + {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + }, + + { /* kSpeakDialog */ + Common::Rect(20, 92, 400, 200), + { + {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, + {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, + {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + } + +}; +} // End of namespace MacVenture + +#endif diff --git a/engines/macventure/script.h b/engines/macventure/script.h index 49b69874e6..5760a31e8a 100644 --- a/engines/macventure/script.h +++ b/engines/macventure/script.h @@ -25,6 +25,8 @@ #include "macventure/container.h" #include "macventure/world.h" +#include "macventure/macventure.h" +#include "macventure/controls.h" namespace MacVenture { diff --git a/engines/macventure/text.h b/engines/macventure/text.h index 2389454042..88dd112681 100644 --- a/engines/macventure/text.h +++ b/engines/macventure/text.h @@ -28,6 +28,7 @@ namespace MacVenture { typedef uint32 ObjID; +class MacVentureEngine; class TextAsset { public: @@ -53,7 +54,7 @@ private: ObjID _sourceObj; const HuffmanLists *_huffman; bool _isOld; - + Common::String _decoded; }; |