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

Project1

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

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
137 小时
注册时间
2012-8-27
帖子
109
跳转到指定楼层
1
发表于 2012-12-1 22:47:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

如何使这个脚本的鼠标不在地图显示,只在菜单中起作用?
RUBY 代码复制
  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.  
  25. =begin
  26. Showing text above event when mouse hovers:
  27.  
  28. If you want a message to appear over an event's head if the mouse is hovering
  29. over the event, put this comment in the event:
  30.  
  31. MOUSE TEXT MESSAGE HERE
  32.  
  33. everything after TEXT will be the hovering display.
  34. --------------------------------------------------------------------------------
  35. Change mouse picture above event when mouse hovers:
  36.  
  37. If you want the mouse's picture to temporarily change whne over an event, put
  38. this comment in the event
  39.  
  40. MOUSE PIC NAME/NUMBER
  41.  
  42. if you put a name, the mouse will become that picture, but if you put a number
  43. then the mouse will become the icon that is the id number
  44. --------------------------------------------------------------------------------
  45. Specific mouse click movement routes:
  46.  
  47. If you want the player to land specifically in a square around an event when
  48. they click to move on the event, put one of these comments in the event:
  49.  
  50. MOUSE MOVE UP/LEFT/RIGHT/DOWN
  51.  
  52. only put the direction that you want the player to land on.
  53. --------------------------------------------------------------------------------
  54. Click to activate:
  55.  
  56. If you want an event to automatically start when it is clicked on, place
  57. this in an event comment:
  58.  
  59. MOUSE CLICK
  60. --------------------------------------------------------------------------------
  61. Don't stop the player when walking over a touch event:
  62.  
  63. By default, this script will stop a mouse-caused movement if the player walks
  64. over/under a player touch/event touch event. If you want the event to activate,
  65. but for the player to keep walking to their destination, put this comment in the
  66. event:
  67.  
  68. MOUSE NOSTOP
  69. --------------------------------------------------------------------------------
  70. Ignore Events:
  71.  
  72. To have an event be ignored when the mouse makes it's movement path(as if the
  73. event isn't there), put this comment in the event:
  74.  
  75. MOUSE THROUGH
  76. --------------------------------------------------------------------------------
  77. Extra Notes:
  78.  
  79. In selectable windows that have more items than what's shown, players can
  80. either put the mouse below the window to scroll down, OR use the mouse's
  81. scroll wheel to scroll up/down.
  82.  
  83. You can activate action button events by standing next to the event and clicking
  84. on it with the mouse.
  85. =end
  86. module JetMouse
  87.  
  88.   # If you are using a graphic, this is it.
  89.   # It must be in the Graphics/System folder.
  90.   CURSOR_PICTURE = "cursor-mouse"
  91.  
  92.   # If you aren't using a graphic, this icon will be the mouse.
  93.   # To use the icon, just put a non-existant picture as the above config
  94.   ICON_INDEX = 387
  95.  
  96.   # Do you want the player to be able to move by clicking the mouse?
  97.   ALLOW_MOUSE_MOVEMENT = true
  98.  
  99.   # Do you want mouse movement to do 8-dir walking?
  100.   # Requires 8-Dir Walking by Jet.
  101.   DO_8DIR_WALKING = false
  102.  
  103.   # Turning this switch on will make the mouse invisible and unusuable until
  104.   # the switch is turned off
  105.   TURN_MOUSE_OFF_SWITCH = 20
  106.  
  107.   # Do you want the mouse to check for mouse wheel scrolling in selectbale
  108.   # windows? Not using this may reduce some rare cases of lag.
  109.   USE_WHEEL_DETECTION = false
  110.  
  111.   # Do you want to use the Dijkstra formula for pathfinding?
  112.   # This is more accurate, but slower.
  113.   USE_DIJKSTRA = true
  114.  
  115. end
  116.  
  117. #===============================================================================
  118. # DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
  119. #===============================================================================
  120. module Mouse
  121.  
  122.   Get_Message = Win32API.new('user32', 'GetMessage', 'plll', 'l')
  123.   GetAsyncKeyState = Win32API.new("user32", "GetAsyncKeyState", 'i', 'i')
  124.   GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  125.   SetCursorPos = Win32API.new('user32', 'SetCursorPos', 'nn', 'n')
  126.   GetCursorPo = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  127.   ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
  128.   FindWindowA = Win32API.new('user32', 'FindWindowA', 'pp', 'l')
  129.   GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
  130.   GetWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'i')
  131.   contents = File.open('Game.ini', 'r') { |f| f.read }
  132.   q = contents[/Title=(.+)/].nil? ? "cccc" : $1
  133.   @handle = FindWindowA.call('RGSS Player', q)
  134.   module_function
  135.  
  136.   Point = Struct.new(:x, :y)
  137.  
  138.   Message = Struct.new(:message, :wparam, :lparam, :pt)
  139.  
  140.   Param = Struct.new(:x, :y, :scroll)
  141.  
  142.   Scroll = 0x0000020A
  143.  
  144.   def hiword(dword); return((dword&0xffff0000) >> 16)&0x0000ffff; end
  145.   def loword(dword); return dword&0x0000ffff; end
  146.  
  147.   def word2signed_short(value)
  148.     return value if (value&0x8000) == 0
  149.     return -1 *((~value&0x7fff) + 1)
  150.   end
  151.  
  152.   def unpack_dword(buffer, offset = 0)
  153.     ret = buffer[offset + 0]&0x000000ff
  154.     ret |=(buffer[offset + 1] <<(8 * 1))&0x0000ff00
  155.     ret |=(buffer[offset + 2] <<(8 * 2))&0x00ff0000
  156.     ret |=(buffer[offset + 3] <<(8 * 3))&0xff000000
  157.     return ret
  158.   end
  159.  
  160.   def unpack_msg(buffer)
  161.     msg = Message.new; msg.pt = Point.new
  162.     msg.message=unpack_dword(buffer,4*1)
  163.     msg.wparam = unpack_dword(buffer, 4 * 2)
  164.     msg.lparam = unpack_dword(buffer,4*3)
  165.     msg.pt.x = unpack_dword(buffer, 4 * 5)
  166.     msg.pt.y = unpack_dword(buffer, 4 * 6)
  167.     return msg
  168.   end
  169.  
  170.   def wmcallback(msg)
  171.     return unless msg.message == Scroll
  172.     param = Param.new
  173.     param.x = word2signed_short(loword(msg.lparam))
  174.     param.y = word2signed_short(hiword(msg.lparam))
  175.     param.scroll = word2signed_short(hiword(msg.wparam))
  176.     return [param.x, param.y, param.scroll]
  177.   end
  178.  
  179.   def click?(button)
  180.     return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  181.     return true if @keys.include?(button)
  182.     return false
  183.   end
  184.  
  185.   def press?(button)
  186.     return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  187.     return true if @press.include?(button)
  188.     return false
  189.   end
  190.  
  191.   def set_pos(x_pos = 0, y_pos = 0)
  192.     width,height = client_size
  193.     if (x_pos.between?(0, width) && y_pos.between?(0, height))
  194.       SetCursorPos.call(client_pos[0] + x_pos,client_pos[1] + y_pos)
  195.     end
  196.   end
  197.  
  198.   def update
  199.     return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  200.     @pos = Mouse.pos
  201.     @keys, @press = [], []
  202.     @keys.push(1) if GetAsyncKeyState.call(1)&0x01==1
  203.     @keys.push(2) if GetAsyncKeyState.call(2)&0x01==1
  204.     @keys.push(3) if GetAsyncKeyState.call(4)&0x01==1
  205.     @press.push(1) if pressed?(1)
  206.     @press.push(2) if pressed?(2)
  207.     @press.push(3) if pressed?(4)
  208.   end
  209.  
  210.   def pressed?(key)
  211.     return true unless GetKeyState.call(key).between?(0, 1)
  212.     return false
  213.   end
  214.  
  215.   def global_pos
  216.     pos = [0, 0].pack('ll')
  217.     GetCursorPo.call(pos) != 0 ?(return pos.unpack('ll')):(return [0, 0])
  218.   end
  219.  
  220.   def pos
  221.     return 0, 0 if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  222.     x, y = screen_to_client(*global_pos)
  223.     width, height = client_size
  224.     begin
  225.       x = 0 if x <= 0; y = 0 if y <= 0
  226.       x = width if x >= width; y = height if y >= height
  227.       return x, y
  228.     end
  229.   end
  230.  
  231.   def screen_to_client(x, y)
  232.     return nil unless x && y
  233.     pos = [x, y].pack('ll')
  234.     ScreenToClient.call(@handle, pos) != 0 ?(return pos.unpack('ll')):(return [0, 0])
  235.   end
  236.  
  237.   def client_size
  238.     rect = [0, 0, 0, 0].pack('l4')
  239.     GetClientRect.call(@handle, rect)
  240.     right,bottom = rect.unpack('l4')[2..3]
  241.     return right, bottom
  242.   end
  243.  
  244.   def client_pos
  245.     rect=[0, 0, 0, 0].pack('l4')
  246.     GetWindowRect.call(@handle, rect)
  247.     left, upper = rect.unpack('l4')[0..1]
  248.     return left + 4, upper + 30
  249.   end
  250.  
  251.   def grid
  252.     return [-1, -1] if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  253.     return [-1, -1] if @pos.nil?
  254.     return [(@pos[0]/32),(@pos[1]/32)]
  255.   end
  256.  
  257.   def true_grid
  258.     return [grid[0] + $game_map.display_x / 256, grid[1] + $game_map.display_y / 256]
  259.   end
  260.  
  261.   def area?(x, y, width, height)
  262.     return false if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  263.     return false if @pos.nil?
  264.     return @pos[0].between?(x, width + x) && @pos[1].between?(y, height + y)
  265.   end
  266.  
  267.   def scroll
  268.     msg="\0"*32;Get_Message.call(msg,0,0,0);r=wmcallback(unpack_msg(msg))
  269.     return r if !r.nil?
  270.   end
  271. end
  272.  
  273. class Sprite_Cursor < Sprite_Base
  274.  
  275.   attr_accessor :current_cursor, :not_default
  276.  
  277.   include JetMouse
  278.  
  279.   def initialize
  280.     super
  281.     @current_cursor = ""
  282.     @not_default = false
  283.     Win32API.new('user32', 'ShowCursor', 'i', 'i').call(0)
  284.     self.z = 5004
  285.     create_cursor(CURSOR_PICTURE)
  286.     $game_switches = []
  287.     update
  288.   end
  289.  
  290.   def create_cursor(cursor = "")
  291.     self.bitmap.dispose unless self.bitmap.nil?
  292.     self.bitmap = nil
  293.     begin
  294.       self.bitmap = Cache.system(cursor)
  295.       @current_cursor = cursor
  296.     rescue
  297.       self.bitmap = Bitmap.new(24, 24)
  298.       bitmap = Cache.system("Iconset")
  299.       rect = Rect.new(ICON_INDEX % 16 * 24, ICON_INDEX / 16 * 24, 24, 24)
  300.       self.bitmap.blt(0, 0, bitmap, rect)
  301.       @current_cursor = ICON_INDEX
  302.     end
  303.     @not_default = false
  304.   end
  305.  
  306.   def change_cursor(cursor)
  307.     self.bitmap.dispose unless self.bitmap.nil?
  308.     self.bitmap = nil
  309.     begin
  310.       self.bitmap = Cache.system(cursor)
  311.       @current_cursor = cursor
  312.       @not_default = true
  313.     rescue
  314.       begin
  315.         self.bitmap = Bitmap.new(24, 24)
  316.         bitmap = Cache.system("Iconset")
  317.         rect = Rect.new(cursor % 16 * 24, cursor / 16 * 24, 24, 24)
  318.         self.bitmap.blt(0, 0, bitmap, rect)
  319.         @current_cursor = cursor
  320.         @not_default = true
  321.       rescue
  322.         create_cursor(CURSOR_PICTURE)
  323.       end
  324.     end
  325.   end
  326.  
  327.   def update
  328.           return if self.disposed?
  329.     if $game_switches[TURN_MOUSE_OFF_SWITCH]
  330.       self.opacity = 0 unless self.opacity == 0
  331.     end
  332.     self.opacity = 255 unless self.opacity == 255
  333.     super
  334.     x = self.x
  335.     y = self.y
  336.     self.x, self.y = Mouse.pos
  337.     self.x -= 8 if @not_default
  338.     self.y -= 8 if @not_default
  339.   end
  340. end
  341.  
  342. $cursor = Sprite_Cursor.new
  343.  
  344. module Input
  345.  
  346.   class << self
  347.  
  348.     alias jet5888_press? press? unless $@
  349.     def press?(arg)
  350.       if arg == Input::C
  351.         return true if Mouse.press?(1)
  352.       elsif arg == Input::B
  353.         return true if Mouse.press?(2)
  354.       end
  355.       jet5888_press?(arg)
  356.     end
  357.  
  358.     alias jet5888_repeat? repeat? unless $@
  359.     def repeat?(arg)
  360.       if arg == Input::C
  361.         return true if Mouse.click?(1)
  362.       elsif arg == Input::B
  363.         return true if Mouse.click?(2)
  364.       end
  365.       jet5888_repeat?(arg)
  366.     end
  367.  
  368.     alias jet5888_trigger? trigger? unless $@
  369.     def trigger?(arg)
  370.       if arg == Input::C
  371.         return true if Mouse.click?(1)
  372.       elsif arg == Input::B
  373.         return true if Mouse.click?(2)
  374.       end
  375.       jet5888_trigger?(arg)
  376.     end
  377.  
  378.     alias jet8432_update update unless $@
  379.     def update(*args, &block)
  380.       jet8432_update(*args, &block)
  381.       if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH] && $cursor.opacity != 0
  382.         $cursor.opacity = 0
  383.       end
  384.       $cursor.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  385.       Mouse.update unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  386.     end
  387.  
  388.     alias jet1626_dir4 dir4 unless $@
  389.     def dir4(*args, &block)
  390.       if !$game_temp.nil?
  391.         if $game_temp.move_because_of_mouse
  392.           if !$game_temp.mouse_path.empty? && $game_player.movable? &&
  393.               !$game_map.interpreter.running? && SceneManager.scene_is?(Scene_Map) &&
  394.               jet1626_dir4(*args, &block) == 0
  395.             f = $game_temp.mouse_path.reverse!.pop
  396.             $game_temp.mouse_path.reverse!
  397.             return f * 2
  398.           else
  399.             $game_temp.move_because_of_mouse = false
  400.             $game_temp.mouse_path = []
  401.           end
  402.         end
  403.       end
  404.       jet1626_dir4(*args, &block)
  405.     end
  406.  
  407.     alias jet1626_dir8 dir8 unless $@
  408.     def dir8(*args, &block)
  409.       if !$game_temp.nil?
  410.         if $game_temp.move_because_of_mouse
  411.           if !$game_temp.mouse_path.empty? && $game_player.movable? &&
  412.               !$game_map.interpreter.running? && SceneManager.scene_is?(Scene_Map) &&
  413.               jet1626_dir8(*args, &block) == 0
  414.             f = $game_temp.mouse_path.reverse!.pop
  415.             $game_temp.mouse_path.reverse!
  416.             if [1, 2, 3, 4].include?(f)
  417.               return f * 2
  418.             else
  419.               case f
  420.               when 5
  421.                 return 1
  422.               when 6
  423.                 return 3
  424.               when 7
  425.                 return 7
  426.               when 8
  427.                 return 9
  428.               end
  429.             end
  430.           else
  431.             $game_temp.move_because_of_mouse = false
  432.             $game_temp.mouse_path = []
  433.           end
  434.         end
  435.       end
  436.       jet1626_dir8(*args, &block)
  437.     end
  438.   end
  439. end
  440.  
  441. class Game_Player
  442.  
  443.         def move_by_input
  444.     return if !movable? || $game_map.interpreter.running?
  445.     move = Input.dir4
  446.     move_straight(move) if move > 0
  447.   end
  448. end
  449.  
  450. class Game_Character
  451.  
  452.   def find_mouse_path(trgt_x, trgt_y)
  453.           fake_char = Game_Character.new
  454.           fake_char.moveto(self.x, self.y)
  455.                 fake_char.set_direction(self.direction)
  456.           path = []
  457.           g = MGraph.new(JetMouse::DO_8DIR_WALKING ? 8 : 4)
  458.     until fake_char.x == trgt_x && fake_char.y == trgt_y
  459.       if JetMouse::USE_DIJKSTRA
  460.         path.push(g.Dijkstra(fake_char.x, fake_char.y, trgt_x, trgt_y))
  461.       else
  462.         path.push(g.AStar(fake_char.x, fake_char.y, trgt_x, trgt_y))
  463.       end
  464.       if path[-1] != 0
  465.         fake_char.move_straight(path[-1] * 2)
  466.       else
  467.         path = []
  468.         break
  469.       end
  470.     end
  471.     Graphics.frame_reset
  472.     return path.reverse
  473.   end
  474. end
  475.  
  476. class PQueue < Array
  477.  
  478.   def addEl(ii)
  479.     iii = 0
  480.     while iii < self.length && self[iii] < ii
  481.       iii += 1
  482.     end
  483.     self.insert(iii,ii)
  484.   end
  485.  
  486.   def remEl(ii)
  487.     iii = 0
  488.     while iii < self.length && self[iii] < ii
  489.       iii += 1
  490.     end
  491.     self.delete_at(iii)
  492.   end
  493.  
  494.   def found?(ii)
  495.     i = 0
  496.     j = self.length-1
  497.     ff = false
  498.     while (not ff) && i <= j
  499.       mid = (i+j)/2
  500.       if self[mid] == ii
  501.         ff = true
  502.       else
  503.         if self[mid] < ii
  504.           i = mid+1
  505.         else
  506.           j = mid-1
  507.         end
  508.       end
  509.     end
  510.     return ff
  511.   end
  512. end
  513.  
  514. class MGraph
  515.  
  516.   attr_accessor :w, :h
  517.   attr_accessor :neighbors
  518.   attr_accessor :passage_table
  519.  
  520.   def initialize(nh, char = $game_player)
  521.     [url=home.php?mod=space&uid=133944]@w[/url] = $game_map.width
  522.     @h = $game_map.height
  523.     @neighbors = nh
  524.     @passage_table = Table.new(@w,@h,nh)
  525.     for i in 0..@w
  526.       for j in 0..@h
  527.         for k in 1..nh
  528.           @passage_table[i,j,k-1] = char.passable?(i, j, k * 2) ? 1 : 0
  529.           if not neighborExist?(nodeOf(i, j), k)
  530.             @passage_table[i, j, k - 1] = 0
  531.           end
  532.         end
  533.       end
  534.     end
  535.   end
  536.  
  537.   def nodeOf(x,y)
  538.     return y*@w+x+1
  539.   end
  540.  
  541.   def xNode(idxNode)
  542.     return (idxNode-1) % @w
  543.   end
  544.  
  545.   def yNode(idxNode)
  546.     return (idxNode-1)/@w
  547.   end
  548.  
  549.   def neighborOf(idxNode,dir)
  550.     case dir
  551.       when 1
  552.         return (idxNode+@w)
  553.       when 2
  554.         return (idxNode-1)
  555.       when 3
  556.         return (idxNode+1)
  557.       when 4
  558.         return (idxNode-@w)
  559.     end
  560.   end
  561.  
  562.   def neighborExist?(idxNode,dir)
  563.     case dir
  564.       when 1
  565.         return (yNode(idxNode)<@h-1)
  566.       when 2
  567.         return (xNode(idxNode)>0)
  568.       when 3
  569.         return (xNode(idxNode)<@w-1)
  570.       when 4
  571.         return (yNode(idxNode)>0)
  572.     end
  573.   end
  574.  
  575.   def reconstruct_path(s,t,vertices_prev)
  576.     u=t
  577.     while vertices_prev[u] != s && vertices_prev[u] != 0
  578.       u = vertices_prev[u]
  579.     end
  580.     case u
  581.       when s+@w
  582.         return 1
  583.       when s-1
  584.         return 2
  585.       when s+1
  586.         return 3
  587.       when s-@w
  588.         return 4
  589.     end
  590.     return 0
  591.   end
  592.  
  593.   def heuristic_dist(u,v)
  594.     dx = xNode(v)-xNode(u)
  595.     dy = yNode(v)-yNode(u)
  596.     return (dx.abs+dy.abs)
  597.   end
  598.  
  599.   def Dijkstra(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.     vertices_dist = Array.new([url=home.php?mod=space&uid=133944]@w[/url] * @h + 1, 9999)
  605.     vertices_prev = Array.new(@w * @h + 1, 0)
  606.     vertices_dist[s] = 0
  607.     while q.length > 1
  608.       d = vertices_dist[q[1]]
  609.       u = q[1]
  610.       if q.length > 2
  611.         for ii in 2..q.length-1
  612.           if vertices_dist[q[ii]] < d
  613.             d = vertices_dist[q[ii]]
  614.             u = q[ii]
  615.           end
  616.         end
  617.       end
  618.       if u == t
  619.         return reconstruct_path(s,t,vertices_prev)
  620.       end
  621.       q.remEl(u)
  622.       for i in 1..@neighbors
  623.         if @passage_table[xNode(u), yNode(u), i - 1] == 1
  624.           v = neighborOf(u, i)
  625.           alt = vertices_dist[u] + 1
  626.           if alt < vertices_dist[v]
  627.             q.addEl(v)
  628.             vertices_dist[v] = alt
  629.             vertices_prev[v] = u
  630.           end
  631.         end
  632.       end
  633.     end
  634.     return 0
  635.   end
  636.  
  637.   def AStar(x1, y1, x2, y2)
  638.     s = nodeOf(x1, y1)
  639.     t = nodeOf(x2, y2)
  640.     q = PQueue.new(1, 0)
  641.     q.addEl(s)
  642.     q1 = Array.new(@w * @h + 1, false)
  643.     vertices_prev = Array.new(@w * @h + 1, 0)
  644.     vertices_dist = Array.new(@w * @h + 1, 9999)
  645.     h_score = Array.new(@w * @h + 1, 0)
  646.     f_score = Array.new(@w * @h + 1, 9999)
  647.     vertices_dist[s] = 0
  648.     h_score[s] = heuristic_dist(s, t)
  649.     f_score[s] = h_score[s]
  650.     while q.length > 1
  651.       d = f_score[q[1]]
  652.       u = q[1]
  653.       if q.length > 2
  654.         for ii in 2..q.length-1
  655.           if f_score[q[ii]] < d
  656.             d = f_score[q[ii]]
  657.             u = q[ii]
  658.           end
  659.         end
  660.       end
  661.       if u == t
  662.         return reconstruct_path(s, t, vertices_prev)
  663.       end
  664.       q.remEl(u)
  665.       q1[u] = true
  666.       for i in 1..@neighbors
  667.         if @passage_table[xNode(u), yNode(u), i - 1] == 1
  668.           v = neighborOf(u, i)
  669.           if !q1[v]
  670.             tentative_g_score = vertices_dist[u] + 1
  671.             if !q.found?(v)
  672.               q.addEl(v)
  673.               tentative_is_better = true
  674.             elsif tentative_g_score < vertices_dist[v]
  675.               tentative_is_better = true
  676.             else
  677.               tentative_is_better = false
  678.             end
  679.             if tentative_is_better
  680.               if vertices_prev[v] != 0
  681.                 if f_score[u] < f_score[vertices_prev[v]]
  682.                   vertices_prev[v] = u
  683.                 end
  684.               else
  685.                 vertices_prev[v] = u
  686.               end
  687.               vertices_dist[v] = tentative_g_score
  688.               h_score[v] = heuristic_dist(v, t)
  689.               f_score[v] = vertices_dist[v] + h_score[v]
  690.             end
  691.           end
  692.         end
  693.       end
  694.     end
  695.     return 0
  696.   end
  697. end
  698.  
  699. class Game_Temp
  700.  
  701.   attr_accessor :move_because_of_mouse
  702.   attr_accessor :mouse_controlled_object
  703.   attr_accessor :making_path
  704.   attr_accessor :mouse_path
  705.   attr_accessor :did_mouse_change
  706.  
  707.   alias jet6742_initialize initialize unless $@
  708.   def initialize(*args, &block)
  709.     jet6742_initialize(*args, &block)
  710.     @move_because_of_mouse = false
  711.     @making_path = false
  712.     @mouse_path = []
  713.   end
  714. end
  715.  
  716. class Window_Selectable
  717.  
  718.   alias jet6742_update update unless $@
  719.   def update(*args, &block)
  720.     jet6742_update(*args, &block)
  721.     update_mouse if self.active && self.visible
  722.   end
  723.  
  724.   alias jet7222_top_row top_row= unless $@
  725.   def top_row=(*args, &block)
  726.     @last_cursor_move = 0 if @last_cursor_move.nil?
  727.     @last_cursor_move -= 1
  728.     return if @in_rect_loop || @last_cursor_move > 0
  729.     jet7222_top_row(*args, &block)
  730.     @last_cursor_move = 10
  731.   end
  732.  
  733.   def update_mouse
  734.     if JetMouse::USE_WHEEL_DETECTION
  735.       f = Mouse.scroll
  736.       if !f.nil?
  737.         if f[2] < 0
  738.           if contents.height > self.height && self.oy - contents.height < -self.height + 32
  739.             self.top_row = self.top_row + 1
  740.           end
  741.         else
  742.           self.top_row = self.top_row - 1 if contents.height > self.height
  743.         end
  744.       end
  745.     end
  746.     original_index = @index
  747.     fake_index = -2
  748.     add_x = self.viewport.nil? ? 0 : self.viewport.ox
  749.     add_y = self.viewport.nil? ? 0 : self.viewport.oy
  750.     self.item_max.times {|i|
  751.       rect = item_rect(i)
  752.       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)
  753.         fake_index = i
  754.       end
  755.     }
  756.     @index = fake_index == -2 ? original_index : fake_index
  757.     update_cursor
  758.   end
  759. end
  760.  
  761. class Scene_File
  762.  
  763.   alias wor_scefil_upd_mouse update unless $@
  764.   def update(*args, &block)
  765.     (0..self.item_max - 1).each do |i|
  766.       ix = @savefile_windows[i].x
  767.       iy = @savefile_windows[i].y + 48
  768.       iw = @savefile_windows[i].width
  769.       ih = @savefile_windows[i].height
  770.       if Mouse.area?(ix, iy, iw, ih)
  771.         @savefile_windows[@index].selected = false
  772.         @savefile_windows[i].selected = true
  773.         @index = i
  774.       end
  775.     end
  776.     wor_scefil_upd_mouse(*args, &block)
  777.   end
  778. end
  779.  
  780. class Window_NameInput
  781.  
  782.   alias wor_winnam_upd_mouse update unless $@
  783.   def update(*args, &block)
  784.     wor_winnam_upd_mouse(*args, &block)
  785.     if self.active and self.visible
  786.       (0..self.table[@page].size - 1).each do |i|
  787.       irect = item_rect(i)
  788.       irx = self.x + 16 + irect.x - self.ox
  789.       iry = self.y + 16 + irect.y - self.oy
  790.       @index = i if Mouse.area?(irx, iry, irect.width, irect.height)
  791.       end
  792.     end
  793.   end
  794. end
  795.  
  796. class Window_PartyCommand
  797.  
  798.   def update_mouse
  799.     (0..self.item_max - 1).each do |i|
  800.     irect = item_rect(i)
  801.     irx = self.viewport.ox + 16 + irect.x - self.ox
  802.     iry = 288 + 16 + irect.y - self.oy + 64
  803.     self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
  804.     end
  805.   end
  806. end
  807.  
  808. class Window_ActorCommand
  809.  
  810.   def update_mouse
  811.     (0..self.item_max - 1).each do |i|
  812.     irect = item_rect(i)
  813.     irx = self.viewport.ox + 288 + 16 + irect.x + 96
  814.     iry = 288 + 16 + irect.y + 64
  815.     self.index = i if Mouse.area?(irx, iry, irect.width, irect.height)
  816.     end
  817.   end
  818. end
  819.  
  820. class Window_EventPopUp < Window_Base
  821.  
  822.   def initialize(x, y, width, height, text)
  823.     super(x, y, width, height)
  824.     self.opacity = 0
  825.     @text = text
  826.     refresh
  827.   end
  828.  
  829.   def refresh
  830.     self.contents.clear
  831.     self.contents.draw_text(0, 0, self.width, 24, @text)
  832.   end
  833. end
  834.  
  835. class Game_Event
  836.  
  837.   attr_accessor :popup_window, :page
  838.  
  839.   def check_for_comment(regexp)
  840.     return false if @list.nil?
  841.     for item in @list
  842.       if item.code == 108 or item.code == 408
  843.         if !item.parameters[0][regexp].nil?
  844.           return $1.nil? ? true : $1
  845.         end
  846.       end
  847.     end
  848.     return false
  849.   end
  850.  
  851.   def through
  852.     return true if check_for_comment(/MOUSE THROUGH/i) && $game_temp.making_path
  853.     return @through
  854.   end
  855.  
  856.   alias jet2734_update update unless $@
  857.   def update(*args, &block)
  858.     jet2734_update(*args, &block)
  859.     update_mouse_popup
  860.     update_mouse_change
  861.   end
  862.  
  863.   def update_mouse_popup
  864.     switch = $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  865.     if Mouse.true_grid == [self.x, self.y] && !switch && !@erased
  866.       f = self.check_for_comment(/MOUSE TEXT(.+)/i)
  867.       if f != false
  868.         q = Bitmap.new(1, 1)
  869.         size = q.text_size(f)
  870.         x = self.screen_x - 16 - size.width / 2
  871.         y = self.screen_y - 52 - size.height / 2
  872.         if self.popup_window != nil
  873.           self.popup_window.dispose
  874.           self.popup_window = nil
  875.         end
  876.         self.popup_window = Window_EventPopUp.new(x, y,
  877.           size.width + 34, size.height + 34, f)
  878.         q.dispose
  879.         q = nil
  880.       end
  881.     else
  882.       if self.popup_window != nil
  883.         self.popup_window.dispose
  884.         self.popup_window = nil
  885.       end
  886.     end
  887.   end
  888.  
  889.   def update_mouse_change
  890.     if Mouse.true_grid == [self.x, self.y]
  891.       f =(self.check_for_comment(/MOUSE PIC(.+)/i) rescue false)
  892.       if f != false
  893.         if f.to_i != 0
  894.           $cursor.change_cursor(f.to_i) unless $cursor.current_cursor == f.to_i
  895.         else
  896.           $cursor.change_cursor(f) unless $cursor.current_cursor == f
  897.         end
  898.         $game_temp.did_mouse_change = true
  899.       end
  900.     end
  901.   end
  902. end
  903.  
  904.  
  905. class Scene_Map
  906.  
  907.   alias jet6742_update update unless $@
  908.   def update(*args, &block)
  909.     if !$game_message.visible
  910.       update_mouse_left_click
  911.     end
  912.     jet6742_update(*args, &block)
  913.     check_mouse_change
  914.   end
  915.  
  916.   alias jet7811_terminate terminate unless $@
  917.   def terminate(*args, &block)
  918.     for event in $game_map.events.values
  919.       next if event.popup_window.nil?
  920.       event.popup_window.dispose unless event.popup_window.disposed?
  921.       event.popup_window = nil
  922.     end
  923.     $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
  924.       JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  925.     $cursor.opacity = 0
  926.     jet7811_terminate(*args, &block)
  927.     $cursor.opacity = 255 unless $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  928.   end
  929.  
  930.   alias jet8887_update_transfer_player update_transfer_player unless $@
  931.   def update_transfer_player(*args, &block)
  932.     if $game_player.transfer?
  933.       $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
  934.         JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  935.     end
  936.     jet8887_update_transfer_player(*args, &block)
  937.   end
  938.  
  939.   def check_mouse_change
  940.     return if $game_switches[JetMouse::TURN_MOUSE_OFF_SWITCH]
  941.     if $game_message.visible || $game_player.transfer?
  942.       $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if ![JetMouse::CURSOR_PICTURE,
  943.         JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  944.       return
  945.     end
  946.     $cursor.create_cursor(JetMouse::CURSOR_PICTURE) if $game_temp.did_mouse_change.nil? &&
  947.       ![JetMouse::CURSOR_PICTURE, JetMouse::ICON_INDEX].include?($cursor.current_cursor)
  948.     $game_temp.did_mouse_change = nil
  949.   end
  950.  
  951.   def update_mouse_left_click
  952.     return if $game_map.interpreter.running? || $game_player.transfer?
  953.     if Mouse.click?(1)
  954.       event_activated = false
  955.       for event in $game_map.events_xy(*Mouse.true_grid)
  956.         if event.check_for_comment(/MOUSE CLICK/i)
  957.           event.start
  958.           event_activated = true
  959.         elsif (event.x - $game_player.x).abs + (event.y - $game_player.y).abs == 1
  960.           if ![3, 4].include?(event.trigger) &&
  961.                (![0, 2].include?(event.priority_type) || event.trigger == 0) &&
  962.                   ![0, 1].include?(event.page.list.size)
  963.             if (event.y - $game_player.y).abs >
  964.                (event.x - $game_player.x).abs
  965.               if event.y - $game_player.y > 0
  966.                 $game_player.set_direction(2)
  967.               else
  968.                 $game_player.set_direction(8)
  969.               end
  970.             else
  971.               if event.x - $game_player.x > 0
  972.                 $game_player.set_direction(6)
  973.               else
  974.                 $game_player.set_direction(4)
  975.               end
  976.             end
  977.             event.start
  978.             event_activated = true
  979.             break
  980.           end
  981.         end
  982.         if !event_activated
  983.           for i in ["UP", "DOWN", "RIGHT", "LEFT"]
  984.             if event.check_for_comment(/MOUSE MOVE #{i}/i)
  985.               event_activated = true
  986.               case i
  987.               when "UP"
  988.                 x, y = event.x, event.y - 1
  989.               when "DOWN"
  990.                 x, y = event.x, event.y + 1
  991.               when "LEFT"
  992.                 x, y = event.x - 1, event.y
  993.               when "RIGHT"
  994.                 x, y = event.x + 1, event.y
  995.               end
  996.               break
  997.             end
  998.           end
  999.         end
  1000.       end
  1001.       if !event_activated
  1002.         x, y = *Mouse.true_grid
  1003.       end
  1004.       if !x.nil?
  1005.         $game_temp.move_because_of_mouse = true
  1006.         g = $game_player.find_mouse_path(x, y)
  1007.         $game_temp.mouse_path = g
  1008.       end
  1009.     end
  1010.   end
  1011. end


Lv3.寻梦者

梦石
0
星屑
4044
在线时间
1077 小时
注册时间
2008-5-17
帖子
218

开拓者

2
发表于 2012-12-1 23:58:51 | 只看该作者
你就不能用代码框???
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-9 14:39

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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