class Sprite_IconScroll < Sprite_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def initialize(viewport, x, y, width, icons = [], icon_hues = [], turns = [])
super(viewport)
@last_paused_ox = 0
@scroll_pause_time = MASIS_SCROLL_SETTINGS[:pause_time]
reset(x, y, width, icons, icon_hues, turns)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Scroll
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def update_scroll
# If flashing through all icons
if MASIS_SCROLL_SETTINGS[:scroll_speed] == 0
self.src_rect.x += self.src_rect.width # Go to the next set of icons
@scroll_pause_time = MASIS_SCROLL_SETTINGS[:pause_time] # Reset pause
self.src_rect.x = 0 if self.src_rect.x >= bitmap.width
elsif MASIS_SCROLL_SETTINGS[:scroll_speed] <= 24
self.src_rect.x += MASIS_SCROLL_SETTINGS[:scroll_speed]
if self.src_rect.x >= @last_paused_ox + 24 # Make sure stops on an icon
# If at the point where repeating original icons, reset src_rect.x
self.src_rect.x = (@last_paused_ox + 24) % @restart_x
@last_paused_ox = self.src_rect.x
@scroll_pause_time = MASIS_SCROLL_SETTINGS[:pause_time] # Reset pause
end
else
self.src_rect.x += MASIS_SCROLL_SETTINGS[:scroll_speed]
@scroll_pause_time = MASIS_SCROLL_SETTINGS[:pause_time] # Reset pause
self.src_rect.x %= @restart_x
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Reset
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def reset(x, y, width, icons = [], icon_hues = [], turns = [])
self.x = x
self.y = y
@restart_x = icons.size*24
src_x = src_rect.x if src_rect
# Only create the icons buffer if not on Flash All mode.
w = MASIS_SCROLL_SETTINGS[:scroll_speed] == 0 ? 0 : width
bitmap.dispose if bitmap
self.bitmap = Bitmap.new(@restart_x + w, 24)
# Remember point at which to reset the src_rect
src_rect.set(src_x ? src_x % @restart_x : 0, 0, width, 24)
draw_bitmap(icons, icon_hues, turns)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Bitmap
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def draw_bitmap(icons, icon_hues = [], turns = [])
# Unless it is simply flashing through each row
if MASIS_SCROLL_SETTINGS[:scroll_speed] != 0
# Create a buffer so that it can smoothly scroll
icons += icons[0, viewport.rect.width / 24]
icon_hues += icon_hues[0, viewport.rect.width / 24] unless icon_hues.empty?
turns = turns + turns
end
# Draw all icons
icons.each_with_index {|n, i|
if icon_hues.size > 0 # Icon Hue Compatibility
draw_icon_with_hue(n, icon_hues.shift, i*24, 0, turns[i])
else
draw_icon(n, i*24, 0, turns[i])
end
}
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Icon (copied from the default Window_Base method)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def draw_icon(icon_index, x, y, turn)
iconset = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
bitmap.blt(x, y, iconset, rect, 255)
if turn != nil && turn >= 1
img = Cache.system("Turns")
rect = Rect.new(turn * 24, 0, 24, 24)
bitmap.blt(x, y, img, rect, 255)
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Icon With Hue (Icon Hue Compatibility)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def draw_icon_with_hue(icon_index, icon_hue, x, y, turn)
iconset = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
# Draw Icon onto small and independent bitmap
icon_bmp = Bitmap.new(24, 24)
icon_bmp.blt(0, 0, iconset, rect)
icon_bmp.hue_change(icon_hue) # Change hue of icon
if turn != nil && turn >= 1
img = Cache.system("Turns")
rect = Rect.new(turn * 24, 0, 24, 24)
icon_bmp.blt(0, 0, img, rect)
end
rect.x, rect.y = 0, 0
bitmap.blt(x, y, icon_bmp, rect, 255)
icon_bmp.dispose # Dispose Icon Bitmap
end
end
class Window_Base
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Draw Actor Icons
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def draw_actor_icons(actor, x, y, width = 96, *args)
icons = (actor.state_icons + actor.buff_icons)
if @iconscroll_sprites
@iconscroll_sprites.each_pair {|key, val|
dispose_icon_scroll_sprites(key) if val.x == x && val.y == y }
end
# If icons exceed the space given and this window enables state scroll
if (width / 24) < icons.size && @iconscroll_sprites
w = (width / 24) * 24
icon_hues = []
if $imported[:MAIcon_Hue] # Icon Hue Compatibility
for state in actor.states
icon_hues.push(state.icon_hue) if state.icon_index != 0
end
end
turns = get_icon_turns(actor, icons)
if @iconscroll_sprites[actor.object_id]
@iconscroll_sprites[actor.object_id].reset(x, y, w, icons, icon_hues, turns)
else
dispose_icon_scroll_sprites(actor.object_id) if @iconscroll_sprites[actor.object_id]
@iconscroll_sprites[actor.object_id] = Sprite_IconScroll.new(@iconscroll_viewport, x, y, w, icons, icon_hues, turns)
end
else # Otherwise, resort to default method
dispose_icon_scroll_sprites(actor.object_id) if @iconscroll_sprites[actor.object_id]
masis_drwactoric_4jv3(actor, x, y, width, *args) # Run Original Method
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * state turns
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def get_icon_turns(actor, icons)
turns = []
for state in actor.states
next if state.icon_index <= 0
turn = actor.state_turns(state.id).to_i
if $imported["YEA-FieldStateEffects"] &&
BattleManager.field_state?(state.id)
turn = BattleManager.field_state_turns(state.id)
end
icons.each_with_index { |ic, i|
turns[i] = turn if ic == state.icon_index
}
end
for i in 0...8
next if actor.buff_icon_index(actor.buff_level(i), i) == 0
turn = actor.buff_turns(i).to_i
icons.each_with_index { |ic, i|
turns[i] = turn if ic == actor.buff_icon_index(actor.buff_level(i), i)
}
end
return turns
end
end