diff options
Diffstat (limited to 'engines/wage/gui.cpp')
-rw-r--r-- | engines/wage/gui.cpp | 440 |
1 files changed, 101 insertions, 339 deletions
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 2841013a26..310e5734b7 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -46,10 +46,8 @@ */ #include "common/timer.h" -#include "common/unzip.h" +#include "common/system.h" #include "graphics/cursorman.h" -#include "graphics/fonts/bdf.h" -#include "graphics/palette.h" #include "graphics/primitives.h" #include "wage/wage.h" @@ -58,60 +56,30 @@ #include "wage/gui.h" #include "wage/macwindow.h" #include "wage/macwindowmanager.h" -#include "wage/menu.h" +#include "wage/macmenu.h" #include "wage/world.h" namespace Wage { -static const byte palette[] = { - 0, 0, 0, // Black - 0x80, 0x80, 0x80, // Gray - 0xff, 0xff, 0xff, // White - 0x00, 0xff, 0x00, // Green - 0x00, 0xcf, 0x00 // Green2 -}; - -static byte fillPatterns[][8] = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, // kPatternSolid - { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }, // kPatternStripes - { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa } // kPatternCheckers2 -}; - -static const byte macCursorArrow[] = { - 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 0, 2, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 0, 0, 2, 3, 3, 3, 3, 3, 3, 3, - 2, 0, 0, 0, 2, 3, 3, 3, 3, 3, 3, - 2, 0, 0, 0, 0, 2, 3, 3, 3, 3, 3, - 2, 0, 0, 0, 0, 0, 2, 3, 3, 3, 3, - 2, 0, 0, 0, 0, 0, 0, 2, 3, 3, 3, - 2, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, - 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, - 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, - 2, 0, 0, 2, 0, 0, 2, 3, 3, 3, 3, - 2, 0, 2, 3, 2, 0, 0, 2, 3, 3, 3, - 2, 2, 3, 3, 2, 0, 0, 2, 3, 3, 3, - 2, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3, - 3, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3, - 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 3 -}; - -static const byte macCursorBeam[] = { - 0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3, - 3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3, - 0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3, +static const MenuData menuSubItems[] = { + { kMenuHighLevel, "File", 0, 0, false }, + { kMenuHighLevel, "Edit", 0, 0, false }, + { kMenuFile, "New", kMenuActionNew, 0, false }, + { kMenuFile, "Open...", kMenuActionOpen, 0, false }, + { kMenuFile, "Close", kMenuActionClose, 0, true }, + { kMenuFile, "Save", kMenuActionSave, 0, false }, + { kMenuFile, "Save as...", kMenuActionSaveAs, 0, true }, + { kMenuFile, "Revert", kMenuActionRevert, 0, false }, + { kMenuFile, "Quit", kMenuActionQuit, 0, true }, + + { kMenuEdit, "Undo", kMenuActionUndo, 'Z', false }, + { kMenuEdit, NULL, 0, 0, false }, + { kMenuEdit, "Cut", kMenuActionCut, 'K', false }, + { kMenuEdit, "Copy", kMenuActionCopy, 'C', false }, + { kMenuEdit, "Paste", kMenuActionPaste, 'V', false }, + { kMenuEdit, "Clear", kMenuActionClear, 'B', false }, + + { 0, NULL, 0, 0, false } }; static void cursorTimerHandler(void *refCon) { @@ -144,13 +112,14 @@ static void cursorTimerHandler(void *refCon) { static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *gui); static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *gui); +static void menuCommandsCallback(int action, Common::String &text, void *data); + Gui::Gui(WageEngine *engine) { _engine = engine; _scene = NULL; _sceneDirty = true; _consoleDirty = true; - _menuDirty = true; _cursorDirty = false; _consoleFullRedraw = true; _screen.create(g_system->getWidth(), g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8()); @@ -160,7 +129,6 @@ Gui::Gui(WageEngine *engine) { _scrollPos = 0; _consoleLineHeight = 8; // Dummy value which makes sense _consoleNumLines = 24; // Dummy value - _builtInFonts = false; _cursorX = 0; _cursorY = 0; @@ -173,26 +141,32 @@ Gui::Gui(WageEngine *engine) { _inputTextLineNum = 0; - g_system->getPaletteManager()->setPalette(palette, 0, ARRAYSIZE(palette) / 3); + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "wageCursor"); - CursorMan.replaceCursorPalette(palette, 0, 4); - CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3); - _cursorIsArrow = true; - CursorMan.showMouse(true); + _menu = _wm.addMenu(); - for (int i = 0; i < ARRAYSIZE(fillPatterns); i++) - _patterns.push_back(fillPatterns[i]); + _menu->setCommandsCallback(menuCommandsCallback, this); - loadFonts(); + _menu->addStaticMenus(menuSubItems); + _menu->addMenuSubItem(kMenuAbout, _engine->_world->getAboutMenuItemName(), kMenuActionAbout); - g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "wageCursor"); + _commandsMenuId = _menu->addMenuItem(_engine->_world->_commandsMenuName.c_str()); + regenCommandsMenu(); + + if (!_engine->_world->_weaponMenuDisabled) { + _weaponsMenuId = _menu->addMenuItem(_engine->_world->_weaponsMenuName.c_str()); - _menu = new Menu(this); + regenWeaponsMenu(); + } else { + _weaponsMenuId = -1; + } + + _menu->calcDimensions(); - _sceneWindow = _wm.addWindow(false, false); + _sceneWindow = _wm.addWindow(false, false, false); _sceneWindow->setCallback(sceneWindowCallback, this); - _consoleWindow = _wm.addWindow(true, true); + _consoleWindow = _wm.addWindow(true, true, true); _consoleWindow->setCallback(consoleWindowCallback, this); } @@ -200,7 +174,6 @@ Gui::~Gui() { _screen.free(); _console.free(); g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); - delete _menu; } void Gui::undrawCursor() { @@ -210,35 +183,9 @@ void Gui::undrawCursor() { _cursorOff = false; } -const Graphics::Font *Gui::getFont(const char *name, Graphics::FontManager::FontUsage fallback) { - const Graphics::Font *font = 0; - - if (!_builtInFonts) { - font = FontMan.getFontByName(name); - - if (!font) - warning("Cannot load font %s", name); - } - - if (_builtInFonts || !font) - font = FontMan.getFontByUsage(fallback); - - return font; -} - -const Graphics::Font *Gui::getTitleFont() { - return getFont("Chicago-12", Graphics::FontManager::kBigGUIFont); -} - void Gui::draw() { if (_engine->_isGameOver) { - if (_menuDirty) { - _wm.setFullRefresh(true); - _wm.draw(); - _menu->render(); - } - - _menuDirty = false; + _wm.draw(); return; } @@ -263,10 +210,7 @@ void Gui::draw() { _wm.draw(); - if (_menuDirty) - _menu->render(); - - if (_cursorDirty) { + if (_cursorDirty && _cursorRect.left < _screen.w && _cursorRect.bottom < _screen.h) { g_system->copyRectToScreen(_screen.getBasePtr(_cursorRect.left, _cursorRect.top), _screen.pitch, _cursorRect.left, _cursorRect.top, _cursorRect.width(), _cursorRect.height()); @@ -275,7 +219,6 @@ void Gui::draw() { _sceneDirty = false; _consoleDirty = false; - _menuDirty = false; _consoleFullRedraw = false; } @@ -288,7 +231,7 @@ void Gui::drawScene() { _sceneDirty = true; _consoleDirty = true; - _menuDirty = true; + _menu->setDirty(true); _consoleFullRedraw = true; } @@ -299,11 +242,6 @@ static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *g } bool Gui::processSceneEvents(WindowClick click, Common::Event &event) { - if (_cursorIsArrow == false) { - CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3); - _cursorIsArrow = true; - } - if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) { Designed *obj = _scene->lookUpEntity(event.mouse.x - _sceneWindow->getDimensions().left, event.mouse.y - _sceneWindow->getDimensions().top); @@ -333,265 +271,89 @@ static bool consoleWindowCallback(WindowClick click, Common::Event &event, void return gui->processConsoleEvents(click, event); } -bool Gui::processConsoleEvents(WindowClick click, Common::Event &event) { - if (click != kBorderInner && _cursorIsArrow == false) { - CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3); - _cursorIsArrow = true; - } - - if (click == kBorderScrollUp || click == kBorderScrollDown) { - if (event.type == Common::EVENT_LBUTTONDOWN) { - int consoleHeight = _consoleWindow->getInnerDimensions().height(); - int textFullSize = _lines.size() * _consoleLineHeight + consoleHeight; - float scrollPos = (float)_scrollPos / textFullSize; - float scrollSize = (float)consoleHeight / textFullSize; - - _consoleWindow->setScroll(scrollPos, scrollSize); - - return true; - } else if (event.type == Common::EVENT_LBUTTONUP) { - int oldScrollPos = _scrollPos; - - switch (click) { - case kBorderScrollUp: - _scrollPos = MAX<int>(0, _scrollPos - _consoleLineHeight); - undrawCursor(); - _cursorY -= (_scrollPos - oldScrollPos); - _consoleDirty = true; - _consoleFullRedraw = true; - break; - case kBorderScrollDown: - _scrollPos = MIN<int>((_lines.size() - 2) * _consoleLineHeight, _scrollPos + _consoleLineHeight); - undrawCursor(); - _cursorY -= (_scrollPos - oldScrollPos); - _consoleDirty = true; - _consoleFullRedraw = true; - break; - default: - return false; - } - - return true; - } - - return false; - } - - if (click == kBorderResizeButton) { - _consoleDirty = true; - _consoleFullRedraw = true; - - return true; - } - - if (click == kBorderInner) { - if (event.type == Common::EVENT_LBUTTONDOWN) { - startMarking(event.mouse.x, event.mouse.y); - - return true; - } else if (event.type == Common::EVENT_LBUTTONUP) { - if (_inTextSelection) { - _inTextSelection = false; - - if (_selectionEndY == -1 || - (_selectionEndX == _selectionStartX && _selectionEndY == _selectionStartY)) { - _selectionStartY = _selectionEndY = -1; - _consoleFullRedraw = true; - _menu->enableCommand(kMenuEdit, kMenuActionCopy, false); - } else { - _menu->enableCommand(kMenuEdit, kMenuActionCopy, true); - - bool cutAllowed = false; - - if (_selectionStartY == _selectionEndY && _selectionStartY == (int)_lines.size() - 1) - cutAllowed = true; - - _menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed); - _menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed); - } - } - - return true; - } else if (event.type == Common::EVENT_MOUSEMOVE) { - if (_inTextSelection) { - updateTextSelection(event.mouse.x, event.mouse.y); - return true; - } - - if (_cursorIsArrow) { - CursorMan.replaceCursor(macCursorBeam, 11, 16, 3, 8, 3); - _cursorIsArrow = false; - } - } - - return false; - } - - return false; +//////////////// +// Menu stuff +//////////////// +void Gui::regenCommandsMenu() { + _menu->createSubMenuFromString(_commandsMenuId, _engine->_world->_commandsMenu.c_str()); } -void Gui::loadFonts() { - Common::Archive *dat; - - dat = Common::makeZipArchive("wage.dat"); - - if (!dat) { - warning("Could not find wage.dat. Falling back to built-in fonts"); - _builtInFonts = true; - +void Gui::regenWeaponsMenu() { + if (_engine->_world->_weaponMenuDisabled) return; - } - Common::ArchiveMemberList list; - dat->listMembers(list); + _menu->clearSubMenu(_weaponsMenuId); - for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) { - Common::SeekableReadStream *stream = dat->createReadStreamForMember((*it)->getName()); + Chr *player = _engine->_world->_player; + ObjArray *weapons = player->getWeapons(true); - Graphics::BdfFont *font = Graphics::BdfFont::loadFont(*stream); + bool empty = true; - delete stream; + for (uint i = 0; i < weapons->size(); i++) { + Obj *obj = (*weapons)[i]; + if (obj->_type == Obj::REGULAR_WEAPON || + obj->_type == Obj::THROW_WEAPON || + obj->_type == Obj::MAGICAL_OBJECT) { + Common::String command(obj->_operativeVerb); + command += " "; + command += obj->_name; - Common::String fontName = (*it)->getName(); + _menu->addMenuSubItem(_weaponsMenuId, command.c_str(), kMenuActionCommand, 0, 0, true); - // Trim the .bdf extension - for (int i = fontName.size() - 1; i >= 0; --i) { - if (fontName[i] == '.') { - while ((uint)i < fontName.size()) { - fontName.deleteLastChar(); - } - break; - } + empty = false; } - - FontMan.assignFontToName(fontName, font); - - debug(2, " %s", fontName.c_str()); } + delete weapons; - _builtInFonts = false; - - delete dat; + if (empty) + _menu->addMenuSubItem(_weaponsMenuId, "You have no weapons", 0, 0, 0, false); } -void Gui::regenCommandsMenu() { - _menu->regenCommandsMenu(); -} - -void Gui::regenWeaponsMenu() { - _menu->regenWeaponsMenu(); -} - -void Gui::processMenuShortCut(byte flags, uint16 ascii) { - _menu->processMenuShortCut(flags, ascii); -} - -void Gui::mouseMove(int x, int y) { - if (_menu->_menuActivated) { - if (_menu->mouseMove(x, y)) - _menuDirty = true; - - return; - } +bool Gui::processEvent(Common::Event &event) { + return _wm.processEvent(event); } -void Gui::pushArrowCursor() { - CursorMan.pushCursor(macCursorArrow, 11, 16, 1, 1, 3); -} +void menuCommandsCallback(int action, Common::String &text, void *data) { + Gui *g = (Gui *)data; -void Gui::popCursor() { - CursorMan.popCursor(); + g->executeMenuCommand(action, text); } -bool Gui::processEvent(Common::Event &event) { - if (_wm.processEvent(event)) - return true; - - switch (event.type) { - case Common::EVENT_MOUSEMOVE: - mouseMove(event.mouse.x, event.mouse.y); +void Gui::executeMenuCommand(int action, Common::String &text) { + switch(action) { + case kMenuActionAbout: + case kMenuActionNew: + case kMenuActionOpen: + case kMenuActionClose: + case kMenuActionSave: + case kMenuActionSaveAs: + case kMenuActionRevert: + case kMenuActionQuit: + + case kMenuActionUndo: + actionUndo(); break; - case Common::EVENT_LBUTTONDOWN: - mouseDown(event.mouse.x, event.mouse.y); + case kMenuActionCut: + actionCut(); break; - case Common::EVENT_LBUTTONUP: - mouseUp(event.mouse.x, event.mouse.y); + case kMenuActionCopy: + actionCopy(); + break; + case kMenuActionPaste: + actionPaste(); + break; + case kMenuActionClear: + actionClear(); break; - default: - return false; - } - - return true; -} - -void Gui::mouseUp(int x, int y) { - if (_menu->_menuActivated) { - if (_menu->mouseRelease(x, y)) { - _sceneDirty = true; - _consoleDirty = true; - _menuDirty = true; - } - - return; - } - - return; -} - -void Gui::mouseDown(int x, int y) { - if (_menu->mouseClick(x, y)) { - _menuDirty = true; - } -} - -int Gui::calcTextX(int x, int textLine) { - const Graphics::Font *font = getConsoleFont(); - - if ((uint)textLine >= _lines.size()) - return 0; - - Common::String str = _lines[textLine]; - - x -= _consoleWindow->getInnerDimensions().left; + case kMenuActionCommand: + _engine->processTurn(&text, NULL); + break; - for (int i = str.size(); i >= 0; i--) { - if (font->getStringWidth(str) < x) { - return i; - } + default: + warning("Unknown action: %d", action); - str.deleteLastChar(); } - - return 0; -} - -int Gui::calcTextY(int y) { - y -= _consoleWindow->getInnerDimensions().top; - - if (y < 0) - y = 0; - - const int firstLine = _scrollPos / _consoleLineHeight; - int textLine = (y - _scrollPos % _consoleLineHeight) / _consoleLineHeight + firstLine; - - return textLine; -} - -void Gui::startMarking(int x, int y) { - _selectionStartY = calcTextY(y); - _selectionStartX = calcTextX(x, _selectionStartY); - - _selectionEndY = -1; - - _inTextSelection = true; -} - -void Gui::updateTextSelection(int x, int y) { - _selectionEndY = calcTextY(y); - _selectionEndX = calcTextX(x, _selectionEndY); - - _consoleFullRedraw = true; } } // End of namespace Wage |