设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 6585|回复: 9
打印 上一主题 下一主题

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
65
在线时间
385 小时
注册时间
2007-7-27
帖子
4106

开拓者

跳转到指定楼层
1
发表于 2016-1-7 21:01:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

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

实现功能:
1 鼠标: 将判定点从按下改为单击(按下再弹起)
2 鼠标: 修改移动事件的判定
3 鼠标: 选择窗口鼠标滑动改变选项,点击即是确认
4 鼠标: 地图上,点击鼠标表示移动到点,会触发事件。长按鼠标表示向点移动,不会触发事件和目的地闪动的动画。鼠标和人物距离远会变为跑动。
5 触摸: 将判定点从按下改为单击
6 触摸: 增加向左快速滑动手势,表示返回
7 触摸: 修正YEP战斗导致chrome触摸无法选中敌人的问题
8 触摸: 选择窗口取消按住拖动改变当前选项,改为按住拖动滑动页面,点击既是确认
9 触摸: 地图上,单击手指是移动到点,会触发时间,按住手指表示向点移动,不会触发事件。手指和人物距离远会变为跑动。
JAVASCRIPT 代码复制下载
  1. //=============================================================================
  2. // Trentswd Plugins - Touch Event Extend
  3. // TWDP_TouchEventEx.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.TWDP_TouchEventEx = true;
  8.  
  9. var TWDP = TWDP || {};
  10. TWDP.TEE = TWDP.TEE || {};
  11.  
  12. //=============================================================================
  13. /*:
  14.  * @plugindesc v1.00 Extend the Touch Event
  15.  * @author Trentswd
  16.  *
  17.  * @help
  18.  * ============================================================================
  19.  * Introduction
  20.  * ============================================================================
  21.  *
  22.  * Don't have time to write this right now, sorry.
  23.  *
  24.  * ============================================================================
  25.  * Plugin Commands
  26.  * ============================================================================
  27.  *
  28.  * Don't have time to write this right now, sorry.
  29.  *
  30.  */
  31. //=============================================================================
  32.  
  33. //=============================================================================
  34. // Parameter Variables
  35. //=============================================================================
  36.  
  37. TWDP.parameters = PluginManager.parameters('TWDP_TouchEventEx');
  38. TWDP.TEE.param = TWDP.TEE.param || {};
  39.  
  40. function distanceOfTwoPoints(x1, y1, x2, y2) {
  41.   return Math.round(
  42.     Math.sqrt(
  43.       Math.pow(x1 - x2, 2) +
  44.       Math.pow(y1 - y2, 2)
  45.     )
  46.   );
  47. };
  48.  
  49. (function($) {
  50.  
  51.   $.backup = $.backup || {};
  52.   //-----------------------------------------------------------------------------
  53.   /**
  54.    * The static class that handles input data from the mouse and touchscreen.
  55.    *
  56.    * @class TouchInput
  57.    */
  58.  
  59.   TouchInput.clickDelta = 5;
  60.   TouchInput.backGestureSpeedThreshold = 30;
  61.   TouchInput.backGestureDistanceThreshold = 20;
  62.  
  63.   /**
  64.    * Initializes the touch system.
  65.    *
  66.    * @static
  67.    * @method initialize
  68.    */
  69.   TouchInput.initialize = function() {
  70.     this.clear();
  71.     this._setupEventHandlers();
  72.   };
  73.  
  74.   /**
  75.    * The wait time of the pseudo key repeat in frames.
  76.    *
  77.    * @static
  78.    * @property keyRepeatWait
  79.    * @type Number
  80.    */
  81.   TouchInput.keyRepeatWait = 24;
  82.  
  83.   /**
  84.    * The interval of the pseudo key repeat in frames.
  85.    *
  86.    * @static
  87.    * @property keyRepeatInterval
  88.    * @type Number
  89.    */
  90.   TouchInput.keyRepeatInterval = 6;
  91.  
  92.   /**
  93.    * Clears all the touch data.
  94.    *
  95.    * @static
  96.    * @method clear
  97.    */
  98.   $.backup.TouchInput_clear = TouchInput.clear;
  99.   TouchInput.clear = function() {
  100.       $.backup.TouchInput_clear.call(this);
  101.  
  102.  
  103.       this._pressed = {};
  104.       this._pressed.left = {};
  105.       this._pressed.left.isPressed = false;
  106.       this._pressed.left.pressX = 0;
  107.       this._pressed.left.pressY = 0;
  108.       this._pressed.right = {};
  109.       this._pressed.right.isPressed = false;
  110.       this._pressed.right.pressX = 0;
  111.       this._pressed.right.pressY = 0;
  112.       this._pressed.middle = {};
  113.       this._pressed.middle.isPressed = false;
  114.       this._pressed.middle.pressX = 0;
  115.       this._pressed.middle.pressY = 0;
  116.       this._pressed.touch = {};
  117.       this._pressed.touch.isPressed = false;
  118.       this._pressed.touch.pressX = 0;
  119.       this._pressed.touch.pressY = 0;
  120.  
  121.       this._clicked = {};
  122.       this._clicked.left = {};
  123.       this._clicked.left.isClicked = false;
  124.       this._clicked.left.x = 0;
  125.       this._clicked.left.y = 0;
  126.       this._clicked.right = {};
  127.       this._clicked.right.isClicked = false;
  128.       this._clicked.right.x = 0;
  129.       this._clicked.right.y = 0;
  130.       this._clicked.middle = {};
  131.       this._clicked.middle.isClicked = false;
  132.       this._clicked.middle.x = 0;
  133.       this._clicked.middle.y = 0;
  134.       this._clicked.touch = {};
  135.       this._clicked.touch.isClicked = false;
  136.       this._clicked.touch.x = 0;
  137.       this._clicked.touch.y = 0;
  138.  
  139.       this._pressed.left.time = 0;
  140.       this._pressed.right.time = 0;
  141.       this._pressed.middle.time = 0;
  142.       this._pressed.touch.time = 0;
  143.  
  144.  
  145.       this._events._clicked = {};
  146.       this._events._clicked.left = {};
  147.       this._events._clicked.left.isClicked = false;
  148.       this._events._clicked.left.x = 0;
  149.       this._events._clicked.left.y = 0;
  150.       this._events._clicked.right = {};
  151.       this._events._clicked.right.isClicked = false;
  152.       this._events._clicked.right.x = 0;
  153.       this._events._clicked.right.y = 0;
  154.       this._events._clicked.middle = {};
  155.       this._events._clicked.middle.isClicked = false;
  156.       this._events._clicked.middle.x = 0;
  157.       this._events._clicked.middle.y = 0;
  158.       this._events._clicked.touch = {};
  159.       this._events._clicked.touch.isClicked = false;
  160.       this._events._clicked.touch.x = 0;
  161.       this._events._clicked.touch.y = 0;
  162.  
  163.       this._events._pressed = {};
  164.       this._events._pressed.left = {};
  165.       this._events._pressed.left.isPressed = false;
  166.       this._events._pressed.left.pressX = 0;
  167.       this._events._pressed.left.pressY = 0;
  168.       this._events._pressed.right = {};
  169.       this._events._pressed.right.isPressed = false;
  170.       this._events._pressed.right.pressX = 0;
  171.       this._events._pressed.right.pressY = 0;
  172.       this._events._pressed.middle = {};
  173.       this._events._pressed.middle.isPressed = false;
  174.       this._events._pressed.middle.pressX = 0;
  175.       this._events._pressed.middle.pressY = 0;
  176.       this._events._pressed.touch = {};
  177.       this._events._pressed.touch.isPressed = false;
  178.       this._events._pressed.touch.pressX = 0;
  179.       this._events._pressed.touch.pressY = 0;
  180.  
  181.       this.touchScroll = {};
  182.       this.touchScroll.x = 0;
  183.       this.touchScroll.y = 0;
  184.       this._events.touchScroll = {};
  185.       this._events.touchScroll.x = 0;
  186.       this._events.touchScroll.y = 0;
  187.     }
  188.     /**
  189.      * Updates the touch data.
  190.      *
  191.      * @static
  192.      * @method update
  193.      */
  194.   $.backup.TouchInput_update = TouchInput.update;
  195.   TouchInput.update = function() {
  196.     $.backup.TouchInput_update.call(this);
  197.  
  198.  
  199.     this._pressed.left.isPressed = this._events._pressed.left.isPressed;
  200.     this._pressed.left.pressX = this._events._pressed.left.pressX;
  201.     this._pressed.left.pressY = this._events._pressed.left.pressY;
  202.  
  203.     this._pressed.right.isPressed = this._events._pressed.right.isPressed;
  204.     this._pressed.right.pressX = this._events._pressed.right.pressX;
  205.     this._pressed.right.pressY = this._events._pressed.right.pressY;
  206.  
  207.     this._pressed.middle.isPressed = this._events._pressed.middle.isPressed;
  208.     this._pressed.middle.pressX = this._events._pressed.middle.pressX;
  209.     this._pressed.middle.pressY = this._events._pressed.middle.pressY;
  210.  
  211.     this._pressed.touch.isPressed = this._events._pressed.touch.isPressed;
  212.     this._pressed.touch.pressX = this._events._pressed.touch.pressX;
  213.     this._pressed.touch.pressY = this._events._pressed.touch.pressY;
  214.  
  215.     if (this._pressed.left.isPressed) {
  216.       this._pressed.left.time++;
  217.     } else {
  218.       this._pressed.left.time = 0;
  219.     }
  220.     if (this._pressed.right.isPressed) {
  221.       this._pressed.right.time++;
  222.     } else {
  223.       this._pressed.right.time = 0;
  224.     }
  225.     if (this._pressed.middle.isPressed) {
  226.       this._pressed.middle.time++;
  227.     } else {
  228.       this._pressed.middle.time = 0;
  229.     }
  230.     if (this._pressed.touch.isPressed) {
  231.       this._pressed.touch.time++;
  232.     } else {
  233.       this._pressed.touch.time = 0;
  234.     }
  235.  
  236.     this._clicked.left.isClicked = this._events._clicked.left.isClicked;
  237.     this._clicked.left.x = this._events._clicked.left.x;
  238.     this._clicked.left.y = this._events._clicked.left.y;
  239.     this._clicked.right.isClicked = this._events._clicked.right.isClicked;
  240.     this._clicked.right.x = this._events._clicked.right.x;
  241.     this._clicked.right.y = this._events._clicked.right.y;
  242.     this._clicked.middle.isClicked = this._events._clicked.middle.isClicked;
  243.     this._clicked.middle.x = this._events._clicked.middle.x;
  244.     this._clicked.middle.y = this._events._clicked.middle.y;
  245.     this._clicked.touch.isClicked = this._events._clicked.touch.isClicked;
  246.     this._clicked.touch.x = this._events._clicked.touch.x;
  247.     this._clicked.touch.y = this._events._clicked.touch.y;
  248.  
  249.  
  250.     this._events._clicked.left.isClicked = false;
  251.     this._events._clicked.left.x = 0;
  252.     this._events._clicked.left.y = 0;
  253.     this._events._clicked.right.isClicked = false;
  254.     this._events._clicked.right.x = 0;
  255.     this._events._clicked.right.y = 0;
  256.     this._events._clicked.middle.isClicked = false;
  257.     this._events._clicked.middle.x = 0;
  258.     this._events._clicked.middle.y = 0;
  259.     this._events._clicked.touch.isClicked = false;
  260.     this._events._clicked.touch.x = 0;
  261.     this._events._clicked.touch.y = 0;
  262.  
  263.     this.touchScroll.x = this._events.touchScroll.x;
  264.     this.touchScroll.y = this._events.touchScroll.y;
  265.     this._events.touchScroll.x = 0;
  266.     this._events.touchScroll.y = 0;
  267.   };
  268.  
  269.   TouchInput.judgePressed = function(button) {
  270.     return this._pressed[button].isPressed;
  271.   }
  272.  
  273.   TouchInput.judgeClicked = function(button) {
  274.     return this._clicked[button].isClicked;
  275.   }
  276.  
  277.   TouchInput.judgeLongPressed = function(button, time) {
  278.     if (time === undefined) {
  279.       time = this.keyRepeatWait
  280.     }
  281.     if (this.judgePressed(button)) {
  282.       return this._pressed[button].time >= time;
  283.     }
  284.     return false;
  285.   }
  286.  
  287.   /**
  288.    * @static
  289.    * @method _onMouseDown
  290.    * @param {MouseEvent} event
  291.    * @private
  292.    */
  293.   TouchInput._onMouseDown = function(event) {
  294.     if (event.button === 0) {
  295.       this._onLeftButtonDown(event);
  296.     } else if (event.button === 1) {
  297.       this._onMiddleButtonDown(event);
  298.     } else if (event.button === 2) {
  299.       this._onRightButtonDown(event);
  300.     }
  301.     this._date = Date.now();
  302.   };
  303.  
  304.   /**
  305.    * @static
  306.    * @method _onLeftButtonDown
  307.    * @param {MouseEvent} event
  308.    * @private
  309.    */
  310.   TouchInput._onLeftButtonDown = function(event) {
  311.     var x = Graphics.pageToCanvasX(event.pageX);
  312.     var y = Graphics.pageToCanvasY(event.pageY);
  313.     if (Graphics.isInsideCanvas(x, y)) {
  314.       this._mousePressed = true;
  315.       this._pressedTime = 0;
  316.       this._events._pressed.left.isPressed = true;
  317.       this._events._pressed.left.pressX = x;
  318.       this._events._pressed.left.pressY = y;
  319.       this._onTrigger(x, y);
  320.     }
  321.   };
  322.  
  323.   /**
  324.    * @static
  325.    * @method _onMiddleButtonDown
  326.    * @param {MouseEvent} event
  327.    * @private
  328.    */
  329.   TouchInput._onMiddleButtonDown = function(event) {
  330.     var x = Graphics.pageToCanvasX(event.pageX);
  331.     var y = Graphics.pageToCanvasY(event.pageY);
  332.     if (Graphics.isInsideCanvas(x, y)) {
  333.       this._events._pressed.middle.isPressed = true;
  334.       this._events._pressed.middle.pressX = x;
  335.       this._events._pressed.middle.pressY = y;
  336.     }
  337.   };
  338.  
  339.   /**
  340.    * @static
  341.    * @method _onRightButtonDown
  342.    * @param {MouseEvent} event
  343.    * @private
  344.    */
  345.   TouchInput._onRightButtonDown = function(event) {
  346.     var x = Graphics.pageToCanvasX(event.pageX);
  347.     var y = Graphics.pageToCanvasY(event.pageY);
  348.     if (Graphics.isInsideCanvas(x, y)) {
  349.       this._events._pressed.right.isPressed = true;
  350.       this._events._pressed.right.pressX = x;
  351.       this._events._pressed.right.pressY = y;
  352.       //this._onCancel(x, y);
  353.     }
  354.   };
  355.  
  356.   /**
  357.    * @static
  358.    * @method _onMouseMove
  359.    * @param {MouseEvent} event
  360.    * @private
  361.    */
  362.   $.backup.TouchInput_onMouseMove = TouchInput._onMouseMove;
  363.   TouchInput._onMouseMove = function(event) {
  364.     $.backup.TouchInput_onMouseMove.call(this, event);
  365.     var x = Graphics.pageToCanvasX(event.pageX);
  366.     var y = Graphics.pageToCanvasY(event.pageY);
  367.     this._onMove(x, y);
  368.  
  369.   };
  370.  
  371.   TouchInput._onClick = function(x, y, button) {
  372.     if (button === 0) {
  373.       if (this._clicked.left.cancelNext) {
  374.         this._clicked.left.cancelNext = false;
  375.         return;
  376.       }
  377.       this._events._clicked.left.isClicked = true;
  378.       this._events._clicked.left.x = x;
  379.       this._events._clicked.left.y = y;
  380.     } else if (button === 1) {
  381.       if (this._clicked.right.cancelNext) {
  382.         this._clicked.right.cancelNext = false;
  383.         return;
  384.       }
  385.       this._events._clicked.right.isClicked = true;
  386.       this._events._clicked.right.x = x;
  387.       this._events._clicked.right.y = y;
  388.       this._onCancel(x, y);
  389.     } else if (button === 2) {
  390.       if (this._clicked.middle.cancelNext) {
  391.         this._clicked.middle.cancelNext = false;
  392.         return;
  393.       }
  394.       this._events._clicked.middle.isClicked = true;
  395.       this._events._clicked.middle.x = x;
  396.       this._events._clicked.middle.y = y;
  397.     } else if (button === 'touch') {
  398.       if (this._clicked.touch.cancelNext) {
  399.         this._clicked.touch.cancelNext = false;
  400.         return;
  401.       }
  402.       this._events._clicked.touch.isClicked = true;
  403.       this._events._clicked.touch.x = x;
  404.       this._events._clicked.touch.y = y;
  405.     }
  406.   }
  407.  
  408.   TouchInput.cancelNextClick = function(button) {
  409.     this._clicked[button].cancelNext = true;
  410.   }
  411.  
  412.   TouchInput._onLeftButtonUp = function(event) {
  413.     var x = Graphics.pageToCanvasX(event.pageX);
  414.     var y = Graphics.pageToCanvasY(event.pageY);
  415.     if (Graphics.isInsideCanvas(x, y)) {
  416.       this._events._pressed.left.isPressed = false;
  417.       var distance = distanceOfTwoPoints(this._pressed.left.pressX, this._pressed.left.pressY,
  418.         x, y)
  419.       if (distance <= this.clickDelta) {
  420.         this._onClick(x, y, 0);
  421.       }
  422.     }
  423.   };
  424.  
  425.   TouchInput._onMiddleButtonUp = function(event) {
  426.     var x = Graphics.pageToCanvasX(event.pageX);
  427.     var y = Graphics.pageToCanvasY(event.pageY);
  428.     if (Graphics.isInsideCanvas(x, y)) {
  429.       this._events._pressed.middle.isPressed = false;
  430.       if (distanceOfTwoPoints(this._pressed.middle.pressX, this._pressed.middle.pressY,
  431.           x, y) <= this.clickDelta) {
  432.         this._onClick(x, y, 2);
  433.       }
  434.     }
  435.   };
  436.  
  437.   TouchInput._onRightButtonUp = function(event) {
  438.     var x = Graphics.pageToCanvasX(event.pageX);
  439.     var y = Graphics.pageToCanvasY(event.pageY);
  440.     if (Graphics.isInsideCanvas(x, y)) {
  441.       this._events._pressed.right.isPressed = false;
  442.       if (distanceOfTwoPoints(this._pressed.right.pressX, this._pressed.right.pressY,
  443.           x, y) <= this.clickDelta) {
  444.         this._onClick(x, y, 1);
  445.       }
  446.     }
  447.   };
  448.  
  449.   /**
  450.    * @static
  451.    * @method _onMouseUp
  452.    * @param {MouseEvent} event
  453.    * @private
  454.    */
  455.   TouchInput._onMouseUp = function(event) {
  456.     if (event.button === 0) {
  457.       var x = Graphics.pageToCanvasX(event.pageX);
  458.       var y = Graphics.pageToCanvasY(event.pageY);
  459.       this._mousePressed = false;
  460.       this._onRelease(x, y);
  461.     }
  462.  
  463.     if (event.button === 0) {
  464.       this._onLeftButtonUp(event);
  465.     } else if (event.button === 1) {
  466.       this._onMiddleButtonUp(event);
  467.     } else if (event.button === 2) {
  468.       this._onRightButtonUp(event);
  469.     }
  470.   };
  471.  
  472.  
  473.   /**
  474.    * @static
  475.    * @method _onTouchStart
  476.    * @param {TouchEvent} event
  477.    * @private
  478.    */
  479.   TouchInput._onTouchStart = function(event) {
  480.     for (var i = 0; i < event.changedTouches.length; i++) {
  481.       var touch = event.changedTouches[i];
  482.       var x = Graphics.pageToCanvasX(touch.pageX);
  483.       var y = Graphics.pageToCanvasY(touch.pageY);
  484.       if (Graphics.isInsideCanvas(x, y)) {
  485.         this._screenPressed = true;
  486.         this._pressedTime = 0;
  487.         this._events._pressed.touch.isPressed = true;
  488.         this._pressed.touch.time = 0;
  489.         this._events._pressed.touch.pressX = x;
  490.         this._events._pressed.touch.pressY = y;
  491.         if (event.touches.length >= 2) {
  492.           this._onCancel(x, y);
  493.         } else {
  494.           this._onTrigger(x, y);
  495.         }
  496.         event.preventDefault();
  497.       }
  498.     }
  499.     if (window.cordova || window.navigator.standalone) {
  500.       event.preventDefault();
  501.     }
  502.   };
  503.  
  504.   /**
  505.    * @static
  506.    * @method _onTouchMove
  507.    * @param {TouchEvent} event
  508.    * @private
  509.    */
  510.   TouchInput._onTouchMove = function(event) {
  511.     for (var i = 0; i < event.changedTouches.length; i++) {
  512.       var touch = event.changedTouches[i];
  513.       var x = Graphics.pageToCanvasX(touch.pageX);
  514.       var y = Graphics.pageToCanvasY(touch.pageY);
  515.       //this._onMove(x, y);
  516.       this._events.touchScroll.x += x - this._x;
  517.       this._events.touchScroll.y += y - this._y;
  518.       this._x = x;
  519.       this._y = y;
  520.  
  521.     }
  522.   };
  523.  
  524.   /**
  525.    * @static
  526.    * @method _onTouchEnd
  527.    * @param {TouchEvent} event
  528.    * @private
  529.    */
  530.   TouchInput._onTouchEnd = function(event) {
  531.     for (var i = 0; i < event.changedTouches.length; i++) {
  532.       var touch = event.changedTouches[i];
  533.       var x = Graphics.pageToCanvasX(touch.pageX);
  534.       var y = Graphics.pageToCanvasY(touch.pageY);
  535.       this._screenPressed = false;
  536.       this._events._pressed.touch.isPressed = false;
  537.       if (this._judgeBackGestrue(event)) {
  538.         this._onCancel(x, y);
  539.       } else if (distanceOfTwoPoints(this._pressed.touch.pressX, this._pressed.touch.pressY,
  540.           x, y) <= this.clickDelta) {
  541.         this._onClick(x, y, 'touch');
  542.       }
  543.       this._pressed.touch.time = 0;
  544.       this._onRelease(x, y);
  545.     }
  546.   };
  547.  
  548.   TouchInput._judgeBackGestrue = function(event) {
  549.     for (var i = 0; i < event.changedTouches.length; i++) {
  550.       var touch = event.changedTouches[i];
  551.       var x = Graphics.pageToCanvasX(touch.pageX);
  552.       var y = Graphics.pageToCanvasY(touch.pageY);
  553.       var distance = distanceOfTwoPoints(this._pressed.touch.pressX, this._pressed.touch.pressY,
  554.         x, y);
  555.       var time = this._pressed.touch.time;
  556.       //console.log(distance, distance / time, x, this._pressed.touch.pressX);
  557.       if (distance > this.clickDelta && distance / time > this.backGestureSpeedThreshold && x < this._pressed.touch.pressX && distance > TouchInput.backGestureDistanceThreshold) {
  558.         return true;
  559.       }
  560.     }
  561.     return false;
  562.   };
  563.  
  564.   /**
  565.    * @static
  566.    * @method _onTouchCancel
  567.    * @param {TouchEvent} event
  568.    * @private
  569.    */
  570.   TouchInput._onTouchCancel = function(event) {
  571.     this._screenPressed = false;
  572.   };
  573.  
  574.   /**
  575.    * @static
  576.    * @method _onPointerDown
  577.    * @param {PointerEvent} event
  578.    * @private
  579.    */
  580.   TouchInput._onPointerDown = function(event) {
  581.     if (event.pointerType === 'touch' && !event.isPrimary) {
  582.       var x = Graphics.pageToCanvasX(event.pageX);
  583.       var y = Graphics.pageToCanvasY(event.pageY);
  584.       if (Graphics.isInsideCanvas(x, y)) {
  585.         // For Microsoft Edge
  586.         this._onCancel(x, y);
  587.         event.preventDefault();
  588.       }
  589.     }
  590.   };
  591.  
  592.   /**
  593.    * @static
  594.    * @method _onTrigger
  595.    * @param {Number} x
  596.    * @param {Number} y
  597.    * @private
  598.    */
  599.   TouchInput._onTrigger = function(x, y) {
  600.     this._events.triggered = true;
  601.     this._x = x;
  602.     this._y = y;
  603.     this._date = Date.now();
  604.   };
  605.  
  606.   /**
  607.    * @static
  608.    * @method _onCancel
  609.    * @param {Number} x
  610.    * @param {Number} y
  611.    * @private
  612.    */
  613.   TouchInput._onCancel = function(x, y) {
  614.     this._events.cancelled = true;
  615.     this._x = x;
  616.     this._y = y;
  617.   };
  618.  
  619.   /**
  620.    * @static
  621.    * @method _onMove
  622.    * @param {Number} x
  623.    * @param {Number} y
  624.    * @private
  625.    */
  626.   TouchInput._onMove = function(x, y) {
  627.     this._events.moved = true;
  628.     this._x = x;
  629.     this._y = y;
  630.   };
  631.  
  632.   /**
  633.    * @static
  634.    * @method _onRelease
  635.    * @param {Number} x
  636.    * @param {Number} y
  637.    * @private
  638.    */
  639.   TouchInput._onRelease = function(x, y) {
  640.     this._events.released = true;
  641.     this._x = x;
  642.     this._y = y;
  643.   };
  644.  
  645.   Window_Selectable.prototype.processTouch = function() {
  646.     if (this.isOpenAndActive()) {
  647.       if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
  648.         //this._touching = true;
  649.       } else if ((TouchInput.judgeClicked("left")) && this.isTouchedInsideFrame()) {
  650.         this.onTouch(false);
  651.         this.onTouch(true);
  652.       } else if (TouchInput.judgeClicked("touch") && this.isTouchedInsideFrame()) {
  653.         this.onTouch(false);
  654.         this.onTouch(true);
  655.       } else if (TouchInput.isCancelled()) {
  656.         if (this.isCancelEnabled()) {
  657.           this.processCancel();
  658.         }
  659.       }
  660.       if (this._touching) {
  661.         if (TouchInput.isPressed()) {
  662.           this.onTouch(false);
  663.         } else {
  664.           this._touching = false;
  665.         }
  666.       }
  667.  
  668.       if (TouchInput.isMoved() && this.isTouchedInsideContents()) {
  669.         this.onTouch(false);
  670.       }
  671.     } else {
  672.       this._touching = false;
  673.     }
  674.   };
  675.  
  676.   Window_Selectable.prototype.onTouch = function(triggered) {
  677.     var lastIndex = this.index();
  678.     var x = this.canvasToLocalX(TouchInput.x);
  679.     var y = this.canvasToLocalY(TouchInput.y);
  680.     var hitIndex = this.hitTest(x, y);
  681.     if (hitIndex >= 0) {
  682.       if (hitIndex === this.index()) {
  683.         if (triggered && this.isTouchOkEnabled()) {
  684.           this.processOk();
  685.         }
  686.       } else if (this.isCursorMovable()) {
  687.         this.select(hitIndex);
  688.         if (triggered && this.isTouchOkEnabled()) {
  689.           this.processOk();
  690.         }
  691.       }
  692.     } else if (this._stayCount >= 10) {
  693.       if (y < this.padding) {
  694.         this.cursorUp();
  695.       } else if (y >= this.height - this.padding) {
  696.         this.cursorDown();
  697.       }
  698.     }
  699.     if (this.index() !== lastIndex && triggered) {
  700.       SoundManager.playCursor();
  701.     }
  702.   };
  703.  
  704.   Window_Selectable.prototype.isTouchedInsideContents = function() {
  705.     var x = this.canvasToLocalX(TouchInput.x);
  706.     var y = this.canvasToLocalY(TouchInput.y);
  707.     if (Imported.TWDP_BaseWindowEx) {
  708.       return x >= this.paddingLeft() && y >= this.paddingTop() && x < this.width - this.paddingLeft() - this.paddingRight() && y < this.height - this.paddingTop() - this.paddingBottom();
  709.     } else {
  710.       return x >= this.padding && y >= this.padding && x < this.width - this.padding * 2 && y < this.height - this.padding * 2;
  711.     }
  712.  
  713.   };
  714.  
  715.   $.backup.Window_Selectable_processWheel = Window_Selectable.prototype.processWheel;
  716.   Window_Selectable.prototype.processWheel = function() {
  717.     $.backup.Window_Selectable_processWheel.call(this);
  718.     if (this._touchSrollY === undefined) {
  719.       this._touchSrollY = 0;
  720.     }
  721.     if (this.isOpenAndActive()) {
  722.       if (TouchInput.judgePressed('touch')) {
  723.         if (this._touchSrollY * TouchInput.touchScroll.y < 0) {
  724.           this._touchSrollY = 0;
  725.         }
  726.         this._touchSrollY += TouchInput.touchScroll.y;
  727.       } else {
  728.         this._touchSrollY = 0;
  729.       }
  730.       //console.log(this._touchSrollY, TouchInput.touchScroll.y, this._cursorRect.height);
  731.  
  732.       if (this._touchSrollY >= this.itemHeight()) {
  733.         this.scrollDown();
  734.         this._touchSrollY -= this.itemHeight();
  735.       }
  736.       if (this._touchSrollY <= -this.itemHeight()) {
  737.         this.scrollUp();
  738.         this._touchSrollY += this.itemHeight();
  739.       }
  740.     }
  741.   };
  742.  
  743.   Window_ShopStatus.prototype.isPageChangeRequested = function() {
  744.     if (Input.isTriggered('shift')) {
  745.       return true;
  746.     }
  747.     if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
  748.       return true;
  749.     }
  750.     return false;
  751.   };
  752.  
  753.   Window_ShopStatus.prototype.isTouchedInsideFrame = function() {
  754.     var x = this.canvasToLocalX(TouchInput.x);
  755.     var y = this.canvasToLocalY(TouchInput.y);
  756.     return x >= 0 && y >= 0 && x < this.width && y < this.height;
  757.   };
  758.  
  759.   Game_Player.prototype.triggerTouchActionD1 = function(x1, y1) {
  760.     if ($gameMap.airship().pos(x1, y1)) {
  761.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))  && this.getOnOffVehicle()) {
  762.         return true;
  763.       }
  764.     }
  765.     this.checkEventTriggerHere([0]);
  766.     return $gameMap.setupStartingEvent();
  767.   };
  768.  
  769.   Game_Player.prototype.triggerTouchActionD2 = function(x2, y2) {
  770.     if ($gameMap.boat().pos(x2, y2) || $gameMap.ship().pos(x2, y2)) {
  771.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) && this.getOnVehicle()) {
  772.         return true;
  773.       }
  774.     }
  775.     if (this.isInBoat() || this.isInShip()) {
  776.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))  && this.getOffVehicle()) {
  777.         return true;
  778.       }
  779.     }
  780.     this.checkEventTriggerThere([0, 1, 2]);
  781.     return $gameMap.setupStartingEvent();
  782.   };
  783.  
  784.   Game_Player.prototype.triggerTouchActionD3 = function(x2, y2) {
  785.     if ($gameMap.isCounter(x2, y2)) {
  786.       this.checkEventTriggerThere([0, 1, 2]);
  787.     }
  788.     return $gameMap.setupStartingEvent();
  789.   };
  790.  
  791.   // Scene_Map.prototype.isFastForward = function() {
  792.   //   return ($gameMap.isEventRunning() && !SceneManager.isSceneChanging() &&
  793.   //     (Input.isLongPressed('ok') || TouchInput.isLongPressed()));
  794.   // };
  795.  
  796.   Scene_Map.prototype.processMapTouch = function() {
  797.     if (TouchInput.judgeLongPressed("left", 15) || TouchInput.judgeLongPressed("touch", 15) || TouchInput.judgeLongPressed("right", 15)) {
  798.       var x = $gameMap.canvasToMapX(TouchInput.x);
  799.       var y = $gameMap.canvasToMapY(TouchInput.y);
  800.       $gameTemp.setPressedDest(x, y);
  801.       $gameTemp.clearDestination();
  802.     } else if ($gameTemp.isPressedDestValid() && (!TouchInput.judgePressed("left") || !TouchInput.judgePressed("touch") || !TouchInput.judgePressed("right"))) {
  803.       $gameTemp.clearPressedDest();
  804.     } else if (TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) {
  805.       var x = $gameMap.canvasToMapX(TouchInput.x);
  806.       var y = $gameMap.canvasToMapY(TouchInput.y);
  807.       $gameTemp.setDestination(x, y);
  808.     }
  809.   };
  810.  
  811.   Scene_Gameover.prototype.isTriggered = function() {
  812.     return Input.isTriggered('ok') || TouchInput.isTriggered();
  813.   };
  814.  
  815.   Game_Player.prototype.moveByInput = function() {
  816.     if (!this.isMoving() && this.canMove()) {
  817.       var direction = this.getInputDirection();
  818.       if (direction > 0) {
  819.         $gameTemp.clearDestination();
  820.       } else if ($gameTemp.isDestinationValid()) {
  821.         var x = $gameTemp.destinationX();
  822.         var y = $gameTemp.destinationY();
  823.         direction = this.findDirectionTo(x, y);
  824.       } else if ($gameTemp.isPressedDestValid()) {
  825.         var x = $gameTemp._pressedDestX;
  826.         var y = $gameTemp._pressedDestY;
  827.         direction = this.findDirectionTo(x, y);
  828.       }
  829.       if (direction > 0) {
  830.         this.executeMove(direction);
  831.       }
  832.     }
  833.   };
  834.  
  835.   Game_Temp.prototype.setPressedDest = function(x, y) {
  836.     this._pressedDestX = x;
  837.     this._pressedDestY = y;
  838.   }
  839.  
  840.  
  841.   Game_Temp.prototype.clearPressedDest = function() {
  842.     this._pressedDestX = null;
  843.     this._pressedDestY = null;
  844.   }
  845.  
  846.  
  847.   Game_Temp.prototype.isPressedDestValid = function() {
  848.     if (this._pressedDestX === null || this._pressedDestX === undefined) {
  849.       return false;
  850.     }
  851.     return true;
  852.   }
  853.  
  854.   Game_Temp.prototype.isPressedDestFar = function() {
  855.     if (!this.isPressedDestValid()) {
  856.       return false;
  857.     }
  858.     if (distanceOfTwoPoints($gamePlayer.x, $gamePlayer.y, this._pressedDestX, this._pressedDestY) >= 3) {
  859.       return true;
  860.     }
  861.     return false;
  862.   }
  863.  
  864.   Game_Player.prototype.findPressedDestDirection = function(x, y) {
  865.     if (this.x === x && this.y === y) {
  866.       return 0;
  867.     }
  868.     var deltaX = this.x - x;
  869.     var deltaY = this.y - y;
  870.     if (Math.abs(deltaX) > Math.abs(deltaY)) {
  871.       if (deltaX > 0) {
  872.         return 4;
  873.       } else {
  874.         return 6;
  875.       }
  876.     } else {
  877.       if (deltaY > 0) {
  878.         return 8;
  879.       } else {
  880.         return 2;
  881.       }
  882.     }
  883.   }
  884.  
  885.   Game_Player.prototype.updateDashing = function() {
  886.     if (this.isMoving()) {
  887.       return;
  888.     }
  889.     if (this.canMove() && !this.isInVehicle() && !$gameMap.isDashDisabled()) {
  890.       this._dashing = this.isDashButtonPressed() || $gameTemp.isDestinationValid() || $gameTemp.isPressedDestFar();
  891.     } else {
  892.       this._dashing = false;
  893.     }
  894.   };
  895.   if (Imported.YEP_BattleEngineCore) {
  896.     Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
  897.       if (!enemy) return false;
  898.       if (!enemy.isSpriteVisible()) return false;
  899.       var x = TouchInput.x;
  900.       var y = TouchInput.y;
  901.       var rect = new Rectangle();
  902.       rect.width = enemy.spriteWidth();
  903.       rect.height = enemy.spriteHeight();
  904.       rect.x = enemy.spritePosX() - rect.width / 2;
  905.       rect.y = enemy.spritePosY() - rect.height;
  906.       return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  907.         y < rect.y + rect.height);
  908.     };
  909.   }
  910.  
  911.  
  912.   // Yanfly.BEC.Window_BattleActor_processTouch =
  913.   //   Window_BattleActor.prototype.processTouch;
  914.   // Window_BattleActor.prototype.processTouch = function() {
  915.   //   if (eval(Yanfly.Param.BECActorSelect) && this.isOpenAndActive()) {
  916.   //     if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  917.   //       if (this.getClickedActor() >= 0) {
  918.   //         var index = this.getClickedActor();
  919.   //         if (this.index() === index) {
  920.   //           return this.processOk();
  921.   //         } else {
  922.   //           SoundManager.playCursor();
  923.   //           return this.select(index);
  924.   //         }
  925.   //       }
  926.   //     }
  927.   //     if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  928.   //       if (this.getClickedActor() >= 0) {
  929.   //         var index = this.getClickedActor();
  930.   //         if (this.index() !== index) {
  931.   //           SoundManager.playCursor();
  932.   //           return this.select(index);
  933.   //         }
  934.   //       }
  935.   //     }
  936.   //     if (Yanfly.Param.BECSelectMouseOver) {
  937.   //       var index = this.getMouseOverActor();
  938.   //       if (index >= 0 && this.index() !== index) {
  939.   //         SoundManager.playCursor();
  940.   //         return this.select(index);
  941.   //       }
  942.   //     }
  943.   //   }
  944.   //   Yanfly.BEC.Window_BattleActor_processTouch.call(this);
  945.   // };
  946.   //
  947.   // Window_BattleActor.prototype.isClickedActor = function(actor) {
  948.   //   if (!actor) return false;
  949.   //   if (!actor.isSpriteVisible()) return false;
  950.   //   if (!actor.isAppeared()) return false;
  951.   //   var x = TouchInput.x;
  952.   //   var y = TouchInput.y;
  953.   //   var rect = new Rectangle();
  954.   //   rect.width = actor.spriteWidth();
  955.   //   rect.height = actor.spriteHeight();
  956.   //   rect.x = actor.spritePosX() - rect.width / 2;
  957.   //   rect.y = actor.spritePosY() - rect.height;
  958.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  959.   //     y < rect.y + rect.height);
  960.   // };
  961.   //
  962.   // Window_BattleActor.prototype.isMouseOverActor = function(actor) {
  963.   //   if (!actor) return false;
  964.   //   if (!actor.isSpriteVisible()) return false;
  965.   //   if (!actor.isAppeared()) return false;
  966.   //   var x = TouchInput._mouseOverX;
  967.   //   var y = TouchInput._mouseOverY;
  968.   //   var rect = new Rectangle();
  969.   //   rect.width = actor.spriteWidth();
  970.   //   rect.height = actor.spriteHeight();
  971.   //   rect.x = actor.spritePosX() - rect.width / 2;
  972.   //   rect.y = actor.spritePosY() - rect.height;
  973.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  974.   //     y < rect.y + rect.height);
  975.   // };
  976.   //
  977.   // Yanfly.BEC.Window_BattleEnemy_processTouch =
  978.   //   Window_BattleEnemy.prototype.processTouch;
  979.   // Window_BattleEnemy.prototype.processTouch = function() {
  980.   //   if (eval(Yanfly.Param.BECEnemySelect) && this.isOpenAndActive()) {
  981.   //     if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
  982.   //       if (this.getClickedEnemy() >= 0) {
  983.   //         var index = this.getClickedEnemy();
  984.   //         if (this.index() === index) {
  985.   //           return this.processOk();
  986.   //         } else {
  987.   //           SoundManager.playCursor();
  988.   //           return this.select(index);
  989.   //         }
  990.   //       }
  991.   //     }
  992.   //     if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
  993.   //       if (this.getClickedEnemy() >= 0) {
  994.   //         var index = this.getClickedEnemy();
  995.   //         if (this.index() !== index) {
  996.   //           SoundManager.playCursor();
  997.   //           return this.select(index);
  998.   //         }
  999.   //       }
  1000.   //     }
  1001.   //     if (Yanfly.Param.BECSelectMouseOver) {
  1002.   //       var index = this.getMouseOverEnemy();
  1003.   //       if (index >= 0 && this.index() !== index) {
  1004.   //         SoundManager.playCursor();
  1005.   //         return this.select(index);
  1006.   //       }
  1007.   //     }
  1008.   //   };
  1009.   //   Yanfly.BEC.Window_BattleEnemy_processTouch.call(this);
  1010.   // };
  1011.   //
  1012.   // Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
  1013.   //   if (!enemy) return false;
  1014.   //   if (!enemy.isSpriteVisible()) return false;
  1015.   //   var x = TouchInput.x;
  1016.   //   var y = TouchInput.y;
  1017.   //   var rect = new Rectangle();
  1018.   //   rect.width = enemy.spriteWidth();
  1019.   //   rect.height = enemy.spriteHeight();
  1020.   //   rect.x = enemy.spritePosX() - rect.width / 2;
  1021.   //   rect.y = enemy.spritePosY() - rect.height;
  1022.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
  1023.   //     y < rect.y + rect.height);
  1024.   // };
  1025.   //
  1026.   // Window_BattleEnemy.prototype.getMouseOverEnemy = function() {
  1027.   //   for (var i = 0; i < this._enemies.length; ++i) {
  1028.   //     var enemy = this._enemies[i];
  1029.   //     if (!enemy) continue;
  1030.   //     if (this.isClickedEnemy(enemy)) {
  1031.   //       if (this._selectDead && !enemy.isDead()) continue;
  1032.   //       var index = this._enemies.indexOf(enemy)
  1033.   //       if (this._inputLock && index !== this.index()) continue;
  1034.   //       return index;
  1035.   //     }
  1036.   //   }
  1037.   //   return -1;
  1038.   // };
  1039. })(TWDP.TEE);
  

评分

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

查看全部评分

吸吸

Lv3.寻梦者

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
帖子
1516
2
发表于 2016-1-7 21:08:03 | 只看该作者
支持,好东西
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
306 小时
注册时间
2014-8-5
帖子
416
3
发表于 2016-1-7 21:41:08 | 只看该作者
very good !
回复 支持 反对

使用道具 举报

Lv1.梦旅人

笑问情缘

梦石
0
星屑
73
在线时间
238 小时
注册时间
2006-5-3
帖子
640
4
发表于 2016-1-8 18:40:38 手机端发表。 | 只看该作者
求给个下载链接,手机不方便
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
55 小时
注册时间
2013-11-24
帖子
22
5
发表于 2016-1-9 09:43:57 | 只看该作者
感谢楼主的分享,我已收藏!~~~
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
帖子
839
6
发表于 2016-1-9 10:27:09 | 只看该作者
要不要考虑分功能独立插件?还是核心函数都重写了?

点评

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

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
26998
在线时间
1535 小时
注册时间
2006-1-10
帖子
2063

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

7
发表于 2016-1-15 20:17:48 | 只看该作者
测试: 交通工具 点击无效     期待修复
交通工具点击都无效,只能用按键

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

点评

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

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
65
在线时间
385 小时
注册时间
2007-7-27
帖子
4106

开拓者

8
 楼主| 发表于 2016-1-16 00:15:11 | 只看该作者
king 发表于 2016-1-15 20:17
测试: 交通工具 点击无效     期待修复
交通工具点击都无效,只能用按键


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

点评

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

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
147
在线时间
21 小时
注册时间
2013-2-11
帖子
13
9
发表于 2016-1-18 00:36:11 | 只看该作者
先收藏了,残念一直未找到中文素材打包的方法...
回复 支持 反对

使用道具 举报

Lv4.逐梦者

世界坑化协会

梦石
0
星屑
7812
在线时间
1563 小时
注册时间
2007-3-13
帖子
5542

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

10
发表于 2016-1-18 09:56:48 | 只看该作者
终于可以点哪开哪了,先马克,最近没空弄工程
你的肩膀上有肩周炎~♪  秒懂  ☚   \没有
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-10 11:12

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表