じ☆ve冰风 发表于 2024-2-13 12:26:17

鼠标触摸增强

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

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

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

//=============================================================================
// Trentswd Plugins - Touch Event Extend
// TWDP_TouchEventEx.js
//=============================================================================

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

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

//=============================================================================
/*:
* @plugindesc v1.00 Extend the Touch Event
* @author Trentswd
*
* @help
* ============================================================================
* Introduction
* ============================================================================
*
* Don't have time to write this right now, sorry.
*
* ============================================================================
* Plugin Commands
* ============================================================================
*
* Don't have time to write this right now, sorry.
*
*/
//=============================================================================

//=============================================================================
// Parameter Variables
//=============================================================================

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

function distanceOfTwoPoints(x1, y1, x2, y2) {
return Math.round(
    Math.sqrt(
      Math.pow(x1 - x2, 2) +
      Math.pow(y1 - y2, 2)
    )
);
};

(function($) {

$.backup = $.backup || {};
//-----------------------------------------------------------------------------
/**
   * The static class that handles input data from the mouse and touchscreen.
   *
   * @class TouchInput
   */

TouchInput.clickDelta = 5;
TouchInput.backGestureSpeedThreshold = 30;
TouchInput.backGestureDistanceThreshold = 20;

/**
   * Initializes the touch system.
   *
   * @static
   * @method initialize
   */
TouchInput.initialize = function() {
    this.clear();
    this._setupEventHandlers();
};

/**
   * The wait time of the pseudo key repeat in frames.
   *
   * @static
   * @property keyRepeatWait
   * @type Number
   */
TouchInput.keyRepeatWait = 24;

/**
   * The interval of the pseudo key repeat in frames.
   *
   * @static
   * @property keyRepeatInterval
   * @type Number
   */
TouchInput.keyRepeatInterval = 6;

/**
   * Clears all the touch data.
   *
   * @static
   * @method clear
   */
$.backup.TouchInput_clear = TouchInput.clear;
TouchInput.clear = function() {
      $.backup.TouchInput_clear.call(this);


      this._pressed = {};
      this._pressed.left = {};
      this._pressed.left.isPressed = false;
      this._pressed.left.pressX = 0;
      this._pressed.left.pressY = 0;
      this._pressed.right = {};
      this._pressed.right.isPressed = false;
      this._pressed.right.pressX = 0;
      this._pressed.right.pressY = 0;
      this._pressed.middle = {};
      this._pressed.middle.isPressed = false;
      this._pressed.middle.pressX = 0;
      this._pressed.middle.pressY = 0;
      this._pressed.touch = {};
      this._pressed.touch.isPressed = false;
      this._pressed.touch.pressX = 0;
      this._pressed.touch.pressY = 0;

      this._clicked = {};
      this._clicked.left = {};
      this._clicked.left.isClicked = false;
      this._clicked.left.x = 0;
      this._clicked.left.y = 0;
      this._clicked.right = {};
      this._clicked.right.isClicked = false;
      this._clicked.right.x = 0;
      this._clicked.right.y = 0;
      this._clicked.middle = {};
      this._clicked.middle.isClicked = false;
      this._clicked.middle.x = 0;
      this._clicked.middle.y = 0;
      this._clicked.touch = {};
      this._clicked.touch.isClicked = false;
      this._clicked.touch.x = 0;
      this._clicked.touch.y = 0;

      this._pressed.left.time = 0;
      this._pressed.right.time = 0;
      this._pressed.middle.time = 0;
      this._pressed.touch.time = 0;


      this._events._clicked = {};
      this._events._clicked.left = {};
      this._events._clicked.left.isClicked = false;
      this._events._clicked.left.x = 0;
      this._events._clicked.left.y = 0;
      this._events._clicked.right = {};
      this._events._clicked.right.isClicked = false;
      this._events._clicked.right.x = 0;
      this._events._clicked.right.y = 0;
      this._events._clicked.middle = {};
      this._events._clicked.middle.isClicked = false;
      this._events._clicked.middle.x = 0;
      this._events._clicked.middle.y = 0;
      this._events._clicked.touch = {};
      this._events._clicked.touch.isClicked = false;
      this._events._clicked.touch.x = 0;
      this._events._clicked.touch.y = 0;

      this._events._pressed = {};
      this._events._pressed.left = {};
      this._events._pressed.left.isPressed = false;
      this._events._pressed.left.pressX = 0;
      this._events._pressed.left.pressY = 0;
      this._events._pressed.right = {};
      this._events._pressed.right.isPressed = false;
      this._events._pressed.right.pressX = 0;
      this._events._pressed.right.pressY = 0;
      this._events._pressed.middle = {};
      this._events._pressed.middle.isPressed = false;
      this._events._pressed.middle.pressX = 0;
      this._events._pressed.middle.pressY = 0;
      this._events._pressed.touch = {};
      this._events._pressed.touch.isPressed = false;
      this._events._pressed.touch.pressX = 0;
      this._events._pressed.touch.pressY = 0;

      this.touchScroll = {};
      this.touchScroll.x = 0;
      this.touchScroll.y = 0;
      this._events.touchScroll = {};
      this._events.touchScroll.x = 0;
      this._events.touchScroll.y = 0;
    }
    /**
   * Updates the touch data.
   *
   * @static
   * @method update
   */
$.backup.TouchInput_update = TouchInput.update;
TouchInput.update = function() {
    $.backup.TouchInput_update.call(this);


    this._pressed.left.isPressed = this._events._pressed.left.isPressed;
    this._pressed.left.pressX = this._events._pressed.left.pressX;
    this._pressed.left.pressY = this._events._pressed.left.pressY;

    this._pressed.right.isPressed = this._events._pressed.right.isPressed;
    this._pressed.right.pressX = this._events._pressed.right.pressX;
    this._pressed.right.pressY = this._events._pressed.right.pressY;

    this._pressed.middle.isPressed = this._events._pressed.middle.isPressed;
    this._pressed.middle.pressX = this._events._pressed.middle.pressX;
    this._pressed.middle.pressY = this._events._pressed.middle.pressY;

    this._pressed.touch.isPressed = this._events._pressed.touch.isPressed;
    this._pressed.touch.pressX = this._events._pressed.touch.pressX;
    this._pressed.touch.pressY = this._events._pressed.touch.pressY;

    if (this._pressed.left.isPressed) {
      this._pressed.left.time++;
    } else {
      this._pressed.left.time = 0;
    }
    if (this._pressed.right.isPressed) {
      this._pressed.right.time++;
    } else {
      this._pressed.right.time = 0;
    }
    if (this._pressed.middle.isPressed) {
      this._pressed.middle.time++;
    } else {
      this._pressed.middle.time = 0;
    }
    if (this._pressed.touch.isPressed) {
      this._pressed.touch.time++;
    } else {
      this._pressed.touch.time = 0;
    }

    this._clicked.left.isClicked = this._events._clicked.left.isClicked;
    this._clicked.left.x = this._events._clicked.left.x;
    this._clicked.left.y = this._events._clicked.left.y;
    this._clicked.right.isClicked = this._events._clicked.right.isClicked;
    this._clicked.right.x = this._events._clicked.right.x;
    this._clicked.right.y = this._events._clicked.right.y;
    this._clicked.middle.isClicked = this._events._clicked.middle.isClicked;
    this._clicked.middle.x = this._events._clicked.middle.x;
    this._clicked.middle.y = this._events._clicked.middle.y;
    this._clicked.touch.isClicked = this._events._clicked.touch.isClicked;
    this._clicked.touch.x = this._events._clicked.touch.x;
    this._clicked.touch.y = this._events._clicked.touch.y;


    this._events._clicked.left.isClicked = false;
    this._events._clicked.left.x = 0;
    this._events._clicked.left.y = 0;
    this._events._clicked.right.isClicked = false;
    this._events._clicked.right.x = 0;
    this._events._clicked.right.y = 0;
    this._events._clicked.middle.isClicked = false;
    this._events._clicked.middle.x = 0;
    this._events._clicked.middle.y = 0;
    this._events._clicked.touch.isClicked = false;
    this._events._clicked.touch.x = 0;
    this._events._clicked.touch.y = 0;

    this.touchScroll.x = this._events.touchScroll.x;
    this.touchScroll.y = this._events.touchScroll.y;
    this._events.touchScroll.x = 0;
    this._events.touchScroll.y = 0;
};

TouchInput.judgePressed = function(button) {
    return this._pressed.isPressed;
}

TouchInput.judgeClicked = function(button) {
    return this._clicked.isClicked;
}

TouchInput.judgeLongPressed = function(button, time) {
    if (time === undefined) {
      time = this.keyRepeatWait
    }
    if (this.judgePressed(button)) {
      return this._pressed.time >= time;
    }
    return false;
}

/**
   * @static
   * @method _onMouseDown
   * @param {MouseEvent} event
   * @private
   */
TouchInput._onMouseDown = function(event) {
    if (event.button === 0) {
      this._onLeftButtonDown(event);
    } else if (event.button === 1) {
      this._onMiddleButtonDown(event);
    } else if (event.button === 2) {
      this._onRightButtonDown(event);
    }
    this._date = Date.now();
};

/**
   * @static
   * @method _onLeftButtonDown
   * @param {MouseEvent} event
   * @private
   */
TouchInput._onLeftButtonDown = function(event) {
    var x = Graphics.pageToCanvasX(event.pageX);
    var y = Graphics.pageToCanvasY(event.pageY);
    if (Graphics.isInsideCanvas(x, y)) {
      this._mousePressed = true;
      this._pressedTime = 0;
      this._events._pressed.left.isPressed = true;
      this._events._pressed.left.pressX = x;
      this._events._pressed.left.pressY = y;
      this._onTrigger(x, y);
    }
};

/**
   * @static
   * @method _onMiddleButtonDown
   * @param {MouseEvent} event
   * @private
   */
TouchInput._onMiddleButtonDown = function(event) {
    var x = Graphics.pageToCanvasX(event.pageX);
    var y = Graphics.pageToCanvasY(event.pageY);
    if (Graphics.isInsideCanvas(x, y)) {
      this._events._pressed.middle.isPressed = true;
      this._events._pressed.middle.pressX = x;
      this._events._pressed.middle.pressY = y;
    }
};

/**
   * @static
   * @method _onRightButtonDown
   * @param {MouseEvent} event
   * @private
   */
TouchInput._onRightButtonDown = function(event) {
    var x = Graphics.pageToCanvasX(event.pageX);
    var y = Graphics.pageToCanvasY(event.pageY);
    if (Graphics.isInsideCanvas(x, y)) {
      this._events._pressed.right.isPressed = true;
      this._events._pressed.right.pressX = x;
      this._events._pressed.right.pressY = y;
      //this._onCancel(x, y);
    }
};

/**
   * @static
   * @method _onMouseMove
   * @param {MouseEvent} event
   * @private
   */
$.backup.TouchInput_onMouseMove = TouchInput._onMouseMove;
TouchInput._onMouseMove = function(event) {
    $.backup.TouchInput_onMouseMove.call(this, event);
    var x = Graphics.pageToCanvasX(event.pageX);
    var y = Graphics.pageToCanvasY(event.pageY);
    this._onMove(x, y);

};

TouchInput._onClick = function(x, y, button) {
    if (button === 0) {
      if (this._clicked.left.cancelNext) {
      this._clicked.left.cancelNext = false;
      return;
      }
      this._events._clicked.left.isClicked = true;
      this._events._clicked.left.x = x;
      this._events._clicked.left.y = y;
    } else if (button === 1) {
      if (this._clicked.right.cancelNext) {
      this._clicked.right.cancelNext = false;
      return;
      }
      this._events._clicked.right.isClicked = true;
      this._events._clicked.right.x = x;
      this._events._clicked.right.y = y;
      this._onCancel(x, y);
    } else if (button === 2) {
      if (this._clicked.middle.cancelNext) {
      this._clicked.middle.cancelNext = false;
      return;
      }
      this._events._clicked.middle.isClicked = true;
      this._events._clicked.middle.x = x;
      this._events._clicked.middle.y = y;
    } else if (button === 'touch') {
      if (this._clicked.touch.cancelNext) {
      this._clicked.touch.cancelNext = false;
      return;
      }
      this._events._clicked.touch.isClicked = true;
      this._events._clicked.touch.x = x;
      this._events._clicked.touch.y = y;
    }
}

TouchInput.cancelNextClick = function(button) {
    this._clicked.cancelNext = true;
}

TouchInput._onLeftButtonUp = function(event) {
    var x = Graphics.pageToCanvasX(event.pageX);
    var y = Graphics.pageToCanvasY(event.pageY);
    if (Graphics.isInsideCanvas(x, y)) {
      this._events._pressed.left.isPressed = false;
      var distance = distanceOfTwoPoints(this._pressed.left.pressX, this._pressed.left.pressY,
      x, y)
      if (distanceTouchInput.backGestureDistanceThreshold) {
      return true;
      }
    }
    return false;
};

/**
   * @static
   * @method _onTouchCancel
   * @param {TouchEvent} event
   * @private
   */
TouchInput._onTouchCancel = function(event) {
    this._screenPressed = false;
};

/**
   * @static
   * @method _onPointerDown
   * @param {PointerEvent} event
   * @private
   */
TouchInput._onPointerDown = function(event) {
    if (event.pointerType === 'touch' && !event.isPrimary) {
      var x = Graphics.pageToCanvasX(event.pageX);
      var y = Graphics.pageToCanvasY(event.pageY);
      if (Graphics.isInsideCanvas(x, y)) {
      // For Microsoft Edge
      this._onCancel(x, y);
      event.preventDefault();
      }
    }
};

/**
   * @static
   * @method _onTrigger
   * @param {Number} x
   * @param {Number} y
   * @private
   */
TouchInput._onTrigger = function(x, y) {
    this._events.triggered = true;
    this._x = x;
    this._y = y;
    this._date = Date.now();
};

/**
   * @static
   * @method _onCancel
   * @param {Number} x
   * @param {Number} y
   * @private
   */
TouchInput._onCancel = function(x, y) {
    this._events.cancelled = true;
    this._x = x;
    this._y = y;
};

/**
   * @static
   * @method _onMove
   * @param {Number} x
   * @param {Number} y
   * @private
   */
TouchInput._onMove = function(x, y) {
    this._events.moved = true;
    this._x = x;
    this._y = y;
};

/**
   * @static
   * @method _onRelease
   * @param {Number} x
   * @param {Number} y
   * @private
   */
TouchInput._onRelease = function(x, y) {
    this._events.released = true;
    this._x = x;
    this._y = y;
};

Window_Selectable.prototype.processTouch = function() {
    if (this.isOpenAndActive()) {
      if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
      //this._touching = true;
      } else if ((TouchInput.judgeClicked("left")) && this.isTouchedInsideFrame()) {
      this.onTouch(false);
      this.onTouch(true);
      } else if (TouchInput.judgeClicked("touch") && this.isTouchedInsideFrame()) {
      this.onTouch(false);
      this.onTouch(true);
      } else if (TouchInput.isCancelled()) {
      if (this.isCancelEnabled()) {
          this.processCancel();
      }
      }
      if (this._touching) {
      if (TouchInput.isPressed()) {
          this.onTouch(false);
      } else {
          this._touching = false;
      }
      }

      if (TouchInput.isMoved() && this.isTouchedInsideContents()) {
      this.onTouch(false);
      }
    } else {
      this._touching = false;
    }
};

Window_Selectable.prototype.onTouch = function(triggered) {
    var lastIndex = this.index();
    var x = this.canvasToLocalX(TouchInput.x);
    var y = this.canvasToLocalY(TouchInput.y);
    var hitIndex = this.hitTest(x, y);
    if (hitIndex >= 0) {
      if (hitIndex === this.index()) {
      if (triggered && this.isTouchOkEnabled()) {
          this.processOk();
      }
      } else if (this.isCursorMovable()) {
      this.select(hitIndex);
      if (triggered && this.isTouchOkEnabled()) {
          this.processOk();
      }
      }
    } else if (this._stayCount >= 10) {
      if (y < this.padding) {
      this.cursorUp();
      } else if (y >= this.height - this.padding) {
      this.cursorDown();
      }
    }
    if (this.index() !== lastIndex && triggered) {
      SoundManager.playCursor();
    }
};

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

};

$.backup.Window_Selectable_processWheel = Window_Selectable.prototype.processWheel;
Window_Selectable.prototype.processWheel = function() {
    $.backup.Window_Selectable_processWheel.call(this);
    if (this._touchSrollY === undefined) {
      this._touchSrollY = 0;
    }
    if (this.isOpenAndActive()) {
      if (TouchInput.judgePressed('touch')) {
      if (this._touchSrollY * TouchInput.touchScroll.y < 0) {
          this._touchSrollY = 0;
      }
      this._touchSrollY += TouchInput.touchScroll.y;
      } else {
      this._touchSrollY = 0;
      }
      //console.log(this._touchSrollY, TouchInput.touchScroll.y, this._cursorRect.height);

      if (this._touchSrollY >= this.itemHeight()) {
      this.scrollDown();
      this._touchSrollY -= this.itemHeight();
      }
      if (this._touchSrollY = 0 && y >= 0 && x < this.width && y < this.height;
};

Game_Player.prototype.triggerTouchActionD1 = function(x1, y1) {
    if ($gameMap.airship().pos(x1, y1)) {
      if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))&& this.getOnOffVehicle()) {
      return true;
      }
    }
    this.checkEventTriggerHere();
    return $gameMap.setupStartingEvent();
};

Game_Player.prototype.triggerTouchActionD2 = function(x2, y2) {
    if ($gameMap.boat().pos(x2, y2) || $gameMap.ship().pos(x2, y2)) {
      if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) && this.getOnVehicle()) {
      return true;
      }
    }
    if (this.isInBoat() || this.isInShip()) {
      if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))&& this.getOffVehicle()) {
      return true;
      }
    }
    this.checkEventTriggerThere();
    return $gameMap.setupStartingEvent();
};

Game_Player.prototype.triggerTouchActionD3 = function(x2, y2) {
    if ($gameMap.isCounter(x2, y2)) {
      this.checkEventTriggerThere();
    }
    return $gameMap.setupStartingEvent();
};

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

Scene_Map.prototype.processMapTouch = function() {
    if (TouchInput.judgeLongPressed("left", 15) || TouchInput.judgeLongPressed("touch", 15) || TouchInput.judgeLongPressed("right", 15)) {
      var x = $gameMap.canvasToMapX(TouchInput.x);
      var y = $gameMap.canvasToMapY(TouchInput.y);
      $gameTemp.setPressedDest(x, y);
      $gameTemp.clearDestination();
    } else if ($gameTemp.isPressedDestValid() && (!TouchInput.judgePressed("left") || !TouchInput.judgePressed("touch") || !TouchInput.judgePressed("right"))) {
      $gameTemp.clearPressedDest();
    } else if (TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) {
      var x = $gameMap.canvasToMapX(TouchInput.x);
      var y = $gameMap.canvasToMapY(TouchInput.y);
      $gameTemp.setDestination(x, y);
    }
};

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

Game_Player.prototype.moveByInput = function() {
    if (!this.isMoving() && this.canMove()) {
      var direction = this.getInputDirection();
      if (direction > 0) {
      $gameTemp.clearDestination();
      } else if ($gameTemp.isDestinationValid()) {
      var x = $gameTemp.destinationX();
      var y = $gameTemp.destinationY();
      direction = this.findDirectionTo(x, y);
      } else if ($gameTemp.isPressedDestValid()) {
      var x = $gameTemp._pressedDestX;
      var y = $gameTemp._pressedDestY;
      direction = this.findDirectionTo(x, y);
      }
      if (direction > 0) {
      this.executeMove(direction);
      }
    }
};

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


Game_Temp.prototype.clearPressedDest = function() {
    this._pressedDestX = null;
    this._pressedDestY = null;
}


Game_Temp.prototype.isPressedDestValid = function() {
    if (this._pressedDestX === null || this._pressedDestX === undefined) {
      return false;
    }
    return true;
}

Game_Temp.prototype.isPressedDestFar = function() {
    if (!this.isPressedDestValid()) {
      return false;
    }
    if (distanceOfTwoPoints($gamePlayer.x, $gamePlayer.y, this._pressedDestX, this._pressedDestY) >= 3) {
      return true;
    }
    return false;
}

Game_Player.prototype.findPressedDestDirection = function(x, y) {
    if (this.x === x && this.y === y) {
      return 0;
    }
    var deltaX = this.x - x;
    var deltaY = this.y - y;
    if (Math.abs(deltaX) > Math.abs(deltaY)) {
      if (deltaX > 0) {
      return 4;
      } else {
      return 6;
      }
    } else {
      if (deltaY > 0) {
      return 8;
      } else {
      return 2;
      }
    }
}

Game_Player.prototype.updateDashing = function() {
    if (this.isMoving()) {
      return;
    }
    if (this.canMove() && !this.isInVehicle() && !$gameMap.isDashDisabled()) {
      this._dashing = this.isDashButtonPressed() || $gameTemp.isDestinationValid() || $gameTemp.isPressedDestFar();
    } else {
      this._dashing = false;
    }
};
if (Imported.YEP_BattleEngineCore) {
    Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
      if (!enemy) return false;
      if (!enemy.isSpriteVisible()) return false;
      var x = TouchInput.x;
      var y = TouchInput.y;
      var rect = new Rectangle();
      rect.width = enemy.spriteWidth();
      rect.height = enemy.spriteHeight();
      rect.x = enemy.spritePosX() - rect.width / 2;
      rect.y = enemy.spritePosY() - rect.height;
      return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
      y < rect.y + rect.height);
    };
}


// Yanfly.BEC.Window_BattleActor_processTouch =
//   Window_BattleActor.prototype.processTouch;
// Window_BattleActor.prototype.processTouch = function() {
//   if (eval(Yanfly.Param.BECActorSelect) && this.isOpenAndActive()) {
//   if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
//       if (this.getClickedActor() >= 0) {
//         var index = this.getClickedActor();
//         if (this.index() === index) {
//         return this.processOk();
//         } else {
//         SoundManager.playCursor();
//         return this.select(index);
//         }
//       }
//   }
//   if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
//       if (this.getClickedActor() >= 0) {
//         var index = this.getClickedActor();
//         if (this.index() !== index) {
//         SoundManager.playCursor();
//         return this.select(index);
//         }
//       }
//   }
//   if (Yanfly.Param.BECSelectMouseOver) {
//       var index = this.getMouseOverActor();
//       if (index >= 0 && this.index() !== index) {
//         SoundManager.playCursor();
//         return this.select(index);
//       }
//   }
//   }
//   Yanfly.BEC.Window_BattleActor_processTouch.call(this);
// };
//
// Window_BattleActor.prototype.isClickedActor = function(actor) {
//   if (!actor) return false;
//   if (!actor.isSpriteVisible()) return false;
//   if (!actor.isAppeared()) return false;
//   var x = TouchInput.x;
//   var y = TouchInput.y;
//   var rect = new Rectangle();
//   rect.width = actor.spriteWidth();
//   rect.height = actor.spriteHeight();
//   rect.x = actor.spritePosX() - rect.width / 2;
//   rect.y = actor.spritePosY() - rect.height;
//   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
//   y < rect.y + rect.height);
// };
//
// Window_BattleActor.prototype.isMouseOverActor = function(actor) {
//   if (!actor) return false;
//   if (!actor.isSpriteVisible()) return false;
//   if (!actor.isAppeared()) return false;
//   var x = TouchInput._mouseOverX;
//   var y = TouchInput._mouseOverY;
//   var rect = new Rectangle();
//   rect.width = actor.spriteWidth();
//   rect.height = actor.spriteHeight();
//   rect.x = actor.spritePosX() - rect.width / 2;
//   rect.y = actor.spritePosY() - rect.height;
//   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
//   y < rect.y + rect.height);
// };
//
// Yanfly.BEC.Window_BattleEnemy_processTouch =
//   Window_BattleEnemy.prototype.processTouch;
// Window_BattleEnemy.prototype.processTouch = function() {
//   if (eval(Yanfly.Param.BECEnemySelect) && this.isOpenAndActive()) {
//   if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
//       if (this.getClickedEnemy() >= 0) {
//         var index = this.getClickedEnemy();
//         if (this.index() === index) {
//         return this.processOk();
//         } else {
//         SoundManager.playCursor();
//         return this.select(index);
//         }
//       }
//   }
//   if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
//       if (this.getClickedEnemy() >= 0) {
//         var index = this.getClickedEnemy();
//         if (this.index() !== index) {
//         SoundManager.playCursor();
//         return this.select(index);
//         }
//       }
//   }
//   if (Yanfly.Param.BECSelectMouseOver) {
//       var index = this.getMouseOverEnemy();
//       if (index >= 0 && this.index() !== index) {
//         SoundManager.playCursor();
//         return this.select(index);
//       }
//   }
//   };
//   Yanfly.BEC.Window_BattleEnemy_processTouch.call(this);
// };
//
// Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
//   if (!enemy) return false;
//   if (!enemy.isSpriteVisible()) return false;
//   var x = TouchInput.x;
//   var y = TouchInput.y;
//   var rect = new Rectangle();
//   rect.width = enemy.spriteWidth();
//   rect.height = enemy.spriteHeight();
//   rect.x = enemy.spritePosX() - rect.width / 2;
//   rect.y = enemy.spritePosY() - rect.height;
//   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
//   y < rect.y + rect.height);
// };
//
// Window_BattleEnemy.prototype.getMouseOverEnemy = function() {
//   for (var i = 0; i < this._enemies.length; ++i) {
//   var enemy = this._enemies;
//   if (!enemy) continue;
//   if (this.isClickedEnemy(enemy)) {
//       if (this._selectDead && !enemy.isDead()) continue;
//       var index = this._enemies.indexOf(enemy)
//       if (this._inputLock && index !== this.index()) continue;
//       return index;
//   }
//   }
//   return -1;
// };
})(TWDP.TEE);

             本帖来自P1论坛作者trentswd,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=388144若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页: [1]
查看完整版本: 鼠标触摸增强