1 /*
2 * This file is part of the Colobot: Gold Edition source code
3 * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
4 * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see http://gnu.org/licenses
18 */
19
20 #include "ui/screen/screen_setup.h"
21
22 #include "common/config.h"
23
24 #include "app/app.h"
25
26 #include "common/restext.h"
27 #include "common/settings.h"
28 #include "common/stringutils.h"
29
30 #include "graphics/engine/camera.h"
31
32 #include "ui/controls/button.h"
33 #include "ui/controls/interface.h"
34 #include "ui/controls/window.h"
35
36 namespace Ui
37 {
38
39 Phase CScreenSetup::m_tab = PHASE_SETUPg;
40
CScreenSetup()41 CScreenSetup::CScreenSetup()
42 : m_simulationSetup{false}
43 {
44 m_settings = CSettings::GetInstancePointer();
45 m_camera = m_main->GetCamera();
46 }
47
SetInSimulation(bool simulationSetup)48 void CScreenSetup::SetInSimulation(bool simulationSetup)
49 {
50 m_simulationSetup = simulationSetup;
51 }
52
GetTab()53 Phase CScreenSetup::GetTab()
54 {
55 return m_tab;
56 }
57
CreateInterface()58 void CScreenSetup::CreateInterface()
59 {
60 CWindow* pw;
61 CButton* pb;
62 Math::Point pos, ddim;
63 std::string name;
64
65 pos.x = 0.10f;
66 pos.y = 0.10f;
67 ddim.x = 0.80f;
68 ddim.y = 0.80f;
69 pw = m_interface->CreateWindows(pos, ddim, 12, EVENT_WINDOW5);
70 pw->SetClosable(true);
71 GetResource(RES_TEXT, RT_TITLE_SETUP, name);
72 pw->SetName(name);
73
74 pos.x = 0.70f;
75 pos.y = 0.10f;
76 ddim.x = 0.20f;
77 ddim.y = 0.20f;
78 pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
79
80 pos.x = 0.10f;
81 ddim.x = 0.80f;
82 pos.y = 0.76f;
83 ddim.y = 0.05f;
84 pw->CreateGroup(pos, ddim, 3, EVENT_NULL); // transparent -> gray
85
86 ddim.x = 0.78f/5-0.01f;
87 ddim.y = 0.06f;
88 pos.x = 0.115f;
89 pos.y = 0.76f;
90 pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUPd);
91 pb->SetState(STATE_SHADOW);
92 pb->SetState(STATE_CARD);
93 pb->SetState(STATE_CHECK, (m_tab == PHASE_SETUPd));
94
95 pos.x += ddim.x+0.01f;
96 pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUPg);
97 pb->SetState(STATE_SHADOW);
98 pb->SetState(STATE_CARD);
99 pb->SetState(STATE_CHECK, (m_tab == PHASE_SETUPg));
100
101 pos.x += ddim.x+0.01f;
102 pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUPp);
103 pb->SetState(STATE_SHADOW);
104 pb->SetState(STATE_CARD);
105 pb->SetState(STATE_CHECK, (m_tab == PHASE_SETUPp));
106
107 pos.x += ddim.x+0.01f;
108 pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUPc);
109 pb->SetState(STATE_SHADOW);
110 pb->SetState(STATE_CARD);
111 pb->SetState(STATE_CHECK, (m_tab == PHASE_SETUPc));
112
113 pos.x += ddim.x+0.01f;
114 pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUPs);
115 pb->SetState(STATE_SHADOW);
116 pb->SetState(STATE_CARD);
117 pb->SetState(STATE_CHECK, (m_tab == PHASE_SETUPs));
118
119 pos.x = 0.10f;
120 ddim.x = 0.80f;
121 pos.y = 0.34f;
122 ddim.y = 0.42f;
123 pw->CreateGroup(pos, ddim, 2, EVENT_INTERFACE_GLINTu); // orange -> transparent
124 pos.x = 0.10f+(6.0f/640.0f);
125 ddim.x = 0.80f-(11.0f/640.0f);
126 pos.y = 0.74f;
127 ddim.y = 0.02f;
128 pw->CreateGroup(pos, ddim, 1, EVENT_INTERFACE_GLINTb); // orange bar
129
130 ddim.x = dim.x*4;
131 ddim.y = dim.y*1;
132 pos.x = ox+sx*3;
133 pos.y = oy+sy*2;
134 pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK);
135 pb->SetState(STATE_SHADOW);
136
137 if ( !m_simulationSetup )
138 {
139 SetBackground("textures/interface/interface.png");
140 CreateVersionDisplay();
141 }
142 }
143
EventProcess(const Event & event)144 bool CScreenSetup::EventProcess(const Event &event)
145 {
146 if ( !m_simulationSetup )
147 {
148 CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
149 if ( pw == nullptr ) return false;
150
151 if ( event.type == pw->GetEventTypeClose() ||
152 event.type == EVENT_INTERFACE_BACK ||
153 (event.type == EVENT_KEY_DOWN && event.GetData<KeyEventData>()->key == KEY(ESCAPE)) )
154 {
155 m_settings->SaveSettings();
156 m_main->ChangePhase(PHASE_MAIN_MENU);
157 return false;
158 }
159
160 switch( event.type )
161 {
162 case EVENT_INTERFACE_SETUPd:
163 m_main->ChangePhase(PHASE_SETUPd);
164 return false;
165
166 case EVENT_INTERFACE_SETUPg:
167 m_main->ChangePhase(PHASE_SETUPg);
168 return false;
169
170 case EVENT_INTERFACE_SETUPp:
171 m_main->ChangePhase(PHASE_SETUPp);
172 return false;
173
174 case EVENT_INTERFACE_SETUPc:
175 m_main->ChangePhase(PHASE_SETUPc);
176 return false;
177
178 case EVENT_INTERFACE_SETUPs:
179 m_main->ChangePhase(PHASE_SETUPs);
180 return false;
181
182 default:
183 break;
184 }
185 }
186 else
187 {
188 CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
189 if ( pw == nullptr ) return false;
190
191 if ( event.type == pw->GetEventTypeClose() ||
192 event.type == EVENT_INTERFACE_BACK ||
193 (event.type == EVENT_KEY_DOWN && event.GetData<KeyEventData>()->key == KEY(ESCAPE)) )
194 {
195 m_settings->SaveSettings();
196 m_interface->DeleteControl(EVENT_WINDOW5);
197 m_main->ChangePhase(PHASE_SIMUL);
198 m_main->StopSuspend();
199 return false;
200 }
201
202 switch( event.type )
203 {
204 case EVENT_INTERFACE_SETUPd:
205 m_main->ChangePhase(PHASE_SETUPds);
206 return false;
207
208 case EVENT_INTERFACE_SETUPg:
209 m_main->ChangePhase(PHASE_SETUPgs);
210 return false;
211
212 case EVENT_INTERFACE_SETUPp:
213 m_main->ChangePhase(PHASE_SETUPps);
214 return false;
215
216 case EVENT_INTERFACE_SETUPc:
217 m_main->ChangePhase(PHASE_SETUPcs);
218 return false;
219
220 case EVENT_INTERFACE_SETUPs:
221 m_main->ChangePhase(PHASE_SETUPss);
222 return false;
223
224 default:
225 break;
226 }
227 }
228
229 return true;
230 }
231
232 } // namespace Ui
233