$VIPArcherScript ||= {};$VIPArcherScript[:window_cursor] = 20150513
module VIPArcher end
module VIPArcher::WindowCursor
FILENAME = "WindowCursor"
BUFFER_X = 0
BUFFER_Y = 6
EFFECT_TYPE = 1
EFFECT_SPEED = 8
CURSOR_FRAME = 1
end
class Sprite_WindowCursor < Sprite_Base
include VIPArcher::WindowCursor
def initialize(window)
super(window.viewport)
@window, @effect, self.opacity = window, [0,0,0], 0
create_bitmap
end
def create_bitmap
begin
self.bitmap = Cache.system(FILENAME)
@w, @h, @frame = self.bitmap.width / CURSOR_FRAME, self.bitmap.height, 0
self.src_rect.set(@frame, 0, @w, @h)
rescue
self.bitmap = Bitmap.new(10, 16)
@w, @h = self.bitmap.width, self.bitmap.height
self.bitmap.blt(0, 0,@window.windowskin, Rect.new(102, 24, 10, 16))
end
end
def update
super
update_visibility
update_position
update_effect if Graphics.frame_count % EFFECT_SPEED == 0
end
def dispose
self.bitmap.dispose
super
end
def update_effect
update_src_rect
return unless EFFECT_TYPE
case @effect[0] += 1
when 1..7 then @effect[EFFECT_TYPE] += 1
when 8..14 then @effect[EFFECT_TYPE] -= 1
else @effect[0] = 0 end
end
def update_src_rect
return if @w == self.bitmap.width
sx = (@frame += 1) % CURSOR_FRAME * @w
self.src_rect.set(sx, 0, @w, @h)
end
def update_visibility
self.visible = @window.visible
self.visible = @window.openness > 250
self.opacity += @window.active ? 45 : -45
self.opacity = 0 if @window.index < 0
end
def update_position
rect = @window.cursor_rect
self.z = @window.z + 100
self.x = @window.x + rect.x - @window.ox + BUFFER_X + @effect[1]
self.y = @window.y + rect.y - @window.oy +
BUFFER_Y + rect.height / 2 + @effect[2]
end
end
class Window_Selectable < Window_Base
alias cursor_sprite_initialize initialize
def initialize(*args)
cursor_sprite_initialize(*args)
create_cursor_sprite
end
def create_cursor_sprite
@cursor_sprite = Sprite_WindowCursor.new(self)
end
alias cursor_sprite_dispose dispose
def dispose
cursor_sprite_dispose
@cursor_sprite.dispose if @cursor_sprite
end
alias cursor_sprite_update update
def update
cursor_sprite_update
@cursor_sprite.update if @cursor_sprite
end
end