IceDragon200

[VXA]Earthen-MouseAddon

Jul 3rd, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.87 KB | None | 0 0
  1. # // 01/24/2012
  2. # // 01/24/2012
  3. if defined? Mouse
  4. module Mixin::MouseSelectable
  5.   def top_rect
  6.     Rect.new(self.vx, self.vy, self.width, 32)
  7.   end
  8.   def bottom_rect
  9.     Rect.new(self.vx, self.vy2-32, self.width, 32)
  10.   end  
  11.   #alias :pre_mouse_update :update
  12.   #def update
  13.   #  pre_mouse_update()
  14.   #  
  15.   #end  
  16.   def mouse_index?(i)
  17.     MouseEx.in_area?(item_rect_to_screen(item_rect(i)).to_v4) && i.between?(0,item_max-1)
  18.   end  
  19.   def current_item_to_screen()
  20.     item_rect_to_screen(item_rect(self.index))
  21.   end  
  22.   def item_rect_to_screen(rect)
  23.     rect = rect.dup
  24.     rect.x = self.x + standard_padding + rect.x - self.ox
  25.     rect.y = self.y + standard_padding + rect.y - self.oy
  26.     rect.height -= 2
  27.     rect
  28.   end
  29.   def cursor_rect_to_screen()
  30.     item_rect_to_screen(cursor_rect.to_rect)
  31.   end  
  32.   def screen_x2content_x(sx)
  33.     sx - self.x - self.padding + self.ox
  34.   end  
  35.   def screen_y2content_y(sy)
  36.     sy - self.y - self.padding + self.oy
  37.   end
  38.   def mouse_in_contents?
  39.     MouseEx.in_area?(self.contents_rect)
  40.   end  
  41.   def process_cursor_move()
  42.     return unless cursor_movable? && !win_busy?
  43.     last_index = @index
  44.     unless mouse_select_index()
  45.       cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
  46.       cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
  47.       cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  48.       cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  49.       cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
  50.       cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
  51.     end  
  52.     Sound.play_cursor if @index != last_index
  53.   end
  54.   def mouse_select_index()
  55.     return false unless MouseEx.moved?
  56.     return false unless mouse_in_contents?
  57.     i = calc_col_index(MouseEx.x) + (calc_row_index(MouseEx.y) * col_max)
  58.     i = i.clamp(0,(item_max-1).max(0))
  59.     self.index = i if i != self.index
  60.     # // LAGGY O_O But kinda works o-e
  61.     #for i in (top_row*col_max)...((top_row*col_max)+page_item_max)
  62.     #  if mouse_index?(i)
  63.     #    self.index = i
  64.     #    return true
  65.     #  end  
  66.     #end
  67.     return true
  68.   end
  69.   def calc_col_index(x)
  70.     (screen_x2content_x(x) / (item_width + spacing).to_f).floor    
  71.   end  
  72.   def calc_row_index(y)
  73.     (screen_y2content_y(y) / (item_height).to_f).floor
  74.   end
  75.   def process_handling
  76.     return unless open? && active && !win_busy?
  77.     if mouse_in_contents?
  78.       return process_ok       if ok_enabled?     && MouseEx.left_click?()
  79.       return process_cancel   if cancel_enabled? && MouseEx.right_click?()
  80.     end  
  81.     return process_ok       if ok_enabled?        && Input.trigger?(:C)
  82.     return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  83.     return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  84.     return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  85.   end
  86. end
  87. class Shell::WinSel #Window::MenuParty
  88.   include Mixin::MouseSelectable  
  89. end  
  90. class Window::Selectable < Window::Base
  91.   remove_method :process_handling
  92.   remove_method :process_cursor_move
  93.   include Mixin::MouseSelectable
  94. end
  95. module Mixin::WheelButtons
  96.   def ex_init
  97.     super()
  98.     @buttons = []
  99.     @buttons << GUIExt::Button_Base.new( nil, 0, 0, 13 )
  100.     @buttons << GUIExt::Button_Base.new( nil, 0, 0, 14 )
  101.     @buttons << GUIExt::Button_Base.new( nil, 0, 0, 15 )
  102.     @buttons << GUIExt::Button_Base.new( nil, 0, 0, 12 )
  103.     @buttons << GUIExt::Button_Base.new( nil, 0, 0, 4 )
  104.     @buttons << GUIExt::Button_Base.new( nil, 0, 0, 5 )
  105.     @buttons[0].set_handler(:click, method(:wheel_left))
  106.     @buttons[1].set_handler(:click, method(:wheel_right))
  107.     @buttons[2].set_handler(:click, method(:wheel_up))
  108.     @buttons[3].set_handler(:click, method(:wheel_down))
  109.     @buttons[4].set_handler(:click, method(:wheel_cancel))
  110.     @buttons[5].set_handler(:click, method(:wheel_ok))
  111.     @buttons[0].help_text = "Previous"
  112.     @buttons[1].help_text = "Next"
  113.     @buttons[2].help_text = "Previous Page"
  114.     @buttons[3].help_text = "Next Page"
  115.     @buttons[4].help_text = "Cancel"
  116.     @buttons[5].help_text = "Ok"
  117.     @buttons.each{|b|b.help_window = Mouse.tooltip_sprite}
  118.   end
  119.   def update()
  120.     super()
  121.   end  
  122.   def refresh_x()
  123.     super()
  124.     @buttons[0].x = self.vx - 32
  125.     @buttons[1].x = self.vx2 + 32
  126.     @buttons[2].x = self.x #- 12
  127.     @buttons[3].x = self.x #- 12
  128.     @buttons[4].x = self.vx - 24
  129.     @buttons[5].x = self.vx2 + 24
  130.   end
  131.   def refresh_y()
  132.     super()
  133.     @buttons[0].y = self.y #- 12
  134.     @buttons[1].y = self.y #- 12
  135.     @buttons[2].y = self.vy - 52
  136.     @buttons[3].y = self.vy2 + 32
  137.     @buttons[4].y = self.vy2 + 40
  138.     @buttons[5].y = self.vy2 + 40
  139.   end
  140.   def refresh_z()
  141.     super()
  142.     @buttons.each { |but| but.z = self.z + 4 }
  143.   end
  144.   def refresh_visible()
  145.     super()
  146.     @buttons.each { |but| but.visible = self.visible }
  147.   end  
  148.   def refresh_active()
  149.     super()
  150.     @buttons.each { |but| but.active = self.active }
  151.   end  
  152.   def refresh_viewport()
  153.     super()
  154.     @buttons.each { |but| but.viewport = self.viewport }
  155.   end
  156. end
  157. #=begin
  158. class Wheel_Command
  159.   include Mixin::WheelButtons
  160.   def process_cursor_move()
  161.     return unless cursor_movable?
  162.     last_index = self.index
  163.     @buttons.each { |but| but.update }
  164.     wheel_up() if Input.repeat?( :UP )
  165.     wheel_down() if Input.repeat?( :DOWN )
  166.     wheel_left() if Input.repeat?( :LEFT )
  167.     wheel_right() if Input.repeat?( :RIGHT )
  168.     Sound.play_cursor() if self.index != last_index
  169.   end
  170. end  
  171. =begin
  172. class Game::RogueCursor
  173.   def update_input()
  174.     return if moving?
  175.     #d = Input.dir4
  176.     #return unless d > 0
  177.     mx = (_map.display_x / 32) + (MouseEx.x / 32) #_map.round_x_with_direction(@x, d)
  178.     my = (_map.display_y / 32) + (MouseEx.y / 32) #_map.round_y_with_direction(@y, d)
  179.     if _map.valid?( mx, my )
  180.       @x, @y = mx, my#[[mx, _map.width-1].min, 0].max, [[my, _map.height-1].min, 0].max
  181.       @real_x = mx#_map.x_with_direction(@x, reverse_dir(d))
  182.       @real_y = my#_map.y_with_direction(@y, reverse_dir(d))
  183.       RogueManager.call_handler( :on_cursor_move )
  184.     end  
  185.   end
  186. end  
  187. =end
  188. module MapScroll
  189.   def self._map
  190.     $game_system.rogue? ? $game_rogue : $game_map
  191.   end
  192.   def self.response_size
  193.     64
  194.   end    
  195.   def self.pressure_effect( sp, press )
  196.     sp.flash(Pallete[:sys_green].xset(:alpha=>(255*press).clamp(0,255)), 60) if sp
  197.   end  
  198.   def self.mscroll_up(press)
  199.     pressure_effect(@edge_sprites[0], press)
  200.     _map.scroll_up(press)
  201.   end
  202.   def self.mscroll_down(press)
  203.     pressure_effect(@edge_sprites[1], press)
  204.     _map.scroll_down(press)
  205.   end
  206.   def self.mscroll_left(press)
  207.     pressure_effect(@edge_sprites[2], press)
  208.     _map.scroll_left(press)
  209.   end
  210.   def self.mscroll_right(press)
  211.     pressure_effect(@edge_sprites[3], press)
  212.     _map.scroll_right(press)
  213.   end
  214.   def self.view_edge
  215.     if @view_edge.nil?
  216.       @view_edge = Handler::ViewEdge.new(Graphics.play_rect.clone)
  217.       @view_edge.set_handler(:left, method(:mscroll_left))
  218.       @view_edge.set_handler(:right, method(:mscroll_right))
  219.       @view_edge.set_handler(:up, method(:mscroll_up))
  220.       @view_edge.set_handler(:down, method(:mscroll_down))
  221.     end
  222.     @view_edge
  223.   end
  224.   def self.edge_responses
  225.     self.view_edge.edge_responses
  226.   end  
  227.   def self.use_egde_sprites?
  228.     false
  229.   end  
  230.   def self.make_edges
  231.     @edge_sprites = []
  232.     if use_egde_sprites?
  233.       @edge_sprites = self.view_edge.make_edge_sprites
  234.     end  
  235.     #@x32_cursor = Sprite.new()
  236.     #@x32_cursor.bitmap = Bitmap.new(32,32)
  237.     #@x32_cursor.bitmap.fill_rect(@x32_cursor.bitmap.rect.contract(2), Pallete[:white])
  238.     #@x32_cursor.bitmap.blur
  239.     #@x32_cursor.bitmap.blur
  240.     #@x32_cursor.opacity = 128
  241.     #@x32_cursor.z = 20
  242.   end  
  243.   def self.edge_sprites()
  244.     @edge_sprites
  245.   end  
  246.   def self.x32_cursor
  247.     @x32_cursor
  248.   end  
  249.   def self.init
  250.     edge_responses()
  251.     make_edges()
  252.   end  
  253. end
  254. module SceneManager
  255.   class << self
  256.     alias :post_mouse_addon_run :run
  257.     def run(*args)
  258.       MapScroll.init
  259.       post_mouse_addon_run(*args)
  260.     end  
  261.   end  
  262. end  
  263. class Game::Map  
  264.   alias :pre_mouse_update :update
  265.   def update(*args)
  266.     pre_mouse_update(*args)
  267.     MapScroll.view_edge.update if @cursor.active if @cursor
  268.     MapScroll.edge_sprites.each { |e| e.update() }
  269.     #MapScroll.x32_cursor.update
  270.     #MapScroll.x32_cursor.x, MapScroll.x32_cursor.y = *mouse_x32_screen_pos()    
  271.   end  
  272.   def mouse_x32_pos_f
  273.     cx, cy = *MouseEx.pos
  274.     #cx -= 16
  275.     #cy -= 16
  276.     cx = (display_x + (cx / 32.0))#.round(0)
  277.     cy = (display_y + (cy / 32.0))#.round(0)
  278.     return cx, cy
  279.   end
  280.   def mouse_x32_pos
  281.     cx, cy = *mouse_x32_pos_f
  282.     cx = cx.floor#.round(0)
  283.     cy = cy.floor#.round(0)
  284.     return cx, cy
  285.   end
  286.   def mouse_x32_screen_pos()
  287.     cx, cy = mouse_x32_pos()
  288.     return adjust_x(cx) * 32, adjust_y(cy) * 32
  289.   end  
  290. end  
  291. class Scene::Rogue < Scene::Base
  292.   #--------------------------------------------------------------------------#
  293.   # ● new-method :refresh_spriteset
  294.   #--------------------------------------------------------------------------#
  295.   def trigger_cursor_mode( forced_off=false )
  296.     if $game_rogue.cursor.active || forced_off
  297.       _map.cursor.moveto( @subject.x, @subject.y )
  298.       _map.release_character_table
  299.       _map.deactivate_cursor
  300.       _map.cursor.focus_off
  301.       _map.clear_active_ranges()
  302.       @subject.focus_on
  303.     else  
  304.       @subject.focus_off
  305.       _map.cursor.moveto( *_map.mouse_x32_pos )#@subject.x, @subject.y )
  306.       _map.static_character_table
  307.       _map.activate_cursor
  308.       _map.cursor.focus_on
  309.       on_cursor_move()
  310.       Mouse.set_pos(_map.cursor.screen_x, _map.cursor.screen_y)
  311.       #rngs = [[0, 1], [0, -1],
  312.       # [1, 0], [-1, 0]].collect { |r| [r[0] + @subject.x, r[1] + @subject.y] }
  313.       #_map.add_ranges( rngs, Color.new(0, 32, 168).to_flash )
  314.     end  
  315.   end
  316. end  
  317. end
Advertisement
Add Comment
Please, Sign In to add comment