1 #include "pch.h"
2 #include "common/Def_Str.h"
3 #include "common/Gui_Def.h"
4 #include "common/GuiCom.h"
5 #include "common/CScene.h"
6 #include "../vdrift/settings.h"
7 #include "../vdrift/game.h"
8 #include "../road/PaceNotes.h"
9 #include "CGame.h"
10 #include "CHud.h"
11 #include "CGui.h"
12 #include "SplitScreen.h"
13 #include "common/Slider.h"
14 #include "common/MultiList2.h"
15 #include <OgreCamera.h>
16 #include <OgreSceneNode.h>
17 #include "../ogre/common/RenderBoxScene.h"
18 using namespace std;
19 using namespace Ogre;
20 using namespace MyGUI;
21 
22 
23 ///  Gui Events
24 
25 //    [Car]
26 //---------------------------------------------------------------------
chkAbs(WP wp)27 void CGui::chkAbs(WP wp)
28 {	if (pChall && !pChall->abs)  return;	ChkEv(abs[iTireSet]);	if (pGame)  pGame->ProcessNewSettings();	}
chkTcs(WP wp)29 void CGui::chkTcs(WP wp)
30 {	if (pChall && !pChall->tcs)  return;	ChkEv(tcs[iTireSet]);	if (pGame)  pGame->ProcessNewSettings();	}
31 
chkGear(Ck *)32 void CGui::chkGear(Ck*)
33 {
34 	if (pGame)  pGame->ProcessNewSettings();
35 }
36 
37 //  reset to same as in default.cfg
btnSSSReset(WP)38 void CGui::btnSSSReset(WP)
39 {
40 	pSet->sss_effect[0] = 0.574f;  pSet->sss_velfactor[0] = 0.626f;
41 	pSet->sss_effect[1] = 0.650f;  pSet->sss_velfactor[1] = 0.734f;
42 	SldUpd_TireSet();  slSSS(0);
43 }
btnSteerReset(WP)44 void CGui::btnSteerReset(WP)
45 {
46 	pSet->steer_range[0] = 1.00f;  pSet->steer_sim[0] = 0.71f;
47 	pSet->steer_range[1] = 0.76f;  pSet->steer_sim[1] = 1.00f;
48 	SldUpd_TireSet();  slSSS(0);
49 }
50 
51 //  sss sliders,  upd graph
slSSS(SV * sv)52 void CGui::slSSS(SV* sv)
53 {
54 	///  upd sss graph
55 	float xs = 5.f, yo = 166.f, x2 = 500.f;
56 	const IntSize& wi = app->mWndOpts->getSize();
57 	const float sx = wi.width/1248.f, sy = wi.height/935.f;
58 	xs *= sx;  yo *= sy;  x2 *= sx;
59 
60 	std::vector<FloatPoint> points,grid;
61 	float vmax = 300.f;  // kmh
62 	const int ii = 200;
63 	int i;
64 	for (i = 0; i <= ii; ++i)
65 	{	float v = float(i)/ii * vmax / 3.6f;  // to m/s
66 		float f = CARCONTROLMAP_LOCAL::GetSSScoeff(v, pSet->sss_velfactor[iTireSet], pSet->sss_effect[iTireSet]);
67 		points.push_back(FloatPoint(v * xs, yo - yo * f));
68 	}
69 	graphSSS->setPoints(points);
70 
71 	//  grid lines
72 	const int y1 = yo +10, y2 = -10, x1 = -10;  //outside
73 	for (i = 0; i < 6; ++i)  // ||
74 	{	float v = i * 50.f / 3.6f;
75 		grid.push_back(FloatPoint(v * xs,  i%2==0 ? y1 : y2));
76 		grid.push_back(FloatPoint(v * xs,  i%2==0 ? y2 : y1));
77 	}
78 	grid.push_back(FloatPoint(x2, y1));
79 	grid.push_back(FloatPoint(x1, y1));
80 	for (i = 0; i < 4; ++i)  // ==
81 	{	grid.push_back(FloatPoint(i%2==0 ? x1 : x2,  yo - yo * i * 0.25f));
82 		grid.push_back(FloatPoint(i%2==0 ? x2 : x1,  yo - yo * i * 0.25f));
83 	}
84 	graphSGrid->setPoints(grid);
85 }
86 
87 //  gravel/asphalt
tabTireSet(Tab,size_t id)88 void CGui::tabTireSet(Tab, size_t id)
89 {
90 	iTireSet = id;
91 	SldUpd_TireSet();
92 	bchAbs->setStateSelected(pSet->abs[id]);
93 	bchTcs->setStateSelected(pSet->tcs[id]);
94 	slSSS(0);
95 }
96 
SldUpd_TireSet()97 void CGui::SldUpd_TireSet()
98 {
99 	int i = iTireSet;
100 	svSSSEffect.UpdF(&pSet->sss_effect[i]);
101 	svSSSVelFactor.UpdF(&pSet->sss_velfactor[i]);
102 	svSteerRangeSurf.UpdF(&pSet->steer_range[i]);
103 	svSteerRangeSim.UpdF(&pSet->steer_sim[pSet->gui.sim_mode == "easy" ? 0 : 1]);
104 }
105 
106 //  player
tabPlayer(Tab,size_t id)107 void CGui::tabPlayer(Tab, size_t id)
108 {
109 	iCurCar = id;
110 	//  update gui for this car (color h,s,v, name, img)
111 	bool plr = iCurCar < 4;
112 	if (plr)
113 	{
114 		string c = pSet->gui.car[iCurCar];
115 		for (size_t i=0; i < carList->getItemCount(); ++i)
116 		if (carList->getItemNameAt(i).substr(7) == c)
117 		{	carList->setIndexSelected(i);
118 			listCarChng(carList, i);
119 	}	}
120 	carList->setVisible(plr);
121 
122 	UpdCarClrSld(false);  // no car color change
123 }
124 
125 //  car color
126 //---------------------------------------------------------------------
127 //  3. apply new color to car/ghost
SetCarClr()128 void CGui::SetCarClr()
129 {
130 	if (!bGI)  return;
131 
132 	int s = app->carModels.size(), i;
133 	if (iCurCar == 4)  // ghost
134 	{
135 		for (i=0; i < s; ++i)
136 			if (app->carModels[i]->isGhost() && !app->carModels[i]->isGhostTrk())
137 				app->carModels[i]->ChangeClr();
138 	}
139 	else if (iCurCar == 5)  // track's ghost
140 	{
141 		for (i=0; i < s; ++i)
142 			if (app->carModels[i]->isGhostTrk())
143 				app->carModels[i]->ChangeClr();
144 	}else
145 		if (iCurCar < s)  // player
146 			app->carModels[iCurCar]->ChangeClr();
147 }
148 
149 //  2. upd game set color and sliders
UpdCarClrSld(bool upd)150 void CGui::UpdCarClrSld(bool upd)
151 {
152 	SldUpd_CarClr();
153 	int i = iCurCar;
154 	pSet->game.car_hue[i] = pSet->gui.car_hue[i];  // copy to apply
155 	pSet->game.car_sat[i] = pSet->gui.car_sat[i];
156 	pSet->game.car_val[i] = pSet->gui.car_val[i];
157 	pSet->game.car_gloss[i]= pSet->gui.car_gloss[i];
158 	pSet->game.car_refl[i] = pSet->gui.car_refl[i];
159 	if (upd)
160 		SetCarClr();
161 }
162 
163 //  1. upd sld and pointers after tab change
SldUpd_CarClr()164 void CGui::SldUpd_CarClr()
165 {
166 	int i = iCurCar;
167 	svCarClrH.UpdF(&pSet->gui.car_hue[i]);
168 	svCarClrS.UpdF(&pSet->gui.car_sat[i]);
169 	svCarClrV.UpdF(&pSet->gui.car_val[i]);
170 	svCarClrGloss.UpdF(&pSet->gui.car_gloss[i]);
171 	svCarClrRefl.UpdF(&pSet->gui.car_refl[i]);
172 }
173 
slCarClr(SV *)174 void CGui::slCarClr(SV*)
175 {
176 	SetCarClr();
177 }
178 
179 //  color buttons
imgBtnCarClr(WP img)180 void CGui::imgBtnCarClr(WP img)
181 {
182 	int i = iCurCar;
183 	pSet->gui.car_hue[i] = s2r(img->getUserString("h"));
184 	pSet->gui.car_sat[i] = s2r(img->getUserString("s"));
185 	pSet->gui.car_val[i] = s2r(img->getUserString("v"));
186 	pSet->gui.car_gloss[i]= s2r(img->getUserString("g"));
187 	pSet->gui.car_refl[i] = s2r(img->getUserString("r"));
188 	UpdCarClrSld();
189 }
btnCarClrRandom(WP)190 void CGui::btnCarClrRandom(WP)
191 {
192 	int i = iCurCar;
193 	pSet->gui.car_hue[i] = Math::UnitRandom();
194 	pSet->gui.car_sat[i] = Math::UnitRandom();
195 	pSet->gui.car_val[i] = Math::UnitRandom();
196 	pSet->gui.car_gloss[i]= Math::UnitRandom();
197 	pSet->gui.car_refl[i] = Math::RangeRandom(0.3f,1.1f);
198 	UpdCarClrSld();
199 }
200 
201 
202 //  [Game]
203 //---------------------------------------------------------------------
204 
comboBoost(CMB)205 void CGui::comboBoost(CMB)
206 {
207 	pSet->gui.boost_type = val;  app->hud->Show();
208 }
comboFlip(CMB)209 void CGui::comboFlip(CMB)
210 {
211 	pSet->gui.flip_type = val;
212 }
comboDamage(CMB)213 void CGui::comboDamage(CMB)
214 {
215 	pSet->gui.damage_type = val;
216 }
comboRewind(CMB)217 void CGui::comboRewind(CMB)
218 {
219 	pSet->gui.rewind_type = val;
220 }
221 
radKmh(WP wp)222 void CGui::radKmh(WP wp){	Radio2(bRkmh, bRmph, true);   pSet->show_mph = false;  hud->Size();  if (app->scn->pace) app->scn->pace->UpdTxt();  }
radMph(WP wp)223 void CGui::radMph(WP wp){	Radio2(bRkmh, bRmph, false);  pSet->show_mph = true;   hud->Size();  if (app->scn->pace) app->scn->pace->UpdTxt();  }
224 
setSimMode(std::string mode)225 void CGui::setSimMode(std::string mode)
226 {
227 	pSet->gui.sim_mode = mode;  bReloadSim = true;
228 	bRsimEasy->setStateSelected(mode == "easy");
229 	bRsimNorm->setStateSelected(mode == "normal");
230 	if (bRsimHard)
231 		bRsimHard->setStateSelected(mode == "hard");
232 	tabTireSet(0,iTireSet);  listCarChng(carList,0);
233 }
234 
radSimEasy(WP)235 void CGui::radSimEasy(WP){	setSimMode("easy");  }
radSimNorm(WP)236 void CGui::radSimNorm(WP){	setSimMode("normal");  }
radSimHard(WP)237 void CGui::radSimHard(WP){	setSimMode("hard");  }
238 
btnNumPlayers(WP wp)239 void CGui::btnNumPlayers(WP wp)
240 {
241 	if      (wp->getName() == "btnPlayers1")  pSet->gui.local_players = 1;
242 	else if (wp->getName() == "btnPlayers2")  pSet->gui.local_players = 2;
243 	else if (wp->getName() == "btnPlayers3")  pSet->gui.local_players = 3;
244 	else if (wp->getName() == "btnPlayers4")  pSet->gui.local_players = 4;
245 	if (valLocPlayers)  valLocPlayers->setCaption(toStr(pSet->gui.local_players));
246 }
247 
chkStartOrd(WP wp)248 void CGui::chkStartOrd(WP wp)
249 {
250 	pSet->gui.start_order = pSet->gui.start_order==0 ? 1 : 0;
251 	Btn chk = wp->castType<Button>();
252     chk->setStateSelected(pSet->gui.start_order > 0);
253 }
254 
255 
256 //  [Graphics]  options  (game only)
257 //---------------------------------------------------------------------
258 
259 //  reflection
slReflDist(SV *)260 void CGui::slReflDist(SV*)
261 {
262 	app->recreateReflections();
263 }
slReflMode(SV * sv)264 void CGui::slReflMode(SV* sv)
265 {
266 	if (bGI)
267 	switch (pSet->refl_mode)
268 	{
269 		case 0: sv->setTextClr(0.0, 1.0, 0.0);  break;
270 		case 1: sv->setTextClr(1.0, 0.5, 0.0);  break;
271 		case 2: sv->setTextClr(1.0, 0.0, 0.0);  break;
272 	}
273 	app->recreateReflections();
274 }
recreateReflections()275 void App::recreateReflections()
276 {
277 	for (std::vector<CarModel*>::iterator it = carModels.begin(); it!=carModels.end(); it++)
278 	{
279 		delete (*it)->pReflect;
280 		(*it)->CreateReflection();
281 	}
282 }
283 
chkParTrl(Ck *)284 void CGui::chkParTrl(Ck*)
285 {
286 	for (std::vector<CarModel*>::iterator it=app->carModels.begin(); it!=app->carModels.end(); it++)
287 		(*it)->UpdParsTrails();
288 }
289 
290 
291 //  [View] size  . . . . . . . . . . . . . . . . . . . .
slHudSize(SV *)292 void CGui::slHudSize(SV*)
293 {
294 	hud->Size();
295 }
slHudCreate(SV *)296 void CGui::slHudCreate(SV*)
297 {
298 	hud->Destroy();  hud->Create();
299 }
chkHudCreate(Ck *)300 void CGui::chkHudCreate(Ck*)
301 {
302 	hud->Destroy();  hud->Create();
303 }
304 
slSizeArrow(SV *)305 void CGui::slSizeArrow(SV*)
306 {
307 	float v = pSet->size_arrow * 0.5f;
308 	if (hud->arrow.nodeRot)
309 		hud->arrow.nodeRot->setScale(v * Vector3::UNIT_SCALE);
310 }
slCountdownTime(SL)311 void CGui::slCountdownTime(SL)
312 {
313 	float v = (int)(val * 10.f +slHalf) * 0.5f;	if (bGI)  pSet->gui.pre_time = v;
314 	if (valCountdownTime){	valCountdownTime->setCaption(fToStr(v,1,4));  }
315 }
316 
317 
318 //  [View]  . . . . . . . . . . . . . . . . . . . .    ---- checks ----    . . . . . . . . . . . . . . . . . . . .
319 
chkWireframe(Ck *)320 void CGui::chkWireframe(Ck*)
321 {
322 	bool b = app->mbWireFrame;
323 
324 	///  Set for all cameras
325 	PolygonMode mode = b ? PM_WIREFRAME : PM_SOLID;
326 
327 	app->refreshCompositor(b);  // disable effects
328 
329 	if (app->mSplitMgr)
330 	for (std::list<Camera*>::iterator it=app->mSplitMgr->mCameras.begin(); it!=app->mSplitMgr->mCameras.end(); ++it)
331 		(*it)->setPolygonMode(mode);
332 
333 	if (app->ndSky)
334 		app->ndSky->setVisible(!b);  // hide sky
335 }
336 
337 //  Hud
chkHudShow(Ck *)338 void CGui::chkHudShow(Ck*)
339 {
340 	hud->Show();
341 }
342 
chkArrow(Ck *)343 void CGui::chkArrow(Ck*)
344 {
345 	if (hud->arrow.nodeRot)
346 		hud->arrow.nodeRot->setVisible(pSet->check_arrow && !app->bHideHudArr);
347 }
chkBeam(Ck *)348 void CGui::chkBeam(Ck*)
349 {
350 	for (int i=0; i < app->carModels.size(); ++i)
351 		app->carModels[i]->ShowNextChk(pSet->check_beam && !app->bHideHudBeam);
352 }
353 
354 //  hud minimap
chkMinimap(Ck *)355 void CGui::chkMinimap(Ck*)
356 {
357 	for (int c=0; c < hud->hud.size(); ++c)
358 		if (hud->hud[c].ndMap)
359 			hud->hud[c].ndMap->setVisible(pSet->trackmap);
360 }
361 
chkMiniUpd(Ck *)362 void CGui::chkMiniUpd(Ck*)
363 {
364 	hud->UpdMiniTer();
365 }
366 
367 //  pacenotes
slUpd_Pace(SV *)368 void CGui::slUpd_Pace(SV*)
369 {
370 	app->scn->UpdPaceParams();
371 }
372 
chkReverse(Ck *)373 void CGui::chkReverse(Ck*){  gcom->ReadTrkStats();  }
374 
375 //  graphs
chkGraphs(Ck *)376 void CGui::chkGraphs(Ck*)
377 {
378 	bool te = pSet->graphs_type == Gh_TireEdit;
379 	for (int i=0; i < app->graphs.size(); ++i)
380 		app->graphs[i]->SetVisible(!te ? pSet->show_graphs :  // reference vis
381 			pSet->show_graphs && (i < 2*App::TireNG || i >= 4*App::TireNG || pSet->te_reference));
382 }
comboGraphs(CMB)383 void CGui::comboGraphs(CMB)
384 {
385 	if (valGraphsType)
386 		valGraphsType->setCaption(toStr(val));
387 	if (bGI /*&& pSet->graphs_type != v*/)  {
388 		pSet->graphs_type = (eGraphType)val;
389 		app->DestroyGraphs();  app->CreateGraphs();  }
390 }
391 
392 //  Startup
chkMultiThread(WP wp)393 void CGui::chkMultiThread(WP wp)
394 {
395 	pSet->multi_thr = pSet->multi_thr ? 0 : 1;
396 	Btn chk = wp->castType<Button>();
397 	chk->setStateSelected(pSet->multi_thr > 0);
398 }
399 
400 
401 //  [Effects]  . . . . . . . . . . . . . . . . . . . .    ---- ------ ----    . . . . . . . . . . . . . . . . . . . .
402 
chkAllEffects(Ck *)403 void CGui::chkAllEffects(Ck*)
404 {
405 	app->recreateCompositor();  //app->refreshCompositor();
406 	app->scn->changeShadows();
407 }
chkEffUpd(Ck *)408 void CGui::chkEffUpd(Ck*)
409 {
410 	app->refreshCompositor();
411 }
chkEffUpdShd(Ck *)412 void CGui::chkEffUpdShd(Ck*)
413 {
414 	app->refreshCompositor();
415 	app->scn->changeShadows();
416 }
417 
slEffUpd(SV *)418 void CGui::slEffUpd(SV*)
419 {
420 	if (bGI)  app->refreshCompositor();
421 }
422 
423 
424 //  [Sound]
slVolMaster(SV *)425 void CGui::slVolMaster(SV*)
426 {
427 	pGame->ProcessNewSettings();
428 }
429 
slVolHud(SV *)430 void CGui::slVolHud(SV*)
431 {
432 	pGame->UpdHudSndVol();
433 }
434 
435 
436 //  Hints, welcome screen
437 //---------------------------------------------------------------------
438 const static char hOrd[/*CGui::iHints*/17]={0,1,2,3,4,5,16,6,7,8,9,10,11,12,13,14, 15};
UpdHint()439 void CGui::UpdHint()
440 {
441 	if (!edHintTitle)  return;
442 	int h = hOrd[iHintCur];
443 	edHintTitle->setCaption(TR("#C0E0FF#{Hint}  #A0D0FF") +toStr(iHintCur+1)+"/"+toStr(iHints)+
444 					  ":   "+TR("#D0E8FF#{Hint-"+toStr(h)+"}"));
445 	edHintText->setCaption(TR("#{Hint-"+toStr(h)+"text}"));
446 }
447 
btnHintPrev(WP)448 void CGui::btnHintPrev(WP)
449 {
450 	iHintCur = (iHintCur-1+iHints) % iHints;  UpdHint();
451 }
btnHintNext(WP)452 void CGui::btnHintNext(WP)
453 {
454 	iHintCur = (iHintCur+1) % iHints;         UpdHint();
455 }
456 
btnHintScreen(WP)457 void CGui::btnHintScreen(WP)
458 {
459 	GuiShortcut(MNU_Options, TABo_Screen,0);  btnHintClose(0);
460 }
btnHintInput(WP)461 void CGui::btnHintInput(WP)
462 {
463 	GuiShortcut(MNU_Options, TABo_Input,0);  btnHintClose(0);
464 }
465 
btnHintClose(WP)466 void CGui::btnHintClose(WP)
467 {
468 	app->mWndWelcome->setVisible(false);
469 }
470 
471 
472 
473 ///  3d car view  TODO ...
474 //--------------------------------------------
475 
GetViewSize()476 IntCoord CGui::GetViewSize()
477 {
478 	IntCoord ic = app->mWndGame->getClientCoord();
479 	return IntCoord(ic.width*0.56f, ic.height*0.38f, ic.width*0.43f, ic.height*0.57f);
480 }
481 
InitCarPrv()482 void CGui::InitCarPrv()
483 {
484 	viewCanvas = app->mWndGame->createWidget<Canvas>("Canvas", GetViewSize(), Align::Stretch);
485 	viewCanvas->setInheritsAlpha(false);
486 	viewCanvas->setPointer("hand");
487 	viewCanvas->setVisible(true);
488 	viewBox->setCanvas(viewCanvas);
489 	viewBox->setBackgroundColour(Colour(0.32,0.35,0.37,1));
490 	//viewBox->setAutoRotation(true);
491 	viewBox->setMouseRotation(true);
492 
493 	//viewBox->injectObject("sphere.mesh");
494 	viewCar = new CarModel(3, 0, CarModel::CT_GHOST, "XZ", viewBox->mScene, pSet, pGame, app->scn->sc, 0, app);
495 	viewCar->Load();
496 	viewCar->Create();
497 	viewCar->ChangeClr();
498 
499 	PosInfo p;  p.bNew = true;
500 	p.pos = Vector3(0,0,0);
501 	p.rot = Quaternion(Degree(180),Vector3(1,0,0)) * Quaternion(Degree(50),Vector3(0,1,0));
502 	p.whPos[0] = Vector3(0,-1,-1);  p.whRot[0] = p.rot;
503 
504 	viewCar->Update(p, p, 0.f);
505 	viewBox->mCamera->setPosition(Vector3(0,4,-7));
506 	viewBox->mCamera->setDirection(-Vector3(0,4,-7));
507 	//viewBox->mCameraNode->setPosition(Vector3(0,2,4));
508 	//viewBox->mCameraNode->lookAt(Vector3(0,0,0), Node::TS_WORLD);
509 	//viewBox->updateViewport();
510 }
511