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 "game/C4Game.h"
24 #include "game/C4Application.h"
25 #include "game/C4Viewport.h"
26 #include "c4group/C4Language.h"
27 #include "gui/C4Gui.h"
28 #include "gui/C4GameDialogs.h"
29 #include "player/C4Player.h"
30 #include "gui/C4GameOverDlg.h"
31 #include "game/C4GraphicsSystem.h"
32 #include "gui/C4MouseControl.h"
33 #include "player/C4PlayerList.h"
34 #include "C4Version.h"
35 
36 void C4FullScreen::CharIn(const char * c) { ::pGUI->CharIn(c); }
37 
39 {
40  pMenu = nullptr;
41 }
42 
44 {
45  if (pMenu) delete pMenu;
46  if (pSurface) delete pSurface;
47 }
48 
49 
51 {
53  return Init(C4Window::W_Fullscreen, pApp, C4ENGINECAPTION, &r);
54 }
55 
57 {
58  if (Game.IsRunning)
59  ShowAbortDlg();
60  else
61  Application.Quit();
62 }
63 
65 {
66  if (pSurface) delete pSurface;
67  pSurface = 0;
69 }
70 
72 {
73  // Execute menu
74  if (pMenu) pMenu->Execute();
75  // Draw
76  RequestUpdate();
77 }
78 
80 {
81  int iPlrNum; C4Player *pPlr;
82  // Not active
83  if (!Active) return false;
84  // Determine film mode
85  bool fFilm = (Game.C4S.Head.Replay && Game.C4S.Head.Film);
86  // Check viewports
87  switch (::Viewports.GetViewportCount())
88  {
89  // No viewports: create no-owner viewport
90  case 0:
91  iPlrNum = NO_OWNER;
92  // Film mode: create viewport for first player (instead of no-owner)
93  if (fFilm)
94  if ((pPlr = ::Players.First))
95  iPlrNum = pPlr->Number;
96  // Create viewport
97  ::Viewports.CreateViewport(iPlrNum, iPlrNum==NO_OWNER);
98  // Non-film (observer mode)
99  if (!fFilm)
100  {
101  // Activate mouse control
102  ::MouseControl.Init(iPlrNum);
103  // Display message for how to open observer menu (this message will be cleared if any owned viewport opens)
104  StdStrBuf sKey;
105  sKey.Format("<c ffff00><%s></c>", Game.KeyboardInput.GetKeyCodeNameByKeyName("FullscreenMenuOpen", false).getData());
106  ::GraphicsSystem.FlashMessage(FormatString(LoadResStr("IDS_MSG_PRESSORPUSHANYGAMEPADBUTT"), sKey.getData()).getData());
107  }
108  break;
109  // One viewport: do nothing
110  case 1:
111  break;
112  // More than one viewport: remove all no-owner viewports
113  default:
115  break;
116  }
117  // Look for no-owner viewport
119  // No no-owner viewport found
120  if (!pNoOwnerVp)
121  {
122  // Close any open fullscreen menu
123  CloseMenu();
124  }
125  // No-owner viewport present
126  else
127  {
128  // movie mode: player present, and no valid viewport assigned?
129  if (Game.C4S.Head.Replay && Game.C4S.Head.Film && (pPlr = ::Players.First))
130  // assign viewport to joined player
131  pNoOwnerVp->Init(pPlr->Number, true);
132  }
133  // Done
134  return true;
135 }
136 
138 {
139  // abort dialog already shown
140  if (C4AbortGameDialog::IsShown()) return false;
141  // not while game over dialog is open
142  if (C4GameOverDlg::IsShown()) return false;
143  // show abort dialog
145 }
146 
148 {
149  // Not during game over dialog
150  if (C4GameOverDlg::IsShown()) return false;
151  // Close previous
152  CloseMenu();
153  // Open menu
154  pMenu = new C4MainMenu();
155  return pMenu->ActivateMain(NO_OWNER);
156 }
157 
159 {
160  if (pMenu)
161  {
162  if (pMenu->IsActive()) pMenu->Close(false);
163  delete pMenu;
164  pMenu = nullptr;
165  }
166 }
167 
169 {
171 }
172 
174 {
175  if (pMenu) return pMenu->KeyControl(byCom);
176  return false;
177 }
const char * getData() const
Definition: StdBuf.h:450
bool IsRunning
Definition: C4Game.h:141
bool KeyControl(BYTE byCom)
Definition: C4Menu.cpp:476
bool ActivateMenuMain()
C4MainMenu * pMenu
Definition: C4FullScreen.h:30
C4Game Game
Definition: C4Globals.cpp:52
int32_t Number
Definition: C4Player.h:88
C4Scenario C4S
Definition: C4Game.h:76
virtual void PerformUpdate()
bool Replay
Definition: C4Scenario.h:72
C4Surface * pSurface
Definition: C4Window.h:279
void Close(bool fOK)
bool ShowRemoveDlg(Dialog *pDlg)
Definition: C4Rect.h:29
uint8_t BYTE
C4Player * First
Definition: C4PlayerList.h:31
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
C4Viewport * GetViewport(int32_t iPlayer, C4Viewport *pPrev=nullptr)
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
virtual void Close()
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:1194
virtual void Quit()
virtual void CharIn(const char *c)
C4KeyboardInput & KeyboardInput
Definition: C4Game.h:98
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
static bool IsShown()
Definition: C4GameOverDlg.h:92
C4PlayerList Players
const int NO_OWNER
Definition: C4Constants.h:138
bool CreateViewport(int32_t iPlayer, bool fSilent=false)
Definition: C4Viewport.cpp:920
int GetConfigWidth()
Definition: C4Application.h:82
bool IsActive()
Definition: C4Menu.cpp:483
virtual bool CharIn(const char *c)
Definition: C4Gui.cpp:782
bool ViewportCheck()
bool Init(int32_t iPlayer, bool fSetTempOnly)
Definition: C4Viewport.cpp:658
C4ViewportList Viewports
Definition: C4Viewport.cpp:841
bool ShowAbortDlg()
void FlashMessage(const char *szMessage)
virtual void RequestUpdate()
Definition: C4AppT.cpp:110
bool Init(int32_t iPlayer)
void Execute()
Definition: C4Menu.cpp:906
virtual void Clear()
bool Active
Definition: C4Window.h:278
bool CloseViewport(int32_t iPlayer, bool fSilent)
Definition: C4Viewport.cpp:964
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:100
C4Window * Init(C4AbstractApp *pApp)
bool MenuKeyControl(BYTE byCom)
C4Application Application
Definition: C4Globals.cpp:44
bool ActivateMain(int32_t iPlayer)
Definition: C4MainMenu.cpp:567
int32_t Film
Definition: C4Scenario.h:73
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277