Advertisement
Falmc

Untitled

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