Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Q(
- ╔════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═════╗
- ║ ╔══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╗ ║
- ╠─╣ Menu Scrollbars ╠─╣
- ╠─╣ by RPG Maker Source. ╠─╣
- ╠─╣ www.rpgmakersource.com ╠─╣
- ║ ╚══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╝ ║
- ╠════╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═════╣
- ║ ┌────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────┐ ║
- ╠─┤ Version 1.1.0 28/11/14 DD/MM/YY ├─╣
- ║ └────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────┘ ║
- ╠══════╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══════╣
- ║ ║
- ║ This work is protected by the following license: ║
- ║ ╔══════════════════════════════════════════════════════════════════╗ ║
- ║ │ │ ║
- ║ │ Copyright © 2014 Maker Systems. │ ║
- ║ │ │ ║
- ║ │ This software is provided 'as-is', without any kind of │ ║
- ║ │ warranty. Under no circumstances will the author be held │ ║
- ║ │ liable for any damages arising from the use of this software. │ ║
- ║ │ │ ║
- ║ │ Permission is granted to anyone to use this software on their │ ║
- ║ │ free or commercial games made with a legal copy of RPG Maker │ ║
- ║ │ VX Ace, as long as Maker Systems - RPG Maker Source is │ ║
- ║ │ credited within the game. │ ║
- ║ │ │ ║
- ║ │ Selling this code or any portions of it 'as-is' or as part of │ ║
- ║ │ another code, is not allowed. │ ║
- ║ │ │ ║
- ║ │ The original header, which includes this copyright notice, │ ║
- ║ │ must not be edited or removed from any verbatim copy of the │ ║
- ║ │ sotware nor from any edited version. │ ║
- ║ │ │ ║
- ║ ╚══════════════════════════════════════════════════════════════════╝ ║
- ║ ║
- ║ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ 1. VERSION HISTORY. ▼ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ ║
- ║ • Version 1.0.0, 24/11/14 - (DD/MM/YY). ║
- ║ ║
- ║ • Version 1.0.1, 27/11/14 - (DD/MM/YY). ║
- ║ ║
- ║ • Version 1.0.2, 27/11/14 - (DD/MM/YY). ║
- ║ ║
- ║ • Version 1.1.0, 28/11/14 - (DD/MM/YY). ║
- ║ - You can now exclude some windows from the cool scrollbars club. ║
- ║ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ 2. USER MANUAL. ▼ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ ║
- ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
- ║ │ ■ Introduction. │ ║
- ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
- ║ ║
- ║ Hello there! This script is "plug and play", you can simply insert it ║
- ║ into your project and it will perform flawlessly. ║
- ║ ║
- ║ This script will create neat scrollbars for any Window that can scroll ║
- ║ its contents. ║
- ║ ║
- ║ It is a nice detail that enhances the look of your menus. If our Smooth ║
- ║ Cursor script is also used, the scrollbars will move smoothly too. ║
- ║ ║
- ║ We hope you enjoy it. ║
- ║ ║
- ║ Thanks for choosing our products. ║
- ║ ║
- ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
- ║ │ ■ Configuration. │ ║
- ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
- ║ ║
- ║ Although the height of the scrollbar is automatically calculated based on ║
- ║ the height of the Window where it will be attached to, you can choose a ║
- ║ width for it. ║
- ║ To do so, right click anywhere in the script editor and select "Find" (or ║
- ║ CTRL + F), search for "WIDTH" (without quotation marks). ║
- ║ ║
- ║ You will see something like "WIDTH = 4" ║
- ║ ║
- ║ Set the number after the equality sign to any number you like, bigger or ║
- ║ equal than 1. ║
- ║ Keep in mind that the number will represent the width in pixels. ║
- ║ ║
- ║ The scrollbar is composed by a background and inside it, an inner ║
- ║ rectangle that represents the contents currently visible. The bigger the ║
- ║ inner rectangle is, the smaller number of contents that are left to be ║
- ║ displayed when scrolling. ║
- ║ You can choose the margin of that inner rectangle. To do so, right click ║
- ║ anywhere in the script editor and select "Find" (or CTRL + F), search for ║
- ║ "MARGIN" (without quotation marks). ║
- ║ ║
- ║ You will see something like "MARGIN = 4" ║
- ║ ║
- ║ Set the number after the equality sign to any number you like, bigger or ║
- ║ equal than 1. ║
- ║ Keep in mind that the margin is applied to both the X and Y axis alike. ║
- ║ Of course, you can also choose the color of both the background and inner ║
- ║ rectangle. ║
- ║ For the background, simply right click anywhere in the script editor and ║
- ║ select "Find" (or CTRL + F), search for "BACK_COLOR" (without quotation ║
- ║ marks). ║
- ║ ║
- ║ You will see something like "BACK_COLOR = '0 0 0 125'" ║
- ║ ║
- ║ You might be asking yourself "What is that supposed to mean?" but worry ║
- ║ not, my friend, because it is actually very simple: ║
- ║ The single quotes are used to encapsulate the color information. You can ║
- ║ put either RGBA values in there or HEX values. ║
- ║ If you want to use RGBA colors, simple leave a space after each color ║
- ║ value, like this: ║
- ║ ║
- ║ BACK_COLOR = 'RED GREEN BLUE ALPHA' ║
- ║ ║
- ║ The values for RED, GREEN, BLUE, and ALPHA must be numbers between 0 and ║
- ║ 255. ║
- ║ ║
- ║ On the other hand, if you want to use HEX codes, simply put a # (hash ║
- ║ character) before it, like this: ║
- ║ ║
- ║ BACK_COLOR = '#0000009B' ║
- ║ ║
- ║ Same rules apply for the inner rectangle colors, and since a gradient ║
- ║ fill is used, you can decide the color for the starting point and for the ║
- ║ ending point too: ║
- ║ ║
- ║ Search "RECT_COLOR1 =" for the starting point's color and "RECT_COLOR2" ║
- ║ for the ending point's color. ║
- ║ ║
- ║ "How do I exclude some Window from the effect?" ║
- ║ Right click anywhere in the script editor and select "Find" (or CTRL + F), ║
- ║ searh for "EXCLUDE" (without quotation marks). ║
- ║ ║
- ║ You will see something like: ║
- ║ "EXCLUDE = 'Window_NoScrollbar Window_NoScrollbarEither'" ║
- ║ ║
- ║ To exclude Windows from the effect, simply add their names between those ║
- ║ single quotes (the name of the class). ║
- ║ For example, to exclude the Item List Window: ║
- ║ ║
- ║ EXCLUDE = 'Window_ItemList Window_NoScrollbarEither' ║
- ║ ║
- ║ That's it, pretty simple, right? If you also use our Smooth Cursor, the ║
- ║ speed of the scrollbar movement will be automatically synchronized with ║
- ║ that of the cursor, to achieve a nice and homogeneous look. ║
- ║ ║
- ║ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ 3. NOTES. ▼ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ ║
- ║ Have fun and enjoy! ║
- ║ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ 4. CONTACT. ▼ ║
- ╠══════════════════════════════════════════════════════════════════════════════╣
- ║ ║
- ║ Keep in touch with us and be the first to know about new releases: ║
- ║ ║
- ║ www.rpgmakersource.com ║
- ║ www.facebook.com/RPGMakerSource ║
- ║ www.twitter.com/RPGMakerSource ║
- ║ www.youtube.com/user/RPGMakerSource ║
- ║ ║
- ║ Get involved! Have an idea for a system? Let us know. ║
- ║ ║
- ║ Spread the word and help us reach more people so we can continue creating ║
- ║ awesome resources for you! ║
- ║ ║
- ╚══════════════════════════════════════════════════════════════════════════════╝)
- #==============================================================================
- # ** MakerSystems
- #------------------------------------------------------------------------------
- # Module four our Systems.
- #==============================================================================
- module MakerSystems
- #============================================================================
- # ** MenuScrollbars
- #----------------------------------------------------------------------------
- # This module contains variables that you can edit to customize the system.
- #============================================================================
- module MenuScrollbars
- #------------------------------------------------------------------------
- # * The width in pixels for the scrollbar. [OPT]
- #------------------------------------------------------------------------
- WIDTH = 8
- #------------------------------------------------------------------------
- # * The margin in pixels for the inner rectangle. [OPT]
- #------------------------------------------------------------------------
- MARGIN = 4
- #------------------------------------------------------------------------
- # * The color for the scrollbar's background. [OPT]
- #------------------------------------------------------------------------
- BACK_COLOR = '0 0 0 125'
- #------------------------------------------------------------------------
- # * The start color for the scrollbar's rect gradient. [OPT]
- #------------------------------------------------------------------------
- RECT_COLOR1 = '255 255 255 160'
- #------------------------------------------------------------------------
- # * The end color for the scrollbar's rect gradient. [OPT]
- #------------------------------------------------------------------------
- RECT_COLOR2 = '200 200 200 160'
- #------------------------------------------------------------------------
- # * Window classes that you don't want a scrollbar in. [OPT]
- #------------------------------------------------------------------------
- EXCLUDE = 'Window_NoScrollbar Window_NoScrollbarEither'
- end
- end
- #==============================================================================
- # ** Window_Selectable
- #------------------------------------------------------------------------------
- # Alias to update, dispose, item_width & draw_all_items.
- # + ms_scrollbar_dispose, ms_scrollbar_check_creation, ms_scrollbar_manage.
- #==============================================================================
- class Window_Selectable < Window_Base
- #--------------------------------------------------------------------------
- # * Alias Update. [NEW]
- #--------------------------------------------------------------------------
- alias_method(:ms_scrollbar_original_update, :update)
- #--------------------------------------------------------------------------
- # * Update. [MOD]
- #--------------------------------------------------------------------------
- def update
- ms_scrollbar_original_update
- ms_scrollbar_manage if @ms_scrollbar_rect
- end
- #--------------------------------------------------------------------------
- # * Alias Dispose. [NEW]
- #--------------------------------------------------------------------------
- alias_method(:ms_scrollbar_original_dispose, :dispose)
- #--------------------------------------------------------------------------
- # * Dispose. [MOD]
- #--------------------------------------------------------------------------
- def dispose
- ms_scrollbar_original_dispose
- ms_scrollbar_dispose if @ms_scrollbar
- end
- #--------------------------------------------------------------------------
- # * Alias Item WIDTH. [NEW]
- #--------------------------------------------------------------------------
- alias_method(:ms_scrollbar_original_item_width, :item_width)
- #--------------------------------------------------------------------------
- # * Item WIDTH. [MOD]
- #--------------------------------------------------------------------------
- def item_width
- if contents_height >= self.height - standard_padding
- ms_scrollbar_original_item_width - MakerSystems::MenuScrollbars::WIDTH
- else
- ms_scrollbar_original_item_width
- end
- end
- #--------------------------------------------------------------------------
- # * Alias Draw All Items. [NEW]
- #--------------------------------------------------------------------------
- alias_method(:ms_scrollbar_original_draw_all_items, :draw_all_items)
- #--------------------------------------------------------------------------
- # * Draw All Items. [MOD]
- #--------------------------------------------------------------------------
- def draw_all_items
- ms_scrollbar_original_draw_all_items
- ms_scrollbar_check_creation
- end
- #--------------------------------------------------------------------------
- # * MS Scrollbar Management. [NEW]
- #--------------------------------------------------------------------------
- def ms_scrollbar_manage
- # Height difference.
- diff = @ms_scrollbar.bitmap.height - @ms_scrollbar_rect.bitmap.height
- # MARGIN for the inner rectangle x.
- margin = MakerSystems::MenuScrollbars::MARGIN / 2
- # Max height.
- max_height = diff - MakerSystems::MenuScrollbars::MARGIN
- # Inner rectangle position.
- i_max = [row_max - page_row_max, 1].max
- i_row = top_row
- i_row = i_max if i_row > i_max
- inner_pos = (i_row * max_height) / i_max
- # Correct visibility.
- if self.is_a?(Window_Command)
- @ms_scrollbar.visible = self.visible ? @list.size > 0 : false
- else
- if @data
- @ms_scrollbar.visible = self.visible ? @data.size > 0 : false
- end
- end
- @ms_scrollbar_rect.visible = @ms_scrollbar.visible
- # Set inner rectangle position & scrollbar visibility.
- if MakerSystems.const_defined?(:Smooth_Cursor) &&
- MakerSystems.const_get(:Smooth_Cursor).instance_of?(::Module)
- # Get speed and set target position.
- delay = MakerSystems::Smooth_Cursor::DELAY_LEVEL
- target_y = (self.y + standard_padding) + inner_pos + margin
- # Handle the transition to the target value.
- step = (target_y - @ms_scrollbar_rect.y).to_f / delay
- if target_y > @ms_scrollbar_rect.y
- @ms_scrollbar_rect.y += step.ceil
- else
- @ms_scrollbar_rect.y += step.floor
- end
- else
- @ms_scrollbar_rect.y = (self.y + standard_padding) + inner_pos + margin
- end
- end
- #--------------------------------------------------------------------------
- # * MS Scrollbar Creation. [NEW]
- #--------------------------------------------------------------------------
- def ms_scrollbar_check_creation
- # Dispose if old scrollbar.
- ms_scrollbar_dispose if @ms_scrollbar
- # Don't proceed if this Window is to be excluded.
- return if MakerSystems::MenuScrollbars::EXCLUDE =~ /#{self.class.name}/
- # If needed.
- if contents_height >= self.height - standard_padding
- # Background width & height.
- w = MakerSystems::MenuScrollbars::WIDTH
- h = self.height - standard_padding * 2
- # Height for the inner rectangle.
- ch = (contents_height - 16)
- rh = h - ((ch - self.height).abs * h) / ch
- # Colors for backbround & inner rectangle.
- colors = [MakerSystems::MenuScrollbars::BACK_COLOR,
- MakerSystems::MenuScrollbars::RECT_COLOR1,
- MakerSystems::MenuScrollbars::RECT_COLOR2].map! { |color|
- if color.include?('#')
- color = color.delete!('#').scan(/../).map { |c| c.to_i(16) }
- else
- color = color.split(' ').map { |c| c.to_i }
- end
- color = Color.new(*color)
- }
- # MARGIN for the inner rectangle x.
- margin = MakerSystems::MenuScrollbars::MARGIN
- # Creates background sprite & bitmap in the correct position.
- @ms_scrollbar = Sprite.new(self.viewport)
- @ms_scrollbar.bitmap = Bitmap.new(w, h)
- @ms_scrollbar.bitmap.fill_rect(0, 0, w, h, colors[0])
- @ms_scrollbar.x = self.x + self.width - standard_padding - w
- @ms_scrollbar.y = self.y + standard_padding
- @ms_scrollbar.z = self.z + 1
- # Creates inner rectangle sprite & bitmap in the correct position.
- @ms_scrollbar_rect = Sprite.new(self.viewport)
- margin = w - 1 if margin >= w
- margin = rh - 1 if margin >= rh
- @ms_scrollbar_rect.bitmap = Bitmap.new(w - margin, rh - margin)
- @ms_scrollbar_rect.bitmap.gradient_fill_rect(0, 0, w, rh, colors[1],
- colors[2])
- @ms_scrollbar_rect.bitmap.blur
- @ms_scrollbar_rect.x = @ms_scrollbar.x + (margin / 2)
- @ms_scrollbar_rect.y = @ms_scrollbar.y + (margin / 2)
- @ms_scrollbar_rect.z = @ms_scrollbar.z + 1
- end
- end
- #--------------------------------------------------------------------------
- # * MS Scrollbar Dispose. [NEW]
- #--------------------------------------------------------------------------
- def ms_scrollbar_dispose
- @ms_scrollbar.bitmap.dispose
- @ms_scrollbar.dispose
- @ms_scrollbar_rect.bitmap.dispose
- @ms_scrollbar_rect.dispose
- @ms_scrollbar = @ms_scrollbar_rect = nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement