Advertisement
fidless

Untitled

Apr 26th, 2019
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.51 KB | None | 0 0
  1. //=============================================================================
  2. // TDDP_MouseSystemEx.js
  3. //=============================================================================
  4.  
  5. var Imported = Imported || {};
  6. Imported.TDDP_MouseSystemEx = "1.8.2";
  7.  
  8. //=============================================================================
  9. /*:
  10. * @plugindesc 1.8.2(fix v.1.2) Custom mouse cursors, highlight menu items on hover, custom event mouse interaction and much more! See Help. id:TDDP_MouseSystemEx
  11. *
  12. * @author Tor Damian Design / Galenmereth
  13. *
  14. * @param ---Custom Cursor---
  15. * @desc This is a heading, no need to touch it.
  16. * @default
  17. *
  18. * @param Use Custom Cursor?
  19. * @desc Whether you want to use a custom mouse cursor image.
  20. * true => ON false => OFF
  21. * @default false
  22. *
  23. * @param Custom Cursor Image
  24. * @desc The filename for the custom cursor. It looks for this in your project's Custom Cursor Folder.
  25. * @default default.png
  26. *
  27. * @param Custom Cursors Folder
  28. * @desc The folder you wish to store the custom cursors in. Must end with a forward slash. Default: img/cursors/
  29. * @default img/cursors/
  30. *
  31. * @param ---Auto Change Cursors---
  32. * @desc Options for automatically changing the mouse cursor when hovering over events with the given event commands in them.
  33. * @default
  34. *
  35. * @param Show Text Cursor
  36. * @desc Automatically show this custom cursor image when hovering over events with Show Text commands in them.
  37. *
  38. * @param Transfer Cursor
  39. * @desc Automatically show this custom cursor image when hovering over events with Transfer Player commands in them.
  40. *
  41. * @param Change Gold Cursor
  42. * @desc Automatically show this custom cursor image when hovering over events with Change Gold commands in them.
  43. *
  44. * @param Change Items Cursor
  45. * @desc Automatically show this custom cursor image when hovering over events with Change Items commands in them.
  46. *
  47. * @param Change Weapons Cursor
  48. * @desc Automatically show this custom cursor image when hovering over events with Change Weapons commands in them.
  49. *
  50. * @param Change Armors Cursor
  51. * @desc Automatically show this custom cursor image when hovering over events with Change Armors commands in them.
  52. *
  53. * @param Battle Processing Cursor
  54. * @desc Automatically show this cursor when hovering over events with Battle Processing commands in them.
  55. *
  56. * @param ---Auto Change Icons---
  57. * @desc Options for automatically showing an icon when hovering over events with the given event commands in them.
  58. * @default
  59. *
  60. * @param Show Text Icon
  61. * @desc Automatically show this icon when hovering over events with Show Text commands in them.
  62. *
  63. * @param Transfer Icon
  64. * @desc Automatically show this icon when hovering over events with Transfer Player commands in them.
  65. *
  66. * @param Change Gold Icon
  67. * @desc Automatically show this icon when hovering over events with Change Gold commands in them.
  68. *
  69. * @param Change Items Icon
  70. * @desc Automatically show this icon when hovering over events with Change Items commands in them.
  71. *
  72. * @param Change Weapons Icon
  73. * @desc Automatically show this icon when hovering over events with Change Weapons commands in them.
  74. *
  75. * @param Change Armors Icon
  76. * @desc Automatically show this icon when hovering over events with Change Armors commands in them.
  77. *
  78. * @param Battle Processing Icon
  79. * @desc Automatically show this icon when hovering over events with Battle Processing commands in them.
  80. *
  81. * @param ---Hover Select---
  82. * @desc This is a heading, no need to touch it.
  83. * @default
  84. *
  85. * @param Highlight On Hover
  86. * @desc Highlight menu items when hovering over them with the mouse.
  87. * true => ON false => OFF
  88. * @default false
  89. *
  90. * @param Hover SE Cooldown
  91. * @desc Audio cooldown (in frames) between playing Cursor SE when Highlight On Hover is set to true. Default 4.
  92. * @default 4
  93. *
  94. * @param ---Customizeable Notetags---
  95. * @desc These are options for activating events by mouse interaction instead of player character.
  96. * @default
  97. *
  98. * @param No Auto Cursor Notetag
  99. * @desc The notetag used to disable auto cursor switching on this event or event page.
  100. * @default no_auto_cursor!
  101. *
  102. * @param No Auto Icon Notetag
  103. * @desc The notetag used to disable auto icon switching on this event or event page.
  104. * @default no_auto_icon!
  105. *
  106. * @param Click Notetag
  107. * @desc The notetag used to trigger the event when it is clicked on.
  108. * Default: click_activate!
  109. * @default click_activate!
  110. *
  111. * @param Hover Notetag
  112. * @desc The notetag used to trigger the event when the mouse is over it.
  113. * Default: hover_activate!
  114. * @default hover_activate!
  115. *
  116. * @param Leave Notetag
  117. * @desc The notetag used to trigger the event when the mouse leaves it.
  118. * Default: leave_activate!
  119. * @default leave_activate!
  120. *
  121. * @param ---Mouse Icons---
  122. * @desc This is a heading, no need to touch it.
  123. * @default
  124. *
  125. * @param Hide Cursor
  126. * @desc Hide the default mouse cursor when an icon is shown.
  127. * true => ON false => OFF
  128. * @default false
  129. *
  130. * @param Icon Offset X
  131. * @desc The icon's offset from the mouse horizontally.
  132. * Default: 9
  133. * @default 9
  134. *
  135. * @param Icon Offset Y
  136. * @desc The icon's offset from the mouse vertically.
  137. * Default: 14
  138. * @default 14
  139. *
  140. * @param ---Mouse Icon Tags---
  141. * @desc This is a heading, no need to touch it.
  142. * @default
  143. *
  144. * @param Icon Tag 1
  145. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  146. * @default quest: 191
  147. *
  148. * @param Icon Tag 2
  149. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  150. * @default chest: 210
  151. *
  152. * @param Icon Tag 3
  153. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  154. * @default door: 106
  155. *
  156. * @param Icon Tag 4
  157. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  158. * @default world_map: 190
  159. *
  160. * @param Icon Tag 5
  161. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  162. * @default potion: 176
  163. *
  164. * @param Icon Tag 6
  165. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  166. * @default poison: 177
  167. *
  168. * @param Icon Tag 7
  169. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  170. * @default four_leaf_clover: 182
  171. *
  172. * @param Icon Tag 8
  173. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  174. * @default notebook: 187
  175. *
  176. * @param Icon Tag 9
  177. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  178. * @default letter: 192
  179. *
  180. * @param Icon Tag 10
  181. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  182. * @default key: 195
  183. *
  184. * @param Icon Tag 11
  185. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  186. * @default key: 195
  187. *
  188. * @param Icon Tag 12
  189. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  190. * @default key: 195
  191. *
  192. * @param Icon Tag 13
  193. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  194. * @default key: 195
  195. *
  196. * @param Icon Tag 14
  197. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  198. * @default key: 195
  199. *
  200. * @param Icon Tag 15
  201. * @desc Set up an icon tag shortcut to be used with the Mouse Hover Icons notetag. See plugin Help for more information.
  202. * @default key: 195
  203. *
  204. * @help =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  205. * Information
  206. * =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  207. * TDDP - MouseSystem is a collection of methods for modifying mouse-based
  208. * interaction in your games. You can set custom mouse cursors, show icons beside
  209. * the mouse when hovering over events, activate events by mouse, and more.
  210. *
  211. * For updates and easy to use documentation, please go to the plugin's website:
  212. * http://mvplugins.tordamian.com/?p=26
  213. *
  214. * There you can also download a PDF of the documentation for offline use, and
  215. * having the documentation in one cleanly presented place means you can always
  216. * be sure it's the most recent available.
  217. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. * Terms & Conditions
  219. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220. * This plugin is free for both non-commercial and commercial use. Please see
  221. * http://mvplugins.tordamian.com/terms-of-use for the full terms of use.
  222. *
  223. * A big thank you to Degica for making this plugin free for commercial use for
  224. * everyone!
  225. */
  226. //=============================================================================
  227. // All anonymous/helper functions are registered on this object for the convenience of other plugins.
  228. var TDDP_MouseSystemEx = {};
  229. (function($) {
  230. "use strict";
  231. /**
  232. * Return .png if no file extension present in filename
  233. */
  234. $._ext = function(filename) {
  235. if (String(filename).split(".").length > 1) {
  236. return filename;
  237. } else {
  238. // Default filetype extension
  239. return filename + ".png";
  240. }
  241. }
  242. //=============================================================================
  243. // Setting up parameters
  244. //=============================================================================
  245. var parameters = $plugins.filter(function(p){return p.description.contains("id:TDDP_MouseSystemEx")})[0].parameters;
  246. // Auto change cursors
  247. $.showTextCursor = String(parameters['Show Text Cursor']) || false;
  248. $.changeGoldCursor = String(parameters['Change Gold Cursor']) || false;
  249. $.changeItemCursor = String(parameters['Change Items Cursor']) || false;
  250. $.changeWeaponCursor = String(parameters['Change Weapons Cursor']) || false;
  251. $.changeArmorCursor = String(parameters['Change Armors Cursor']) || false;
  252. $.transferPlayerCursor = String(parameters['Transfer Cursor']) || false;
  253. $.battleProcessingCursor = String(parameters['Battle Processing Cursor']) || false;
  254. // Auto change icons
  255. $.showTextIcon = String(parameters['Show Text Icon']) || false;
  256. $.changeGoldIcon = String(parameters['Change Gold Icon']) || false;
  257. $.changeItemIcon = String(parameters['Change Items Icon']) || false;
  258. $.changeWeaponIcon = String(parameters['Change Weapons Icon']) || false;
  259. $.changeArmorIcon = String(parameters['Change Armors Icon']) || false;
  260. $.transferPlayerIcon = String(parameters['Transfer Icon']) || false;
  261. $.battleProcessingIcon = String(parameters['Battle Processing Icon']) || false;
  262. // Settings
  263. $.highlightOnHover = Boolean(parameters['Highlight On Hover'] === 'true' || false);
  264. $.audioCooldownOnHover = Number(parameters['Hover SE Cooldown'] || 4)
  265. $.hideCursor = Boolean(parameters['Hide Cursor'] === 'true' || false);
  266. $.iconOffsetX = Number(parameters['Icon Offset X']) || 0;
  267. $.iconOffsetY = Number(parameters['Icon Offset Y']) || 0;
  268. $.noAutoCursorNotetag = String(parameters['No Auto Cursor Notetag']);
  269. $.noAutoIconNotetag = String(parameters['No Auto Icon Notetag']);
  270. $.clickToActivateNote = String(parameters['Click Notetag']);
  271. $.hoverToActivateNote = String(parameters['Hover Notetag']);
  272. $.leaveToActivateNote = String(parameters['Leave Notetag']);
  273. $.useCustomCursor = Boolean(parameters['Use Custom Cursor?'] === 'true' || false);
  274. $.cursorImage = $._ext(String(parameters['Custom Cursor Image']));
  275. $.defaultCursorImage = $.cursorImage;
  276. $.customCursorPath = String(parameters['Custom Cursors Folder']);
  277.  
  278. $._cursorFilenameInUse = null; // Helper to compare changes
  279. $._lastUpdateFrame = 0; // Last frame cursor got updated
  280. $._cssClassPrefix = "TDDP_customCursor_";
  281. $._indexFilename = "_index.json";
  282.  
  283. // Add all mouse icon tags
  284. $.mouseIconTags = {}
  285. for(var i = 1; i <= 15; ++i) {
  286. var tag = parameters['Icon Tag ' + i]
  287. if (!tag) continue;
  288. tag = tag.split(":");
  289. var key = tag[0];
  290. var val = tag[1].replace(' ', '');
  291. $.mouseIconTags[key] = val;
  292. }
  293. /**
  294. * Load and setup the custom cursor CSS additions
  295. */
  296. $._loadAndSetupCustomCursorCSS = function() {
  297. var xhr = new XMLHttpRequest();
  298. var url = this.customCursorPath + this._indexFilename;
  299. xhr.open('GET', url);
  300. xhr.overrideMimeType('application/json');
  301. xhr.onload = function() {
  302. if (xhr.status < 400) {
  303. var dummyContainerElement = document.createElement('div');
  304. dummyContainerElement.id = "TDD_MS_CursorDummies";
  305. document.body.appendChild(dummyContainerElement);
  306. // Next we iterate the cached cursor list
  307. var classPrefix = this._cssClassPrefix;
  308. var cachedCursors = JSON.parse(xhr.responseText);
  309. for (var i=0, max=cachedCursors.length; i<max; i++) {
  310. var cursor = cachedCursors[i];
  311. var cursorName = cursor.split(".")[0];
  312. var ox = 0;
  313. cursorName = cursorName.replace(/_x(\d*)/g, function(m, p1) {
  314. if (p1) ox = p1;
  315. return "";
  316. });
  317. var oy = 0;
  318. cursorName = cursorName.replace(/_y(\d*)/, function(m, p1){
  319. if (p1) oy = p1;
  320. return "";
  321. });
  322. var cursorPath = this.customCursorPath + cursor;
  323. var sheet = window.document.styleSheets[0];
  324. sheet.insertRule('.' + classPrefix + cursorName + ' { cursor: url(../' + cursorPath + ')' + ox + ' ' + oy + ', default; }', sheet.cssRules.length);
  325. // To ensure all the cursors get prefetched by browsers, we create dummy divs to hold all the styles...
  326. var dummyLoaderElement = document.createElement('div');
  327. dummyLoaderElement.id = cursorName + "_dummy";
  328. dummyContainerElement.appendChild(dummyLoaderElement);
  329. dummyLoaderElement.className = classPrefix + cursorName;
  330. }
  331. }
  332. }.bind(this);
  333. xhr.onerror = function() {
  334. //
  335. };
  336. xhr.send();
  337. }
  338. /**
  339. * Pre-cache all custom cursors when in test mode
  340. */
  341. // Check if playtest; if so, store file. If not, read stored
  342. $._precacheCustomCursors = function() {
  343. if (StorageManager.isLocalMode() && Utils.isOptionValid('test')) {
  344. var fs = require('fs');
  345. // Find that relative local path
  346. var path = require('path');
  347. path = path.dirname(process.mainModule.filename)
  348. path = path + '/' + this.customCursorPath
  349. path = decodeURIComponent(path);
  350. // Check if cursors dir exists, make if not
  351. if (!fs.existsSync(path)) {
  352. alert('TDDP MouseSystemEx\nThe chosen cursor folder "' + this.customCursorPath + '" has been created for you. Please put any custom cursor image files in this folder.');
  353. fs.mkdirSync(path);
  354. }
  355. // Read dir
  356.  
  357. var files = fs.readdirSync(path).filter(function(v) {
  358. if(v != this._indexFilename && v[1]) return v;
  359. }.bind(this));
  360. // Store in json
  361. fs.writeFile(path + this._indexFilename, JSON.stringify(files), 'utf8', this._loadAndSetupCustomCursorCSS.bind(this));
  362. } else {
  363. // Read stored file
  364. this._loadAndSetupCustomCursorCSS();
  365. }
  366. }.apply(TDDP_MouseSystemEx);
  367. //=============================================================================
  368. // Game_Interpreter - register plugin commands
  369. //=============================================================================
  370. /**
  371. * Alias and extend pluginCommand
  372. */
  373. var Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  374. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  375. Game_Interpreter_pluginCommand.call(this, command, args)
  376. if (command === 'SetCustomCursor') $._setCustomCursor(args[0]);
  377. if (command === 'ResetCustomCursor') $._resetCustomCursor();
  378. };
  379. //=============================================================================
  380. // Helper functions
  381. //=============================================================================
  382. /**
  383. * Get events at x and y coordinates. Separate function for compatibility
  384. *
  385. * @method _eventsXy
  386. * @param x {Number} Map X coordinate
  387. * @param y {Number} Map Y coordinate
  388. * @return {Array} of events at given coordinates
  389. */
  390. $._eventsXy = function(x, y) {
  391. return $gameMap.eventsXy(x, y);
  392. }
  393. /**
  394. * Show custom cursor
  395. */
  396. $._showCustomCursor = function(filename) {
  397. var filename = filename || this.cursorImage;
  398. document.body.className = this._cssClassPrefix + filename.split(".")[0];
  399. }
  400. /**
  401. * Set new default custom cursor
  402. */
  403. $._setCustomCursor = function(filename) {
  404. this.cursorImage = filename;
  405. this._showCustomCursor(TouchInput.cursorImage);
  406. }
  407. /**
  408. * Reset custom cursor to parameter setting defaults
  409. */
  410. $._resetCustomCursor = function() {
  411. this._setCustomCursor(this.defaultCursorImage);
  412. }
  413. /**
  414. * Show the mouse cursor
  415. */
  416. $._showMouseCursor = function() {
  417. if (this.useCustomCursor) {
  418. document.body.style.cursor = '';
  419. this._showCustomCursor();
  420. } else {
  421. document.body.style.cursor = 'inherit';
  422. }
  423. }
  424. /**
  425. * Hide the mouse cursor
  426. */
  427. $._hideMouseCursor = function() {
  428. document.body.style.cursor = 'none';
  429. }
  430. /**
  431. * Return Comments from event page. Multiline comments require an additional check (408)
  432. */
  433. $._filterComments = function(pageListObject) {
  434. var comments = (pageListObject.code == 108 || pageListObject.code == 408) ? true : false;
  435. return comments;
  436. }
  437. /**
  438. * Return Show Text messages from event page
  439. */
  440. $._filterMessages = function(pageListObject) {
  441. return pageListObject.code == 401;
  442. }
  443. /**
  444. * Return Transfer Player events from event page
  445. */
  446. $._filterTransferPlayer = function(pageListObject) {
  447. return pageListObject.code == 201;
  448. }
  449. /**
  450. * Return Battle Processing events from event page
  451. */
  452. $._filterBattleProcess = function(pageListObject) {
  453. return pageListObject.code == 301;
  454. }
  455. /**
  456. * Return Change Gold events from event page
  457. */
  458. $._filterChangeGold = function(pageListObject) {
  459. return pageListObject.code == 125;
  460. }
  461. /**
  462. * Return Change Items events from event page
  463. */
  464. $._filterChangeItems = function(pageListObject) {
  465. return pageListObject.code == 126;
  466. }
  467. /**
  468. * Return Change Weapons events from event page
  469. */
  470. $._filterChangeWeapons = function(pageListObject) {
  471. return pageListObject.code == 127;
  472. }
  473. /**
  474. * Return Change Armors events from event page
  475. */
  476. $._filterChangeArmors = function(pageListObject) {
  477. return pageListObject.code == 128;
  478. }
  479. /**
  480. * Check if current scene is of the type Scene_Map
  481. */
  482. $._isSceneMap = function() {
  483. return (SceneManager._scene instanceof Scene_Map);
  484. }
  485. /**
  486. * Find a given notetag either in a game_event's Note box or Comment box on current active page
  487. */
  488. $._findInEventNotetags = function(game_event, notetag, onMatch) {
  489. if (!game_event.page()) return false;
  490. var comments = game_event.page().list.filter(this._filterComments);
  491. var result = null;
  492. var foundMatch = false;
  493. var matchInString = function(string) {
  494. result = string.match(notetag);
  495. if (result !== null) {
  496. foundMatch = true;
  497. }
  498. }
  499. // First see if there's a relevant page comment, has higher priority
  500. if (comments.length > 0) {
  501. comments.forEach(function(comment) {
  502. if (foundMatch) return;
  503. matchInString(comment.parameters[0]);
  504. })
  505. }
  506. // If nothing found in page comment, check Note box
  507. if (!foundMatch) {
  508. if (game_event.event().note) {
  509. matchInString(game_event.event().note);
  510. }
  511. }
  512. if (foundMatch){ onMatch.call(game_event, result); }
  513. }
  514. /**
  515. * Arrays of pairs of cursors/icons and filters to run to check if they should be used
  516. */
  517. $.autoCursorFilters = [
  518. // The order is the priority; the first match stops further lookup
  519. [$.battleProcessingCursor, $._filterBattleProcess],
  520. [$.transferPlayerCursor, $._filterTransferPlayer],
  521. [$.changeGoldCursor, $._filterChangeGold],
  522. [$.changeItemCursor, $._filterChangeItems],
  523. [$.changeWeaponCursor, $._filterChangeWeapons],
  524. [$.changeArmorCursor, $._filterChangeArmors],
  525. [$.showTextCursor, $._filterMessages],
  526. ];
  527. $.autoIconFilters = [
  528. // The order is the priority; the first match stops further lookup
  529. [$.battleProcessingIcon, $._filterBattleProcess],
  530. [$.transferPlayerIcon, $._filterTransferPlayer],
  531. [$.changeGoldIcon, $._filterChangeGold],
  532. [$.changeItemIcon, $._filterChangeItems],
  533. [$.changeWeaponIcon, $._filterChangeWeapons],
  534. [$.changeArmorIcon, $._filterChangeArmors],
  535. [$.showTextIcon, $._filterMessages],
  536. ];
  537. /**
  538. * Function to check whether conditions are prime to check for events under the mouse
  539. */
  540. $.conditionsValidForMouseHoverCheck = function() {
  541. return (SceneManager.isCurrentSceneStarted() && this._isSceneMap() &&
  542. $gameMap !== null &&
  543. $dataMap !== null &&
  544. !$gameMap._interpreter.isRunning());
  545. }
  546. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  547. // START - Highlight On Hover option
  548. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  549. if ($.highlightOnHover){
  550. //=========================================================================
  551. // TouchInput modifications
  552. //=========================================================================
  553. /**
  554. * Removing the check for whether _mousePressed is active to facilitate hover events
  555. */
  556. TouchInput._onMouseMove = function(event) {
  557. var x = Graphics.pageToCanvasX(event.pageX);
  558. var y = Graphics.pageToCanvasY(event.pageY);
  559. this._onMove(x, y);
  560. };
  561. //=========================================================================
  562. // Window_Selectable modifications
  563. //=========================================================================
  564. /**
  565. * Aliased update function, adds processMouseMoved() call
  566. */
  567. var _Window_Selectable_update = Window_Selectable.prototype.update;
  568. Window_Selectable.prototype.update = function() {
  569. this.processMouseMoved();
  570. _Window_Selectable_update.call(this);
  571. };
  572. /**
  573. * Check if conditions are right for calling onTouch when using mouse movement (for hover activation)
  574. */
  575. Window_Selectable.prototype.processMouseMoved = function() {
  576. if (this.isOpenAndActive() && TouchInput.isMoved() && this.cursorIsWithinWindow()) {
  577. this.onTouch(false);
  578. }
  579. };
  580. /**
  581. * Check if cursor is within window
  582. */
  583. Window_Selectable.prototype.cursorIsWithinWindow = function() {
  584. var _x = this.canvasToLocalX(TouchInput.x);
  585. var _y = this.canvasToLocalY(TouchInput.y);
  586. if (_x > this.padding && _x <= this.width - this.padding) {
  587. if (_y > this.padding && _y < this.height - this.padding) {
  588. return true;
  589. }
  590. }
  591. return false;
  592. }
  593.  
  594. //=============================================================================
  595. // SoundManager modifications
  596. //=============================================================================
  597. /*
  598. * Static var to keep track of last played cursor SE frame
  599. */
  600. SoundManager._lastPlayCursorFrame = 0;
  601. /**
  602. * Aliased function to add check for whether playCursor should play, based on cooldown setting
  603. */
  604. var _SoundManager_playCursor = SoundManager.playCursor;
  605. SoundManager.playCursor = function() {
  606. var _canPlay = SoundManager._lastPlayCursorFrame > Graphics.frameCount
  607. || Graphics.frameCount > SoundManager._lastPlayCursorFrame + $.audioCooldownOnHover;
  608.  
  609. if (_canPlay) {
  610. _SoundManager_playCursor.call(this);
  611. SoundManager._lastPlayCursorFrame = Graphics.frameCount;
  612. }
  613. };
  614. }
  615. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  616. // END - Highlight On Hover option
  617. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  618. //=============================================================================
  619. // TouchInput modifications
  620. //=============================================================================
  621. /**
  622. * Alias and extend initialize() with _setupCursorIconObject()
  623. */
  624. var _TouchInput_initialize = TouchInput.initialize;
  625. TouchInput.initialize = function() {
  626. this._setupCursorIconObject();
  627. _TouchInput_initialize.call(this);
  628. };
  629. /**
  630. * Setup cursorIcon object
  631. */
  632. TouchInput._setupCursorIconObject = function() {
  633. this.cursorIcon = new Sprite();
  634. this.cursorIcon.drawIcon = Window_Base.prototype.drawIcon;
  635. this.cursorIcon.bitmap = new Bitmap(Window_Base._iconWidth, Window_Base._iconHeight);
  636. this.cursorIcon.contents = this.cursorIcon.bitmap;
  637. this.cursorIcon.iconIndex = null;
  638. }
  639. /**
  640. * Alias and extend _onMouseMove() to use new function _checkCursorStatus()
  641. */
  642. var _TouchInput_onMouseMove = TouchInput._onMouseMove;
  643. TouchInput._onMouseMove = function(event) {
  644. _TouchInput_onMouseMove.call(this, event);
  645. this._checkCursorStatus(event.pageX, event.pageY);
  646. };
  647. /**
  648. * Check cursor's status and whether to alter cursor
  649. * @method _checkCursorStatus
  650. * @param pageX {Number} Mouse page X coordinate
  651. * @param pageY {Number} Mouse page Y coordinate
  652. */
  653. TouchInput._checkCursorStatus = function(pageX, pageY) {
  654. // Check for events under mouse and perform actions, and get event in result
  655. var overEvents = this._checkForEventUnderMouse(pageX, pageY);
  656.  
  657. // Update cursor icon position
  658. if (this.cursorIcon.iconIndex) {
  659. this.cursorIcon.x = Graphics.pageToCanvasX(pageX) +
  660. (this.cursorIcon.customOffsetX !== null ? this.cursorIcon.customOffsetX : $.iconOffsetX);
  661. this.cursorIcon.y = Graphics.pageToCanvasY(pageY) +
  662. (this.cursorIcon.customOffsetY !== null ? this.cursorIcon.customOffsetY : $.iconOffsetY);
  663. this.cursorIcon.visible = true;
  664. }
  665.  
  666. // Check if leave activate is to be triggered for a previously active event
  667. this._activeEvents = this._activeEvents || [];
  668. while (this._activeEvents.length > 0) {
  669. var activeEvent = this._activeEvents.shift();
  670. if (activeEvent.TDDP_MS.leaveActivate) {
  671. if (!overEvents || overEvents.length == 0 || overEvents.indexOf(activeEvent) == -1) {
  672. activeEvent.start();
  673. }
  674. }
  675. }
  676. // Reset active events if new over events
  677. this._activeEvents = overEvents || this._activeEvents;
  678. }
  679. /**
  680. * Alias and extend update() to store last event coords for checking if cursor has left an event
  681. */
  682. var _TouchInput_update = TouchInput.update;
  683. TouchInput.update = function() {
  684. _TouchInput_update.call(this);
  685. if (this._lastEventPageX == this._curEventPageX && this._lastEventPageY == this._curEventPageY) {
  686. this._checkCursorStatus(this._lastEventPageX, this._lastEventPageY);
  687. }
  688. this._lastEventPageX = this._curEventPageX;
  689. this._lastEventPageY = this._curEventPageY;
  690. }
  691. /**
  692. * Perform check for event under mouse and perform functions depending on parsed notetag properties
  693. * @method _checkForEventUnderMouse
  694. * @param pageX {Number} Mouse page X coordinate
  695. * @param pageY {Number} Mouse page Y coordinate
  696. * @return {Array} of found events or {Boolean} false if none.
  697. */
  698. TouchInput._checkForEventUnderMouse = function(pageX, pageY) {
  699. this._curEventPageX = pageX;
  700. this._curEventPageY = pageY;
  701. if ($.conditionsValidForMouseHoverCheck()) {
  702. var x = $gameMap.canvasToMapX(Graphics.pageToCanvasX(pageX));
  703. var y = $gameMap.canvasToMapY(Graphics.pageToCanvasY(pageY));
  704. var events = $._eventsXy(x, y);
  705. events.reverse().forEach(function(game_event) {
  706. if (game_event.TDDP_MS.hoverIcon) {
  707. TouchInput._updateCursorIcon(game_event.TDDP_MS.hoverIcon);
  708. if ($.hideCursor) $._hideMouseCursor();
  709. } else {
  710. TouchInput._hideCursorIcon();
  711. };
  712. if (game_event.TDDP_MS.hoverActivate && !$gameMessage.isBusy()) {
  713. game_event.start();
  714. };
  715. if (game_event.TDDP_MS.hideCursor) {
  716. $._hideMouseCursor();
  717. };
  718. if (game_event.TDDP_MS.customOffsetX && game_event.TDDP_MS.customOffsetY) {
  719. TouchInput.cursorIcon.customOffsetX = game_event.TDDP_MS.customOffsetX;
  720. TouchInput.cursorIcon.customOffsetY = game_event.TDDP_MS.customOffsetY;
  721. };
  722. if ($.useCustomCursor) {
  723. if (game_event.TDDP_MS.customCursor) {
  724. $._showCustomCursor(game_event.TDDP_MS.customCursor);
  725. } else {
  726. $._showCustomCursor();
  727. }
  728. };
  729. if (game_event.TDDP_MS.hoverSwitch) {
  730. var key = [$gameMap._mapId, game_event._eventId, game_event.TDDP_MS.hoverSwitch.key]
  731. $gameSelfSwitches.setValue(key, game_event.TDDP_MS.hoverSwitch.val === 'true')
  732. };
  733. });
  734. if (events && events.length > 0) return events;
  735. }
  736. // If no events found under cursor perform default actions
  737. TouchInput._hideCursorIcon();
  738. $._showMouseCursor();
  739. return false;
  740. };
  741. /**
  742. * Update the cursor icon
  743. * @method _updateCursorIcon
  744. * @param iconIndex {Number} The icon index to show next to the cursor
  745. */
  746. TouchInput._updateCursorIcon = function(iconIndex) {
  747. if (this.cursorIcon.iconIndex != iconIndex) {
  748. this.cursorIcon.iconIndex = iconIndex;
  749. this.cursorIcon.contents.clear();
  750. this.cursorIcon.drawIcon(iconIndex, 0, 0);
  751. this.cursorIcon.visible = false;
  752. }
  753. };
  754. /**
  755. * Hide the cursor icon
  756. * @method _hideCursorIcon
  757. */
  758. TouchInput._hideCursorIcon = function() {
  759. this.cursorIcon.iconIndex = null;
  760. this.cursorIcon.visible = false;
  761. this.cursorIcon.customOffsetX = null;
  762. this.cursorIcon.customOffsetY = null;
  763. }
  764. /**
  765. * Alias and extend _onTrigger() to only fire if we're not activating on click
  766. */
  767. var _TouchInput_onTrigger = TouchInput._onTrigger;
  768. TouchInput._onTrigger = function(x, y) {
  769. if (TouchInput._activateClickEvents(x, y)) {
  770. $gameTemp.clearDestination(); // Invalidate destination
  771. } else {
  772. _TouchInput_onTrigger.call(this, x, y);
  773. }
  774. };
  775. /**
  776. * Activate click events if valid and return true if so
  777. * @method _activateClickEvents
  778. * @param x {Number} Map X coordinate
  779. * @param y {Number} Map Y coordinate
  780. */
  781. TouchInput._activateClickEvents = function(x, y) {
  782. var found_click_event = false;
  783. if ($.conditionsValidForMouseHoverCheck()) {
  784. var x = $gameMap.canvasToMapX(x);
  785. var y = $gameMap.canvasToMapY(y);
  786. $._eventsXy(x, y).reverse().forEach(function(game_event) {
  787. if (game_event.TDDP_MS.clickActivate) {
  788. game_event.start();
  789. found_click_event = true;
  790. };
  791. if (game_event.TDDP_MS.clickSwitch) {
  792. var key = [$gameMap._mapId, game_event._eventId, game_event.TDDP_MS.clickSwitch.key]
  793. $gameSelfSwitches.setValue(key, game_event.TDDP_MS.clickSwitch.val === 'true');
  794. found_click_event = true;
  795. };
  796. });
  797. }
  798. return found_click_event;
  799. }
  800. //=============================================================================
  801. // Spriteset_Map modifications
  802. //=============================================================================
  803. /**
  804. * Alias and extend createScreenSprites() to also create cursor icon holder sprite
  805. */
  806. var _Spriteset_Map_createScreenSprites = Spriteset_Map.prototype.createScreenSprites;
  807. Spriteset_Map.prototype.createScreenSprites = function() {
  808. _Spriteset_Map_createScreenSprites.call(this);
  809. this.createCursorIconSprite();
  810. };
  811. /**
  812. * Create a container sprite for the cursor icon
  813. */
  814. Spriteset_Map.prototype.createCursorIconSprite = function() {
  815. this._cursorIconSprite = new Sprite();
  816. this._cursorIconSprite.setFrame(0, 0, Graphics.width, Graphics.height);
  817. this._cursorIconSprite.addChild(TouchInput.cursorIcon);
  818. this.addChild(this._cursorIconSprite);
  819. };
  820. //=============================================================================
  821. // Game_Event modifications
  822. //=============================================================================
  823. /**
  824. * Alias and extend setupPage() to also setup mouse system properties
  825. */
  826. var _Game_Event_setupPage = Game_Event.prototype.setupPage;
  827. Game_Event.prototype.setupPage = function() {
  828. _Game_Event_setupPage.call(this);
  829. this.setupMouseSystemProperties();
  830. };
  831. /**
  832. * Setup mouse system properties on events, for storing notetag parsing on page updates
  833. */
  834. Game_Event.prototype.setupMouseSystemProperties = function() {
  835. this.TDDP_MS = {};
  836. this.TDDP_MS.hoverIcon = false;
  837. this.TDDP_MS.allowAutoCursor = true;
  838. this.TDDP_MS.allowAutoIcon = true;
  839. this.TDDP_MS.clickActivate = false;
  840. this.TDDP_MS.hoverActivate = false;
  841. this.TDDP_MS.leaveActivate = false;
  842. this.TDDP_MS.hideCursor = false;
  843. this.TDDP_MS.customOffsetX = false;
  844. this.TDDP_MS.customOffsetY = false;
  845. this.TDDP_MS.customCursor = false;
  846. this.TDDP_MS.clickSwitch = false;
  847. this.TDDP_MS.hoverSwitch = false;
  848. $._findInEventNotetags(this, /hover_icon\s(.*?);/i, function(result) {
  849. if (!result) return;
  850. result = result[result.length - 1];
  851. if ($.mouseIconTags[result]) {
  852. result = $.mouseIconTags[result];
  853. }
  854. this.TDDP_MS.hoverIcon = Number(result);
  855. });
  856. $._findInEventNotetags(this, $.noAutoCursorNotetag, function() {
  857. this.TDDP_MS.allowAutoCursor = false;
  858. });
  859. $._findInEventNotetags(this, $.noAutoIconNotetag, function() {
  860. this.TDDP_MS.allowAutoIcon = false;
  861. });
  862. $._findInEventNotetags(this, $.clickToActivateNote, function() {
  863. this.TDDP_MS.clickActivate = true;
  864. });
  865. $._findInEventNotetags(this, $.hoverToActivateNote, function() {
  866. this.TDDP_MS.hoverActivate = true;
  867. });
  868. $._findInEventNotetags(this, $.leaveToActivateNote, function() {
  869. this.TDDP_MS.leaveActivate = true;
  870. });
  871. $._findInEventNotetags(this, 'hide_cursor!', function() {
  872. this.TDDP_MS.hideCursor = true;
  873. });
  874. $._findInEventNotetags(this, /icon_offset\s(.*?)\s(.*?);/i, function(result) {
  875. this.TDDP_MS.customOffsetX = Number(result[1]);
  876. this.TDDP_MS.customOffsetY = Number(result[2]);
  877. });
  878. $._findInEventNotetags(this, /hover_cursor\s(.*?);/i, function(result) {
  879. this.TDDP_MS.customCursor = result[result.length - 1];
  880. });
  881. $._findInEventNotetags(this, /click_switch\s(.*?)\s(.*?);/i, function(result) {
  882. this.TDDP_MS.clickSwitch = {};
  883. this.TDDP_MS.clickSwitch.key = String(result[1]);
  884. this.TDDP_MS.clickSwitch.val = String(result[2]);
  885.  
  886. });
  887. $._findInEventNotetags(this, /hover_switch\s(.*?)\s(.*?);/i, function(result) {
  888. this.TDDP_MS.hoverSwitch = {};
  889. this.TDDP_MS.hoverSwitch.key = String(result[1]);
  890. this.TDDP_MS.hoverSwitch.val = String(result[2]);
  891. });
  892. // If no active event page, there's no event commands to go through
  893. if (!this.page()) return;
  894. // Auto cursor checks, only if there's a page and allowed
  895. if (this.TDDP_MS.allowAutoCursor) {
  896. for (var i=0, max=$.autoCursorFilters.length; i < max; i++) {
  897. if (this.TDDP_MS.customCursor) break;
  898. var entry = $.autoCursorFilters[i];
  899. var cursor = entry[0];
  900. var filter = entry[1];
  901. if (typeof cursor == "string") {
  902. var matches = this.page().list.filter(filter);
  903. if (matches.length > 0) {
  904. this.TDDP_MS.customCursor = cursor;
  905. }
  906. }
  907. }
  908. }
  909. // Auto icon checks
  910. if (this.TDDP_MS.allowAutoIcon) {
  911. for (var i=0, max=$.autoIconFilters.length; i < max; i++) {
  912. if (this.TDDP_MS.hoverIcon) break;
  913. var entry = $.autoIconFilters[i];
  914. var icon = entry[0];
  915. var filter = entry[1];
  916. if (typeof icon == "string") {
  917. var matches = this.page().list.filter(filter);
  918. if (matches.length > 0) {
  919. if (isNaN(icon)) {
  920. // Icon is a string, so let's look in Icon Tags
  921. icon = $.mouseIconTags[icon]
  922. }
  923. this.TDDP_MS.hoverIcon = Number(icon);
  924. }
  925. }
  926. }
  927. }
  928. }
  929.  
  930. Graphics.isFontLoaded = function(name) {
  931. if (Graphics._cssFontLoading && process.versions.chromium !== '41.0.2272.76') {
  932. if(Graphics._fontLoaded){
  933. return Graphics._fontLoaded.check('10px "'+name+'"');
  934. }
  935.  
  936. return false;
  937. } else {
  938. if (!this._hiddenCanvas) {
  939. this._hiddenCanvas = document.createElement('canvas');
  940. }
  941. var context = this._hiddenCanvas.getContext('2d');
  942. var text = 'abcdefghijklmnopqrstuvwxyz';
  943. var width1, width2;
  944. context.font = '40px ' + name + ', sans-serif';
  945. width1 = context.measureText(text).width;
  946. context.font = '40px sans-serif';
  947. width2 = context.measureText(text).width;
  948. return width1 !== width2;
  949. }
  950. };
  951.  
  952. })(TDDP_MouseSystemEx);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement