Advertisement
Guest User

GlobalScript.asc

a guest
Oct 31st, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. Object* curObj;
  2. int prevX, prevY;
  3.  
  4. function GetCursorObject()
  5. {
  6. int x, y;
  7. int type;
  8. String name;
  9. // check object under cursor
  10. x = mouse.x; y = mouse.y;
  11.  
  12. type = GetLocationType(x, y);
  13. name = Game.GetLocationName(x, y);
  14. // change cursor mode
  15. if (type != eLocationNothing) {
  16. if (type == eLocationCharacter) mouse.Mode = eModeTalkto;
  17. if (type == eLocationHotspot) mouse.Mode = eModeLookat; //mouse.Mode = eModeInteract;
  18. if (type == eLocationObject) {
  19. curObj = Object.GetAtScreenXY(x, y);
  20. if (curObj.GetProperty("active")) mouse.Mode = eModePickup; else mouse.Mode = eModePointer;
  21. }
  22. nameObj.Text = name;
  23. } else {
  24. mouse.Mode = eModePointer;
  25. nameObj.Text = "";
  26. }
  27. }
  28.  
  29. // called when the game starts, before the first room is loaded
  30. function game_start()
  31. {
  32.  
  33. }
  34.  
  35. GUI * movingGUI;
  36. int guiX, guiY;
  37.  
  38. function on_event(EventType event, int data)
  39. {
  40. if (event == eEventGUIMouseUp) {
  41. //debuginfo.Text = "mouseUp";
  42. movingGUI = null;
  43. }
  44. }
  45. /*
  46. function unhandled_event(int what, int type)
  47. {
  48. if (what == 2 && type == 5) debuginfo.Text = "pickup";
  49.  
  50. }
  51. */
  52. // put anything you want to happen every game cycle in here
  53. function repeatedly_execute()
  54. {
  55. if (mouse.Visible) GetCursorObject();
  56. // moving windows
  57. if (movingGUI != null) {
  58. movingGUI.X += mouse.x - prevX;
  59. movingGUI.Y += mouse.y - prevY;
  60. }
  61. prevX = mouse.x; prevY = mouse.y;
  62. // inventory
  63. if (mouse.y > inventoryGui.Y) {
  64. if (player.ActiveInventory == null) {
  65. //mouse.Mode = eModeUseinv;
  66. mouse.Mode = eModeInteract;
  67. //mouse.Mode = eModePickup;
  68. //debuginfo.Text = "YES";
  69. }
  70. } else {
  71. //if (mouse.Mode == eModeInteract) {
  72. //debuginfo.Text = "NO";
  73. mouse.Mode = eModePointer;
  74. //}
  75. }
  76. }
  77.  
  78. function iInvBook_Interact()
  79. {
  80. debuginfo.Text = "NO";
  81. player.ActiveInventory = iInvBook1;
  82. }
  83.  
  84. // put here anything you want to happen every game cycle, even when the game is blocked
  85. function repeatedly_execute_always()
  86. {
  87. }
  88.  
  89. // called when a key is pressed. keycode holds the key's ASCII code
  90. function on_key_press(eKeyCode keycode)
  91. {
  92. if (keycode == eKeyP) { if (IsGamePaused() == 1) UnPauseGame(); else PauseGame(); }
  93. if (IsGamePaused()) keycode = 0;
  94. //
  95. if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q
  96. if (keycode == eKeyF9) RestartGame(); // F9
  97. if (keycode == eKeyF12) SaveScreenShot("scrnshot.pcx"); // F12
  98. if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory
  99. if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version
  100. if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas
  101. if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room
  102. //
  103. if (keycode == eKey1) Game.ChangeTranslation("english");
  104. if (keycode == eKey2) Game.ChangeTranslation("russian");
  105. }
  106.  
  107. function MouseClick()
  108. {
  109. isMouse = true;
  110. //debuginfo.Text = "YesMouse";
  111. //ProcessClick(mouse.x, mouse.y, eModeWalkto);
  112. if (mouse.Mode == eModePointer) ProcessClick(mouse.x, mouse.y, eModeWalkto);
  113. else ProcessClick(mouse.x, mouse.y, mouse.Mode);
  114. }
  115.  
  116. function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  117. {
  118. if (IsGamePaused() == 1) { }
  119. else if (button == eMouseLeft)
  120. {
  121. MouseClick();
  122. }
  123. else // right-click, so cycle cursor
  124. {
  125. ProcessClick(mouse.x, mouse.y, eModeLookat);
  126. //ProcessClick(mouse.x, mouse.y, eModeInteract);
  127. }
  128. //
  129. if (button == eMouseLeftInv) {
  130. //player.ActiveInventory = Game.inv_activated;
  131. //player.ActiveInventory =
  132. debuginfo.Text = "123";
  133. }
  134. }
  135.  
  136.  
  137. // DIALOGS
  138.  
  139. function dialog_request(int param) {
  140. }
  141. /*
  142. function OpenDoor(int index)
  143. {
  144. RestoreWalkableArea(10+index);
  145. object[5+index].Graphic = 164;
  146. }
  147. */
  148.  
  149.  
  150.  
  151. // GUI computer
  152.  
  153. // Message Box
  154.  
  155. function SwitchAllGUI(GUI *except, bool on)
  156. {
  157. int i = 0;
  158. while (i < 10) {
  159. if (gui[i] != null) {
  160. if (gui[i] != except) gui[i].Clickable = on;
  161. }
  162. i++;
  163. }
  164. }
  165.  
  166. function MessageBox(String caption, String text)
  167. {
  168. SwitchAllGUI(message, false);
  169. messageCaption.Text = caption;
  170. messageText.Text = text;
  171. message.X = screen.Width / 2;
  172. message.Y = screen.Height / 2;
  173. message.Visible = true;
  174. }
  175.  
  176. // files
  177.  
  178. function File1_OnClick(GUIControl *control, MouseButton button)
  179. {
  180. viewer1.Visible = true;
  181. }
  182.  
  183. function File2_OnClick(GUIControl *control, MouseButton button)
  184. {
  185. viewer2.Visible = true;
  186. }
  187.  
  188. function File3_OnClick(GUIControl *control, MouseButton button)
  189. {
  190. viewer3.Visible = true;
  191. }
  192.  
  193. String savedText;
  194.  
  195. function FileSaved_OnClick(GUIControl *control, MouseButton button)
  196. {
  197. edit.Text = savedText;
  198. notepad.Visible = true;
  199. }
  200.  
  201. // viewer
  202.  
  203. function viewer_OnClick(GUI *theGui, MouseButton button)
  204. {
  205. movingGUI = theGui;
  206. }
  207.  
  208. function ViewerClose_OnClick(GUIControl *control, MouseButton button)
  209. {
  210. control.OwningGUI.Visible = false;
  211. }
  212.  
  213. // notepad
  214.  
  215. function notepadIcon_OnClick(GUIControl *control, MouseButton button)
  216. {
  217. edit.Text = "";
  218. notepad.Visible = true;
  219. }
  220.  
  221. function SaveFile_OnClick(GUIControl *control, MouseButton button)
  222. {
  223. savedText = edit.Text;
  224. //Display("File saved in 'saved.txt'");
  225. MessageBox("notepad", "File saved in 'saved.txt'");
  226. FileSaved.Visible = true;
  227. }
  228.  
  229. function NotepadClose_OnClick(GUIControl *control, MouseButton button)
  230. {
  231. notepad.Visible = false;
  232. }
  233.  
  234. // message
  235.  
  236. function messageButton_OnClick(GUIControl *control, MouseButton button)
  237. {
  238. SwitchAllGUI(message, true);
  239. message.Visible = false;
  240. }
  241.  
  242. function messageClose_OnClick(GUIControl *control, MouseButton button)
  243. {
  244. SwitchAllGUI(message, true);
  245. message.Visible = false;
  246. }
  247.  
  248. // password
  249.  
  250. function archive_OnClick(GUIControl *control, MouseButton button)
  251. {
  252. password.X = (screen.Width - password.Width) / 2;
  253. password.Y = (screen.Height - password.Height) / 2;
  254. passwordEdit.Text = "*****";
  255. password.Visible = true;
  256. }
  257.  
  258. function Extract() {
  259.  
  260. }
  261.  
  262. function passwordOK_OnClick(GUIControl *control, MouseButton button)
  263. {
  264. if (passwordEdit.Text == correctPassword) {
  265. password.Visible = false;
  266. MessageBox("Extracting...", "Complete successful");
  267. Extract();
  268. } else {
  269. password.Visible = false;
  270. MessageBox("Extracting...", "Password incorrect");
  271. }
  272. }
  273.  
  274. function passwordClose_OnClick(GUIControl *control, MouseButton button)
  275. {
  276. password.Visible = false;
  277. }
  278.  
  279. // folder
  280.  
  281. function FolderOpen_OnClick(GUIControl *control, MouseButton button)
  282. {
  283. folder.X = 60;
  284. folder.Y = 30;
  285. folder.Visible = true;
  286. }
  287.  
  288. function FolderClose_OnClick(GUIControl *control, MouseButton button)
  289. {
  290. folder.Visible = false;
  291. }
  292.  
  293.  
  294. /*
  295. GUI *theGui = GUI.GetAtScreenXY(mouse.x, mouse.y);
  296. if (theGui != null) debuginfo.Text = String.Format("%d", theGui.ID);
  297. */
  298.  
  299. // back
  300.  
  301. function backButton_OnClick(GUIControl *control, MouseButton button)
  302. {
  303. player.ChangeRoom(4, 0, 0);
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement