OpenClonk
C4FullScreen.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Main class to execute the game fullscreen mode */
19 
20 #include "C4Include.h"
21 #include "game/C4FullScreen.h"
22 
23 #include "C4Version.h"
24 #include "game/C4Application.h"
25 #include "game/C4GraphicsSystem.h"
26 #include "game/C4Viewport.h"
27 #include "gui/C4GameDialogs.h"
28 #include "gui/C4GameOverDlg.h"
29 #include "gui/C4Gui.h"
30 #include "gui/C4MouseControl.h"
31 #include "player/C4Player.h"
32 #include "player/C4PlayerList.h"
33 
34 void C4FullScreen::CharIn(const char * c) { ::pGUI->CharIn(c); }
35 
37 {
38  MainMenu = nullptr;
39 }
40 
42 {
43  if (MainMenu)
44  {
45  delete MainMenu;
46  }
47  if (pSurface)
48  {
49  delete pSurface;
50  }
51 }
52 
53 
55 {
57  return Init(C4Window::W_Fullscreen, application, C4ENGINECAPTION, &r);
58 }
59 
61 {
62  if (Game.IsRunning)
63  {
64  ShowAbortDlg();
65  }
66  else
67  {
68  Application.Quit();
69  }
70 }
71 
73 {
74  if (pSurface)
75  {
76  delete pSurface;
77  }
78  pSurface = nullptr;
80 }
81 
83 {
84  // Execute menu
85  if (MainMenu)
86  {
87  MainMenu->Execute();
88  }
89  // Draw
90  RequestUpdate();
91 }
92 
94 {
95  // Not active
96  if (!Active)
97  {
98  return false;
99  }
100 
101 
102  // Determine film mode
103  bool is_film_mode = (Game.C4S.Head.Replay && Game.C4S.Head.Film);
104 
105  // Check viewports
106  C4Player *player;
107  switch (::Viewports.GetViewportCount())
108  {
109  // No viewports: create no-owner viewport
110  case 0:
111  {
112  int player_count = NO_OWNER;
113  // Film mode: create viewport for first player (instead of no-owner)
114  if (is_film_mode)
115  {
116  if ((player = ::Players.First))
117  {
118  player_count = player->Number;
119  }
120  }
121  // Create viewport
122  ::Viewports.CreateViewport(player_count, player_count == NO_OWNER);
123  // Non-film (observer mode)
124  if (!is_film_mode)
125  {
126  // Activate mouse control
127  ::MouseControl.Init(player_count);
128  // Display message for how to open observer menu (this message will be cleared if any owned viewport opens)
129  StdStrBuf key;
130  key.Format("<c ffff00><%s></c>", Game.KeyboardInput.GetKeyCodeNameByKeyName("FullscreenMenuOpen", false).getData());
131  ::GraphicsSystem.FlashMessage(FormatString(LoadResStr("IDS_MSG_PRESSORPUSHANYGAMEPADBUTT"), key.getData()).getData());
132  }
133  }
134  break;
135  // One viewport: do nothing
136  case 1:
137  break;
138  // More than one viewport: remove all no-owner viewports
139  default:
141  break;
142  }
143  // Look for no-owner viewport
144  C4Viewport *no_owner_viewport = ::Viewports.GetViewport(NO_OWNER);
145  // No no-owner viewport found
146  if (!no_owner_viewport)
147  {
148  // Close any open fullscreen menu
149  CloseMenu();
150  }
151  // No-owner viewport present
152  else
153  {
154  // movie mode: player present, and no valid viewport assigned?
155  if (Game.C4S.Head.Replay && Game.C4S.Head.Film && (player = ::Players.First))
156  {
157  // assign viewport to joined player
158  no_owner_viewport->Init(player->Number, true);
159  }
160  }
161  // Done
162  return true;
163 }
164 
166 {
167  // abort dialog already shown
169  {
170  return false;
171  }
172  // not while game over dialog is open
174  {
175  return false;
176  }
177  // show abort dialog
179 }
180 
182 {
183  // Not during game over dialog
185  {
186  return false;
187  }
188  // Close previous
189  CloseMenu();
190  // Open menu
191  MainMenu = new C4MainMenu();
192  return MainMenu->ActivateMain(NO_OWNER);
193 }
194 
196 {
197  if (MainMenu)
198  {
199  if (MainMenu->IsActive())
200  {
201  MainMenu->Close(false);
202  }
203  delete MainMenu;
204  MainMenu = nullptr;
205  }
206 }
207 
209 {
211 }
212 
214 {
215  if (MainMenu)
216  {
217  return MainMenu->KeyControl(command);
218  }
219  return false;
220 }
const int NO_OWNER
Definition: C4Constants.h:137
C4Game Game
Definition: C4Globals.cpp:52
C4Application Application
Definition: C4Globals.cpp:44
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4PlayerList Players
C4ViewportList Viewports
uint8_t BYTE
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
static bool IsShown()
Definition: C4GameDialogs.h:47
int GetConfigWidth()
Definition: C4Application.h:83
int GetConfigHeight()
Definition: C4Application.h:84
void Quit() override
void Clear() override
virtual C4Window * Init(WindowKind windowKind, C4AbstractApp *pApp, const char *Title, const C4Rect *size)
Definition: C4AppT.cpp:109
C4MainMenu * MainMenu
Definition: C4FullScreen.h:30
~C4FullScreen() override
bool MenuKeyControl(BYTE command)
bool ShowAbortDlg()
bool ActivateMenuMain()
bool ViewportCheck()
void CharIn(const char *c) override
void PerformUpdate() override
void Close() override
void Close(bool fOK)
virtual bool CharIn(const char *c)
Definition: C4Gui.cpp:779
bool ShowRemoveDlg(Dialog *pDlg)
C4Scenario C4S
Definition: C4Game.h:74
C4KeyboardInput & KeyboardInput
Definition: C4Game.h:96
bool IsRunning
Definition: C4Game.h:140
static bool IsShown()
Definition: C4GameOverDlg.h:91
void FlashMessage(const char *message)
StdStrBuf GetKeyCodeNameByKeyName(const char *szKeyName, bool fShort=false, int32_t iIndex=0)
bool ActivateMain(int32_t iPlayer)
Definition: C4MainMenu.cpp:566
bool KeyControl(BYTE byCom)
Definition: C4Menu.cpp:473
void Execute()
Definition: C4Menu.cpp:903
bool IsActive()
Definition: C4Menu.cpp:480
bool Init(int32_t iPlayer)
C4Player * First
Definition: C4PlayerList.h:31
Definition: C4Rect.h:28
bool Replay
Definition: C4Scenario.h:72
int32_t Film
Definition: C4Scenario.h:73
C4SHead Head
Definition: C4Scenario.h:232
bool Init(int32_t for_player, bool set_temporary_only)
Definition: C4Viewport.cpp:786
int32_t GetViewportCount()
C4Viewport * GetViewport(int32_t player_nr, C4Viewport *prev=nullptr)
bool CloseViewport(int32_t player_nr, bool silent)
bool CreateViewport(int32_t player_nr, bool silent=false)
C4Surface * pSurface
Definition: C4Window.h:275
virtual void Clear()
Definition: C4AppT.cpp:102
virtual void RequestUpdate()
Definition: C4AppT.cpp:112
bool Active
Definition: C4Window.h:274
@ W_Fullscreen
Definition: C4Window.h:268
const char * getData() const
Definition: StdBuf.h:442
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174