Advertisement
MakerSystems

RPG Maker VX Ace - Smooth Cursor + Smooth SaveCursor

Nov 26th, 2014
2,577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.23 KB | None | 0 0
  1. %Q(
  2. ╔════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═════╗
  3. ║ ╔══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╗ ║
  4. ╠─╣ Smooth Cursor ╠─╣
  5. ╠─╣ by RPG Maker Source. ╠─╣
  6. ╠─╣ www.rpgmakersource.com ╠─╣
  7. ║ ╚══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╝ ║
  8. ╠════╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═════╣
  9. ║ ┌────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────┐ ║
  10. ╠─┤ Version 1.0.4 24/05/15 DD/MM/YY ├─╣
  11. ║ └────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────┘ ║
  12. ╠══════╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══════╣
  13. ║ ║
  14. ║ This work is protected by the following license: ║
  15. ║ ╔══════════════════════════════════════════════════════════════════╗ ║
  16. ║ │ │ ║
  17. ║ │ Copyright © 2014 Maker Systems. │ ║
  18. ║ │ │ ║
  19. ║ │ This software is provided 'as-is', without any kind of │ ║
  20. ║ │ warranty. Under no circumstances will the author be held │ ║
  21. ║ │ liable for any damages arising from the use of this software. │ ║
  22. ║ │ │ ║
  23. ║ │ Permission is granted to anyone to use this software on their │ ║
  24. ║ │ free or commercial games made with a legal copy of RPG Maker │ ║
  25. ║ │ VX Ace, as long as Maker Systems - RPG Maker Source is │ ║
  26. ║ │ credited within the game. │ ║
  27. ║ │ │ ║
  28. ║ │ Selling this code or any portions of it 'as-is' or as part of │ ║
  29. ║ │ another code, is not allowed. │ ║
  30. ║ │ │ ║
  31. ║ │ The original header, which includes this copyright notice, │ ║
  32. ║ │ must not be edited or removed from any verbatim copy of the │ ║
  33. ║ │ sotware nor from any edited version. │ ║
  34. ║ │ │ ║
  35. ║ ╚══════════════════════════════════════════════════════════════════╝ ║
  36. ║ ║
  37. ║ ║
  38. ╠══════════════════════════════════════════════════════════════════════════════╣
  39. ║ 1. VERSION HISTORY. ▼ ║
  40. ╠══════════════════════════════════════════════════════════════════════════════╣
  41. ║ ║
  42. ║ • Version 1.0.0, 24/11/14 - (DD/MM/YY). ║
  43. ║ ║
  44. ║ • Version 1.0.1, 30/11/14 - (DD/MM/YY). ║
  45. ║ ║
  46. ║ • Version 1.0.2, 17/12/14 - (DD/MM/YY). ║
  47. ║ ║
  48. ║ • Version 1.0.3, 30/03/15 - (DD/MM/YY). ║
  49. ║ ║
  50. ║ • Version 1.0.4, 24/05/15 - (DD/MM/YY). ║
  51. ║ ║
  52. ╠══════════════════════════════════════════════════════════════════════════════╣
  53. ╠══════════════════════════════════════════════════════════════════════════════╣
  54. ║ 2. USER MANUAL. ▼ ║
  55. ╠══════════════════════════════════════════════════════════════════════════════╣
  56. ║ ║
  57. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  58. ║ │ ■ Introduction. │ ║
  59. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  60. ║ ║
  61. ║ Hello there! This script is "plug and play", you can simply insert it into ║
  62. ║ your project and it will perform flawlessly. ║
  63. ║ ║
  64. ║ This script embellishes your GUIs by changing the way the default Window ║
  65. ║ cursor works in RPG Maker VX Ace. The cursor will smoothly move to its new ║
  66. ║ position when selecting items and will also smoothly change its size when ║
  67. ║ needed. ║
  68. ║ ║
  69. ║ The scrolling of the window contents will also be smooth. ║
  70. ║ ║
  71. ║ We hope you enjoy it. ║
  72. ║ ║
  73. ║ Thanks for choosing our products. ║
  74. ║ ║
  75. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  76. ║ │ ■ Configuration. │ ║
  77. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  78. ║ ║
  79. ║ "How do I change the speed of the cursor movement?" ║
  80. ║ Right click anywhere in the script editor and select "Find" (or CTRL + F) ║
  81. ║ search for "DELAY_LEVEL" (without quotation marks). ║
  82. ║ ║
  83. ║ You will see something like "DELAY_LEVEL = 4" ║
  84. ║ ║
  85. ║ Set the number after the equality sign to any numer you like, bigger or ║
  86. ║ equal than 1. The bigger the number, the stronger the deceleration effect ║
  87. ║ and thus the slower the cursor speed when changing selections (or ║
  88. ║ dimensions). Small numbers result in a faster deceleration, default value ║
  89. ║ is 4. ║
  90. ║ ║
  91. ║ ║
  92. ╠══════════════════════════════════════════════════════════════════════════════╣
  93. ╠══════════════════════════════════════════════════════════════════════════════╣
  94. ║ 3. NOTES. ▼ ║
  95. ╠══════════════════════════════════════════════════════════════════════════════╣
  96. ║ ║
  97. ║ Have fun and enjoy! ║
  98. ║ ║
  99. ╠══════════════════════════════════════════════════════════════════════════════╣
  100. ╠══════════════════════════════════════════════════════════════════════════════╣
  101. ║ 4. CONTACT. ▼ ║
  102. ╠══════════════════════════════════════════════════════════════════════════════╣
  103. ║ ║
  104. ║ Keep in touch with us and be the first to know about new releases: ║
  105. ║ ║
  106. ║ www.rpgmakersource.com ║
  107. ║ www.facebook.com/RPGMakerSource ║
  108. ║ www.twitter.com/RPGMakerSource ║
  109. ║ www.youtube.com/user/RPGMakerSource ║
  110. ║ ║
  111. ║ Get involved! Have an idea for a system? Let us know. ║
  112. ║ ║
  113. ║ Spread the word and help us reach more people so we can continue creating ║
  114. ║ awesome resources for you! ║
  115. ║ ║
  116. ╚══════════════════════════════════════════════════════════════════════════════╝)
  117.  
  118. #==============================================================================
  119. # ** MakerSystems
  120. #------------------------------------------------------------------------------
  121. # Module for our Systems.
  122. #==============================================================================
  123.  
  124. module MakerSystems
  125.  
  126. #============================================================================
  127. # ** SmoothCursor
  128. #----------------------------------------------------------------------------
  129. # Module for Smooth Cursor.
  130. #============================================================================
  131.  
  132. module SmoothCursor
  133.  
  134. #------------------------------------------------------------------------
  135. # * Low values yield a fast effect. [OPT]
  136. #------------------------------------------------------------------------
  137. DELAY_LEVEL = 4
  138.  
  139. end
  140.  
  141. end
  142.  
  143. #==============================================================================
  144. # ** Window_Selectable
  145. #------------------------------------------------------------------------------
  146. # Alias to Update. Update Cursor Replaced. Added method to handle the effect.
  147. #==============================================================================
  148.  
  149. class Window_Selectable < Window_Base
  150.  
  151. #--------------------------------------------------------------------------
  152. # * Update Alias [NEW]
  153. #--------------------------------------------------------------------------
  154. alias_method(:ms_smooth_cursor_original_update, :update)
  155. #--------------------------------------------------------------------------
  156. # * Update [MOD]
  157. #--------------------------------------------------------------------------
  158. def update
  159. # Original method.
  160. ms_smooth_cursor_original_update
  161. # Stop unless cursor update is needed.
  162. return unless @ms_smooth_cursor_target && self.index >= 0 && !disposed?
  163. # Update smooth cursor features.
  164. ms_smooth_cursor_update
  165. end
  166. #--------------------------------------------------------------------------
  167. # * Smooth Cursor Update [NEW]
  168. #--------------------------------------------------------------------------
  169. def ms_smooth_cursor_update
  170. # Current Rect.
  171. now = cursor_rect
  172. # Get the target Rect.
  173. target = @ms_smooth_cursor_target[0]
  174. # Get the target Offset Y.
  175. target_oy = @ms_smooth_cursor_target[1]
  176. # Shortcut to desired delay.
  177. delay = MakerSystems::SmoothCursor::DELAY_LEVEL.to_f
  178. # Calculates and applies step value for X.
  179. step = ((target.x - now.x).to_f / delay)
  180. now.x += target.x > now.x ? step.ceil : step.floor
  181. # Calculates and applies step value for Y.
  182. step = ((target.y - now.y).to_f / delay)
  183. now.y += target.y > now.y ? step.ceil : step.floor
  184. # Calculates and applies step value for Width.
  185. step = ((target.width - now.width).to_f / delay)
  186. now.width += target.width > now.width ? step.ceil : step.floor
  187. # Calculates and applies step value for Height.
  188. step = ((target.height - now.height).to_f / delay)
  189. now.height += target.height > now.height ? step.ceil : step.floor
  190. if self.respond_to?(:visible_line_number) && visible_line_number == 1
  191. # Calculates and applies step value for Offset Y.
  192. step = ((target_oy - self.ox).to_f / delay)
  193. self.ox += target_oy > self.ox ? step.ceil : step.floor
  194. # If targets reached, stop ms_smooth_cursor_update.
  195. if cursor_rect == target && self.ox == target_oy
  196. @ms_smooth_cursor_target = nil
  197. end
  198. else
  199. # Calculates and applies step value for Offset Y.
  200. step = ((target_oy - self.oy).to_f / delay)
  201. self.oy += target_oy > self.oy ? step.ceil : step.floor
  202. # If targets reached, stop ms_smooth_cursor_update.
  203. if cursor_rect == target && self.oy == target_oy
  204. @ms_smooth_cursor_target = nil
  205. end
  206. end
  207. end
  208.  
  209. #--------------------------------------------------------------------------
  210. # * Top Col (HorzCommand), [NEW]
  211. #--------------------------------------------------------------------------
  212. def ms_smooth_cursor_hrzcommand_top_col=(col)
  213. col = 0 if col < 0
  214. col = col_max - 1 if col > col_max - 1
  215. @ms_smooth_cursor_target_ox = col * (item_width + spacing)
  216. end
  217. #--------------------------------------------------------------------------
  218. # * Bottom Col (HorzCommand). [NEW]
  219. #--------------------------------------------------------------------------
  220. def ms_smooth_cursor_hrzcommand_bottom_col=(col)
  221. self.ms_smooth_cursor_hrzcommand_top_col = col - (col_max - 1)
  222. end
  223. #--------------------------------------------------------------------------
  224. # * Ensure Cursor Visible (HorzCommand). [NEW]
  225. #--------------------------------------------------------------------------
  226. def ms_smooth_cursor_hrzcommand_ensure_cursor_visible
  227. self.ms_smooth_cursor_hrzcommand_top_col = index if index < top_col
  228. self.ms_smooth_cursor_hrzcommand_bottom_col = index if index > bottom_col
  229. end
  230. #--------------------------------------------------------------------------
  231. # * Update Cursor. [REP]
  232. #--------------------------------------------------------------------------
  233. def update_cursor
  234. if @cursor_all
  235. cursor_rect.set(0, 0, contents.width, row_max * item_height)
  236. self.top_row = 0
  237. elsif @index < 0
  238. cursor_rect.empty
  239. else
  240. if self.respond_to?(:visible_line_number) && visible_line_number == 1 &&
  241. self.respond_to?(:top_col)
  242. # Special case for HorzCommand window or any horizontally extended one.
  243. ms_target_oy = self.ox
  244. ms_smooth_cursor_hrzcommand_ensure_cursor_visible
  245. if @ms_smooth_cursor_target_ox
  246. ms_target_oy = @ms_smooth_cursor_target_ox
  247. end
  248. else
  249. # Manages Offset Y as in ensure_cursor_visible but instead of using
  250. # top_row to set the value, passes it to ms_smooth_cursor_update.
  251. ms_target_oy = self.oy
  252. if row < top_row || row > bottom_row
  253. msrow = row
  254. msrow = msrow - (page_row_max - 1) if row > bottom_row
  255. msrow = 0 if msrow < 0
  256. msrow = row_max - 1 if msrow > row_max - 1
  257. ms_target_oy = msrow * item_height
  258. end
  259. end
  260. # New targets.
  261. @ms_smooth_cursor_target = [item_rect(@index), ms_target_oy]
  262. end
  263. end
  264.  
  265. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement