File: man_machine_interface.h

package info (click to toggle)
warmux 1%3A11.04.1%2Brepack2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 126,388 kB
  • sloc: cpp: 186,040; xml: 8,909; sh: 3,358; makefile: 1,052; ansic: 713
file content (143 lines) | stat: -rw-r--r-- 4,097 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/******************************************************************************
 *  Warmux is a convivial mass murder game.
 *  Copyright (C) 2001-2011 Warmux Team.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 ******************************************************************************
 * Virtual class to handle man/machine interaction
 *****************************************************************************/

#ifndef MAN_MACHINE_INTERFACE_H
#define MAN_MACHINE_INTERFACE_H
//-----------------------------------------------------------------------------
#include <map>
#include <list>
#include <vector>
#include <WARMUX_base.h>
//-----------------------------------------------------------------------------

// Forward declarations
#ifndef _SDL_events_h
union SDL_Event;
#endif

class ManMachineInterface
{
public:
  typedef enum
  {
    KEY_QUIT,
    KEY_WEAPONS1,
    KEY_WEAPONS2,
    KEY_WEAPONS3,
    KEY_WEAPONS4,
    KEY_WEAPONS5,
    KEY_WEAPONS6,
    KEY_WEAPONS7,
    KEY_WEAPONS8,
    KEY_PAUSE,
    KEY_FULLSCREEN,
    KEY_TOGGLE_INTERFACE,
    KEY_CENTER,
    KEY_TOGGLE_WEAPONS_MENUS,
    KEY_CHAT,
    KEY_MOVE_LEFT,
    KEY_MOVE_LEFT_SLOWLY,
    KEY_MOVE_CAMERA_LEFT,
    KEY_MOVE_RIGHT,
    KEY_MOVE_RIGHT_SLOWLY,
    KEY_MOVE_CAMERA_RIGHT,
    KEY_UP,
    KEY_UP_SLOWLY,
    KEY_MOVE_CAMERA_UP,
    KEY_DOWN,
    KEY_DOWN_SLOWLY,
    KEY_MOVE_CAMERA_DOWN,
    KEY_JUMP,
    KEY_HIGH_JUMP,
    KEY_BACK_JUMP,
    KEY_SHOOT,
    KEY_CHANGE_WEAPON,
    KEY_WEAPON_1,
    KEY_WEAPON_2,
    KEY_WEAPON_3,
    KEY_WEAPON_4,
    KEY_WEAPON_5,
    KEY_WEAPON_6,
    KEY_WEAPON_7,
    KEY_WEAPON_8,
    KEY_WEAPON_9,
    KEY_WEAPON_LESS,
    KEY_WEAPON_MORE,
    KEY_NEXT_CHARACTER,
    KEY_MENU_OPTIONS_FROM_GAME,
    KEY_MINIMAP_FROM_GAME,
    KEY_HELP,
    KEY_DECREASE_MINIMAP,
    KEY_INCREASE_MINIMAP,
    KEY_DECREASE_VOLUME,
    KEY_INCREASE_VOLUME,
    KEY_SCREENSHOT,
    KEY_NONE
  } Key_t;

protected:
  // This is a widget in charge of displaying and setting the config
  friend class ControlItem;
  friend class ControlConfig;

  typedef enum
  {
    KEY_PRESSED,
    KEY_RELEASED,
    KEY_REFRESH,
    X_AXIS_MOTION,
    Y_AXIS_MOTION
  } Key_Event_t;

  virtual void SetDefaultConfig() { };
  std::map<int, std::vector<Key_t> > layout;
  std::list<uint32_t> registred_event;
  bool PressedKeys[256]; // stupid default value

  void RegisterEvent(uint32_t event_type) { registred_event.push_back(event_type); };
  bool IsRegistredEvent(uint32_t event_type);
  void HandleKeyPressed(const Key_t &action_key);
  void HandleKeyReleased(const Key_t &action_key);

  void SetKeyAction(int key, Key_t at) { layout[key].push_back(at); };
  void ClearKeyAction(Key_t at);
  void ClearKeyBindings() { layout.clear(); }

  int GetKeyFromKeyName(const std::string &name) const;
  std::string GetKeyNameFromKey(int key) const;

  Key_t GetActionFromActionName(const std::string &name) const;
  std::string GetActionNameFromAction(Key_t) const;
  std::string GetHumanReadableActionName(Key_t) const;

  ManMachineInterface() { SetDefaultConfig(); };
  virtual ~ManMachineInterface() { };

public:
  virtual bool HandleKeyEvent(const SDL_Event& evnt) = 0;
  virtual void Reset();

  // Get the key associated to an action.
  int GetKeyAssociatedToAction(Key_t at) const;
};

//-----------------------------------------------------------------------------
#endif /* MAN_MACHINE_INTERFACE_H */