V-Gears 0
Free Final Fantasy VII engine.
InputManager.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The V-Gears Team
3 *
4 * This file is part of V-Gears
5 *
6 * V-Gears is free software: you can redistribute it and/or modify it under
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, version 3.0 (GPLv3) of the License.
9 *
10 * V-Gears is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#pragma once
17
18#include <vector>
19#include <OgreSingleton.h>
20#include <OgreString.h>
21#include <OgreStringVector.h>
22#include <OIS/OIS.h>
23#include "Event.h"
24#include "Manager.h"
25
26typedef std::vector<VGears::Event> InputEventArray;
27
28typedef std::vector<int> ButtonList;
29
30class ConfigCmd;
31
37class InputManager : public Manager, public Ogre::Singleton<InputManager>{
38
39 public:
40
45
49 virtual ~InputManager();
50
56 void Input(const VGears::Event& event) override;
57
61 void Update();
62
66 void UpdateDebug() override;
67
71 void OnResize() override;
72
78 void ClearField() override;
79
85 void ClearBattle() override;
86
92 void ClearWorld() override;
93
105 void ButtonPressed(int button, char text, bool down);
106
116 void MousePressed(int button, bool down);
117
126 void MouseMoved(int x, int y);
127
136 void MouseScrolled(int value);
137
144 void Reset();
145
152 bool IsButtonPressed(int button) const;
153
161 void GetInputEvents(InputEventArray& input_events);
162
166 void InitCmd();
167
175 void BindCommand(
176 ConfigCmd* cmd, const Ogre::StringVector& params, const ButtonList& buttons
177 );
178
185 void BindGameEvent(const Ogre::String& event, const ButtonList& buttons);
186
192 void ActivateBinds(const int button);
193
200 void AddGameEvents(const int button, const VGears::EventType type);
201
202 private:
203
209 void UpdateField() override;
210
216 void UpdateBattle() override;
217
223 void UpdateWorld() override;
224
228 bool button_state_[256];
229
235 char button_text_[256];
236
243
248
253
257 struct BindInfo{
258
262 BindInfo(): cmd(NULL){}
263
268
272 Ogre::StringVector params;
273
278 };
279
283 std::vector<BindInfo> binds_;
284
289
294
299 };
300
304 std::vector<BindGameEventInfo> bind_game_events_;
305};
306
std::vector< VGears::Event > InputEventArray
Definition: InputManager.h:26
std::vector< int > ButtonList
Definition: InputManager.h:28
A configuration command.
Definition: ConfigCmd.h:31
The input manager.
Definition: InputManager.h:37
void ButtonPressed(int button, char text, bool down)
Triggered when a keyboard button is pressed or released.
Definition: InputManager.cpp:53
void UpdateField() override
Updates the input manager while on the fields.
Definition: InputManager.cpp:227
void ActivateBinds(const int button)
Activates all bindings for a button.
Definition: InputManager.cpp:155
void BindGameEvent(const Ogre::String &event, const ButtonList &buttons)
Binds a game event to an input event.
Definition: InputManager.cpp:148
void UpdateBattle() override
Updates the input manager while on a battle.
Definition: InputManager.cpp:229
void OnResize() override
Handles resizing events.
Definition: InputManager.cpp:41
bool button_state_[256]
The state of eahc button.
Definition: InputManager.h:228
std::vector< BindGameEventInfo > bind_game_events_
List of game event bindings.
Definition: InputManager.h:304
void MousePressed(int button, bool down)
Triggered when a mouse button is pressed or released.
Definition: InputManager.cpp:74
std::vector< BindInfo > binds_
List of command bindings.
Definition: InputManager.h:283
void ClearWorld() override
Clears all world map information in the input manager.
Definition: InputManager.cpp:47
void ClearField() override
Clears all field information in the input manager.
Definition: InputManager.cpp:43
void MouseMoved(int x, int y)
Triggered when a mouse moves.
Definition: InputManager.cpp:81
void BindCommand(ConfigCmd *cmd, const Ogre::StringVector &params, const ButtonList &buttons)
Binds a command to an input event.
Definition: InputManager.cpp:138
char button_text_[256]
The text of each button.
Definition: InputManager.h:235
void MouseScrolled(int value)
Triggered when a mouse scrolls.
Definition: InputManager.cpp:89
InputManager()
Constructor.
Definition: InputManager.cpp:29
bool IsButtonPressed(int button) const
Checks if a button is being pressed.
Definition: InputManager.cpp:131
void Reset()
Resets all keyboard and mouse events to their default state.
Definition: InputManager.cpp:49
void AddGameEvents(const int button, const VGears::EventType type)
Adds a game event associated to a button.
Definition: InputManager.cpp:189
void Update()
Update keyboard and mouse buttons, movements and scroll status.
Definition: InputManager.cpp:96
void InitCmd()
Initializes all command bindings.
Definition: InputManagerCommands.h:121
void GetInputEvents(InputEventArray &input_events)
Retrieves the current input events.
Definition: InputManager.cpp:133
void ClearBattle() override
Clears all battle information in the input manager.
Definition: InputManager.cpp:45
InputEventArray event_queue_
The event queue.
Definition: InputManager.h:252
void UpdateWorld() override
Updates the input manager while on the world map.
Definition: InputManager.cpp:231
float repeat_timer_
The time a key has been pressed.
Definition: InputManager.h:247
bool repeat_first_wait_
Indicates if a key held down is waiting to repeat events.
Definition: InputManager.h:242
void Input(const VGears::Event &event) override
Makes the input manager itself handles an input event.
Definition: InputManager.cpp:37
void UpdateDebug() override
Updates the input manager with debug information.
Definition: InputManager.cpp:39
virtual ~InputManager()
Destructor.
Definition: InputManager.cpp:35
A base manager.
Definition: Manager.h:24
Ogre::String String
Definition: TypeDefine.h:37
EventType
Type of event.
Definition: Event.h:27
A game event binding.
Definition: InputManager.h:288
Ogre::String event
The game event.
Definition: InputManager.h:293
ButtonList buttons
The buttons bond to the command.
Definition: InputManager.h:298
A command binding.
Definition: InputManager.h:257
ConfigCmd * cmd
The bind command.
Definition: InputManager.h:267
ButtonList buttons
The buttons bond to the command.
Definition: InputManager.h:277
Ogre::StringVector params
The command parameters.
Definition: InputManager.h:272
BindInfo()
Constructor.
Definition: InputManager.h:262
An input event.
Definition: Event.h:84