summaryrefslogtreecommitdiff
path: root/src/event.h
blob: 63ca037bcaaf5f14f4ea836eb15646c0a75a438a (plain)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
 * This file is part of the planetblupi source code
 * Copyright (C) 1997, Daniel Roux & EPSITEC SA
 * Copyright (C) 2017-2018, Mathieu Schroeter
 * http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games
 *
 * 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 3 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, see http://gnu.org/licenses
 */

#pragma once

#include <string>
#include <unordered_map>
#include <vector>

#include "button.h"
#include "menu.h"
#include "pixmap.h"
#include "progress.h"

class CMovie;

/////////////////////////////////////////////////////////////////////////////

typedef struct {
  Uint32       message;
  Sint32       type;
  Sint32       iconMenu[20];
  Sint32       x, y;
  const char * toolTips[16];
} Button;

typedef struct {
  Uint32        phase;
  char          backName[20];
  std::string   backWideName;
  CPixmap::Mode mode;
  Sint32        bCDrom;
  Button        buttons[MAXBUTTON];
} Phase;

typedef struct {
  Sint16 majRev;
  Sint16 minRev;
  Sint16 bSchool;
  Sint16 bPrivate;
  Sint16 world;
  Sint16 skill;
  Sint16 reserve1[99];
} DemoHeader;

typedef struct {
  Sint32 time;
  Uint32 message;
  Uint32 wParam; // WParam
  Uint32 lParam; // LParam
} DemoEvent;

struct DemoSDLEvent {
  Uint32 time;
  Uint32 type;
  Sint32 scancode; // keysym
  Sint32 sym;      // keysym
  Uint8  button;
  Sint32 x;
  Sint32 y;
};

enum class Language {
  undef = -1,
  en    = 0,
  en_US = 1,
  fr    = 2,
  de    = 3,
  it    = 4,
  pl    = 5,
  end,
};

class CEvent
{
public:
  CEvent ();
  ~CEvent ();

  bool  IsDemoPlaying ();
  Point GetMousePos ();
  void
              Create (CPixmap * pPixmap, CDecor * pDecor, CSound * pSound, CMovie * pMovie);
  void        SetFullScreen (bool bFullScreen, double prevScale = 1);
  Sint32      GetWorld ();
  Sint32      GetPhysicalWorld ();
  Sint32      GetImageWorld ();
  bool        IsHelpHide ();
  bool        IsBaseMusicAvailable (Sint32 music, const std::string & format);
  std::string GetMusicLocation (Sint32 music);
  bool        LoadBackground ();
  bool        ChangePhase (Uint32 phase);
  bool        MovieToStart ();
  Uint32      GetPhase ();
  void        TryInsert ();

  Sint32 GetButtonIndex (Sint32 button);
  Sint32 GetState (Sint32 button);
  void   SetState (Sint32 button, Sint32 state);
  bool   GetEnable (Sint32 button);
  void   SetEnable (Sint32 button, bool bEnable);
  bool   GetHide (Sint32 button);
  void   SetHide (Sint32 button, bool bHide);
  Sint32 GetMenu (Sint32 button);
  void   SetMenu (Sint32 button, Sint32 menu);

  bool         DrawButtons ();
  MouseSprites MousePosToSprite (Point pos);
  void         MouseSprite (Point pos);
  void         WaitMouse (bool bWait);
  void         HideMouse (bool bHide);
  Point        GetLastMousePos ();
  bool         TreatEvent (const SDL_Event & event);
  bool         TreatEventBase (const SDL_Event & event);

  void DecorAutoShift ();

  bool StartMovie (const std::string & pFilename);
  void StopMovie ();
  bool IsMovie ();

  void Read (Sint32 message);
  void Write (Sint32 message);

  void   SetSpeed (Sint32 speed);
  Sint32 GetSpeed ();
  bool   GetPause ();
  bool   IsShift ();

  void DemoStep ();

  void IntroStep ();

  void SetWindowSize (Uint8 newScale);
  void SetUpdateVersion (const std::string & version);

  bool EventButtons (const SDL_Event & event, Point pos);
  bool PlayMove (Point pos);

  static void PushUserEvent (Sint32 code, void * data = nullptr);

protected:
  void DrawTextCenter (const char * text, Sint32 x, Sint32 y, Sint32 font = 0);
  bool CreateButtons (Sint32 phase);
  bool MouseOnButton (Point pos);
  Sint32 SearchPhase (Uint32 phase);
  void   DecorShift (Sint32 dx, Sint32 dy);

  bool PlayDown (Point pos, const SDL_Event & event);
  bool PlayUp (Point pos);

  Language GetStartLanguage ();
  Language GetLanguage ();
  void     SetLanguage (Language lang = Language::undef);
  void     SetWindowSize (double prevScale, double newScale);

  void ChangeButtons (Sint32 message);

  void BuildFloor (Point cel, Sint32 insIcon);
  void BuildWater (Point cel, Sint32 insIcon);
  bool
       BuildDown (Point pos, Uint16 mod, const SDL_Event * event, bool bMix = true);
  bool BuildMove (Point pos, Uint16 mod, const SDL_Event & event);

  void PrivateLibelle ();
  bool ReadLibelle (Sint32 world, bool bSchool, bool bHelp);
  bool WriteInfo ();
  bool ReadInfo ();

  void DemoRecStart ();
  void DemoRecStop ();
  bool DemoPlayStart (const std::string * demoFile = nullptr);
  void DemoPlayStop ();
  static void
       WinToSDLEvent (Uint32 msg, WParam wParam, LParam lParam, SDL_Event & event);
  void DemoRecEvent (const SDL_Event & event);

protected:
  std::vector<Language>                    m_Languages;
  std::vector<Language>::iterator          m_Lang;
  std::string                              m_LangStart;
  Sint32                                   m_speed;
  Sint32                                   m_exercice;
  Sint32                                   m_mission;
  Sint32                                   m_private;
  Sint32                                   m_maxMission;
  Uint32                                   m_phase;
  Sint32                                   m_index;
  bool                                     m_bSchool;
  bool                                     m_bPrivate;
  bool                                     m_bAccessBuild;
  CPixmap *                                m_pPixmap;
  CDecor *                                 m_pDecor;
  CSound *                                 m_pSound;
  CMovie *                                 m_pMovie;
  std::string                              m_movieToStart;
  Sint32                                   m_phaseAfterMovie;
  CButton                                  m_buttons[MAXBUTTON];
  Sint32                                   m_lastFloor[MAXBUTTON];
  Sint32                                   m_lastObject[MAXBUTTON];
  Sint32                                   m_lastHome[MAXBUTTON];
  bool                                     m_bRunMovie;
  bool                                     m_bBuildModify;
  CJauge                                   m_jauges[2];
  CMenu                                    m_menu;
  bool                                     m_bMenu;
  Point                                    m_menuPos;
  Sint32                                   m_menuNb;
  Buttons                                  m_menuButtons[MAXBUTTON];
  Errors                                   m_menuErrors[MAXBUTTON];
  std::unordered_map<Sint32, const char *> m_menuTexts;
  Sint32                                   m_menuPerso;
  Point                                    m_menuCel;
  Point                                    m_oldMousePos;
  bool                                     m_bMouseDown;
  bool                                     m_bHili;
  Sint32                                   m_fileWorld[10];
  Sint32                                   m_fileTime[10];
  Point                                    m_posToolTips;
  char                                     m_textToolTips[50];
  MouseSprites                             m_mouseSprite;
  bool                                     m_bFillMouse;
  bool                                     m_bWaitMouse;
  bool                                     m_bHideMouse;
  Sint32                                   m_rankCheat;
  Sint32                                   m_posCheat;
  bool                                     m_bMovie;
  bool                                     m_bSpeed;
  bool                                     m_bHelp;
  bool                                     m_bAllMissions;
  Sint32                                   m_scrollSpeed;
  Sint32                                   m_scrollSpeedPrev;
  bool                                     m_bPause;
  bool                                     m_bShift;
  Sint32                                   m_shiftPhase;
  Point                                    m_shiftVector;
  Point                                    m_shiftOffset;
  char                                     m_libelle[1000];
  Sint32                                   m_tryPhase;
  Sint32                                   m_tryInsertCount;
  Point                                    m_posInfoButton;
  Point                                    m_posHelpButton;
  bool                                     m_bHiliInfoButton;
  bool                                     m_bHiliHelpButton;
  bool                                     m_bInfoHelp;
  bool                                     m_bDemoRec;
  bool                                     m_bDemoPlay;
  DemoEvent *                              m_pDemoBuffer;
  std::vector<DemoSDLEvent>                m_pDemoSDLBuffer;
  bool                                     m_bStartRecording;
  Uint32                                   m_demoTime;
  size_t                                   m_demoIndex;
  size_t                                   m_demoEnd;
  Sint32                                   m_demoNumber;
  Uint16                                   m_keymod;
  Point                                    m_debugPos;
  Sint32                                   m_introTime;
  Sint32                                   m_updateBlinking;
  std::string                              m_updateVersion;
  Uint32                                   shiftDirection;
  bool                                     statDisabled;
};

/////////////////////////////////////////////////////////////////////////////