=begin
================================================================================
KURO ANY BAR V2.0
================================================================================
Introduction :
A multi simple active bar for any kind of use.
From now will be used to support my advanced event system.
================================================================================
Changelog :
V.2.1 (10-12-2014)
* More property : skinpic.
* Kini hanya menerima nilai dari game variable.
* Fixed, value yang nembus nilai max atau kurang dari 0.
* Fixed, flip picture.
* Fixed, ukuran dan posisi text.
* Rapihin.
V.2.0 (06-09-2014)
* Method baru : Kuro::Bar.update
* More property : picture, gradien, etc.
* Gauge animatif.
* New interface : rombak habis-habisan.
V.1.0 (03-09-2014)
* Awal pembuatan, dan selesainya script.
================================================================================
Current feature :
* Multi simple custom bar.
* Come with custom text.
* Could be aligned.
* Vertical? no prob~
* Can use picture as the bar.
================================================================================
How to use :
Konfigurasi bar nya berada di module sesuai dengan format yang tertera.
Jadi tinggal siap panggil di mana saja melalui event dengan script call.
Kuro::Bar.create(ID) <<< buat bar
Kuro::Bar.update(ID,KEY,VALUE) <<< edit property bar
Kuro::Bar.delete(ID) <<< hapus bar
ID = adalah nomor id preset yang anda buat (0 = default preset)
KEY = nama property daripada bar di preset anda (:x, :y, :width)
VALUE = nilai baru untuk property preset anda.
================================================================================
=end
module Kuro
module Bar
#===============================================================================
# CONFIGURATION START
#===============================================================================
# COLOR PALLETTE
# ==============================================================================
# Palet warna. Silahkan saja kalo mau membuat warna anda sendiri.
# WARNA = Color.new(red, green, blue)
BLACK = Color.new(0,0,0)
WHITE = Color.new(255,255,255)
RED = Color.new(255,0,0)
GREEN = Color.new(0,255,0)
BLUE = Color.new(0,0,255)
YELLOW = Color.new(255,255,0)
CYAN = Color.new(0,255,255)
MAGENTA = Color.new(255,0,255)
# Palet warna untuk gradient. Gabung-gabungkan saja palet warna di atas.
# HANYA 2 WARNA !
# GRADIEN = [WARNA 1, WARNA 2]
GREENBLACK = [GREEN,BLACK]
BLUEBLACK = [BLUE,BLACK]
REDBLACK = [RED,BLACK]
# BAR DEFAULT VALUE
# ==============================================================================
PRESET = [{ # Default setting
# Setting default nya (PRESET[0]).
# Kalo ada property yang gak ada di preset yang anda buat, bakal pake value
# dari property yang ada di sini.
:x => 0, # X coordinate
:y => 0, # Y coordinate
:z => 50, # Z coordinate
:width => 100, # Bar width
:height => 10, # Bar height
:color => WHITE, # Bar color
:opaback => 255, # Back skin opacity (0~255)
:picture => nil, # Use picture as bar (in folder system)
:skinpic => nil, # Use picture as bar foreskin (in folder system)
:flip => false, # Flip the bar?
:text => nil, # Text (\\b = base value, \\m = max value)
:align => 0, # Bar align (0 = left, 1 = mid, 2 = right)
:base => 1, # Variable ID as base value (use "" for eval script)
:max => "100", # Variable ID as max value (use "" for eval script)
:vertical => false # Was it vertical?
}]
# Kecepatan animasi bar. Semakin gede, semakin cepat.
BOOST = 3
# BAR PRESET
#===============================================================================
# Mulai buat preset anda sendiri dari sini. Berantakan gak masalah selama
# nama key nya bener. Ingat, jangan lupa naruh tanda koma!
PRESET[1] = { # Actor 1 HP
:base => "$game_actors[1].hp",
:max => "$game_actors[1].mhp",
:text => "[\\b/\\m]",
:color => GREENBLACK,
:width => 120,
:height => 12,
:skinpic => "barskin",
}
PRESET[2] = { # Actor 1 MP
:y => 12,
:width => 120,
:height => 12,
:color => BLUEBLACK,
:base => "$game_actors[1].mp",
:max => "$game_actors[1].mmp",
:text => "[\\b/\\m]",
:skinpic => "barskin",
}
PRESET[3] = { # Quest : Kill Rat
:x => 16,
:y => 380,
:width => 512,
:height => 24,
:color => REDBLACK,
:opaback => 128,
:base => 1,
:max => "10",
:text => "kill rat (\\b/\\m)",
}
PRESET[4] = { # Mashing Button !!!
:x => 192,
:y => 240,
:picture => "screwthis",
:opaback => 200,
:base => 2,
:max => "100",
:align => 1,
}
PRESET[5] = { # Hit me!
:x => 364,
:width => 180,
:height => 24,
:base => 3,
:max => "30",
:text => "[\\b/\\m]",
:align => 2,
}
#===============================================================================
# CONFIGURATION END
#===============================================================================
def self.create(id)
$kab[id] = AnyBar.new(id)
end
def self.update(id,key,value)
return if PRESET[id][key] == value
PRESET[id][key] = value
if $kab[id] != nil
$kab[id].load
end
end
def self.delete(id)
if $kab[id] != nil
$kab[id].dispose
$kab[id] = nil
end
end
end
end
class AnyBar
def initialize(id)
@id = id
load
end
def load
d = Kuro::Bar::PRESET[0]
v = Kuro::Bar::PRESET[@id]
a = d.keys
k = []
for i in 0...a.size
if v.include?(a[i])
k[i] = v[a[i]]
else
k[i] = d[a[i]]
end
end
@x = k[0]
@y = k[1]
@z = k[2]
@w = k[3]
@h = k[4]
@c = k[5]
@o = k[6]
@p = k[7]
@s = k[8]
@f = k[9]
@t = k[10]
@a = k[11]
@n = k[12]
if k[13].is_a? Fixnum
@m = [$game_variables[k[13]],1].max
else
@m = [eval(k[13]),1].max
end
@v = k[14]
refresh
create
end
def refresh
@back.bitmap.dispose unless @back==nil
@bar.bitmap.dispose unless @bar==nil
@skin.bitmap.dispose unless @skin==nil
@text.bitmap.dispose unless @text==nil
end
def create
create_back if @o > 0
create_bar
create_skin if @s != nil
create_text if @t != nil
update
end
def create_back
@back = Sprite.new
if @p != nil
@back.bitmap = Cache.system(@p)
@back.tone = Tone.new(-255,-255,-255)
@back.mirror = @f
else
@back.bitmap = Bitmap.new(@w,@h)
@back.bitmap.fill_rect(0,0,@w,@h,Color.new(0,0,0,@o))
end
@back.x = @x
@back.y = @y
@back.z = @z
end
def create_bar
@bar = Sprite.new
if @p != nil
@bar.bitmap = Cache.system(@p)
@w = @bar.bitmap.width
@h = @bar.bitmap.height
@bar.mirror = @f
else
@bar.bitmap = Bitmap.new(@w,@h)
if @c.is_a? Array
@bar.bitmap.gradient_fill_rect(0,0,@w,@h,@c[0],@c[1],@v)
else
@bar.bitmap.fill_rect(0,0,@w,@h,@c)
end
end
@bar.x = @x
@bar.y = @y
@bar.z = @z+1
getvar
if @v
@bar.src_rect.height = @b*@h/@m
@bar.src_rect.y = (@h-@bar.height)/2 if @a==1
@bar.src_rect.y = (@h-@bar.height) if @a==2
@bar.y = @y+(@h-@bar.height)/2 if @a==1
@bar.y = @y+(@h-@bar.height) if @a==2
else
@bar.src_rect.width = @b*@w/@m
@bar.src_rect.x = (@w-@bar.width)/2 if @a==1
@bar.src_rect.x = (@w-@bar.width) if @a==2
@bar.x = @x+(@w-@bar.width)/2 if @a==1
@bar.x = @x+(@w-@bar.width) if @a==2
end
end
def create_skin
@skin = Sprite.new
@skin.bitmap = Cache.system(@s)
@skin.mirror = @f
@skin.x = @x
@skin.y = @y
@skin.z = @z+2
end
def create_text
@text = Sprite.new
@text.bitmap = Bitmap.new([@w,@h].max,20)
@text.bitmap.font.size = [@h,16].max
@text.x = @x
@text.x -= @text.width/2 if @v
@text.y = @y
@text.z = @z+3
end
def getvar
if @n.is_a? Fixnum
$game_variables[@n] = [[$game_variables[@n],0].max,@m].min
@b = $game_variables[@n]
else
@b = eval(@n)
end
end
def update
update_back if @back != nil
update_bar
update_text if @text != nil
update_skin if @skin != nil
end
def update_back
@back.update
end
def update_bar
getvar
htarget = @b*@h/@m
wtarget = @b*@w/@m
boost = Kuro::Bar::BOOST
return if @bar.height==htarget.round and @bar.width==wtarget.round
if @v
if @bar.height>htarget.round
@bar.src_rect.height = [@bar.src_rect.height-boost,htarget.round].max
else
@bar.src_rect.height = [@bar.src_rect.height+boost,htarget.round].min
end
@bar.src_rect.y = (@h-@bar.height)/2 if @a==1
@bar.src_rect.y = (@h-@bar.height) if @a==2
@bar.y = @y+(@h-@bar.height)/2 if @a==1
@bar.y = @y+(@h-@bar.height) if @a==2
else
if @bar.width>wtarget.round
@bar.src_rect.width = [@bar.src_rect.width-boost,wtarget.round].max
else
@bar.src_rect.width = [@bar.src_rect.width+boost,wtarget.round].min
end
@bar.src_rect.x = (@w-@bar.width)/2 if @a==1
@bar.src_rect.x = (@w-@bar.width) if @a==2
@bar.x = @x+(@w-@bar.width)/2 if @a==1
@bar.x = @x+(@w-@bar.width) if @a==2
end
end
def update_skin
@skin.update
end
def update_text
@text.bitmap.clear
if @v
@text.bitmap.draw_text(0,0,@h,@w,convert(@t),1)
@text.angle=-90
else
@text.bitmap.draw_text(0,0,@w,@h,convert(@t),1)
end
end
def convert(text)
text = text.gsub(/\\b/){@b.to_s}
text = text.gsub(/\\m/){@m.to_s}
return text
end
def dispose
@back.dispose if @back != nil
@bar.dispose
@text.dispose if @text != nil
@skin.dispose if @skin != nil
end
end
class Scene_Map < Scene_Base
alias kab_potato update
def update
kab_potato
$kab = [] if $kab == nil
for i in 0...$kab.length
$kab[i].update unless $kab[i] == nil
end
end
end