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 
CharIn(const char * c)34 void C4FullScreen::CharIn(const char * c) { ::pGUI->CharIn(c); }
35 
C4FullScreen()36 C4FullScreen::C4FullScreen()
37 {
38 	pMenu = nullptr;
39 }
40 
~C4FullScreen()41 C4FullScreen::~C4FullScreen()
42 {
43 	if (pMenu) delete pMenu;
44 	if (pSurface) delete pSurface;
45 }
46 
47 
Init(C4AbstractApp * pApp)48 C4Window * C4FullScreen::Init(C4AbstractApp * pApp)
49 {
50 	C4Rect r(0, 0, Application.GetConfigWidth(), Application.GetConfigHeight());
51 	return Init(C4Window::W_Fullscreen, pApp, C4ENGINECAPTION, &r);
52 }
53 
Close()54 void C4FullScreen::Close()
55 {
56 	if (Game.IsRunning)
57 		ShowAbortDlg();
58 	else
59 		Application.Quit();
60 }
61 
Clear()62 void C4FullScreen::Clear()
63 {
64 	if (pSurface) delete pSurface;
65 	pSurface = nullptr;
66 	C4Window::Clear();
67 }
68 
Execute()69 void C4FullScreen::Execute()
70 {
71 	// Execute menu
72 	if (pMenu) pMenu->Execute();
73 	// Draw
74 	RequestUpdate();
75 }
76 
ViewportCheck()77 bool C4FullScreen::ViewportCheck()
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:
112 		::Viewports.CloseViewport(NO_OWNER, true);
113 		break;
114 	}
115 	// Look for no-owner viewport
116 	C4Viewport *pNoOwnerVp = ::Viewports.GetViewport(NO_OWNER);
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 
ShowAbortDlg()135 bool C4FullScreen::ShowAbortDlg()
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
142 	return ::pGUI->ShowRemoveDlg(new C4AbortGameDialog());
143 }
144 
ActivateMenuMain()145 bool C4FullScreen::ActivateMenuMain()
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 
CloseMenu()156 void C4FullScreen::CloseMenu()
157 {
158 	if (pMenu)
159 	{
160 		if (pMenu->IsActive()) pMenu->Close(false);
161 		delete pMenu;
162 		pMenu = nullptr;
163 	}
164 }
165 
PerformUpdate()166 void C4FullScreen::PerformUpdate()
167 {
168 	GraphicsSystem.Execute();
169 }
170 
MenuKeyControl(BYTE byCom)171 bool C4FullScreen::MenuKeyControl(BYTE byCom)
172 {
173 	if (pMenu) return pMenu->KeyControl(byCom);
174 	return false;
175 }
176