查看: 2495|回复: 3

[已经解决] 鼠标所在地图上的XY坐标

[复制链接]
梦石
0
星屑
103
在线时间
10 小时
注册时间
2018-1-13
回帖
5
发表于 2019-6-16 12:28:46 | 显示全部楼层 |阅读模式
悬赏50星屑已解决
本帖最后由 VIPArcher 于 2022-6-8 17:18 编辑

这是一个鼠标脚本,我想通过赋值的方式赋予变量鼠标所在地图上XY坐标的位置,可是鼠标所在地图上XY坐标的代码名称我没有找到,希望有大佬相助
  1. =begin
  2. ==========================================================================
  3. 鼠标系统按钮2.5
  4. ===========================================================================
  5. 这是一个基于鼠标脚本,让之创造尽可能多的按钮,你要在地图屏幕或地图地,也是游戏中
  6. 为您提供完整的RMVXACE鼠标交互播放
  7. 安装、复制并粘贴上面主这个脚本做鼠标触发
  8. - 左击:动作按钮
  9. - 右键点击:取消按钮,关闭窗口# - 鼠标滚轮中键: DASH
  10. ————————————————————————————————————————
  11. *主要功能
  12. - 允许您创建按钮,并配置它们做一些事情
  13. - 事件可以是按钮也对应地按钮!对于一些难题等等
  14. - 允许您显示事件名称
  15. - 全鼠标交互
  16. - WASD移动可选
  17. - 寻路功能,玩家可以用鼠标
  18. Mouse.show_cursor内的鼠标光标(假的)
  19. 如果你想手动改变鼠标光标使用下面的脚本调用# Mouse.set_cursor ( :图标集, X)
  20. - 将x更改为任何图标索引#
  21. 如果你想显示一个图片,而不是图标集使用下一个脚本调用# Mouse.set_cursor
  22. =end
  23. #===========================================================================#
  24. #  #*****************#                                                      #
  25. #  #*** By Falcao ***#         Mouse System Buttons 2.5                     #
  26. #  #*****************#         This is a button based mouse script, allow   #
  27. #                              create as many buttons you want to the map   #
  28. #                              screen or map ground, also provide you full  #
  29. #       RMVXACE                mouse interaction within the game play       #
  30. #                                                                           #
  31. #                                                                           #
  32. # Falcao RGSS site:  [url]http://falcaorgss.wordpress.com[/url]                        #
  33. # Falcao Forum site: [url]http://makerpalace.com[/url]                                 #
  34. #                                                                           #
  35. #===========================================================================#

  36. #----------------------------------------------------------------------------
  37. # * Version 2.5 change log (Date: June 9 2013)
  38. #
  39. # Fixed non-refreshing item description bug
  40. # Fixed Save file selection issue
  41. # Added ability to start events even if the player is no facing the event
  42. # Removed option to display arrow selector on save file
  43. # Added compatibility for multiples game resolutions
  44. # Item selection with mouse is now more occurate
  45. # Fixed issue with pearl skillbar (when clicking any tool perform path finding)
  46. # Cleaned up some code
  47. #
  48. #----------------------------------------------------------------------------
  49. # * Version 2.0 change log (Date: January 13 2013)
  50. #
  51. # - Added path finding, now the game player is able to move using the mouse
  52. # - Now you are able to change the mouse cursor icon in game
  53. # - Two new notetags added to change the mouse cursor by event comment tags
  54. # - Fixed crash when pointing a notetagged event with a valid condition
  55. #----------------------------------------------------------------------------
  56. # * Version 1.6 change log (Date: November 21 2012)
  57. #
  58. # - Added compatibility for any game screen resolution
  59. # - System optimized to consume less cpu than before
  60. # - Added extra compatibility for Pearl ABS Liquid
  61. # - Removed the font fix
  62. # - Added the imported bolean
  63. #----------------------------------------------------------------------------
  64. # * Version 1.5 change log
  65. #
  66. # - Fixed cursor sound over loading on selectable windows
  67. # - Fixed bug when selecting event graphic tileset that have mouse comment tag
  68. # - FIxed minor bug when transfering (event name now erase completely)
  69. # - Added option to turn on / off arrow selector on save file
  70. # - Important! changes on mouse comment tags!
  71. #   ~ CLICK START change to MOUSE START
  72. #   ~ ANIMATION   change to MOUSE ANIMATION
  73. #   ~ NAME        change to MOUSE NAME
  74. #
  75. #---------------------------------------------------------------------------
  76. # * installation
  77. #
  78. # Copy and paste this script above main done!
  79. #
  80. # * Mouse triggers
  81. #   - Left click:     Action button
  82. #   - Right click:    Cancel button, close windows
  83. #   - Mouse wheel middle button:   DASH
  84. #
  85. #---------------------------------------------------------------------------
  86. # * Main features
  87. #
  88. # - Allow you create buttons and configure them to do something
  89. # - Events can be buttons too, map ground buttons! for some puzzles etc.
  90. # - Allow you display event name
  91. # - Full mouse interaction
  92. # - WASD movement optional
  93. # - Path finding feature, player is able to move using the mouse
  94. # - Mouse cursor changing in-game enabled
  95. #---------------------------------------------------------------------------
  96. # * Event buttons commands
  97. #
  98. # Write this lines on event comments tags
  99. #
  100. # MOUSE START       - Event start when you click the event
  101. # MOUSE ANIMATION x - Show animation when mouse is over event,
  102. #                     ex: MOUSE ANIMATION 1
  103. # MOUSE NAME x      - Display event name when mouse is over event,
  104. #                     ex: MOUSE NAME Falcao
  105. # MOUSE ICON x      - change the mouse cursor icon when it is over the event
  106. #                     change x for the icon index to display
  107. # MOUSE PIC X       - Change the mouse cursor when is over an event but in this
  108. #                     case it display a picture graphic name, change x for the
  109. #                     picture name
  110. #------------------------------------------------------------------------------
  111. # * Script calls
  112. #
  113. # Call this line to turn off/on the mouse cursor within the game true/false
  114. # Mouse.show_cursor(false)
  115. #
  116. # If you want to change the mouse cursor manually use the following script calls
  117. # Mouse.set_cursor(:iconset, x)     - change x for any icon index
  118. #
  119. # if you want to show a picture instead iconset use the next script call
  120. # Mouse.set_cursor(:picture, name)  - change name for picture name
  121. #-----------------------------------------------------------------------------

  122. module Map_Buttons

  123. # You can easily insert as many buttons you want to the map screen
  124. # define here below your buttons parameters

  125.   Insert = {
  126. #-----------------------------------------------------------------------------
  127. #  A => [B, C, D, E, F]
  128. #  
  129. #  A = Button number 按键序号
  130. #
  131. #  B = Name  游戏中按键显示的名字
  132. #  C = X position in screen tile  屏幕上X坐标
  133. #  D = Y position in screen tile  屏幕上Y坐标
  134. #  E = Icon, if you want a picture write picture 'name' otherwise icon index
  135. #  F = What this button gonna do?, you have two options, call scene or call
  136. #  common event, if you want scene put scene name, if you want common event
  137. #  put common event ID

  138. #Y坐标12,显示在最靠近屏幕下方。添加新菜单的时候请将Y坐标-1。
  139. #F处可填场景呼叫和公共事件ID。

  140.   # This button call the menu screen

  141.   
  142.   
  143. # ID=> ["显示名称", X,   Y, 图标Index, 呼出菜单],
  144.     1=>  ["Menu",    16,  11, 117,      Scene_Menu],
  145. # ID=> ["显示名称", X,   Y, 图标Index, 呼出菜单],
  146.   

  147.   }

  148. # * General configutration

  149. # Mouse cursor icon, if you want a picture write pic 'name' otherwise icon index
  150.   CursorIcon = 386

  151. # Switch ID to turn off/on the icons on the screen
  152.   Switch = 100

  153. # Allow movement with  W A S D keys true/false
  154.   WASD_Movement = true

  155. # When you click on event, do you want the player to ignore the self movement?
  156.   IgnoreEventPath = true

  157. # Switch id to enable or disable the path finding feature
  158.   PathFinderSwitch = 500
  159. #
  160. #----------------------------------------------------------------------------
  161. #
  162. # * License
  163. #
  164. # You can use this script in non comercial games, in you need it for comercial
  165. # games let me know. [email]falmc99@gmail.com[/email]
  166. #-----------------------------------------------------------------------------

  167.   def self.check_value(value)
  168.     return 'numeric' if value.is_a? Fixnum
  169.     return 'string'
  170.   end
  171. end

  172. ($imported ||= {})[:Mouse_System_Buttons] = 2.0

  173. # This class create all screen and event buttons on game screen
  174. class Interactive_Buttoms
  175.   attr_reader :cursoring
  176.   def initialize
  177.     create_screen_buttoms
  178.     @ani_delay = 0
  179.     @pearl_abs = $imported["Falcao Pearl ABS Liquid"]
  180.   end

  181.   def create_screen_buttoms
  182.     @buttons_sprites = []
  183.     for i in Map_Buttons::Insert.values
  184.       @buttons_sprites.push(Sprite_Buttons.new(i[0], i[1], i[2], i[3], i[4]))
  185.     end
  186.   end

  187.   def create_button_text
  188.     if @button_text.nil?
  189.       @button_text = Sprite.new
  190.       @button_text.bitmap = Bitmap.new(100, 32)
  191.       @button_text.z = 50
  192.       @button_text.bitmap.font.size = 16
  193.     end
  194.   end

  195.   def dispose_screen_buttons
  196.     for button in @buttons_sprites
  197.       button.dispose
  198.     end
  199.     @buttons_sprites = []
  200.   end

  201.   def dispose_button_text
  202.     if not @button_text.nil?
  203.       @button_text.dispose
  204.       @button_text.bitmap.dispose
  205.       @button_text = nil
  206.     end
  207.   end

  208.   def dispose
  209.     dispose_screen_buttons
  210.     dispose_button_text
  211.   end

  212.   def update
  213.     if $game_switches[Map_Buttons::Switch] and not @buttons_sprites.empty?
  214.       dispose_screen_buttons
  215.     elsif not $game_switches[Map_Buttons::Switch] and @buttons_sprites.empty?
  216.       create_screen_buttoms
  217.     end
  218.     update_buttons
  219.     update_event_selection
  220.   end

  221.   # path update
  222.   def update_path
  223.     return if $game_switches[Map_Buttons::PathFinderSwitch]
  224.     return if $game_message.busy?
  225.     return unless $game_player.normal_walk?
  226.     @mxx, @myy = Mouse.map_grid[0], Mouse.map_grid[1]
  227.     if Map_Buttons::IgnoreEventPath
  228.       $game_map.events.values.each do |event|
  229.         return if event.x == @mxx and event.y == @myy
  230.       end
  231.     end
  232.     $game_player.find_path(@mxx, @myy) unless on_toolbar?
  233.   end


  234.   def on_toolbar?
  235.     return false unless @pearl_abs
  236.     9.times.each {|x| return true if @mxx == PearlSkillBar::Tile_X + x and
  237.     @myy == PearlSkillBar::Tile_Y}
  238.     return false
  239.   end


  240.   def update_buttons
  241.     for button in @buttons_sprites
  242.       button.update
  243.       if button.zooming
  244.         @screen_b = true
  245.         create_button_text
  246.         if button.x > 272
  247.           x, y = button.px * 32 - 98, button.py * 32
  248.           draw_button_text(x, y, button.name, 2)
  249.         elsif button.x < 272
  250.           x, y = button.px * 32 + 31, button.py * 32
  251.           draw_button_text(x, y, button.name, 0)
  252.         end
  253.       end
  254.     end

  255.     if @screen_b != nil
  256.       unless mouse_over_button?
  257.         dispose_button_text
  258.         @screen_b = nil
  259.       end
  260.     end
  261.   end

  262.   def reset_cursor
  263.     if Map_Buttons::check_value(@cursoring[1]) == 'numeric'
  264.       Mouse.set_cursor(:iconset, @cursoring[1], true)
  265.     else
  266.       Mouse.set_cursor(:picture, @cursoring[1], true)
  267.     end
  268.     @cursoring = nil
  269.   end

  270.   def apply_iconchanging(sym, operand, event)
  271.     cursor = $game_system.cursorr
  272.     cursor = Map_Buttons::CursorIcon if cursor.nil?
  273.     @cursoring = [event, cursor]
  274.     Mouse.set_cursor(sym, operand, true)
  275.   end

  276.   def update_event_selection
  277.     return if @screen_b #disable event buttom if mouse over screen buttom
  278.     update_path if Mouse.trigger?(0)
  279.     for event in $game_map.events.values
  280.       next if event.page.nil?
  281.       if event.x == Mouse.map_grid[0] and event.y == Mouse.map_grid[1]
  282.         if event.mouse_start
  283.           if Mouse.trigger?(0) and !$game_map.interpreter.running?
  284.             event.start
  285.           end
  286.         end

  287.         if event.square_size?($game_player, 2)
  288.           if Mouse.trigger?(0) and !$game_map.interpreter.running?
  289.             event.start
  290.           end
  291.         end

  292.         anime = event.mouse_animation
  293.         if anime != 0
  294.           @ani_delay += 1
  295.           event.animation_id = anime if @ani_delay == 1
  296.           @ani_delay = 0 if @ani_delay > 16
  297.         end
  298.         name = event.mouse_name
  299.         if name != ""
  300.           @Eve = [event.x, event.y, event, name]
  301.           create_button_text
  302.         end
  303.         icon = event.mouse_iconset
  304.         picture = event.mouse_picture
  305.         if !icon.nil? and icon != 0 and @cursoring.nil?
  306.           apply_iconchanging(:iconset, icon, event)
  307.         elsif !picture.nil? and picture != "" and @cursoring.nil?
  308.           apply_iconchanging(:picture, picture, event)
  309.         end
  310.       end
  311.     end

  312.     if @cursoring != nil
  313.       reset_cursor if not mouse_over_event?(@cursoring[0].x, @cursoring[0].y)
  314.     end

  315.     if @Eve != nil
  316.       @eve[2].ch_oy.nil? ? event_oy = 32 : event_oy = @eve[2].ch_oy
  317.       if event_oy > 32
  318.         draw_button_text(@eve[2].screen_x - 49,
  319.         @eve[2].screen_y - event_oy / 2 - 50, @eve[3], 1)
  320.       else
  321.         draw_button_text(@eve[2].screen_x - 49,
  322.         @eve[2].screen_y - event_oy / 2 - 36, @eve[3], 1)
  323.       end
  324.       if not mouse_over_event?(@eve[0], @eve[1])
  325.         dispose_button_text
  326.         @eve = nil
  327.       end
  328.     end
  329.   end

  330.   def draw_button_text(x, y, text, a=0)
  331.     return if @button_text.nil?
  332.     @button_text.x = x
  333.     @button_text.y = y
  334.     return if @old_name == text
  335.     @button_text.bitmap.clear
  336.     @button_text.bitmap.draw_text(2, 0, @button_text.bitmap.width, 32, text, a)
  337.     @old_name = text
  338.   end

  339.   def mouse_over_button?
  340.     for button in @buttons_sprites
  341.       if Mouse.object_area?(button.x, button.y - 6, button.width, button.height)
  342.         return true
  343.       end
  344.     end
  345.     @old_name = nil
  346.     return false
  347.   end

  348.   def mouse_over_event?(event_x, event_y)
  349.     if Mouse.map_grid[0] == event_x and Mouse.map_grid[1] == event_y
  350.       return true
  351.     end
  352.     @old_name = nil
  353.     return false
  354.   end
  355. end

  356. # Set buttons sprites
  357. class Spriteset_Map
  358.   alias falcao_insert_buttuns_view create_viewports
  359.   def create_viewports
  360.     @interact_buttoms = Interactive_Buttoms.new
  361.     falcao_insert_buttuns_view
  362.   end

  363.   alias falcao_insert_buttuns_dis dispose
  364.   def dispose
  365.     @interact_buttoms.reset_cursor if @interact_buttoms.cursoring != nil
  366.     @interact_buttoms.dispose
  367.     falcao_insert_buttuns_dis
  368.   end

  369.   alias falcao_insert_buttuns_up update
  370.   def update
  371.     if $game_player.clear_mousepointers
  372.       @interact_buttoms.dispose
  373.       $game_player.clear_mousepointers = nil
  374.     end
  375.     @interact_buttoms.update
  376.     falcao_insert_buttuns_up
  377.   end
  378. end

  379. # comments definition
  380. class Game_Event < Game_Character
  381.   attr_reader   :mouse_start, :mouse_animation, :mouse_name, :mouse_iconset
  382.   attr_reader   :mouse_picture, :page
  383.   alias falcaomouse_setup setup_page_settings
  384.   def setup_page_settings
  385.     falcaomouse_setup
  386.     @mouse_start     = check_comment("MOUSE START")
  387.     @mouse_animation = check_value("MOUSE ANIMATION")
  388.     @mouse_name      = check_name("MOUSE NAME")
  389.     @mouse_iconset   = check_value("MOUSE ICON")#
  390.     @mouse_picture   = check_name("MOUSE PIC")#
  391.   end

  392.   def check_comment(comment)
  393.     return false if @list.nil? or @list.size <= 0
  394.     for item in @list
  395.       if item.code == 108 or item.code == 408
  396.         if item.parameters[0].include?(comment)
  397.           return true
  398.         end
  399.       end
  400.     end
  401.     return false
  402.   end

  403.   def check_value(comment)
  404.     return 0 if @list.nil? or @list.size <= 0
  405.     for item in @list
  406.       if item.code == 108 or item.code == 408
  407.         if item.parameters[0] =~ /#{comment}[ ]?(\d+)?/
  408.           return $1.to_i
  409.         end
  410.       end
  411.     end
  412.     return 0
  413.   end

  414.   def check_name(comment)
  415.     return "" if @list.nil? or @list.size <= 0
  416.     for item in @list
  417.       next unless item.code == 108 or item.code == 408
  418.       if item.parameters[0] =~ /#{comment} (.*)/
  419.         return $1.to_s
  420.       end
  421.     end
  422.     return ""
  423.   end

  424.   def square_size?(target, size)
  425.     distance = (@x - target.x).abs + (@y - target.y).abs
  426.     enable   = (distance <= size-1)
  427.     return true if enable
  428.     return false
  429.   end

  430. end

  431. # Create screen buttons sprites
  432. class Sprite_Buttons < Sprite
  433.   attr_reader   :px
  434.   attr_reader   :py
  435.   attr_reader   :name
  436.   attr_reader   :zooming
  437.   def initialize(name, px, py, icon_index, action=nil)
  438.     super()
  439.     self.z = 50
  440.     @icon_index = icon_index
  441.     @px = px
  442.     @py = py
  443.     @action = action
  444.     @object_zooming = 0
  445.     @zooming = false
  446.     @name = name
  447.     set_bitmap
  448.     update
  449.   end

  450.   def update
  451.     super
  452.     if Mouse.object_area?(self.x, self.y - 4, self.bitmap.width,
  453.       self.bitmap.height)
  454.       @zooming = true
  455.       @object_zooming += 1
  456.       case @object_zooming
  457.       when 1..10  ; self.zoom_x -= 0.02 ;  self.zoom_y -= 0.02
  458.       when 11..20 ; self.zoom_x += 0.02 ;  self.zoom_y += 0.02
  459.       when 21..30 ; self.zoom_x = 1.0   ;  self.zoom_y = 1.0
  460.         @object_zooming = 0
  461.       end
  462.       if Mouse.trigger?(0) and @action != nil
  463.         unless $game_map.interpreter.running?
  464.           Sound.play_ok
  465.           if @action == Scene_Menu and not $game_system.menu_disabled
  466.             SceneManager.call(@action)
  467.             Window_MenuCommand::init_command_position
  468.             return
  469.           end
  470.          if Map_Buttons::check_value(@action) == 'numeric'
  471.            $game_temp.reserve_common_event(@action)
  472.          else
  473.            SceneManager.call(@action)
  474.          end
  475.         end
  476.       end
  477.     elsif @object_zooming > 0
  478.       self.zoom_x = 1.0
  479.       self.zoom_y = 1.0
  480.       @object_zooming = 0
  481.     else
  482.       @zooming = false
  483.     end
  484.   end

  485.   def set_bitmap
  486.     if Map_Buttons::check_value(@icon_index) == 'numeric'
  487.       self.bitmap = Bitmap.new(24, 24)
  488.       bitmap = Cache.system("Iconset")
  489.       rect = Rect.new(@icon_index % 16 * 24, @icon_index / 16 * 24, 24, 24)
  490.       self.bitmap.blt(0, 0, bitmap, rect)
  491.     else
  492.       self.bitmap = Cache.picture(@icon_index)
  493.     end
  494.     self.x = @px * 32 + 4
  495.     self.y = @py * 32 + 4
  496.   end
  497. end

  498. # Game_character new variable
  499. class Game_CharacterBase
  500.   attr_accessor :ch_oy
  501. end

  502. # Sprite character
  503. class Sprite_Character < Sprite_Base
  504.   alias falcaoadd_oxy_set_character_bitmap set_character_bitmap
  505.   def set_character_bitmap
  506.     falcaoadd_oxy_set_character_bitmap
  507.     @character.ch_oy = self.oy
  508.   end
  509. end

  510. class Game_System
  511.   attr_accessor :current_cursor
  512.   def cursorr
  513.     return Map_Buttons::CursorIcon if @current_cursor.nil?
  514.     return @current_cursor
  515.   end
  516. end

  517. # Mouse module
  518. module Mouse

  519.   GetKeyState    = Win32API.new('user32',    'GetAsyncKeyState', 'i',     'i')
  520.   GetCursorPos   = Win32API.new('user32',    'GetCursorPos',     'p',     'i')
  521.   GetClientRect  = Win32API.new('user32',    'GetClientRect',    %w(l p), 'i')
  522.   ShowCursor     = Win32API.new('user32',    'ShowCursor',       'i',     'l')
  523.   ScreenToClient = Win32API.new('user32',    'ScreenToClient',   %w(l p), 'i')
  524.   Findwindow     = Win32API.new('user32',    'FindWindowA',      %w(p p), 'l')
  525.   GetPrivatePro  = Win32API.new('kernel32',  'GetPrivateProfileStringA',
  526.   %w(p p p p l p), 'l')

  527.   ShowCursor.call(0)

  528.   @triggers     =   [[0, 1], [0, 2], [0, 4]]
  529.   @old_pos      =   0

  530.   # Mouse Sprite

  531.   def self.set_cursor(sym, operand, write=false)
  532.     case sym
  533.     when :iconset
  534.       $mouse_cursor.bitmap = Bitmap.new(24, 24)
  535.       bitmap = Cache.system("Iconset")
  536.       rect = Rect.new(operand % 16 * 24, operand / 16 * 24, 24, 24)
  537.       $mouse_cursor.bitmap.blt(0, 0, bitmap, rect)
  538.     when :picture then $mouse_cursor.bitmap = Cache.picture(operand)
  539.     end
  540.     $game_system.current_cursor = operand if write
  541.   end

  542.   $mouse_cursor = Sprite.new
  543.   icon = Map_Buttons::CursorIcon
  544.   if Map_Buttons::check_value(icon) == 'numeric'
  545.     set_cursor(:iconset, icon)
  546.   else
  547.     set_cursor(:picture, icon)
  548.   end
  549.   $mouse_cursor.z = 10001
  550.   $mouse_cursor.x = $mouse_cursor.y = 1000
  551.   $mouse_cursor.ox = 4

  552.   def self.show_cursor(value)
  553.     unless value
  554.       @pos[0] = @pos[1] = 600
  555.     end
  556.     $mouse_cursor.visible = value
  557.   end

  558.   def self.map_grid
  559.     return nil if @pos == nil
  560.     x = ($game_map.display_x).to_i + (@pos[0] / 32)
  561.     y = ($game_map.display_y).to_i + (@pos[1] / 32)
  562.     return [x, y]
  563.   end

  564.   def self.standing?
  565.     return false if @old_px != @pos[0]
  566.     return false if @old_py != @pos[1]
  567.     return true
  568.   end

  569.   def self.input_keys
  570.     $game_arrows.mode_on ? type = $game_arrows.in_type : type = Input::C
  571.     keys = {0 => type, 1 => Input::B, 2 => Input::A}
  572.     return keys
  573.   end

  574.   def self.object_area?(x, y, width, height)
  575.     return false if @pos.nil?
  576.     return @pos[0].between?(x, width + x) && @pos[1].between?(y, height + y)
  577.   end

  578.   def self.position
  579.     return @pos == nil ? [0, 0] : @pos
  580.   end

  581.   def self.global_pos
  582.     pos = [0, 0].pack('ll')
  583.     return GetCursorPos.call(pos) == 0 ? nil : pos.unpack('ll')
  584.   end

  585.   def self.screen_to_client(x=0, y=0)
  586.     pos = [x, y].pack('ll')
  587.     return ScreenToClient.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  588.   end  

  589.   def self.pos
  590.     global_pos = [0, 0].pack('ll')   
  591.     gx, gy = GetCursorPos.call(global_pos) == 0 ? nil : global_pos.unpack('ll')
  592.     local_pos = [gx, gy].pack('ll')
  593.     x, y = ScreenToClient.call(self.hwnd,
  594.     local_pos) == 0 ? nil : local_pos.unpack('ll')
  595.     begin
  596.       if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
  597.         @old_px, @old_py = x, y
  598.         return x, y
  599.       else
  600.         return -20, -20
  601.       end
  602.     rescue
  603.       return 0, 0
  604.     end
  605.   end  

  606.   def self.update
  607.     old_pos = @pos
  608.     @pos = self.pos
  609.     self.input_keys
  610.     if !$mouse_cursor.visible && old_pos != @pos
  611.       $mouse_cursor.visible = true
  612.     end
  613.     if old_pos != [-20, -20] && @pos == [-20, -20]
  614.       ShowCursor.call(1)
  615.     elsif old_pos == [-20, -20] && @pos != [-20, -20]
  616.        ShowCursor.call(0)
  617.     end
  618.     for i in @triggers
  619.       n = GetKeyState.call(i[1])
  620.       if [0, 1].include?(n)
  621.         i[0] = (i[0] > 0 ? i[0] * -1 : 0)
  622.       else
  623.         i[0] = (i[0] > 0 ? i[0] + 1 : 1)
  624.       end
  625.     end
  626.   end

  627.   # trigger definition
  628.   def self.trigger?(id = 0)
  629.     pos = self.pos
  630.     if pos != [-20,-20]
  631.     case id
  632.       when 0  
  633.         return @triggers[id][0] == 1
  634.       when 1  
  635.         if @triggers[1][0] == 1 && !$game_system.menu_disabled
  636.           return @triggers[id][0] == 1
  637.         end
  638.       when 2
  639.         return @triggers[id][0] == 1
  640.       end   
  641.     end
  642.   end

  643.   # repeat definition
  644.   def self.repeat?(id = 0)
  645.     if @triggers[id][0] <= 0
  646.       return false
  647.     else
  648.       return @triggers[id][0] % 5 == 1 && @triggers[id][0] % 5 != 2
  649.     end
  650.   end

  651.   #press definition
  652.   def self.press?(id = 0)
  653.     if @triggers[id][0] <= 0
  654.       return false
  655.     else
  656.       return true
  657.     end
  658.   end

  659.   def self.screen_to_client(x=0, y=0)
  660.     pos = [x, y].pack('ll')
  661.     return ScreenToClient.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  662.   end

  663.   def self.hwnd
  664.     if @hwnd.nil?
  665.       game_name = "\0" * 256
  666.       GetPrivatePro.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
  667.       game_name.delete!("\0")
  668.       @hwnd = Findwindow.call('RGSS Player', game_name)
  669.     end
  670.     return @hwnd
  671.   end

  672.   def self.client_size
  673.     rect = [0, 0, 0, 0].pack('l4')
  674.     GetClientRect.call(self.hwnd, rect)
  675.     right, bottom = rect.unpack('l4')[2..3]
  676.     return right, bottom
  677.   end
  678. end

  679. # Input module aliased
  680. class << Input
  681.   unless self.method_defined?(:falcao21_mouse_update)
  682.     alias_method :falcao21_mouse_update,   :update
  683.     alias_method :falcao21_mouse_trigger?, :trigger?
  684.     alias_method :falcao21_mouse_repeat?,  :repeat?
  685.     alias_method :fal_mouse_input_press?,  :press?
  686.   end

  687.   def update
  688.     if $mouse_cursor.visible
  689.       Mouse.update
  690.       $game_arrows.update
  691.       mx, my = *Mouse.position
  692.       $mouse_cursor.x = mx unless mx.nil?
  693.       $mouse_cursor.y = my unless my.nil?   
  694.     end
  695.     falcao21_mouse_update
  696.   end

  697.   # trigger
  698.   def trigger?(constant)
  699.     return true if falcao21_mouse_trigger?(constant)
  700.     unless Mouse.pos.nil?
  701.       if Mouse.input_keys.has_value?(constant)
  702.         mouse_trigger = Mouse.input_keys.index(constant)
  703.         return true if Mouse.trigger?(mouse_trigger)
  704.       end
  705.     end
  706.     return false
  707.   end

  708.   # press
  709.   def press?(constant)
  710.     return true if fal_mouse_input_press?(constant)
  711.     unless Mouse.pos.nil?
  712.       if Mouse.input_keys.has_value?(constant)
  713.         mouse_trigger = Mouse.input_keys.index(constant)
  714.         return true if Mouse.press?(mouse_trigger)      
  715.       end
  716.     end
  717.     return false
  718.   end

  719.   # repeat
  720.   def repeat?(constant)
  721.     return true if falcao21_mouse_repeat?(constant)
  722.     unless Mouse.pos.nil?
  723.       if Mouse.input_keys.has_value?(constant)
  724.         mouse_trigger = Mouse.input_keys.index(constant)     
  725.         return true if Mouse.repeat?(mouse_trigger)
  726.       end
  727.     end
  728.     return false
  729.   end
  730. end

  731. # Here your best friend, you can call this script within the game, scene etc.
  732. # $game_arrows.create_arrows(x, y), create it, $game_arrows.dispose, delete it
  733. class Game_Arrow_Selector
  734.   attr_accessor :mode_on
  735.   attr_accessor :in_type
  736.   def initialize
  737.     @mode_on = false
  738.   end

  739.   def create_arrows(x, y)
  740.     return unless @arrows_sprites.nil?
  741.     buttons = {1=> 'UP', 2=> 'RIGHT', 3=> 'DOWN',
  742.     4=> 'LEFT', 5=> 'OK', 6=> 'Cancel'}
  743.     @arrows_sprites = []
  744.     for i in buttons.values
  745.       @arrows_sprites.push(Garrows_Sprites.new(i, x, y))
  746.     end
  747.   end

  748.   def dispose
  749.     return if @arrows_sprites.nil?
  750.     for arrow in @arrows_sprites
  751.       arrow.dispose
  752.     end
  753.     @arrows_sprites = nil
  754.     @mode_on = false
  755.   end

  756.   def update
  757.     return if @arrows_sprites.nil?
  758.     for arrow in @arrows_sprites
  759.       arrow.update
  760.     end
  761.   end
  762. end

  763. class Garrows_Sprites < Sprite
  764.   def initialize(name, x, y)
  765.     super()
  766.     self.z = 1000
  767.     @px, @py = x, y
  768.     @name = name
  769.     @object_zooming = 0
  770.     @zooming = false
  771.     set_bitmap
  772.     update
  773.   end

  774.   def update
  775.     super
  776.     if Mouse.object_area?(self.x + @fix[0], self.y + @fix[1],
  777.       self.bitmap.width + @fix[2], self.bitmap.height + @fix[3])
  778.       $game_arrows.mode_on = true
  779.       $game_arrows.in_type = Input::UP    if @name == 'UP'
  780.       $game_arrows.in_type = Input::DOWN  if @name == 'DOWN'
  781.       $game_arrows.in_type = Input::LEFT  if @name == 'LEFT'
  782.       $game_arrows.in_type = Input::RIGHT if @name == 'RIGHT'
  783.       $game_arrows.in_type = Input::C     if @name == 'OK'
  784.       $game_arrows.in_type = Input::B     if @name == 'Cancel'
  785.       @object_zooming += 1
  786.       @zooming = true
  787.       case @object_zooming
  788.       when 1..10  ; self.zoom_x -= 0.01 ;  self.zoom_y -= 0.01
  789.       when 11..20 ; self.zoom_x += 0.01 ;  self.zoom_y += 0.01
  790.       when 21..30 ; self.zoom_x = 1.0   ;  self.zoom_y = 1.0
  791.         @object_zooming = 0
  792.       end
  793.     elsif @object_zooming > 0
  794.       self.zoom_x = 1.0
  795.       self.zoom_y = 1.0
  796.       @object_zooming = 0
  797.     elsif @zooming
  798.       @zooming = false
  799.       $game_arrows.mode_on = false
  800.     end
  801.   end

  802.   def set_bitmap
  803.     self.bitmap = Bitmap.new(24, 15) if @name != 'Cancel'
  804.     case @name
  805.     when 'UP'
  806.       self.x = @px + 25 ; self.y = @py - 2
  807.       self.angle = 182  ; @fix = [-23, -18, 0,  0]
  808.     when 'DOWN'
  809.       self.x = @px + 1 ; self.y = @py + 26
  810.       @fix = [0, -4, 0,  0]
  811.     when 'LEFT'
  812.       self.x = @px      ; self.y = @py + 1
  813.       self.angle = - 92 ; @fix = [-14, -4, - 9,  9]
  814.     when 'RIGHT'
  815.       self.x = @px + 26  ; self.y = @py + 26
  816.       self.angle = + 92  ; @fix = [0, - 26, - 9,  9]
  817.     when 'OK'
  818.       self.x = @px + 1  ; self.y = @py + 6
  819.       @fix = [0, -4, 0,  0]
  820.       self.bitmap.font.size = 20
  821.       self.bitmap.draw_text(4, -7, self.bitmap.width, 32, @name)
  822.       return
  823.     when 'Cancel'
  824.       self.x = @px - 11  ; self.y = @py + 42
  825.       @fix = [0, -4, 0,  0]
  826.       self.bitmap = Bitmap.new(50, 15)
  827.       self.bitmap.font.size = 20
  828.       self.bitmap.draw_text(2, -7, self.bitmap.width, 32, @name)
  829.       return
  830.     end
  831.     draw_crappy_triangle(0, 0)
  832.   end

  833.   # This method create a crappy triangle pointing down
  834.   def draw_crappy_triangle(px, py)
  835.     color = Color.new(192, 224, 255, 255)
  836.     x, y, w, =  0, 4, 24
  837.     self.bitmap.fill_rect(px + 1, py, 22, 1, color)
  838.     self.bitmap.fill_rect(px,     py + 1, 24, 4, color)
  839.     for i in 1..10
  840.       x += 1; y += 1; w -= 2
  841.       self.bitmap.fill_rect(px + x, py + y,       w, 1, color)
  842.     end
  843.   end
  844. end

  845. $game_arrows = Game_Arrow_Selector.new

  846. # Arrow selector is displayed when Input number is on
  847. class Game_Interpreter
  848.   alias falcao_setup_num_input setup_num_input
  849.   def setup_num_input(params)
  850.     falcao_setup_num_input(params)
  851.     $game_arrows.create_arrows(256, 194) if $game_message.position == 0
  852.     $game_arrows.create_arrows(256, 340) if $game_message.position == 1
  853.     $game_arrows.create_arrows(256, 180) if $game_message.position == 2
  854.   end
  855. end

  856. # Arrow selector is disposed when press ok
  857. class Window_NumberInput < Window_Base
  858.   alias falcao_process_ok process_ok
  859.   def process_ok
  860.     falcao_process_ok
  861.     $game_arrows.dispose
  862.   end
  863. end

  864. # WASD Movements
  865. module Input
  866.   class << self
  867.     if !method_defined?('vxe_dir4')
  868.       alias vxace_dir4 dir4
  869.     end
  870.     def dir4
  871.       if Map_Buttons::WASD_Movement
  872.         return 2 if (Input.press?(Input::Y))
  873.         return 4 if (Input.press?(Input::X))
  874.         return 6 if (Input.press?(Input::Z))
  875.         return 8 if (Input.press?(Input::R))
  876.       end
  877.       return vxace_dir4
  878.     end
  879.   end
  880. end

  881. # If event start with mouse
  882. class Game_Player < Game_Character
  883.   alias falcao_start_map_event start_map_event
  884.   def start_map_event(x, y, triggers, normal)
  885.     $game_map.events_xy(x, y).each do |event_click|
  886.       return if event_click.check_comment("MOUSE START")
  887.     end  
  888.     falcao_start_map_event(x, y, triggers, normal)
  889.   end
  890. end

  891. # clear pointers when tranfering
  892. class Game_Player < Game_Character
  893.   attr_accessor :clear_mousepointers
  894.   alias falcaomouse_perform_transfer perform_transfer
  895.   def perform_transfer
  896.     @clear_mousepointers = true if $game_map.map_id !=  @new_map_id
  897.     falcaomouse_perform_transfer
  898.   end
  899. end

  900. # Path find
  901. class Game_Character < Game_CharacterBase
  902.   attr_accessor :map, :runpath
  903.   alias pathfind1_ini initialize
  904.   def initialize
  905.     pathfind1_ini
  906.     @map = nil
  907.     @runpath = false
  908.   end

  909.   alias pathfind1_up update
  910.   def update
  911.     run_path if @runpath == true
  912.     pathfind1_up
  913.   end

  914.   def run_path
  915.     return if moving?
  916.     step = @map[@x,@y]
  917.     if step == 1
  918.       @map = nil
  919.       @runpath = false
  920.       return
  921.     end
  922.     dir = rand(2)
  923.     case dir
  924.     when 0
  925.       move_straight(6) if @map[@x+1,@y] == step - 1 && step != 0
  926.       move_straight(2) if @map[@x,@y+1] == step - 1 && step != 0
  927.       move_straight(4) if @map[@x-1,@y] == step - 1 && step != 0
  928.       move_straight(8) if @map[@x,@y-1] == step - 1 && step != 0
  929.     when 1
  930.       move_straight(8) if @map[@x,@y-1] == step - 1 && step != 0
  931.       move_straight(4) if @map[@x-1,@y] == step - 1 && step != 0
  932.       move_straight(2) if @map[@x,@y+1] == step - 1 && step != 0
  933.       move_straight(6) if @map[@x+1,@y] == step - 1 && step != 0
  934.     end
  935.   end

  936.   def find_path(x,y)
  937.     sx, sy = @x, @y
  938.     result = setup_map(sx,sy,x,y)
  939.     @runpath = result[0]
  940.     @map = result[1]
  941.     @map[sx,sy] = result[2] if result[2] != nil
  942.   end

  943.   def clear_path
  944.     @map = nil
  945.     @runpath = false
  946.   end

  947.   def setup_map(sx,sy,ex,ey)
  948.     map = Table.new($game_map.width, $game_map.height)
  949.     map[ex,ey] = 1
  950.     old_positions = []
  951.     new_positions = []
  952.     old_positions.push([ex, ey])
  953.     depth = 2
  954.     depth.upto(100){|step|
  955.       loop do
  956.         break if old_positions[0] == nil
  957.         x,y = old_positions.shift
  958.         return [true, map, step] if x == sx and y+1 == sy
  959.         if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
  960.           map[x,y + 1] = step
  961.           new_positions.push([x,y + 1])
  962.         end
  963.         return [true, map, step] if x-1 == sx and y == sy
  964.         if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
  965.           map[x - 1,y] = step
  966.           new_positions.push([x - 1,y])
  967.         end
  968.         return [true, map, step] if x+1 == sx and y == sy
  969.         if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
  970.           map[x + 1,y] = step
  971.           new_positions.push([x + 1,y])
  972.         end
  973.         return [true, map, step] if x == sx and y-1 == sy
  974.         if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
  975.           map[x,y - 1] = step
  976.           new_positions.push([x,y - 1])
  977.         end
  978.       end
  979.       old_positions = new_positions
  980.       new_positions = []
  981.     }
  982.     return [false, nil, nil]
  983.   end
  984. end

  985. class Game_Player
  986.   alias pathfind_player_update update
  987.   def update
  988.     clear_path if Input.dir4 != 0
  989.     pathfind_player_update
  990.   end

  991.   alias findpath_perform_transfer perform_transfer
  992.   def perform_transfer
  993.     clear_path if $game_map.map_id !=  @new_map_id
  994.     findpath_perform_transfer
  995.   end
  996. end

  997. # Window selectable (Thanks wora for some lines here)
  998. class Window_Selectable < Window_Base
  999.   alias mouse_selection_ini initialize
  1000.   def initialize(*args)
  1001.     mouse_selection_ini(*args)
  1002.     @scroll_wait = 0
  1003.     @cursor_wait = 0
  1004.     @sdelay = 0
  1005.   end

  1006.   alias mouse_selection_update update
  1007.   def update
  1008.     update_mouse_selection if self.active and self.visible
  1009.     @sdelay -= 1 if @sdelay > 0
  1010.     mouse_selection_update
  1011.   end

  1012.   def update_mouse_selection
  1013.     @cursor_wait -= 1 if @cursor_wait > 0
  1014.     plus_x = self.x + 16 - self.ox
  1015.     plus_y = self.y + 8 - self.oy
  1016.     unless self.viewport.nil?
  1017.       plus_x += self.viewport.rect.x - self.viewport.ox
  1018.       plus_y += self.viewport.rect.y - self.viewport.oy
  1019.     end
  1020.     (0..self.item_max - 1).each do |i|
  1021.       irect = item_rect(i)
  1022.       move_cursor(i) if Mouse.object_area?(
  1023.       irect.x + plus_x, irect.y + plus_y, irect.width, irect.height)
  1024.       update_cursor
  1025.     end
  1026.   end

  1027.   def move_cursor(index)
  1028.     return if @index == index
  1029.     @scroll_wait -= 1 if @scroll_wait > 0
  1030.     row1 = @index / self.col_max
  1031.     row2 = index / self.col_max
  1032.     bottom = self.top_row + (self.page_row_max - 1)
  1033.     if index != @index and @sdelay == 0
  1034.       Sound.play_cursor
  1035.       @sdelay = 5
  1036.     end
  1037.     if row1 == self.top_row and row2 < self.top_row
  1038.       return if @scroll_wait > 0
  1039.       @index = [@index - self.col_max, 0].max
  1040.       @scroll_wait = 30
  1041.     elsif row1 == bottom and row2 > bottom
  1042.       return if @scroll_wait > 0
  1043.       @index = [@index + self.col_max, self.item_max - 1].min
  1044.       @scroll_wait = 30
  1045.     else
  1046.       @index = index
  1047.     end
  1048.     select(@index)
  1049.     return if @cursor_wait > 0
  1050.     @cursor_wait += 2
  1051.   end
  1052. end


  1053. class Window_NameInput
  1054.   def item_max
  1055.     return 90
  1056.   end
  1057. end

  1058. class Scene_File < Scene_MenuBase

  1059.   alias mouse_top_index top_index=
  1060.   def top_index=(index)
  1061.     @scroll_timer = 0 if @scroll_timer.nil? ; @scroll_timer -= 1
  1062.     return if @scroll_timer > 0
  1063.     mouse_top_index(index) ; @scroll_timer = 35
  1064.   end

  1065.   alias mouse_sb_update update
  1066.   def update
  1067.     (0..self.item_max - 1).each do |i|
  1068.       ix = @savefile_windows[i].x
  1069.       iy = @savefile_windows[i].y + 40 - @savefile_viewport.oy
  1070.       iw = @savefile_windows[i].width
  1071.       ih = @savefile_windows[i].height
  1072.       if Mouse.object_area?(ix, iy, iw, ih)
  1073.         @savefile_windows[@index].selected = false
  1074.         @savefile_windows[i].selected = true
  1075.         @index = i
  1076.       end
  1077.       ensure_cursor_visible
  1078.     end
  1079.     mouse_sb_update
  1080.   end
  1081. end
复制代码

XAS ACE.part1.rar

2 MB, 下载次数: 137

最佳答案

查看完整内容

画面xy: 地图xy:
梦石
0
星屑
7230
在线时间
1685 小时
注册时间
2017-4-28
回帖
84

开拓者

发表于 2019-6-16 12:28:47 | 显示全部楼层
画面xy:
  1. Mouse.pos[0] #x
  2. Mouse.pos[1] #y
复制代码


地图xy:
  1. Mouse.map_grid[0] #x
  2. Mouse.map_grid[1] #y
复制代码
回复

使用道具 举报

梦石
0
星屑
103
在线时间
10 小时
注册时间
2018-1-13
回帖
5
 楼主| 发表于 2019-6-20 17:20:48 | 显示全部楼层

$game_variables[1] = Mouse.map_grid[0]
我用了这个来检测我鼠标的X坐标 但怎么都显示是0

点评

你把这一句脚本放到哪裹? 请确保有正常运行 你上传的文件我解压失败,可能缺个part2 如果是附件尺寸限制问题,可只上传Data文件  发表于 2019-6-20 19:24
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部