1 #pragma once
2 #include "BaseApp.h"
3 #include "common/Gui_Def.h"
4 #include "common/SliderValue.h"
5 
6 #include <MyGUI_Enumerator.h>
7 #include "common/MessageBox/MessageBoxStyle.h"
8 
9 #include "../network/networkcallbacks.hpp"
10 #include "../oics/ICSInputControlSystem.h"
11 #include <boost/thread.hpp>
12 
13 #include "ChampsXml.h"  // progress..
14 #include "ChallengesXml.h"
15 #include "CInput.h"
16 
17 namespace Ogre {  class SceneNode;  class Root;  class SceneManager;  class RenderWindow;  class Viewport;  class Light;  }
18 namespace MyGUI{  class MultiList2;  class Slider;  class Message;  class PolygonalSkin;  }
19 namespace wraps {	class RenderBoxScene;  }
20 class Scene;  class SplineRoad;  class GAME;  class CHud;  class CData;
21 class CGuiCom;  class CarInfo;  class GuiPopup;
22 
23 
24 //  tracks,cars list items - with info for sorting
25 struct CarL
26 {
27 	std::string name;
28 	const CarInfo* ci;
29 };
30 
31 
32 class CGui : public BGui,
33 			 public GameClientCallback, public MasterClientCallback,
34 			 public ICS::DetectingBindingListener
35 {
36 public:
37 	App* app;  GAME* pGame;  SETTINGS* pSet;
38 	Scene* sc;  CData* data;
39 	CHud* hud;  MyGUI::Gui* mGui;  CGuiCom* gcom;
40 
41 	CGui(App* ap1);
42 	~CGui();
43 	//friend class CarModel;
44 
45 	typedef std::list <std::string> strlist;
46 
47 
48 	///  Gui
49 	///-----------------------------------------------------------------------------------------------------------------
50 
51 	bool bGI;  // gui inited  set values
52 	void InitGui(), GuiUpdate();
53 	void UpdGuiAfterPreset();
54 
55 	Txt valTrkNet;
56 	std::vector<Tab> vSubTabsGame, vSubTabsOpts;
57 
58 	//  car list
59 	void CarListUpd(bool resetNotFound=false);
60 	void AddCarL(std::string name, const CarInfo* ci);
61 	std::list<CarL> liCar;
62 	void FillCarList();
63 
64 	const static int colCar[16],colCh[16],colChL[16],colSt[16];
65 
66 
67 	//  util
68 	void toggleGui(bool toggle=true);
69 	void GuiShortcut(MNU_Btns mnu, int tab, int subtab=-1);
70 	bool loadReadme;
71 
72 
73 	//  hints
74 	const int iHints;  int iHintCur;  void UpdHint();
75 	Ck ckShowWelcome;
76 	Ed edHintTitle, edHintText;
77 	void btnHintPrev(WP), btnHintNext(WP);
78 	void btnHintScreen(WP), btnHintInput(WP), btnHintClose(WP);
79 
80 
81 	///  [Input] tab
82 	///-----------------------------------------------------------------------------------------------------------------
83 
84 	//  bind events   . . . . .
85 	virtual void keyBindingDetected(
86 		ICS::InputControlSystem* ICS, ICS::Control* control,  SDL_Keycode key,
87 		ICS::Control::ControlChangingDirection direction);
88 
89 	virtual void joystickAxisBindingDetected(
90 		ICS::InputControlSystem* ICS, ICS::Control* control,  int deviceId, int axis,
91 		ICS::Control::ControlChangingDirection direction);
92 
93 	virtual void joystickButtonBindingDetected(
94 		ICS::InputControlSystem* ICS, ICS::Control* control,  int deviceId, unsigned int button,
95 		ICS::Control::ControlChangingDirection direction);
96 
97 	//  not needed
joystickPOVBindingDetected(ICS::InputControlSystem * ICS,ICS::Control * control,int deviceId,int pov,ICS::InputControlSystem::POVAxis axis,ICS::Control::ControlChangingDirection direction)98 	virtual void joystickPOVBindingDetected(
99 		ICS::InputControlSystem* ICS, ICS::Control* control,  int deviceId, int pov,
100 		ICS::InputControlSystem::POVAxis axis,
101 		ICS::Control::ControlChangingDirection direction) {  return;  }
102 
mouseAxisBindingDetected(ICS::InputControlSystem * ICS,ICS::Control * control,ICS::InputControlSystem::NamedAxis axis,ICS::Control::ControlChangingDirection direction)103 	virtual void mouseAxisBindingDetected(
104 		ICS::InputControlSystem* ICS, ICS::Control* control,  ICS::InputControlSystem::NamedAxis axis,
105 		ICS::Control::ControlChangingDirection direction) {  return;  }
106 
mouseButtonBindingDetected(ICS::InputControlSystem * ICS,ICS::Control * control,unsigned int button,ICS::Control::ControlChangingDirection direction)107 	virtual void mouseButtonBindingDetected(
108 		ICS::InputControlSystem* ICS, ICS::Control* control,  unsigned int button,
109 		ICS::Control::ControlChangingDirection direction) {  return;  }
110 
111 	//  init
112 	void CreateInputTab( int iTab, bool player,
113 		const std::vector<InputAction>& actions, ICS::InputControlSystem* ICS);
114 	void InitInputGui();
115 
116 	//  bind
117 	void inputBindBtnClicked(WP), inputUnbind(WP), inputBindBtn2(WP, int, int, MyGUI::MouseButton mb);
118 	enum EBind {  B_Done=0, B_First, B_Second  };
119 	void UpdateInputButton(Btn button, const InputAction& action, EBind bind = B_Done);
120 
121 	InputAction* mBindingAction;
122 	Btn mBindingSender;
123 
124 	virtual void notifyInputActionBound(bool complete);
125 	bool actionIsActive(std::string, std::string);
126 
127 	//  input gui
128 	Tab tabInput;  void tabInputChg(Tab, size_t);
129 	Txt txtInpDetail;  WP panInputDetail;  Btn chOneAxis;
130 	Ed edInputIncrease;
131 
132 	void editInput(Ed), btnInputInv(WP), chkOneAxis(WP);
133 	void comboInputKeyAllPreset(CMB);
134 	void UpdateInputBars(), inputDetailBtn(WP);
135 	bool TabInputId(int* pId);
136 
137 
138 	///  [Tweak]  -----------------------------------------
139 	const static int ciEdCar = 12;
140 	Ed edCar[ciEdCar],edPerfTest, edTweakCol;
141 	Txt txtTweakPath, txtTweakTire, txtTweakPathCol;
142 
143 	Tab tabTweak, tabEdCar;
144 	void tabCarEdChng(Tab, size_t), tabTweakChng(Tab, size_t);
145 
146 	///  tire
147 	Ed edTweakTireSet;  void editTweakTireSet(Ed);
148 	Li liTwkTiresUser, liTwkTiresOrig;
149 	void listTwkTiresUser(Li, size_t), listTwkTiresOrig(Li, size_t);
150 	void btnTweakTireLoad(WP), btnTweakTireReset(WP), btnTweakTireDelete(WP);
151 	void FillTweakLists();  Ogre::String sTireLoad;
152 
153 	///  surface
154 	Li liTwkSurfaces;  void listTwkSurfaces(Li, size_t);
155 	int idTwkSurf;  void btnTwkSurfPick(WP), updSld_TwkSurf(int id);
156 	SV svSuFrict, svSuFrictX, svSuFrictY, svSuRollDrag, svSuRollRes;
157 	SV svSuBumpWave, svSuBumpAmp, svSuBumpWave2, svSuBumpAmp2;
158 	Cmb cmbSurfTire, cmbSurfType;  void comboSurfTire(CMB), comboSurfType(CMB);
159 
160 	void TweakToggle();
161 	void TweakCarSave(),TweakCarLoad(), TweakTireSave();
162 
163 	void TweakColUpd(bool user), TweakColLoad(),TweakColSave();
164 
165 	const static Ogre::String csLateral[15][2], csLongit[13][2], csAlign[18][2], sCommon;
166 
167 	void btnTweakCarSave(WP),  btnTweakCarLoad(WP);
168 	void btnTweakTireSave(WP), btnTweakColSave(WP);
169 
170 	bool GetCarPath(std::string* pathCar/*out*/,
171 		std::string* pathSave/*=0*/, std::string* pathSaveDir/*=0*/,
172 		std::string carname, bool forceOrig=false);
173 
174 	//  graphs
175 	Cmb cmbGraphs;  void comboGraphs(CMB);  Txt valGraphsType;
176 
177 
178 	///  [Options]  game only
179 	///-----------------------------------------------------------------------------------------------------------------
180 	//  reflection
181 	SV svReflSkip, svReflFaces, svReflSize;
182 	SlV(ReflDist);  SlV(ReflMode);
183 
184 	//  hud view
185 	SV svSizeGaug;
186 	SV svTypeGaug, svLayoutGaug;
187 
188 	SV svSizeMinimap, svZoomMinimap;
189 	void slHudSize(SV*), slHudCreate(SV*);
190 
191 	SlV(SizeArrow);
192 	SLV(CountdownTime);  //-
193 	SV svDbgTxtClr, svDbgTxtCnt;
194 
195 	//  sound
196 	SlV(VolMaster);  SlV(VolHud);
197 	SV svVolEngine, svVolTires, svVolSusp, svVolEnv;
198 	SV svVolFlSplash, svVolFlCont, svVolCarCrash, svVolCarScrap;
199 	Ck ckSndChk, ckSndChkWr, ckReverb;
200 
201 
202 	///  Checks  . . . . . . . . . . . . . . . . . . . .
203 	CK(Reverse);  // track
204 
205 	//  Options
206 	SV svParticles, svTrails;
207 	Ck ckParticles, ckTrails;  void chkParTrl(Ck*);
208 
209 	//  Hud view
210 	Ck ckDigits, ckGauges;  void chkHudShow(Ck*);
211 	//  Minimap
212 	CK(Arrow);  CK(Beam);
213 	CK(Minimap);  void chkMiniUpd(Ck*);
214 	Ck ckMiniZoom, ckMiniRot, ckMiniTer, ckMiniBorder;
215 	//  Camera
216 	Ck ckCamInfo, ckCamTilt, ckCamLoop;
217 	Ck ckCamBnc;  SV svCamBnc;
218 	SV svFov, svFovMax, svFovSm;
219 	//  Pacenotes
220 	Ck ckPaceShow;  SV svPaceDist, svPaceSize, svPaceNext;
221 	SV svPaceNear, svPaceAlpha;
222 	void slUpd_Pace(SV*);
223 	//  Times, opp
224 	Ck ckTimes, ckOpponents, ckOppSort;
225 
226 	//  Graphs
227 	SV svTC_r, svTC_xr;
228 	SV svTE_yf, svTE_xfx, svTE_xfy, svTE_xpow;
229 	Ck ckTE_Common, ckTE_Reference;  void chkTEupd(Ck*);
230 
231 	//  Hud dbg,other
232 	Ck ckFps;  CK(Wireframe);
233 	//  profiler
234 	Ck ckProfilerTxt, ckBulletDebug, ckBltProfTxt, ckSoundInfo;
235 	//  car dbg
236 	Ck ckCarDbgBars, ckCarDbgTxt, ckCarDbgSurf;
237 	Ck ckTireVis;  void chkHudCreate(Ck*);
238 	CK(Graphs);
239 
240 	//  Startup
241 	Ck ckAutoStart, ckEscQuits;
242 	Ck ckStartInMain, ckOgreDialog;
243 	Ck ckBltLines, ckShowPics;
244 	Ck ckMouseCapture, ckDevKeys, ckScreenPng;
245 	void chkMultiThread(WP);
246 
247 	//  [Effects]
248 	CK(AllEffects);
249 	Ck ckBoostFOV;
250 	Ck ckBloom, ckBlur, ckSoftPar, ckSSAO, ckGodRays, ckDoF, ckHDR;
251 	void chkEffUpd(Ck*), chkEffUpdShd(Ck*);
252 
253 	SV svBloomInt, svBloomOrig;
254 	SV svBlurIntens;  // motion blur
255 	SV svDofFocus, svDofFar;  // depth of field
256 	void slEffUpd(SV*);
257 	//  hdr
258 	SV svHDRParam1, svHDRParam2, svHDRParam3;
259 	SV svHDRBloomInt, svHDRBloomOrig, svHDRAdaptScale;
260 	SV svHDRVignRadius, svHDRVignDark;
261 
262 
263 	///  Car 3d view  ---
264 	CarModel* viewCar;
265 	Can viewCanvas;
266 	wraps::RenderBoxScene* viewBox;  Ogre::Vector3 viewSc;
267 	MyGUI::IntCoord GetViewSize();
268 	void InitCarPrv();
269 
270 	WP graphV, graphS;
271 	MyGUI::PolygonalSkin* graphVel,*graphVGrid, *graphSSS,*graphSGrid;
272 
273 
274 	///  [Car] color  --===---
275 	SV svCarClrH, svCarClrS, svCarClrV;
276 	SV svCarClrGloss, svCarClrRefl;  void slCarClr(SV*);
277 	void SldUpd_CarClr();
278 	void UpdCarClrSld(bool upd=true);
279 	void SetCarClr();
280 
281 
282 	//  [Setup] car
283 	Ck ckCarGear, ckCarRear, ckCarRearInv;  void chkGear(Ck*);
284 	Ck ckAbs, ckTcs;
285 	Btn bchAbs,bchTcs;
286 	void chkAbs(WP), chkTcs(WP);
287 
288 	//  gui car tire set gravel/asphalt
289 	int iTireSet;
290 	void tabTireSet(Tab, size_t);
291 	void SldUpd_TireSet();
292 
293 	SV svSSSEffect, svSSSVelFactor;
294 	SV svSteerRangeSurf, svSteerRangeSim;
295 	void btnSSSReset(WP), btnSteerReset(WP), slSSS(SV*);
296 
297 	void imgBtnCarClr(WP), btnCarClrRandom(WP);
298 
299 	//  radios
300 	Btn bRkmh, bRmph;  // km/h, mph
301 	void radKmh(WP), radMph(WP);
302 
303 	Btn bRsimEasy, bRsimNorm, bRsimHard;  // sim mode
304 	void radSimEasy(WP), radSimNorm(WP), radSimHard(WP);
305 	void setSimMode(std::string mode);
306 	bool bReloadSim;
307 
308 	//  [Game] setup
309 	Ck ckVegetCollis, ckCarCollis, ckRoadWCollis, ckDynamicObjs;
310 	SV svNumLaps;  SLV(RplNumViewports);  //-
311 	SV svDamageDec;
312 	SV svBmin,svBmax,svBpow,svBperKm,svBaddSec;
313 
314 
315 	///  [Replay]  -----------------------------
316 	Li rplList;
317 	void listRplChng(Li, size_t);
318 	void updReplaysList();
319 
320 	//  cur rpl stats gui
321 	Txt valRplName, valRplInfo,
322 		valRplName2,valRplInfo2;
323 
324 	//  controls percent and time info
325 	Txt valRplPerc, valRplCur, valRplLen;
326 
327 	//  gui save
328 	Ed edRplName, edRplDesc;
329 	Ogre::String getRplName();
330 	void btnRplLoad(WP), btnRplSave(WP);
331 	void btnRplDelete(WP), btnRplRename(WP);
332 
333 	//  chk, options
334 	Ck ckRplAutoRec, ckRplBestOnly, ckRplGhost, ckRplParticles;
335 	Ck ckRplRewind, ckRplGhostOther, ckRplTrackGhost;
336 	SV svGhoHideDist, svGhoHideDistTrk;
337 
338 	//  list filtering
339 	Btn rbRplCur, rbRplAll;  // radio
340 	void btnRplCur(WP),btnRplAll(WP);
341 	CK(RplGhosts);
342 	void edRplFind(Ed);  Ogre::String sRplFind;
343 
344 	//  controls bar buttons
345 	Btn btRplPl;  void UpdRplPlayBtn();
346 	Sl slRplPos;  void slRplPosEv(SL);
347 	bool bRplBack, bRplFwd;
348 	void btnRplToStart(WP),btnRplToEnd(WP), btnRplPlay(WP);
349 	void btnRplBackDn(WP,int,int,MyGUI::MouseButton), btnRplBackUp(WP,int,int,MyGUI::MouseButton);
350 	void btnRplFwdDn(WP,int,int, MyGUI::MouseButton), btnRplFwdUp(WP,int,int, MyGUI::MouseButton);
351 	void msgRplDelete(MyGUI::Message*, MyGUI::MessageBoxStyle);
352 
353 	//  tools, convert
354 	void btnRenameOldTrk(WP), btnConvertAllRpl(WP);
355 	bool bConvertRpl;
356 	boost::thread mThrConvert;  void ThreadConvert();
357 	Txt txtConvert;
358 	int iConvCur,iConvAll,iConvFiles, iConvPathCur,iConvPathAll;  // files, dirs
359 	boost::uintmax_t totalConv,totalConvCur,totalConvNew;  // size
360 
361 
362 	//  Game
363 	///---------------------------------------
364 	Btn btNewGameCar;
365 	void btnNewGame(WP), btnNewGameStart(WP);
366 
367 	//  split
368 	void btnNumPlayers(WP);
369 	Txt valLocPlayers;
370 	Ck ckSplitVert;
371 	void chkStartOrd(WP);
372 
373 	//  [Car] list
374 	int iCurCar;  // current
375 	Ogre::String sListCar;
376 
377 	Mli2 carList;
378 	void listCarChng(Mli2, size_t);
379 	void btnCarView1(WP), btnCarView2(WP);
380 
381 	void changeCar(), changeTrack();
382 
383 	//  [Car] stats
384 	const static int iCarSt = 10;
385 	Img barCarSt[iCarSt];
386 	Txt txCarStTxt[iCarSt], txCarStVals[iCarSt],
387 		txCarSpeed, txCarType, txCarYear,
388 		txCarAuthor,txTrackAuthor;
389 	Img barCarSpeed;
390 	void UpdCarStats(bool car);
391 	std::vector<Ogre::String> vsu; //CarStatsUnits
392 
393 	Img imgCar;  Ed carDesc;
394 	Cmb cmbBoost, cmbFlip, cmbDamage, cmbRewind;
395 	void comboBoost(CMB), comboFlip(CMB), comboDamage(CMB), comboRewind(CMB);
396 
397 
398 	//  key util
399 	int LNext(Mli2, int rel, int ofs), LNext(Li, int rel, int ofs),
400 		LNext(Mli, int rel);  // util next in list
401 	void LNext(int rel);  void tabPlayer(Tab, size_t);
402 
403 	const Ogre::String& GetGhostFile(std::string* ghCar=NULL);
404 	std::string GetRplListDir();
405 
406 
407 	///  championships & challenges
408 	///-----------------------------------------------------------------------------------------------------------------
409 	Btn btStTut, btStChamp, btStChall;
410 	Img imgTut, imgChamp, imgChall;
411 	//  tabs
412 	Tab tabTut, tabChamp, tabChall;
413 	void tabTutType(Tab, size_t), tabChampType(Tab, size_t);
414 	void tabChallType(Tab, size_t);
415 
416 	//  stages
417 	Ed edChInfo, edChDesc;  WP panCh;
418 	Txt txtCh, valCh, txtChP[3], valChP[3];  // stages info, pass/progress
419 	void btnStageNext(WP), btnStagePrev(WP);  Txt valStageNum;
420 	void StageListAdd(int n, Ogre::String name, int laps, Ogre::String progress);
421 
422 	//  xml  [1]= reversed  L= challenge
423 	ProgressXml progress[2];
424 	ProgressLXml progressL[2];
425 	void ProgressSave(bool upgGui=true), ProgressLSave(bool upgGui=true);
426 	Chall* pChall;  // current challenge or 0 if not
427 
428 	//  load
429 	void Ch_XmlLoad(), Ch_LoadEnd();
430 	void UpdChallDetail(int id);
431 	//  const
432 	const static Ogre::String StrPrize(int i/*0 none..3 gold*/), strPrize[4],clrPrize[4];
433 	const static int ciAddPos[3];  const static float cfSubPoints[3];
434 
435 	//  common
436 	Mli2 liStages, liNetEnd;  void listStageChng(Mli2, size_t);
437 	Mli2 liChamps;  void listChampChng(Mli2, size_t);
438 	Mli2 liChalls;  void listChallChng(Mli2, size_t);
439 
440 	void btnChampStart(WP), btnChampEndClose(WP), btnChampStageBack(WP), btnChampStageStart(WP);
441 	void btnChallStart(WP), btnChallEndClose(WP), btnChallStageBack(WP), btnChallStageStart(WP);
442 	void btnChRestart(WP);  Btn btChRestart;
443 
444 	Btn btChampStage, btChallStage;
445 	Ed edChampStage, edChampEnd;  Img imgChampStage, imgChampEndCup;
446 	Ed edChallStage, edChallEnd;  Img imgChallStage;
447 	Img imgChallFail, imgChallCup;
448 	Txt txChallEndC, txChallEndF, txChampEndF;
449 	int iChSnd;  // snd id to play
450 
451 	//  main
452 	void ChampsListUpdate(), ChampFillStageInfo(bool finished), ChampionshipAdvance(float timeCur);
453 	void ChallsListUpdate(), ChallFillStageInfo(bool finished), ChallengeAdvance(float timeCur);
454 	void btnChampInfo(WP), UpdChampTabVis();
455 	CK(ChampRev);
456 
457 	void ReadTrkStatsChamp(Ogre::String track,bool reverse);
458 	void updChampListDim();
459 
460 	//  chall util
461 	Ogre::String StrChallCars(const Chall& ch);
462 	bool IsChallCar(Ogre::String name);
463 	bool isChallGui();  void BackFromChs();
464 
465 	//  _Tools_
466 	void ToolGhosts(),ToolGhostsConv(), ToolTestTrkGhosts();
467 
468 
469 	///  multiplayer game
470 	///-----------------------------------------------------------------------------------------------------------------
471 	void rebuildGameList(), rebuildPlayerList();
472 	void updateGameInfo(), updateGameSet(), updateGameInfoGUI();
473 	void setNetGuiHosting(bool enabled);
474 	void gameListChanged(protocol::GameList list);
475 
476 	void peerConnected(PeerInfo peer), peerDisconnected(PeerInfo peer);
477 	void peerInfo(PeerInfo peer);
478 	void peerMessage(PeerInfo peer, std::string msg);
479 	void peerState(PeerInfo peer, uint8_t state);
480 	void gameInfo(protocol::GameInfo game);
481 	void startRace(), returnToLobby();
482 	void timeInfo(ClientID id, uint8_t lap, double time);
483 	void error(std::string what);
484 	void join(std::string host, std::string port, std::string password);
485 	void uploadGameInfo();
486 
487 	mutable boost::mutex netGuiMutex;
488 	protocol::GameInfo netGameInfo;
489 
490 	///  multiplayer gui  --------------------
491 	Tab tabsNet;
492 	WP  panNetServer, panNetGame, panNetTrack;
493 	Mli listServers, listPlayers;
494 	int iColLock, iColHost, iColPort;  // ids of columns in listServers
495 
496 	//  upd gui triggers
497 	bool bRebuildPlayerList, bRebuildGameList;
498 	bool bUpdateGameInfo, bUpdChat;
499 	bool bStartGame, bStartedGame;
500 	void UpdGuiNetw();
501 
502 	//  chat,msg  ----
503 	Ed edNetChat;  // chat area, set text through sChatBuffer
504 	MyGUI::UString sChatBuffer,sChatLast1,sChatLast2;  int iChatMove;
505 	void AddChatMsg(const MyGUI::UString& clr, const MyGUI::UString& msg, bool add=true);
506 
507 	Ed edNetChatMsg;
508 	Btn btnNetSendMsg;  void chatSendMsg();
509 	GuiPopup* popup;  // msg with edits
510 
511 	//  Net gui
512 	Btn btnNetRefresh, btnNetJoin;    void evBtnNetRefresh(WP), evBtnNetJoin(WP),   evBtnNetJoinLockedClose();
513 	Btn btnNetCreate,  btnNetDirect;  void evBtnNetCreate(WP),  evBtnNetDirect(WP), evBtnNetDirectClose();
514 	Btn btnNetReady,   btnNetLeave;	  void evBtnNetReady(WP),   evBtnNetLeave(WP);
515 	void btnNetEndClose(WP);
516 
517 	Txt valNetGameInfo, valNetPassword;
518 	Ed edNetGameName,   edNetPassword;   void evEdNetGameName(Ed),   evEdNetPassword(Ed);
519 	Ed edNetNick,       edNetLocalPort;  void evEdNetNick(Ed),       evEdNetLocalPort(Ed);
520 	Ed edNetServerPort, edNetServerIP;   void evEdNetServerPort(Ed), evEdNetServerIP(Ed);
521 };
522