OptionsSheet.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:14k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // OptionsSheet.cpp: implementation of the COptionsSheet class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "OptionsSheet.h"
  6. #include "audio.h"
  7. #include "mediaplayer.h"
  8. #include "gamesetting.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. COptionsSheet::COptionsSheet()
  13. {
  14. m_iFather=0;
  15. }
  16. COptionsSheet::~COptionsSheet()
  17. {
  18. }
  19. bool COptionsSheet::InitSheet()
  20. {
  21. RECT rect;
  22. ////////////// Init 3 Button
  23. rect.top=555;
  24. rect.bottom=585;
  25. for(int i=0;i<OP_ITEM_NUM;i++)
  26. {
  27. rect.left=50+i*250;
  28. rect.right=250+i*250;
  29.     m_cButton[i].SetButtonRect(rect);
  30. }
  31.     m_cButton[0].SetButtonText("Back");
  32. m_cButton[1].SetButtonText("Default");
  33. m_cButton[2].SetButtonText("Accept");
  34. //////////////////////////////////////////
  35. //////////////////// Init bars
  36. int x=220,y=95;
  37. int dy=32;
  38. char **str;
  39. str=new char* [4];
  40. for(int j=0;j<4;j++)
  41. str[j]=new char [32];
  42. strcpy(str[0],"640 x 480");
  43. strcpy(str[1],"800 x 600");
  44. strcpy(str[2],"1024 x 768");
  45. strcpy(str[3],"1280 x 960");
  46. //////////    m_cResolutionBar
  47. rect.top=y;
  48. rect.bottom=y+18;
  49. rect.left=x;
  50. rect.right=x+170;
  51. m_cResolutionBar.SetChangeBar(rect,str,4,1);
  52. //////////    m_cColorDepthBar
  53. rect.top=y+dy;
  54. rect.bottom=y+dy+18;
  55. strcpy(str[0],"16");
  56. strcpy(str[1],"32");
  57. m_cColorDepthBar.SetChangeBar(rect,str,2,0);
  58. //////////    m_cModelDetailBar
  59. rect.top=y+dy*3;
  60. rect.bottom=y+dy*3+18;
  61. strcpy(str[0],"Low");
  62. strcpy(str[1],"Medium");
  63. strcpy(str[2],"Height");
  64. m_cModelDetailBar.SetChangeBar(rect,str,3,0);
  65. //////////    m_cTexQualityBar
  66. rect.top=y+dy*4;
  67. rect.bottom=y+dy*4+18;
  68. m_cTexQualityBar.SetChangeBar(rect,str,3,2);
  69. //////// m_cForestDensityBar
  70. rect.top=y+dy*6;
  71. rect.bottom=y+dy*6+18;
  72. m_cForestDensityBar.SetChangeBar(rect,str,3,0);
  73. //////////    m_cFontTypeBar
  74. rect.top=y+dy*8;
  75. rect.bottom=y+dy*8+18;
  76. strcpy(str[0],"Elegence");
  77. strcpy(str[1],"Strong");
  78. m_cFontTypeBar.SetChangeBar(rect,str,2,0);
  79. //////////////////////////////////////
  80.     ///////////////////// init Scroll bar
  81. //////// m_cBrightnessBar
  82. rect.top=y+dy*2;
  83. rect.bottom=y+dy*2+18;
  84. m_cBrightnessBar.SetScrollBar(rect,true,60,-30,0);
  85. //////// m_cVisiblebDistBar
  86. rect.top=y+dy*5;
  87. rect.bottom=y+dy*5+18;
  88. m_cVisiblebDistBar.SetScrollBar(rect,true,80,30,6);
  89. //////// m_cFogDensityBar
  90. rect.top=y+dy*7;
  91. rect.bottom=y+dy*7+18;
  92. m_cFogDensityBar.SetScrollBar(rect,true,80,30,1);
  93.     ///////////////////audio
  94. ///////////////music check box
  95. y=440;
  96. rect.top=y;
  97. rect.bottom=y+18;
  98.     rect.right=rect.left+18;
  99.     m_cMusicCheckBox.SetCheckBox(rect);
  100. ///////////////sound check box
  101. rect.left=315;
  102. rect.right=rect.left+18;
  103. m_cSoundCheckBox.SetCheckBox(rect);
  104.     ///////////////// music volume
  105. rect.left=x;
  106. rect.right=x+170;
  107. rect.top=y+dy;
  108. rect.bottom=y+dy+18;
  109. m_cMusicVolumeBar.SetScrollBar(rect,true,100,0,70);
  110.     ////////////////  sound volume
  111. rect.top=y+dy*2;
  112. rect.bottom=y+dy*2+18;
  113. m_cSoundVolumeBar.SetScrollBar(rect,true,100,0,70);
  114. ///////////////////////////////////mouse
  115.     /////////////   m_cMouseInvert;
  116.     y=440;
  117. rect.left=670;
  118. rect.right=770;
  119. rect.top=y;
  120. rect.bottom=y+18;
  121. strcpy(str[0],"No");
  122. strcpy(str[1],"Yes");
  123. m_cMouseInvert.SetChangeBar(rect,str,2,0);
  124. ////////////   m_cMouseSensitivity
  125. rect.left=610;
  126. rect.right=770;
  127. rect.top=y+dy;
  128. rect.bottom=y+dy+18;
  129. m_cMouseSensitivity.SetScrollBar(rect,true,100,20,16);
  130.  
  131. /////////////////keyboard setting
  132. ///////////////// m_cKeySetting
  133. rect.left=450;
  134. rect.right=770;
  135. rect.top=95;
  136. rect.bottom=365;
  137. m_cKeySetting.SetCtrlSetBox(rect);
  138. ////////////////////////////////////////////
  139. for(j=0;j<4;j++)
  140. delete [] str[j];
  141. delete [] str;
  142.     ///////////////////////////////////////////////
  143. LoadSetting();
  144. /////////////////////////////////////////
  145. m_iSelect=-1;
  146.     m_bActive=false;
  147. return true;
  148. }
  149. int COptionsSheet::RenderSheet()
  150. {
  151. if(!m_bActive)return -1;
  152. DrawBackGround();
  153. for(int i=0;i<OP_ITEM_NUM;i++)
  154. {
  155.     m_cButton[i].RenderButton();
  156. }
  157. /////////////////////////////////////
  158. for(i=0;i<OP_ITEM_NUM;i++)
  159. {
  160.     if(m_cButton[i].m_bSelected)
  161. {
  162. m_cButton[i].m_bSelected=false;
  163. m_iSelect=i;
  164. }
  165. UpdateOptionsSheet();
  166.     ////////// video
  167. m_cResolutionBar.RenderChangeBar();
  168. m_cColorDepthBar.RenderChangeBar();
  169. m_cModelDetailBar.RenderChangeBar();
  170. m_cTexQualityBar.RenderChangeBar();
  171. m_cFontTypeBar.RenderChangeBar();
  172. m_cBrightnessBar.RenderScrollBar();
  173. m_cVisiblebDistBar.RenderScrollBar();
  174. m_cForestDensityBar.RenderChangeBar();
  175. m_cFogDensityBar.RenderScrollBar();
  176. ////////// audio
  177. m_cSoundCheckBox.RenderCheckBox();
  178. m_cMusicCheckBox.RenderCheckBox();
  179. m_cMusicVolumeBar.RenderScrollBar();
  180. m_cSoundVolumeBar.RenderScrollBar(); 
  181.     /////////// mouse
  182. m_cMouseInvert.RenderChangeBar();
  183. m_cMouseSensitivity.RenderScrollBar();
  184. //////////  Keyboard
  185. m_cKeySetting.RenderCtrlSetBox();
  186.     ///////////////////////////////////
  187. return -1;
  188. }
  189. void COptionsSheet::UpdateOptionsSheet()
  190. {
  191. if(CInput::m_keys[VK_ESCAPE])
  192. {
  193. CInput::m_keys[VK_ESCAPE]=false;
  194. m_iSelect=0;
  195. return ;
  196. }
  197. if(CInput::m_keys[13])//enter key
  198. {
  199. CInput::m_keys[13]=false;
  200. m_iSelect=2;
  201. return ;
  202. }
  203. if(m_cFontTypeBar.m_bValueChanged)
  204. {
  205.         CImgText cText;
  206.     cText.SetFontType(m_cFontTypeBar.GetSelected());
  207. }
  208. if(m_cMusicCheckBox.m_bValueChanged)
  209. {
  210.         m_cMusicVolumeBar.SetEnable(m_cMusicCheckBox.m_bChecked);
  211. if(m_cMusicCheckBox.m_bChecked)
  212. {
  213. CMediaPlayer::SetMediaActive(true);
  214. CMediaPlayer::Play();
  215. }
  216. else
  217. {
  218. CMediaPlayer::SetMediaActive(false);
  219. CMediaPlayer::Pause();
  220. }
  221. }
  222. if(m_cMusicVolumeBar.m_bValueChanged)
  223. {
  224. CMediaPlayer::SetVolume(m_cMusicVolumeBar.GetValue());
  225. }
  226. if(m_cSoundCheckBox.m_bValueChanged)
  227. {
  228.         m_cSoundVolumeBar.SetEnable(m_cSoundCheckBox.m_bChecked);
  229. if(m_cSoundCheckBox.m_bChecked)
  230. CAudio::SetAudioActive(true);
  231. else
  232. {
  233. CAudio::SetAudioActive(false);
  234. CAudio::StopAll();
  235. }
  236. }
  237. if(m_cSoundVolumeBar.m_bValueChanged)
  238. {
  239. CAudio::SetVolume(m_cSoundVolumeBar.GetValue());
  240. CAudio::Play(MENU_SOUND_TEST,1,true);
  241. }
  242. if(m_cBrightnessBar.m_bValueChanged)
  243. {
  244. CGameSetting::m_iGamma=m_cBrightnessBar.GetValue();
  245. }
  246.     if(m_iSelect==1)
  247. {
  248. m_iSelect=-1;
  249. CGameSetting cGameSetting;
  250.         cGameSetting.LoadDefaultSetting();
  251. LoadSetting();
  252. }
  253.     if(m_iSelect==2)
  254. {
  255. SaveSetting();
  256. }
  257. }
  258. void  COptionsSheet::LoadSetting()
  259. {
  260. CGameSetting cGameSetting;
  261. ///////////////////// Load Resolution
  262.     if(cGameSetting.m_iScrWidth==640) m_cResolutionBar.SetItem(0);
  263.     if(cGameSetting.m_iScrWidth==800) m_cResolutionBar.SetItem(1);
  264.     if(cGameSetting.m_iScrWidth==1024)m_cResolutionBar.SetItem(2);
  265.     if(cGameSetting.m_iScrWidth==1280)m_cResolutionBar.SetItem(3);
  266.     if(cGameSetting.m_iColorDepth==16) m_cColorDepthBar.SetItem(0);
  267.     if(cGameSetting.m_iColorDepth==32) m_cColorDepthBar.SetItem(1);
  268. //////////////////// Load Render
  269.     m_cBrightnessBar.SetValue(cGameSetting.m_iGamma);
  270.     if(cGameSetting.m_iModelDetail==LOW   ) m_cModelDetailBar.SetItem(0);
  271.     if(cGameSetting.m_iModelDetail==MEDIUM) m_cModelDetailBar.SetItem(1);
  272.     if(cGameSetting.m_iModelDetail==HEIGHT) m_cModelDetailBar.SetItem(2);
  273.     if(cGameSetting.m_iTexQuality==LOW   ) m_cTexQualityBar.SetItem(0);
  274.     if(cGameSetting.m_iTexQuality==MEDIUM) m_cTexQualityBar.SetItem(1);
  275.     if(cGameSetting.m_iTexQuality==HEIGHT) m_cTexQualityBar.SetItem(2);
  276.     m_cVisiblebDistBar.SetValue(cGameSetting.m_iVisibleDist);
  277.     if(cGameSetting.m_iForestDensity==LOW   ) m_cForestDensityBar.SetItem(0);
  278.     if(cGameSetting.m_iForestDensity==MEDIUM) m_cForestDensityBar.SetItem(1);
  279.     if(cGameSetting.m_iForestDensity==HEIGHT) m_cForestDensityBar.SetItem(2);
  280.     m_cFogDensityBar.SetValue(cGameSetting.m_iFogDensity);
  281.     ///////////////////  Load audio
  282. if(cGameSetting.m_bMusic)
  283. {
  284. m_cMusicCheckBox.SetState(true);
  285. m_cMusicVolumeBar.SetEnable(true);
  286. CMediaPlayer::SetMediaActive(true);
  287. CMediaPlayer::Play();
  288. }
  289. else 
  290. {
  291. m_cMusicCheckBox.SetState(false);
  292. m_cMusicVolumeBar.SetEnable(false);
  293. CMediaPlayer::SetMediaActive(false);
  294. CMediaPlayer::Pause();
  295. }
  296. if(cGameSetting.m_bSound)
  297. {
  298. m_cSoundCheckBox.SetState(true);
  299. m_cSoundVolumeBar.SetEnable(true);
  300. CAudio::SetAudioActive(true);
  301. }
  302. else
  303. {
  304. m_cSoundCheckBox.SetState(false);
  305. m_cSoundVolumeBar.SetEnable(false);
  306. CAudio::SetAudioActive(false);
  307. }
  308.     m_cMusicVolumeBar.SetValue(cGameSetting.m_iMusicVolume);
  309. CMediaPlayer::SetVolume(cGameSetting.m_iMusicVolume);
  310.     m_cSoundVolumeBar.SetValue(cGameSetting.m_iSoundVolume);
  311. CAudio::SetVolume(cGameSetting.m_iSoundVolume);
  312. if(!cGameSetting.m_bAudioEnable)m_cMusicCheckBox.SetEnable(false);
  313. if(!cGameSetting.m_bAudioEnable)m_cSoundCheckBox.SetEnable(false);
  314. if(!cGameSetting.m_bAudioEnable)m_cMusicVolumeBar.SetEnable(false);
  315. if(!cGameSetting.m_bAudioEnable)m_cSoundVolumeBar.SetEnable(false);
  316. ///////////////////////////////////mouse
  317.     if(cGameSetting.m_bMouseInvert==0) m_cMouseInvert.SetItem(0);
  318.     if(cGameSetting.m_bMouseInvert==1) m_cMouseInvert.SetItem(1);
  319.     m_cMouseSensitivity.SetValue(cGameSetting.m_iMouseSens);
  320. ////////////////////////////////// Keyboard
  321.     m_cKeySetting.LoadSetting();
  322. }
  323. void  COptionsSheet::SaveSetting()
  324. {
  325. CGameSetting cGameSetting;
  326. ////////////// Save Resolution
  327. int select=m_cResolutionBar.GetSelected();
  328.     if(select==0)cGameSetting.m_iScrWidth=640;
  329.     if(select==1)cGameSetting.m_iScrWidth=800;
  330.     if(select==2)cGameSetting.m_iScrWidth=1024;
  331.     if(select==3)cGameSetting.m_iScrWidth=1280;
  332. select=m_cColorDepthBar.GetSelected();
  333.     if(select==0)cGameSetting.m_iColorDepth=16;
  334.     if(select==1)cGameSetting.m_iColorDepth=32;
  335. //////////    save Render
  336.     cGameSetting.m_iGamma=m_cBrightnessBar.GetValue();
  337. select=m_cModelDetailBar.GetSelected();
  338.     if(select==0)cGameSetting.m_iModelDetail=LOW;
  339.     if(select==1)cGameSetting.m_iModelDetail=MEDIUM;
  340.     if(select==2)cGameSetting.m_iModelDetail=HEIGHT;
  341. select=m_cTexQualityBar.GetSelected();
  342.     if(select==0)cGameSetting.m_iTexQuality=LOW;
  343.     if(select==1)cGameSetting.m_iTexQuality=MEDIUM;
  344.     if(select==2)cGameSetting.m_iTexQuality=HEIGHT;
  345.     cGameSetting.m_iVisibleDist=m_cVisiblebDistBar.GetValue();
  346. select=m_cForestDensityBar.GetSelected();
  347.     if(select==0)cGameSetting.m_iForestDensity=LOW;
  348.     if(select==1)cGameSetting.m_iForestDensity=MEDIUM;
  349.     if(select==2)cGameSetting.m_iForestDensity=HEIGHT;
  350.     cGameSetting.m_iFogDensity=m_cFogDensityBar.GetValue();
  351.     ///////////////////   save  audio
  352.     if(m_cMusicCheckBox.m_bChecked)cGameSetting.m_bMusic=true;
  353. else cGameSetting.m_bMusic=false;
  354.     if(m_cSoundCheckBox.m_bChecked)cGameSetting.m_bSound=true;
  355. else cGameSetting.m_bSound=false;
  356. cGameSetting.m_iMusicVolume=m_cMusicVolumeBar.GetValue();
  357. cGameSetting.m_iSoundVolume=m_cSoundVolumeBar.GetValue();
  358. /////////////////  save mouse
  359.     /////////////   m_cMouseInvert;
  360. select=m_cMouseInvert.GetSelected();
  361.     if(select==0)cGameSetting.m_bMouseInvert=false;
  362.     if(select==1)cGameSetting.m_bMouseInvert=true;
  363. cGameSetting.m_iMouseSens=m_cMouseSensitivity.GetValue();
  364. //////////////////// Keyboard
  365. m_cKeySetting.SaveSetting();
  366.     ///////////////////////////////////////////////
  367. /////// Save to config.ini
  368.     cGameSetting.SaveSetting();
  369. ////////////////////////////////////////
  370. }
  371. void  COptionsSheet::DrawBackGround()
  372. {
  373. CGameSetting cGameSetting;
  374. ///////////////////title and rectangle
  375. CImgText cText;
  376. glColor3f(1,1,0);
  377. cText.PrintString(20,14,"Game Setting",0,24,0);
  378. glColor3f(0,0.7f,0);
  379.     ////////////////
  380. int x0=10,x1=800-x0;
  381. int y0=50,y1=540;
  382.     DrawRectangle( x0, x1, y0, y1);  //  All
  383.     x0=13;  x1=420;
  384. y0=53;  y1=392;
  385.     DrawRectangle( x0, x1, y0, y1);  // left top
  386. y0=395;  y1=537;
  387.     DrawRectangle( x0, x1, y0, y1);  // left bottom
  388.     x0=423;  x1=787;
  389. y0=53;  y1=392;
  390.     DrawRectangle( x0, x1, y0, y1);  // right top
  391. y0=395;  y1=537;
  392.     DrawRectangle( x0, x1, y0, y1);  // right bottom
  393. ////////////////// video
  394. glColor3f(0.8f,0.8f,0);
  395. cText.PrintString(20,60,"Video Setting",0,20,0);
  396. glColor3f(0,1,0);
  397. int x=30,y=95;
  398. int dy=32;
  399. cText.PrintString(x,y + 0,  "Resolution",0,16,0);
  400. cText.PrintString(x,y + dy*1,"Color Depth",0,16,0);
  401. cText.PrintString(x,y + dy*2,"Brightness",0,16,0);
  402. cText.PrintString(x,y + dy*3,"Model Detail",0,16,0);
  403. cText.PrintString(x,y + dy*4,"Texture Quality",0,16,0);
  404. cText.PrintString(x,y + dy*5,"Visible Distance",0,16,0);
  405. cText.PrintString(x,y + dy*6,"Forest Density",0,16,0);
  406. cText.PrintString(x,y + dy*7,"Fog Density",0,16,0);
  407. cText.PrintString(x,y + dy*8,"Font Type",0,16,0);
  408.     ///////////////// audio
  409. if(!cGameSetting.m_bAudioEnable)glColor3f(0.5f,0.5f,0.5f);
  410. else  glColor3f(0.8f,0.8f,0);
  411. cText.PrintString(20,405,"Audio Setting",0,20,0);
  412. if(!cGameSetting.m_bAudioEnable)glColor3f(0.5f,0.5f,0.5f);
  413. else  glColor3f(0,1,0);
  414.     y=440;
  415. cText.PrintString(x,y + 0,       "Audio Select",0,16,0);
  416. cText.PrintString(x+215,y + 0,   "Music",0,16,0);
  417. cText.PrintString(x+307,y + 0,   "Sound",0,16,0);
  418. cText.PrintString(x,y + dy,      "Music Volume",0,16,0);
  419. cText.PrintString(x,y + dy*2,    "Sound Volume",0,16,0);
  420. if(!cGameSetting.m_bAudioEnable)
  421. {
  422. glColor3f(1,0,0);
  423. cText.PrintString(220,405,"Audio Inavlid",0,20,0);
  424. }
  425.     //////////////// Mouse
  426. glColor3f(0.8f,0.8f,0);
  427. cText.PrintString(440,400,"Mouse Setting",0,20,0);
  428. glColor3f(0,1,0);
  429. x=450;
  430.     y=440;
  431. cText.PrintString(x,y + 0,   "Invert",0,16,0);
  432. cText.PrintString(x,y + dy*1,"Sensitivity",0,16,0);
  433. /////////////// Keyboard
  434. glColor3f(0.8f,0.8f,0);
  435. cText.PrintString(440,60,"Keyboard Setting",0,20,0);
  436. ////////////////
  437. glColor3f(1,1,1);
  438. }
  439. void COptionsSheet::DrawRectangle(int x0,int x1,int y0,int y1)
  440. {
  441. glBegin(GL_LINE_LOOP);
  442. glVertex3i(x0-400,300-y0,-520);
  443. glVertex3i(x1-400,300-y0,-520);
  444. glVertex3i(x1-400,300-y1,-520);
  445. glVertex3i(x0-400,300-y1,-520);
  446.     glEnd();
  447. }