1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "engines/nancy/nancy.h"
24 #include "engines/nancy/sound.h"
25 #include "engines/nancy/input.h"
26 #include "engines/nancy/cursor.h"
27 #include "engines/nancy/util.h"
28 
29 #include "engines/nancy/state/help.h"
30 
31 #include "engines/nancy/ui/button.h"
32 
33 namespace Common {
34 DECLARE_SINGLETON(Nancy::State::Help);
35 }
36 
37 namespace Nancy {
38 namespace State {
39 
Help()40 Help::Help() :
41 		_state(kInit),
42 		_image(),
43 		_button(nullptr) {}
44 
~Help()45 Help::~Help() {
46 	delete _button;
47 }
48 
process()49 void Help::process() {
50 	switch (_state) {
51 	case kInit:
52 		init();
53 		// fall through
54 	case kBegin:
55 		begin();
56 		// fall through
57 	case kRun:
58 		run();
59 		break;
60 	case kWaitForSound:
61 		waitForSound();
62 		break;
63 	}
64 }
65 
init()66 void Help::init() {
67 	Common::SeekableReadStream *chunk = g_nancy->getBootChunkStream("HELP");
68 
69 	chunk->seek(0);
70 	Common::String imageName;
71 	readFilename(*chunk, imageName);
72 	_image.init(imageName);
73 
74 	chunk->skip(20);
75 	Common::Rect buttonSrc, buttonDest;
76 	buttonDest.left = chunk->readUint16LE();
77 	buttonDest.top = chunk->readUint16LE();
78 	buttonDest.right = chunk->readUint16LE();
79 	buttonDest.bottom = chunk->readUint16LE();
80 	buttonSrc.left = chunk->readUint16LE();
81 	buttonSrc.top = chunk->readUint16LE();
82 	buttonSrc.right = chunk->readUint16LE();
83 	buttonSrc.bottom = chunk->readUint16LE();
84 
85 	_button = new UI::Button(_image, 5, _image._drawSurface, buttonSrc, buttonDest);
86 	_button->init();
87 
88 	_state = kBegin;
89 }
90 
begin()91 void Help::begin() {
92 	if (!g_nancy->_sound->isSoundPlaying("MSND")) {
93 		g_nancy->_sound->playSound("MSND");
94 	}
95 
96 	_image.registerGraphics();
97 	_button->registerGraphics();
98 	_image.setVisible(true);
99 
100 	g_nancy->_cursorManager->setCursorType(CursorManager::kNormalArrow);
101 
102 	_state = kRun;
103 }
104 
run()105 void Help::run() {
106 	NancyInput input = g_nancy->_input->getInput();
107 	_button->handleInput(input);
108 
109 	if (_button->_isClicked) {
110 		_button->_isClicked = false;
111 		g_nancy->_sound->playSound("BUOK");
112 		_state = kWaitForSound;
113 	}
114 }
115 
waitForSound()116 void Help::waitForSound() {
117 	if (!g_nancy->_sound->isSoundPlaying("BUOK")) {
118 		g_nancy->_sound->stopSound("BUOK");
119 		g_nancy->setToPreviousState();
120 	}
121 }
122 
123 } // End of namespace State
124 } // End of namespace Nancy
125