Advertisement
MakerSystems

RPG Maker VX Ace - Menu Scrollbars

Nov 26th, 2014
1,738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.42 KB | None | 0 0
  1. %Q(
  2. ╔════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═════╗
  3. ║ ╔══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╗ ║
  4. ╠─╣ Menu Scrollbars ╠─╣
  5. ╠─╣ by RPG Maker Source. ╠─╣
  6. ╠─╣ www.rpgmakersource.com ╠─╣
  7. ║ ╚══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╝ ║
  8. ╠════╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═════╣
  9. ║ ┌────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────┐ ║
  10. ╠─┤ Version 1.1.0 28/11/14 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, 27/11/14 - (DD/MM/YY). ║
  45. ║ ║
  46. ║ • Version 1.0.2, 27/11/14 - (DD/MM/YY). ║
  47. ║ ║
  48. ║ • Version 1.1.0, 28/11/14 - (DD/MM/YY). ║
  49. ║ - You can now exclude some windows from the cool scrollbars club. ║
  50. ║ ║
  51. ╠══════════════════════════════════════════════════════════════════════════════╣
  52. ╠══════════════════════════════════════════════════════════════════════════════╣
  53. ║ 2. USER MANUAL. ▼ ║
  54. ╠══════════════════════════════════════════════════════════════════════════════╣
  55. ║ ║
  56. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  57. ║ │ ■ Introduction. │ ║
  58. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  59. ║ ║
  60. ║ Hello there! This script is "plug and play", you can simply insert it ║
  61. ║ into your project and it will perform flawlessly. ║
  62. ║ ║
  63. ║ This script will create neat scrollbars for any Window that can scroll ║
  64. ║ its contents. ║
  65. ║ ║
  66. ║ It is a nice detail that enhances the look of your menus. If our Smooth ║
  67. ║ Cursor script is also used, the scrollbars will move smoothly too. ║
  68. ║ ║
  69. ║ We hope you enjoy it. ║
  70. ║ ║
  71. ║ Thanks for choosing our products. ║
  72. ║ ║
  73. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  74. ║ │ ■ Configuration. │ ║
  75. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  76. ║ ║
  77. ║ Although the height of the scrollbar is automatically calculated based on ║
  78. ║ the height of the Window where it will be attached to, you can choose a ║
  79. ║ width for it. ║
  80. ║ To do so, right click anywhere in the script editor and select "Find" (or ║
  81. ║ CTRL + F), search for "WIDTH" (without quotation marks). ║
  82. ║ ║
  83. ║ You will see something like "WIDTH = 4" ║
  84. ║ ║
  85. ║ Set the number after the equality sign to any number you like, bigger or ║
  86. ║ equal than 1. ║
  87. ║ Keep in mind that the number will represent the width in pixels. ║
  88. ║ ║
  89. ║ The scrollbar is composed by a background and inside it, an inner ║
  90. ║ rectangle that represents the contents currently visible. The bigger the ║
  91. ║ inner rectangle is, the smaller number of contents that are left to be ║
  92. ║ displayed when scrolling. ║
  93. ║ You can choose the margin of that inner rectangle. To do so, right click ║
  94. ║ anywhere in the script editor and select "Find" (or CTRL + F), search for ║
  95. ║ "MARGIN" (without quotation marks). ║
  96. ║ ║
  97. ║ You will see something like "MARGIN = 4" ║
  98. ║ ║
  99. ║ Set the number after the equality sign to any number you like, bigger or ║
  100. ║ equal than 1. ║
  101. ║ Keep in mind that the margin is applied to both the X and Y axis alike. ║
  102. ║ Of course, you can also choose the color of both the background and inner ║
  103. ║ rectangle. ║
  104. ║ For the background, simply right click anywhere in the script editor and ║
  105. ║ select "Find" (or CTRL + F), search for "BACK_COLOR" (without quotation ║
  106. ║ marks). ║
  107. ║ ║
  108. ║ You will see something like "BACK_COLOR = '0 0 0 125'" ║
  109. ║ ║
  110. ║ You might be asking yourself "What is that supposed to mean?" but worry ║
  111. ║ not, my friend, because it is actually very simple: ║
  112. ║ The single quotes are used to encapsulate the color information. You can ║
  113. ║ put either RGBA values in there or HEX values. ║
  114. ║ If you want to use RGBA colors, simple leave a space after each color ║
  115. ║ value, like this: ║
  116. ║ ║
  117. ║ BACK_COLOR = 'RED GREEN BLUE ALPHA' ║
  118. ║ ║
  119. ║ The values for RED, GREEN, BLUE, and ALPHA must be numbers between 0 and ║
  120. ║ 255. ║
  121. ║ ║
  122. ║ On the other hand, if you want to use HEX codes, simply put a # (hash ║
  123. ║ character) before it, like this: ║
  124. ║ ║
  125. ║ BACK_COLOR = '#0000009B' ║
  126. ║ ║
  127. ║ Same rules apply for the inner rectangle colors, and since a gradient ║
  128. ║ fill is used, you can decide the color for the starting point and for the ║
  129. ║ ending point too: ║
  130. ║ ║
  131. ║ Search "RECT_COLOR1 =" for the starting point's color and "RECT_COLOR2" ║
  132. ║ for the ending point's color. ║
  133. ║ ║
  134. ║ "How do I exclude some Window from the effect?" ║
  135. ║ Right click anywhere in the script editor and select "Find" (or CTRL + F), ║
  136. ║ searh for "EXCLUDE" (without quotation marks). ║
  137. ║ ║
  138. ║ You will see something like: ║
  139. ║ "EXCLUDE = 'Window_NoScrollbar Window_NoScrollbarEither'" ║
  140. ║ ║
  141. ║ To exclude Windows from the effect, simply add their names between those ║
  142. ║ single quotes (the name of the class). ║
  143. ║ For example, to exclude the Item List Window: ║
  144. ║ ║
  145. ║ EXCLUDE = 'Window_ItemList Window_NoScrollbarEither' ║
  146. ║ ║
  147. ║ That's it, pretty simple, right? If you also use our Smooth Cursor, the ║
  148. ║ speed of the scrollbar movement will be automatically synchronized with ║
  149. ║ that of the cursor, to achieve a nice and homogeneous look. ║
  150. ║ ║
  151. ║ ║
  152. ╠══════════════════════════════════════════════════════════════════════════════╣
  153. ╠══════════════════════════════════════════════════════════════════════════════╣
  154. ║ 3. NOTES. ▼ ║
  155. ╠══════════════════════════════════════════════════════════════════════════════╣
  156. ║ ║
  157. ║ Have fun and enjoy! ║
  158. ║ ║
  159. ╠══════════════════════════════════════════════════════════════════════════════╣
  160. ╠══════════════════════════════════════════════════════════════════════════════╣
  161. ║ 4. CONTACT. ▼ ║
  162. ╠══════════════════════════════════════════════════════════════════════════════╣
  163. ║ ║
  164. ║ Keep in touch with us and be the first to know about new releases: ║
  165. ║ ║
  166. ║ www.rpgmakersource.com ║
  167. ║ www.facebook.com/RPGMakerSource ║
  168. ║ www.twitter.com/RPGMakerSource ║
  169. ║ www.youtube.com/user/RPGMakerSource ║
  170. ║ ║
  171. ║ Get involved! Have an idea for a system? Let us know. ║
  172. ║ ║
  173. ║ Spread the word and help us reach more people so we can continue creating ║
  174. ║ awesome resources for you! ║
  175. ║ ║
  176. ╚══════════════════════════════════════════════════════════════════════════════╝)
  177.  
  178. #==============================================================================
  179. # ** MakerSystems
  180. #------------------------------------------------------------------------------
  181. # Module four our Systems.
  182. #==============================================================================
  183.  
  184. module MakerSystems
  185.  
  186. #============================================================================
  187. # ** MenuScrollbars
  188. #----------------------------------------------------------------------------
  189. # This module contains variables that you can edit to customize the system.
  190. #============================================================================
  191.  
  192. module MenuScrollbars
  193.  
  194. #------------------------------------------------------------------------
  195. # * The width in pixels for the scrollbar. [OPT]
  196. #------------------------------------------------------------------------
  197. WIDTH = 8
  198. #------------------------------------------------------------------------
  199. # * The margin in pixels for the inner rectangle. [OPT]
  200. #------------------------------------------------------------------------
  201. MARGIN = 4
  202. #------------------------------------------------------------------------
  203. # * The color for the scrollbar's background. [OPT]
  204. #------------------------------------------------------------------------
  205. BACK_COLOR = '0 0 0 125'
  206. #------------------------------------------------------------------------
  207. # * The start color for the scrollbar's rect gradient. [OPT]
  208. #------------------------------------------------------------------------
  209. RECT_COLOR1 = '255 255 255 160'
  210. #------------------------------------------------------------------------
  211. # * The end color for the scrollbar's rect gradient. [OPT]
  212. #------------------------------------------------------------------------
  213. RECT_COLOR2 = '200 200 200 160'
  214. #------------------------------------------------------------------------
  215. # * Window classes that you don't want a scrollbar in. [OPT]
  216. #------------------------------------------------------------------------
  217. EXCLUDE = 'Window_NoScrollbar Window_NoScrollbarEither'
  218.  
  219. end
  220.  
  221. end
  222.  
  223. #==============================================================================
  224. # ** Window_Selectable
  225. #------------------------------------------------------------------------------
  226. # Alias to update, dispose, item_width & draw_all_items.
  227. # + ms_scrollbar_dispose, ms_scrollbar_check_creation, ms_scrollbar_manage.
  228. #==============================================================================
  229.  
  230. class Window_Selectable < Window_Base
  231.  
  232. #--------------------------------------------------------------------------
  233. # * Alias Update. [NEW]
  234. #--------------------------------------------------------------------------
  235. alias_method(:ms_scrollbar_original_update, :update)
  236. #--------------------------------------------------------------------------
  237. # * Update. [MOD]
  238. #--------------------------------------------------------------------------
  239. def update
  240. ms_scrollbar_original_update
  241. ms_scrollbar_manage if @ms_scrollbar_rect
  242. end
  243. #--------------------------------------------------------------------------
  244. # * Alias Dispose. [NEW]
  245. #--------------------------------------------------------------------------
  246. alias_method(:ms_scrollbar_original_dispose, :dispose)
  247. #--------------------------------------------------------------------------
  248. # * Dispose. [MOD]
  249. #--------------------------------------------------------------------------
  250. def dispose
  251. ms_scrollbar_original_dispose
  252. ms_scrollbar_dispose if @ms_scrollbar
  253. end
  254. #--------------------------------------------------------------------------
  255. # * Alias Item WIDTH. [NEW]
  256. #--------------------------------------------------------------------------
  257. alias_method(:ms_scrollbar_original_item_width, :item_width)
  258. #--------------------------------------------------------------------------
  259. # * Item WIDTH. [MOD]
  260. #--------------------------------------------------------------------------
  261. def item_width
  262. if contents_height >= self.height - standard_padding
  263. ms_scrollbar_original_item_width - MakerSystems::MenuScrollbars::WIDTH
  264. else
  265. ms_scrollbar_original_item_width
  266. end
  267. end
  268. #--------------------------------------------------------------------------
  269. # * Alias Draw All Items. [NEW]
  270. #--------------------------------------------------------------------------
  271. alias_method(:ms_scrollbar_original_draw_all_items, :draw_all_items)
  272. #--------------------------------------------------------------------------
  273. # * Draw All Items. [MOD]
  274. #--------------------------------------------------------------------------
  275. def draw_all_items
  276. ms_scrollbar_original_draw_all_items
  277. ms_scrollbar_check_creation
  278. end
  279. #--------------------------------------------------------------------------
  280. # * MS Scrollbar Management. [NEW]
  281. #--------------------------------------------------------------------------
  282. def ms_scrollbar_manage
  283. # Height difference.
  284. diff = @ms_scrollbar.bitmap.height - @ms_scrollbar_rect.bitmap.height
  285. # MARGIN for the inner rectangle x.
  286. margin = MakerSystems::MenuScrollbars::MARGIN / 2
  287. # Max height.
  288. max_height = diff - MakerSystems::MenuScrollbars::MARGIN
  289. # Inner rectangle position.
  290. i_max = [row_max - page_row_max, 1].max
  291. i_row = top_row
  292. i_row = i_max if i_row > i_max
  293. inner_pos = (i_row * max_height) / i_max
  294. # Correct visibility.
  295. if self.is_a?(Window_Command)
  296. @ms_scrollbar.visible = self.visible ? @list.size > 0 : false
  297. else
  298. if @data
  299. @ms_scrollbar.visible = self.visible ? @data.size > 0 : false
  300. end
  301. end
  302. @ms_scrollbar_rect.visible = @ms_scrollbar.visible
  303. # Set inner rectangle position & scrollbar visibility.
  304. if MakerSystems.const_defined?(:Smooth_Cursor) &&
  305. MakerSystems.const_get(:Smooth_Cursor).instance_of?(::Module)
  306. # Get speed and set target position.
  307. delay = MakerSystems::Smooth_Cursor::DELAY_LEVEL
  308. target_y = (self.y + standard_padding) + inner_pos + margin
  309. # Handle the transition to the target value.
  310. step = (target_y - @ms_scrollbar_rect.y).to_f / delay
  311. if target_y > @ms_scrollbar_rect.y
  312. @ms_scrollbar_rect.y += step.ceil
  313. else
  314. @ms_scrollbar_rect.y += step.floor
  315. end
  316. else
  317. @ms_scrollbar_rect.y = (self.y + standard_padding) + inner_pos + margin
  318. end
  319. end
  320. #--------------------------------------------------------------------------
  321. # * MS Scrollbar Creation. [NEW]
  322. #--------------------------------------------------------------------------
  323. def ms_scrollbar_check_creation
  324. # Dispose if old scrollbar.
  325. ms_scrollbar_dispose if @ms_scrollbar
  326. # Don't proceed if this Window is to be excluded.
  327. return if MakerSystems::MenuScrollbars::EXCLUDE =~ /#{self.class.name}/
  328. # If needed.
  329. if contents_height >= self.height - standard_padding
  330. # Background width & height.
  331. w = MakerSystems::MenuScrollbars::WIDTH
  332. h = self.height - standard_padding * 2
  333. # Height for the inner rectangle.
  334. ch = (contents_height - 16)
  335. rh = h - ((ch - self.height).abs * h) / ch
  336. # Colors for backbround & inner rectangle.
  337. colors = [MakerSystems::MenuScrollbars::BACK_COLOR,
  338. MakerSystems::MenuScrollbars::RECT_COLOR1,
  339. MakerSystems::MenuScrollbars::RECT_COLOR2].map! { |color|
  340. if color.include?('#')
  341. color = color.delete!('#').scan(/../).map { |c| c.to_i(16) }
  342. else
  343. color = color.split(' ').map { |c| c.to_i }
  344. end
  345. color = Color.new(*color)
  346. }
  347. # MARGIN for the inner rectangle x.
  348. margin = MakerSystems::MenuScrollbars::MARGIN
  349. # Creates background sprite & bitmap in the correct position.
  350. @ms_scrollbar = Sprite.new(self.viewport)
  351. @ms_scrollbar.bitmap = Bitmap.new(w, h)
  352. @ms_scrollbar.bitmap.fill_rect(0, 0, w, h, colors[0])
  353. @ms_scrollbar.x = self.x + self.width - standard_padding - w
  354. @ms_scrollbar.y = self.y + standard_padding
  355. @ms_scrollbar.z = self.z + 1
  356. # Creates inner rectangle sprite & bitmap in the correct position.
  357. @ms_scrollbar_rect = Sprite.new(self.viewport)
  358. margin = w - 1 if margin >= w
  359. margin = rh - 1 if margin >= rh
  360. @ms_scrollbar_rect.bitmap = Bitmap.new(w - margin, rh - margin)
  361. @ms_scrollbar_rect.bitmap.gradient_fill_rect(0, 0, w, rh, colors[1],
  362. colors[2])
  363. @ms_scrollbar_rect.bitmap.blur
  364. @ms_scrollbar_rect.x = @ms_scrollbar.x + (margin / 2)
  365. @ms_scrollbar_rect.y = @ms_scrollbar.y + (margin / 2)
  366. @ms_scrollbar_rect.z = @ms_scrollbar.z + 1
  367. end
  368. end
  369. #--------------------------------------------------------------------------
  370. # * MS Scrollbar Dispose. [NEW]
  371. #--------------------------------------------------------------------------
  372. def ms_scrollbar_dispose
  373. @ms_scrollbar.bitmap.dispose
  374. @ms_scrollbar.dispose
  375. @ms_scrollbar_rect.bitmap.dispose
  376. @ms_scrollbar_rect.dispose
  377. @ms_scrollbar = @ms_scrollbar_rect = nil
  378. end
  379.  
  380. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement