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 = 3 # seconds
@@SCROLL_SPEED = 1 # pixels / frame (60 frames / sec)
@@SHOW_ICONS = true # display icons for items and skills?
alias :pre_scrolling_initialize :initialize
def initialize
pre_scrolling_initialize
@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)
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
if ((i = get_icon_index(text)) != 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
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
for item in $data_items
return item.icon_index if !item.nil? && item.description == desc
end
for skill in $data_skills
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