Advertisement
roninator2

Kanji Smooth Cursor - mod

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