查看: 7375|回复: 9

[原创发布] 鼠标触摸增强

[复制链接]
梦石
0
星屑
90
在线时间
387 小时
注册时间
2007-7-27
回帖
4075

开拓者

发表于 2016-1-7 21:01:51 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 trentswd 于 2016-1-16 00:14 编辑

之前练手用的,因为覆盖了很多函数,感觉会冲突的哗啦哗啦
默认工程可以用,用了YEP的也可以用,不过写的比较乱,主要是分享一下想法

update 2016/01/16:
- 修正交通工具无效的问题

实现功能:
1 鼠标: 将判定点从按下改为单击(按下再弹起)
2 鼠标: 修改移动事件的判定
3 鼠标: 选择窗口鼠标滑动改变选项,点击即是确认
4 鼠标: 地图上,点击鼠标表示移动到点,会触发事件。长按鼠标表示向点移动,不会触发事件和目的地闪动的动画。鼠标和人物距离远会变为跑动。
5 触摸: 将判定点从按下改为单击
6 触摸: 增加向左快速滑动手势,表示返回
7 触摸: 修正YEP战斗导致chrome触摸无法选中敌人的问题
8 触摸: 选择窗口取消按住拖动改变当前选项,改为按住拖动滑动页面,点击既是确认
9 触摸: 地图上,单击手指是移动到点,会触发时间,按住手指表示向点移动,不会触发事件。手指和人物距离远会变为跑动。
  1. //=============================================================================
  2. // Trentswd Plugins - Touch Event Extend
  3. // TWDP_TouchEventEx.js
  4. //=============================================================================

  5. var Imported = Imported || {};
  6. Imported.TWDP_TouchEventEx = true;

  7. var TWDP = TWDP || {};
  8. TWDP.TEE = TWDP.TEE || {};

  9. //=============================================================================
  10. /*:
  11. * @plugindesc v1.00 Extend the Touch Event
  12. * @author Trentswd
  13. *
  14. * @help
  15. * ============================================================================
  16. * Introduction
  17. * ============================================================================
  18. *
  19. * Don't have time to write this right now, sorry.
  20. *
  21. * ============================================================================
  22. * Plugin Commands
  23. * ============================================================================
  24. *
  25. * Don't have time to write this right now, sorry.
  26. *
  27. */
  28. //=============================================================================

  29. //=============================================================================
  30. // Parameter Variables
  31. //=============================================================================

  32. TWDP.parameters = PluginManager.parameters('TWDP_TouchEventEx');
  33. TWDP.TEE.param = TWDP.TEE.param || {};

  34. function distanceOfTwoPoints(x1, y1, x2, y2) {
  35.   return Math.round(
  36.     Math.sqrt(
  37.       Math.pow(x1 - x2, 2) +
  38.       Math.pow(y1 - y2, 2)
  39.     )
  40.   );
  41. };

  42. (function($) {

  43.   $.backup = $.backup || {};
  44.   //-----------------------------------------------------------------------------
  45.   /**
  46.    * The static class that handles input data from the mouse and touchscreen.
  47.    *
  48.    * @class TouchInput
  49.    */

  50.   TouchInput.clickDelta = 5;
  51.   TouchInput.backGestureSpeedThreshold = 30;
  52.   TouchInput.backGestureDistanceThreshold = 20;

  53.   /**
  54.    * Initializes the touch system.
  55.    *
  56.    * @static
  57.    * @method initialize
  58.    */
  59.   TouchInput.initialize = function() {
  60.     this.clear();
  61.     this._setupEventHandlers();
  62.   };

  63.   /**
  64.    * The wait time of the pseudo key repeat in frames.
  65.    *
  66.    * @static
  67.    * @property keyRepeatWait
  68.    * @type Number
  69.    */
  70.   TouchInput.keyRepeatWait = 24;

  71.   /**
  72.    * The interval of the pseudo key repeat in frames.
  73.    *
  74.    * @static
  75.    * @property keyRepeatInterval
  76.    * @type Number
  77.    */
  78.   TouchInput.keyRepeatInterval = 6;

  79.   /**
  80.    * Clears all the touch data.
  81.    *
  82.    * @static
  83.    * @method clear
  84.    */
  85.   $.backup.TouchInput_clear = TouchInput.clear;
  86.   TouchInput.clear = function() {
  87.       $.backup.TouchInput_clear.call(this);


  88.       this._pressed = {};
  89.       this._pressed.left = {};
  90.       this._pressed.left.isPressed = false;
  91.       this._pressed.left.pressX = 0;
  92.       this._pressed.left.pressY = 0;
  93.       this._pressed.right = {};
  94.       this._pressed.right.isPressed = false;
  95.       this._pressed.right.pressX = 0;
  96.       this._pressed.right.pressY = 0;
  97.       this._pressed.middle = {};
  98.       this._pressed.middle.isPressed = false;
  99.       this._pressed.middle.pressX = 0;
  100.       this._pressed.middle.pressY = 0;
  101.       this._pressed.touch = {};
  102.       this._pressed.touch.isPressed = false;
  103.       this._pressed.touch.pressX = 0;
  104.       this._pressed.touch.pressY = 0;

  105.       this._clicked = {};
  106.       this._clicked.left = {};
  107.       this._clicked.left.isClicked = false;
  108.       this._clicked.left.x = 0;
  109.       this._clicked.left.y = 0;
  110.       this._clicked.right = {};
  111.       this._clicked.right.isClicked = false;
  112.       this._clicked.right.x = 0;
  113.       this._clicked.right.y = 0;
  114.       this._clicked.middle = {};
  115.       this._clicked.middle.isClicked = false;
  116.       this._clicked.middle.x = 0;
  117.       this._clicked.middle.y = 0;
  118.       this._clicked.touch = {};
  119.       this._clicked.touch.isClicked = false;
  120.       this._clicked.touch.x = 0;
  121.       this._clicked.touch.y = 0;

  122.       this._pressed.left.time = 0;
  123.       this._pressed.right.time = 0;
  124.       this._pressed.middle.time = 0;
  125.       this._pressed.touch.time = 0;


  126.       this._events._clicked = {};
  127.       this._events._clicked.left = {};
  128.       this._events._clicked.left.isClicked = false;
  129.       this._events._clicked.left.x = 0;
  130.       this._events._clicked.left.y = 0;
  131.       this._events._clicked.right = {};
  132.       this._events._clicked.right.isClicked = false;
  133.       this._events._clicked.right.x = 0;
  134.       this._events._clicked.right.y = 0;
  135.       this._events._clicked.middle = {};
  136.       this._events._clicked.middle.isClicked = false;
  137.       this._events._clicked.middle.x = 0;
  138.       this._events._clicked.middle.y = 0;
  139.       this._events._clicked.touch = {};
  140.       this._events._clicked.touch.isClicked = false;
  141.       this._events._clicked.touch.x = 0;
  142.       this._events._clicked.touch.y = 0;

  143.       this._events._pressed = {};
  144.       this._events._pressed.left = {};
  145.       this._events._pressed.left.isPressed = false;
  146.       this._events._pressed.left.pressX = 0;
  147.       this._events._pressed.left.pressY = 0;
  148.       this._events._pressed.right = {};
  149.       this._events._pressed.right.isPressed = false;
  150.       this._events._pressed.right.pressX = 0;
  151.       this._events._pressed.right.pressY = 0;
  152.       this._events._pressed.middle = {};
  153.       this._events._pressed.middle.isPressed = false;
  154.       this._events._pressed.middle.pressX = 0;
  155.       this._events._pressed.middle.pressY = 0;
  156.       this._events._pressed.touch = {};
  157.       this._events._pressed.touch.isPressed = false;
  158.       this._events._pressed.touch.pressX = 0;
  159.       this._events._pressed.touch.pressY = 0;

  160.       this.touchScroll = {};
  161.       this.touchScroll.x = 0;
  162.       this.touchScroll.y = 0;
  163.       this._events.touchScroll = {};
  164.       this._events.touchScroll.x = 0;
  165.       this._events.touchScroll.y = 0;
  166.     }
  167.     /**
  168.      * Updates the touch data.
  169.      *
  170.      * @static
  171.      * @method update
  172.      */
  173.   $.backup.TouchInput_update = TouchInput.update;
  174.   TouchInput.update = function() {
  175.     $.backup.TouchInput_update.call(this);


  176.     this._pressed.left.isPressed = this._events._pressed.left.isPressed;
  177.     this._pressed.left.pressX = this._events._pressed.left.pressX;
  178.     this._pressed.left.pressY = this._events._pressed.left.pressY;

  179.     this._pressed.right.isPressed = this._events._pressed.right.isPressed;
  180.     this._pressed.right.pressX = this._events._pressed.right.pressX;
  181.     this._pressed.right.pressY = this._events._pressed.right.pressY;

  182.     this._pressed.middle.isPressed = this._events._pressed.middle.isPressed;
  183.     this._pressed.middle.pressX = this._events._pressed.middle.pressX;
  184.     this._pressed.middle.pressY = this._events._pressed.middle.pressY;

  185.     this._pressed.touch.isPressed = this._events._pressed.touch.isPressed;
  186.     this._pressed.touch.pressX = this._events._pressed.touch.pressX;
  187.     this._pressed.touch.pressY = this._events._pressed.touch.pressY;

  188.     if (this._pressed.left.isPressed) {
  189.       this._pressed.left.time++;
  190.     } else {
  191.       this._pressed.left.time = 0;
  192.     }
  193.     if (this._pressed.right.isPressed) {
  194.       this._pressed.right.time++;
  195.     } else {
  196.       this._pressed.right.time = 0;
  197.     }
  198.     if (this._pressed.middle.isPressed) {
  199.       this._pressed.middle.time++;
  200.     } else {
  201.       this._pressed.middle.time = 0;
  202.     }
  203.     if (this._pressed.touch.isPressed) {
  204.       this._pressed.touch.time++;
  205.     } else {
  206.       this._pressed.touch.time = 0;
  207.     }

  208.     this._clicked.left.isClicked = this._events._clicked.left.isClicked;
  209.     this._clicked.left.x = this._events._clicked.left.x;
  210.     this._clicked.left.y = this._events._clicked.left.y;
  211.     this._clicked.right.isClicked = this._events._clicked.right.isClicked;
  212.     this._clicked.right.x = this._events._clicked.right.x;
  213.     this._clicked.right.y = this._events._clicked.right.y;
  214.     this._clicked.middle.isClicked = this._events._clicked.middle.isClicked;
  215.     this._clicked.middle.x = this._events._clicked.middle.x;
  216.     this._clicked.middle.y = this._events._clicked.middle.y;
  217.     this._clicked.touch.isClicked = this._events._clicked.touch.isClicked;
  218.     this._clicked.touch.x = this._events._clicked.touch.x;
  219.     this._clicked.touch.y = this._events._clicked.touch.y;


  220.     this._events._clicked.left.isClicked = false;
  221.     this._events._clicked.left.x = 0;
  222.     this._events._clicked.left.y = 0;
  223.     this._events._clicked.right.isClicked = false;
  224.     this._events._clicked.right.x = 0;
  225.     this._events._clicked.right.y = 0;
  226.     this._events._clicked.middle.isClicked = false;
  227.     this._events._clicked.middle.x = 0;
  228.     this._events._clicked.middle.y = 0;
  229.     this._events._clicked.touch.isClicked = false;
  230.     this._events._clicked.touch.x = 0;
  231.     this._events._clicked.touch.y = 0;

  232.     this.touchScroll.x = this._events.touchScroll.x;
  233.     this.touchScroll.y = this._events.touchScroll.y;
  234.     this._events.touchScroll.x = 0;
  235.     this._events.touchScroll.y = 0;
  236.   };

  237.   TouchInput.judgePressed = function(button) {
  238.     return this._pressed[button].isPressed;
  239.   }

  240.   TouchInput.judgeClicked = function(button) {
  241.     return this._clicked[button].isClicked;
  242.   }

  243.   TouchInput.judgeLongPressed = function(button, time) {
  244.     if (time === undefined) {
  245.       time = this.keyRepeatWait
  246.     }
  247.     if (this.judgePressed(button)) {
  248.       return this._pressed[button].time >= time;
  249.     }
  250.     return false;
  251.   }

  252.   /**
  253.    * @static
  254.    * @method _onMouseDown
  255.    * @param {MouseEvent} event
  256.    * @private
  257.    */
  258.   TouchInput._onMouseDown = function(event) {
  259.     if (event.button === 0) {
  260.       this._onLeftButtonDown(event);
  261.     } else if (event.button === 1) {
  262.       this._onMiddleButtonDown(event);
  263.     } else if (event.button === 2) {
  264.       this._onRightButtonDown(event);
  265.     }
  266.     this._date = Date.now();
  267.   };

  268.   /**
  269.    * @static
  270.    * @method _onLeftButtonDown
  271.    * @param {MouseEvent} event
  272.    * @private
  273.    */
  274.   TouchInput._onLeftButtonDown = function(event) {
  275.     var x = Graphics.pageToCanvasX(event.pageX);
  276.     var y = Graphics.pageToCanvasY(event.pageY);
  277.     if (Graphics.isInsideCanvas(x, y)) {
  278.       this._mousePressed = true;
  279.       this._pressedTime = 0;
  280.       this._events._pressed.left.isPressed = true;
  281.       this._events._pressed.left.pressX = x;
  282.       this._events._pressed.left.pressY = y;
  283.       this._onTrigger(x, y);
  284.     }
  285.   };

  286.   /**
  287.    * @static
  288.    * @method _onMiddleButtonDown
  289.    * @param {MouseEvent} event
  290.    * @private
  291.    */
  292.   TouchInput._onMiddleButtonDown = function(event) {
  293.     var x = Graphics.pageToCanvasX(event.pageX);
  294.     var y = Graphics.pageToCanvasY(event.pageY);
  295.     if (Graphics.isInsideCanvas(x, y)) {
  296.       this._events._pressed.middle.isPressed = true;
  297.       this._events._pressed.middle.pressX = x;
  298.       this._events._pressed.middle.pressY = y;
  299.     }
  300.   };

  301.   /**
  302.    * @static
  303.    * @method _onRightButtonDown
  304.    * @param {MouseEvent} event
  305.    * @private
  306.    */
  307.   TouchInput._onRightButtonDown = function(event) {
  308.     var x = Graphics.pageToCanvasX(event.pageX);
  309.     var y = Graphics.pageToCanvasY(event.pageY);
  310.     if (Graphics.isInsideCanvas(x, y)) {
  311.       this._events._pressed.right.isPressed = true;
  312.       this._events._pressed.right.pressX = x;
  313.       this._events._pressed.right.pressY = y;
  314.       //this._onCancel(x, y);
  315.     }
  316.   };

  317.   /**
  318.    * @static
  319.    * @method _onMouseMove
  320.    * @param {MouseEvent} event
  321.    * @private
  322.    */
  323.   $.backup.TouchInput_onMouseMove = TouchInput._onMouseMove;
  324.   TouchInput._onMouseMove = function(event) {
  325.     $.backup.TouchInput_onMouseMove.call(this, event);
  326.     var x = Graphics.pageToCanvasX(event.pageX);
  327.     var y = Graphics.pageToCanvasY(event.pageY);
  328.     this._onMove(x, y);

  329.   };

  330.   TouchInput._onClick = function(x, y, button) {
  331.     if (button === 0) {
  332.       if (this._clicked.left.cancelNext) {
  333.         this._clicked.left.cancelNext = false;
  334.         return;
  335.       }
  336.       this._events._clicked.left.isClicked = true;
  337.       this._events._clicked.left.x = x;
  338.       this._events._clicked.left.y = y;
  339.     } else if (button === 1) {
  340.       if (this._clicked.right.cancelNext) {
  341.         this._clicked.right.cancelNext = false;
  342.         return;
  343.       }
  344.       this._events._clicked.right.isClicked = true;
  345.       this._events._clicked.right.x = x;
  346.       this._events._clicked.right.y = y;
  347.       this._onCancel(x, y);
  348.     } else if (button === 2) {
  349.       if (this._clicked.middle.cancelNext) {
  350.         this._clicked.middle.cancelNext = false;
  351.         return;
  352.       }
  353.       this._events._clicked.middle.isClicked = true;
  354.       this._events._clicked.middle.x = x;
  355.       this._events._clicked.middle.y = y;
  356.     } else if (button === 'touch') {
  357.       if (this._clicked.touch.cancelNext) {
  358.         this._clicked.touch.cancelNext = false;
  359.         return;
  360.       }
  361.       this._events._clicked.touch.isClicked = true;
  362.       this._events._clicked.touch.x = x;
  363.       this._events._clicked.touch.y = y;
  364.     }
  365.   }

  366.   TouchInput.cancelNextClick = function(button) {
  367.     this._clicked[button].cancelNext = true;
  368.   }

  369.   TouchInput._onLeftButtonUp = function(event) {
  370.     var x = Graphics.pageToCanvasX(event.pageX);
  371.     var y = Graphics.pageToCanvasY(event.pageY);
  372.     if (Graphics.isInsideCanvas(x, y)) {
  373.       this._events._pressed.left.isPressed = false;
  374.       var distance = distanceOfTwoPoints(this._pressed.left.pressX, this._pressed.left.pressY,
  375.         x, y)
  376.       if (distance <= this.clickDelta) {
  377.         this._onClick(x, y, 0);
  378.       }
  379.     }
  380.   };

  381.   TouchInput._onMiddleButtonUp = function(event) {
  382.     var x = Graphics.pageToCanvasX(event.pageX);
  383.     var y = Graphics.pageToCanvasY(event.pageY);
  384.     if (Graphics.isInsideCanvas(x, y)) {
  385.       this._events._pressed.middle.isPressed = false;
  386.       if (distanceOfTwoPoints(this._pressed.middle.pressX, this._pressed.middle.pressY,
  387.           x, y) <= this.clickDelta) {
  388.         this._onClick(x, y, 2);
  389.       }
  390.     }
  391.   };

  392.   TouchInput._onRightButtonUp = function(event) {
  393.     var x = Graphics.pageToCanvasX(event.pageX);
  394.     var y = Graphics.pageToCanvasY(event.pageY);
  395.     if (Graphics.isInsideCanvas(x, y)) {
  396.       this._events._pressed.right.isPressed = false;
  397.       if (distanceOfTwoPoints(this._pressed.right.pressX, this._pressed.right.pressY,
  398.           x, y) <= this.clickDelta) {
  399.         this._onClick(x, y, 1);
  400.       }
  401.     }
  402.   };

  403.   /**
  404.    * @static
  405.    * @method _onMouseUp
  406.    * @param {MouseEvent} event
  407.    * @private
  408.    */
  409.   TouchInput._onMouseUp = function(event) {
  410.     if (event.button === 0) {
  411.       var x = Graphics.pageToCanvasX(event.pageX);
  412.       var y = Graphics.pageToCanvasY(event.pageY);
  413.       this._mousePressed = false;
  414.       this._onRelease(x, y);
  415.     }

  416.     if (event.button === 0) {
  417.       this._onLeftButtonUp(event);
  418.     } else if (event.button === 1) {
  419.       this._onMiddleButtonUp(event);
  420.     } else if (event.button === 2) {
  421.       this._onRightButtonUp(event);
  422.     }
  423.   };


  424.   /**
  425.    * @static
  426.    * @method _onTouchStart
  427.    * @param {TouchEvent} event
  428.    * @private
  429.    */
  430.   TouchInput._onTouchStart = function(event) {
  431.     for (var i = 0; i < event.changedTouches.length; i++) {
  432.       var touch = event.changedTouches[i];
  433.       var x = Graphics.pageToCanvasX(touch.pageX);
  434.       var y = Graphics.pageToCanvasY(touch.pageY);
  435.       if (Graphics.isInsideCanvas(x, y)) {
  436.         this._screenPressed = true;
  437.         this._pressedTime = 0;
  438.         this._events._pressed.touch.isPressed = true;
  439.         this._pressed.touch.time = 0;
  440.         this._events._pressed.touch.pressX = x;
  441.         this._events._pressed.touch.pressY = y;
  442.         if (event.touches.length >= 2) {
  443.           this._onCancel(x, y);
  444.         } else {
  445.           this._onTrigger(x, y);
  446.         }
  447.         event.preventDefault();
  448.       }
  449.     }
  450.     if (window.cordova || window.navigator.standalone) {
  451.       event.preventDefault();
  452.     }
  453.   };

  454.   /**
  455.    * @static
  456.    * @method _onTouchMove
  457.    * @param {TouchEvent} event
  458.    * @private
  459.    */
  460.   TouchInput._onTouchMove = function(event) {
  461.     for (var i = 0; i < event.changedTouches.length; i++) {
  462.       var touch = event.changedTouches[i];
  463.       var x = Graphics.pageToCanvasX(touch.pageX);
  464.       var y = Graphics.pageToCanvasY(touch.pageY);
  465.       //this._onMove(x, y);
  466.       this._events.touchScroll.x += x - this._x;
  467.       this._events.touchScroll.y += y - this._y;
  468.       this._x = x;
  469.       this._y = y;

  470.     }
  471.   };

  472.   /**
  473.    * @static
  474.    * @method _onTouchEnd
  475.    * @param {TouchEvent} event
  476.    * @private
  477.    */
  478.   TouchInput._onTouchEnd = function(event) {
  479.     for (var i = 0; i < event.changedTouches.length; i++) {
  480.       var touch = event.changedTouches[i];
  481.       var x = Graphics.pageToCanvasX(touch.pageX);
  482.       var y = Graphics.pageToCanvasY(touch.pageY);
  483.       this._screenPressed = false;
  484.       this._events._pressed.touch.isPressed = false;
  485.       if (this._judgeBackGestrue(event)) {
  486.         this._onCancel(x, y);
  487.       } else if (distanceOfTwoPoints(this._pressed.touch.pressX, this._pressed.touch.pressY,
  488.           x, y) <= this.clickDelta) {
  489.         this._onClick(x, y, 'touch');
  490.       }
  491.       this._pressed.touch.time = 0;
  492.       this._onRelease(x, y);
  493.     }
  494.   };

  495.   TouchInput._judgeBackGestrue = function(event) {
  496.     for (var i = 0; i < event.changedTouches.length; i++) {
  497.       var touch = event.changedTouches[i];
  498.       var x = Graphics.pageToCanvasX(touch.pageX);
  499.       var y = Graphics.pageToCanvasY(touch.pageY);
  500.       var distance = distanceOfTwoPoints(this._pressed.touch.pressX, this._pressed.touch.pressY,
  501.         x, y);
  502.       var time = this._pressed.touch.time;
  503.       //console.log(distance, distance / time, x, this._pressed.touch.pressX);
  504.       if (distance > this.clickDelta && distance / time > this.backGestureSpeedThreshold && x < this._pressed.touch.pressX && distance > TouchInput.backGestureDistanceThreshold) {
  505.         return true;
  506.       }
  507.     }
  508.     return false;
  509.   };

  510.   /**
  511.    * @static
  512.    * @method _onTouchCancel
  513.    * @param {TouchEvent} event
  514.    * @private
  515.    */
  516.   TouchInput._onTouchCancel = function(event) {
  517.     this._screenPressed = false;
  518.   };

  519.   /**
  520.    * @static
  521.    * @method _onPointerDown
  522.    * @param {PointerEvent} event
  523.    * @private
  524.    */
  525.   TouchInput._onPointerDown = function(event) {
  526.     if (event.pointerType === 'touch' && !event.isPrimary) {
  527.       var x = Graphics.pageToCanvasX(event.pageX);
  528.       var y = Graphics.pageToCanvasY(event.pageY);
  529.       if (Graphics.isInsideCanvas(x, y)) {
  530.         // For Microsoft Edge
  531.         this._onCancel(x, y);
  532.         event.preventDefault();
  533.       }
  534.     }
  535.   };

  536.   /**
  537.    * @static
  538.    * @method _onTrigger
  539.    * @param {Number} x
  540.    * @param {Number} y
  541.    * @private
  542.    */
  543.   TouchInput._onTrigger = function(x, y) {
  544.     this._events.triggered = true;
  545.     this._x = x;
  546.     this._y = y;
  547.     this._date = Date.now();
  548.   };

  549.   /**
  550.    * @static
  551.    * @method _onCancel
  552.    * @param {Number} x
  553.    * @param {Number} y
  554.    * @private
  555.    */
  556.   TouchInput._onCancel = function(x, y) {
  557.     this._events.cancelled = true;
  558.     this._x = x;
  559.     this._y = y;
  560.   };

  561.   /**
  562.    * @static
  563.    * @method _onMove
  564.    * @param {Number} x
  565.    * @param {Number} y
  566.    * @private
  567.    */
  568.   TouchInput._onMove = function(x, y) {
  569.     this._events.moved = true;
  570.     this._x = x;
  571.     this._y = y;
  572.   };

  573.   /**
  574.    * @static
  575.    * @method _onRelease
  576.    * @param {Number} x
  577.    * @param {Number} y
  578.    * @private
  579.    */
  580.   TouchInput._onRelease = function(x, y) {
  581.     this._events.released = true;
  582.     this._x = x;
  583.     this._y = y;
  584.   };

  585.   Window_Selectable.prototype.processTouch = function() {
  586.     if (this.isOpenAndActive()) {
  587.       if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
  588.         //this._touching = true;
  589.       } else if ((TouchInput.judgeClicked("left")) && this.isTouchedInsideFrame()) {
  590.         this.onTouch(false);
  591.         this.onTouch(true);
  592.       } else if (TouchInput.judgeClicked("touch") && this.isTouchedInsideFrame()) {
  593.         this.onTouch(false);
  594.         this.onTouch(true);
  595.       } else if (TouchInput.isCancelled()) {
  596.         if (this.isCancelEnabled()) {
  597.           this.processCancel();
  598.         }
  599.       }
  600.       if (this._touching) {
  601.         if (TouchInput.isPressed()) {
  602.           this.onTouch(false);
  603.         } else {
  604.           this._touching = false;
  605.         }
  606.       }

  607.       if (TouchInput.isMoved() && this.isTouchedInsideContents()) {
  608.         this.onTouch(false);
  609.       }
  610.     } else {
  611.       this._touching = false;
  612.     }
  613.   };

  614.   Window_Selectable.prototype.onTouch = function(triggered) {
  615.     var lastIndex = this.index();
  616.     var x = this.canvasToLocalX(TouchInput.x);
  617.     var y = this.canvasToLocalY(TouchInput.y);
  618.     var hitIndex = this.hitTest(x, y);
  619.     if (hitIndex >= 0) {
  620.       if (hitIndex === this.index()) {
  621.         if (triggered && this.isTouchOkEnabled()) {
  622.           this.processOk();
  623.         }
  624.       } else if (this.isCursorMovable()) {
  625.         this.select(hitIndex);
  626.         if (triggered && this.isTouchOkEnabled()) {
  627.           this.processOk();
  628.         }
  629.       }
  630.     } else if (this._stayCount >= 10) {
  631.       if (y < this.padding) {
  632.         this.cursorUp();
  633.       } else if (y >= this.height - this.padding) {
  634.         this.cursorDown();
  635.       }
  636.     }
  637.     if (this.index() !== lastIndex && triggered) {
  638.       SoundManager.playCursor();
  639.     }
  640.   };

  641.   Window_Selectable.prototype.isTouchedInsideContents = function() {
  642.     var x = this.canvasToLocalX(TouchInput.x);
  643.     var y = this.canvasToLocalY(TouchInput.y);
  644.     if (Imported.TWDP_BaseWindowEx) {
  645.       return x >= this.paddingLeft() && y >= this.paddingTop() && x < this.width - this.paddingLeft() - this.paddingRight() && y < this.height - this.paddingTop() - this.paddingBottom();
  646.     } else {
  647.       return x >= this.padding && y >= this.padding && x < this.width - this.padding * 2 && y < this.height - this.padding * 2;
  648.     }

  649.   };

  650.   $.backup.Window_Selectable_processWheel = Window_Selectable.prototype.processWheel;
  651.   Window_Selectable.prototype.processWheel = function() {
  652.     $.backup.Window_Selectable_processWheel.call(this);
  653.     if (this._touchSrollY === undefined) {
  654.       this._touchSrollY = 0;
  655.     }
  656.     if (this.isOpenAndActive()) {
  657.       if (TouchInput.judgePressed('touch')) {
  658.         if (this._touchSrollY * TouchInput.touchScroll.y < 0) {
  659.           this._touchSrollY = 0;
  660.         }
  661.         this._touchSrollY += TouchInput.touchScroll.y;
  662.       } else {
  663.         this._touchSrollY = 0;
  664.       }
  665.       //console.log(this._touchSrollY, TouchInput.touchScroll.y, this._cursorRect.height);

  666.       if (this._touchSrollY >= this.itemHeight()) {
  667.         this.scrollDown();
  668.         this._touchSrollY -= this.itemHeight();
  669.       }
  670.       if (this._touchSrollY <= -this.itemHeight()) {
  671.         this.scrollUp();
  672.         this._touchSrollY += this.itemHeight();
  673.       }
  674.     }
  675.   };

  676.   Window_ShopStatus.prototype.isPageChangeRequested = function() {
  677.     if (Input.isTriggered('shift')) {
  678.       return true;
  679.     }
  680.     if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
  681.       return true;
  682.     }
  683.     return false;
  684.   };

  685.   Window_ShopStatus.prototype.isTouchedInsideFrame = function() {
  686.     var x = this.canvasToLocalX(TouchInput.x);
  687.     var y = this.canvasToLocalY(TouchInput.y);
  688.     return x >= 0 && y >= 0 && x < this.width && y < this.height;
  689.   };

  690.   Game_Player.prototype.triggerTouchActionD1 = function(x1, y1) {
  691.     if ($gameMap.airship().pos(x1, y1)) {
  692.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))  && this.getOnOffVehicle()) {
  693.         return true;
  694.       }
  695.     }
  696.     this.checkEventTriggerHere([0]);
  697.     return $gameMap.setupStartingEvent();
  698.   };

  699.   Game_Player.prototype.triggerTouchActionD2 = function(x2, y2) {
  700.     if ($gameMap.boat().pos(x2, y2) || $gameMap.ship().pos(x2, y2)) {
  701.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) && this.getOnVehicle()) {
  702.         return true;
  703.       }
  704.     }
  705.     if (this.isInBoat() || this.isInShip()) {
  706.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))  && this.getOffVehicle()) {
  707.         return true;
  708.       }
  709.     }
  710.     this.checkEventTriggerThere([0, 1, 2]);
  711.     return $gameMap.setupStartingEvent();
  712.   };

  713.   Game_Player.prototype.triggerTouchActionD3 = function(x2, y2) {
  714.     if ($gameMap.isCounter(x2, y2)) {
  715.       this.checkEventTriggerThere([0, 1, 2]);
  716.     }
  717.     return $gameMap.setupStartingEvent();
  718.   };

  719.   // Scene_Map.prototype.isFastForward = function() {
  720.   //   return ($gameMap.isEventRunning() && !SceneManager.isSceneChanging() &&
  721.   //     (Input.isLongPressed('ok') || TouchInput.isLongPressed()));
  722.   // };

  723.   Scene_Map.prototype.processMapTouch = function() {
  724.     if (TouchInput.judgeLongPressed("left", 15) || TouchInput.judgeLongPressed("touch", 15) || TouchInput.judgeLongPressed("right", 15)) {
  725.       var x = $gameMap.canvasToMapX(TouchInput.x);
  726.       var y = $gameMap.canvasToMapY(TouchInput.y);
  727.       $gameTemp.setPressedDest(x, y);
  728.       $gameTemp.clearDestination();
  729.     } else if ($gameTemp.isPressedDestValid() && (!TouchInput.judgePressed("left") || !TouchInput.judgePressed("touch") || !TouchInput.judgePressed("right"))) {
  730.       $gameTemp.clearPressedDest();
  731.     } else if (TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) {
  732.       var x = $gameMap.canvasToMapX(TouchInput.x);
  733.       var y = $gameMap.canvasToMapY(TouchInput.y);
  734.       $gameTemp.setDestination(x, y);
  735.     }
  736.   };

  737.   Scene_Gameover.prototype.isTriggered = function() {
  738.     return Input.isTriggered('ok') || TouchInput.isTriggered();
  739.   };

  740.   Game_Player.prototype.moveByInput = function() {
  741.     if (!this.isMoving() && this.canMove()) {
  742.       var direction = this.getInputDirection();
  743.       if (direction > 0) {
  744.         $gameTemp.clearDestination();
  745.       } else if ($gameTemp.isDestinationValid()) {
  746.         var x = $gameTemp.destinationX();
  747.         var y = $gameTemp.destinationY();
  748.         direction = this.findDirectionTo(x, y);
  749.       } else if ($gameTemp.isPressedDestValid()) {
  750.         var x = $gameTemp._pressedDestX;
  751.         var y = $gameTemp._pressedDestY;
  752.         direction = this.findDirectionTo(x, y);
  753.       }
  754.       if (direction > 0) {
  755.         this.executeMove(direction);
  756.       }
  757.     }
  758.   };

  759.   Game_Temp.prototype.setPressedDest = function(x, y) {
  760.     this._pressedDestX = x;
  761.     this._pressedDestY = y;
  762.   }


  763.   Game_Temp.prototype.clearPressedDest = function() {
  764.     this._pressedDestX = null;
  765.     this._pressedDestY = null;
  766.   }


  767.   Game_Temp.prototype.isPressedDestValid = function() {
  768.     if (this._pressedDestX === null || this._pressedDestX === undefined) {
  769.       return false;
  770.     }
  771.     return true;
  772.   }

  773.   Game_Temp.prototype.isPressedDestFar = function() {
  774.     if (!this.isPressedDestValid()) {
  775.       return false;
  776.     }
  777.     if (distanceOfTwoPoints($gamePlayer.x, $gamePlayer.y, this._pressedDestX, this._pressedDestY) >= 3) {
  778.       return true;
  779.     }
  780.     return false;
  781.   }

  782.   Game_Player.prototype.findPressedDestDirection = function(x, y) {
  783.     if (this.x === x && this.y === y) {
  784.       return 0;
  785.     }
  786.     var deltaX = this.x - x;
  787.     var deltaY = this.y - y;
  788.     if (Math.abs(deltaX) > Math.abs(deltaY)) {
  789.       if (deltaX > 0) {
  790.         return 4;
  791.       } else {
  792.         return 6;
  793.       }
  794.     } else {
  795.       if (deltaY > 0) {
  796.         return 8;
  797.       } else {
  798.         return 2;
  799.       }
  800.     }
  801.   }

  802.   Game_Player.prototype.updateDashing = function() {
  803.     if (this.isMoving()) {
  804.       return;
  805.     }
  806.     if (this.canMove() && !this.isInVehicle() && !$gameMap.isDashDisabled()) {
  807.       this._dashing = this.isDashButtonPressed() || $gameTemp.isDestinationValid() || $gameTemp.isPressedDestFar();
  808.     } else {
  809.       this._dashing = false;
  810.     }
  811.   };
  812.   if (Imported.YEP_BattleEngineCore) {
  813.     Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
  814.       if (!enemy) return false;
  815.       if (!enemy.isSpriteVisible()) return false;
  816.       var x = TouchInput.x;
  817.       var y = TouchInput.y;
  818.       var rect = new Rectangle();
  819.       rect.width = enemy.spriteWidth();
  820.       rect.height = enemy.spriteHeight();
  821.       rect.x = enemy.spritePosX() - rect.width / 2;
  822.       rect.y = enemy.spritePosY() - rect.height;
  823.       return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  824.         y < rect.y + rect.height);
  825.     };
  826.   }


  827.   // Yanfly.BEC.Window_BattleActor_processTouch =
  828.   //   Window_BattleActor.prototype.processTouch;
  829.   // Window_BattleActor.prototype.processTouch = function() {
  830.   //   if (eval(Yanfly.Param.BECActorSelect) && this.isOpenAndActive()) {
  831.   //     if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  832.   //       if (this.getClickedActor() >= 0) {
  833.   //         var index = this.getClickedActor();
  834.   //         if (this.index() === index) {
  835.   //           return this.processOk();
  836.   //         } else {
  837.   //           SoundManager.playCursor();
  838.   //           return this.select(index);
  839.   //         }
  840.   //       }
  841.   //     }
  842.   //     if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  843.   //       if (this.getClickedActor() >= 0) {
  844.   //         var index = this.getClickedActor();
  845.   //         if (this.index() !== index) {
  846.   //           SoundManager.playCursor();
  847.   //           return this.select(index);
  848.   //         }
  849.   //       }
  850.   //     }
  851.   //     if (Yanfly.Param.BECSelectMouseOver) {
  852.   //       var index = this.getMouseOverActor();
  853.   //       if (index >= 0 && this.index() !== index) {
  854.   //         SoundManager.playCursor();
  855.   //         return this.select(index);
  856.   //       }
  857.   //     }
  858.   //   }
  859.   //   Yanfly.BEC.Window_BattleActor_processTouch.call(this);
  860.   // };
  861.   //
  862.   // Window_BattleActor.prototype.isClickedActor = function(actor) {
  863.   //   if (!actor) return false;
  864.   //   if (!actor.isSpriteVisible()) return false;
  865.   //   if (!actor.isAppeared()) return false;
  866.   //   var x = TouchInput.x;
  867.   //   var y = TouchInput.y;
  868.   //   var rect = new Rectangle();
  869.   //   rect.width = actor.spriteWidth();
  870.   //   rect.height = actor.spriteHeight();
  871.   //   rect.x = actor.spritePosX() - rect.width / 2;
  872.   //   rect.y = actor.spritePosY() - rect.height;
  873.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  874.   //     y < rect.y + rect.height);
  875.   // };
  876.   //
  877.   // Window_BattleActor.prototype.isMouseOverActor = function(actor) {
  878.   //   if (!actor) return false;
  879.   //   if (!actor.isSpriteVisible()) return false;
  880.   //   if (!actor.isAppeared()) return false;
  881.   //   var x = TouchInput._mouseOverX;
  882.   //   var y = TouchInput._mouseOverY;
  883.   //   var rect = new Rectangle();
  884.   //   rect.width = actor.spriteWidth();
  885.   //   rect.height = actor.spriteHeight();
  886.   //   rect.x = actor.spritePosX() - rect.width / 2;
  887.   //   rect.y = actor.spritePosY() - rect.height;
  888.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  889.   //     y < rect.y + rect.height);
  890.   // };
  891.   //
  892.   // Yanfly.BEC.Window_BattleEnemy_processTouch =
  893.   //   Window_BattleEnemy.prototype.processTouch;
  894.   // Window_BattleEnemy.prototype.processTouch = function() {
  895.   //   if (eval(Yanfly.Param.BECEnemySelect) && this.isOpenAndActive()) {
  896.   //     if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  897.   //       if (this.getClickedEnemy() >= 0) {
  898.   //         var index = this.getClickedEnemy();
  899.   //         if (this.index() === index) {
  900.   //           return this.processOk();
  901.   //         } else {
  902.   //           SoundManager.playCursor();
  903.   //           return this.select(index);
  904.   //         }
  905.   //       }
  906.   //     }
  907.   //     if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  908.   //       if (this.getClickedEnemy() >= 0) {
  909.   //         var index = this.getClickedEnemy();
  910.   //         if (this.index() !== index) {
  911.   //           SoundManager.playCursor();
  912.   //           return this.select(index);
  913.   //         }
  914.   //       }
  915.   //     }
  916.   //     if (Yanfly.Param.BECSelectMouseOver) {
  917.   //       var index = this.getMouseOverEnemy();
  918.   //       if (index >= 0 && this.index() !== index) {
  919.   //         SoundManager.playCursor();
  920.   //         return this.select(index);
  921.   //       }
  922.   //     }
  923.   //   };
  924.   //   Yanfly.BEC.Window_BattleEnemy_processTouch.call(this);
  925.   // };
  926.   //
  927.   // Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
  928.   //   if (!enemy) return false;
  929.   //   if (!enemy.isSpriteVisible()) return false;
  930.   //   var x = TouchInput.x;
  931.   //   var y = TouchInput.y;
  932.   //   var rect = new Rectangle();
  933.   //   rect.width = enemy.spriteWidth();
  934.   //   rect.height = enemy.spriteHeight();
  935.   //   rect.x = enemy.spritePosX() - rect.width / 2;
  936.   //   rect.y = enemy.spritePosY() - rect.height;
  937.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  938.   //     y < rect.y + rect.height);
  939.   // };
  940.   //
  941.   // Window_BattleEnemy.prototype.getMouseOverEnemy = function() {
  942.   //   for (var i = 0; i < this._enemies.length; ++i) {
  943.   //     var enemy = this._enemies[i];
  944.   //     if (!enemy) continue;
  945.   //     if (this.isClickedEnemy(enemy)) {
  946.   //       if (this._selectDead && !enemy.isDead()) continue;
  947.   //       var index = this._enemies.indexOf(enemy)
  948.   //       if (this._inputLock && index !== this.index()) continue;
  949.   //       return index;
  950.   //     }
  951.   //   }
  952.   //   return -1;
  953.   // };
  954. })(TWDP.TEE);
复制代码

评分

参与人数 3星屑 +160 梦石 +1 收起 理由
v2sam + 100 要的就是这个
余烬之中 + 1 原创发布
king + 60 精品

查看全部评分

吸吸
梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2016-1-7 21:08:03 | 显示全部楼层
支持,好东西
回复

使用道具 举报

梦石
0
星屑
60
在线时间
306 小时
注册时间
2014-8-5
回帖
403
发表于 2016-1-7 21:41:08 | 显示全部楼层
very good !
回复

使用道具 举报

笑问情缘

梦石
0
星屑
68
在线时间
238 小时
注册时间
2006-5-3
回帖
544
发表于 2016-1-8 18:40:38 来自手机 | 显示全部楼层
求给个下载链接,手机不方便
回复

使用道具 举报

梦石
0
星屑
50
在线时间
55 小时
注册时间
2013-11-24
回帖
21
发表于 2016-1-9 09:43:57 | 显示全部楼层
感谢楼主的分享,我已收藏!~~~
回复

使用道具 举报

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
回帖
780
发表于 2016-1-9 10:27:09 | 显示全部楼层
要不要考虑分功能独立插件?还是核心函数都重写了?

点评

主要是改了Scene_Map Game_Temp Window_Selectable 分开来就没什么用了  发表于 2016-1-9 17:21
回复

使用道具 举报

梦石
0
星屑
29220
在线时间
1535 小时
注册时间
2006-1-10
回帖
1898

开拓者第一届地图绘制大赛RTP组第四名

发表于 2016-1-15 20:17:48 | 显示全部楼层
测试: 交通工具 点击无效     期待修复
交通工具点击都无效,只能用按键

我把这脚本关闭后,点击交通工具就有效果,正常!

点评

哎呀 我把交通工具忘了 我看看  发表于 2016-1-15 23:34
MV帮助 http://miaowm5.github.io/RMMV-F1/日复一日,年复一年人还是保留一点自我兴趣的好啊~~~忘记过去 ,这样我就可以  放弃未来了……哭~~终于找回以前的头像了,哎~~原来我是那么的想念阿……
画地图没灵感?很烦?很无聊 【 戳 我 】一 大 波 地 图 在 等 你  \^0^/
我的游戏
回复

使用道具 举报

梦石
0
星屑
90
在线时间
387 小时
注册时间
2007-7-27
回帖
4075

开拓者

 楼主| 发表于 2016-1-16 00:15:11 | 显示全部楼层
king 发表于 2016-1-15 20:17
测试: 交通工具 点击无效     期待修复
交通工具点击都无效,只能用按键


更新了,把判断改成了单击,和原来的差不多

点评

谢谢!我待会更新工程!  发表于 2016-1-16 00:18
吸吸
回复

使用道具 举报

梦石
0
星屑
137
在线时间
18 小时
注册时间
2013-2-11
回帖
13
发表于 2016-1-18 00:36:11 | 显示全部楼层
先收藏了,残念一直未找到中文素材打包的方法...
回复

使用道具 举报

世界坑化协会

梦石
0
星屑
9600
在线时间
1594 小时
注册时间
2007-3-13
回帖
5265

极短26参与极短25参与极短23参与极短21参与开拓者贵宾第一届化妆舞会最佳服饰奖

发表于 2016-1-18 09:56:48 | 显示全部楼层
终于可以点哪开哪了,先马克,最近没空弄工程
忍卷NINMAKI游戏DEMO上线了~♪  点我下载  ☚
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部