UMainMenu.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. unit UMainMenu;
  2. interface
  3. uses Controls,Classes,GLGameMenu;
  4. procedure MouseDownMenu(Sender: TObject;
  5. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  6. function PosInMenu(X,Y:Integer; Menu:TGLGameMenu):Boolean;
  7. procedure SwitchToMenu(Menu:TGLGameMenu);
  8. procedure MenuSelect2(Menu:TGLGameMenu; X,Y:Integer);
  9. implementation
  10. uses Unit1,SysUtils,Dialogs,UNetwork,UIni,UMessageThread,Forms,UMyUtils;
  11. procedure MenuSelect2(Menu:TGLGameMenu; X,Y:Integer);
  12. begin
  13. Y:=Y+26;
  14. if (X >= Menu.BoxLeft) and (Y >= Menu.MenuTop) and
  15. (X <= Menu.BoxRight) and (Y <= Menu.BoxBottom) then
  16. begin
  17. Menu.Selected := (Y - Menu.MenuTop)
  18. div (Menu.Font.CharHeight + Menu.Spacing);
  19. end;
  20. end;
  21. procedure SwitchToMenu(Menu:TGLGameMenu);
  22. var C1:Integer;
  23. begin
  24. for C1:=0 to Form1.Menu.Count-1 do
  25. Form1.Menu.Children[C1].Visible:=false;
  26. if not Assigned(Menu) then ShowMessage('error 27: menu not assigned')
  27. else
  28. Menu.Visible:=true;
  29. end;
  30. function PosInMenu(X,Y:Integer; Menu:TGLGameMenu):Boolean;
  31. begin
  32. Y:=Y+26;
  33. Result:=(X>=Menu.BoxLeft)
  34. and (Y>=Menu.MenuTop)
  35. and (X<=Menu.BoxRight)
  36. and (Y<=Menu.BoxBottom)
  37. end;
  38. procedure MouseDownMenu(Sender: TObject;
  39. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  40. var C1:Integer; C2:Char;
  41. begin
  42. if (Button<>TMouseButton(0))
  43. and (Button<>TMouseButton(3)) then Exit;
  44. if Form1.MainMenu.Visible
  45. and (PosInMenu(X,Y,Form1.MainMenu)
  46. or (Button=TMouseButton(3))) then begin
  47. if Form1.MainMenu.Selected=0 then begin
  48. C2:='p';
  49. Form1.FormKeyPress(Sender,C2);
  50. end;
  51. if Form1.MainMenu.Selected=1 then begin
  52. C2:='n';
  53. Form1.FormKeyPress(Sender,C2);
  54. end;
  55. if Form1.MainMenu.Selected=2 then begin
  56. SwitchToMenu(Form1.SettingsMenu);
  57. end;
  58. if Form1.MainMenu.Selected=3 then begin
  59. SwitchToMenu(Form1.MPMenu);
  60. end;
  61. if Form1.MainMenu.Selected=4 then begin
  62. C2:='r';
  63. Form1.FormKeyPress(Sender,C2);
  64. end;
  65. if Form1.MainMenu.Selected=5 then begin
  66. C2:='b';
  67. Form1.FormKeyPress(Sender,C2);
  68. end;
  69. Exit;
  70. end;
  71. if Form1.MPMenu.Visible
  72. and (PosInMenu(X,Y,Form1.MPMenu)
  73. or (Button=TMouseButton(3))) then begin
  74. if Form1.MPMenu.Selected=0 then
  75. SwitchToMenu(Form1.MPHostMenu);
  76. if Form1.MPMenu.Selected=1 then
  77. SwitchToMenu(Form1.MPJoinMenu);
  78. if Form1.MPMenu.Selected=2 then
  79. SwitchToMenu(Form1.MainMenu);
  80. Exit;
  81. end;
  82. if Form1.MPHostMenu.Visible
  83. and (PosInMenu(X,Y,Form1.MPHostMenu)
  84. or (Button=TMouseButton(3))) then begin
  85. if Form1.MPHostMenu.Selected=0 then begin
  86. MyInputBox(
  87. 'Multiplayer-Port',
  88. 'Port (1024-49151):',
  89. IntToStr(MPPort),
  90. 1025,
  91. 49150,
  92. MPPort);
  93. Form3.ClientSocket.Port:=MPPort;
  94. Form3.ServerSocket.Port:=MPPort;
  95. end;
  96. if Form1.MPHostMenu.Selected=1 then begin
  97. if Form3.ServerSocket.Active then
  98. MessageOut('Server is already open!','Invalid Command')
  99. else begin
  100. if Form3.ClientSocket.Active then begin
  101. if (MessageDlg('Client socket will be closed. Continue?', mtWarning,
  102. [mbYes, mbNo], 0) = mrYes) then begin
  103. Form3.ClientSocket.Close;
  104. Form3.ServerSocket.Open;
  105. end;
  106. end else Form3.ServerSocket.Open;
  107. MessageOut('Server is open to join!','Server open');
  108. end;
  109. end;
  110. if Form1.MPHostMenu.Selected=2 then
  111. SwitchToMenu(Form1.MPMenu);
  112. Exit;
  113. end;
  114. if Form1.MPJoinMenu.Visible
  115. and (PosInMenu(X,Y,Form1.MPJoinMenu)
  116. or (Button=TMouseButton(3))) then begin
  117. if Form1.MPJoinMenu.Selected=0 then begin
  118. MyInputBox(
  119. 'Server-IP',
  120. 'Servername/IP-Adress:',
  121. MPServerAddress,
  122. '',
  123. MPServerAddress);
  124. ini.WriteString('Multiplayer','MPServerAddress',MPServerAddress);
  125. Form3.ClientSocket.Host:=MPServerAddress;
  126. end;
  127. if Form1.MPJoinMenu.Selected=1 then begin
  128. MyInputBox(
  129. 'Multiplayer-Port',
  130. 'Port (1024-49151):',
  131. IntToStr(MPPort),
  132. 1025,
  133. 49150,
  134. MPPort);
  135. Form3.ClientSocket.Port:=MPPort;
  136. Form3.ServerSocket.Port:=MPPort;
  137. end;
  138. if Form1.MPJoinMenu.Selected=2 then begin
  139. if Form3.ClientSocket.Active then
  140. MessageOut('You are already connected to a game!','Invalid Command')
  141. else begin
  142. if Form3.ServerSocket.Active then begin
  143. if (MessageDlg('Server socket will be closed. Continue?', mtWarning,
  144. [mbYes, mbNo], 0) = mrYes) then begin
  145. Form3.ServerSocket.Close;
  146. Form3.ClientSocket.Open;
  147. end;
  148. end else Form3.ClientSocket.Open;
  149. end;
  150. end;
  151. if Form1.MPJoinMenu.Selected=3 then
  152. SwitchToMenu(Form1.MPMenu);
  153. Exit;
  154. end;
  155. if Form1.SettingsMenu.Visible
  156. and (PosInMenu(X,Y,Form1.SettingsMenu)
  157. or (Button=TMouseButton(3))) then begin
  158. // if Form1.SettingsMenu.Selected=0 then
  159. // SwitchToMenu(Form1.DiffMenu);
  160. if Form1.SettingsMenu.Selected=0 then
  161. SwitchToMenu(Form1.VideoMenu);
  162. if Form1.SettingsMenu.Selected=1 then
  163. SwitchToMenu(Form1.MainMenu);
  164. Exit;
  165. end;
  166. if Form1.VideoMenu.Visible
  167. and (PosInMenu(X,Y,Form1.VideoMenu)
  168. or (Button=TMouseButton(3))) then begin
  169. if Form1.VideoMenu.Selected=0 then begin
  170. C2:='m';
  171. Form1.FormKeyPress(Sender,C2);
  172. end;
  173. if Form1.VideoMenu.Selected=1 then begin
  174. MessageOut('Resize yourself by dragging the window`s borders.',
  175. 'You lazy ass!');
  176. end;
  177. if Form1.VideoMenu.Selected=2 then begin
  178. MyInputBox(
  179. 'Shading Distance',
  180. 'Distance:',
  181. IntToStr(ShaderWidth),
  182. 0,
  183. RaumRange,
  184. ShaderWidth);
  185. Form1.ReloadWallShaders;
  186. end;
  187. if Form1.VideoMenu.Selected=3 then
  188. SwitchToMenu(Form1.SettingsMenu);
  189. Exit;
  190. end;
  191. end;
  192. end.