Scrolling Window Help

Started by PrinceEndymion88, August 16, 2014, 06:45:03 pm

Previous topic - Next topic

PrinceEndymion88

Hi guys, I've found this script for Rpg MakerVX, someone know if exist something similar for Rpg Maker XP or maybe is possible to convert it?
class Sprite

  def draw_icon(icon_index, x, y, enabled = true)
bitmap = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
self.bitmap.blt(x, y, bitmap, rect, enabled ? 255 : 128)
  end

end

class Window_Help < Window_Base

  @@SCROLL_DELAY = 2  # seconds
  @@SCROLL_SPEED = 1  # pixels / frame (60 frames / sec)
  @@SHOW_ICONS   = true  # display icons for items and skills?

  alias :scroll_init :initialize
  def initialize(*args)
scroll_init(*args)
@internal_frame_count = 0
@text_is_long = false
@icon_sprite = Sprite.new
@icon_sprite.x = self.x + 16
@icon_sprite.y = self.y + 16
@icon_sprite.z = self.z + 1
@icon_sprite.bitmap = Bitmap.new(32, 32)
self.windowskin = get_altered_skin
  end

  def get_altered_skin
default = Cache.system('Window')
window = Bitmap.new(default.width, default.height)
window.blt(0, 0, default, default.rect)
window.fill_rect(80, 16, 32, 32, Color.new(0,0,0,0))
return window
  end

  def set_text(text, align = 0)
unless (text == @text) && (align == @align)
@internal_frame_count = 0
txt_width = self.contents.text_size(text).width
@text_is_long = txt_width > (self.width - 32) 
self.contents.dispose
w = @text_is_long ? (txt_width + self.width - 32) : self.width - 32
self.contents = Bitmap.new(w, self.height - 32)
self.contents.clear 
self.ox = 0
self.contents.font.color = normal_color
i = get_icon_index(text)
unless i.nil?
draw_sprite(i, 0, 0)
self.contents.draw_text(32, 0, self.contents.width, WLH, text, align)
else
@icon_sprite.bitmap.clear
self.contents.draw_text(4, 0, self.contents.width, WLH, text, align)
end
@text = text
@align = align
end
  end

  def draw_sprite(icon_index, x, y)
@icon_sprite.bitmap.clear
# get the background image at 'rect'
# so that text does not appear under the icon
bitmap = Graphics.snap_to_bitmap
rect = Rect.new(@icon_sprite.x, @icon_sprite.x,
@icon_sprite.bitmap.width, @icon_sprite.bitmap.height)
@icon_sprite.bitmap.blt(x, y, bitmap, rect)
@icon_sprite.draw_icon(icon_index, x, y)
  end

  def get_icon_index(desc)
return nil unless @@SHOW_ICONS
$data_items.each do |item|
return item.icon_index if !item.nil? && item.description == desc
end
$data_weapons.each do |weapon|
return weapon.icon_index if !weapon.nil? && weapon.description == desc
end
$data_armors.each do |armor|
return armor.icon_index if !armor.nil? && armor.description == desc
end
$data_skills.each do |skill|
return skill.icon_index if !skill.nil? && skill.description == desc
end
return nil
  end

  def update
super
@internal_frame_count += 1
if ((@internal_frame_count > @@SCROLL_DELAY * 60) && @text_is_long)
if self.ox >= (self.contents.width - self.width + 48)
self.ox = 0
@internal_frame_count = 0
else
self.ox += @@SCROLL_SPEED
end
end
  end

  def dispose
super
@icon_sprite.dispose
  end

end

ForeverZer0

A picture would be better than a script. As for "converting" it, its more like just making an XP version, not conversion, so the original script is kinda worthless. A picture shows what you want much better.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

PrinceEndymion88

Description
Scrolls the help window for long descriptions.




PrinceEndymion88

August 17, 2014, 12:20:16 pm #4 Last Edit: August 17, 2014, 12:22:47 pm by PrinceEndymion88
I've tried it but it seems doesn't work! And sometimes it goes in conflict with Sfont script! mmmmh...
#=============================================================================
# * SFonts
#=============================================================================
# Trickster
# Version 1.0
# 12.19.07
#=============================================================================
# Introduction
#  - This script adds SFont support for rmxp. An sfont is a image file with
#    characters already drawn onto it. The top row of pixels in this image shows
#    where the characters are and where the breaks are.
# Setting up images
#  - The top left hand pixel (0, 0) is the skip color and tells if a column
#    of pixels is empty or contain data
#  - Images should be placed in Graphics/SFonts
#  - For more reference see the example image Arial_Text
# To Use
#  - You can use this script in one of two ways
#    - 1) Set <Bitmap>.sfont to an SFont object then call <Bitmap>.draw_text
#    - 2) Call <SFont>.render(<String>) and then blt it to a Bitmap object
# Documentation
#  - SFont.new(<String/Bitmap>, <Array>, <Integer/String>)
#  - Where the first parameter is a filename (in Graphics/SFonts) or a Bitmap
#     object containing the Font data
#  - the second parameter is an Array of all of the characters in order in the
#    file the default is specified in @@glyphs below you
#  - the last parameter is either the width that should be used for the space
#    character or the character whose width you want to use for the space
#    character the default is " which is the width of the " character if "
#    character is not in the glyph then the height of the bitmap will be used
# Credits
#  - John Croisant for the original code for Rubygame which I used as a base for
#    this script
#  - Adam Bedore for the example sfont image more of his sfont work is given
#    here - http://www.zlurp.com/irq/download.html
# Websites
#  - Official SFont Page with sample fonts - http://www.linux-games.com/sfont
#  - SFont generator utility - http://www.nostatic.org/sfont
#  - SFont generator script for GIMP by Roger Feese
#       http://www.nostatic.org/sfont/render-sfont22.scm
#=============================================================================

module RPG
module Cache
  #--------------------------------------------------------------------------
  # * SFont Load
  #--------------------------------------------------------------------------
  def self.sfont(file)
    self.load_bitmap("Graphics/SFonts/", file)
  end
end
end

class SFont
  #--------------------------------------------------------------------------
  # * Class Variables
  #--------------------------------------------------------------------------
  @@glyphs = [
    "!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0",
    "1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@",
    "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
    "Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`",
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
    "q","r","s","t","u","v","w","x","y","z","{","|","}","~","∞",
    ]
  #--------------------------------------------------------------------------
  # * Get Glyphs
  #--------------------------------------------------------------------------
  def SFont.glyphs
    return @@glyphs
  end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(file, glyphs = @@glyphs, space = '"')
    if file.is_a?(String)
      bitmap = RPG::Cache.sfont(file)
    elsif file.is_a?(Bitmap)
      bitmap = file
    else
      raise(ArgumentError, "File Must be a String or Bitmap")
    end
   
    @height = bitmap.height
    @skip = bitmap.get_pixel(0, 0)
    @glyphs = {}
   
    x = 2
    glyphs.each {|char| x = load_glyph(bitmap, char, x)}
   
    unless glyphs.include?(' ')
      if space.is_a?(Numeric)
        space = space.to_i
      elsif space.is_a?(String)
        if glyphs.include?(space)
          space = @glyphs[space].width
        elsif !@glyphs['"'].nil?
          space = @glyphs['"'].width
        else
          space = bitmap.height
        end
      else
        raise(ArgumentError, "Space must be either a String or Numeric")
      end
      @glyphs[" "] = Bitmap.new(space, @height)
    end
    @glyphs.default = @glyphs[" "]
  end
  #--------------------------------------------------------------------------
  # * Text Size
  #--------------------------------------------------------------------------
  def text_size(text)
    width = 0
    text.each_byte {|byte| width += @glyphs["%c" % byte].width}
    return width
  end
  #--------------------------------------------------------------------------
  # * Render
  #--------------------------------------------------------------------------
  def render(text)
    width = text_size(text)
    bitmap = Bitmap.new(width, @height)
    x = 0
    text.each_byte do |byte|
      glyph = @glyphs["%c" % byte]
      bitmap.blt(x, 0, glyph, glyph.rect)
      x += glyph.width
    end
    return bitmap
  end
  #--------------------------------------------------------------------------
  # * Private: Load glyph
  #--------------------------------------------------------------------------
  private
  def load_glyph(bitmap, char, xi)
    while bitmap.get_pixel(xi, 0) == @skip && xi < bitmap.width
      xi += 1
    end
    return -1 if xi >= bitmap.width
    xf = xi
    while bitmap.get_pixel(xf, 0) != @skip && xf < bitmap.width
      xf += 1
    end
    return -1 if xf >= bitmap.width
   
    rect = Rect.new(xi, 0, xf - xi, bitmap.height)
    @glyphs[char] = Bitmap.new(xf - xi, bitmap.height)
    @glyphs[char].blt(0, 0, bitmap, rect)
   
    return xf+1
  end
end