设为首页 收藏本站
登录 /立即注册 /找回密码

URPGs

快捷导航
  • 门户Portal
  • 论坛BBS
  • 群组Group
  • 导读Guide
  • 家园Space
  • 工具Tools
  • 广播Follow
  • 期刊Periodical
  • 排行榜Ranklist
  • 社区茶坊
  • pixlr图片编辑
  • 资源列表
  • photobucket
  • RMVA Lite [In English]
  • RM RTP
  • TryRUBY
  • RMXP+RMVX下载[VeryCD]
  • RMVA下载[66RPG]
搜索
  • 本版
  • 帖子
  • 用户
URPGs»论坛 › 技术讨论 › 技术讨论 › 简易鼠标模块VA移植版
返回列表 发新帖
查看: 3215|回复: 2

[RMVA 技术讨论] 简易鼠标模块VA移植版

[复制链接]
satgo1546
satgo1546 当前离线
积分
201
查看详细资料 窥视卡 雷达卡
发表于 2013-8-18 19:37:19 | 显示全部楼层 |阅读模式
原帖:(6R卡住,待填充)
这次只是移植到VA了……
几乎没什么改动……
所以我闲得蛋疼把标识符全改成小写了……
使用方法:自己看脚本注释懒得再写了=-=
(关于FSL啥的我什么都不知道 )
[code=ruby]#===============================================================================
# ■ [VA]简易鼠标输入VA移植版
#    [VA]EasyMouseInput
#-------------------------------------------------------------------------------
#    click?          :返回是否左键单击
#    rightclick?     :返回是否右键单击
#    down?           :返回是否左键单击
#    rightdown?      :返回是否左键单击
#    getx            :返回鼠标的画面X坐标
#    gety            :返回鼠标的画面Y坐标
#    getdragrect     :返回鼠标拖动形成的方框,格式为Rect
#    27~43行为设定,请根据游戏实际情况更改
#-------------------------------------------------------------------------------
#    更新作者: ⑨
#    VA移植:satgo1546(其实根本没改多少)
#    许可协议: FSL
#===============================================================================
$fscript = {} if $fscript == nil
$fscript["EasyMouseInput"] = "1.0.0000"

#-------------------------------------------------------------------------------
# ▼ 通用配置模块
#-------------------------------------------------------------------------------

module FSL
  module EasyMouseConfig
    # 窗口大小,不用修改
    WINDOW_X = Graphics.width
    WINDOW_Y = Graphics.height
   
    # 鼠标左键和右键点击的SE
    CLICK_AUDIO_PATH = nil
    R_CLICK_AUDIO_PATH = nil
   
    # 鼠标是否限制在窗口中不能移动
    MOUSE_IN_RECT = false
   
    # 用图片代替鼠标指针
    SHOW_MOUSE_IMAGE = true
   
    # 鼠标图形路径
    # 会读取这个路径下的MouseN、MouseL、MouseR图片,分别代表普通、左键/右键按下
    MOUSE_IMAGE_PATH = "Graphics/System/"
  end
end

# API =========================================================================
$show_cursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
$get_cursor_pos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
$screen_to_client = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
$get_active_window = Win32API.new("user32", "GetActiveWindow", nil, 'l')
$screen_to_client = Win32API.new("user32", "ScreenToClient", 'lp', 'l')
$clip_cursor = Win32API.new("user32", "ClipCursor", 'p', 'l')
$get_async_key_state = Win32API.new("user32", "GetAsyncKeyState", 'l', 'i')
$hwnd = $get_active_window.call()
#==============================================================================
# ■ Mouse
#------------------------------------------------------------------------------
#  处理响应鼠标的模块
#==============================================================================

module Mouse
  include (FSL::EasyMouseConfig)
  attr_accessor :mousex
  attr_accessor :mousey
  attr_accessor :click
  attr_accessor :rightclick
  attr_accessor :downflag
  attr_accessor :rightdownflag
  attr_accessor :dragrect
  attr_accessor :dragrect_x_1
  attr_accessor :dragrect_x_2
  attr_accessor :dragrect_y_1
  attr_accessor :dragrect_y_2
  $show_cursor.call(0) if SHOW_MOUSE_IMAGE  
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def self.update
    getmouselocation
    setmouserect if FSL::EasyMouseConfig::MOUSE_IN_RECT
    @click = mouseclickjudge
    @rightClick = mouserightclickjudge
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标左键点击
  #--------------------------------------------------------------------------
  def self.click?
    return @click
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标右键点击
  #--------------------------------------------------------------------------
  def self.rightclick?
    return @rightclick
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标左键正按下
  #--------------------------------------------------------------------------
  def self.down?
    if @downflag == 1
      return true
    else
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标右键正按下
  #--------------------------------------------------------------------------
  def self.rightdown?
    if @rightdownflag == 1
      return true
    else
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标X
  #--------------------------------------------------------------------------
  def self.getx
    return @mousex
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标Y
  #--------------------------------------------------------------------------
  def self.gety
    return @mousey
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标拖动矩形
  #--------------------------------------------------------------------------
  def self.getdragrect
    return dragrect
  end
  #--------------------------------------------------------------------------
  # ● 单击鼠标
  #--------------------------------------------------------------------------
  def self.mouseclickjudge
    result = $get_async_key_state.call(0x01)
   
    if @downflag == 0 && result != 0
      @dragrect_x_1 = @mousex
      @dragrect_y_1 = @mousey
      @dragrect = Rect.new(0, 0, 0, 0)
    end
    if @downflag == 1 && result == 0
      @dragrect_x_2 = @mousex
      @dragrect_y_2 = @mousey
      setdragrect
    end
   
    if @downflag == 1 && result != 0
      return false
    end
    if result != 0
      @downflag = 1
      Audio.se_play(CLICK_AUDIO_PATH) if CLICK_AUDIO_PATH != nil
      return true
    else
      @downflag = 0
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 右击鼠标
  #--------------------------------------------------------------------------
  def self.mouserightclickjudge
    result = $get_async_key_state.call(0x02)
    if @rightdownflag == 1 && result != 0
      return false
    end
    if result != 0
      @rightdownflag = 1
      Audio.se_play(R_CLICK_AUDIO_PATH) if R_CLICK_AUDIO_PATH != nil
      return true
    else
      @rightdownflag = 0
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 把鼠标限制在窗口中
  #--------------------------------------------------------------------------
  def self.setmouserect
    w = [0, 0].pack("ll")
    $screen_to_client.call($hwnd, w)
    w = w.unpack("ll")
    x = w[0]
    y = w[1]
    $clip_cursor.call([-x, -y, -x+WINDOW_X, -y+WINDOW_Y].pack('llll'))
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标在屏幕中的位置
  #--------------------------------------------------------------------------
  def self.getmouselocation
    c = [0, 0]
    c = c.pack("ll")
    $get_cursor_pos.call(c)
    c = c.unpack("ll")
    w = [0, 0].pack("ll")
    $screen_to_client.call($hwnd, w)
    w = w.unpack("ll")
    @mousex = c[0] + w[0]
    @mousey = c[1] + w[1]
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标拖动的矩形
  #--------------------------------------------------------------------------
  def self.setdragrect
    @dragrect = Rect.new(0, 0, 0, 0)
    if @dragrect_x_1 >= @dragrect_x_2
      @dragrect.x = @dragrect_x_2
      @dragrect.width = @dragrect_x_1 - @dragrect_x_2
    else
      @dragrect.x = @dragrect_x_1
      @dragrect.width = @dragrect_x_2 - @dragrect_x_1
    end
    if @dragrect_y_1 >= @dragrect_y_2
      @dragrect.y = @dragrect_y_2
      @dragrect.height = @dragrect_y_1 - @dragrect_y_2
    else
      @dragrect.y = @dragrect_y_1
      @dragrect.height = @dragrect_y_2 - @dragrect_y_1
    end
  end
end

#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
#  游戏中全部画面的超级类。
#==============================================================================
class Scene_Base
  include (FSL::EasyMouseConfig)
  
  alias start_easy_mouse_input start
  def start
    start_easy_mouse_input
    if SHOW_MOUSE_IMAGE
      @mouse_sprite = Sprite.new
      @mouse_bitmap = []
      @mouse_bitmap[1] = Bitmap.new(MOUSE_IMAGE_PATH + "MouseN")
      @mouse_bitmap[2] = Bitmap.new(MOUSE_IMAGE_PATH + "MouseL")
      @mouse_bitmap[3] = Bitmap.new(MOUSE_IMAGE_PATH + "MouseR")
      @mouse_sprite.bitmap = @mouse_bitmap_1
      @mouse_sprite.ox = @mouse_sprite.oy = 4
      @mousebitmapindex = 0
      @mouse_sprite.z = 70000
    end
  end
  
  alias termin_easy_mouse_input terminate
  def terminate
    termin_easy_mouse_input
    if SHOW_MOUSE_IMAGE
      @mouse_sprite.dispose
      @mouse_sprite.bitmap.dispose
    end
  end
  
  alias upd_easy_mouse_input update
  def update
    upd_easy_mouse_input
    Mouse.update
    if SHOW_MOUSE_IMAGE
      @mouse_sprite.x = Mouse.getx
      @mouse_sprite.y = Mouse.gety
      if Mouse.down?
        newindex = 2
      elsif Mouse.rightdown?
        newindex = 3
      else
        newindex = 1
      end
      if @mousebitmapindex != newindex
        @mousebitmapindex = newindex
        @mouse_sprite.bitmap = @mouse_bitmap[@mousebitmapindex]
      end
    end
  end
end[/code]

评分

参与人数 1经验 +10 收起 理由
水终结者 + 10 塞糖~

查看全部评分

回复

使用道具 举报

  • 提升卡
  • 置顶卡
  • 沉默卡
  • 喧嚣卡
  • 变色卡
  • 抢沙发
  • 千斤顶
  • 显身卡
lbq
lbq 当前离线
积分
199
查看详细资料 窥视卡 雷达卡
发表于 2013-8-18 20:32:14 | 显示全部楼层
Win32api神马的最讨厌了

点评

satgo1546
反正我是改的啦啦啦  发表于 2013-8-18 21:00
回复 Like Dislike

使用道具 举报

  • 显身卡
orzfly
orzfly 当前离线
积分
55
查看详细资料 窥视卡 雷达卡
发表于 2013-8-18 23:44:08 | 显示全部楼层
呵呵。
回复 Like Dislike

使用道具 举报

  • 显身卡
返回列表 发新帖
高级模式
B Color Image Link Quote Code Smilies
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

站点统计|Archiver|手机版|意见反馈[feedback]| URPGs RPG Maker 游戏制作讨论

GMT+8, 2025-5-9 22:21 , Processed in 0.029221 second(s), 11 queries .

Powered by Discuz! X3.5

© 2011-2019 URPGs (Discuz! X3.4 © 2001-2019 Comsenz Inc.)

积分 0, 距离下一级还需 积分
快速回复 返回顶部 返回列表