Advertisement
Falmc

Mouse

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