ScummVM API documentation
controller.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef ULTIMA4_CONTROLLERS_CONTROLLER_H
23#define ULTIMA4_CONTROLLERS_CONTROLLER_H
24
25#include "ultima/ultima4/metaengine.h"
26
27namespace Ultima {
28namespace Ultima4 {
29
36public:
37 Controller(int timerInterval = 1);
38 virtual ~Controller();
39
40 /* methods for interacting with event manager */
41 virtual bool isCombatController() const {
42 return false;
43 }
44
50 bool notifyKeyPressed(int key);
51
56 bool notifyMousePress(const Common::Point &mousePos);
57
58 int getTimerInterval();
59
64 static void timerCallback(void *data);
65
71 virtual void setActive();
72
76 virtual bool keyPressed(int key) {
77 return false;
78 }
79
83 virtual bool mousePressed(const Common::Point &mousePos) {
84 return false;
85 }
86
90 virtual void keybinder(KeybindingAction action) {}
91
97 virtual void timerFired();
98
102 bool shouldQuit() const;
103private:
104 int _timerInterval;
105};
106
107// helper functions for the waitable controller; they just avoid
108// having eventhandler dependencies in this header file
109void Controller_startWait();
110void Controller_endWait();
111
117template<class T>
119private:
120 bool _exitWhenDone;
121 T _defaultValue;
122protected:
123 T _value;
124 void doneWaiting() {
125 if (_exitWhenDone)
126 Controller_endWait();
127 }
128public:
129 WaitableController(T defaultValue) : _defaultValue(defaultValue),
130 _value(defaultValue), _exitWhenDone(false) {}
131
132 virtual T getValue() {
133 return shouldQuit() ? _defaultValue : _value;
134 }
135
136 virtual T waitFor() {
137 _exitWhenDone = true;
138 Controller_startWait();
139 return getValue();
140 }
141
145 virtual bool mousePressed(const Common::Point &mousePos) {
146 // Treat mouse clicks as an abort
147 doneWaiting();
148 _value = _defaultValue;
149 return true;
150 }
151};
152
154public:
155 virtual ~TurnCompleter() {
156 }
157 virtual void finishTurn() = 0;
158
159 virtual void finishTurnAfterCombatEnds() {
160 finishTurn();
161 }
162};
163
164} // End of namespace Ultima4
165} // End of namespace Ultima
166
167#endif
Definition: controller.h:35
virtual void keybinder(KeybindingAction action)
Definition: controller.h:90
virtual bool mousePressed(const Common::Point &mousePos)
Definition: controller.h:83
bool notifyKeyPressed(int key)
virtual bool keyPressed(int key)
Definition: controller.h:76
static void timerCallback(void *data)
bool notifyMousePress(const Common::Point &mousePos)
Definition: controller.h:153
Definition: controller.h:118
virtual bool mousePressed(const Common::Point &mousePos)
Definition: controller.h:145
Definition: rect.h:144