ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

topmenu.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/ui/world/topmenu.h"
00024 
00025 #include "engines/stark/ui/cursor.h"
00026 #include "engines/stark/ui/world/button.h"
00027 
00028 #include "engines/stark/gfx/driver.h"
00029 
00030 #include "engines/stark/resources/knowledgeset.h"
00031 #include "engines/stark/resources/sound.h"
00032 
00033 #include "engines/stark/services/diary.h"
00034 #include "engines/stark/services/global.h"
00035 #include "engines/stark/services/services.h"
00036 #include "engines/stark/services/userinterface.h"
00037 #include "engines/stark/services/gamemessage.h"
00038 
00039 #include "engines/stark/visual/image.h"
00040 
00041 namespace Stark {
00042 
00043 TopMenu::TopMenu(Gfx::Driver *gfx, Cursor *cursor) :
00044         Window(gfx, cursor),
00045         _widgetsVisible(false),
00046         _newInventoryItemExplosionAnimTimeRemaining(0),
00047         _newDiaryEntryAnimTimeRemaining(0),
00048         _newInventoryItemChestClosingAnimTimeRemaining(0) {
00049 
00050     _position = Common::Rect(Gfx::Driver::kOriginalWidth, Gfx::Driver::kTopBorderHeight);
00051     _visible = true;
00052 
00053     Common::String inventoryText = StarkGameMessage->getTextByKey(GameMessage::kInventory);
00054     Common::String optionsText = StarkGameMessage->getTextByKey(GameMessage::kOptions);
00055     Common::String quitText = StarkGameMessage->getTextByKey(GameMessage::kQuit);
00056 
00057     _inventoryButton = new Button(inventoryText, StaticProvider::kInventory, Common::Point(32, 2), Button::kAlignLeft, Common::Point(64, 20));
00058     _optionsButton = new Button(optionsText, StaticProvider::kDiaryNormal, Common::Point(560, 2), Button::kAlignRight, Common::Point(560, 20));
00059     _exitButton = new Button(quitText, StaticProvider::kQuit, Common::Point(608, 2), Button::kAlignRight, Common::Point(608, 20));
00060 
00061     _inventoryNewItemSound = StarkStaticProvider->getUISound(StaticProvider::kInventoryNewItem);
00062 }
00063 
00064 TopMenu::~TopMenu() {
00065     delete _exitButton;
00066     delete _inventoryButton;
00067     delete _optionsButton;
00068 }
00069 
00070 void TopMenu::onGameLoop() {
00071     _widgetsVisible = (isMouseInside() && StarkUserInterface->isInteractive()) || isAnimationPlaying();
00072 
00073     if (!_widgetsVisible) {
00074         return;
00075     }
00076 
00077     if (StarkDiary->hasUnreadEntries()) {
00078         _optionsButton->setUIElement(StaticProvider::kDiaryTabbed);
00079     } else {
00080         _optionsButton->setUIElement(StaticProvider::kDiaryNormal);
00081     }
00082 
00083     updateAnimations();
00084 }
00085 
00086 void TopMenu::onRender() {
00087     if (!_widgetsVisible) {
00088         return;
00089     }
00090 
00091     _inventoryButton->render();
00092     _optionsButton->render();
00093     _exitButton->render();
00094 }
00095 
00096 bool TopMenu::isAnimationPlaying() const {
00097     return _newInventoryItemExplosionAnimTimeRemaining > 0
00098            || _newDiaryEntryAnimTimeRemaining > 0
00099            || _newInventoryItemChestClosingAnimTimeRemaining > 0;
00100 }
00101 
00102 void TopMenu::updateAnimations() {
00103     if (_newInventoryItemExplosionAnimTimeRemaining > 0) {
00104         _newInventoryItemExplosionAnimTimeRemaining -= StarkGlobal->getMillisecondsPerGameloop();
00105 
00106         if (_newInventoryItemExplosionAnimTimeRemaining <= 0) {
00107             _inventoryButton->stopImageExplosion();
00108 
00109             _newInventoryItemChestClosingAnimTimeRemaining = 20 * 33; // 20 frames at 30 fps
00110             _inventoryButton->goToAnimStatement(12);
00111         }
00112     }
00113 
00114     if (_newInventoryItemChestClosingAnimTimeRemaining > 0) {
00115         _newInventoryItemChestClosingAnimTimeRemaining -= StarkGlobal->getMillisecondsPerGameloop();
00116     }
00117 
00118     if (_newDiaryEntryAnimTimeRemaining > 0) {
00119         _newDiaryEntryAnimTimeRemaining -= StarkGlobal->getMillisecondsPerGameloop();
00120         if (_newDiaryEntryAnimTimeRemaining <= 0) {
00121             _optionsButton->stopImageFlashing();
00122         }
00123     }
00124 }
00125 
00126 void TopMenu::onMouseMove(const Common::Point &pos) {
00127     if (_widgetsVisible && StarkUserInterface->isInteractive()) {
00128         Button *hoveredButton = getButtonAtPosition(pos);
00129         if (hoveredButton) {
00130             _cursor->setCursorType(Cursor::kActive);
00131             hoveredButton->showButtonHint();
00132         } else {
00133             _cursor->setCursorType(Cursor::kDefault);
00134         }
00135     } else {
00136         _cursor->setCursorType(Cursor::kPassive);
00137     }
00138 }
00139 
00140 void TopMenu::onClick(const Common::Point &pos) {
00141     if (!_widgetsVisible || !StarkUserInterface->isInteractive()) {
00142         return;
00143     }
00144 
00145     if (_exitButton->containsPoint(pos)) {
00146         StarkUserInterface->confirm(GameMessage::kQuitGamePrompt, StarkUserInterface,
00147                                     &UserInterface::requestQuitToMainMenu);
00148     }
00149 
00150     if (_inventoryButton->containsPoint(pos)) {
00151         StarkUserInterface->inventoryOpen(true);
00152     }
00153 
00154     if (_optionsButton->containsPoint(pos)) {
00155         StarkUserInterface->optionsOpen();
00156     }
00157 }
00158 
00159 Button *TopMenu::getButtonAtPosition(const Common::Point &point) const {
00160     if (_exitButton->containsPoint(point)) {
00161         return _exitButton;
00162     } else if (_optionsButton->containsPoint(point)) {
00163         return _optionsButton;
00164     } else if (_inventoryButton->containsPoint(point)) {
00165         return _inventoryButton;
00166     }
00167 
00168     return nullptr;
00169 }
00170 
00171 void TopMenu::onScreenChanged() {
00172     _exitButton->resetHintVisual();
00173     _inventoryButton->resetHintVisual();
00174     _optionsButton->resetHintVisual();
00175 }
00176 
00177 void TopMenu::notifyInventoryItemEnabled(uint16 itemIndex) {
00178     _newInventoryItemExplosionAnimTimeRemaining = 128 * 33; // 128 frames at 30 fps
00179     _inventoryButton->goToAnimStatement(2);
00180 
00181     Visual *inventoryItemImage = StarkGlobal->getInventory()->getInventoryItemVisual(itemIndex);
00182     _inventoryButton->startImageExplosion(inventoryItemImage->get<VisualImageXMG>());
00183 
00184     assert(_inventoryNewItemSound);
00185     _inventoryNewItemSound->stop();
00186     _inventoryNewItemSound->play();
00187 }
00188 
00189 void TopMenu::notifyDiaryEntryEnabled() {
00190     if (StarkDiary->isEnabled()) {
00191         _newDiaryEntryAnimTimeRemaining = 5000;
00192         VisualImageXMG *diaryImage = StarkStaticProvider->getUIElement(StaticProvider::kDiaryTabbed);
00193         _optionsButton->startImageFlashing(diaryImage);
00194     }
00195 }
00196 
00197 } // End of namespace Stark


Generated on Sat Mar 16 2019 05:01:56 for ResidualVM by doxygen 1.7.1
curved edge   curved edge