none.gif

ac68u

XP/VX ACE鼠标系统脚本,PC和Joiplay都能点击/触屏了

闲的无聊咨询GPT能不能给VX ACE做一个脚本,使VX、XP像MV一样支持鼠标游玩

它让我搜索,给了几个关键词,然后搜到了比较有用的东西

感觉比国内RPG论坛Sion用户分享的脚本好使,不需要额外的图片或DLL文件

https://forums.rpgmakerweb.com/index.php?threads/amaranths-super-simple-mouse-system-for-ace.17829/

1. 启动RPG Maker VX Ace或XP

2. 最上面菜单栏——工具——脚本编辑

3. 脚本最下面的main上边插入新脚本,随便命名,然后放入以下代码保存,即可游玩

注1:Shaz的原生脚本不能在Joiplay运行,个人删改了一些代码能跑起来,Joiplay体验不如MV自带好使,PC的还行

注2:不想花费精力学Ruby,有能力的同学改善代码增进用户体验

复制代码
  1. #============================================================================
  2. # SUPER SIMPLE MOUSE SCRIPT
  3. # v1.10 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This is a conversion of the XP Mouse script by Near Fantastica and
  6. # SephirothSpawn modified by Amaranth Games, to run under VX Ace.
  7. #----------------------------------------------------------------------------
  8. # To Install:
  9. # Copy and paste into a new slot in materials, below all other scripts
  10. #----------------------------------------------------------------------------
  11. # To Customize:
  12. # Add keyword icon index pairs to the ICON hash (below this documentation).  
  13. # Each of the keywords can be used in an event comment to make the mouse
  14. # cursor change into that icon when hovering over the event.
  15. #----------------------------------------------------------------------------
  16. # To Use:
  17. # Add the following comment to an event page:
  18. #   <mouse icon [x y] [name]>
  19. #   where icon is the keyword from the ICON hash below
  20. #   x and y are the offsets to override player movement (optional)
  21. #   name is the text to display next to the icon when hovering over the event (optional)
  22. #
  23. # Examples:
  24. # <mouse fight>
  25. #   will change the cursor into the 'fight' icon when over the event
  26. # <mouse touch 0 1>
  27. #   will change the cursor into the 'touch' icon when over the event, and
  28. #   make the player walk to the tile below the event when the mouse button is
  29. #   clicked
  30. # <mouse talk Gloria>
  31. #   will change the cursor into the 'talk' icon and display the name Gloria
  32. # <mouse talk 0 2 Henry Smith>
  33. #   will change the cursor into the 'talk' icon and display the name Henry Smith,
  34. #   and when the mouse button is clicked, the player will walk to the tile
  35. #   two below the event (good to use for shops where there's a counter in between)
  36. #
  37. # To force pathfinding on the player or an event, simply add a move route with
  38. # the player or event as the subject, with a Script command, and call
  39. # find_path(x, y) where x and y are the coordinates of the tile you want to move to
  40. # Examples:
  41. # Set Move Route (Player): Script: find_path(5, 8)
  42. #   will make the player find a path to tile 5, 8
  43. # Set Move Route (This Event): Script: find_path(10, 5)
  44. #   will make the event find a path to tile 10, 5
  45. #
  46. # NOTE: The path will be ATTEMPTED.  If there is no path TO that exact tile,
  47. # a path to an adjacent tile will be attempted.  If no path is found there
  48. # either, no movement will occur.
  49. # If a route is found, the player or event will begin moving towards it.  But
  50. # if their path is blocked while they are moving, movement will be cancelled.
  51. #----------------------------------------------------------------------------
  52. # Author's Notes:
  53. # This script should work with any RTP script.
  54. # I do not guarantee that it will work with ANY other script (especially anything
  55. # that overrides player or event movement, such as pixel movement scripts, or
  56. # custom window scripts).
  57. #
  58. # Script OVERWRITES the following methods:
  59. # Game_Map.setup_starting_map_event
  60. # Game_Map.setup_autorun_common_event
  61. #
  62. # If you have other scripts that ALIAS these methods, this mouse script should
  63. # be placed above them.
  64. #----------------------------------------------------------------------------
  65. # Terms:
  66. # Use in free and commercial games
  67. # Credit: Near Fantastica, SephirothSpawn, Amaranth Games, Shaz
  68. #----------------------------------------------------------------------------
  69. # Versions:
  70. # 1.0  -  6 Sept 2013 - initial release
  71. # 1.02 -  7 Sept 2013 - fixed crash when loading games saved prior to adding script
  72. #                     - fixed player gets stuck on impassable area on world map
  73. #                       when clicking while leaving air ship
  74. # 1.03 -  8 Sept 2013 - fixed actor moving to diagonal tile instead of adjacent
  75. # 1.04 - 10 Sept 2013 - fixed vehicle pathfinding on world map
  76. #                     - fixed event trigger when no path found
  77. # 1.05 - 14 Sept 2013 - tweaked accessing of tilemap offset
  78. # 1.06 -  3 Nov  2013 - disabled mouse movement when waiting for NPC move route
  79. #                     - fixed events not triggering after player finishes walking
  80. # 1.07 -  6 Nov  2013 - slow down mouse scrolling, and don't loop save files
  81. # 1.08 - 24 Nov  2013 - cater for YEA Core large resolution with too-small maps
  82. #                     - fixed early event activation bug introduced in 1.06
  83. #                     - replaced calc of Windows_Selectable boundaries with item_rect
  84. #                     - added ability to completely disable mouse
  85. # 1.09 - 21 Dec  2013 - fixed mouse re-enable when calling common events
  86. # 1.10 -  6 Apr  2014 - add interaction for top part of > 32pixel high event
  87. #                     - activate an event without walking up to it
  88. #                       (add <autoactivate> comment at top of event page)
  89. #                     - arrow keys override mouse movement when pathfinding
  90. #                     - ignore mouse in menus when using keyboard
  91. #                     - make player walk to counter opposite shopkeepers
  92. #============================================================================
  93. #============================================================================
  94. # SUPER SIMPLE MOUSE SCRIPT
  95. # Mouse Sprite
  96. #============================================================================
  97. # Add/remove/change icon names here.  The icon name is what will be used in the
  98. # event <mouse ...> command to show a different mouse icon when hovering over
  99. # the event.  These MUST be in lower case here!
  100. ICON = {'arrow' => 386, 'talk' => 4, 'look' => 3, 'fight' => 116,
  101.         'touch' => 491, 'exit' => 121}
  102. DEFAULT_ICON = 'arrow'
  103. # 在此处添加/删除/更改图标名称。图标名称是 # 事件  命令中使用的名称,用于在将鼠标悬停在 # 事件上时显示不同的鼠标图标。这些在这里必须是小写的!图标 = {'箭头' => 386, '谈话' => 4, '看' => 3, '战斗' => 116, '触摸' => 491, '退出' => 121} DEFAULT_ICON = '箭头'
  104. class Sprite_Mouse < Sprite
  105.   #--------------------------------------------------------------------------
  106.   # * Initialization
  107.   #--------------------------------------------------------------------------
  108.   def initialize
  109.     super
  110.     self.z = 10100
  111.     self.ox = 4
  112.     update
  113.     @dummy = Bitmap.new(32, 32)
  114.     self.bitmap = Bitmap.new(32, 32)
  115.     @enabled = true
  116.     @ignored = false
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Frame Update
  120.   #--------------------------------------------------------------------------
  121.   def update
  122.     return if !@enabled
  123.     super
  124.     if !SceneManager.scene.nil?
  125.       if !Mouse.position.nil?
  126.         mx, my = *Mouse.position
  127.         if @cursor == DEFAULT_ICON
  128.           self.x = mx unless mx.nil?
  129.         else
  130.           self.x = [mx, Graphics.width - self.bitmap.width].min unless mx.nil?
  131.         end
  132.         self.y = my unless my.nil?
  133.       end
  134.       if @scene != SceneManager.scene.class || Mouse.trigger?
  135.         @scene = SceneManager.scene.class
  136.         set_bitmap
  137.       end
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Set Bitmap
  142.   #--------------------------------------------------------------------------
  143.   def set_bitmap(cursor = DEFAULT_ICON, text = nil)
  144.     if @ignored
  145.       cursor = DEFAULT_ICON
  146.       text = nil
  147.     end
  148.       
  149.     if @cursor != cursor || @text != text
  150.       @cursor = cursor
  151.       @text = text
  152.       item_cursor = ICON[cursor]
  153.       rect = Rect.new(item_cursor % 16 * 24, item_cursor / 16 * 24, 24, 24)
  154.       if @text.nil?
  155.         self.bitmap = Bitmap.new(24, 32)
  156.         self.bitmap.blt(0, 0, Cache.system('Iconset'), rect)
  157.       else
  158.         w = @dummy.text_size(@text).width
  159.         h = @dummy.font.size
  160.         bitmap = Bitmap.new(26 + w, [32, h+2].max)
  161.         bitmap.font.size = @dummy.font.size
  162.         bitmap.font.shadow = true
  163.         if self.x + 26 + w > Graphics.width
  164.           bitmap.draw_text(0, 0, w, h, @text)
  165.           bitmap.blt(w, 0, Cache.system('Iconset'), rect)
  166.         else
  167.           bitmap.blt(0, 0, Cache.system('Iconset'), rect)
  168.           bitmap.draw_text(26, 0, w, h, @text)
  169.         end
  170.         self.bitmap = bitmap
  171.       end
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Update Event Cursors
  176.   #--------------------------------------------------------------------------
  177.   def update_event_cursors
  178.     # Remove mouse icon and text if we're off the grid
  179.     if Mouse.grid.nil?
  180.       set_bitmap
  181.       return
  182.     end
  183.     # Set cursor and text according to event
  184.     x, y = *Mouse.grid
  185.     event = $game_map.lowest_mouse_event_xy(x, y)
  186.     unless event.nil? && y < 410
  187.       if !event.mouse_icon.nil? || !event.mouse_text.nil?
  188.         set_bitmap(event.mouse_icon, event.mouse_text)
  189.         return
  190.       end
  191.     end
  192.     # default bitmap if not over an event
  193.     set_bitmap
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # * Enable Mouse
  197.   #--------------------------------------------------------------------------
  198.   def enabled=(value)
  199.     @enabled = value
  200.     self.visible = value
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * Mouse Enabled?
  204.   #--------------------------------------------------------------------------
  205.   def enabled?
  206.     @enabled
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Ignore Mouse
  210.   #--------------------------------------------------------------------------
  211.   def ignored=(value)
  212.     @ignored = value
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Mouse Ignored?
  216.   #--------------------------------------------------------------------------
  217.   def ignored?
  218.     @ignored
  219.   end
  220. end
  221. $mouse = Sprite_Mouse.new
  222. #============================================================================
  223. # SUPER SIMPLE MOUSE SCRIPT
  224. # Mouse Module
  225. #============================================================================
  226. #==============================================================================
  227. # ** Mouse Module
  228. #------------------------------------------------------------------------------
  229. #  by Near Fantastica and SephirothSpawn
  230. #  adapted and converted to VX Ace by Shaz
  231. #==============================================================================
  232. module Mouse
  233.   #--------------------------------------------------------------------------
  234.   # * Mouse to Input Triggers
  235.   #   key => Input::KeyCONSTANT (key: 0 - left, 1 - middle, 2 - right)
  236.   #--------------------------------------------------------------------------
  237.   Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}
  238.   #--------------------------------------------------------------------------
  239.   # * API Declarations
  240.   #--------------------------------------------------------------------------
  241.   GAKS = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
  242.   GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
  243.   Cursor_Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  244.   Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  245.   Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
  246.   Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  247.   Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  248.   ShowCursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
  249.   #--------------------------------------------------------------------------
  250.   # * Module Variables
  251.   #--------------------------------------------------------------------------
  252.   @triggers = [[0, 1], [0, 2], [0, 4]]
  253.   @old_pos = 0
  254.   @pos_i = 0
  255.   @sys_cursor_visible = false
  256.   #--------------------------------------------------------------------------
  257.   # * Mouse Grid Position
  258.   #--------------------------------------------------------------------------
  259.   def self.grid
  260.     return nil if @pos.nil?
  261.     mx, my = SceneManager.scene.instance_variable_get(:@spriteset).tilemap_offset
  262.     x = (@pos[0] + mx) / 32
  263.     y = (@pos[1] + my) / 32
  264.     return [x, y]
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * Mouse Position
  268.   #--------------------------------------------------------------------------
  269.   def self.position
  270.     return @pos.nil? ? [0, 0] : @pos
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # * Mouse Global Position
  274.   #--------------------------------------------------------------------------
  275.   def self.global_pos
  276.     pos = [0, 0].pack('ll')
  277.     return Cursor_Pos.call(pos) == 0 ? nil : pos.unpack('ll')
  278.   end
  279.   #--------------------------------------------------------------------------
  280.   # * Screen to Client
  281.   #--------------------------------------------------------------------------
  282.   def self.screen_to_client(x=0, y=0)
  283.     pos = [x, y].pack('ll')
  284.     return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # * Mouse Position
  288.   #--------------------------------------------------------------------------
  289.   def self.pos
  290.     gx, gy = global_pos
  291.     x, y = screen_to_client(gx, gy)
  292.     
  293.     # Test boundaries
  294.     begin
  295.       if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
  296.         return x, y
  297.       else
  298.         return -20, -20
  299.       end
  300.     rescue
  301.       return 0, 0
  302.     end
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # * Update Mouse Position
  306.   #--------------------------------------------------------------------------
  307.   def self.update
  308.     old_pos = @pos
  309.     @pos = self.pos
  310.     
  311.     # Has mouse been moved?
  312.     if old_pos != @pos
  313.       Input.method = :mouse
  314.     end
  315.     
  316.     # Which mouse to show - custom, or system?
  317.     if $mouse.enabled? == @sys_cursor_visible
  318.       @sys_cursor_visible = !@sys_cursor_visible
  319.       ShowCursor.call(@sys_cursor_visible ? 1 : 0)
  320.     end
  321.     
  322.     return if !$mouse.enabled?
  323.     
  324.     # Leaving / Entering Range?
  325.     if old_pos != [-20, -20] && @pos == [-20, -20] # leaving range
  326.       ShowCursor.call(1)
  327.     elsif old_pos == [-20, -20] && @pos != [-20, -20] # entering range
  328.       ShowCursor.call(0)
  329.     end
  330.     
  331.     # Update Triggers
  332.     for i in @triggers
  333.       n = GAKS.call(i[1])
  334.       if [0, 1].include?(n)
  335.         i[0] = (i[0] > 0 ? i[0] * -1 : 0)
  336.       else
  337.         i[0] = (i[0] > 0 ? i[0] + 1 : 1)
  338.       end
  339.     end
  340.   end
  341.   #--------------------------------------------------------------------------
  342.   # * Trigger?
  343.   #   id : 0:Left, 1:Right, 2:Center
  344.   #--------------------------------------------------------------------------
  345.   def self.trigger?(id = 0)
  346.     if pos != [-20, -20]
  347.       return @triggers[id][0] == 1
  348.     end
  349.     return false
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # * Repeat?
  353.   #   id : 0:Left, 1:Right, 2:Center
  354.   #--------------------------------------------------------------------------
  355.   def self.repeat?(id = 0)
  356.     return @triggers[id][0] > 0 && @triggers[id][0] % 5 == 1
  357.   end
  358.   #--------------------------------------------------------------------------
  359.   # * Hwnd
  360.   #--------------------------------------------------------------------------
  361.   def self.hwnd
  362.     if @hwnd.nil?
  363.       title = "\0" * 256
  364.       Readini.call('Game', 'Title', '', title, 255, '.\\Game.ini')
  365.       
  366.       @hwnd = Findwindow.call('RGSS Player', title)
  367.       ShowCursor.call(0)
  368.     end
  369.     return @hwnd
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # * Client Size
  373.   #--------------------------------------------------------------------------
  374.   def self.client_size
  375.     rect = [0, 0, 0, 0].pack('l4')
  376.     Client_rect.call(self.hwnd, rect)
  377.     return rect.unpack('l4')[2..3]
  378.   end
  379. end
  380. #============================================================================
  381. # SUPER SIMPLE MOUSE SCRIPT
  382. # Input
  383. #============================================================================
  384. class << Input
  385.   #--------------------------------------------------------------------------
  386.   # * Public Instance Variables
  387.   #--------------------------------------------------------------------------
  388.   attr_accessor :method
  389.   #--------------------------------------------------------------------------
  390.   # * Alias Listings
  391.   #--------------------------------------------------------------------------
  392.   alias :seph_mouse_input_update :update
  393.   alias :seph_mouse_input_trigger? :trigger?
  394.   alias :seph_mouse_input_repeat? :repeat?
  395.   #--------------------------------------------------------------------------
  396.   # * Frame Update
  397.   #--------------------------------------------------------------------------
  398.   def update
  399.     $mouse.update
  400.     Mouse.update
  401.     seph_mouse_input_update
  402.     # Are we using the mouse or the keyboard?
  403.     @method = :keyboard if dir4 != 0 || dir8 != 0
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # * Trigger? Test
  407.   #--------------------------------------------------------------------------
  408.   def trigger?(constant)
  409.     return true if seph_mouse_input_trigger?(constant)
  410.     if $mouse.enabled? && !Mouse.pos.nil?
  411.       if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
  412.         return true if Mouse.trigger?(Mouse::Mouse_to_Input_Triggers.index(constant))
  413.       end
  414.     end
  415.     return false
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # * Repeat? Test
  419.   #--------------------------------------------------------------------------
  420.   def repeat?(constant)
  421.     return true if seph_mouse_input_repeat?(constant)
  422.     if $mouse.enabled? && !Mouse.pos.nil?
  423.       if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
  424.         return true if Mouse.repeat?(Mouse::Mouse_to_Input_Triggers.index(constant))
  425.       end
  426.     end
  427.     return false
  428.   end
  429. end
  430. #============================================================================
  431. # SUPER SIMPLE MOUSE SCRIPT
  432. # Map
  433. #============================================================================
  434. class Spriteset_Map
  435.   #--------------------------------------------------------------------------
  436.   # * Tilemap Offset
  437.   #--------------------------------------------------------------------------
  438.   def tilemap_offset
  439.     if $imported && $imported["YEA-CoreEngine"]
  440.       [@tilemap.ox - @viewport1.rect.x, @tilemap.oy - @viewport1.rect.y]
  441.     else
  442.       [@tilemap.ox, @tilemap.oy]
  443.     end
  444.   end
  445. end
  446. class Game_Map
  447.   #--------------------------------------------------------------------------
  448.   # * Detect/Set Up Starting Map Event
  449.   #--------------------------------------------------------------------------
  450.   def setup_starting_map_event
  451.     event = @events.values.find {|event| event.starting }
  452.     event.clear_starting_flag if event
  453.     @interpreter.setup(event.list, event.id, event.trigger_in?([0,1,2,3])) if event
  454.     event
  455.   end
  456.   #--------------------------------------------------------------------------
  457.   # * Detect/Set Up Autorun Common Event
  458.   #--------------------------------------------------------------------------
  459.   def setup_autorun_common_event
  460.     event = $data_common_events.find do |event|
  461.       event && event.autorun? && $game_switches[event.switch_id]
  462.     end
  463.     @interpreter.setup(event.list, 0, true) if event
  464.     event
  465.   end
  466.   #--------------------------------------------------------------------------
  467.   # * Get ID of Lowest Mouse-enabled Event at Designated Coordinates
  468.   #--------------------------------------------------------------------------
  469.   def lowest_mouse_event_xy(x, y)
  470.     list = events_xy(x, y) + events_xy(x, y+1)
  471.     list.sort! {|a, b| b.y - a.y}
  472.     evt = nil
  473.     list.each do |event|
  474.       if (event.pos?(x, y) || (event.pos?(x, y+1) && event.height > 32)) &&
  475.         (evt.nil? || event.y > evt.y)
  476.         evt = event
  477.         break
  478.       end
  479.     end
  480.     return evt
  481.   end
  482. end
  483. class Scene_Map
  484.   #--------------------------------------------------------------------------
  485.   # * Frame Update
  486.   #--------------------------------------------------------------------------
  487.   alias shaz_mouse_scene_map_update update
  488.   def update
  489.     $mouse.update_event_cursors
  490.     shaz_mouse_scene_map_update
  491.   end
  492. end
  493. #============================================================================
  494. # SUPER SIMPLE MOUSE SCRIPT
  495. # Event
  496. #============================================================================
  497. module RPG
  498.   class Event
  499.     class Page
  500.       #--------------------------------------------------------------------
  501.       # * Public Instance Variables
  502.       #--------------------------------------------------------------------
  503.       attr_reader :mouse_icon
  504.       attr_reader :mouse_text
  505.       attr_reader :mouse_position
  506.       attr_reader :mouse_autoactivate
  507.       #--------------------------------------------------------------------
  508.       # * Build Stats
  509.       #--------------------------------------------------------------------
  510.       def build_stats
  511.         # Mouse icons (icon mandatory, others optional)
  512.         # <mouse icon destx desty name>
  513.         @mouse_icon = nil
  514.         @mouse_text = nil
  515.         @mouse_position = [0, 0]
  516.         @mouse_autoactivate = false
  517.         # look for mouse instructions
  518.         list.each do |command|
  519.           if [108, 408].include?(command.code)
  520.             comment = command.parameters[0]
  521.               case comment
  522.               when /<mouse/i
  523.                 params = /<mouse (.*)>/i.match(comment)[1].split(' ')
  524.                 @mouse_icon = params.shift
  525.                 if params.size > 1 && params[0] =~ /\d+/ && params[1] =~ /\d+/
  526.                   @mouse_position = [params.shift.to_i, params.shift.to_i]
  527.                 end
  528.                 if params.size > 0
  529.                   @mouse_text = params.join(' ')
  530.                 end
  531.               when /<autoactivate>/
  532.                 @mouse_autoactivate = true
  533.               end
  534.           end #if
  535.         end #do
  536.       end #def
  537.     end
  538.   end
  539. end
  540. class Game_Event < Game_Character
  541.   #--------------------------------------------------------------------------
  542.   # * Public Instance Variables
  543.   #--------------------------------------------------------------------------
  544.   attr_reader   :mouse_icon
  545.   attr_reader   :mouse_text
  546.   attr_reader   :mouse_position
  547.   attr_reader   :mouse_autoactivate
  548.   #--------------------------------------------------------------------------
  549.   # * Start Event
  550.   #--------------------------------------------------------------------------
  551.   alias shaz_mouse_game_event_start start
  552.   def start
  553.     $game_player.start_event(@id) if !empty?
  554.     shaz_mouse_game_event_start
  555.   end
  556.   #--------------------------------------------------------------------------
  557.   # * Clear Event Page Settings
  558.   #--------------------------------------------------------------------------
  559.   alias shaz_mouse_game_event_clear_page_settings clear_page_settings
  560.   def clear_page_settings
  561.     shaz_mouse_game_event_clear_page_settings
  562.     @mouse_icon = nil
  563.     @mouse_text = nil
  564.     @mouse_position = [0, 0]
  565.     @mouse_autoactivate = false
  566.     @height = 0
  567.   end
  568.   #--------------------------------------------------------------------------
  569.   # * Set Up Event Page Settings
  570.   #--------------------------------------------------------------------------
  571.   alias shaz_mouse_game_event_setup_page_settings setup_page_settings
  572.   def setup_page_settings
  573.     shaz_mouse_game_event_setup_page_settings
  574.     @page.build_stats
  575.     @mouse_icon         = @page.mouse_icon
  576.     @mouse_text         = @page.mouse_text
  577.     @mouse_position     = @page.mouse_position
  578.     @mouse_autoactivate = @page.mouse_autoactivate
  579.     set_size
  580.   end
  581. end
  582. #============================================================================
  583. # SUPER SIMPLE MOUSE SCRIPT
  584. # Character
  585. #============================================================================
  586. class Game_CharacterBase
  587.   attr_reader :height                            # Height of character bitmap
  588.   #--------------------------------------------------------------------------
  589.   # * Initialize Public Member Variables
  590.   #--------------------------------------------------------------------------
  591.   alias shaz_mouse_game_characterbase_init_public_members init_public_members
  592.   def init_public_members
  593.     shaz_mouse_game_characterbase_init_public_members
  594.     @height = 0
  595.   end
  596.   #--------------------------------------------------------------------------
  597.   # * Change Graphics
  598.   #     character_name  : new character graphic filename
  599.   #     character_index : new character graphic index
  600.   #--------------------------------------------------------------------------
  601.   alias shaz_mouse_game_characterbase_set_graphic set_graphic
  602.   def set_graphic(character_name, character_index)
  603.     shaz_mouse_game_characterbase_set_graphic(character_name, character_index)
  604.     set_size
  605.   end
  606.   #--------------------------------------------------------------------------
  607.   # * Set character width/height size
  608.   #--------------------------------------------------------------------------
  609.   def set_size
  610.     bw = Cache.character(@character_name).width
  611.     bh = Cache.character(@character_name).height
  612.     sign = @character_name[/^[\!\$]./]
  613.     if sign && sign.include?('$')
  614.       @width = bw / 3
  615.       @height = bh / 4
  616.     else
  617.       @width = bw / 12
  618.       @height = bh / 8
  619.     end
  620.   end
  621.   #--------------------------------------------------------------------------
  622.   # * Detect Collision with Event
  623.   #--------------------------------------------------------------------------
  624.   def collide_with_events?(x, y)
  625.     $game_map.events_xy_nt(x, y).any? do |event|
  626.       self != event && (event.normal_priority? || self.is_a?(Game_Event))
  627.     end
  628.   end
  629.   #--------------------------------------------------------------------------
  630.   # * Detect Collision with Vehicle
  631.   #--------------------------------------------------------------------------
  632.   def collide_with_vehicles?(x, y)
  633.     !self.is_a?(Game_Player) && ($game_map.boat.pos_nt?(x, y) || $game_map.ship.pos_nt?(x, y))
  634.   end
  635.   #--------------------------------------------------------------------------
  636.   # * Frame Update
  637.   #--------------------------------------------------------------------------
  638.   alias shaz_mouse_game_characterbase_update update
  639.   def update
  640.     run_path if @runpath
  641.     shaz_mouse_game_characterbase_update
  642.   end
  643.   #--------------------------------------------------------------------------
  644.   # * Run Path
  645.   #--------------------------------------------------------------------------
  646.   def run_path
  647.     return if moving?
  648.     @step = @map.nil? || @map[@x, @y].nil? ? 0 : @map[@x, @y] - 1
  649.     if @step < 1
  650.       clear_path
  651.     else
  652.       x, y = @x, @y
  653.       dirs = []
  654.       dirs.push(6) if @map[@x+1, @y] == @step && passable?(@x, @y, 6)
  655.       dirs.push(2) if @map[@x, @y+1] == @step && passable?(@x, @y, 2)
  656.       dirs.push(4) if @map[@x-1, @y] == @step && passable?(@x, @y, 4)
  657.       dirs.push(8) if @map[@x, @y-1] == @step && passable?(@x, @y, 8)
  658.       while dirs.size > 0
  659.         dir = dirs.delete_at(rand(dirs.size))
  660.         move_straight(dir)
  661.         break if x != @x || y != @y
  662.       end
  663.       # clear the path if we couldn't move
  664.       clear_path if x == @x && y == @y
  665.     end
  666.   end
  667.   #--------------------------------------------------------------------------
  668.   # * Find Path
  669.   #--------------------------------------------------------------------------
  670.   def find_path(x, y)
  671.     sx, sy = @x, @y
  672.     @tx, @ty = x, y
  673.     result = setup_map(sx, sy)
  674.     @runpath = result[0]
  675.     @map = result[1]
  676.     @map[sx, sy] = result[2] if result[2] != nil
  677.   end
  678.   #--------------------------------------------------------------------------
  679.   # * Clear Path
  680.   #--------------------------------------------------------------------------
  681.   def clear_path
  682.     @map = nil
  683.     @runpath = false
  684.   end
  685.   #--------------------------------------------------------------------------
  686.   # * Setup Map
  687.   #--------------------------------------------------------------------------
  688.   def setup_map(sx, sy)
  689.     map = Table.new($game_map.width, $game_map.height)
  690.     update_counter = 0
  691.     map[@tx, @ty] = 1
  692.     old_positions = [[@tx, @ty]]
  693.     new_positions = []
  694.     
  695.     # if tile is impassable, but CAN move to adjacent tiles, use the adjacent tiles instead
  696.     if (!passable?(@tx, @ty, 2) && !passable?(@tx, @ty, 4) &&
  697.       !passable?(@tx, @ty, 6) && !passable?(@tx, @ty, 8)) ||
  698.       $game_map.events_xy_nt(@tx, @ty).any? { |evt| evt.normal_priority? && evt != self }
  699.       old_positions = []
  700.       
  701.       # Can we move from the destination tile in any direction?
  702.       if map_passable?(@tx, @ty, 2)
  703.         map[@tx, @ty+1] = 1
  704.         old_positions.push([@tx, @ty+1])
  705.       end
  706.       if map_passable?(@tx, @ty, 8)
  707.         map[@tx, @ty-1] = 1
  708.         old_positions.push([@tx, @ty-1])
  709.       end
  710.       if map_passable?(@tx, @ty, 4)
  711.         map[@tx-1, @ty] = 1
  712.         old_positions.push([@tx-1, @ty])
  713.       end
  714.       if map_passable?(@tx, @ty, 6)
  715.         map[@tx+1, @ty] = 1
  716.         old_positions.push([@tx+1, @ty])
  717.       end
  718.       
  719.       # If not, can we at least move up to the destination tile?
  720.       if old_positions.size == 0
  721.         if map_passable?(@tx-1,@ty,6)
  722.           map[@tx-1,@ty] = 1
  723.           old_positions.push([@tx-1,@ty])
  724.         end
  725.         if map_passable?(@tx+1,@ty,4)
  726.           map[@tx+1,@ty] = 1
  727.           old_positions.push([@tx+1,@ty])
  728.         end
  729.         if map_passable?(@tx,@ty-1,2)
  730.           map[@tx,@ty-1] = 1
  731.           old_positions.push([@tx,@ty-1])
  732.         end
  733.         if map_passable?(@tx,@ty+1,8)
  734.           map[@tx,@ty+1] = 1
  735.           old_positions.push([@tx,@ty+1])
  736.         end
  737.       end
  738.     end
  739.     
  740.     # If there are any counters, can we move to the tile on the other side?
  741.     if map_passable?(@tx-2,@ty,6) && $game_map.counter?(@tx-1,@ty)
  742.       map[@tx-2,@ty] = 1
  743.       old_positions.push([@tx-2,@ty])
  744.     end
  745.     if map_passable?(@tx+2,@ty,4) && $game_map.counter?(@tx+1,@ty)
  746.       map[@tx+2,@ty] = 1
  747.       old_positions.push([@tx+2,@ty])
  748.     end
  749.     if map_passable?(@tx,@ty-2,2) && $game_map.counter?(@tx,@ty-1)
  750.       map[@tx,@ty-2] = 1
  751.       old_positions.push([@tx,@ty-2])
  752.     end
  753.     if map_passable?(@tx,@ty+2,2) && $game_map.counter?(@tx,@ty+1)
  754.       map[@tx,@ty+2] = 1
  755.       old_positions.push([@tx,@ty+2])
  756.     end
  757.     
  758.     
  759.     depth = 2
  760.     depth.upto(100) { |step|
  761.       break if old_positions[0].nil?
  762.       @step = step
  763.       loop do
  764.         break if old_positions[0].nil?
  765.         x, y = old_positions.shift
  766.         return [true, map, @step-1] if x == sx && y == sy
  767.         if map[x, y + 1] == 0 && passable?(x, y, 2)
  768.           map[x, y + 1] = @step
  769.           new_positions.push([x, y + 1])
  770.         end
  771.         if map[x - 1, y] == 0 && passable?(x, y, 4)
  772.           map[x - 1, y] = @step
  773.           new_positions.push([x - 1, y])
  774.         end
  775.         if map[x + 1, y] == 0 && passable?(x, y, 6)
  776.           map[x + 1, y] = @step
  777.           new_positions.push([x + 1, y])
  778.         end
  779.         if map[x, y - 1] == 0 && passable?(x, y, 8)
  780.           map[x, y - 1] = @step
  781.           new_positions.push([x, y - 1])
  782.         end
  783.         # Update graphics? (to reduce lag)
  784.         update_counter += 1
  785.         if update_counter > 50
  786.           Graphics.update
  787.           update_counter = 0
  788.         end
  789.       end
  790.       old_positions = new_positions
  791.       new_positions = []
  792.     }
  793.     return [false, nil, nil]
  794.   end
  795. end  
  796. class Game_Character < Game_CharacterBase
  797.   #--------------------------------------------------------------------------
  798.   # * Force Move Route
  799.   #--------------------------------------------------------------------------
  800.   alias shaz_mouse_game_character_force_move_route force_move_route
  801.   def force_move_route(move_route)
  802.     clear_path
  803.     shaz_mouse_game_character_force_move_route(move_route)
  804.   end
  805. end
  806. #============================================================================
  807. # SUPER SIMPLE MOUSE SCRIPT
  808. # Player
  809. #============================================================================
  810. class Game_Player < Game_Character
  811.   #--------------------------------------------------------------------------
  812.   # * Trigger Map Event
  813.   #     triggers : Trigger array
  814.   #     normal   : Is priority set to [Same as Characters] ?
  815.   #--------------------------------------------------------------------------
  816.   alias shaz_mouse_game_player_start_map_event start_map_event
  817.   def start_map_event(x, y, triggers, normal)
  818.     @started_events = []
  819.     shaz_mouse_game_player_start_map_event(x, y, triggers, normal)
  820.   end
  821.   #--------------------------------------------------------------------------
  822.   # * Start Event
  823.   #--------------------------------------------------------------------------
  824.   def start_event(event_id)
  825.     @started_events = [] if @started_events.nil?
  826.     @started_events.push(event_id)
  827.   end
  828.   #--------------------------------------------------------------------------
  829.   # * Processing of Movement via Input from Directional Buttons
  830.   #--------------------------------------------------------------------------
  831.   alias shaz_mouse_game_player_move_by_input move_by_input
  832.   def move_by_input
  833.     if Input.dir4 > 0
  834.       clear_path
  835.       shaz_mouse_game_player_move_by_input
  836.     else
  837.       # Move by mouse input
  838.       if !$game_message.busy? && !$game_message.visible && !@move_route_forcing &&
  839.         !@vehicle_getting_on && !@vehicle_getting_off &&
  840.         Mouse.trigger?(0) && !Mouse.grid.nil? && !$mouse.ignored?
  841.         mx, my = *Mouse.grid
  842.         # turn in direction
  843.         if (@x - mx).abs >= (@y - my).abs
  844.           set_direction(@x > mx ? 4 : 6)
  845.         else
  846.           set_direction(@y > my ? 8 : 2)
  847.         end
  848.         # find path
  849.         @event = $game_map.lowest_mouse_event_xy(mx, my)
  850.         if @event.nil?
  851.           find_path(mx, my)
  852.         elsif @event.mouse_autoactivate
  853.           @event.start
  854.           @started_events = []
  855.           clear_path
  856.         
  857.         end
  858.       end
  859.     end
  860.   end
  861.   #--------------------------------------------------------------------------
  862.   # * Frame Update
  863.   #--------------------------------------------------------------------------
  864.   alias shaz_mouse_game_player_update update
  865.   def update
  866.     shaz_mouse_game_player_update
  867.     update_pathfinding if [email protected]? && !moving?
  868.   end
  869.   #--------------------------------------------------------------------------
  870.   # * Check event after pathfinding
  871.   #--------------------------------------------------------------------------
  872.   def update_pathfinding
  873.     if @map.nil? || @map[@x, @y] <= 1
  874.       dir = @x < @event.x ? 6 : @x > @event.x ? 4 : @y < @event.y ? 2 : @y > @event.y ? 8 : 0
  875.       # Face event and trigger it (only if not triggered by start_map_event)
  876.       turn_toward_character(@event) if [email protected]?(@x, @y)
  877.       if !@started_events.include?(@event.id) && [email protected]? && !in_airship?
  878.         @event.start
  879.         @started_events = []
  880.       end
  881.       clear_path
  882.     end
  883.   end
  884.   #--------------------------------------------------------------------------
  885.   # * Clear Path
  886.   #--------------------------------------------------------------------------
  887.   def clear_path
  888.     @event = nil
  889.     super
  890.   end
  891. end
  892. #============================================================================
  893. # SUPER SIMPLE MOUSE SCRIPT
  894. # Interpreter
  895. #============================================================================
  896. class Game_Interpreter
  897.   #--------------------------------------------------------------------------
  898.   # * Event Setup
  899.   #--------------------------------------------------------------------------
  900.   alias shaz_mouse_game_interpreter_setup setup
  901.   def setup(list, event_id = 0, lock_player = false)
  902.     shaz_mouse_game_interpreter_setup(list, event_id)
  903.     @lock_player = lock_player
  904.   end
  905.   #--------------------------------------------------------------------------
  906.   # * Execute
  907.   #--------------------------------------------------------------------------
  908.   alias shaz_mouse_game_interpreter_run run
  909.   def run
  910.     $mouse.ignored = true if @lock_player
  911.     shaz_mouse_game_interpreter_run
  912.     $mouse.ignored = false if @lock_player
  913.   end
  914. end
  915. #============================================================================
  916. # SUPER SIMPLE MOUSE SCRIPT
  917. # Windows
  918. #============================================================================
  919. class Window_Selectable < Window_Base
  920.   #--------------------------------------------------------------------------
  921.   # * Frame Update
  922.   #--------------------------------------------------------------------------
  923.   alias shaz_mouse_window_selectable_update update
  924.   def update
  925.     shaz_mouse_window_selectable_update
  926.     process_mouse_handling if Input.method == :mouse
  927.   end
  928.   #--------------------------------------------------------------------------
  929.   # * Mouse Movement Processing
  930.   #--------------------------------------------------------------------------
  931.   def process_mouse_handling
  932.     return unless $mouse.enabled? && cursor_movable?
  933.     # Add a delay to prevent too-fast scrolling
  934.     @delay = @delay ? @delay + 1 : 0
  935.     return if @delay % 3 > 0
  936.     
  937.     mx, my = *Mouse.position
  938.     vx = self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x
  939.     vy = self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y
  940.     if mx.between?(vx, vx + self.width) &&
  941.       my.between?(vy, vy + self.height)
  942.       mx -= vx
  943.       mx -= padding
  944.       my -= vy
  945.       my -= padding
  946.       my += oy
  947.       for i in 0 ... item_max
  948.         rect = item_rect(i)
  949.         if mx.between?(rect.x, rect.x + rect.width) &&
  950.           my.between?(rect.y, rect.y + rect.height)
  951.           last_index = @index
  952.           select(i)
  953.           if @index != last_index
  954.             Sound.play_cursor
  955.           end
  956.           break
  957.         end
  958.       end
  959.     end
  960.   end
  961. end  
  962. class Window_NameInput < Window_Selectable
  963.   #--------------------------------------------------------------------------
  964.   # * Mouse Movement Processing
  965.   #--------------------------------------------------------------------------
  966.   def process_mouse_handling
  967.     return unless $mouse.enabled?
  968.     # Add a delay to prevent too-fast scrolling
  969.     @delay = @delay ? @delay + 1 : 0
  970.     return if @delay % 3 > 0
  971.     
  972.     mx, my = *Mouse.position
  973.     vx = (self.viewport ? self.x - self.viewport.ox + self.viewport.rect.x : self.x) + padding
  974.     vy = (self.viewport ? self.y - self.viewport.oy + self.viewport.rect.y : self.y) + padding
  975.     if mx.between?(vx, vx + self.width - padding * 2) &&
  976.       my.between?(vy, vy + self.height - padding * 2)
  977.       mx -= vx
  978.       my -= vy
  979.       x = (mx > 5*32+16 ? mx-16 : mx) / 32
  980.       y = my / line_height
  981.       last_index = @index
  982.       @index = y * 10 + x
  983.       Sound.play_cursor if @index != last_index
  984.     end
  985.   end
  986. end
  987. class Scene_File < Scene_MenuBase
  988.   #--------------------------------------------------------------------------
  989.   # * Update Cursor
  990.   #--------------------------------------------------------------------------
  991.   alias shaz_mouse_scene_file_update_cursor update_cursor
  992.   def update_cursor
  993.     shaz_mouse_scene_file_update_cursor
  994.     process_mouse_handling if Input.method == :mouse
  995.   end
  996.   #--------------------------------------------------------------------------
  997.   # * Mouse Movement Processing
  998.   #--------------------------------------------------------------------------
  999.   def process_mouse_handling
  1000.     return unless $mouse.enabled?
  1001.     # Add a delay to prevent too-fast scrolling
  1002.     @delay = @delay ? @delay + 1 : 0
  1003.     return if @delay % 3 > 0
  1004.     
  1005.     mx, my = *Mouse.position
  1006.     vx = @savefile_viewport.ox + mx
  1007.     vy = @savefile_viewport.oy + my
  1008.     last_index = @index
  1009.     new_index = vy / savefile_height
  1010.     if @index != new_index
  1011.       if new_index > @index
  1012.         cursor_down(false)
  1013.       else
  1014.         cursor_up(false)
  1015.       end
  1016.       Sound.play_cursor
  1017.       @savefile_windows[last_index].selected = false
  1018.       @savefile_windows[@index].selected = true
  1019.     end
  1020.   end
  1021. end



none.gif

hyyd

感谢大佬,真是帮大忙了,想找这东西找了好久

maple

B2F  2023-10-03 00:49
    

none.gif

e88f6be5

优秀

none.gif

e615f30a

牛!先马住,用的时候看看