File: 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 (194 lines) | stat: -rw-r--r-- 5,537 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/******************************************************************************
 *  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
 ******************************************************************************
 * Graphical interface showing various information about the game.
 *****************************************************************************/

#ifndef INTERFACE_H
#define INTERFACE_H
#include <vector>
#include <WARMUX_base.h>
#include <WARMUX_singleton.h>
#include "interface/weapon_menu.h"
#include "gui/progress_bar.h"
#include "weapon/weapon_strength_bar.h"

// Forward declarations
class Character;
class Team;
class Text;
class Polygon;
class Weapon;
class WeaponHelp;
class Profile;
class EnergyBar;

#ifdef WIN32
#undef interface
#endif

class Interface : public Singleton<Interface>
{
public:
  typedef enum
  {
    CLICK_TYPE_LONG,
    CLICK_TYPE_DOWN,
    CLICK_TYPE_UP
  } ClickType;

  typedef enum
  {
    MODE_NORMAL,
    MODE_CONTROL,
    MODE_SMALL,
    MODE_REPLAY
  } Mode;

  Character *character_under_cursor;
  Weapon *weapon_under_cursor;
  WeaponsMenu weapons_menu;
  WeaponHelp *help;
  Team *tmp_team;

private:
  // Regular part of the interface
  int     clock_width;

  // Timers
  Text * global_timer;
  Text * timer;
  uint remaining_turn_time;

  ProgressBar wind_bar;

  // This part is for normal interface mode
  EnergyBar * energy_bar;

  // Character information
  Text * t_character_name;
  Text * t_team_name;
  Text * t_player_name;
  Text * t_character_energy;

  // Weapon information
  Text * t_weapon_name;
  Text * t_weapon_stock;

  // Replay info
  Text * t_speed;
  void SetSpeed(const Double& speed);

  // Related to interface mode
  Mode mode;
  Surface default_toolbar;
  Surface control_toolbar;
  Surface replay_toolbar;
  Surface small_interface;

  // Other stuff
  int start_hide_display;
  int start_show_display;
  bool display_timer;
  bool display_minimap;
  WeaponStrengthBar weapon_strength_bar;

  Sprite *clock, *clock_normal, *clock_emergency;
  Point2i bottom_bar_pos;
  int last_width;
  float zoom;

  //Minimap
  Surface *minimap;
  uint m_last_minimap_redraw;
  Point2i m_last_preview_size;
  //Styled box
  Surface *mask;
  Surface *scratch;

  Color m_camera_preview_color;
  Color m_playing_character_preview_color;
  Color m_text_color, m_energy_text_color;

  void FreeDrawElements();
  void DrawCharacterInfo();
  void DrawTeamEnergy() const;
  void DrawWeaponInfo() const;
  void DrawWindIndicator(const Point2i &wind_bar_pos) const;
  void DrawWindInfo() const;
  void DrawClock(const Point2i &time_pos) const;
  void DrawTimeInfo() const;
  void DrawMapPreview();
  void DrawReplayInfo() const;
  void DrawSmallInterface() const;

  void LoadDataInternal(Profile *res);
  int GetWidth() const { return default_toolbar.GetWidth(); }
  int GetHeight() const;
  Point2i GetSize() const { return Point2i(GetWidth(), GetHeight()); }

  // Handle clicks for various states of the interface
  bool ReplayClick(const Point2i &mouse_pos, ClickType type, Point2i old_mouse_pos = Point2i());
  bool ControlClick(const Point2i &mouse_pos, ClickType type, Point2i old_mouse_pos = Point2i());
  bool DefaultClick(const Point2i &mouse_pos, ClickType type, Point2i old_mouse_pos = Point2i());
  // -1 means nothing clicked, 0 means return false, 1 means return true
  int AnyClick(const Point2i &mouse_pos, ClickType type, Point2i old_mouse_pos = Point2i());

protected:
  friend class Singleton<Interface>;
  Interface();
  ~Interface();

public:
  const WeaponsMenu &GetWeaponsMenu() const { return weapons_menu; }

  void Reset();
  void Draw();
  void LoadData();

  Point2i GetMenuPosition() const { return bottom_bar_pos; }
  bool IsDisplayed () const { return mode != MODE_SMALL; }
  Mode GetMode() const { return mode; }
  void EnableDisplay(bool display)
  {
    if (mode==MODE_REPLAY) return;
    mode = (display) ? MODE_NORMAL : MODE_SMALL;
  }
  void Show();
  void Hide();

  void SetCurrentOverflyWeapon(Weapon * weapon) { weapon_under_cursor = weapon; }
  void UpdateTimer(uint utimer, bool emergency, bool reset_anim);
  void UpdateWindIndicator(int wind_value);
  void EnableDisplayTimer(bool _display) { display_timer = _display; }
  void ToggleMinimap() { display_minimap = !display_minimap; }
  void MinimapSizeDelta(int delta);
  bool Intersect(const Point2i &mouse_pos);

  bool ActionClickUp(const Point2i &mouse_pos, const Point2i &old_click_pos);
  bool ActionLongClick(const Point2i &mouse_pos, const Point2i &old_mouse_pos);
  bool ActionClickDown(const Point2i &mouse_pos);

  int GetMenuHeight() const;
};

void AbsoluteDraw(const Surface& s, const Point2i& pos);
void HideGameInterface();
inline void ShowGameInterface() { Interface::GetInstance()->Show(); }

#endif