OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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  pMenu = nullptr;
39 }
40 
42 {
43  if (pMenu) delete pMenu;
44  if (pSurface) delete pSurface;
45 }
46 
47 
49 {
51  return Init(C4Window::W_Fullscreen, pApp, C4ENGINECAPTION, &r);
52 }
53 
55 {
56  if (Game.IsRunning)
57  ShowAbortDlg();
58  else
59  Application.Quit();
60 }
61 
63 {
64  if (pSurface) delete pSurface;
65  pSurface = nullptr;
67 }
68 
70 {
71  // Execute menu
72  if (pMenu) pMenu->Execute();
73  // Draw
74  RequestUpdate();
75 }
76 
78 {
79  int iPlrNum; C4Player *pPlr;
80  // Not active
81  if (!Active) return false;
82  // Determine film mode
83  bool fFilm = (Game.C4S.Head.Replay && Game.C4S.Head.Film);
84  // Check viewports
85  switch (::Viewports.GetViewportCount())
86  {
87  // No viewports: create no-owner viewport
88  case 0:
89  iPlrNum = NO_OWNER;
90  // Film mode: create viewport for first player (instead of no-owner)
91  if (fFilm)
92  if ((pPlr = ::Players.First))
93  iPlrNum = pPlr->Number;
94  // Create viewport
95  ::Viewports.CreateViewport(iPlrNum, iPlrNum==NO_OWNER);
96  // Non-film (observer mode)
97  if (!fFilm)
98  {
99  // Activate mouse control
100  ::MouseControl.Init(iPlrNum);
101  // Display message for how to open observer menu (this message will be cleared if any owned viewport opens)
102  StdStrBuf sKey;
103  sKey.Format("<c ffff00><%s></c>", Game.KeyboardInput.GetKeyCodeNameByKeyName("FullscreenMenuOpen", false).getData());
104  ::GraphicsSystem.FlashMessage(FormatString(LoadResStr("IDS_MSG_PRESSORPUSHANYGAMEPADBUTT"), sKey.getData()).getData());
105  }
106  break;
107  // One viewport: do nothing
108  case 1:
109  break;
110  // More than one viewport: remove all no-owner viewports
111  default:
113  break;
114  }
115  // Look for no-owner viewport
117  // No no-owner viewport found
118  if (!pNoOwnerVp)
119  {
120  // Close any open fullscreen menu
121  CloseMenu();
122  }
123  // No-owner viewport present
124  else
125  {
126  // movie mode: player present, and no valid viewport assigned?
127  if (Game.C4S.Head.Replay && Game.C4S.Head.Film && (pPlr = ::Players.First))
128  // assign viewport to joined player
129  pNoOwnerVp->Init(pPlr->Number, true);
130  }
131  // Done
132  return true;
133 }
134 
136 {
137  // abort dialog already shown
138  if (C4AbortGameDialog::IsShown()) return false;
139  // not while game over dialog is open
140  if (C4GameOverDlg::IsShown()) return false;
141  // show abort dialog
143 }
144 
146 {
147  // Not during game over dialog
148  if (C4GameOverDlg::IsShown()) return false;
149  // Close previous
150  CloseMenu();
151  // Open menu
152  pMenu = new C4MainMenu();
153  return pMenu->ActivateMain(NO_OWNER);
154 }
155 
157 {
158  if (pMenu)
159  {
160  if (pMenu->IsActive()) pMenu->Close(false);
161  delete pMenu;
162  pMenu = nullptr;
163  }
164 }
165 
167 {
169 }
170 
172 {
173  if (pMenu) return pMenu->KeyControl(byCom);
174  return false;
175 }
const char * getData() const
Definition: StdBuf.h:442
bool IsRunning
Definition: C4Game.h:139
void PerformUpdate() override
bool KeyControl(BYTE byCom)
Definition: C4Menu.cpp:473
bool ActivateMenuMain()
C4MainMenu * pMenu
Definition: C4FullScreen.h:30
C4Game Game
Definition: C4Globals.cpp:52
int32_t Number
Definition: C4Player.h:86
C4Scenario C4S
Definition: C4Game.h:74
~C4FullScreen() override
bool Replay
Definition: C4Scenario.h:72
C4Surface * pSurface
Definition: C4Window.h:274
void Close(bool fOK)
bool ShowRemoveDlg(Dialog *pDlg)
Definition: C4Rect.h:27
uint8_t BYTE
C4Player * First
Definition: C4PlayerList.h:31
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
C4Viewport * GetViewport(int32_t iPlayer, C4Viewport *pPrev=nullptr)
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdStrBuf GetKeyCodeNameByKeyName(const char *szKeyName, bool fShort=false, int32_t iIndex=0)
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
C4KeyboardInput & KeyboardInput
Definition: C4Game.h:96
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
static bool IsShown()
Definition: C4GameOverDlg.h:92
C4PlayerList Players
const int NO_OWNER
Definition: C4Constants.h:137
void Clear() override
void CharIn(const char *c) override
bool CreateViewport(int32_t iPlayer, bool fSilent=false)
Definition: C4Viewport.cpp:917
int GetConfigWidth()
Definition: C4Application.h:82
bool IsActive()
Definition: C4Menu.cpp:480
void Quit() override
virtual bool CharIn(const char *c)
Definition: C4Gui.cpp:779
bool ViewportCheck()
bool Init(int32_t iPlayer, bool fSetTempOnly)
Definition: C4Viewport.cpp:658
void Close() override
C4ViewportList Viewports
Definition: C4Viewport.cpp:841
bool ShowAbortDlg()
void FlashMessage(const char *szMessage)
virtual void RequestUpdate()
Definition: C4AppT.cpp:109
bool Init(int32_t iPlayer)
void Execute()
Definition: C4Menu.cpp:903
bool Active
Definition: C4Window.h:273
bool CloseViewport(int32_t iPlayer, bool fSilent)
Definition: C4Viewport.cpp:961
int32_t GetViewportCount()
int GetConfigHeight()
Definition: C4Application.h:83
C4SHead Head
Definition: C4Scenario.h:230
static bool IsShown()
Definition: C4GameDialogs.h:47
virtual void Clear()
Definition: C4AppT.cpp:99
C4Window * Init(C4AbstractApp *pApp)
bool MenuKeyControl(BYTE byCom)
C4Application Application
Definition: C4Globals.cpp:44
bool ActivateMain(int32_t iPlayer)
Definition: C4MainMenu.cpp:566
int32_t Film
Definition: C4Scenario.h:73
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270