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 "ultima/ultima4/controllers/alpha_action_controller.h"
24 #include "ultima/ultima4/events/event_handler.h"
25 #include "ultima/ultima4/gfx/screen.h"
26 
27 namespace Ultima {
28 namespace Ultima4 {
29 
keyPressed(int key)30 bool AlphaActionController::keyPressed(int key) {
31 	if (Common::isLower(key))
32 		key = toupper(key);
33 
34 	if (key >= 'A' && key <= toupper(_lastValidLetter)) {
35 		_value = key - 'A';
36 		doneWaiting();
37 	} else {
38 		g_screen->screenMessage("\n%s", _prompt.c_str());
39 		g_screen->update();
40 		return KeyHandler::defaultHandler(key, nullptr);
41 	}
42 
43 	return true;
44 }
45 
keybinder(KeybindingAction action)46 void AlphaActionController::keybinder(KeybindingAction action) {
47 	if (action == KEYBIND_ESCAPE) {
48 		g_screen->screenMessage("\n");
49 		_value = -1;
50 		doneWaiting();
51 	}
52 }
53 
get(char lastValidLetter,const Common::String & prompt,EventHandler * eh)54 int AlphaActionController::get(char lastValidLetter, const Common::String &prompt, EventHandler *eh) {
55 	if (!eh)
56 		eh = eventHandler;
57 
58 	AlphaActionController ctrl(lastValidLetter, prompt);
59 	eh->pushController(&ctrl);
60 	return ctrl.waitFor();
61 }
62 
63 } // End of namespace Ultima4
64 } // End of namespace Ultima
65