查看: 1417|回复: 1

[已经过期] 鼠标脚本求修改

[复制链接]
梦石
0
星屑
50
在线时间
137 小时
注册时间
2012-8-27
回帖
86
发表于 2012-12-1 22:47:01 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 Mic_洛洛 于 2012-12-4 15:51 编辑

如何使这个脚本的鼠标不在地图显示,只在菜单中起作用?
  1. #===============================================================================
  2. # Mouse System (RGSS3)
  3. # By Jet10985(Jet)
  4. # Some Code by: Woratana, Berka
  5. # Uses: ListRA-92's Path Finding
  6. # Super Heavy Testing/Debug Help/Requested By: Nathanial(Beleren)
  7. #===============================================================================
  8. # This script will allow full use of the mouse inside of rmvx for various
  9. # purposes.
  10. # This script has: 7 customization options.
  11. #===============================================================================
  12. # Overwritten Methods:
  13. # Game_Player: move_by_input
  14. #-------------------------------------------------------------------------------
  15. # Aliased methods:
  16. # Scene_Map: update, terminate, update_transfer_player
  17. # Input: update, trigger?, press?, repeat?, dir4, dir8
  18. # Window_Selectable: update, top_row=
  19. # Scene_File: update
  20. # Window_NameInput: update
  21. # Game_Temp: initialize
  22. # Game_Event: initialize, update
  23. #===============================================================================

  24. =begin
  25. Showing text above event when mouse hovers:

  26. If you want a message to appear over an event's head if the mouse is hovering
  27. over the event, put this comment in the event:

  28. MOUSE TEXT MESSAGE HERE

  29. everything after TEXT will be the hovering display.
  30. --------------------------------------------------------------------------------
  31. Change mouse picture above event when mouse hovers:

  32. If you want the mouse's picture to temporarily change whne over an event, put
  33. this comment in the event

  34. MOUSE PIC NAME/NUMBER

  35. if you put a name, the mouse will become that picture, but if you put a number
  36. then the mouse will become the icon that is the id number
  37. --------------------------------------------------------------------------------
  38. Specific mouse click movement routes:

  39. If you want the player to land specifically in a square around an event when
  40. they click to move on the event, put one of these comments in the event:

  41. MOUSE MOVE UP/LEFT/RIGHT/DOWN

  42. only put the direction that you want the player to land on.
  43. --------------------------------------------------------------------------------
  44. Click to activate:

  45. If you want an event to automatically start when it is clicked on, place
  46. this in an event comment:

  47. MOUSE CLICK
  48. --------------------------------------------------------------------------------
  49. Don't stop the player when walking over a touch event:

  50. By default, this script will stop a mouse-caused movement if the player walks
  51. over/under a player touch/event touch event. If you want the event to activate,
  52. but for the player to keep walking to their destination, put this comment in the
  53. event:

  54. MOUSE NOSTOP
  55. --------------------------------------------------------------------------------
  56. Ignore Events:

  57. To have an event be ignored when the mouse makes it's movement path(as if the
  58. event isn't there), put this comment in the event:

  59. MOUSE THROUGH
  60. --------------------------------------------------------------------------------
  61. Extra Notes:

  62. In selectable windows that have more items than what's shown, players can
  63. either put the mouse below the window to scroll down, OR use the mouse's
  64. scroll wheel to scroll up/down.

  65. You can activate action button events by standing next to the event and clicking
  66. on it with the mouse.
  67. =end
  68. module JetMouse
  69.   
  70.   # If you are using a graphic, this is it.
  71.   # It must be in the Graphics/System folder.
  72.   CURSOR_PICTURE = "cursor-mouse"
  73.   
  74.   # If you aren't using a graphic, this icon will be the mouse.
  75.   # To use the icon, just put a non-existant picture as the above config
  76.   ICON_INDEX = 387
  77.   
  78.   # Do you want the player to be able to move by clicking the mouse?
  79.   ALLOW_MOUSE_MOVEMENT = true
  80.   
  81.   # Do you want mouse movement to do 8-dir walking?
  82.   # Requires 8-Dir Walking by Jet.
  83.   DO_8DIR_WALKING = false
  84.   
  85.   # Turning this switch on will make the mouse invisible and unusuable until
  86.   # the switch is turned off
  87.   TURN_MOUSE_OFF_SWITCH = 20
  88.   
  89.   # Do you want the mouse to check for mouse wheel scrolling in selectbale
  90.   # windows? Not using this may reduce some rare cases of lag.
  91.   USE_WHEEL_DETECTION = false
  92.   
  93.   # Do you want to use the Dijkstra formula for pathfinding?
  94.   # This is more accurate, but slower.
  95.   USE_DIJKSTRA = true
  96.   
  97. end

  98. #===============================================================================
  99. # DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
  100. #===============================================================================
  101. module Mouse
  102.   
  103.   Get_Message = Win32API.new('user32', 'GetMessage', 'plll', 'l')
  104.   GetAsyncKeyState = Win32API.new("user32", "GetAsyncKeyState", 'i', 'i')
  105.   GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  106.   SetCursorPos = Win32API.new('user32', 'SetCursorPos', 'nn', 'n')
  107.   GetCursorPo = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  108.   ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
  109.   FindWindowA = Win32API.new('user32', 'FindWindowA', 'pp', 'l')
  110.   GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
  111.   GetWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'i')
  112.   contents = File.open('Game.ini', 'r') { |f| f.read }
  113.   q = contents[/Title=(.+)/].nil? ? "cccc" : $1
  114.   @handle = FindWindowA.call('RGSS Player', q)
  115.   module_function
  116.   
  117.   Point = Struct.new(:x, :y)
  118.   
  119.   Message = Struct.new(:message, :wparam, :lparam, :pt)
  120.   
  121.   Param = Struct.new(:x, :y, :scroll)
  122.   
  123.   Scroll = 0x0000020A
  124.   
  125.   def hiword(dword); return((dword&0xffff0000) >> 16)&0x0000ffff; end
  126.   def loword(dword); return dword&0x0000ffff; end
  127.    
  128.   def word2signed_short(value)
  129.     return value if (value&0x8000) == 0
  130.     return -1 *((~value&0x7fff) + 1)
  131.   end
  132.   
  133.   def unpack_dword(buffer, offset = 0)
  134.     ret = buffer[offset + 0]&0x000000ff
  135.     ret |=(buffer[offset + 1] <<(8 * 1))&0x0000ff00
  136.     ret |=(buffer[offset + 2] <<(8 * 2))&0x00ff0000
  137.     ret |=(buffer[offset + 3] <<(8 * 3))&0xff000000
  138.     return ret
  139.   end
  140.   
  141.   def unpack_msg(buffer)
  142.     msg = Message.new; msg.pt = Point.new
  143.     msg.message=unpack_dword(buffer,4*1)
  144.     msg.wparam = unpack_dword(buffer, 4 * 2)
  145.     msg.lparam = unpack_dword(buffer,4*3)
  146.     msg.pt.x = unpack_dword(buffer, 4 * 5)
  147.     msg.pt.y = unpack_dword(buffer, 4 * 6)
  148.     return msg
  149.   end
  150.   
  151.   def wmcallback(msg)
  152.     return unless msg.message == Scroll
  153.     param = Param.new
  154.     param.x = word2signed_short(loword(msg.lparam))
  155.     param.y = word2signed_short(hiword(msg.lparam))
  156.     param.scroll = word2signed_short(hiword(msg.wparam))
  157.     return [param.x, param.y, param.scroll]
  158.   end
  159.   
  160.   def click?(button)
  161.     return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  162.     return true if @keys.include?(button)
  163.     return false
  164.   end
  165.   
  166.   def press?(button)
  167.     return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  168.     return true if @press.include?(button)
  169.     return false
  170.   end
  171.   
  172.   def set_pos(x_pos = 0, y_pos = 0)
  173.     width,height = client_size
  174.     if (x_pos.between?(0, width) && y_pos.between?(0, height))
  175.       SetCursorPos.call(client_pos[0] + x_pos,client_pos[1] + y_pos)
  176.     end
  177.   end
  178.   
  179.   def update
  180.     return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  181.     @pos = Mouse.pos
  182.     @keys, @press = [], []
  183.     @keys.push(1) if GetAsyncKeyState.call(1)&0x01==1
  184.     @keys.push(2) if GetAsyncKeyState.call(2)&0x01==1
  185.     @keys.push(3) if GetAsyncKeyState.call(4)&0x01==1
  186.     @press.push(1) if pressed?(1)
  187.     @press.push(2) if pressed?(2)
  188.     @press.push(3) if pressed?(4)
  189.   end
  190.   
  191.   def pressed?(key)
  192.     return true unless GetKeyState.call(key).between?(0, 1)
  193.     return false
  194.   end
  195.   
  196.   def global_pos
  197.     pos = [0, 0].pack('ll')
  198.     GetCursorPo.call(pos) != 0 ?(return pos.unpack('ll')):(return [0, 0])
  199.   end
  200.   
  201.   def pos
  202.     return 0, 0 if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  203.     x, y = screen_to_client(*global_pos)
  204.     width, height = client_size
  205.     begin
  206.       x = 0 if x <= 0; y = 0 if y <= 0
  207.       x = width if x >= width; y = height if y >= height
  208.       return x, y
  209.     end
  210.   end
  211.   
  212.   def screen_to_client(x, y)
  213.     return nil unless x && y
  214.     pos = [x, y].pack('ll')
  215.     ScreenToClient.call(@handle, pos) != 0 ?(return pos.unpack('ll')):(return [0, 0])
  216.   end
  217.   
  218.   def client_size
  219.     rect = [0, 0, 0, 0].pack('l4')
  220.     GetClientRect.call(@handle, rect)
  221.     right,bottom = rect.unpack('l4')[2..3]
  222.     return right, bottom
  223.   end
  224.   
  225.   def client_pos
  226.     rect=[0, 0, 0, 0].pack('l4')
  227.     GetWindowRect.call(@handle, rect)
  228.     left, upper = rect.unpack('l4')[0..1]
  229.     return left + 4, upper + 30
  230.   end
  231.   
  232.   def grid
  233.     return [-1, -1] if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  234.     return [-1, -1] if @pos.nil?
  235.     return [(@pos[0]/32),(@pos[1]/32)]
  236.   end
  237.   
  238.   def true_grid
  239.     return [grid[0] + $game_map.display_x / 256, grid[1] + $game_map.display_y / 256]
  240.   end
  241.   
  242.   def area?(x, y, width, height)
  243.     return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  244.     return false if @pos.nil?
  245.     return @pos[0].between?(x, width + x) && @pos[1].between?(y, height + y)
  246.   end
  247.   
  248.   def scroll
  249.     msg="\0"*32;Get_Message.call(msg,0,0,0);r=wmcallback(unpack_msg(msg))
  250.     return r if !r.nil?
  251.   end
  252. end

  253. class Sprite_Cursor < Sprite_Base
  254.   
  255.   attr_accessor :current_cursor, :not_default
  256.   
  257.   include JetMouse
  258.   
  259.   def initialize
  260.     super
  261.     @current_cursor = ""
  262.     @not_default = false
  263.     Win32API.new('user32', 'ShowCursor', 'i', 'i').call(0)
  264.     self.z = 5004
  265.     create_cursor(CURSOR_PICTURE)
  266.     $game_switches = []
  267.     update
  268.   end
  269.   
  270.   def create_cursor(cursor = "")
  271.     self.bitmap.dispose unless self.bitmap.nil?
  272.     self.bitmap = nil
  273.     begin
  274.       self.bitmap = Cache.system(cursor)
  275.       @current_cursor = cursor
  276.     rescue
  277.       self.bitmap = Bitmap.new(24, 24)
  278.       bitmap = Cache.system("Iconset")
  279.       rect = Rect.new(ICON_INDEX % 16 * 24, ICON_INDEX / 16 * 24, 24, 24)
  280.       self.bitmap.blt(0, 0, bitmap, rect)
  281.       @current_cursor = ICON_INDEX
  282.     end
  283.     @not_default = false
  284.   end
  285.   
  286.   def change_cursor(cursor)
  287.     self.bitmap.dispose unless self.bitmap.nil?
  288.     self.bitmap = nil
  289.     begin
  290.       self.bitmap = Cache.system(cursor)
  291.       @current_cursor = cursor
  292.       @not_default = true
  293.     rescue
  294.       begin
  295.         self.bitmap = Bitmap.new(24, 24)
  296.         bitmap = Cache.system("Iconset")
  297.         rect = Rect.new(cursor % 16 * 24, cursor / 16 * 24, 24, 24)
  298.         self.bitmap.blt(0, 0, bitmap, rect)
  299.         @current_cursor = cursor
  300.         @not_default = true
  301.       rescue
  302.         create_cursor(CURSOR_PICTURE)
  303.       end
  304.     end
  305.   end

  306.   def update
  307.           return if self.disposed?
  308.     if $game_switches[TURN_MOUSE_OFF_SWITCH]
  309.       self.opacity = 0 unless self.opacity == 0
  310.     end
  311.     self.opacity = 255 unless self.opacity == 255
  312.     super
  313.     x = self.x
  314.     y = self.y
  315.     self.x, self.y = Mouse.pos
  316.     self.x -= 8 if @not_default
  317.     self.y -= 8 if @not_default
  318.   end
  319. end

  320. $cursor = Sprite_Cursor.new

  321. module Input
  322.   
  323.   class << self
  324.    
  325.     alias jet5888_press? press? unless $@
  326.     def press?(arg)
  327.       if arg == Input::C
  328.         return true if Mouse.press?(1)
  329.       elsif arg == Input::B
  330.         return true if Mouse.press?(2)
  331.       end
  332.       jet5888_press?(arg)
  333.     end
  334.    
  335.     alias jet5888_repeat? repeat? unless $@
  336.     def repeat?(arg)
  337.       if arg == Input::C
  338.         return true if Mouse.click?(1)
  339.       elsif arg == Input::B
  340.         return true if Mouse.click?(2)
  341.       end
  342.       jet5888_repeat?(arg)
  343.     end
  344.    
  345.     alias jet5888_trigger? trigger? unless $@
  346.     def trigger?(arg)
  347.       if arg == Input::C
  348.         return true if Mouse.click?(1)
  349.       elsif arg == Input::B
  350.         return true if Mouse.click?(2)
  351.       end
  352.       jet5888_trigger?(arg)
  353.     end
  354.    
  355.     alias jet8432_update update unless $@
  356.     def update(*args, &block)
  357.       jet8432_update(*args, &block)
  358.       if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH] && $cursor.opacity != 0
  359.         $cursor.opacity = 0
  360.       end
  361.       $cursor.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  362.       Mouse.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  363.     end
  364.   
  365.     alias jet1626_dir4 dir4 unless $@
  366.     def dir4(*args, &block)
  367.       if !$game_temp.nil?
  368.         if $game_temp.move_because_of_mouse
  369.           if !$game_temp.mouse_path.empty? && $game_player.movable? &&
  370.               !$game_map.interpreter.running? && SceneManager.scene_is?(Scene_Map) &&
  371.               jet1626_dir4(*args, &block) == 0
  372.             f = $game_temp.mouse_path.reverse!.pop
  373.             $game_temp.mouse_path.reverse!
  374.             return f * 2
  375.           else
  376.             $game_temp.move_because_of_mouse = false
  377.             $game_temp.mouse_path = []
  378.           end
  379.         end
  380.       end
  381.       jet1626_dir4(*args, &block)
  382.     end
  383.    
  384.     alias jet1626_dir8 dir8 unless $@
  385.     def dir8(*args, &block)
  386.       if !$game_temp.nil?
  387.         if $game_temp.move_because_of_mouse
  388.           if !$game_temp.mouse_path.empty? && $game_player.movable? &&
  389.               !$game_map.interpreter.running? && SceneManager.scene_is?(Scene_Map) &&
  390.               jet1626_dir8(*args, &block) == 0
  391.             f = $game_temp.mouse_path.reverse!.pop
  392.             $game_temp.mouse_path.reverse!
  393.             if [1, 2, 3, 4].include?(f)
  394.               return f * 2
  395.             else
  396.               case f
  397.               when 5
  398.                 return 1
  399.               when 6
  400.                 return 3
  401.               when 7
  402.                 return 7
  403.               when 8
  404.                 return 9
  405.               end
  406.             end
  407.           else
  408.             $game_temp.move_because_of_mouse = false
  409.             $game_temp.mouse_path = []
  410.           end
  411.         end
  412.       end
  413.       jet1626_dir8(*args, &block)
  414.     end
  415.   end
  416. end

  417. class Game_Player
  418.         
  419.         def move_by_input
  420.     return if !movable? || $game_map.interpreter.running?
  421.     move = Input.dir4
  422.     move_straight(move) if move > 0
  423.   end
  424. end

  425. class Game_Character
  426.   
  427.   def find_mouse_path(trgt_x, trgt_y)
  428.           fake_char = Game_Character.new
  429.           fake_char.moveto(self.x, self.y)
  430.                 fake_char.set_direction(self.direction)
  431.           path = []
  432.           g = MGraph.new(JetMouse::DO_8DIR_WALKING ? 8 : 4)
  433.     until fake_char.x == trgt_x && fake_char.y == trgt_y
  434.       if JetMouse::USE_DIJKSTRA
  435.         path.push(g.Dijkstra(fake_char.x, fake_char.y, trgt_x, trgt_y))
  436.       else
  437.         path.push(g.AStar(fake_char.x, fake_char.y, trgt_x, trgt_y))
  438.       end
  439.       if path[-1] != 0
  440.         fake_char.move_straight(path[-1] * 2)
  441.       else
  442.         path = []
  443.         break
  444.       end
  445.     end
  446.     Graphics.frame_reset
  447.     return path.reverse
  448.   end
  449. end

  450. class PQueue < Array

  451.   def addEl(ii)
  452.     iii = 0
  453.     while iii < self.length && self[iii] < ii
  454.       iii += 1
  455.     end
  456.     self.insert(iii,ii)
  457.   end

  458.   def remEl(ii)
  459.     iii = 0
  460.     while iii < self.length && self[iii] < ii
  461.       iii += 1
  462.     end
  463.     self.delete_at(iii)
  464.   end

  465.   def found?(ii)
  466.     i = 0
  467.     j = self.length-1
  468.     ff = false
  469.     while (not ff) && i <= j
  470.       mid = (i+j)/2
  471.       if self[mid] == ii
  472.         ff = true
  473.       else
  474.         if self[mid] < ii
  475.           i = mid+1
  476.         else
  477.           j = mid-1
  478.         end
  479.       end
  480.     end
  481.     return ff
  482.   end
  483. end

  484. class MGraph

  485.   attr_accessor :w, :h
  486.   attr_accessor :neighbors
  487.   attr_accessor :passage_table

  488.   def initialize(nh, char = $game_player)
  489.     [url=home.php?mod=space&uid=133944]@w[/url] = $game_map.width
  490.     @h = $game_map.height
  491.     @neighbors = nh
  492.     @passage_table = Table.new(@w,@h,nh)
  493.     for i in 0..@w
  494.       for j in 0..@h
  495.         for k in 1..nh
  496.           @passage_table[i,j,k-1] = char.passable?(i, j, k * 2) ? 1 : 0
  497.           if not neighborExist?(nodeOf(i, j), k)
  498.             @passage_table[i, j, k - 1] = 0
  499.           end
  500.         end
  501.       end
  502.     end
  503.   end

  504.   def nodeOf(x,y)
  505.     return y*@w+x+1
  506.   end

  507.   def xNode(idxNode)
  508.     return (idxNode-1) % @w
  509.   end
  510.   
  511.   def yNode(idxNode)
  512.     return (idxNode-1)/@w
  513.   end

  514.   def neighborOf(idxNode,dir)
  515.     case dir
  516.       when 1
  517.         return (idxNode+@w)
  518.       when 2
  519.         return (idxNode-1)
  520.       when 3
  521.         return (idxNode+1)
  522.       when 4
  523.         return (idxNode-@w)
  524.     end
  525.   end

  526.   def neighborExist?(idxNode,dir)
  527.     case dir
  528.       when 1
  529.         return (yNode(idxNode)<@h-1)
  530.       when 2
  531.         return (xNode(idxNode)>0)
  532.       when 3
  533.         return (xNode(idxNode)<@w-1)
  534.       when 4
  535.         return (yNode(idxNode)>0)
  536.     end
  537.   end

  538.   def reconstruct_path(s,t,vertices_prev)
  539.     u=t
  540.     while vertices_prev[u] != s && vertices_prev[u] != 0
  541.       u = vertices_prev[u]
  542.     end
  543.     case u
  544.       when s+@w
  545.         return 1
  546.       when s-1
  547.         return 2
  548.       when s+1
  549.         return 3
  550.       when s-@w
  551.         return 4
  552.     end
  553.     return 0
  554.   end

  555.   def heuristic_dist(u,v)
  556.     dx = xNode(v)-xNode(u)
  557.     dy = yNode(v)-yNode(u)
  558.     return (dx.abs+dy.abs)
  559.   end
  560.   
  561.   def Dijkstra(x1, y1, x2, y2)
  562.     s = nodeOf(x1, y1)
  563.     t = nodeOf(x2, y2)
  564.     q = PQueue.new(1, 0)
  565.     q.addEl(s)
  566.     vertices_dist = Array.new([url=home.php?mod=space&uid=133944]@w[/url] * @h + 1, 9999)
  567.     vertices_prev = Array.new(@w * @h + 1, 0)
  568.     vertices_dist[s] = 0
  569.     while q.length > 1
  570.       d = vertices_dist[q[1]]
  571.       u = q[1]
  572.       if q.length > 2
  573.         for ii in 2..q.length-1
  574.           if vertices_dist[q[ii]] < d
  575.             d = vertices_dist[q[ii]]
  576.             u = q[ii]
  577.           end
  578.         end
  579.       end
  580.       if u == t
  581.         return reconstruct_path(s,t,vertices_prev)
  582.       end
  583.       q.remEl(u)
  584.       for i in 1..@neighbors
  585.         if @passage_table[xNode(u), yNode(u), i - 1] == 1
  586.           v = neighborOf(u, i)
  587.           alt = vertices_dist[u] + 1
  588.           if alt < vertices_dist[v]
  589.             q.addEl(v)
  590.             vertices_dist[v] = alt
  591.             vertices_prev[v] = u
  592.           end
  593.         end
  594.       end
  595.     end
  596.     return 0
  597.   end
  598.   
  599.   def AStar(x1, y1, x2, y2)
  600.     s = nodeOf(x1, y1)
  601.     t = nodeOf(x2, y2)
  602.     q = PQueue.new(1, 0)
  603.     q.addEl(s)
  604.     q1 = Array.new(@w * @h + 1, false)
  605.     vertices_prev = Array.new(@w * @h + 1, 0)
  606.     vertices_dist = Array.new(@w * @h + 1, 9999)
  607.     h_score = Array.new(@w * @h + 1, 0)
  608.     f_score = Array.new(@w * @h + 1, 9999)
  609.     vertices_dist[s] = 0
  610.     h_score[s] = heuristic_dist(s, t)
  611.     f_score[s] = h_score[s]
  612.     while q.length > 1
  613.       d = f_score[q[1]]
  614.       u = q[1]
  615.       if q.length > 2
  616.         for ii in 2..q.length-1
  617.           if f_score[q[ii]] < d
  618.             d = f_score[q[ii]]
  619.             u = q[ii]
  620.           end
  621.         end
  622.       end
  623.       if u == t
  624.         return reconstruct_path(s, t, vertices_prev)
  625.       end
  626.       q.remEl(u)
  627.       q1[u] = true
  628.       for i in 1..@neighbors
  629.         if @passage_table[xNode(u), yNode(u), i - 1] == 1
  630.           v = neighborOf(u, i)
  631.           if !q1[v]
  632.             tentative_g_score = vertices_dist[u] + 1
  633.             if !q.found?(v)
  634.               q.addEl(v)
  635.               tentative_is_better = true
  636.             elsif tentative_g_score < vertices_dist[v]
  637.               tentative_is_better = true
  638.             else
  639.               tentative_is_better = false
  640.             end
  641.             if tentative_is_better
  642.               if vertices_prev[v] != 0
  643.                 if f_score[u] < f_score[vertices_prev[v]]
  644.                   vertices_prev[v] = u
  645.                 end
  646.               else
  647.                 vertices_prev[v] = u
  648.               end
  649.               vertices_dist[v] = tentative_g_score
  650.               h_score[v] = heuristic_dist(v, t)
  651.               f_score[v] = vertices_dist[v] + h_score[v]
  652.             end
  653.           end
  654.         end
  655.       end
  656.     end
  657.     return 0
  658.   end
  659. end

  660. class Game_Temp
  661.   
  662.   attr_accessor :move_because_of_mouse
  663.   attr_accessor :mouse_controlled_object
  664.   attr_accessor :making_path
  665.   attr_accessor :mouse_path
  666.   attr_accessor :did_mouse_change
  667.   
  668.   alias jet6742_initialize initialize unless $@
  669.   def initialize(*args, &block)
  670.     jet6742_initialize(*args, &block)
  671.     @move_because_of_mouse = false
  672.     @making_path = false
  673.     @mouse_path = []
  674.   end
  675. end

  676. class Window_Selectable
  677.   
  678.   alias jet6742_update update unless $@
  679.   def update(*args, &block)
  680.     jet6742_update(*args, &block)
  681.     update_mouse if self.active && self.visible
  682.   end
  683.   
  684.   alias jet7222_top_row top_row= unless $@
  685.   def top_row=(*args, &block)
  686.     @last_cursor_move = 0 if @last_cursor_move.nil?
  687.     @last_cursor_move -= 1
  688.     return if @in_rect_loop || @last_cursor_move > 0
  689.     jet7222_top_row(*args, &block)
  690.     @last_cursor_move = 10
  691.   end
  692.   
  693.   def update_mouse
  694.     if JetMouse::USE_WHEEL_DETECTION
  695.       f = Mouse.scroll
  696.       if !f.nil?
  697.         if f[2] < 0
  698.           if contents.height > self.height && self.oy - contents.height < -self.height + 32
  699.             self.top_row = self.top_row + 1
  700.           end
  701.         else
  702.           self.top_row = self.top_row - 1 if contents.height > self.height
  703.         end
  704.       end
  705.     end
  706.     original_index = @index
  707.     fake_index = -2
  708.     add_x = self.viewport.nil? ? 0 : self.viewport.ox
  709.     add_y = self.viewport.nil? ? 0 : self.viewport.oy
  710.     self.item_max.times {|i|
  711.       rect = item_rect(i)
  712.       if Mouse.area?(self.x - self.ox + rect.x + 16 + add_x, self.y - self.oy + rect.y + 16 + add_y, rect.width, rect.height)
  713.         fake_index = i
  714.       end
  715.     }
  716.     @index = fake_index == -2 ? original_index : fake_index
  717.     update_cursor
  718.   end
  719. end

  720. class Scene_File
  721.   
  722.   alias wor_scefil_upd_mouse update unless $@
  723.   def update(*args, &block)
  724.     (0..self.item_max - 1).each do |i|
  725.       ix = @savefile_windows[i].x
  726.       iy = @savefile_windows[i].y + 48
  727.       iw = @savefile_windows[i].width
  728.       ih = @savefile_windows[i].height
  729.       if Mouse.area?(ix, iy, iw, ih)
  730.         @savefile_windows[@index].selected = false
  731.         @savefile_windows[i].selected = true
  732.         @index = i
  733.       end
  734.     end
  735.     wor_scefil_upd_mouse(*args, &block)
  736.   end
  737. end

  738. class Window_NameInput
  739.   
  740.   alias wor_winnam_upd_mouse update unless $@
  741.   def update(*args, &block)
  742.     wor_winnam_upd_mouse(*args, &block)
  743.     if self.active and self.visible
  744.       (0..self.table[@page].size - 1).each do |i|
  745.       irect = item_rect(i)
  746.       irx = self.x + 16 + irect.x - self.ox
  747.       iry = self.y + 16 + irect.y - self.oy
  748.       @index = i if Mouse.area?(irx, iry, irect.width, irect.height)
  749.       end
  750.     end
  751.   end
  752. end

  753. class Window_PartyCommand
  754.   
  755.   def update_mouse
  756.     (0..self.item_max - 1).each do |i|
  757.     irect = item_rect(i)
  758.     irx = self.viewport.ox + 16 + irect.x - self.ox
  759.     iry = 288 + 16 + irect.y - self.oy + 64
  760.     self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
  761.     end
  762.   end
  763. end

  764. class Window_ActorCommand
  765.   
  766.   def update_mouse
  767.     (0..self.item_max - 1).each do |i|
  768.     irect = item_rect(i)
  769.     irx = self.viewport.ox + 288 + 16 + irect.x + 96
  770.     iry = 288 + 16 + irect.y + 64
  771.     self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
  772.     end
  773.   end
  774. end

  775. class Window_EventPopUp < Window_Base
  776.   
  777.   def initialize(x, y, width, height, text)
  778.     super(x, y, width, height)
  779.     self.opacity = 0
  780.     @text = text
  781.     refresh
  782.   end
  783.   
  784.   def refresh
  785.     self.contents.clear
  786.     self.contents.draw_text(0, 0, self.width, 24, @text)
  787.   end
  788. end

  789. class Game_Event
  790.   
  791.   attr_accessor :popup_window, :page
  792.   
  793.   def check_for_comment(regexp)
  794.     return false if @list.nil?
  795.     for item in @list
  796.       if item.code == 108 or item.code == 408
  797.         if !item.parameters[0][regexp].nil?
  798.           return $1.nil? ? true : $1
  799.         end
  800.       end
  801.     end
  802.     return false
  803.   end
  804.   
  805.   def through
  806.     return true if check_for_comment(/MOUSE THROUGH/i) && $game_temp.making_path
  807.     return @through
  808.   end
  809.   
  810.   alias jet2734_update update unless $@
  811.   def update(*args, &block)
  812.     jet2734_update(*args, &block)
  813.     update_mouse_popup
  814.     update_mouse_change
  815.   end
  816.   
  817.   def update_mouse_popup
  818.     switch = $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  819.     if Mouse.true_grid == [self.x, self.y] && !switch && !@erased
  820.       f = self.check_for_comment(/MOUSE TEXT(.+)/i)
  821.       if f != false
  822.         q = Bitmap.new(1, 1)
  823.         size = q.text_size(f)
  824.         x = self.screen_x - 16 - size.width / 2
  825.         y = self.screen_y - 52 - size.height / 2
  826.         if self.popup_window != nil
  827.           self.popup_window.dispose
  828.           self.popup_window = nil
  829.         end
  830.         self.popup_window = Window_EventPopUp.new(x, y,
  831.           size.width + 34, size.height + 34, f)
  832.         q.dispose
  833.         q = nil
  834.       end
  835.     else
  836.       if self.popup_window != nil
  837.         self.popup_window.dispose
  838.         self.popup_window = nil
  839.       end
  840.     end
  841.   end
  842.   
  843.   def update_mouse_change
  844.     if Mouse.true_grid == [self.x, self.y]
  845.       f =(self.check_for_comment(/MOUSE PIC(.+)/i) rescue false)
  846.       if f != false
  847.         if f.to_i != 0
  848.           $cursor.change_cursor(f.to_i) unless $cursor.current_cursor == f.to_i
  849.         else
  850.           $cursor.change_cursor(f) unless $cursor.current_cursor == f
  851.         end
  852.         $game_temp.did_mouse_change = true
  853.       end
  854.     end
  855.   end
  856. end


  857. class Scene_Map
  858.   
  859.   alias jet6742_update update unless $@
  860.   def update(*args, &block)
  861.     if !$game_message.visible
  862.       update_mouse_left_click
  863.     end
  864.     jet6742_update(*args, &block)
  865.     check_mouse_change
  866.   end
  867.   
  868.   alias jet7811_terminate terminate unless $@
  869.   def terminate(*args, &block)
  870.     for event in $game_map.events.values
  871.       next if event.popup_window.nil?
  872.       event.popup_window.dispose unless event.popup_window.disposed?
  873.       event.popup_window = nil
  874.     end
  875.     $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
  876.       JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  877.     $cursor.opacity = 0
  878.     jet7811_terminate(*args, &block)
  879.     $cursor.opacity = 255 unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  880.   end
  881.   
  882.   alias jet8887_update_transfer_player update_transfer_player unless $@
  883.   def update_transfer_player(*args, &block)
  884.     if $game_player.transfer?
  885.       $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
  886.         JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  887.     end
  888.     jet8887_update_transfer_player(*args, &block)
  889.   end
  890.   
  891.   def check_mouse_change
  892.     return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  893.     if $game_message.visible || $game_player.transfer?
  894.       $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
  895.         JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  896.       return
  897.     end
  898.     $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if $game_temp.did_mouse_change.nil? &&
  899.       ![JetMouse::CURSOR_PICTURE, JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  900.     $game_temp.did_mouse_change = nil
  901.   end

  902.   def update_mouse_left_click
  903.     return if $game_map.interpreter.running? || $game_player.transfer?
  904.     if Mouse.click?(1)
  905.       event_activated = false
  906.       for event in $game_map.events_xy(*Mouse.true_grid)
  907.         if event.check_for_comment(/MOUSE CLICK/i)
  908.           event.start
  909.           event_activated = true
  910.         elsif (event.x - $game_player.x).abs + (event.y - $game_player.y).abs == 1
  911.           if ![3, 4].include?(event.trigger) &&
  912.                (![0, 2].include?(event.priority_type) || event.trigger == 0) &&
  913.                   ![0, 1].include?(event.page.list.size)
  914.             if (event.y - $game_player.y).abs >
  915.                (event.x - $game_player.x).abs
  916.               if event.y - $game_player.y > 0
  917.                 $game_player.set_direction(2)
  918.               else
  919.                 $game_player.set_direction(8)
  920.               end
  921.             else
  922.               if event.x - $game_player.x > 0
  923.                 $game_player.set_direction(6)
  924.               else
  925.                 $game_player.set_direction(4)
  926.               end
  927.             end
  928.             event.start
  929.             event_activated = true
  930.             break
  931.           end
  932.         end
  933.         if !event_activated
  934.           for i in ["UP", "DOWN", "RIGHT", "LEFT"]
  935.             if event.check_for_comment(/MOUSE MOVE #{i}/i)
  936.               event_activated = true
  937.               case i
  938.               when "UP"
  939.                 x, y = event.x, event.y - 1
  940.               when "DOWN"
  941.                 x, y = event.x, event.y + 1
  942.               when "LEFT"
  943.                 x, y = event.x - 1, event.y
  944.               when "RIGHT"
  945.                 x, y = event.x + 1, event.y
  946.               end
  947.               break
  948.             end
  949.           end
  950.         end
  951.       end
  952.       if !event_activated
  953.         x, y = *Mouse.true_grid
  954.       end
  955.       if !x.nil?
  956.         $game_temp.move_because_of_mouse = true
  957.         g = $game_player.find_mouse_path(x, y)
  958.         $game_temp.mouse_path = g
  959.       end
  960.     end
  961.   end
  962. end
复制代码


梦石
0
星屑
4221
在线时间
1104 小时
注册时间
2008-5-17
回帖
199

开拓者

发表于 2012-12-1 23:58:51 | 显示全部楼层
你就不能用代码框???
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部