Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[VX] Scroll Bar

Scroll Bar
by Dargor
Version 1.3


Introduction

This little piece of code will display a scroll bar on the right side of any selectable window with more than 1 row.

Screenshots

That's all!

Script

Code:
#==============================================================================

# ** Scroll Bar

#------------------------------------------------------------------------------

#  © Dargor, 2008

#  27/06/08

#  Version 1.3

#------------------------------------------------------------------------------

#  VERSION HISTORY:

#   - 1.0 (26/05/08), Initial release

#   - 1.1 (24/06/08), Prevent the Stack error

#   - 1.2 (27/06/08), Added an option for Z-axis correction

#   - 1.3 (27/06/08), Added an option to improve compatibility with RPGXP

#------------------------------------------------------------------------------

#  INSTRUCTIONS:

#   - Paste this above main

#   - Edit the constants in Scroll_Bar module

#==============================================================================

 

#==============================================================================

# ** Scroll Bar Customization Module

#==============================================================================

module Scroll_Bar

  # Scroll Bar back color

  Back_Color = Color.new(0,0,0)

  # Scroll Bar color

  Bar_Color = Color.new(28,64,255)

  # Use Z-axis correction 

  # (creates a new viewport for windows above a Scroll Bar)

  Z_Correction = true

  # Minimum viewport Z-axis

  Minimum_Z = 100

  # Used in RPG Maker XP

  XP = false

end

 

#==============================================================================

# ** Window_Base

#------------------------------------------------------------------------------

#  This is a superclass of all windows in the game.

#==============================================================================

 

class Window_Base < Window

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  alias dargor_vx_scrollbar_window_base_initialize initialize

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize(*args)

    dargor_vx_scrollbar_window_base_initialize(*args)

    if Scroll_Bar::Z_Correction && !Scroll_Bar::XP

      self.viewport = Viewport.new(0,0,Graphics.width,Graphics.height)

      self.viewport.z = Scroll_Bar::Minimum_Z

    end

  end

end

 

#==============================================================================

# ** Window_Selectable

#------------------------------------------------------------------------------

#  This window contains cursor movement and scroll functions.

#==============================================================================

 

class Window_Selectable < Window_Base

  #--------------------------------------------------------------------------

  # * Alias Listing

  #--------------------------------------------------------------------------

  if @scroll_bar_stack.nil?

    alias dargor_vx_scrollbar_window_selectable_update update

    alias dargor_vx_scrollbar_window_selectable_dispose dispose

    @scroll_bar_stack = true

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # The usual

    dargor_vx_scrollbar_window_selectable_update

    # return if row_max = 0

    return if row_max <= 1

    # Create bar rect

    draw_scroll_bar

  end

  #--------------------------------------------------------------------------

  # * Draw Scroll Bar

  #--------------------------------------------------------------------------

  def draw_scroll_bar

    # Setup colors

    back_color = Scroll_Bar::Back_Color

    bar_color = Scroll_Bar::Bar_Color

    # Setup Rect

    bar_width = 4

    bar_height = (self.height - 32) / row_max

    bar_y = ((self.index / @column_max) * bar_height)

    loss = (self.height - 32) - ((@item_max * bar_height) / @column_max)

    loss = loss.to_f / @item_max.to_f

    bar_y += self.index * loss

    bar_x = self.x + self.contents.width - bar_width + 8

    # Create Bar Window

    if @bar_window != nil

      @bar_window.dispose

      @bar_window = nil

      @bar_window = Window_Base.new(bar_x,self.y,48,self.height)

    else

      @bar_window = Window_Base.new(bar_x,self.y,48,self.height)

      @bar_window.contents_opacity = 0

    end

    # Set Bar Window Attributes

    @bar_window.contents_opacity += 32

    @bar_window.opacity = 0

    unless Scroll_Bar::XP

      @bar_window.openness = self.openness

      @bar_window.viewport = self.viewport

    end

    @bar_window.visible = self.visible

    @bar_window.x = bar_x + 7

    @bar_window.y = self.y

    @bar_window.z = self.z

    @bar_window.height = self.height

    @bar_window.contents = Bitmap.new(@bar_window.width - 32, @bar_window.height - 32)

    @bar_window.contents_opacity = self.opacity if Scroll_Bar::XP

    # Create bar rectangles

    back_rect = Rect.new(0,0,bar_width,self.height - 32)

    bar_rect  = Rect.new(0,bar_y,bar_width,bar_height)

    # Draw Bars

    @bar_window.contents.fill_rect(back_rect, back_color)

    @bar_window.contents.fill_rect(bar_rect, bar_color)

    for i in 0...bar_width

      x = i

      i_rect = Rect.new(x,0,1,i)

      @bar_window.contents.fill_rect(i_rect, Color.new(0,0,0,0))

      y = back_rect.height - i

      i_rect = Rect.new(x,y,1,i)

      @bar_window.contents.fill_rect(i_rect, Color.new(0,0,0,0))

    end

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    dargor_vx_scrollbar_window_selectable_dispose

    @bar_window.dispose if @bar_window != nil

  end

end

 

Notes

The script does NOT requires my Custom Commands script!!! XD

-Dargor
 
@Sir Lord Biowulve
Simply remove these 2 lines and it will work under XP.
Code:
@bar_window.openness = self.openness
    @bar_window.viewport = self.viewport
 
Sorry if this is a necropost, but..

Would it be possible to make it so the scrollbar's "Z" axis goes behind any windows that come in front of it? I ask, cause with some of the scripts I'm using it puts that scroll bar over text and windows. Was just curious if it could be set to be behind windows.
 
I understand that. But if what I'm getting here is correct, this is only for the Show Choices event command, and in eventing, you are not capable of having more than 4(?) choices, so how exactly would this let you do that? Hope I'm making sense here, I usually don't. :tongue:
  -KRoP
 
I noticed a glitch.  When you press F12 to return back to the start screen and click new game (I'm not sure with continue), You get the following error...
Code:
Script 'scroll bar' line 96: SystemStackError Occurred.

stack level to deep
 
its called the 'most annoying problem in the world' glitch... when you press F12 (usually when you are using aliases and it tries to alias the same thing twice) it will error because the game isnt compeltely reset so to speak... in other words you can make a few edits to make it do something else when reset... but you cant truly remove the reset function therefore its still annoying...
 
@van helblaze 
It has been fixed.

@mechacrash
The Reset Exception is a real bitch. You can avoid System Stack errors by putting your aliases into an if statement like that
Code:
if @stack_variable.nil?
  alias new_method old_method
  @stack_variable = true
end
Besides that, you can force the Reset Exception to close the game instead of "reseting" the game or clear the current executable and call a new one using Thread.new. There's a couple of methods but you're right, it really annoying.
 
i do as such in main:
class Reset < Exception
end
begin
#blablabla
rescue Reset
  Thread.new{system('Game.exe')}
end

and that pretty much fixes it... i have other, better methods but i dont know them off my head and they're made specifically for my errorlogger and for pure ruby... so they may not work in rmxp
 
psiclone":20dp4ene said:
Sorry if this is a necropost, but..

Would it be possible to make it so the scrollbar's "Z" axis goes behind any windows that come in front of it? I ask, cause with some of the scripts I'm using it puts that scroll bar over text and windows. Was just curious if it could be set to be behind windows.

Bumping my question, since you didn't catch it..
 
I agree this is extremely nice eye candy, especially in games with lots of different scenes, and choice windows. Very nice job :smile:! Though, this isn't that bad of a bug, I am using XP, and I have UCoders Message System: http://rmxp.org/forums/index.php?topic=36265.0. The error is that I have four choices in one window, and then I selected one choice which led to a new two choice window, and whenever I exit the two choice window by the back key (default ESC), or select a choice which leads out of all message windows I appear with this wierd map scrollbar:

http://img166.imageshack.us/img166/6822/scrollbarerrorqk0.th.jpg[/img]. I find this very wierd, could you please find out for me what is wrong, and help fix it? Don't worry about the other stuff on the screen other than the map, that's my HUD, and if you look into the bottom, right hand corner you will see the back scrollbar image with no scrollbar. Please help me solve this compatibility issue.
 
I have updated the script to version 1.3

I have added an option to automatically correct the Z-axis bug and an option to improve compatibility with RPG Maker XP.
The Z correction feature will not work under XP.
 
So basically, the script snippet fix that will fix the compatibility issue between this, and UCoders Message System is in RGSS2?

EDIT: Wait sorry for the above, you weren't even talking about that error, could you please help me fix it, it's in the post above your last post.
 
Two things.

1) Thanks for addressing the z-axis of the scroll bar, Dargor, it works like a charm. However...

2) There is a slightly major problem with GubiD's Tactical Battle System. Whenever you select an action in combat, the menu that has choices for attack/move/etc, leaves behind the scrollbar on the map, even when the battle is over, and it never disappears until the next menu appears, then it just makes a new scroll bar to leave behind.

The script I'm using currently in my game is, as of yet, unedited from his post.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top