TheoAllen

Theo - Moving Cursor

Aug 17th, 2013
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.82 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Moving Cursor
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # -----------------------------------------------------------------------------
  7. # Requires :
  8. # >> Theo - Core Movement (Basic Modules)
  9. # =============================================================================
  10. ($imported ||= {})[:Theo_MovingCursor] = true
  11. # =============================================================================
  12. # CHANGE LOGS:
  13. # -----------------------------------------------------------------------------
  14. # 2013.08.17 - Finished script
  15. # =============================================================================
  16. =begin
  17.  
  18.   Perkenalan :
  19.   Script ini ngebikin cursor dalam window bergerak pindah
  20.  
  21.   Cara penggunaan :
  22.   Pasang script ini dibawah Theo - Basic Module
  23.   Pastikan $imported[:Theo_Movement] diset ke true di basic modul gw
  24.   Edit konfignya kalo perlu
  25.  
  26.   Terms of Use :
  27.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  28.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  29.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.  
  30.  
  31. =end
  32. # =============================================================================
  33. # Sedikit Konfig
  34. # =============================================================================
  35.  
  36.   CursorMove_Duration = 5
  37. # Durasi dalam satuan frame. Dimana 60 frame sama dengan 1 detik
  38.  
  39. # =============================================================================
  40. # Akhir dari konfig
  41. # =============================================================================
  42. # ----------------------------------------------------------------------------
  43. # Altered Rect Class
  44. # ----------------------------------------------------------------------------
  45. class Rect
  46.   include THEO::Movement
  47.  
  48.   def empty?
  49.     width <= 0 && height <= 0
  50.   end
  51.  
  52.   def update
  53.     set_obj(self) unless obj_defined?
  54.     update_move
  55.   end
  56.  
  57. end
  58. # ----------------------------------------------------------------------------
  59. # Altered Window Selectable
  60. # ----------------------------------------------------------------------------
  61. class Window_Selectable < Window_Base
  62.   # --------------------------------------------------------------------------
  63.   # Overwrite update cursor
  64.   # --------------------------------------------------------------------------
  65.   def update_cursor
  66.     if @cursor_all
  67.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  68.       self.top_row = 0
  69.     elsif @index < 0
  70.       cursor_rect.empty
  71.     else
  72.       ensure_cursor_visible
  73.       if cursor_rect.empty?
  74.         cursor_rect.set(item_rect(@index))
  75.       else
  76.         cursor_rect.set_obj(cursor_rect) unless cursor_rect.obj_defined?
  77.         target_rect = item_rect(@index)
  78.         xpos = target_rect.x
  79.         ypos = target_rect.y
  80.         cursor_rect.goto(xpos,ypos,CursorMove_Duration)
  81.       end
  82.     end
  83.   end
  84.  
  85.   alias moving_cursor_update update
  86.   def update
  87.     moving_cursor_update
  88.     cursor_rect.update
  89.   end
  90.   # --------------------------------------------------------------------------
  91.   # Overwrite Cursor Index Movement
  92.   # --------------------------------------------------------------------------
  93.   def cursor_down(wrap = false)
  94.     if index < item_max - col_max || (wrap && col_max == 1)
  95.       select((index + col_max) % item_max,false)
  96.     end
  97.   end
  98.   def cursor_up(wrap = false)
  99.     if index >= col_max || (wrap && col_max == 1)
  100.       select((index - col_max + item_max) % item_max,false)
  101.     end
  102.   end
  103.   def cursor_right(wrap = false)
  104.     if col_max >= 2 && (index < item_max - 1 || (wrap && horizontal?))
  105.       select((index + 1) % item_max,false)
  106.     end
  107.   end
  108.   def cursor_left(wrap = false)
  109.     if col_max >= 2 && (index > 0 || (wrap && horizontal?))
  110.       select((index - 1 + item_max) % item_max,false)
  111.     end
  112.   end
  113.   def cursor_pagedown
  114.     if top_row + page_row_max < row_max
  115.       self.top_row += page_row_max
  116.       select([@index + page_item_max, item_max - 1].min,false)
  117.     end
  118.   end
  119.   def cursor_pageup
  120.     if top_row > 0
  121.       self.top_row -= page_row_max
  122.       select([@index - page_item_max, 0].max,false)
  123.     end
  124.   end
  125.   # --------------------------------------------------------------------------
  126.   # Aliased Index Select
  127.   # --------------------------------------------------------------------------
  128.   alias moving_cursor_select select
  129.   def select(index, instant = true)
  130.     moving_cursor_select(index)
  131.     if instant && index > 0 && !@cursor_all
  132.       cursor_rect.set(item_rect(@index))
  133.     end
  134.   end
  135. end
  136.  
  137. module THEO
  138.   module Movement
  139.    
  140.     def obj_defined?
  141.       !@move_obj.nil?
  142.     end
  143.    
  144.   end
  145. end
Advertisement
Add Comment
Please, Sign In to add comment