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

Project1

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

[已经解决] 如何实现鼠标操作?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
12 小时
注册时间
2013-2-6
帖子
18
跳转到指定楼层
 楼主| 发表于 2013-2-7 16:58:03 | 只看该作者 |只看大图 回帖奖励 |正序浏览 |阅读模式

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

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

x
本帖最后由 zehir 于 2013-2-7 22:15 编辑

就是那种常见的鼠标操作……我现在还停留在键盘操作的阶段……

Lv1.梦旅人

梦石
0
星屑
50
在线时间
12 小时
注册时间
2013-2-6
帖子
18
7
 楼主| 发表于 2013-2-7 22:12:48 | 只看该作者
Sion 发表于 2013-2-7 20:50
http://rpg.blue/thread-284480-1-1.html
用我写的吧

万分感谢大神!不知道该说啥好了……谢谢!
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
12 小时
注册时间
2013-2-6
帖子
18
6
 楼主| 发表于 2013-2-7 21:36:50 | 只看该作者
本帖最后由 zehir 于 2013-2-7 21:38 编辑
Sion 发表于 2013-2-7 20:50
http://rpg.blue/thread-284480-1-1.html
用我写的吧


谢谢!话说VA的教程在哪里找?VA和VX是什么关系?有啥区别?

点评

反正都是用ruby写的,ruby的版本不一样,语法差不多。然后脚本的内部结构不太一样。参考vx的帮助文档再对照va自己的。ruby语法http://ruby-doc.org/core-1.9.3/  发表于 2013-2-7 21:43
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
12 小时
注册时间
2013-2-6
帖子
18
5
 楼主| 发表于 2013-2-7 21:13:44 | 只看该作者
Sion 发表于 2013-2-7 20:50
http://rpg.blue/thread-284480-1-1.html
用我写的吧

谢谢你!代码我收下了!话说这个的原理是什么?

点评

什么的原理?……总而言之先从语法学起吧,多读脚本。  发表于 2013-2-7 21:32
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
12 小时
注册时间
2013-2-6
帖子
18
4
 楼主| 发表于 2013-2-7 21:13:06 | 只看该作者
tseyik 发表于 2013-2-7 20:01
Mouse System Buttons 2.0
脚本范例
http://www.mediafire.com/?ycdwlvzd5wmrdjj

谢谢你!代码我收下了!
回复 支持 反对

使用道具 举报

Lv2.观梦者 (暗夜天使)

梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
帖子
2309

贵宾

3
发表于 2013-2-7 20:50:12 | 只看该作者
http://rpg.blue/thread-284480-1-1.html
用我写的吧{:2_259:}
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
22973
在线时间
8639 小时
注册时间
2011-12-31
帖子
3367
2
发表于 2013-2-7 20:01:58 | 只看该作者
本帖最后由 tseyik 于 2013-3-19 08:50 编辑

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

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
145
在线时间
95 小时
注册时间
2012-4-30
帖子
53
1
发表于 2013-2-7 17:26:23 | 只看该作者
图书馆不是有吗
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-12-1 00:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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