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

Project1

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

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
103
在线时间
10 小时
注册时间
2018-1-13
帖子
10
跳转到指定楼层
1
发表于 2019-6-16 12:28:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
50星屑
本帖最后由 VIPArcher 于 2022-6-8 17:18 编辑

这是一个鼠标脚本,我想通过赋值的方式赋予变量鼠标所在地图上XY坐标的位置,可是鼠标所在地图上XY坐标的代码名称我没有找到,希望有大佬相助
RUBY 代码复制
  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. #----------------------------------------------------------------------------
  38. # * Version 2.5 change log (Date: June 9 2013)
  39. #
  40. # Fixed non-refreshing item description bug
  41. # Fixed Save file selection issue
  42. # Added ability to start events even if the player is no facing the event
  43. # Removed option to display arrow selector on save file
  44. # Added compatibility for multiples game resolutions
  45. # Item selection with mouse is now more occurate
  46. # Fixed issue with pearl skillbar (when clicking any tool perform path finding)
  47. # Cleaned up some code
  48. #
  49. #----------------------------------------------------------------------------
  50. # * Version 2.0 change log (Date: January 13 2013)
  51. #
  52. # - Added path finding, now the game player is able to move using the mouse
  53. # - Now you are able to change the mouse cursor icon in game
  54. # - Two new notetags added to change the mouse cursor by event comment tags
  55. # - Fixed crash when pointing a notetagged event with a valid condition
  56. #----------------------------------------------------------------------------
  57. # * Version 1.6 change log (Date: November 21 2012)
  58. #
  59. # - Added compatibility for any game screen resolution
  60. # - System optimized to consume less cpu than before
  61. # - Added extra compatibility for Pearl ABS Liquid
  62. # - Removed the font fix
  63. # - Added the imported bolean
  64. #----------------------------------------------------------------------------
  65. # * Version 1.5 change log
  66. #
  67. # - Fixed cursor sound over loading on selectable windows
  68. # - Fixed bug when selecting event graphic tileset that have mouse comment tag
  69. # - FIxed minor bug when transfering (event name now erase completely)
  70. # - Added option to turn on / off arrow selector on save file
  71. # - Important! changes on mouse comment tags!
  72. #   ~ CLICK START change to MOUSE START
  73. #   ~ ANIMATION   change to MOUSE ANIMATION
  74. #   ~ NAME        change to MOUSE NAME
  75. #
  76. #---------------------------------------------------------------------------
  77. # * installation
  78. #
  79. # Copy and paste this script above main done!
  80. #
  81. # * Mouse triggers
  82. #   - Left click:     Action button
  83. #   - Right click:    Cancel button, close windows
  84. #   - Mouse wheel middle button:   DASH
  85. #
  86. #---------------------------------------------------------------------------
  87. # * Main features
  88. #
  89. # - Allow you create buttons and configure them to do something
  90. # - Events can be buttons too, map ground buttons! for some puzzles etc.
  91. # - Allow you display event name
  92. # - Full mouse interaction
  93. # - WASD movement optional
  94. # - Path finding feature, player is able to move using the mouse
  95. # - Mouse cursor changing in-game enabled
  96. #---------------------------------------------------------------------------
  97. # * Event buttons commands
  98. #
  99. # Write this lines on event comments tags
  100. #
  101. # MOUSE START       - Event start when you click the event
  102. # MOUSE ANIMATION x - Show animation when mouse is over event,
  103. #                     ex: MOUSE ANIMATION 1
  104. # MOUSE NAME x      - Display event name when mouse is over event,
  105. #                     ex: MOUSE NAME Falcao
  106. # MOUSE ICON x      - change the mouse cursor icon when it is over the event
  107. #                     change x for the icon index to display
  108. # MOUSE PIC X       - Change the mouse cursor when is over an event but in this
  109. #                     case it display a picture graphic name, change x for the
  110. #                     picture name
  111. #------------------------------------------------------------------------------
  112. # * Script calls
  113. #
  114. # Call this line to turn off/on the mouse cursor within the game true/false
  115. # Mouse.show_cursor(false)
  116. #
  117. # If you want to change the mouse cursor manually use the following script calls
  118. # Mouse.set_cursor(:iconset, x)     - change x for any icon index
  119. #
  120. # if you want to show a picture instead iconset use the next script call
  121. # Mouse.set_cursor(:picture, name)  - change name for picture name
  122. #-----------------------------------------------------------------------------
  123.  
  124. module Map_Buttons
  125.  
  126. # You can easily insert as many buttons you want to the map screen
  127. # define here below your buttons parameters
  128.  
  129.   Insert = {
  130. #-----------------------------------------------------------------------------
  131. #  A => [B, C, D, E, F]
  132. #  
  133. #  A = Button number 按键序号
  134. #
  135. #  B = Name  游戏中按键显示的名字
  136. #  C = X position in screen tile  屏幕上X坐标
  137. #  D = Y position in screen tile  屏幕上Y坐标
  138. #  E = Icon, if you want a picture write picture 'name' otherwise icon index
  139. #  F = What this button gonna do?, you have two options, call scene or call
  140. #  common event, if you want scene put scene name, if you want common event
  141. #  put common event ID
  142.  
  143. #Y坐标12,显示在最靠近屏幕下方。添加新菜单的时候请将Y坐标-1。
  144. #F处可填场景呼叫和公共事件ID。
  145.  
  146.   # This button call the menu screen
  147.  
  148.  
  149.  
  150. # ID=> ["显示名称", X,   Y, 图标Index, 呼出菜单],
  151.     1=>  ["Menu",    16,  11, 117,      Scene_Menu],
  152. # ID=> ["显示名称", X,   Y, 图标Index, 呼出菜单],
  153.  
  154.  
  155.   }
  156.  
  157. # * General configutration
  158.  
  159. # Mouse cursor icon, if you want a picture write pic 'name' otherwise icon index
  160.   CursorIcon = 386
  161.  
  162. # Switch ID to turn off/on the icons on the screen
  163.   Switch = 100
  164.  
  165. # Allow movement with  W A S D keys true/false
  166.   WASD_Movement = true
  167.  
  168. # When you click on event, do you want the player to ignore the self movement?
  169.   IgnoreEventPath = true
  170.  
  171. # Switch id to enable or disable the path finding feature
  172.   PathFinderSwitch = 500
  173. #
  174. #----------------------------------------------------------------------------
  175. #
  176. # * License
  177. #
  178. # You can use this script in non comercial games, in you need it for comercial
  179. # games let me know. [email][email protected][/email]
  180. #-----------------------------------------------------------------------------
  181.  
  182.   def self.check_value(value)
  183.     return 'numeric' if value.is_a? Fixnum
  184.     return 'string'
  185.   end
  186. end
  187.  
  188. ($imported ||= {})[:Mouse_System_Buttons] = 2.0
  189.  
  190. # This class create all screen and event buttons on game screen
  191. class Interactive_Buttoms
  192.   attr_reader :cursoring
  193.   def initialize
  194.     create_screen_buttoms
  195.     @ani_delay = 0
  196.     @pearl_abs = $imported["Falcao Pearl ABS Liquid"]
  197.   end
  198.  
  199.   def create_screen_buttoms
  200.     @buttons_sprites = []
  201.     for i in Map_Buttons::Insert.values
  202.       @buttons_sprites.push(Sprite_Buttons.new(i[0], i[1], i[2], i[3], i[4]))
  203.     end
  204.   end
  205.  
  206.   def create_button_text
  207.     if @button_text.nil?
  208.       @button_text = Sprite.new
  209.       @button_text.bitmap = Bitmap.new(100, 32)
  210.       @button_text.z = 50
  211.       @button_text.bitmap.font.size = 16
  212.     end
  213.   end
  214.  
  215.   def dispose_screen_buttons
  216.     for button in @buttons_sprites
  217.       button.dispose
  218.     end
  219.     @buttons_sprites = []
  220.   end
  221.  
  222.   def dispose_button_text
  223.     if not @button_text.nil?
  224.       @button_text.dispose
  225.       @button_text.bitmap.dispose
  226.       @button_text = nil
  227.     end
  228.   end
  229.  
  230.   def dispose
  231.     dispose_screen_buttons
  232.     dispose_button_text
  233.   end
  234.  
  235.   def update
  236.     if $game_switches[Map_Buttons::Switch] and not @buttons_sprites.empty?
  237.       dispose_screen_buttons
  238.     elsif not $game_switches[Map_Buttons::Switch] and @buttons_sprites.empty?
  239.       create_screen_buttoms
  240.     end
  241.     update_buttons
  242.     update_event_selection
  243.   end
  244.  
  245.   # path update
  246.   def update_path
  247.     return if $game_switches[Map_Buttons::PathFinderSwitch]
  248.     return if $game_message.busy?
  249.     return unless $game_player.normal_walk?
  250.     @mxx, @myy = Mouse.map_grid[0], Mouse.map_grid[1]
  251.     if Map_Buttons::IgnoreEventPath
  252.       $game_map.events.values.each do |event|
  253.         return if event.x == @mxx and event.y == @myy
  254.       end
  255.     end
  256.     $game_player.find_path(@mxx, @myy) unless on_toolbar?
  257.   end
  258.  
  259.  
  260.   def on_toolbar?
  261.     return false unless @pearl_abs
  262.     9.times.each {|x| return true if @mxx == PearlSkillBar::Tile_X + x and
  263.     @myy == PearlSkillBar::Tile_Y}
  264.     return false
  265.   end
  266.  
  267.  
  268.   def update_buttons
  269.     for button in @buttons_sprites
  270.       button.update
  271.       if button.zooming
  272.         @screen_b = true
  273.         create_button_text
  274.         if button.x > 272
  275.           x, y = button.px * 32 - 98, button.py * 32
  276.           draw_button_text(x, y, button.name, 2)
  277.         elsif button.x < 272
  278.           x, y = button.px * 32 + 31, button.py * 32
  279.           draw_button_text(x, y, button.name, 0)
  280.         end
  281.       end
  282.     end
  283.  
  284.     if @screen_b != nil
  285.       unless mouse_over_button?
  286.         dispose_button_text
  287.         @screen_b = nil
  288.       end
  289.     end
  290.   end
  291.  
  292.   def reset_cursor
  293.     if Map_Buttons::check_value(@cursoring[1]) == 'numeric'
  294.       Mouse.set_cursor(:iconset, @cursoring[1], true)
  295.     else
  296.       Mouse.set_cursor(:picture, @cursoring[1], true)
  297.     end
  298.     @cursoring = nil
  299.   end
  300.  
  301.   def apply_iconchanging(sym, operand, event)
  302.     cursor = $game_system.cursorr
  303.     cursor = Map_Buttons::CursorIcon if cursor.nil?
  304.     @cursoring = [event, cursor]
  305.     Mouse.set_cursor(sym, operand, true)
  306.   end
  307.  
  308.   def update_event_selection
  309.     return if @screen_b #disable event buttom if mouse over screen buttom
  310.     update_path if Mouse.trigger?(0)
  311.     for event in $game_map.events.values
  312.       next if event.page.nil?
  313.       if event.x == Mouse.map_grid[0] and event.y == Mouse.map_grid[1]
  314.         if event.mouse_start
  315.           if Mouse.trigger?(0) and !$game_map.interpreter.running?
  316.             event.start
  317.           end
  318.         end
  319.  
  320.         if event.square_size?($game_player, 2)
  321.           if Mouse.trigger?(0) and !$game_map.interpreter.running?
  322.             event.start
  323.           end
  324.         end
  325.  
  326.         anime = event.mouse_animation
  327.         if anime != 0
  328.           @ani_delay += 1
  329.           event.animation_id = anime if @ani_delay == 1
  330.           @ani_delay = 0 if @ani_delay > 16
  331.         end
  332.         name = event.mouse_name
  333.         if name != ""
  334.           @Eve = [event.x, event.y, event, name]
  335.           create_button_text
  336.         end
  337.         icon = event.mouse_iconset
  338.         picture = event.mouse_picture
  339.         if !icon.nil? and icon != 0 and @cursoring.nil?
  340.           apply_iconchanging(:iconset, icon, event)
  341.         elsif !picture.nil? and picture != "" and @cursoring.nil?
  342.           apply_iconchanging(:picture, picture, event)
  343.         end
  344.       end
  345.     end
  346.  
  347.     if @cursoring != nil
  348.       reset_cursor if not mouse_over_event?(@cursoring[0].x, @cursoring[0].y)
  349.     end
  350.  
  351.     if @Eve != nil
  352.       @eve[2].ch_oy.nil? ? event_oy = 32 : event_oy = @eve[2].ch_oy
  353.       if event_oy > 32
  354.         draw_button_text(@eve[2].screen_x - 49,
  355.         @eve[2].screen_y - event_oy / 2 - 50, @eve[3], 1)
  356.       else
  357.         draw_button_text(@eve[2].screen_x - 49,
  358.         @eve[2].screen_y - event_oy / 2 - 36, @eve[3], 1)
  359.       end
  360.       if not mouse_over_event?(@eve[0], @eve[1])
  361.         dispose_button_text
  362.         @eve = nil
  363.       end
  364.     end
  365.   end
  366.  
  367.   def draw_button_text(x, y, text, a=0)
  368.     return if @button_text.nil?
  369.     @button_text.x = x
  370.     @button_text.y = y
  371.     return if @old_name == text
  372.     @button_text.bitmap.clear
  373.     @button_text.bitmap.draw_text(2, 0, @button_text.bitmap.width, 32, text, a)
  374.     @old_name = text
  375.   end
  376.  
  377.   def mouse_over_button?
  378.     for button in @buttons_sprites
  379.       if Mouse.object_area?(button.x, button.y - 6, button.width, button.height)
  380.         return true
  381.       end
  382.     end
  383.     @old_name = nil
  384.     return false
  385.   end
  386.  
  387.   def mouse_over_event?(event_x, event_y)
  388.     if Mouse.map_grid[0] == event_x and Mouse.map_grid[1] == event_y
  389.       return true
  390.     end
  391.     @old_name = nil
  392.     return false
  393.   end
  394. end
  395.  
  396. # Set buttons sprites
  397. class Spriteset_Map
  398.   alias falcao_insert_buttuns_view create_viewports
  399.   def create_viewports
  400.     @interact_buttoms = Interactive_Buttoms.new
  401.     falcao_insert_buttuns_view
  402.   end
  403.  
  404.   alias falcao_insert_buttuns_dis dispose
  405.   def dispose
  406.     @interact_buttoms.reset_cursor if @interact_buttoms.cursoring != nil
  407.     @interact_buttoms.dispose
  408.     falcao_insert_buttuns_dis
  409.   end
  410.  
  411.   alias falcao_insert_buttuns_up update
  412.   def update
  413.     if $game_player.clear_mousepointers
  414.       @interact_buttoms.dispose
  415.       $game_player.clear_mousepointers = nil
  416.     end
  417.     @interact_buttoms.update
  418.     falcao_insert_buttuns_up
  419.   end
  420. end
  421.  
  422. # comments definition
  423. class Game_Event < Game_Character
  424.   attr_reader   :mouse_start, :mouse_animation, :mouse_name, :mouse_iconset
  425.   attr_reader   :mouse_picture, :page
  426.   alias falcaomouse_setup setup_page_settings
  427.   def setup_page_settings
  428.     falcaomouse_setup
  429.     @mouse_start     = check_comment("MOUSE START")
  430.     @mouse_animation = check_value("MOUSE ANIMATION")
  431.     @mouse_name      = check_name("MOUSE NAME")
  432.     @mouse_iconset   = check_value("MOUSE ICON")#
  433.     @mouse_picture   = check_name("MOUSE PIC")#
  434.   end
  435.  
  436.   def check_comment(comment)
  437.     return false if @list.nil? or @list.size <= 0
  438.     for item in @list
  439.       if item.code == 108 or item.code == 408
  440.         if item.parameters[0].include?(comment)
  441.           return true
  442.         end
  443.       end
  444.     end
  445.     return false
  446.   end
  447.  
  448.   def check_value(comment)
  449.     return 0 if @list.nil? or @list.size <= 0
  450.     for item in @list
  451.       if item.code == 108 or item.code == 408
  452.         if item.parameters[0] =~ /#{comment}[ ]?(\d+)?/
  453.           return $1.to_i
  454.         end
  455.       end
  456.     end
  457.     return 0
  458.   end
  459.  
  460.   def check_name(comment)
  461.     return "" if @list.nil? or @list.size <= 0
  462.     for item in @list
  463.       next unless item.code == 108 or item.code == 408
  464.       if item.parameters[0] =~ /#{comment} (.*)/
  465.         return $1.to_s
  466.       end
  467.     end
  468.     return ""
  469.   end
  470.  
  471.   def square_size?(target, size)
  472.     distance = (@x - target.x).abs + (@y - target.y).abs
  473.     enable   = (distance <= size-1)
  474.     return true if enable
  475.     return false
  476.   end
  477.  
  478. end
  479.  
  480. # Create screen buttons sprites
  481. class Sprite_Buttons < Sprite
  482.   attr_reader   :px
  483.   attr_reader   :py
  484.   attr_reader   :name
  485.   attr_reader   :zooming
  486.   def initialize(name, px, py, icon_index, action=nil)
  487.     super()
  488.     self.z = 50
  489.     @icon_index = icon_index
  490.     @px = px
  491.     @py = py
  492.     @action = action
  493.     @object_zooming = 0
  494.     @zooming = false
  495.     @name = name
  496.     set_bitmap
  497.     update
  498.   end
  499.  
  500.   def update
  501.     super
  502.     if Mouse.object_area?(self.x, self.y - 4, self.bitmap.width,
  503.       self.bitmap.height)
  504.       @zooming = true
  505.       @object_zooming += 1
  506.       case @object_zooming
  507.       when 1..10  ; self.zoom_x -= 0.02 ;  self.zoom_y -= 0.02
  508.       when 11..20 ; self.zoom_x += 0.02 ;  self.zoom_y += 0.02
  509.       when 21..30 ; self.zoom_x = 1.0   ;  self.zoom_y = 1.0
  510.         @object_zooming = 0
  511.       end
  512.       if Mouse.trigger?(0) and @action != nil
  513.         unless $game_map.interpreter.running?
  514.           Sound.play_ok
  515.           if @action == Scene_Menu and not $game_system.menu_disabled
  516.             SceneManager.call(@action)
  517.             Window_MenuCommand::init_command_position
  518.             return
  519.           end
  520.          if Map_Buttons::check_value(@action) == 'numeric'
  521.            $game_temp.reserve_common_event(@action)
  522.          else
  523.            SceneManager.call(@action)
  524.          end
  525.         end
  526.       end
  527.     elsif @object_zooming > 0
  528.       self.zoom_x = 1.0
  529.       self.zoom_y = 1.0
  530.       @object_zooming = 0
  531.     else
  532.       @zooming = false
  533.     end
  534.   end
  535.  
  536.   def set_bitmap
  537.     if Map_Buttons::check_value(@icon_index) == 'numeric'
  538.       self.bitmap = Bitmap.new(24, 24)
  539.       bitmap = Cache.system("Iconset")
  540.       rect = Rect.new(@icon_index % 16 * 24, @icon_index / 16 * 24, 24, 24)
  541.       self.bitmap.blt(0, 0, bitmap, rect)
  542.     else
  543.       self.bitmap = Cache.picture(@icon_index)
  544.     end
  545.     self.x = @px * 32 + 4
  546.     self.y = @py * 32 + 4
  547.   end
  548. end
  549.  
  550. # Game_character new variable
  551. class Game_CharacterBase
  552.   attr_accessor :ch_oy
  553. end
  554.  
  555. # Sprite character
  556. class Sprite_Character < Sprite_Base
  557.   alias falcaoadd_oxy_set_character_bitmap set_character_bitmap
  558.   def set_character_bitmap
  559.     falcaoadd_oxy_set_character_bitmap
  560.     @character.ch_oy = self.oy
  561.   end
  562. end
  563.  
  564. class Game_System
  565.   attr_accessor :current_cursor
  566.   def cursorr
  567.     return Map_Buttons::CursorIcon if @current_cursor.nil?
  568.     return @current_cursor
  569.   end
  570. end
  571.  
  572. # Mouse module
  573. module Mouse
  574.  
  575.   GetKeyState    = Win32API.new('user32',    'GetAsyncKeyState', 'i',     'i')
  576.   GetCursorPos   = Win32API.new('user32',    'GetCursorPos',     'p',     'i')
  577.   GetClientRect  = Win32API.new('user32',    'GetClientRect',    %w(l p), 'i')
  578.   ShowCursor     = Win32API.new('user32',    'ShowCursor',       'i',     'l')
  579.   ScreenToClient = Win32API.new('user32',    'ScreenToClient',   %w(l p), 'i')
  580.   Findwindow     = Win32API.new('user32',    'FindWindowA',      %w(p p), 'l')
  581.   GetPrivatePro  = Win32API.new('kernel32',  'GetPrivateProfileStringA',
  582.   %w(p p p p l p), 'l')
  583.  
  584.   ShowCursor.call(0)
  585.  
  586.   @triggers     =   [[0, 1], [0, 2], [0, 4]]
  587.   @old_pos      =   0
  588.  
  589.   # Mouse Sprite
  590.  
  591.   def self.set_cursor(sym, operand, write=false)
  592.     case sym
  593.     when :iconset
  594.       $mouse_cursor.bitmap = Bitmap.new(24, 24)
  595.       bitmap = Cache.system("Iconset")
  596.       rect = Rect.new(operand % 16 * 24, operand / 16 * 24, 24, 24)
  597.       $mouse_cursor.bitmap.blt(0, 0, bitmap, rect)
  598.     when :picture then $mouse_cursor.bitmap = Cache.picture(operand)
  599.     end
  600.     $game_system.current_cursor = operand if write
  601.   end
  602.  
  603.   $mouse_cursor = Sprite.new
  604.   icon = Map_Buttons::CursorIcon
  605.   if Map_Buttons::check_value(icon) == 'numeric'
  606.     set_cursor(:iconset, icon)
  607.   else
  608.     set_cursor(:picture, icon)
  609.   end
  610.   $mouse_cursor.z = 10001
  611.   $mouse_cursor.x = $mouse_cursor.y = 1000
  612.   $mouse_cursor.ox = 4
  613.  
  614.   def self.show_cursor(value)
  615.     unless value
  616.       @pos[0] = @pos[1] = 600
  617.     end
  618.     $mouse_cursor.visible = value
  619.   end
  620.  
  621.   def self.map_grid
  622.     return nil if @pos == nil
  623.     x = ($game_map.display_x).to_i + (@pos[0] / 32)
  624.     y = ($game_map.display_y).to_i + (@pos[1] / 32)
  625.     return [x, y]
  626.   end
  627.  
  628.   def self.standing?
  629.     return false if @old_px != @pos[0]
  630.     return false if @old_py != @pos[1]
  631.     return true
  632.   end
  633.  
  634.   def self.input_keys
  635.     $game_arrows.mode_on ? type = $game_arrows.in_type : type = Input::C
  636.     keys = {0 => type, 1 => Input::B, 2 => Input::A}
  637.     return keys
  638.   end
  639.  
  640.   def self.object_area?(x, y, width, height)
  641.     return false if @pos.nil?
  642.     return @pos[0].between?(x, width + x) && @pos[1].between?(y, height + y)
  643.   end
  644.  
  645.   def self.position
  646.     return @pos == nil ? [0, 0] : @pos
  647.   end
  648.  
  649.   def self.global_pos
  650.     pos = [0, 0].pack('ll')
  651.     return GetCursorPos.call(pos) == 0 ? nil : pos.unpack('ll')
  652.   end
  653.  
  654.   def self.screen_to_client(x=0, y=0)
  655.     pos = [x, y].pack('ll')
  656.     return ScreenToClient.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  657.   end  
  658.  
  659.   def self.pos
  660.     global_pos = [0, 0].pack('ll')   
  661.     gx, gy = GetCursorPos.call(global_pos) == 0 ? nil : global_pos.unpack('ll')
  662.     local_pos = [gx, gy].pack('ll')
  663.     x, y = ScreenToClient.call(self.hwnd,
  664.     local_pos) == 0 ? nil : local_pos.unpack('ll')
  665.     begin
  666.       if (x >= 0 && y >= 0 && x <= Graphics.width && y <= Graphics.height)
  667.         @old_px, @old_py = x, y
  668.         return x, y
  669.       else
  670.         return -20, -20
  671.       end
  672.     rescue
  673.       return 0, 0
  674.     end
  675.   end  
  676.  
  677.   def self.update
  678.     old_pos = @pos
  679.     @pos = self.pos
  680.     self.input_keys
  681.     if !$mouse_cursor.visible && old_pos != @pos
  682.       $mouse_cursor.visible = true
  683.     end
  684.     if old_pos != [-20, -20] && @pos == [-20, -20]
  685.       ShowCursor.call(1)
  686.     elsif old_pos == [-20, -20] && @pos != [-20, -20]
  687.        ShowCursor.call(0)
  688.     end
  689.     for i in @triggers
  690.       n = GetKeyState.call(i[1])
  691.       if [0, 1].include?(n)
  692.         i[0] = (i[0] > 0 ? i[0] * -1 : 0)
  693.       else
  694.         i[0] = (i[0] > 0 ? i[0] + 1 : 1)
  695.       end
  696.     end
  697.   end
  698.  
  699.   # trigger definition
  700.   def self.trigger?(id = 0)
  701.     pos = self.pos
  702.     if pos != [-20,-20]
  703.     case id
  704.       when 0  
  705.         return @triggers[id][0] == 1
  706.       when 1  
  707.         if @triggers[1][0] == 1 && !$game_system.menu_disabled
  708.           return @triggers[id][0] == 1
  709.         end
  710.       when 2
  711.         return @triggers[id][0] == 1
  712.       end   
  713.     end
  714.   end
  715.  
  716.   # repeat definition
  717.   def self.repeat?(id = 0)
  718.     if @triggers[id][0] <= 0
  719.       return false
  720.     else
  721.       return @triggers[id][0] % 5 == 1 && @triggers[id][0] % 5 != 2
  722.     end
  723.   end
  724.  
  725.   #press definition
  726.   def self.press?(id = 0)
  727.     if @triggers[id][0] <= 0
  728.       return false
  729.     else
  730.       return true
  731.     end
  732.   end
  733.  
  734.   def self.screen_to_client(x=0, y=0)
  735.     pos = [x, y].pack('ll')
  736.     return ScreenToClient.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  737.   end
  738.  
  739.   def self.hwnd
  740.     if @hwnd.nil?
  741.       game_name = "\0" * 256
  742.       GetPrivatePro.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
  743.       game_name.delete!("\0")
  744.       @hwnd = Findwindow.call('RGSS Player', game_name)
  745.     end
  746.     return @hwnd
  747.   end
  748.  
  749.   def self.client_size
  750.     rect = [0, 0, 0, 0].pack('l4')
  751.     GetClientRect.call(self.hwnd, rect)
  752.     right, bottom = rect.unpack('l4')[2..3]
  753.     return right, bottom
  754.   end
  755. end
  756.  
  757. # Input module aliased
  758. class << Input
  759.   unless self.method_defined?(:falcao21_mouse_update)
  760.     alias_method :falcao21_mouse_update,   :update
  761.     alias_method :falcao21_mouse_trigger?, :trigger?
  762.     alias_method :falcao21_mouse_repeat?,  :repeat?
  763.     alias_method :fal_mouse_input_press?,  :press?
  764.   end
  765.  
  766.   def update
  767.     if $mouse_cursor.visible
  768.       Mouse.update
  769.       $game_arrows.update
  770.       mx, my = *Mouse.position
  771.       $mouse_cursor.x = mx unless mx.nil?
  772.       $mouse_cursor.y = my unless my.nil?   
  773.     end
  774.     falcao21_mouse_update
  775.   end
  776.  
  777.   # trigger
  778.   def trigger?(constant)
  779.     return true if falcao21_mouse_trigger?(constant)
  780.     unless Mouse.pos.nil?
  781.       if Mouse.input_keys.has_value?(constant)
  782.         mouse_trigger = Mouse.input_keys.index(constant)
  783.         return true if Mouse.trigger?(mouse_trigger)
  784.       end
  785.     end
  786.     return false
  787.   end
  788.  
  789.   # press
  790.   def press?(constant)
  791.     return true if fal_mouse_input_press?(constant)
  792.     unless Mouse.pos.nil?
  793.       if Mouse.input_keys.has_value?(constant)
  794.         mouse_trigger = Mouse.input_keys.index(constant)
  795.         return true if Mouse.press?(mouse_trigger)      
  796.       end
  797.     end
  798.     return false
  799.   end
  800.  
  801.   # repeat
  802.   def repeat?(constant)
  803.     return true if falcao21_mouse_repeat?(constant)
  804.     unless Mouse.pos.nil?
  805.       if Mouse.input_keys.has_value?(constant)
  806.         mouse_trigger = Mouse.input_keys.index(constant)     
  807.         return true if Mouse.repeat?(mouse_trigger)
  808.       end
  809.     end
  810.     return false
  811.   end
  812. end
  813.  
  814. # Here your best friend, you can call this script within the game, scene etc.
  815. # $game_arrows.create_arrows(x, y), create it, $game_arrows.dispose, delete it
  816. class Game_Arrow_Selector
  817.   attr_accessor :mode_on
  818.   attr_accessor :in_type
  819.   def initialize
  820.     @mode_on = false
  821.   end
  822.  
  823.   def create_arrows(x, y)
  824.     return unless @arrows_sprites.nil?
  825.     buttons = {1=> 'UP', 2=> 'RIGHT', 3=> 'DOWN',
  826.     4=> 'LEFT', 5=> 'OK', 6=> 'Cancel'}
  827.     @arrows_sprites = []
  828.     for i in buttons.values
  829.       @arrows_sprites.push(Garrows_Sprites.new(i, x, y))
  830.     end
  831.   end
  832.  
  833.   def dispose
  834.     return if @arrows_sprites.nil?
  835.     for arrow in @arrows_sprites
  836.       arrow.dispose
  837.     end
  838.     @arrows_sprites = nil
  839.     @mode_on = false
  840.   end
  841.  
  842.   def update
  843.     return if @arrows_sprites.nil?
  844.     for arrow in @arrows_sprites
  845.       arrow.update
  846.     end
  847.   end
  848. end
  849.  
  850. class Garrows_Sprites < Sprite
  851.   def initialize(name, x, y)
  852.     super()
  853.     self.z = 1000
  854.     @px, @py = x, y
  855.     @name = name
  856.     @object_zooming = 0
  857.     @zooming = false
  858.     set_bitmap
  859.     update
  860.   end
  861.  
  862.   def update
  863.     super
  864.     if Mouse.object_area?(self.x + @fix[0], self.y + @fix[1],
  865.       self.bitmap.width + @fix[2], self.bitmap.height + @fix[3])
  866.       $game_arrows.mode_on = true
  867.       $game_arrows.in_type = Input::UP    if @name == 'UP'
  868.       $game_arrows.in_type = Input::DOWN  if @name == 'DOWN'
  869.       $game_arrows.in_type = Input::LEFT  if @name == 'LEFT'
  870.       $game_arrows.in_type = Input::RIGHT if @name == 'RIGHT'
  871.       $game_arrows.in_type = Input::C     if @name == 'OK'
  872.       $game_arrows.in_type = Input::B     if @name == 'Cancel'
  873.       @object_zooming += 1
  874.       @zooming = true
  875.       case @object_zooming
  876.       when 1..10  ; self.zoom_x -= 0.01 ;  self.zoom_y -= 0.01
  877.       when 11..20 ; self.zoom_x += 0.01 ;  self.zoom_y += 0.01
  878.       when 21..30 ; self.zoom_x = 1.0   ;  self.zoom_y = 1.0
  879.         @object_zooming = 0
  880.       end
  881.     elsif @object_zooming > 0
  882.       self.zoom_x = 1.0
  883.       self.zoom_y = 1.0
  884.       @object_zooming = 0
  885.     elsif @zooming
  886.       @zooming = false
  887.       $game_arrows.mode_on = false
  888.     end
  889.   end
  890.  
  891.   def set_bitmap
  892.     self.bitmap = Bitmap.new(24, 15) if @name != 'Cancel'
  893.     case @name
  894.     when 'UP'
  895.       self.x = @px + 25 ; self.y = @py - 2
  896.       self.angle = 182  ; @fix = [-23, -18, 0,  0]
  897.     when 'DOWN'
  898.       self.x = @px + 1 ; self.y = @py + 26
  899.       @fix = [0, -4, 0,  0]
  900.     when 'LEFT'
  901.       self.x = @px      ; self.y = @py + 1
  902.       self.angle = - 92 ; @fix = [-14, -4, - 9,  9]
  903.     when 'RIGHT'
  904.       self.x = @px + 26  ; self.y = @py + 26
  905.       self.angle = + 92  ; @fix = [0, - 26, - 9,  9]
  906.     when 'OK'
  907.       self.x = @px + 1  ; self.y = @py + 6
  908.       @fix = [0, -4, 0,  0]
  909.       self.bitmap.font.size = 20
  910.       self.bitmap.draw_text(4, -7, self.bitmap.width, 32, @name)
  911.       return
  912.     when 'Cancel'
  913.       self.x = @px - 11  ; self.y = @py + 42
  914.       @fix = [0, -4, 0,  0]
  915.       self.bitmap = Bitmap.new(50, 15)
  916.       self.bitmap.font.size = 20
  917.       self.bitmap.draw_text(2, -7, self.bitmap.width, 32, @name)
  918.       return
  919.     end
  920.     draw_crappy_triangle(0, 0)
  921.   end
  922.  
  923.   # This method create a crappy triangle pointing down
  924.   def draw_crappy_triangle(px, py)
  925.     color = Color.new(192, 224, 255, 255)
  926.     x, y, w, =  0, 4, 24
  927.     self.bitmap.fill_rect(px + 1, py, 22, 1, color)
  928.     self.bitmap.fill_rect(px,     py + 1, 24, 4, color)
  929.     for i in 1..10
  930.       x += 1; y += 1; w -= 2
  931.       self.bitmap.fill_rect(px + x, py + y,       w, 1, color)
  932.     end
  933.   end
  934. end
  935.  
  936. $game_arrows = Game_Arrow_Selector.new
  937.  
  938. # Arrow selector is displayed when Input number is on
  939. class Game_Interpreter
  940.   alias falcao_setup_num_input setup_num_input
  941.   def setup_num_input(params)
  942.     falcao_setup_num_input(params)
  943.     $game_arrows.create_arrows(256, 194) if $game_message.position == 0
  944.     $game_arrows.create_arrows(256, 340) if $game_message.position == 1
  945.     $game_arrows.create_arrows(256, 180) if $game_message.position == 2
  946.   end
  947. end
  948.  
  949. # Arrow selector is disposed when press ok
  950. class Window_NumberInput < Window_Base
  951.   alias falcao_process_ok process_ok
  952.   def process_ok
  953.     falcao_process_ok
  954.     $game_arrows.dispose
  955.   end
  956. end
  957.  
  958. # WASD Movements
  959. module Input
  960.   class << self
  961.     if !method_defined?('vxe_dir4')
  962.       alias vxace_dir4 dir4
  963.     end
  964.     def dir4
  965.       if Map_Buttons::WASD_Movement
  966.         return 2 if (Input.press?(Input::Y))
  967.         return 4 if (Input.press?(Input::X))
  968.         return 6 if (Input.press?(Input::Z))
  969.         return 8 if (Input.press?(Input::R))
  970.       end
  971.       return vxace_dir4
  972.     end
  973.   end
  974. end
  975.  
  976. # If event start with mouse
  977. class Game_Player < Game_Character
  978.   alias falcao_start_map_event start_map_event
  979.   def start_map_event(x, y, triggers, normal)
  980.     $game_map.events_xy(x, y).each do |event_click|
  981.       return if event_click.check_comment("MOUSE START")
  982.     end  
  983.     falcao_start_map_event(x, y, triggers, normal)
  984.   end
  985. end
  986.  
  987. # clear pointers when tranfering
  988. class Game_Player < Game_Character
  989.   attr_accessor :clear_mousepointers
  990.   alias falcaomouse_perform_transfer perform_transfer
  991.   def perform_transfer
  992.     @clear_mousepointers = true if $game_map.map_id !=  @new_map_id
  993.     falcaomouse_perform_transfer
  994.   end
  995. end
  996.  
  997. # Path find
  998. class Game_Character < Game_CharacterBase
  999.   attr_accessor :map, :runpath
  1000.   alias pathfind1_ini initialize
  1001.   def initialize
  1002.     pathfind1_ini
  1003.     @map = nil
  1004.     @runpath = false
  1005.   end
  1006.  
  1007.   alias pathfind1_up update
  1008.   def update
  1009.     run_path if @runpath == true
  1010.     pathfind1_up
  1011.   end
  1012.  
  1013.   def run_path
  1014.     return if moving?
  1015.     step = @map[@x,@y]
  1016.     if step == 1
  1017.       @map = nil
  1018.       @runpath = false
  1019.       return
  1020.     end
  1021.     dir = rand(2)
  1022.     case dir
  1023.     when 0
  1024.       move_straight(6) if @map[@x+1,@y] == step - 1 && step != 0
  1025.       move_straight(2) if @map[@x,@y+1] == step - 1 && step != 0
  1026.       move_straight(4) if @map[@x-1,@y] == step - 1 && step != 0
  1027.       move_straight(8) if @map[@x,@y-1] == step - 1 && step != 0
  1028.     when 1
  1029.       move_straight(8) if @map[@x,@y-1] == step - 1 && step != 0
  1030.       move_straight(4) if @map[@x-1,@y] == step - 1 && step != 0
  1031.       move_straight(2) if @map[@x,@y+1] == step - 1 && step != 0
  1032.       move_straight(6) if @map[@x+1,@y] == step - 1 && step != 0
  1033.     end
  1034.   end
  1035.  
  1036.   def find_path(x,y)
  1037.     sx, sy = @x, @y
  1038.     result = setup_map(sx,sy,x,y)
  1039.     @runpath = result[0]
  1040.     @map = result[1]
  1041.     @map[sx,sy] = result[2] if result[2] != nil
  1042.   end
  1043.  
  1044.   def clear_path
  1045.     @map = nil
  1046.     @runpath = false
  1047.   end
  1048.  
  1049.   def setup_map(sx,sy,ex,ey)
  1050.     map = Table.new($game_map.width, $game_map.height)
  1051.     map[ex,ey] = 1
  1052.     old_positions = []
  1053.     new_positions = []
  1054.     old_positions.push([ex, ey])
  1055.     depth = 2
  1056.     depth.upto(100){|step|
  1057.       loop do
  1058.         break if old_positions[0] == nil
  1059.         x,y = old_positions.shift
  1060.         return [true, map, step] if x == sx and y+1 == sy
  1061.         if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
  1062.           map[x,y + 1] = step
  1063.           new_positions.push([x,y + 1])
  1064.         end
  1065.         return [true, map, step] if x-1 == sx and y == sy
  1066.         if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
  1067.           map[x - 1,y] = step
  1068.           new_positions.push([x - 1,y])
  1069.         end
  1070.         return [true, map, step] if x+1 == sx and y == sy
  1071.         if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
  1072.           map[x + 1,y] = step
  1073.           new_positions.push([x + 1,y])
  1074.         end
  1075.         return [true, map, step] if x == sx and y-1 == sy
  1076.         if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
  1077.           map[x,y - 1] = step
  1078.           new_positions.push([x,y - 1])
  1079.         end
  1080.       end
  1081.       old_positions = new_positions
  1082.       new_positions = []
  1083.     }
  1084.     return [false, nil, nil]
  1085.   end
  1086. end
  1087.  
  1088. class Game_Player
  1089.   alias pathfind_player_update update
  1090.   def update
  1091.     clear_path if Input.dir4 != 0
  1092.     pathfind_player_update
  1093.   end
  1094.  
  1095.   alias findpath_perform_transfer perform_transfer
  1096.   def perform_transfer
  1097.     clear_path if $game_map.map_id !=  @new_map_id
  1098.     findpath_perform_transfer
  1099.   end
  1100. end
  1101.  
  1102. # Window selectable (Thanks wora for some lines here)
  1103. class Window_Selectable < Window_Base
  1104.   alias mouse_selection_ini initialize
  1105.   def initialize(*args)
  1106.     mouse_selection_ini(*args)
  1107.     @scroll_wait = 0
  1108.     @cursor_wait = 0
  1109.     @sdelay = 0
  1110.   end
  1111.  
  1112.   alias mouse_selection_update update
  1113.   def update
  1114.     update_mouse_selection if self.active and self.visible
  1115.     @sdelay -= 1 if @sdelay > 0
  1116.     mouse_selection_update
  1117.   end
  1118.  
  1119.   def update_mouse_selection
  1120.     @cursor_wait -= 1 if @cursor_wait > 0
  1121.     plus_x = self.x + 16 - self.ox
  1122.     plus_y = self.y + 8 - self.oy
  1123.     unless self.viewport.nil?
  1124.       plus_x += self.viewport.rect.x - self.viewport.ox
  1125.       plus_y += self.viewport.rect.y - self.viewport.oy
  1126.     end
  1127.     (0..self.item_max - 1).each do |i|
  1128.       irect = item_rect(i)
  1129.       move_cursor(i) if Mouse.object_area?(
  1130.       irect.x + plus_x, irect.y + plus_y, irect.width, irect.height)
  1131.       update_cursor
  1132.     end
  1133.   end
  1134.  
  1135.   def move_cursor(index)
  1136.     return if @index == index
  1137.     @scroll_wait -= 1 if @scroll_wait > 0
  1138.     row1 = @index / self.col_max
  1139.     row2 = index / self.col_max
  1140.     bottom = self.top_row + (self.page_row_max - 1)
  1141.     if index != @index and @sdelay == 0
  1142.       Sound.play_cursor
  1143.       @sdelay = 5
  1144.     end
  1145.     if row1 == self.top_row and row2 < self.top_row
  1146.       return if @scroll_wait > 0
  1147.       @index = [@index - self.col_max, 0].max
  1148.       @scroll_wait = 30
  1149.     elsif row1 == bottom and row2 > bottom
  1150.       return if @scroll_wait > 0
  1151.       @index = [@index + self.col_max, self.item_max - 1].min
  1152.       @scroll_wait = 30
  1153.     else
  1154.       @index = index
  1155.     end
  1156.     select(@index)
  1157.     return if @cursor_wait > 0
  1158.     @cursor_wait += 2
  1159.   end
  1160. end
  1161.  
  1162.  
  1163. class Window_NameInput
  1164.   def item_max
  1165.     return 90
  1166.   end
  1167. end
  1168.  
  1169. class Scene_File < Scene_MenuBase
  1170.  
  1171.   alias mouse_top_index top_index=
  1172.   def top_index=(index)
  1173.     @scroll_timer = 0 if @scroll_timer.nil? ; @scroll_timer -= 1
  1174.     return if @scroll_timer > 0
  1175.     mouse_top_index(index) ; @scroll_timer = 35
  1176.   end
  1177.  
  1178.   alias mouse_sb_update update
  1179.   def update
  1180.     (0..self.item_max - 1).each do |i|
  1181.       ix = @savefile_windows[i].x
  1182.       iy = @savefile_windows[i].y + 40 - @savefile_viewport.oy
  1183.       iw = @savefile_windows[i].width
  1184.       ih = @savefile_windows[i].height
  1185.       if Mouse.object_area?(ix, iy, iw, ih)
  1186.         @savefile_windows[@index].selected = false
  1187.         @savefile_windows[i].selected = true
  1188.         @index = i
  1189.       end
  1190.       ensure_cursor_visible
  1191.     end
  1192.     mouse_sb_update
  1193.   end
  1194. end

XAS ACE.part1.rar

2 MB, 下载次数: 137

最佳答案

查看完整内容

画面xy: 地图xy:

Lv4.逐梦者

梦石
0
星屑
7290
在线时间
1690 小时
注册时间
2017-4-28
帖子
85

开拓者

2
发表于 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
复制代码
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
103
在线时间
10 小时
注册时间
2018-1-13
帖子
10
3
 楼主| 发表于 2019-6-20 17:20:48 | 只看该作者

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

点评

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

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-11-16 19:05

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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