Advertisement
neutale

Kanji - Smooth Cursor Movement

Mar 12th, 2020
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.93 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Smooth Cursor Movement var 0.00 by Kanji the Grass
  3. # This work is provided under the MTCM Blue License
  4. # https://en.materialcommons.tk/mtcm-b-summary/
  5. # Credits display: Kanji the Grass
  6. #==============================================================================
  7. class Window_Selectable
  8.   def c_max_time
  9.     return 3
  10.   end
  11.   #--------------------------------------------------------------------------
  12.   # ● Set cursor position
  13.   #--------------------------------------------------------------------------
  14.   alias kns_index index=
  15.   def index=(index)
  16.     @last_index2 = @index
  17.     @cursor_end = false
  18.     @c_time = 0
  19.     kns_index(index)
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # ● Update cursor
  23.   #--------------------------------------------------------------------------
  24.   def update_cursor
  25.     if @cursor_all
  26.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  27.       self.top_row = 0
  28.     elsif @index < 0
  29.       cursor_rect.empty
  30.     else
  31.       ensure_cursor_visible
  32.       @o_rect = @last_index2 == -1 ? @o_rect.empty : item_rect(@last_index2)
  33.       @t_rect = @index == -1 ? @t_rect.empty : item_rect(@index)
  34.     end
  35.   end
  36.   def update_cursor_par_frame
  37.     return unless self.visible
  38.     if !(@cursor_all || @index < 0) && !@cursor_end
  39.       x, y = @o_rect.x, @o_rect.y
  40.       x2, y2 = @t_rect.x, @t_rect.y
  41.       nx = (x2 - x) * @c_time.next.to_f / c_max_time + x
  42.       ny = (y2 - y) * @c_time.next.to_f / c_max_time + y
  43.       cursor_rect.set(nx, ny, @t_rect.width, @t_rect.height)
  44.       @c_time += 1
  45.       @cursor_end = @c_time >= c_max_time
  46.       Graphics.frame_reset
  47.     end
  48.   end
  49.  
  50.   alias kns_initialize initialize
  51.   def initialize(x, y, width, height)
  52.     kns_initialize(x, y, width, height)
  53.     @oy_time = @t_oy = 0
  54.     @ox_time = @t_ox = 0
  55.     @last_index2 = 0
  56.     @cursor_end = false
  57.     @c_time = 0
  58.     @o_rect = Rect.new(0,0,1,10)
  59.     @t_rect = Rect.new(0,0,1,10)
  60.   end
  61.   alias kns_update update
  62.   def update
  63.     kns_update
  64.     update_scroll_o
  65.     update_cursor_par_frame
  66.   end
  67.   alias kns_oy oy=
  68.   def oy=(oy)
  69.     return if @t_oy == oy
  70.     @oy_time = 0
  71.     @t_oy = oy
  72.   end
  73.   alias kns_ox ox=
  74.   def ox=(ox)
  75.     return if @t_ox == ox
  76.     @ox_time = 0
  77.     @t_ox = ox
  78.   end
  79.   def update_scroll_o
  80.     return unless self.visible
  81.     need_reset = nil
  82.     if @t_oy != self.oy
  83.       @oy_time = @oy_time.next % scroll_o_time
  84.       kns_oy((@t_oy - self.oy) * @oy_time.next.to_f / scroll_o_time + self.oy)
  85.       @oy_time += 1
  86.       need_reset = true
  87.     end
  88.     if @t_ox != self.ox
  89.       @ox_time = @ox_time.next % scroll_o_time
  90.       kns_ox((@t_ox - self.ox) * @ox_time.next.to_f / scroll_o_time + self.ox)
  91.       @ox_time += 1
  92.       need_reset = true
  93.     end
  94.     Graphics.frame_reset if need_reset
  95.   end
  96.   def scroll_o_time
  97.     return 12
  98.   end
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement