Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrolling help window
#1
Scrolling help window
by Jimmie
Apr 8 2009

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


[Image: gallery_543_2_34059.png]
(It's the one at the bottom, in case you missed it)

The screenshot pretty much explains itself. This is a window to which you pass the possible commands a player can perform. The window then shows the commands, scrolling if there is not enough space to show them all.

Details
The window uses icons to display the buttons. When you tell the window what commands to display, you send the icon names together with the description like so:

Code:
@c_window.set_commands(["CButton", "BButton", "AllArrows", ["LButton", "RButton"]], ["Select item", "Back to menu", "Navigate", "Change character"])

(These are the commands shown in the screenshot. Note that "Change character" has two buttons assigned to it.)
Of course, icons should be in your icons folder.

Installing
Copy the code below into a new script slot above Main. Replace the window skin name on line 10 with the name of one you have. Then in any scene in which you want a help window, you'll have to do a few things.
  1. Create the window using @aHelpWindow = Window_Scrolling_Help.new(x, y, width, height)
  2. Assign commands to the window with @aHelpWindow.set_commands(icons, text)
  3. Update the window every frame using @aHelpWindow.update
  4. Dispose the window when the scene closes using @aHelpWindow.dispose
That should be everything you need to use the window. Of course, remember to move/shrink other windows so that there is room for this one.
x, y, width and height can be left out when callin #new. They will default to 0, 448, 640 and 32 respectively.


Code:
# By Nitt aka jimme reashu
# Can't be bothered to make a proper header for this. I've an item suite to write!
# Version 1.0.0  9 April 2009
class Window_Scrolling_Help < Window_Base
  ICON_SIZE = 18
  
  def initialize(x = 0, y = 448, width = 640, height = 32)
    super(x-8, y - 16, width + 16, height + 32)
    @dummy = Window_Base.new(x, y, width, height)
    @dummy.windowskin = RPG::Cache.windowskin("002-Gray01")
    self.windowskin = nil
    @dummy.z = 1000
    self.z = 1001
  end
  
  def set_commands(icons, text)
    for i in 0...icons.size
      if icons[i].is_a?(String)
        icons[i] = [icons[i]]
      end
    end
    
    fulltext = ""
    text.each{|a|fulltext << a}
    iconnumber = 0
    icons.each{|a|iconnumber += a.size}
    test_bitmap = Bitmap.new(1,1)
    textwidth = test_bitmap.text_size(fulltext).width
    fullwidth = textwidth + (ICON_SIZE + 4) * iconnumber + text.size * 32
    if fullwidth > self.width - 32
      self.contents = Bitmap.new(fullwidth * 2 + 64, self.height - 32)
      draw_commands(0, icons, text)
      draw_commands(fullwidth + 64, icons, text)
      
      self.ox = -96
    else
      self.contents = Bitmap.new(self.width - 32, self.height - 32)
      draw_commands((self.contents.width - fullwidth)/2, icons, text)
      self.ox = 0
    end
  
  end
  
  def draw_commands(x, icons, text)
    for i in 0...icons.size
      for j in 0...icons[i].size
        self.contents.blt(x, ((self.height - 32) - ICON_SIZE)/2, RPG::Cache.icon(icons[i][j]), Rect.new(0, 0, ICON_SIZE, ICON_SIZE))
        x += ICON_SIZE + 4
      end
      self.contents.draw_text(x, 0, self.contents.width, self.height - 32, text[i])
      x += self.contents.text_size(text[i]).width + 32
    end
  end
        
  def update
    if self.contents.width > self.width - 32
      self.ox += 1
      if self.ox == self.contents.width/2
        self.ox = -32
      end
    end
  end
  
  def dispose
    @dummy.dispose
    super
  end
  
end


Caution
This window was not designed to be moved around after creation. If it is, the background will be left behind. If you want this functionality, let me know and I'll add it.

Resources
Here are the icons and window skin I used, in case you want them:

.zip   Icons.zip (Size: 7.24 KB / Downloads: 1)

[Image: gallery_543_2_2228.png]


[i]Good luck, have fun!
//Nitt
}




Users browsing this thread: