じ☆ve冰风 发表于 2026-7-31 21:35:14

Kuro Any Bar

Kuro Any Bar
V2.1
Tipe: Eventer Tool​
Introduction
"I want my game to have multiple bar on map which I can define it as I wanted it to be!" And thus this script was born.

Feature

[*]Animated multi-function bar.
[*]Might be called as much as you wanted.
[*]Can use either variable ID or eval script.
[*]Very customable and easy to use!
[*]Additionally including the text which you can edit.
[*]Can use picture as the bar.
Screenshots

https://dl.dropboxusercontent.com/u/51143583/image/Kuro%20Any%20Bar.PNG


Demo
https://db.tt/CwRDmzxo V2.1 (10/12/2014)

Script

Spoiler                Code:       
=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    =
    GREENBLACK =
    BLUEBLACK=
    REDBLACK=

# BAR DEFAULT VALUE
# ==============================================================================
    PRESET = [{ # Default setting
# Setting default nya (PRESET).
# 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 = { # Actor 1 HP
      :base    => "$game_actors.hp",
      :max      => "$game_actors.mhp",
      :text    => "[\\b/\\m]",
      :color    => GREENBLACK,
      :width    => 120,
      :height=> 12,
      :skinpic=> "barskin",
    }
    PRESET = { # Actor 1 MP
      :y      => 12,
      :width    => 120,
      :height=> 12,
      :color    => BLUEBLACK,
      :base    => "$game_actors.mp",
      :max      => "$game_actors.mmp",
      :text    => "[\\b/\\m]",
      :skinpic=> "barskin",
    }
    PRESET = { # 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 = { # Mashing Button !!!
      :x      => 192,
      :y      => 240,
      :picture=> "screwthis",
      :opaback=> 200,
      :base    => 2,
      :max      => "100",
      :align    => 1,
    }
    PRESET = { # Hit me!
      :x      => 364,
      :width    => 180,
      :height=> 24,
      :base    => 3,
      :max      => "30",
      :text    => "[\\b/\\m]",
      :align    => 2,
    }
#===============================================================================
# CONFIGURATION END
#===============================================================================
   
    def self.create(id)
      $kab = AnyBar.new(id)
    end
    def self.update(id,key,value)
      return if PRESET == value
      PRESET = value
      if $kab != nil
      $kab.load
      end
    end
    def self.delete(id)
      if $kab != nil
      $kab.dispose
      $kab = nil
      end
    end
end
end

class AnyBar
def initialize(id)
    @id = id
    load
end
def load
    d = Kuro::Bar::PRESET
    v = Kuro::Bar::PRESET[@id]
    a = d.keys
    k = []
    for i in 0...a.size
      if v.include?(a)
      k = v]
      else
      k = d]
      end
    end
    @x = k
    @y = k
    @z = k
    @w = k
    @h = k
    @c = k
    @o = k
    @p = k
    @s = k
    @f = k
    @t = k
    @a = k
    @n = k
    if k.is_a? Fixnum
      @m = [$game_variables],1].max
    else
      @m = ),1].max
    end
    @v = k
    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,@c,@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.update unless $kab == nil
    end
end
end






How to use?
Configuration help are written in the module. You may define the bar preset ID by yourself there.
You may call this via script call event :
Kuro::Bar.create(ID) to create the bar preset ID
Kuro::Bar.update(ID, KEY, NEW_VALUE) edit the VALUE from KEY in preset ID.
Kuro::Bar.delete(ID) Erase the bar preset ID.
See the demo for more detail.

Credits
Kuro DCupu

Author's Notes
I'm more like an eventer myself and this script has only been used for my own personal purpose as an eventer until now, so any distaste, error, bug or glitch are expected.
I did share it on certain forum at http://rmid.forumotion.net/t8641p10-rgss3-kuro-any-bar but not many feedback, thus this script stop progressing by then.


本贴来自国际rpgmaker官方论坛作者:Kuro DCupu处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/kuro-any-bar.40919/
页: [1]
查看完整版本: Kuro Any Bar