幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3612|回复: 11

[已解决] 求助-RMXP鼠标脚本的问题

[复制链接]

16

主题

36

帖子

1063

积分

⑥精研

积分
1063
发表于 2010-6-15 08:44:57 | 显示全部楼层 |阅读模式
我最近在汉化艾拉的希望,由于许多人抱怨鼠标纸箱事件后,不会自动改变图样,游戏很难玩下去。所以我打算给它添上这个功能。
但是鼠标图像的改变成功了,但在判断事件类型时却出错了。一直提示未定义模块,我快疯了。明明我已经定义了!
无奈之下只能到处找人帮忙了,麻烦大家帮忙看看,到底是错在哪里?
  1. [color=#FF0000]class Game_Event
  2.   attr_accessor :flag
  3. end
  4. class Game_Map
  5.   #--------------------------------------------------------------------------
  6.   # ● 检查鼠标处是否有自定义的事件并返回类型
  7.   #--------------------------------------------------------------------------
  8.   def check_event_custom(mouse_x, mouse_y)
  9.     for event in $game_map.events.values #循环所有事件检查
  10.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / 4
  11.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 4
  12.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  13.         for i in 0...event.list.size
  14.           if event.list[i].parameters[0] == "item" #类型判断
  15.             event.flag = 1
  16.           elsif event.list[i].parameters[0] == "npc" #类型判断
  17.             event.flag = 2
  18.           end
  19.           return event.flag #返回事件类型标志
  20.         end
  21.       end
  22.     end
  23.     return $mouse_icon_id #使鼠标图不变化
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 检查鼠标处是否有事件可以开启
  27.   #--------------------------------------------------------------------------
  28.   def check_event_custom_start(mouse_x, mouse_y)     
  29.     for event in $game_map.events.values #循环所有事件检查
  30.       #事件角色图片宽度、高度
  31.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  32.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  33.       #判断是否鼠标在事件上
  34.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  35.         way_x = $game_player.x - event.x
  36.         way_y = $game_player.y - event.y
  37.         if ([1, -1].include?($game_player.x-event.x) and $game_player.y-event.y == 0) or ([1, -1].include?($game_player.y-event.y) and $game_player.x-event.x == 0)
  38.           for i in 0...event.list.size
  39.             if ["item","npc"].include?(event.list[i].parameters[0]) #当事件属于自定义事件
  40.               #判断主角朝向
  41.               if way_x == -1
  42.                 p_direction = 6 if way_y == 0
  43.               elsif way_x == 0
  44.                 p_direction = 2 if way_y == -1
  45.                 p_direction = 8 if way_y == 1
  46.               else
  47.                 p_direction = 4 if way_y == 0
  48.               end
  49.               event.start #开启事件
  50.               return 1, p_direction #返回即将开启事件以及角色朝向
  51.             end
  52.           end
  53.         end
  54.       end
  55.     end
  56.     return 0, 5 #返回不会开启事件以及角色朝向不变
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  60.   #--------------------------------------------------------------------------
  61.   def check_event_custom_exist(mouse_x, mouse_y)
  62.     for event in $game_map.events.values #循环所有事件检查
  63.       #事件角色图片宽度、高度
  64.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  65.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  66.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  67.         for i in 0...event.list.size
  68.           return 1, event if ["item", "npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  69.         end
  70.       end
  71.     end
  72.     return 0, event #返回不存在自定义事件,以及事件体
  73.   end
  74. end[/color]
  75. # Encapsulation of a mouse event
  76. MouseEvent = Struct.new(:sender, :trigger, :info)
  77. #==============================================================================
  78. # ** Mouse module
  79. #------------------------------------------------------------------------------
  80. # Manages the Win32API calls and the base mouse functionalities
  81. #==============================================================================
  82. module Mouse
  83.   #--------------------------------------------------------------------------
  84.   # * 鼠标输入触发器
  85.   #--------------------------------------------------------------------------
  86.   LEFT_CLICK = 1
  87.   RIGHT_CLICK = 2
  88.   MIDDLE_CLICK = 4
  89.   
  90.   MOUSE_TRIGGERS = [LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK]
  91.   #--------------------------------------------------------------------------
  92.   # * API Declaration
  93.   #--------------------------------------------------------------------------
  94.   $ShowCursor      = Win32API.new("user32", "ShowCursor", 'i', 'l')
  95.   ASYNC_KEY        = Win32API.new('user32', 'GetAsyncKeyState', 'i',     'i')
  96.   SCREEN_TO_CLIENT = Win32API.new('user32', 'ScreenToClient',   %w(l p), 'i')
  97.   CURSOR_POS       = Win32API.new('user32', 'GetCursorPos',     'p',     'i')
  98.   FIND_WINDOW      = Win32API.new('user32', 'FindWindowA',      %w(p p), 'l')
  99.   module_function
  100.   ##
  101.   # Start up procedures
  102.   #
  103.   def start_up
  104.     # 创建一个模块的配置参考
  105.     @@const = System::Mouse
  106.     # 初始化按钮状态
  107.     @button_states = Array.new(5, 0)
  108.     # 计算窗口的句柄
  109.     window_handle
  110.     # 了解鼠标状态
  111.     mouse_status = Utility.read_ini('mouse')
  112.     @enabled = !(mouse_status == '0' || mouse_status == '')
  113.     # 如果鼠标脚本启用则创建鼠标
  114.     if @enabled
  115.       $ShowCursor.call(0)
  116.       # 创建鼠标
  117.       create_cursor
  118.       # 更新游标
  119.       update
  120.     end
  121.   end
  122.   
  123.   
  124.   ##
  125.   # 终止鼠标脚本
  126.   #
  127.   def shutdown
  128.     # 终结掉鼠标
  129.     @mouse_sprite.dispose unless @mouse_sprite.nil? || @mouse_sprite.disposed?
  130.     $ShowCursor.call(1)
  131.   end
  132.   
  133.   ##
  134.   # 打开鼠标脚本
  135.   # 如果它已经打开,什么都不会发生
  136.   #
  137.   def turn_on
  138.     return if self.enabled
  139.     @enabled = true
  140.     # 创建鼠标
  141.     create_cursor
  142.     # 更新游标
  143.     update
  144.   end
  145.   
  146.   ##
  147.   # 鼠标脚本关闭。
  148.   # 如果它已关闭,什么都不会发生
  149.   #
  150.   def turn_off
  151.     return unless self.enabled
  152.     @enabled = false
  153.     # 显示光标如果是隐藏
  154.     unless @mouse_sprite.nil? || @mouse_sprite.disposed?
  155.       # 终止鼠标
  156.       @mouse_sprite.dispose
  157.       # 删除引用,以便将垃圾清除干净
  158.       @mouse_sprite = nil
  159.     end
  160.   end
  161.   
  162.   ##
  163.   # 更新
  164.   #
  165.   def update
  166.     # 只在启用时更新
  167.     return unless self.enabled
  168.     # 取新的位置
  169.     sx, sy = screen_pos
  170.     # 如果鼠标位置发生了变化
  171.     if @sx != sx || @sy != sy
  172.       # 储存新的屏幕x和y
  173.       @sx = sx
  174.       @sy = sy
  175.       # 获取相对位置
  176.       if Input.is_fullscreen  
  177.         rx, ry = sx, sy
  178.       else
  179.         rx, ry = screen_to_client(sx, sy)
  180.       end
  181.       return unless rx >= 0 && rx < 640 && ry >= 0 && ry < 480
  182.       
  183.       
  184.       
  185.       
  186. [color=#FF0000]     #########################################################      
  187.       #可能能在此处判断鼠标图像
  188.       #########################################################
  189.       # 变更光标的位置
  190.       @mouse_sprite.x = rx
  191.       @mouse_sprite.y = ry
  192.       $mouse_icon_id = $game_map.check_event_custom(rx,ry)  if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
  193.       if $scene.is_a?(Scene_Map) == false
  194.          $mouse_icon_id = 0
  195.       end
  196.       case $mouse_icon_id
  197.       when 1
  198.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Arrow3.png')
  199.       when 2
  200.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Arrow2.png')
  201.       when 11
  202.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  203.       when 12
  204.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  205.       when 13
  206.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  207.       when 14
  208.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  209.       when 16
  210.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  211.       when 17
  212.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  213.       when 18
  214.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  215.       when 19
  216.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  217.       when 0
  218.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  219.       end
  220.     end[/color]    # 检查点击
  221.     for trigger in MOUSE_TRIGGERS
  222.       # 获取异步状态
  223.       state = ASYNC_KEY.call(trigger)
  224.       # If 0 or 1
  225.       if state == 0 || state == 1
  226.         if @button_states[trigger] > 0
  227.           @button_states[trigger] *= -1
  228.         else
  229.           @button_states[trigger] = 0
  230.         end
  231.       else
  232.         if @button_states[trigger] > 0
  233.           @button_states[trigger] += 1
  234.         else
  235.           @button_states[trigger] = 1
  236.         end
  237.       end
  238.     end
  239.   end
  240.   
  241.   ##
  242.   # Check for press
  243.   #   返回false,如果不启用鼠标
  244.   #
  245.   def press?(id = LEFT_CLICK)
  246.     return false unless self.enabled
  247.     return @button_states[id] >= 1
  248.   end
  249.   
  250.   ##
  251.   # 查触发
  252.   #   返回false,如果不启用鼠标
  253.   #
  254.   def trigger?(id = LEFT_CLICK)
  255.     return false unless self.enabled
  256.     return @button_states[id] == 1
  257.   end
  258.   
  259.   ##
  260.   # 重复检查
  261.   #   返回false,如果不启用鼠标
  262.   #
  263.   def repeat?(id = LEFT_CLICK)
  264.     return false unless self.enabled
  265.     if @button_states[id] <= 0
  266.       return false
  267.     elsif @button_states[id] == 1
  268.       return true
  269.     elsif @button_states[id] > @@const::REPEAT_START_WAIT
  270.       return @button_states[id] % @@const::REPEAT_WAIT == 1
  271.     end
  272.   end
  273.   
  274.   ##
  275.   # 回true如果鼠标脚本启用
  276.   #
  277.   def enabled
  278.     @enabled
  279.   end
  280.   
  281.   ##
  282.   # 获得屏幕坐标
  283.   #
  284.   def screen_pos
  285.     # 包0位置
  286.     pos = [0, 0].pack('ll')
  287.     # 裸装的光标位置返回呼叫
  288.     return CURSOR_POS.call(pos) == 0 ? nil : pos.unpack('ll')
  289.   end
  290.   
  291.   ##
  292.   # 转换屏的X和Y坐标的相对坐标。
  293.   # Top-left corner = (0, 0)
  294.   #
  295.   def pos
  296.     return @mouse_sprite.x, @mouse_sprite.y
  297.   end
  298.   
  299.   ##
  300.   # 检查鼠标是否在窗口内部
  301.   #
  302.   def inside?
  303.     x, y = pos
  304.     return x >= 0 && x < 640 && y >= 0 && y < 480
  305.   end
  306.   
  307.   ##
  308.   # 屏幕坐标转换为相对的客户端窗口
  309.   #
  310.   def screen_to_client(x, y)
  311.     # 如果X和Y空返回零
  312.     return nil unless x and y
  313.     if @ori_pos.nil?
  314.       @stc_wait = 0
  315.     end
  316.     if @stc_wait <= 0
  317.       # Locate upper-left corner
  318.       pack = [0, 0].pack('ll')
  319.       SCREEN_TO_CLIENT.call(window_handle, pack)
  320.       @ori_pos = pack.unpack('ll')
  321.       # 等待10帧以开始下一次查找
  322.       @stc_wait = 10
  323.     else
  324.       @stc_wait -= 1
  325.     end
  326.     # Translocate X- and Y-coordinates
  327.     x += @ori_pos[0]
  328.     y += @ori_pos[1]
  329.     return x, y
  330.   end
  331.   
  332.   ##
  333.   # 检索窗口句柄
  334.   #
  335.   def window_handle
  336.     if @window_handle.nil?
  337.       # 游戏名称查找
  338.       game_name = Utility.read_ini('Title')
  339.       # 查找窗口
  340.       @window_handle = FIND_WINDOW.call('RGSS Player', game_name)
  341.     end
  342.     return @window_handle
  343.   end
  344.   
  345.   # 开辟了单独的类模块的
  346.   class << self
  347.     ###################
  348.     # Private methods #
  349.     ###################
  350.     private
  351.     ##
  352.     # 创建光标
  353.     #
  354.     def create_cursor
  355.       @mouse_sprite = Sprite.new
  356.       @mouse_sprite.z = 50000
  357.       @mouse_sprite.bitmap = RPG::Cache.icon(@@const::DEFAULT_ICON)
  358.     end
  359.   end
  360. end
  361. class Window_Base
  362.   ##
  363.   # 更新鼠标位置
  364.   # Mouse enabled subclasses should overwrite this method
  365.   #
  366.   def mouse_move(mx, my)
  367.     return unless $DEBUG
  368.     raise StandardError.new("mouse_move(mx, my) was not overwritten in #{self.class}")
  369.   end
  370.   
  371.   ##
  372.   # 更新鼠标(只有当鼠标启用时才调用)
  373.   # Note: The mouse is over the window
  374.   #
  375.   def mouse_update
  376.     return unless $DEBUG
  377.     raise StandardError.new("mouse_update was not overwritten in #{self.class}")
  378.   end
  379.   
  380.   ##
  381.   # 判断鼠标位置是否超过窗口,是的话让鼠标图像停留在窗口边框
  382.   #
  383.   def over_contents?(mx, my)
  384.     return mx >= 16 && mx < width - 16 &&
  385.            my >= 16 && my < height - 16
  386.   end
  387. end
  388. class Window_Selectable
  389.   ##
  390.   # Get the height of the elements
  391.   #
  392.   def element_height
  393.     return 32
  394.   end
  395.   
  396.   ##
  397.   # Get the height of the elements
  398.   #
  399.   def element_width
  400.     return self.width / @column_max - 32
  401.   end
  402.   
  403.   ##
  404.   # Calculates the index from the x and y coordinate
  405.   # Assumes (0,0) to be upper-left corner of the contents
  406.   #
  407.   def calculate_index(x, y)
  408.     ex = x / element_width
  409.     ey = y / element_height
  410.     return ex + (ey + top_row) * @column_max
  411.   end
  412.   
  413.   ##
  414.   #
  415.   #
  416.   def cause_scroll(index)
  417.     # Get  row
  418.     row = index / @column_max
  419.     # If row is before top row or more to back than back row
  420.     return row < self.top_row || row > self.top_row + (self.page_row_max - 1)
  421.   end
  422.   ##
  423.   # 更新鼠标位置
  424.   # Mouse enabled subclasses should overwrite this method
  425.   #
  426.   def mouse_move(mx, my)
  427.     # Cursor position less than 0 implies that the cursor is hidden
  428.     return if @index < 0 || !self.active
  429.     # Store the coordinates
  430.     @mx, @my = mx, my
  431.    
  432.     # Ignore the move if it is not over the contents
  433.     if mx >= 16 && mx < width - 16
  434.       index = calculate_index(mx-16, my-16)
  435.       # If the index is valid
  436.       if index < @item_max && index >= 0
  437.         # Scroll wait
  438.         if cause_scroll(index) && self.scroll_wait > 0
  439.           return
  440.         elsif cause_scroll(index)
  441.           self.scroll_wait = System::Mouse::SCROLL_WAIT
  442.           @scrolling = true
  443.         else
  444.           @scrolling = false
  445.         end
  446.         # Change the index
  447.         @index = index
  448.       end
  449.     end
  450.   end
  451.   
  452.   ##
  453.   # Update mouse (Only called if mouse is enabled)
  454.   # Note: The mouse is over the window
  455.   #
  456.   def mouse_update
  457.     # Only update if active
  458.     return unless self.active
  459.     # Scroll wait update
  460.     if self.scroll_wait > 0
  461.       self.scroll_wait -= 1
  462.       return
  463.     elsif @scrolling
  464.       # See if the scrolling should continue
  465.       index = calculate_index(@mx-16, @my-16)
  466.       if cause_scroll(index) && index < @item_max && index >= 0
  467.         self.scroll_wait = System::Mouse::SCROLL_WAIT
  468.         @index = index
  469.       else
  470.         # Stop scrolling
  471.         @scrolling = false
  472.       end
  473.     end
  474.     @mx, @my = -1, -1 if @mx.nil?
  475.     # Check for click
  476.     if Mouse.trigger?(Mouse::LEFT_CLICK) && over_contents?(@mx, @my)
  477.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  478.     end
  479.   end
  480. end
  481. class Window_Target
  482.   ##
  483.   # Update mouse position
  484.   # Mouse enabled subclasses should overwrite this method
  485.   #
  486.   def mouse_move(mx, my)
  487.     return unless self.active
  488.     if @index >= 0
  489.       super
  490.       return
  491.     else
  492.       # Store the coordinates
  493.       @mx, @my = mx, my
  494.     end
  495.   end
  496.   ##
  497.   # Update mouse (Only called if mouse is enabled)
  498.   # Note: The mouse is over the window
  499.   #
  500.   def mouse_update
  501.     if @index >= 0
  502.       super
  503.       return
  504.     else
  505.       # Only update if active
  506.       return unless self.active
  507.       @mx, @my = -1, -1 if @mx.nil?
  508.       # Check for click
  509.       if Mouse.trigger?(Mouse::LEFT_CLICK) && over_contents?(@mx, @my)
  510.         owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  511.       end
  512.     end
  513.   end
  514. end
  515. class Window_NameInput  
  516.   ##
  517.   # Determines whether the given coordinates are within the given area
  518.   #
  519.   def is_in?(x,y, rx,ry,rw,rh)
  520.     return x >= rx && x < rx + rw &&
  521.            y >= ry && y < ry + rh
  522.   end
  523.   
  524.   ##
  525.   # Calculates the index from the coordinates
  526.   #
  527.   def calculate_index(x, y)
  528.     # Check [OK] position
  529.     return 90 if is_in?(x,y,  428, 9 * 32, 48, 32)
  530.     if is_in?(x,y,  140, 0, 5*32, 9*32)
  531.       # Left box
  532.       x = (x - 140) / 32
  533.       y /= 32
  534.       return x + y * 5
  535.     elsif is_in?(x,y,  320, 0, 5*32, 9*32)
  536.       # Right box
  537.       x = (x - 320) / 32
  538.       y /= 32
  539.       return x + y * 5 + 45
  540.     end
  541.     # Outside
  542.     return -1
  543.   end
  544.   
  545.   ##
  546.   # Update mouse position
  547.   # Mouse enabled subclasses should overwrite this method
  548.   #
  549.   def mouse_move(mx, my)
  550.     @mx, @my = mx, my
  551.     index = calculate_index(mx-16, my-16)
  552.     @index = index unless index < 0
  553.   end
  554.   
  555.   ##
  556.   # Update mouse (Only called if mouse is enabled)
  557.   # Note: The mouse is over the window
  558.   #
  559.   def mouse_update
  560.     if Mouse.trigger?(Mouse::LEFT_CLICK) && calculate_index(@mx-16, @my-16) >= 0
  561.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  562.     end
  563.   end
  564. end
  565. class Window_Message
  566.   ##
  567.   # Check for normal trigger
  568.   #
  569.   def normal_trigger?
  570.     return true if Input.trigger?(Input::C)
  571.     if Mouse.trigger?(Mouse::LEFT_CLICK)
  572.       return true if $game_temp.choice_max <= 0
  573.       index = calculate_index(@mx - 16, @my - 16)
  574.       return true if index >= 0 && index < @item_max
  575.     end
  576.   end
  577.   
  578.   ##
  579.   # Update mouse (Only called if mouse is enabled)
  580.   #
  581.   def mouse_update
  582.     # Do nothing
  583.   end
  584.   
  585.   ##
  586.   # Calculates the index from the x and y coordinate
  587.   # Assumes (0,0) to be upper-left corner of the contents
  588.   #
  589.   def calculate_index(x, y)
  590.     return -1 if x > @cursor_width + 8
  591.     ey = (y - $game_temp.choice_start * 32) / element_height
  592.     return (ey + top_row) * @column_max
  593.   end
  594. end
  595. class Arrow_Base
  596.   ##
  597.   # Update mouse (Only called if mouse is enabled)
  598.   # Note: The mouse is over the window
  599.   #
  600.   def mouse_update
  601.     return unless $DEBUG
  602.     raise StandardError.new("mouse_update was not overwritten in #{self.class}")
  603.   end
  604. end
  605. class Arrow_Enemy  
  606.   ##
  607.   # Update mouse position
  608.   #
  609.   def mouse_move(mx, my)
  610.     # Pass Through Enemies
  611.     for enemy in $game_troop.enemies
  612.       # Skip if Non-Existing Enemy
  613.       next unless enemy.exist?
  614.       # Gets Paddings
  615.       w, h = enemy.battler_width / 2, enemy.battler_height
  616.       # If Within Mouse Padding Range
  617.       if mx.between?(enemy.screen_x - w, enemy.screen_x + w) &&
  618.          my.between?(enemy.screen_y - h, enemy.screen_y + 10)
  619.         # Set Index
  620.         @index = $game_troop.enemies.index(enemy)
  621.         break
  622.       end
  623.     end
  624.   end
  625.   
  626.   ##
  627.   # Update mouse (Only called if mouse is enabled)
  628.   #
  629.   def mouse_update
  630.     if Mouse.trigger?(Mouse::LEFT_CLICK)# && @my < 320
  631.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  632.     end
  633.     mx, my = Mouse.pos
  634.     return if @mx == mx && @my == my
  635.     @mx, @my = mx, my
  636.     # Pass Through Enemies
  637.     for enemy in $game_troop.enemies
  638.       # Skip if Non-Existing Enemy
  639.       next unless enemy.exist?
  640.       # Gets Paddings
  641.       w, h = enemy.battler_width / 2, enemy.battler_height
  642.       # If Within Mouse Padding Range
  643.       if mx.between?(enemy.screen_x - w, enemy.screen_x + w) &&
  644.          my.between?(enemy.screen_y - h, enemy.screen_y + 10)
  645.         # Set Index
  646.         @index = $game_troop.enemies.index(enemy)
  647.         break
  648.       end
  649.     end
  650.   end
  651. end
  652. class Arrow_Actor
  653.   ##
  654.   # Update mouse (Only called if mouse is enabled)
  655.   #
  656.   def mouse_update
  657.     if Mouse.trigger?(Mouse::LEFT_CLICK)# && @my > 288
  658.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  659.     end
  660.     # Get mouse position
  661.     mx, my = Mouse.pos
  662.     # Checks that the mouse have moved
  663.     return if @mx == mx && @my == my
  664.     # Store new position
  665.     @mx, @my = mx, my
  666.     # Pass Through Actors
  667.     for actor in $game_party.actors
  668.       # Gets Paddings
  669.       w, h = actor.battler_width / 2, actor.battler_height
  670.       # If Within Mouse Padding Range
  671.       if mx.between?(actor.screen_x - w, actor.screen_x + w) &&
  672.          my.between?(actor.screen_y - h, actor.screen_y + 10)
  673.         # Set Index
  674.         @index = $game_party.actors.index(actor)
  675.       end
  676.     end
  677.   end
  678. end
复制代码

以上就是鼠标脚本,红色部分,我是用四方向行走脚本添加的,运行时会卡在
$mouse_icon_id = $game_map.check_event_custom(rx,ry)  if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
这句上,提示check_event_custom是未定义的方法,可我明明定义了。
如果把这句话改为具体的数字如:
$mouse_icon_id = 1,那么能正常进入游戏,刚进游戏图形是箭头,进入到地图后就变成小手,也就是说我添加的这段鼠标图像改变判断代码,并没放错地方。

其中,鼠标图像ARROW是箭头,Arrow3是小手。麻烦大家帮帮看看,该怎么修改。

另外,游戏中鼠标的启动和卸载语句都在MAIN中。分别为:
  # Start up the mouse
  Mouse.start_up

  # Shutdown mouse
  Mouse.shutdown

而每个窗口都有对应的鼠标控制赋权语句及刷新语句如:
    # Add as a mouse enabled window
    mouse_windows << @item_window

mouse.update

另:请不要叫我用其他的脚本,我都试过了,这个游戏如果直接添加其他的鼠标脚本,那么会引起冲突,完全进不了游戏,即使把原有脚本清除掉,再放其他的鼠标脚本,也会不定时出错,而且不会提示具体错在哪里。
回复

使用道具 举报

16

主题

36

帖子

1063

积分

⑥精研

积分
1063
 楼主| 发表于 2010-6-15 08:47:36 | 显示全部楼层
用于参考的四方向行走的鼠标脚本:

完整鼠标系统(四方向):
  1. #==============================================================================
  2. # ■ 完整鼠标系统(四方向)
  3. #------------------------------------------------------------------------------
  4. #  使用时务必配合专用寻路算法
  5. #   By whbm
  6. #==============================================================================
  7. #下面做一下介绍与使用说明:
  8. #    在屏幕上单击鼠标的时候,会自动进行寻路,这里为了速度更快并且为了进行迷
  9. #宫时的难度寻路被限定在当时的屏幕内部。(否则玩家直接点到终点,呵呵....知道
  10. #后果了吧)
  11. #    在角色移动过程中再次单击鼠标(即双击)并在单击第二次鼠标的时候不松手,
  12. #角色将会跟随鼠标方向移动。(这个应该好理解,不用多说吧)当角色贴着欲被启动
  13. #的事件的时候,单击NPC即可启动事件。若未贴着,将会产生自动寻路到NPC附近的某
  14. #点,那时在单击NPC即可。
  15. #    当鼠标停在某些事件上时候会发现有不同的图标,设置方法为:宝箱事件请在事
  16. #件的执行内容中添加 注释,注释内容为 Item 注意大小写。NPC事件请在事件的执行
  17. #内容中添加 注释注释内容为 NPC 注意大小写。若不箱改变某事件的图标,则不要写
  18. #那两个注释。
  19. #    当把脚本转到您工程的时候千万别忘了那个寻路用的脚本。
  20. #==============================================================================
  21. class Game_Event
  22.   attr_accessor :flag
  23. end
  24. #==============================================================================
  25. # ■ Game_Map
  26. #------------------------------------------------------------------------------
  27. #  处理地图的类。包含卷动以及可以通行的判断功能。
  28. # 本类的实例请参考 $game_map 。
  29. #==============================================================================
  30. class Game_Map
  31.   #--------------------------------------------------------------------------
  32.   # ● 检查鼠标处是否有自定义的事件并返回类型
  33.   #--------------------------------------------------------------------------
  34.   def check_event_custom(mouse_x, mouse_y)
  35.     for event in $game_map.events.values #循环所有事件检查
  36.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / 4
  37.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 4
  38.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  39.         for i in 0...event.list.size
  40.           if event.list[i].parameters[0] == "Item" #类型判断
  41.             event.flag = 1
  42.           elsif event.list[i].parameters[0] == "Npc" #类型判断
  43.             event.flag = 2
  44.           else
  45.             event.flag = 0 if $game_player.get_mouse_sta != 2 #无标志
  46.           end
  47.           return event.flag #返回事件类型标志
  48.         end
  49.       end
  50.     end
  51.     return 0 if $game_player.get_mouse_sta != 2 #如果不是在跟随鼠标状态,则返回无标志
  52.     return $mouse_icon_id #使鼠标图不变化
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # ● 检查鼠标处是否有事件可以开启
  56.   #--------------------------------------------------------------------------
  57.   def check_event_custom_start(mouse_x, mouse_y)
  58.     for event in $game_map.events.values #循环所有事件检查
  59.       #事件角色图片宽度、高度
  60.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  61.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  62.       #判断是否鼠标在事件上
  63.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  64.         way_x = $game_player.x - event.x
  65.         way_y = $game_player.y - event.y
  66.         if ([1, -1].include?($game_player.x-event.x) and $game_player.y-event.y == 0) or ([1, -1].include?($game_player.y-event.y) and $game_player.x-event.x == 0)
  67.           for i in 0...event.list.size
  68.             if ["Item","Npc"].include?(event.list[i].parameters[0]) #当事件属于自定义事件
  69.               #判断主角朝向
  70.               if way_x == -1
  71.                 p_direction = 6 if way_y == 0
  72.               elsif way_x == 0
  73.                 p_direction = 2 if way_y == -1
  74.                 p_direction = 8 if way_y == 1
  75.               else
  76.                 p_direction = 4 if way_y == 0
  77.               end
  78.               event.start #开启事件
  79.               return 1, p_direction #返回即将开启事件以及角色朝向
  80.             end
  81.           end
  82.         end
  83.       end
  84.     end
  85.     return 0, 5 #返回不会开启事件以及角色朝向不变
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  89.   #--------------------------------------------------------------------------
  90.   def check_event_custom_exist(mouse_x, mouse_y)
  91.     for event in $game_map.events.values #循环所有事件检查
  92.       #事件角色图片宽度、高度
  93.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  94.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  95.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  96.         for i in 0...event.list.size
  97.           return 1, event if ["Item", "Npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  98.         end
  99.       end
  100.     end
  101.     return 0, event #返回不存在自定义事件,以及事件体
  102.   end
  103. end
  104. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  105. $敌人选框扩大 = 20
  106. $角色选框扩大 = 30
  107. #==============================================================================
  108. # ● API调用
  109. #==============================================================================
  110. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  111. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  112. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  113. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  114. $Window_HWND = $GetActiveWindow.call
  115. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  116. module Mouse  
  117. LEFT = 0x01
  118. RIGHT = 0x02
  119. def self.init(sprite = nil)
  120.    $ShowCursor.call(0)
  121.    
  122.    @show_cursor = false
  123.    
  124.    @mouse_sprite = Sprite.new
  125.    @mouse_sprite.z = 99999
  126.    @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Weapon01.png')
  127.    @left_press = false
  128.    @right_press = false
  129.    @left_trigger = false
  130.    @right_trigger = false
  131.    @left_repeat = false
  132.    @right_repeat = false
  133.    @click_lock = false
  134.    
  135.    update
  136. end
  137. def self.exit
  138.    @mouse_sprite.bitmap.dispose
  139.    @mouse_sprite.dispose
  140.    @show_cursor = true
  141.    $ShowCursor.call(1)
  142. end
  143. def self.mouse_debug
  144.    return @mouse_debug.bitmap
  145. end
  146. def self.update
  147.    left_down = $GetKeyState.call(0x01)
  148.    right_down = $GetKeyState.call(0x02)
  149.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  150.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  151.      @a = !@a
  152.    end
  153.    if $scene.is_a?(Scene_Map) == false
  154.      $mouse_icon_id = 0
  155.    end
  156.    if $mouse_icon_id != $mouse_icon_id_last
  157.      case $mouse_icon_id
  158.      when 1
  159.        if @a
  160.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem1')
  161.        else
  162.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem2')
  163.        end
  164.      when 2
  165.        if @a
  166.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo1')
  167.        else
  168.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo2')
  169.        end
  170.      when 11
  171.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_LEFT')
  172.      when 12
  173.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_DOWN')
  174.      when 13
  175.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_RIGHT')
  176.      when 14
  177.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LEFT')
  178.      when 16
  179.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_RIGHT')
  180.      when 17
  181.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_LEFT')
  182.      when 18
  183.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UP')
  184.      when 19
  185.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_RIGHT')
  186.      when 0
  187.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/木剑')
  188.      end
  189.      $mouse_icon_id_last = $mouse_icon_id
  190.    end
  191.    @click_lock = false
  192.    mouse_x, mouse_y = self.get_mouse_pos
  193.    if @mouse_sprite != nil
  194.      @mouse_sprite.x = mouse_x
  195.      @mouse_sprite.y = mouse_y
  196.    end
  197.    if left_down[7] == 1
  198.      @left_repeat = (not @left_repeat)
  199.      @left_trigger = (not @left_press)
  200.      @left_press = true
  201.    else
  202.      @left_press = false
  203.      @left_trigger = false
  204.      @left_repeat = false
  205.    end
  206.    if right_down[7] == 1
  207.      @right_repeat = (not @right_repeat)
  208.      @right_trigger = (not @right_press)
  209.      @right_press = true
  210.    else
  211.      @right_press = false
  212.      @right_trigger = false
  213.      @right_repeat = false
  214.    end
  215. end
  216. def self.get_mouse_pos
  217.    point_var = [0, 0].pack('ll')
  218.    if $GetCursorPos.call(point_var) != 0
  219.      if $ScreenToClient.call($Window_HWND, point_var) != 0
  220.        x, y = point_var.unpack('ll')
  221.        if (x < 0) or (x > 10000) then x = 0 end
  222.        if (y < 0) or (y > 10000) then y = 0 end
  223.        if x > 640 then x = 640 end
  224.        if y > 480 then y = 480 end
  225.        return x, y
  226.      else
  227.        return 0, 0
  228.      end
  229.    else
  230.      return 0, 0
  231.    end
  232. end
  233. def self.press?(mouse_code)
  234.    if mouse_code == LEFT
  235.      if @click_lock
  236.        return false
  237.      else
  238.        return @left_press
  239.      end
  240.    elsif mouse_code == RIGHT
  241.      return @right_press
  242.    else
  243.      return false
  244.    end
  245. end
  246. def self.trigger?(mouse_code)
  247.    if mouse_code == LEFT
  248.      if @click_lock
  249.        return false
  250.      else
  251.        return @left_trigger
  252.      end
  253.    elsif mouse_code == RIGHT
  254.      return @right_trigger
  255.    else
  256.      return false
  257.    end
  258. end
  259. def self.repeat?(mouse_code)
  260.    if mouse_code == LEFT
  261.      if @click_lock
  262.        return false
  263.      else
  264.        return @left_repeat
  265.      end
  266.    elsif mouse_code == RIGHT
  267.      return @right_repeat
  268.    else
  269.      return false
  270.    end
  271. end
  272. def self.click_lock?
  273.    return @click_lock
  274. end
  275. def self.click_lock
  276.    @click_lock = true
  277. end
  278. def self.click_unlock
  279.    @click_lock = false
  280. end
  281. end
  282. module Input
  283. if @self_update == nil
  284.    @self_update = method('update')
  285.    @self_press = method('press?')
  286.    @self_trigger = method('trigger?')
  287.    @self_repeat = method('repeat?')
  288. end
  289. def self.update
  290.    @self_update.call
  291.    Mouse.update
  292. end
  293. def self.press?(key_code)
  294.    if @self_press.call(key_code)
  295.      return true
  296.    end
  297.    if key_code == C
  298.      return Mouse.press?(Mouse::LEFT)
  299.    elsif key_code == B
  300.      return Mouse.press?(Mouse::RIGHT)
  301.    else
  302.      return @self_press.call(key_code)
  303.    end
  304. end
  305. def self.trigger?(key_code)
  306.    if @self_trigger.call(key_code)
  307.      return true
  308.    end
  309.    if key_code == C
  310.      return Mouse.trigger?(Mouse::LEFT)
  311.    elsif key_code == B
  312.      return Mouse.trigger?(Mouse::RIGHT)
  313.    else
  314.      return @self_trigger.call(key_code)
  315.    end
  316. end
  317. def self.repeat?(key_code)
  318.    if @self_repeat.call(key_code)
  319.      return true
  320.    end
  321.    if key_code == C
  322.      return Mouse.repeat?(Mouse::LEFT)
  323.    elsif key_code == B
  324.      return Mouse.repeat?(Mouse::RIGHT)
  325.    else
  326.      return @self_repeat.call(key_code)
  327.    end
  328. end
  329. end
  330. class Window_Selectable
  331. if @self_alias == nil
  332.    alias self_update update
  333.    @self_alias = true
  334. end
  335. def update
  336.    self_update
  337.    if self.active and @item_max > 0
  338.      index_var = @index
  339.      tp_index = @index
  340.      mouse_x, mouse_y = Mouse.get_mouse_pos
  341.      mouse_not_in_rect = true
  342.      for i in 0...@item_max
  343.        @index = i
  344.        update_cursor_rect
  345.        top_x = self.cursor_rect.x + self.x + 16
  346.        top_y = self.cursor_rect.y + self.y + 16
  347.        bottom_x = top_x + self.cursor_rect.width
  348.        bottom_y = top_y + self.cursor_rect.height
  349.        if (mouse_x > top_x) and (mouse_y > top_y) and
  350.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  351.          mouse_not_in_rect = false
  352.          if tp_index != @index
  353.            tp_index = @index
  354.            $game_system.se_play($data_system.cursor_se)
  355.          end
  356.          break
  357.        end
  358.      end
  359.      if mouse_not_in_rect
  360.        @index = index_var
  361.        update_cursor_rect
  362.        Mouse.click_lock
  363.      else
  364.        Mouse.click_unlock               
  365.      end
  366.    end
  367. end
  368. end
  369. class Window_NameInput
  370. if @self_alias == nil
  371.    alias self_update update
  372.    @self_alias = true
  373. end
  374. def update
  375.    self_update
  376.    if self.active
  377.      index_var = @index
  378.      mouse_x, mouse_y = Mouse.get_mouse_pos
  379.      mouse_not_in_rect = true
  380.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  381.        @index = i
  382.        update_cursor_rect
  383.        top_x = self.cursor_rect.x + self.x + 16
  384.        top_y = self.cursor_rect.y + self.y + 16
  385.        bottom_x = top_x + self.cursor_rect.width
  386.        bottom_y = top_y + self.cursor_rect.height
  387.        if (mouse_x > top_x) and (mouse_y > top_y) and
  388.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  389.          mouse_not_in_rect = false
  390.          break
  391.        end
  392.      end
  393.      if mouse_not_in_rect
  394.        @index = index_var
  395.        update_cursor_rect
  396.        Mouse.click_lock
  397.      else
  398.        Mouse.click_unlock
  399.      end
  400.    end
  401. end
  402. end
  403. class Window_InputNumber
  404. if @self_alias == nil
  405.    alias self_update update
  406.    @self_alias = true
  407. end
  408. def update
  409.    self_update
  410.    mouse_x, mouse_y = Mouse.get_mouse_pos
  411.    if self.active and @digits_max > 0
  412.      index_var = @index
  413.      mouse_not_in_rect = true
  414.      for i in 0...@digits_max
  415.        @index = i
  416.        update_cursor_rect
  417.        top_x = self.cursor_rect.x + self.x + 16
  418.        bottom_x = top_x + self.cursor_rect.width
  419.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  420.          mouse_not_in_rect = false
  421.          break
  422.        end
  423.      end
  424.      if mouse_not_in_rect
  425.        @index = index_var
  426.        update_cursor_rect
  427.        Mouse.click_lock
  428.      else
  429.        Mouse.click_unlock
  430.      end
  431.    end
  432.    if @last_mouse_y == nil
  433.      @last_mouse_y = mouse_y
  434.    end
  435.    check_pos = (@last_mouse_y - mouse_y).abs
  436.    if check_pos > 10
  437.      $game_system.se_play($data_system.cursor_se)
  438.      place = 10 ** (@digits_max - 1 - @index)
  439.      n = @number / place % 10
  440.      @number -= n * place
  441.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  442.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  443.      @number += n * place
  444.      refresh
  445.      @last_mouse_y = mouse_y
  446.    end
  447. end
  448. end
  449. class Scene_File
  450. if @self_alias == nil
  451.    alias self_update update
  452.    @self_alias = true
  453. end
  454. def update
  455.    mouse_x, mouse_y = Mouse.get_mouse_pos
  456.    Mouse.click_lock
  457.    idx = 0
  458.    for i in @savefile_windows
  459.      top_x = i.x + 16
  460.      top_y = i.y + 16
  461.      bottom_x = top_x + i.width
  462.      bottom_y = top_y + i.height
  463.      if (mouse_x > top_x) and (mouse_y > top_y) and
  464.         (mouse_x < bottom_x) and (mouse_y < bottom_y)
  465.        i.selected = true
  466.        if @file_index != idx
  467.          @file_index = idx
  468.          $game_system.se_play($data_system.cursor_se)
  469.        end            
  470.        Mouse.click_unlock
  471.      else
  472.        i.selected = false
  473.      end
  474.      idx += 1
  475.    end
  476.    self_update
  477. end
  478. end
  479. class Arrow_Enemy
  480. if @self_alias == nil
  481.    alias self_update update
  482.    @self_alias = true
  483. end
  484. def update
  485.    mouse_x, mouse_y = Mouse.get_mouse_pos
  486.    idx = 0
  487.    for i in $game_troop.enemies do
  488.      if i.exist?
  489.        top_x = i.screen_x - self.ox
  490.        top_y = i.screen_y - self.oy
  491.        bottom_x = top_x + self.src_rect.width
  492.        bottom_y = top_y + self.src_rect.height
  493.        if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  494.           (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  495.          if @index != idx
  496.            $game_system.se_play($data_system.cursor_se)
  497.            @index = idx
  498.          end
  499.        end
  500.      end
  501.      idx += 1
  502.    end
  503.    self_update
  504. end
  505. end
  506. class Arrow_Actor
  507. if @self_alias == nil
  508.    alias self_update update
  509.    @self_alias = true
  510. end
  511. def update
  512.    mouse_x, mouse_y = Mouse.get_mouse_pos
  513.    idx = 0
  514.    for i in $game_party.actors do
  515.      if i.exist?
  516.        top_x = i.screen_x - self.ox
  517.        top_y = i.screen_y - self.oy
  518.        bottom_x = top_x + self.src_rect.width
  519.        bottom_y = top_y + self.src_rect.height
  520.        if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  521.           (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  522.          if @index != idx
  523.            $game_system.se_play($data_system.cursor_se)
  524.            @index = idx
  525.          end
  526.        end
  527.      end
  528.      idx += 1
  529.    end
  530.    self_update
  531. end
  532. end
  533. #==============================================================================
  534. # ■ Game_Player
  535. #------------------------------------------------------------------------------
  536. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  537. # 本类的实例请参考 $game_player。
  538. #   鼠标控制角色的主程序
  539. #==============================================================================
  540. class Game_Player
  541. if @self_alias == nil
  542.    alias self_update update
  543.    @self_alias = true
  544. end
  545. #--------------------------------------------------------------------------
  546. # ● 得到鼠标的状态
  547. #--------------------------------------------------------------------------
  548. def get_mouse_sta
  549.    return @mouse_sta
  550. end
  551. #--------------------------------------------------------------------------
  552. # ● 完整鼠标系统
  553. #--------------------------------------------------------------------------
  554. def update
  555.    mouse_x, mouse_y = Mouse.get_mouse_pos
  556.    @mtp_x = mouse_x
  557.    @mtp_y = mouse_y
  558.    unless $game_system.map_interpreter.running? and @mouse_sta == 2 #鼠标状态不为跟随状态
  559.      #得到鼠标图标方向
  560.      $mouse_icon_id = $game_map.check_event_custom(mouse_x,mouse_y)  if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
  561.    else
  562.      #令鼠标图标为正常
  563.      $mouse_icon_id = 0 if @mouse_sta != 2
  564.    end
  565.    
  566.    #单击鼠标时进行判断寻路或跟随
  567.    if Mouse.trigger?(Mouse::LEFT) #当点击鼠标时
  568.      unless $game_system.map_interpreter.running? or
  569.             @move_route_forcing or $game_temp.message_window_showing #各种无效情况的排除
  570.        #初始化
  571.        @mouse_sta = 1
  572.        p_direction = 5
  573.        #检查鼠标处能否开启事件
  574.        event_start,p_direction = $game_map.check_event_custom_start(mouse_x, mouse_y)
  575.        #若在移动中再次点击鼠标左键(即双击左键),则改鼠标状态为跟随状态
  576.        @mouse_sta = 2 if @paths_id != nil and @paths_id != @paths.size
  577.        if @mouse_sta != 2
  578.          #鼠标状态不为跟随状态则取数据并初始化路径
  579.          trg_x = (mouse_x + $game_map.display_x / 4) / 32
  580.          trg_y = (mouse_y + $game_map.display_y / 4) / 32
  581.          @paths = []
  582.          @paths_id = 0
  583.          if event_start == 0 #若不能开启事件
  584.            if trg_x != $game_player.x or trg_y != $game_player.y #若目标不为自身则开始寻路
  585.              find_path = Find_Path.new
  586.              @paths = find_path.find_player_short_path(trg_x, trg_y, @mtp_x, @mtp_y)
  587.            end
  588.          else #若能开启事件则改变角色朝向
  589.            @direction = p_direction
  590.          end
  591.        end
  592.      end
  593.    end
  594.    #开始移动
  595.    if @mouse_sta != nil and @mouse_sta == 1 #若鼠标状态为寻路状态
  596.      unless moving? or $game_system.map_interpreter.running? or
  597.             @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  598.        if @paths_id != nil and @paths != nil and @paths_id <= @paths.size #若没有完成路径
  599.          case @paths[@paths_id] #判断路径
  600.          when 6
  601.            @last_move_x = true
  602.            move_right
  603.            @paths_id += 1
  604.            @direction = 6
  605.          when 4
  606.            @last_move_x = true
  607.            move_left
  608.            @paths_id += 1
  609.            @direction = 4
  610.          when 2
  611.            @last_move_x = false
  612.            move_down
  613.            @direction = 2
  614.            @paths_id += 1
  615.          when 8
  616.            @last_move_x = false
  617.            move_up
  618.            @direction = 8
  619.            @paths_id += 1
  620.          end
  621.        end
  622.      end
  623.    elsif @paths != nil and @mouse_sta == 2 #当鼠标状态为跟随,且在移动中
  624.      if Mouse.press?(Mouse::LEFT) #持续按住鼠标
  625.        unless moving? or $game_system.map_interpreter.running? or
  626.               @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  627.          #跟随方向判断并跟随
  628.          if @mtp_x > self.screen_x
  629.            if @mtp_y - self.screen_y > - ( @mtp_x - self.screen_x ) and
  630.               @mtp_y - self.screen_y < @mtp_x - self.screen_x
  631.              move_right
  632.              $mouse_icon_id = 16
  633.              @direction = 6
  634.            end
  635.            if @mtp_y - self.screen_y > @mtp_x - self.screen_x
  636.              move_down
  637.              $mouse_icon_id = 12
  638.              @direction = 2
  639.            end
  640.            if @mtp_y - self.screen_y < - ( @mtp_x - self.screen_x )
  641.              move_up
  642.              $mouse_icon_id = 18
  643.              @direction = 8
  644.            end
  645.          end
  646.          if @mtp_x < self.screen_x
  647.            if @mtp_y - self.screen_y > - ( self.screen_x - @mtp_x ) and
  648.               @mtp_y - self.screen_y < self.screen_x - @mtp_x
  649.              move_left
  650.              $mouse_icon_id = 14
  651.              @direction = 4
  652.            end
  653.            if @mtp_y - self.screen_y > self.screen_x - @mtp_x
  654.              move_down
  655.              $mouse_icon_id = 12
  656.              @direction = 2
  657.            end
  658.            if @mtp_y - self.screen_y < - ( self.screen_x - @mtp_x )
  659.              move_up
  660.              $mouse_icon_id = 18
  661.              @direction = 8
  662.            end
  663.          end
  664.        end
  665.      else #没状态的情况
  666.        $mouse_icon_id = 0
  667.        @mouse_sta = 0
  668.        @paths_id = @paths.size #终止寻路移动
  669.      end
  670.    end
  671. self_update
  672. end
  673. end
  674. Mouse.init
  675. END { Mouse.exit }
复制代码

四方向寻路(完整鼠标专用):
  1. #==============================================================================
  2. # ■ Find_Path
  3. #------------------------------------------------------------------------------
  4. #  寻路算法--完整鼠标系统(四方向)专用版
  5. #   By whbm
  6. #==============================================================================
  7. class Find_Path
  8. #--------------------------------------------------------------------------
  9. def initialize  #初始化
  10. @open_list = []
  11. @close_lise = []
  12. @path = []
  13. end  #结束初始化
  14. #--------------------------------------------------------------------------
  15. def fp_passable?(x, y, d, tr_x = -2, tr_y = -2)  #开始判定通行
  16. return false if (tr_x == @unable_xa or
  17.                  tr_x == @unable_xb or
  18.                  tr_y == @unable_ya or
  19.                  tr_y == @unable_yb)
  20. if [2, 4, 6, 8].include?(d)
  21.    if $game_player.passable?(x, y, d)
  22.      return true
  23.    else
  24.      return false
  25.    end
  26. end
  27. end  #结束判定通行
  28. #--------------------------------------------------------------------------
  29. def get_g(now_point)  #开始计算G值
  30. d = now_point[2]
  31. return 0 if d == 5
  32. father_point = get_father_point(now_point)
  33. g = father_point[3] + 10
  34. return g
  35. end  #结束计算G值
  36. #--------------------------------------------------------------------------
  37. def get_h(now_point)  #开始计算H值
  38. now_x = now_point[0]
  39. now_y = now_point[1]
  40. #print @trg_x,now_x,@trg_y,now_y
  41. h = (@trg_x - now_x).abs + (@trg_y - now_y).abs
  42. return h * 10
  43. end  #结束计算H值
  44. #--------------------------------------------------------------------------
  45. def get_f(now_point)  #开始计算F值
  46. f = now_point[3] + now_point[4]
  47. return f
  48. end  #结束计算F值
  49. #--------------------------------------------------------------------------
  50. def get_point(x, y) #取已知坐标点
  51. if @open_list.size != 0
  52.    @open_list.each do |point|
  53.      if point[0] == x and point[1] == y
  54.        return point
  55.        break
  56.      end
  57.    end
  58. end
  59. if @close_list.size != 0
  60.    @close_list.each do |point|
  61.      if point[0] == x and point[1] == y
  62.        return point
  63.        break
  64.      end
  65.    end
  66. end
  67. end  #结束取已知坐标点
  68. #--------------------------------------------------------------------------
  69. def get_father_point(now_point)  #取已知点的父节点
  70. d = now_point[2]
  71. return now_point if d == 5
  72. x = now_point[0] + (d == 6 ? 1 : (d == 4 ? -1 : 0))
  73. y = now_point[1] + (d == 2 ? 1 : (d == 8 ? -1 : 0))
  74. return get_point(x, y)
  75. end  #结束取已知点的父节点
  76. #--------------------------------------------------------------------------
  77. def new_point(x, y, d)  #开始建立新节点
  78. #print x,y,d
  79. point = [x, y, d]
  80. point.push get_g(point)
  81. point.push get_h(point)
  82. point.push get_f(point)
  83. return point
  84. end  #结束建立新节点
  85. #--------------------------------------------------------------------------
  86. def get_direction(self_x, self_y, trg_x, trg_y)
  87.   if trg_x > self_x
  88.     if trg_y - self_y > -  ( trg_x - self_x ) and
  89.       trg_y - self_y < ( trg_x - self_x )
  90.       return 6
  91.     end
  92.     if trg_y - self_y > ( trg_x - self_x )
  93.       return 2
  94.     end
  95.     if trg_y - self_y < - ( trg_x - self_x )
  96.       return 8
  97.     end
  98.   end
  99.   if trg_x < self_x
  100.     if trg_y - self_y > - ( self_x - trg_x ) and
  101.       trg_y - self_y < ( self_x - trg_x )
  102.       return 4
  103.     end
  104.     if trg_y - self_y > ( self_x - trg_x )
  105.       return 2
  106.     end
  107.     if trg_y - self_y < - ( self_x - trg_x )
  108.       return 8
  109.     end
  110.   end
  111. end
  112. #--------------------------------------------------------------------------
  113. def get_d_x_y(x, y, d)
  114.   d_x = x + (d == 6 ? 1 : (d == 4 ? -1 : 0))
  115.   d_y = y + (d == 2 ? 1 : (d == 8 ? -1 : 0))
  116.   return d_x, d_y
  117. end
  118. #--------------------------------------------------------------------------
  119. def find_short_path_other(self_x, self_y, trg_x, trg_y,
  120.                           real_self_x, real_self_y, real_trg_x, real_trg_y)
  121.   @self_x = self_x
  122.   @self_y = self_y
  123.   @now_x = self_x
  124.   @now_y = self_y
  125.   @trg_x = trg_x
  126.   @trg_y = trg_y
  127.   @path = []
  128.   direction = get_direction(real_self_x, real_self_y, real_trg_x, real_trg_y)
  129.   @now_trg_x, @now_trg_y = get_d_x_y(@self_x, @self_y, direction)
  130.   while fp_passable?(@now_x, @now_y, direction)
  131.     @path.push direction
  132.     @now_x = @now_trg_x
  133.     @now_y = @now_trg_y
  134.     @now_trg_x, @now_trg_y = get_d_x_y(@now_x, @now_y, direction)
  135.   end
  136.   return @path
  137. end
  138. #--------------------------------------------------------------------------
  139. def find_short_path(self_x, self_y, trg_x, trg_y,
  140.                     real_self_x, real_self_y, real_trg_x, real_trg_y)  #开始搜索路径
  141.   
  142. return find_short_path_other(self_x, self_y, trg_x, trg_y,
  143.                               real_self_x, real_self_y, real_trg_x, real_trg_y) if not
  144.                   (fp_passable?(trg_x, trg_y + 1, 8) or
  145.                    fp_passable?(trg_x + 1, trg_y, 4) or
  146.                    fp_passable?(trg_x - 1, trg_y, 6) or
  147.                    fp_passable?(trg_x, trg_y - 1, 2)) and @goal_type != 1
  148.                   
  149.                   
  150.   #根据屏幕限定搜索面积..加速
  151. @unable_xa = $game_map.display_x / 128 - 1
  152. @unable_ya = $game_map.display_y / 128 - 1
  153. @unable_xb = $game_map.display_x / 128 + 20
  154. @unable_yb = $game_map.display_y / 128 + 20
  155. @self_x = self_x
  156. @self_y = self_y
  157. @now_x = self_x
  158. @now_y = self_y
  159. @trg_x = trg_x
  160. @trg_y = trg_y
  161. @open_list = []
  162. @close_list = []
  163. #准备搜索
  164. #print @self_x,@self_y
  165. @now_point = new_point(@self_x, @self_y, 5) #令起始点为当前点
  166. @open_list.push @now_point #将当前点加入关闭列表
  167. #开始搜索
  168. begin
  169. loop do
  170.    check_trg = check_around_point(@now_point)
  171.    if check_trg == true
  172.      @path = get_path
  173.      break
  174.    end
  175.    @now_point = get_lowest_f_point
  176.    if @now_point == [] or @now_point == nil
  177.      @path = []
  178.      break
  179.    end
  180. end
  181. rescue Hangup
  182.   retry
  183. end
  184. return @path
  185. end  #结束搜索路径
  186. #--------------------------------------------------------------------------
  187. def find_player_short_path(trg_x, trg_y,
  188.                            real_trg_x, real_trg_y)  #寻找角色的最短路径
  189. self_x = $game_player.x
  190. self_y = $game_player.y
  191. real_self_x = $game_player.screen_x
  192. real_self_y = $game_player.screen_y
  193. @goal_type, event = $game_map.check_event_custom_exist(real_trg_x, real_trg_y)
  194. if @goal_type == 1
  195.    trg_x = event.x
  196.    trg_y = event.y
  197. end
  198. return find_short_path(self_x, self_y, trg_x, trg_y,
  199.                         real_self_x, real_self_y, real_trg_x, real_trg_y)
  200. end  #结束角色的寻找路径
  201. #--------------------------------------------------------------------------
  202. def get_path  #取得最终的路径
  203. path = []
  204. now_point = @open_list[@open_list.size - 1]
  205. path.push(10 - now_point[2])
  206. last_point = now_point
  207. loop do
  208.    now_point = get_father_point(now_point)
  209.    break if now_point[2] == 5
  210.    path.push(10 - now_point[2])
  211. end
  212. return path.reverse
  213. end  #结束取得最终的路径
  214. #--------------------------------------------------------------------------
  215. def get_lowest_f_point  #开始取得最低F值的点
  216. if @open_list == []
  217.    return []
  218. end
  219. last_lowest_f_point = @open_list[0]
  220. @open_list.each do |point|
  221.    last_lowest_f_point = point if point[5] < last_lowest_f_point[5]
  222. end
  223. return last_lowest_f_point
  224. end  #结束取得最低F值点
  225. #--------------------------------------------------------------------------
  226. def check_around_point(point)  #开始检查已知点的八方节点
  227. for d in [1, 2, 3, 4, 6, 7, 8, 9]
  228.    x = point[0] + ((d == 9 or d == 6 or d == 3) ? 1 : ((d == 7 or d == 4 or d == 1) ? -1 : 0))
  229.    y = point[1] + ((d == 1 or d == 2 or d == 3) ? 1 : ((d == 7 or d == 8 or d == 9) ? -1 : 0))
  230.    if in_close_list?(x, y) #在关闭列表中
  231.      next
  232.    elsif in_open_list?(x, y) #在开启列表中
  233.      get_new_g_point = new_point(x, y, 10 - d)
  234.      get_last_g_point = get_point(x, y)
  235.      if get_new_g_point[3] >= get_last_g_point[3]
  236.        next
  237.      else
  238.        #如果改变父节点是新G值更小则确定改变
  239.        @open_list[@open_list.index(get_last_g_point)] = get_new_g_point
  240.      end
  241.    else
  242.      if fp_passable?(point[0], point[1], d, x, y)
  243.        # 如果不在开启列表中、且不在关闭列表中、且通行则添加它到新八周节点
  244.        @open_list.push new_point(x, y, 10 - d)
  245.        #如果将目标点添加到了开启列表中就返回true
  246.        return true if x == @trg_x and y == @trg_y
  247.        return true if @goal_type == 1 and [1, 0, -1].include?(x - @trg_x) and [1, 0, -1].include?(y - @trg_y)
  248.      end
  249.    end
  250. end
  251. #此刻没有找到目标点并将当前点加入关闭列表并在开启列表中删除
  252. @close_list.push point
  253. @open_list.delete(point)
  254. #此刻没找到目标点并返回false
  255. return false
  256. end  #结束计算已知点的八方节点
  257. #--------------------------------------------------------------------------
  258. def in_open_list?(x, y)  #开始检查谋点是否在开启列表中
  259. @open_list.each do |point|
  260.    return true if point[0] == x and point[1] == y
  261. end
  262. return false
  263. end  #结束检查谋点是否在开启列表中
  264. #--------------------------------------------------------------------------
  265. def in_close_list?(x, y)  #开始检查谋点是否在关闭列表中
  266. @close_list.each do |point|
  267.    return true if point[0] == x and point[1] == y
  268. end
  269. return false
  270. end  #结束检查谋点是否在关闭列表中
  271. #--------------------------------------------------------------------------
  272. end
复制代码
回复 支持 反对

使用道具 举报

550

主题

9116

帖子

214748万

积分

超级版主

如同神一般的存在,腿神!拖后腿的神~~

Rank: 8Rank: 8

积分
2147483647
发表于 2010-6-15 09:17:16 | 显示全部楼层
这么长的东西,就不能直接传个工程。。。
我就是你们的神,庶民们,追随我吧!跟着我一起拖后腿!
回复 支持 反对

使用道具 举报

16

主题

36

帖子

1063

积分

⑥精研

积分
1063
 楼主| 发表于 2010-6-15 11:22:24 | 显示全部楼层
工程下载:
http://u.115.com/file/t243d84e9a
Ella__s_Hope.rar

密码请看短消息,请勿外传。
另外,还要麻烦您一下。
这个游戏中是利用脚本
$game_temp.message_actor_id = 0
来清除头像
利用脚本
$game_temp.message_actor_id = 1
………………
………………
$game_temp.message_actor_id = N
来显示指定的人物头像。
能否帮我改一下,让$game_temp.message_actor_id 不等于0时,顺便在对话框上方出现个名字框,并将对应角色的名字显示上去。等于0时清除头像,顺便也清除名字框。
然后,当对话中有\\name[名字]样的字符后,就将中挎号中的内容显示在名字框里。


只要能帮我解决鼠标问题我就很开心了,关于名字框的请求,如果实在没空就算了。
回复 支持 反对

使用道具 举报

550

主题

9116

帖子

214748万

积分

超级版主

如同神一般的存在,腿神!拖后腿的神~~

Rank: 8Rank: 8

积分
2147483647
发表于 2010-6-15 14:35:18 | 显示全部楼层
外传是不可能的。。。。我本身就讨厌那种人,我拆别人的加密包也是自己拆着玩


话说这个包太大了吧。。。随便放几个图片给我测试就好了
我就是你们的神,庶民们,追随我吧!跟着我一起拖后腿!
回复 支持 反对

使用道具 举报

16

主题

36

帖子

1063

积分

⑥精研

积分
1063
 楼主| 发表于 2010-6-15 14:52:57 | 显示全部楼层
我现在上传的游戏,只要一运行就会变成这样…………
  

如果把
      $mouse_icon_id = $game_map.check_event_custom(rx,ry)  if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
改为
      $mouse_icon_id = 1

那么开始游戏时就是这样:
  

进入地图后就是这样:
  

也就是说,这段代码我没插错地方,但不晓得为什么就是不行…………


麻烦你啦!
另:建议把游戏下下来试试,因为这个游戏的鼠标脚本很乱,分散在各个地方,我虽然把它集中放置在一个地方,并且运行没出错。
但实在很难说是否有漏掉某些小定义之类的…………

本帖子中包含更多资源

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

x
回复 支持 反对

使用道具 举报

550

主题

9116

帖子

214748万

积分

超级版主

如同神一般的存在,腿神!拖后腿的神~~

Rank: 8Rank: 8

积分
2147483647
发表于 2010-6-15 16:09:20 | 显示全部楼层
  1. class Game_Event
  2.   attr_accessor :flag
  3. end
  4. class Game_Map
  5.   #--------------------------------------------------------------------------
  6.   # ● 检查鼠标处是否有自定义的事件并返回类型
  7.   #--------------------------------------------------------------------------
  8.   def check_event_custom(mouse_x, mouse_y)
  9.     for event in $game_map.events.values #循环所有事件检查
  10.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / 4
  11.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 4
  12.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y > event.screen_y - event_height and mouse_y < event.screen_y
  13.         for i in 0...event.list.size
  14.           if event.list[i].parameters[0] == "item" #类型判断
  15.             event.flag = 1
  16.           elsif event.list[i].parameters[0] == "npc" #类型判断
  17.             event.flag = 2
  18.           end
  19.           return event.flag #返回事件类型标志
  20.         end
  21.       end
  22.     end
  23.     return $mouse_icon_id #使鼠标图不变化
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 检查鼠标处是否有事件可以开启
  27.   #--------------------------------------------------------------------------
  28.   def check_event_custom_start(mouse_x, mouse_y)     
  29.     for event in $game_map.events.values #循环所有事件检查
  30.       #事件角色图片宽度、高度
  31.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  32.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  33.       #判断是否鼠标在事件上
  34.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y > event.screen_y - event_height and mouse_y < event.screen_y
  35.         way_x = $game_player.x - event.x
  36.         way_y = $game_player.y - event.y
  37.         if ([1, -1].include?($game_player.x-event.x) and $game_player.y-event.y == 0) or ([1, -1].include?($game_player.y-event.y) and $game_player.x-event.x == 0)
  38.           for i in 0...event.list.size
  39.             if ["item","npc"].include?(event.list[i].parameters[0]) #当事件属于自定义事件
  40.               #判断主角朝向
  41.               if way_x == -1
  42.                 p_direction = 6 if way_y == 0
  43.               elsif way_x == 0
  44.                 p_direction = 2 if way_y == -1
  45.                 p_direction = 8 if way_y == 1
  46.               else
  47.                 p_direction = 4 if way_y == 0
  48.               end
  49.               event.start #开启事件
  50.               return 1, p_direction #返回即将开启事件以及角色朝向
  51.             end
  52.           end
  53.         end
  54.       end
  55.     end
  56.     return 0, 5 #返回不会开启事件以及角色朝向不变
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  60.   #--------------------------------------------------------------------------
  61.   def check_event_custom_exist(mouse_x, mouse_y)
  62.     for event in $game_map.events.values #循环所有事件检查
  63.       #事件角色图片宽度、高度
  64.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  65.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  66.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y > event.screen_y - event_height and mouse_y < event.screen_y
  67.         for i in 0...event.list.size
  68.           return 1, event if ["item", "npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  69.         end
  70.       end
  71.     end
  72.     return 0, event #返回不存在自定义事件,以及事件体
  73.   end
  74. end
  75. # Encapsulation of a mouse event
  76. MouseEvent = Struct.new(:sender, :trigger, :info)
  77. #==============================================================================
  78. # ** Mouse module
  79. #------------------------------------------------------------------------------
  80. # Manages the Win32API calls and the base mouse functionalities
  81. #==============================================================================
  82. module Mouse
  83.   #--------------------------------------------------------------------------
  84.   # * 鼠标输入触发器
  85.   #--------------------------------------------------------------------------
  86.   LEFT_CLICK = 1
  87.   RIGHT_CLICK = 2
  88.   MIDDLE_CLICK = 4
  89.   
  90.   MOUSE_TRIGGERS = [LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK]
  91.   #--------------------------------------------------------------------------
  92.   # * API Declaration
  93.   #--------------------------------------------------------------------------
  94.   $ShowCursor      = Win32API.new("user32", "ShowCursor", 'i', 'l')
  95.   ASYNC_KEY        = Win32API.new('user32', 'GetAsyncKeyState', 'i',     'i')
  96.   SCREEN_TO_CLIENT = Win32API.new('user32', 'ScreenToClient',   %w(l p), 'i')
  97.   CURSOR_POS       = Win32API.new('user32', 'GetCursorPos',     'p',     'i')
  98.   FIND_WINDOW      = Win32API.new('user32', 'FindWindowA',      %w(p p), 'l')
  99.   module_function
  100.   ##
  101.   # Start up procedures
  102.   #
  103.   def start_up
  104.     # 创建一个模块的配置参考
  105.     @@const = System::Mouse
  106.     # 初始化按钮状态
  107.     @button_states = Array.new(5, 0)
  108.     # 计算窗口的句柄
  109.     window_handle
  110.     # 了解鼠标状态
  111.     mouse_status = Utility.read_ini('mouse')
  112.     @enabled = !(mouse_status == '0' || mouse_status == '')
  113.     # 如果鼠标脚本启用则创建鼠标
  114.     if @enabled
  115.       $ShowCursor.call(0)
  116.       # 创建鼠标
  117.       create_cursor
  118.       # 更新游标
  119.       update
  120.     end
  121.   end
  122.   
  123.   
  124.   ##
  125.   # 终止鼠标脚本
  126.   #
  127.   def shutdown
  128.     # 终结掉鼠标
  129.     @mouse_sprite.dispose unless @mouse_sprite.nil? || @mouse_sprite.disposed?
  130.     $ShowCursor.call(1)
  131.   end
  132.   
  133.   ##
  134.   # 打开鼠标脚本
  135.   # 如果它已经打开,什么都不会发生
  136.   #
  137.   def turn_on
  138.     return if self.enabled
  139.     @enabled = true
  140.     # 创建鼠标
  141.     create_cursor
  142.     # 更新游标
  143.     update
  144.   end
  145.   
  146.   ##
  147.   # 鼠标脚本关闭。
  148.   # 如果它已关闭,什么都不会发生
  149.   #
  150.   def turn_off
  151.     return unless self.enabled
  152.     @enabled = false
  153.     # 显示光标如果是隐藏
  154.     unless @mouse_sprite.nil? || @mouse_sprite.disposed?
  155.       # 终止鼠标
  156.       @mouse_sprite.dispose
  157.       # 删除引用,以便将垃圾清除干净
  158.       @mouse_sprite = nil
  159.     end
  160.   end
  161.   
  162.   ##
  163.   # 更新
  164.   #
  165.   def update
  166.     # 只在启用时更新
  167.     return unless self.enabled
  168.     # 取新的位置
  169.     sx, sy = screen_pos
  170.     # 如果鼠标位置发生了变化
  171.     if @sx != sx || @sy != sy
  172.       # 储存新的屏幕x和y
  173.       @sx = sx
  174.       @sy = sy
  175.       # 获取相对位置
  176.       if Input.is_fullscreen  
  177.         rx, ry = sx, sy
  178.       else
  179.         rx, ry = screen_to_client(sx, sy)
  180.       end
  181.       return unless rx >= 0 && rx < 640 && ry >= 0 && ry < 480
  182.       @mouse_sprite.x = rx
  183.       @mouse_sprite.y = ry
  184.       
  185.       
  186.       
  187.       
  188.       #########################################################      
  189.       #可能能在此处判断鼠标图像
  190.       #########################################################
  191.       # 变更光标的位置
  192.       if $scene.is_a?(Scene_Map) == false
  193.          $mouse_icon_id = 0
  194.       end
  195.       if $game_map
  196.         mouse_tmp = $mouse_icon_id
  197.         $mouse_icon_id = $game_map.check_event_custom(rx,ry)# if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
  198.       end
  199.       case $mouse_icon_id
  200.       when 1
  201.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Arrow3.png')
  202.       when 2
  203.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Arrow2.png')
  204.       when 11
  205.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  206.       when 12
  207.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  208.       when 13
  209.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  210.       when 14
  211.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  212.       when 16
  213.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  214.       when 17
  215.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  216.       when 18
  217.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  218.       when 19
  219.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  220.       when 0
  221.         @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/arrow.png')
  222.       end
  223.       if $game_map && mouse_tmp != $mouse_icon_id
  224.         $mouse_icon_id = mouse_tmp
  225.       end
  226.     end
  227.     # 检查点击
  228.     for trigger in MOUSE_TRIGGERS
  229.       # 获取异步状态
  230.       state = ASYNC_KEY.call(trigger)
  231.       # If 0 or 1
  232.       if state == 0 || state == 1
  233.         if @button_states[trigger] > 0
  234.           @button_states[trigger] *= -1
  235.         else
  236.           @button_states[trigger] = 0
  237.         end
  238.       else
  239.         if @button_states[trigger] > 0
  240.           @button_states[trigger] += 1
  241.         else
  242.           @button_states[trigger] = 1
  243.         end
  244.       end
  245.     end
  246.   end
  247.   
  248.   ##
  249.   # Check for press
  250.   #   返回false,如果不启用鼠标
  251.   #
  252.   def press?(id = LEFT_CLICK)
  253.     return false unless self.enabled
  254.     return @button_states[id] >= 1
  255.   end
  256.   
  257.   ##
  258.   # 查触发
  259.   #   返回false,如果不启用鼠标
  260.   #
  261.   def trigger?(id = LEFT_CLICK)
  262.     return false unless self.enabled
  263.     return @button_states[id] == 1
  264.   end
  265.   
  266.   ##
  267.   # 重复检查
  268.   #   返回false,如果不启用鼠标
  269.   #
  270.   def repeat?(id = LEFT_CLICK)
  271.     return false unless self.enabled
  272.     if @button_states[id] <= 0
  273.       return false
  274.     elsif @button_states[id] == 1
  275.       return true
  276.     elsif @button_states[id] > @@const::REPEAT_START_WAIT
  277.       return @button_states[id] % @@const::REPEAT_WAIT == 1
  278.     end
  279.   end
  280.   
  281.   ##
  282.   # 回true如果鼠标脚本启用
  283.   #
  284.   def enabled
  285.     @enabled
  286.   end
  287.   
  288.   ##
  289.   # 获得屏幕坐标
  290.   #
  291.   def screen_pos
  292.     # 包0位置
  293.     pos = [0, 0].pack('ll')
  294.     # 裸装的光标位置返回呼叫
  295.     return CURSOR_POS.call(pos) == 0 ? nil : pos.unpack('ll')
  296.   end
  297.   
  298.   ##
  299.   # 转换屏的X和Y坐标的相对坐标。
  300.   # Top-left corner = (0, 0)
  301.   #
  302.   def pos
  303.     return @mouse_sprite.x, @mouse_sprite.y
  304.   end
  305.   
  306.   ##
  307.   # 检查鼠标是否在窗口内部
  308.   #
  309.   def inside?
  310.     x, y = pos
  311.     return x >= 0 && x < 640 && y >= 0 && y < 480
  312.   end
  313.   
  314.   ##
  315.   # 屏幕坐标转换为相对的客户端窗口
  316.   #
  317.   def screen_to_client(x, y)
  318.     # 如果X和Y空返回零
  319.     return nil unless x and y
  320.     if @ori_pos.nil?
  321.       @stc_wait = 0
  322.     end
  323.     if @stc_wait <= 0
  324.       # Locate upper-left corner
  325.       pack = [0, 0].pack('ll')
  326.       SCREEN_TO_CLIENT.call(window_handle, pack)
  327.       @ori_pos = pack.unpack('ll')
  328.       # 等待10帧以开始下一次查找
  329.       @stc_wait = 10
  330.     else
  331.       @stc_wait -= 1
  332.     end
  333.     # Translocate X- and Y-coordinates
  334.     x += @ori_pos[0]
  335.     y += @ori_pos[1]
  336.     return x, y
  337.   end
  338.   
  339.   ##
  340.   # 检索窗口句柄
  341.   #
  342.   def window_handle
  343.     if @window_handle.nil?
  344.       # 游戏名称查找
  345.       game_name = Utility.read_ini('Title')
  346.       # 查找窗口
  347.       @window_handle = FIND_WINDOW.call('RGSS Player', game_name)
  348.     end
  349.     return @window_handle
  350.   end
  351.   
  352.   # 开辟了单独的类模块的
  353.   class << self
  354.     ###################
  355.     # Private methods #
  356.     ###################
  357.     private
  358.     ##
  359.     # 创建光标
  360.     #
  361.     def create_cursor
  362.       @mouse_sprite = Sprite.new
  363.       @mouse_sprite.z = 50000
  364.       @mouse_sprite.bitmap = RPG::Cache.icon(@@const::DEFAULT_ICON)
  365.     end
  366.   end
  367. end
  368. class Window_Base
  369.   ##
  370.   # 更新鼠标位置
  371.   # Mouse enabled subclasses should overwrite this method
  372.   #
  373.   def mouse_move(mx, my)
  374.     return unless $DEBUG
  375.     raise StandardError.new("mouse_move(mx, my) was not overwritten in #{self.class}")
  376.   end
  377.   
  378.   ##
  379.   # 更新鼠标(只有当鼠标启用时才调用)
  380.   # Note: The mouse is over the window
  381.   #
  382.   def mouse_update
  383.     return unless $DEBUG
  384.     raise StandardError.new("mouse_update was not overwritten in #{self.class}")
  385.   end
  386.   
  387.   ##
  388.   # 判断鼠标位置是否超过窗口,是的话让鼠标图像停留在窗口边框
  389.   #
  390.   def over_contents?(mx, my)
  391.     return mx >= 16 && mx < width - 16 &&
  392.            my >= 16 && my < height - 16
  393.   end
  394. end
  395. class Window_Selectable
  396.   ##
  397.   # Get the height of the elements
  398.   #
  399.   def element_height
  400.     return 32
  401.   end
  402.   
  403.   ##
  404.   # Get the height of the elements
  405.   #
  406.   def element_width
  407.     return self.width / @column_max - 32
  408.   end
  409.   
  410.   ##
  411.   # Calculates the index from the x and y coordinate
  412.   # Assumes (0,0) to be upper-left corner of the contents
  413.   #
  414.   def calculate_index(x, y)
  415.     ex = x / element_width
  416.     ey = y / element_height
  417.     return ex + (ey + top_row) * @column_max
  418.   end
  419.   
  420.   ##
  421.   #
  422.   #
  423.   def cause_scroll(index)
  424.     # Get  row
  425.     row = index / @column_max
  426.     # If row is before top row or more to back than back row
  427.     return row < self.top_row || row > self.top_row + (self.page_row_max - 1)
  428.   end
  429.   ##
  430.   # 更新鼠标位置
  431.   # Mouse enabled subclasses should overwrite this method
  432.   #
  433.   def mouse_move(mx, my)
  434.     # Cursor position less than 0 implies that the cursor is hidden
  435.     return if @index < 0 || !self.active
  436.     # Store the coordinates
  437.     @mx, @my = mx, my
  438.    
  439.     # Ignore the move if it is not over the contents
  440.     if mx >= 16 && mx < width - 16
  441.       index = calculate_index(mx-16, my-16)
  442.       # If the index is valid
  443.       if index < @item_max && index >= 0
  444.         # Scroll wait
  445.         if cause_scroll(index) && self.scroll_wait > 0
  446.           return
  447.         elsif cause_scroll(index)
  448.           self.scroll_wait = System::Mouse::SCROLL_WAIT
  449.           @scrolling = true
  450.         else
  451.           @scrolling = false
  452.         end
  453.         # Change the index
  454.         @index = index
  455.       end
  456.     end
  457.   end
  458.   
  459.   ##
  460.   # Update mouse (Only called if mouse is enabled)
  461.   # Note: The mouse is over the window
  462.   #
  463.   def mouse_update
  464.     # Only update if active
  465.     return unless self.active
  466.     # Scroll wait update
  467.     if self.scroll_wait > 0
  468.       self.scroll_wait -= 1
  469.       return
  470.     elsif @scrolling
  471.       # See if the scrolling should continue
  472.       index = calculate_index(@mx-16, @my-16)
  473.       if cause_scroll(index) && index < @item_max && index >= 0
  474.         self.scroll_wait = System::Mouse::SCROLL_WAIT
  475.         @index = index
  476.       else
  477.         # Stop scrolling
  478.         @scrolling = false
  479.       end
  480.     end
  481.     @mx, @my = -1, -1 if @mx.nil?
  482.     # Check for click
  483.     if Mouse.trigger?(Mouse::LEFT_CLICK) && over_contents?(@mx, @my)
  484.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  485.     end
  486.   end
  487. end
  488. class Window_Target
  489.   ##
  490.   # Update mouse position
  491.   # Mouse enabled subclasses should overwrite this method
  492.   #
  493.   def mouse_move(mx, my)
  494.     return unless self.active
  495.     if @index >= 0
  496.       super
  497.       return
  498.     else
  499.       # Store the coordinates
  500.       @mx, @my = mx, my
  501.     end
  502.   end
  503.   ##
  504.   # Update mouse (Only called if mouse is enabled)
  505.   # Note: The mouse is over the window
  506.   #
  507.   def mouse_update
  508.     if @index >= 0
  509.       super
  510.       return
  511.     else
  512.       # Only update if active
  513.       return unless self.active
  514.       @mx, @my = -1, -1 if @mx.nil?
  515.       # Check for click
  516.       if Mouse.trigger?(Mouse::LEFT_CLICK) && over_contents?(@mx, @my)
  517.         owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  518.       end
  519.     end
  520.   end
  521. end
  522. class Window_NameInput  
  523.   ##
  524.   # Determines whether the given coordinates are within the given area
  525.   #
  526.   def is_in?(x,y, rx,ry,rw,rh)
  527.     return x >= rx && x < rx + rw &&
  528.            y >= ry && y < ry + rh
  529.   end
  530.   
  531.   ##
  532.   # Calculates the index from the coordinates
  533.   #
  534.   def calculate_index(x, y)
  535.     # Check [OK] position
  536.     return 90 if is_in?(x,y,  428, 9 * 32, 48, 32)
  537.     if is_in?(x,y,  140, 0, 5*32, 9*32)
  538.       # Left box
  539.       x = (x - 140) / 32
  540.       y /= 32
  541.       return x + y * 5
  542.     elsif is_in?(x,y,  320, 0, 5*32, 9*32)
  543.       # Right box
  544.       x = (x - 320) / 32
  545.       y /= 32
  546.       return x + y * 5 + 45
  547.     end
  548.     # Outside
  549.     return -1
  550.   end
  551.   
  552.   ##
  553.   # Update mouse position
  554.   # Mouse enabled subclasses should overwrite this method
  555.   #
  556.   def mouse_move(mx, my)
  557.     @mx, @my = mx, my
  558.     index = calculate_index(mx-16, my-16)
  559.     @index = index unless index < 0
  560.   end
  561.   
  562.   ##
  563.   # Update mouse (Only called if mouse is enabled)
  564.   # Note: The mouse is over the window
  565.   #
  566.   def mouse_update
  567.     if Mouse.trigger?(Mouse::LEFT_CLICK) && calculate_index(@mx-16, @my-16) >= 0
  568.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  569.     end
  570.   end
  571. end
  572. class Window_Message
  573.   ##
  574.   # Check for normal trigger
  575.   #
  576.   def normal_trigger?
  577.     return true if Input.trigger?(Input::C)
  578.     if Mouse.trigger?(Mouse::LEFT_CLICK)
  579.       return true if $game_temp.choice_max <= 0
  580.       index = calculate_index(@mx - 16, @my - 16)
  581.       return true if index >= 0 && index < @item_max
  582.     end
  583.   end
  584.   
  585.   ##
  586.   # Update mouse (Only called if mouse is enabled)
  587.   #
  588.   def mouse_update
  589.     # Do nothing
  590.   end
  591.   
  592.   ##
  593.   # Calculates the index from the x and y coordinate
  594.   # Assumes (0,0) to be upper-left corner of the contents
  595.   #
  596.   def calculate_index(x, y)
  597.     return -1 if x > @cursor_width + 8
  598.     ey = (y - $game_temp.choice_start * 32) / element_height
  599.     return (ey + top_row) * @column_max
  600.   end
  601. end
  602. class Arrow_Base
  603.   ##
  604.   # Update mouse (Only called if mouse is enabled)
  605.   # Note: The mouse is over the window
  606.   #
  607.   def mouse_update
  608.     return unless $DEBUG
  609.     raise StandardError.new("mouse_update was not overwritten in #{self.class}")
  610.   end
  611. end
  612. class Arrow_Enemy  
  613.   ##
  614.   # Update mouse position
  615.   #
  616.   def mouse_move(mx, my)
  617.     # Pass Through Enemies
  618.     for enemy in $game_troop.enemies
  619.       # Skip if Non-Existing Enemy
  620.       next unless enemy.exist?
  621.       # Gets Paddings
  622.       w, h = enemy.battler_width / 2, enemy.battler_height
  623.       # If Within Mouse Padding Range
  624.       if mx.between?(enemy.screen_x - w, enemy.screen_x + w) &&
  625.          my.between?(enemy.screen_y - h, enemy.screen_y + 10)
  626.         # Set Index
  627.         @index = $game_troop.enemies.index(enemy)
  628.         break
  629.       end
  630.     end
  631.   end
  632.   
  633.   ##
  634.   # Update mouse (Only called if mouse is enabled)
  635.   #
  636.   def mouse_update
  637.     if Mouse.trigger?(Mouse::LEFT_CLICK)# && @my < 320
  638.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  639.     end
  640.     mx, my = Mouse.pos
  641.     return if @mx == mx && @my == my
  642.     @mx, @my = mx, my
  643.     # Pass Through Enemies
  644.     for enemy in $game_troop.enemies
  645.       # Skip if Non-Existing Enemy
  646.       next unless enemy.exist?
  647.       # Gets Paddings
  648.       w, h = enemy.battler_width / 2, enemy.battler_height
  649.       # If Within Mouse Padding Range
  650.       if mx.between?(enemy.screen_x - w, enemy.screen_x + w) &&
  651.          my.between?(enemy.screen_y - h, enemy.screen_y + 10)
  652.         # Set Index
  653.         @index = $game_troop.enemies.index(enemy)
  654.         break
  655.       end
  656.     end
  657.   end
  658. end
  659. class Arrow_Actor
  660.   ##
  661.   # Update mouse (Only called if mouse is enabled)
  662.   #
  663.   def mouse_update
  664.     if Mouse.trigger?(Mouse::LEFT_CLICK)# && @my > 288
  665.       owner.fireEvent(MouseEvent.new(self, Mouse::LEFT_CLICK, @index))
  666.     end
  667.     # Get mouse position
  668.     mx, my = Mouse.pos
  669.     # Checks that the mouse have moved
  670.     return if @mx == mx && @my == my
  671.     # Store new position
  672.     @mx, @my = mx, my
  673.     # Pass Through Actors
  674.     for actor in $game_party.actors
  675.       # Gets Paddings
  676.       w, h = actor.battler_width / 2, actor.battler_height
  677.       # If Within Mouse Padding Range
  678.       if mx.between?(actor.screen_x - w, actor.screen_x + w) &&
  679.          my.between?(actor.screen_y - h, actor.screen_y + 10)
  680.         # Set Index
  681.         @index = $game_party.actors.index(actor)
  682.       end
  683.     end
  684.   end
  685. end
复制代码
我就是你们的神,庶民们,追随我吧!跟着我一起拖后腿!
回复 支持 反对

使用道具 举报

550

主题

9116

帖子

214748万

积分

超级版主

如同神一般的存在,腿神!拖后腿的神~~

Rank: 8Rank: 8

积分
2147483647
发表于 2010-6-15 16:11:47 | 显示全部楼层
这个就是把原来的鼠标替换掉就好了。。。就是你给我的那个工程里的Mouse module完全用这个替换掉

用法。。。事件页第一句 用事件脚本 里面 写npc  代表变成 对话图标
item 代表 抓手图标。。。以上
我就是你们的神,庶民们,追随我吧!跟着我一起拖后腿!
回复 支持 反对

使用道具 举报

550

主题

9116

帖子

214748万

积分

超级版主

如同神一般的存在,腿神!拖后腿的神~~

Rank: 8Rank: 8

积分
2147483647
发表于 2010-6-15 16:13:40 | 显示全部楼层
另外。。。关于对话的。。。你直接引进 fuki吧。。。反正你是要翻译的对吧?不如用fuki还好一些
我就是你们的神,庶民们,追随我吧!跟着我一起拖后腿!
回复 支持 反对

使用道具 举报

16

主题

36

帖子

1063

积分

⑥精研

积分
1063
 楼主| 发表于 2010-6-15 16:24:05 | 显示全部楼层
好感动哦!
secondsen 斑竹是世界第一大好人!辛苦了!
我马上改去!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2024-4-29 12:02 , Processed in 0.037163 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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