Advertisement
MakerSystems

RPG Maker VX Ace - Command Slider

Nov 26th, 2014
1,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.67 KB | None | 0 0
  1. %Q(
  2. ╔════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═════╗
  3. ║ ╔══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╗ ║
  4. ╠─╣ Command Slider ╠─╣
  5. ╠─╣ by RPG Maker Source. ╠─╣
  6. ╠─╣ www.rpgmakersource.com ╠─╣
  7. ║ ╚══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╝ ║
  8. ╠════╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═════╣
  9. ║ ┌────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────┐ ║
  10. ╠─┤ Version 1.2.0 28/04/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, 28/11/14 - (DD/MM/YY). ║
  45. ║ ║
  46. ║ • Version 1.1.0, 28/11/14 - (DD/MM/YY). ║
  47. ║ - You can now exclude some windows from the cool sliding effect club. ║
  48. ║ ║
  49. ║ • Version 1.1.1, 29/11/14 - (DD/MM/YY). ║
  50. ║ ║
  51. ║ • Version 1.2.0, 28/04/15 - (DD/MM/YY). ║
  52. ║ - Changed method structure for better compatibility. ║
  53. ║ ║
  54. ╠══════════════════════════════════════════════════════════════════════════════╣
  55. ╠══════════════════════════════════════════════════════════════════════════════╣
  56. ║ 2. USER MANUAL. ▼ ║
  57. ╠══════════════════════════════════════════════════════════════════════════════╣
  58. ║ ║
  59. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  60. ║ │ ■ Introduction. │ ║
  61. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  62. ║ ║
  63. ║ Hello there! This script is "plug and play", you can simply insert it into ║
  64. ║ your project and it will perform flawlessly. ║
  65. ║ ║
  66. ║ This script will add a nice effect to the selection of items inside your ║
  67. ║ menu and works for all Window_Command windows. ║
  68. ║ ║
  69. ║ The effect is simple: when an item is selected, its text is smoothly ║
  70. ║ centered inside the selection rectangle, when selecting other item, the ║
  71. ║ last selected item will smoothly move back to its original position. ║
  72. ║ ║
  73. ║ We hope you enjoy it. ║
  74. ║ ║
  75. ║ Thanks for choosing our products. ║
  76. ║ ║
  77. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  78. ║ │ ■ Configuration. │ ║
  79. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  80. ║ ║
  81. ║ "How do I change the speed of the effect?" ║
  82. ║ Right click anywhere in the script editor and select "Find" (or CTRL + F) ║
  83. ║ search for "DELAY_LEVEL" (without quotation marks). ║
  84. ║ ║
  85. ║ You will see something like "DELAY_LEVEL = 4" ║
  86. ║ ║
  87. ║ Set the number after the equality sign to any numer you like, bigger or ║
  88. ║ equal than 1. The bigger the number, the stronger the deceleration effect ║
  89. ║ and thus the slower the item text moves. Small numbers result in a faster ║
  90. ║ deceleration, default value is 4. ║
  91. ║ ║
  92. ║ "How do I exclude some Window from the effect?" ║
  93. ║ Right click anywhere in the script editor and select "Find" (or CTRL + F), ║
  94. ║ searh for "EXCLUDE" (without quotation marks). ║
  95. ║ ║
  96. ║ You will see something like: ║
  97. ║ "EXCLUDE = 'Window_ExcludedWindow'" ║
  98. ║ ║
  99. ║ To exclude Windows from the effect, simply add their names between those ║
  100. ║ single quotes (the name of the class). ║
  101. ║ For example, to exclude the Menu Command Window: ║
  102. ║ ║
  103. ║ EXCLUDE = 'Window_MenuCommand Window_ExcludedWindow' ║
  104. ║ ║
  105. ║ ║
  106. ╠══════════════════════════════════════════════════════════════════════════════╣
  107. ╠══════════════════════════════════════════════════════════════════════════════╣
  108. ║ 3. NOTES. ▼ ║
  109. ╠══════════════════════════════════════════════════════════════════════════════╣
  110. ║ ║
  111. ║ Have fun and enjoy! ║
  112. ║ ║
  113. ╠══════════════════════════════════════════════════════════════════════════════╣
  114. ╠══════════════════════════════════════════════════════════════════════════════╣
  115. ║ 4. CONTACT. ▼ ║
  116. ╠══════════════════════════════════════════════════════════════════════════════╣
  117. ║ ║
  118. ║ Keep in touch with us and be the first to know about new releases: ║
  119. ║ ║
  120. ║ www.rpgmakersource.com ║
  121. ║ www.facebook.com/RPGMakerSource ║
  122. ║ www.twitter.com/RPGMakerSource ║
  123. ║ www.youtube.com/user/RPGMakerSource ║
  124. ║ ║
  125. ║ Get involved! Have an idea for a system? Let us know. ║
  126. ║ ║
  127. ║ Spread the word and help us reach more people so we can continue creating ║
  128. ║ awesome resources for you! ║
  129. ║ ║
  130. ╚══════════════════════════════════════════════════════════════════════════════╝)
  131.  
  132. #==============================================================================
  133. # ** MakerSystems
  134. #------------------------------------------------------------------------------
  135. # Module for our Systems.
  136. #==============================================================================
  137.  
  138. module MakerSystems
  139.  
  140. #============================================================================
  141. # ** CommandSlider
  142. #----------------------------------------------------------------------------
  143. # Module for Smooth Cursor.
  144. #============================================================================
  145.  
  146. module CommandSlider
  147.  
  148. #------------------------------------------------------------------------
  149. # * Low values yield a fast effect. [OPT]
  150. #------------------------------------------------------------------------
  151. DELAY_LEVEL = 4
  152. #------------------------------------------------------------------------
  153. # * Window classes that you don't want to have the effect. [OPT]
  154. #------------------------------------------------------------------------
  155. EXCLUDE = 'Window_ExcludedWindow'
  156.  
  157. end
  158.  
  159. end
  160.  
  161. #==============================================================================
  162. # ** Window_Command
  163. #------------------------------------------------------------------------------
  164. # Draw Item replaced.
  165. #==============================================================================
  166.  
  167. class Window_Command < Window_Selectable
  168.  
  169. #--------------------------------------------------------------------------
  170. # * Draw Item. [REP]
  171. #--------------------------------------------------------------------------
  172. def draw_item(index)
  173. # Text for this Command.
  174. string = command_name(index)
  175. # Correct font color.
  176. change_color(normal_color, command_enabled?(index))
  177. # Command Slide processing only if needed.
  178. if visible_line_number == 1 || alignment == 1 || alignment == 2 ||
  179. MakerSystems::CommandSlider::EXCLUDE =~ /#{self.class.name}/
  180. draw_text(item_rect_for_text(index), string, alignment)
  181. else
  182. # Update placement if needed.
  183. update_placement if respond_to?(:update_placement)
  184. # Container for the Commands.
  185. @ms_command_slider ||= []
  186. return if @ms_command_slider.any? { |command| command[4] == index }
  187. # Get Rect for this command.
  188. rect = item_rect_for_text(index)
  189. # Create Sprite and its Bitmap for this command.
  190. sprite = Sprite.new(self.viewport)
  191. sprite.z = self.z + 10
  192. sprite.bitmap = Bitmap.new(rect.width, rect.height)
  193. sprite.bitmap.font = contents.font
  194. # Position Offset for this Command.
  195. offset_x = rect.x + standard_padding
  196. offset_y = rect.y + standard_padding
  197. # Target X for this Command.
  198. target_x = (rect.width - self.contents.text_size(string).width) / 2
  199. # Sets Sprite position.
  200. sprite.x = self.x + offset_x
  201. sprite.y = self.y + offset_y
  202. if self.height < fitting_height(visible_line_number)
  203. if sprite.y < self.y || sprite.y + sprite.bitmap.height >
  204. self.y + self.height - standard_padding
  205. sprite.visible = false
  206. end
  207. end
  208. # Draws Command text.
  209. sprite.bitmap.draw_text(0, 0, rect.width, rect.height, string, alignment)
  210. # Pushes Command to Commands container.
  211. @ms_command_slider << [sprite, offset_x, offset_y, target_x, index, 0,
  212. sprite.bitmap.text_size(string).width > self.width]
  213. end
  214. end
  215. #--------------------------------------------------------------------------
  216. # * Set Openness. [MOD]
  217. #--------------------------------------------------------------------------
  218. def openness=(value)
  219. # Superclass method.
  220. super(value)
  221. # Keeps Commands from being visible until Window is opened.
  222. if @ms_command_slider
  223. @ms_command_slider.each { |obj| obj[0].visible = self.openness == 255 }
  224. end
  225. end
  226. #--------------------------------------------------------------------------
  227. # * Alias Update. [NEW]
  228. #--------------------------------------------------------------------------
  229. alias_method(:ms_command_slider_original_update, :update)
  230. #--------------------------------------------------------------------------
  231. # * Update. [MOD]
  232. #--------------------------------------------------------------------------
  233. def update
  234. # Original method.
  235. ms_command_slider_original_update
  236. # Update Command Slider.
  237. ms_command_slider_update
  238. end
  239. #--------------------------------------------------------------------------
  240. # * Command Slider Update. [NEW]
  241. #--------------------------------------------------------------------------
  242. def ms_command_slider_update
  243. # Updates Command Slider if needed.
  244. if visible_line_number != 1 && @ms_command_slider
  245. # Goes through each Sprite command data.
  246. @ms_command_slider.each do |command|
  247. # Get Sprite.
  248. sprite = command[0]
  249. # Get Offsets.
  250. offset_x = command[1]
  251. offset_y = command[2]
  252. # Get target X.
  253. target_x = command[3]
  254. # Get the index that the Sprite represents.
  255. c_index = command[4]
  256. # Current mod to X.
  257. mod_x = command[5]
  258. # Correct target X.
  259. target_x = c_index == self.index && !command[6] ? target_x : 0
  260. # Shortcut to DELAY_LEVEL.
  261. delay = MakerSystems::CommandSlider::DELAY_LEVEL
  262. # Calculates and applies step value to current mod X.
  263. step = (target_x - mod_x).to_f / delay
  264. mod_x += target_x > mod_x ? step.ceil : step.floor
  265. # Updates Sprite.
  266. if sprite.viewport != self.viewport
  267. sprite.viewport = self.viewport
  268. end
  269. sprite.x = self.x - self.ox + offset_x + mod_x
  270. sprite.y = self.y - self.oy + offset_y
  271. sprite.z = self.z + 1
  272. sprite.visible = self.openness == 255
  273. if self.height < fitting_height(visible_line_number)
  274. if sprite.y < self.y || sprite.y + sprite.bitmap.height >
  275. self.y + self.height - standard_padding
  276. sprite.visible = false
  277. end
  278. end
  279. # Updates command data to account for mod X changes.
  280. command[5] = mod_x
  281. end
  282. end
  283. end
  284. #--------------------------------------------------------------------------
  285. # * Alias Set X. [NEW]
  286. #--------------------------------------------------------------------------
  287. alias_method(:ms_command_slider_original_set_x, :x=)
  288. #--------------------------------------------------------------------------
  289. # * Set X. [MOD]
  290. #--------------------------------------------------------------------------
  291. def x=(value)
  292. ms_command_slider_original_set_x(value)
  293. ms_command_slider_update
  294. end
  295. #--------------------------------------------------------------------------
  296. # * Alias Set Y. [NEW]
  297. #--------------------------------------------------------------------------
  298. alias_method(:ms_command_slider_original_set_y, :y=)
  299. #--------------------------------------------------------------------------
  300. # * Set Y. [MOD]
  301. #--------------------------------------------------------------------------
  302. def y=(value)
  303. ms_command_slider_original_set_y(value)
  304. ms_command_slider_update
  305. end
  306. #--------------------------------------------------------------------------
  307. # * Alias Dispose. [NEW]
  308. #--------------------------------------------------------------------------
  309. alias_method(:ms_command_slider_original_dispose, :dispose)
  310. #--------------------------------------------------------------------------
  311. # * Dispose. [MOD]
  312. #--------------------------------------------------------------------------
  313. def dispose
  314. # Original method.
  315. ms_command_slider_original_dispose
  316. # Dispose Command Slider.
  317. ms_command_slider_dispose
  318. end
  319. #--------------------------------------------------------------------------
  320. # * Command Slider Dispose. [NEW]
  321. #--------------------------------------------------------------------------
  322. def ms_command_slider_dispose
  323. # Disposes Command Slider if needed.
  324. if @ms_command_slider
  325. @ms_command_slider.each do |command|
  326. command[0].bitmap.dispose
  327. command[0].dispose
  328. command.clear
  329. end
  330. @ms_command_slider = nil
  331. end
  332. end
  333.  
  334. end
  335.  
  336. #==============================================================================
  337. # ** Window_MenuCommand
  338. #------------------------------------------------------------------------------
  339. # This command window appears on the menu screen.
  340. #==============================================================================
  341.  
  342. class Window_MenuCommand < Window_Command
  343.  
  344. #--------------------------------------------------------------------------
  345. # * Alias Select Last. [NEW]
  346. #--------------------------------------------------------------------------
  347. alias_method(:ms_command_slider_original_select_last, :select_last)
  348. #--------------------------------------------------------------------------
  349. # * Select Last. [MOD]
  350. #--------------------------------------------------------------------------
  351. def select_last
  352. ms_command_slider_original_select_last
  353. update
  354. end
  355.  
  356. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement