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

游戏引擎

开发平台:

Visual C++

  1. // SinglePlayerSheet.cpp: implementation of the CSinglePlayerSheet class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "SinglePlayerSheet.h"
  6. #include "texmanager.h"
  7. #include <stdio.h>
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CSinglePlayerSheet::CSinglePlayerSheet()
  12. {
  13. }
  14. CSinglePlayerSheet::~CSinglePlayerSheet()
  15. {
  16. }
  17. bool CSinglePlayerSheet::InitSheet()
  18. {
  19. RECT rect;
  20. rect.top=555;
  21. rect.bottom=585;
  22. for(int i=0;i<SP_ITEM_NUM;i++)
  23. {
  24. rect.left=50+i*250;
  25. rect.right=250+i*250;
  26.     m_cButton[i].SetButtonRect(rect);
  27. }
  28.     m_cButton[0].SetButtonText("Back");
  29. m_cButton[1].SetButtonText("Load Save");
  30. m_cButton[2].SetButtonText("New Game");
  31. m_cButton[1].SetButtonState(BUTTON_DEAD);
  32. /////////////////////change bar
  33.    
  34. rect.top=80;
  35. rect.bottom=290;
  36. rect.left=100;
  37. rect.right=300;
  38. unsigned int texid[4];
  39. CTexManager cTexManager;
  40. texid[0]=cTexManager.GetTextureID(TEX_HERO_PHOTO_0);
  41. texid[1]=cTexManager.GetTextureID(TEX_HERO_PHOTO_1);
  42. texid[2]=cTexManager.GetTextureID(TEX_HERO_PHOTO_2);
  43. texid[3]=cTexManager.GetTextureID(TEX_HERO_PHOTO_3);
  44. m_cHero.SetChangeBar(rect,texid,4,0);
  45. ///////////////// script
  46. rect.top=80;
  47. rect.bottom=300;
  48. rect.left=320;
  49. rect.right=700;
  50. m_cScript.SetViewBox(rect,"script/hero0.txt");
  51. //////////// name edit
  52. rect.left=240;
  53. rect.right=560;
  54. rect.top=330;
  55. rect.bottom=500;
  56.     m_cPlayerList.SetListBox(rect,PLAYER_NAME,"script/players.txt");
  57. rect.left=250;
  58. rect.right=395;
  59. rect.top=500;
  60. rect.bottom=520;
  61. m_cModifyButton.SetButton(rect,"Change Name");
  62. rect.left=405;
  63. rect.right=550;
  64. m_cDeleteButton.SetButton(rect,"Delete Player");
  65. ////////////////////////////////
  66. m_iSelect=-1;
  67.     m_bActive=false;
  68. return true;
  69. }
  70. int CSinglePlayerSheet::RenderSheet()
  71. {
  72. if(!m_bActive)return -1;
  73. UpdateSinglePlayer();
  74. DrawBackGround();
  75. for(int i=0;i<SP_ITEM_NUM;i++)
  76. {
  77.     m_cButton[i].RenderButton();
  78. }
  79. /////////////////////////////
  80.   m_cHero.RenderChangeBar();
  81. if(m_cHero.m_bValueChanged)
  82. {
  83. char file[64];
  84. wsprintf(file,"script/hero%d.txt",m_cHero.GetSelected());
  85. m_cScript.SetText(file);
  86. }
  87. m_cScript.RenderViewBox();
  88.     m_cPlayerList.RenderListBox();
  89. m_cModifyButton.RenderButton();
  90. m_cDeleteButton.RenderButton();
  91. for(i=0;i<SP_ITEM_NUM;i++)
  92. {
  93.     if(m_cButton[i].m_bSelected)
  94. {
  95. m_cButton[i].m_bSelected=false;
  96. m_iSelect=i;
  97. return i;
  98. }
  99. if(CInput::m_keys[13]) // key enter pressed
  100. {
  101. CInput::m_keys[13]=false;
  102. m_iSelect=2;
  103. return 2;
  104. }
  105. return -1;
  106. }
  107. void   CSinglePlayerSheet::UpdateSinglePlayer()
  108. {
  109. if(CInput::m_keys[VK_ESCAPE])
  110. {
  111. CInput::m_keys[VK_ESCAPE]=false;
  112. m_iSelect=0;
  113. return ;
  114. }
  115. if(m_cModifyButton.m_bSelected)
  116. {
  117. m_cModifyButton.m_bSelected=false;
  118. m_cPlayerList.SetCurrentItemEnableEdit();
  119. }
  120. if(m_cDeleteButton.m_bSelected)
  121. {
  122. m_cDeleteButton.m_bSelected=false;
  123. m_cPlayerList.ClearCurrentItem();
  124. }
  125. }
  126. void  CSinglePlayerSheet::DrawBackGround()
  127. {
  128. CImgText cText;
  129. glColor3f(0,1,0);
  130. cText.PrintString(50,20,"Single Player",0,24,0);
  131. glColor3f(0,0.7f,0);
  132. ////////////////
  133. int x0=10,x1=800-x0;
  134. int y0=50,y1=540;
  135.     DrawRectangle( x0, x1, y0, y1);  //  All
  136.     x0=80;  x1=800-x0;
  137. y0=70;  y1=300;
  138.     DrawRectangle( x0, x1, y0, y1);  //  top
  139. }
  140. void CSinglePlayerSheet::DrawRectangle(int x0,int x1,int y0,int y1)
  141. {
  142. glBegin(GL_LINE_LOOP);
  143. glVertex3i(x0-400,300-y0,-520);
  144. glVertex3i(x1-400,300-y0,-520);
  145. glVertex3i(x1-400,300-y1,-520);
  146. glVertex3i(x0-400,300-y1,-520);
  147.     glEnd();
  148. }
  149. void CSinglePlayerSheet::SavePlayerInfo()
  150. {
  151.     m_cPlayerList.SaveItemTitle("script/players.txt");
  152. }