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 
27 namespace Ultima {
28 namespace Ultima4 {
29 
35 class Controller {
36 public:
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;
103 private:
104  int _timerInterval;
105 };
106 
107 // helper functions for the waitable controller; they just avoid
108 // having eventhandler dependencies in this header file
109 void Controller_startWait();
110 void Controller_endWait();
111 
117 template<class T>
119 private:
120  bool _exitWhenDone;
121  T _defaultValue;
122 protected:
123  T _value;
124  void doneWaiting() {
125  if (_exitWhenDone)
126  Controller_endWait();
127  }
128 public:
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 
154 public:
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
virtual bool mousePressed(const Common::Point &mousePos)
Definition: controller.h:145
Definition: controller.h:153
Definition: controller.h:35
static void timerCallback(void *data)
Definition: detection.h:27
bool notifyMousePress(const Common::Point &mousePos)
virtual void keybinder(KeybindingAction action)
Definition: controller.h:90
Definition: rect.h:45
virtual bool keyPressed(int key)
Definition: controller.h:76
Definition: controller.h:118
virtual bool mousePressed(const Common::Point &mousePos)
Definition: controller.h:83
bool notifyKeyPressed(int key)