silver wind
Member
[rgss]#==============================================================================
# ** Additional Bitmap Methods
#------------------------------------------------------------------------------
# By Untra and Glitchfinder
# 5/29/10
# v0.85
#==============================================================================
class Bitmap
#------------------------------------------------------------------------------
#Make sure you have uabm.dll in your project folder.
#You can get it from (assuming link is not dead):
#http://www.box.net/shared/9m54d8hkzu
#------------------------------------------------------------------------------
Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
#--------------------------------------------------------------------------
# * Brighten
#--------------------------------------------------------------------------
def brighten(amount)
Brighten.call(self.__id__, amount)
end
#--------------------------------------------------------------------------
# * Darken
#--------------------------------------------------------------------------
def darken(amount)
Darken.call(self.__id__, amount)
end
#--------------------------------------------------------------------------
# * Invert
#--------------------------------------------------------------------------
def invert
Invert.call(self.__id__)
end
#--------------------------------------------------------------------------
# * Grayscale
#--------------------------------------------------------------------------
def grayscale
Grayscale.call(self.__id__)
end
end
#==============================================================================
# * Edit by Silver Wind
#==============================================================================
class Game_Event
def name
return @event.name
end
end
#-------------------------------------------------------------------------#
class Game_Map
def get_event(key)
if key.is_a?(String)
return get_event_by_name(key)
else
return get_event_by_id(key)
end
end
def get_event_by_name(name)
for i in @map.events.keys
ev = @events
return ev if ev.name == name
end
# Error: No such event
return nil
end
def get_event_by_id(i)
for k in @map.events.keys
ev = @events[k]
return ev if ev.id== i
end
# Error: No such event
return nil
end
end
#-------------------------------------------------------------------------#
class Scene_Map
def bitmap_effect(event, action, amount=nil)
ev = $game_map.get_event(event)
sprite = @spriteset.get_sprite(ev)
return if ev.nil?
case (action)
when 'brighten'
sprite.brighten_by(amount)
when 'darken'
sprite.darken_by(amount)
when 'invert'
sprite.invert
when 'grayscale'
sprite.grayscale
end
end
end
#-------------------------------------------------------------------------#
class Spriteset_Map
def get_sprite(event)
for sprite in @character_sprites
ev = sprite.character
# if it's the same Game_Event object.
if ev.object_id == event.object_id
target_sprite = sprite
end
end
return target_sprite
end
end
#-------------------------------------------------------------------------#
class Sprite_Character < RPG::Sprite
def brighten_by(x)
self.bitmap.brighten(x)
end
def darken_by(x)
self.bitmap.darken(x)
end
def invert
self.bitmap.invert
end
def grayscale
self.bitmap.grayscale
end
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
#----------------------------- edit -----------------------------#
# clone the bitmap before using it for an event.
bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.bitmap = bitmap.clone
#----------------------------------------------------------------#
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
#----------------------------- edit -----------------------------#
# clone the bitmap before using it for an event.
bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
self.bitmap = bitmap.clone
#----------------------------------------------------------------#
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
#-------------------------------------------------------------------------#
def brighten(event,amount)
#return unless $scene.is_a?(Scene_Map)
$scene.bitmap_effect(event,'brighten',amount)
end
def darken(event,amount)
$scene.bitmap_effect(event,'darken',amount)
end
def invert(event)
$scene.bitmap_effect(event,'invert')
end
def grayscale(event)
$scene.bitmap_effect(event,'grayscale')
end
[/rgss]
Tiny edit. only 170 lines o.o;
The 4 last methods are meant to keep the call short in the script box.
Send the event name or number as parameter:
brighten("EV001",64)
invert(2)
# ** Additional Bitmap Methods
#------------------------------------------------------------------------------
# By Untra and Glitchfinder
# 5/29/10
# v0.85
#==============================================================================
class Bitmap
#------------------------------------------------------------------------------
#Make sure you have uabm.dll in your project folder.
#You can get it from (assuming link is not dead):
#http://www.box.net/shared/9m54d8hkzu
#------------------------------------------------------------------------------
Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
#--------------------------------------------------------------------------
# * Brighten
#--------------------------------------------------------------------------
def brighten(amount)
Brighten.call(self.__id__, amount)
end
#--------------------------------------------------------------------------
# * Darken
#--------------------------------------------------------------------------
def darken(amount)
Darken.call(self.__id__, amount)
end
#--------------------------------------------------------------------------
# * Invert
#--------------------------------------------------------------------------
def invert
Invert.call(self.__id__)
end
#--------------------------------------------------------------------------
# * Grayscale
#--------------------------------------------------------------------------
def grayscale
Grayscale.call(self.__id__)
end
end
#==============================================================================
# * Edit by Silver Wind
#==============================================================================
class Game_Event
def name
return @event.name
end
end
#-------------------------------------------------------------------------#
class Game_Map
def get_event(key)
if key.is_a?(String)
return get_event_by_name(key)
else
return get_event_by_id(key)
end
end
def get_event_by_name(name)
for i in @map.events.keys
ev = @events
return ev if ev.name == name
end
# Error: No such event
return nil
end
def get_event_by_id(i)
for k in @map.events.keys
ev = @events[k]
return ev if ev.id== i
end
# Error: No such event
return nil
end
end
#-------------------------------------------------------------------------#
class Scene_Map
def bitmap_effect(event, action, amount=nil)
ev = $game_map.get_event(event)
sprite = @spriteset.get_sprite(ev)
return if ev.nil?
case (action)
when 'brighten'
sprite.brighten_by(amount)
when 'darken'
sprite.darken_by(amount)
when 'invert'
sprite.invert
when 'grayscale'
sprite.grayscale
end
end
end
#-------------------------------------------------------------------------#
class Spriteset_Map
def get_sprite(event)
for sprite in @character_sprites
ev = sprite.character
# if it's the same Game_Event object.
if ev.object_id == event.object_id
target_sprite = sprite
end
end
return target_sprite
end
end
#-------------------------------------------------------------------------#
class Sprite_Character < RPG::Sprite
def brighten_by(x)
self.bitmap.brighten(x)
end
def darken_by(x)
self.bitmap.darken(x)
end
def invert
self.bitmap.invert
end
def grayscale
self.bitmap.grayscale
end
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
#----------------------------- edit -----------------------------#
# clone the bitmap before using it for an event.
bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.bitmap = bitmap.clone
#----------------------------------------------------------------#
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
#----------------------------- edit -----------------------------#
# clone the bitmap before using it for an event.
bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
self.bitmap = bitmap.clone
#----------------------------------------------------------------#
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
#-------------------------------------------------------------------------#
def brighten(event,amount)
#return unless $scene.is_a?(Scene_Map)
$scene.bitmap_effect(event,'brighten',amount)
end
def darken(event,amount)
$scene.bitmap_effect(event,'darken',amount)
end
def invert(event)
$scene.bitmap_effect(event,'invert')
end
def grayscale(event)
$scene.bitmap_effect(event,'grayscale')
end
[/rgss]
Tiny edit. only 170 lines o.o;
The 4 last methods are meant to keep the call short in the script box.
Send the event name or number as parameter:
brighten("EV001",64)
invert(2)